mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-23 23:40:53 +07:00
selftests/bpf: Fix test_core_autosize on big-endian machines
[ Upstream commit d164dd9a5c08c16a883b3de97d13948c7be7fa4d ]
The "probed" part of test_core_autosize copies an integer using
bpf_core_read() into an integer of a potentially different size.
On big-endian machines a destination offset is required for this to
produce a sensible result.
Fixes: 888d83b961
("selftests/bpf: Validate libbpf's auto-sizing of LD/ST/STX instructions")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210812224814.187460-1-iii@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
82b40e0aa7
commit
bda2e0a03c
@ -125,6 +125,16 @@ int handle_downsize(void *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define bpf_core_read_int bpf_core_read
|
||||
#else
|
||||
#define bpf_core_read_int(dst, sz, src) ({ \
|
||||
/* Prevent "subtraction from stack pointer prohibited" */ \
|
||||
volatile long __off = sizeof(*dst) - (sz); \
|
||||
bpf_core_read((char *)(dst) + __off, sz, src); \
|
||||
})
|
||||
#endif
|
||||
|
||||
SEC("raw_tp/sys_enter")
|
||||
int handle_probed(void *ctx)
|
||||
{
|
||||
@ -132,23 +142,23 @@ int handle_probed(void *ctx)
|
||||
__u64 tmp;
|
||||
|
||||
tmp = 0;
|
||||
bpf_core_read(&tmp, bpf_core_field_size(in->ptr), &in->ptr);
|
||||
bpf_core_read_int(&tmp, bpf_core_field_size(in->ptr), &in->ptr);
|
||||
ptr_probed = tmp;
|
||||
|
||||
tmp = 0;
|
||||
bpf_core_read(&tmp, bpf_core_field_size(in->val1), &in->val1);
|
||||
bpf_core_read_int(&tmp, bpf_core_field_size(in->val1), &in->val1);
|
||||
val1_probed = tmp;
|
||||
|
||||
tmp = 0;
|
||||
bpf_core_read(&tmp, bpf_core_field_size(in->val2), &in->val2);
|
||||
bpf_core_read_int(&tmp, bpf_core_field_size(in->val2), &in->val2);
|
||||
val2_probed = tmp;
|
||||
|
||||
tmp = 0;
|
||||
bpf_core_read(&tmp, bpf_core_field_size(in->val3), &in->val3);
|
||||
bpf_core_read_int(&tmp, bpf_core_field_size(in->val3), &in->val3);
|
||||
val3_probed = tmp;
|
||||
|
||||
tmp = 0;
|
||||
bpf_core_read(&tmp, bpf_core_field_size(in->val4), &in->val4);
|
||||
bpf_core_read_int(&tmp, bpf_core_field_size(in->val4), &in->val4);
|
||||
val4_probed = tmp;
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user