Blob Blame History Raw
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 7 Apr 2022 23:44:10 +0200
Subject: libbpf: Make BPF-side of USDT support work on big-endian machines
Patch-mainline: v5.19-rc1
Git-commit: 6f403d9d530635f533577d37929c61474d6c5d7f
References: jsc#PED-1377

BPF_USDT_ARG_REG_DEREF handling always reads 8 bytes, regardless of
the actual argument size. On little-endian the relevant argument bits
end up in the lower bits of val, and later on the code that handles
all the argument types expects them to be there.

On big-endian they end up in the upper bits of val, breaking that
expectation. Fix by right-shifting val on big-endian.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220407214411.257260-3-iii@linux.ibm.com
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
 tools/lib/bpf/usdt.bpf.h |    3 +++
 1 file changed, 3 insertions(+)

--- a/tools/lib/bpf/usdt.bpf.h
+++ b/tools/lib/bpf/usdt.bpf.h
@@ -177,6 +177,9 @@ int bpf_usdt_arg(struct pt_regs *ctx, __
 		err = bpf_probe_read_user(&val, sizeof(val), (void *)val + arg_spec->val_off);
 		if (err)
 			return err;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+		val >>= arg_spec->arg_bitshift;
+#endif
 		break;
 	default:
 		return -EINVAL;