bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/3] Add USDT support for s390
@ 2022-04-07 21:44 Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 1/3] libbpf: Minor style improvements in USDT code Ilya Leoshkevich
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ilya Leoshkevich @ 2022-04-07 21:44 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev
  Cc: bpf, Ilya Leoshkevich

This series adds USDT support for s390, making the "usdt" test pass
there. Patch 1 is a collection of minor cleanups, patch 2 adds
BPF-side support, patch 3 adds userspace-side support.

Ilya Leoshkevich (3):
  libbpf: Minor style improvements in USDT code
  libbpf: Make BPF-side of USDT support work on big-endian machines
  libbpf: Add s390-specific USDT arg spec parsing logic

 tools/lib/bpf/usdt.bpf.h |  7 ++--
 tools/lib/bpf/usdt.c     | 69 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 68 insertions(+), 8 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 1/3] libbpf: Minor style improvements in USDT code
  2022-04-07 21:44 [PATCH bpf-next 0/3] Add USDT support for s390 Ilya Leoshkevich
@ 2022-04-07 21:44 ` Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 2/3] libbpf: Make BPF-side of USDT support work on big-endian machines Ilya Leoshkevich
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ilya Leoshkevich @ 2022-04-07 21:44 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev
  Cc: bpf, Ilya Leoshkevich

Fix several typos and references to non-existing headers.
Also use __BYTE_ORDER__ instead of __BYTE_ORDER for consistency with
the rest of the bpf code - see commit 45f2bebc8079 ("libbpf: Fix
endianness detection in BPF_CORE_READ_BITFIELD_PROBED()") for
rationale).

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/lib/bpf/usdt.bpf.h |  4 ++--
 tools/lib/bpf/usdt.c     | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/lib/bpf/usdt.bpf.h b/tools/lib/bpf/usdt.bpf.h
index 60237acf6b02..420d743734e1 100644
--- a/tools/lib/bpf/usdt.bpf.h
+++ b/tools/lib/bpf/usdt.bpf.h
@@ -166,7 +166,7 @@ int bpf_usdt_arg(struct pt_regs *ctx, __u64 arg_num, long *res)
 	case BPF_USDT_ARG_REG_DEREF:
 		/* Arg is in memory addressed by register, plus some offset
 		 * (e.g., "-4@-1204(%rbp)" in USDT arg spec). Register is
-		 * identified lik with BPF_USDT_ARG_REG case, and the offset
+		 * identified like with BPF_USDT_ARG_REG case, and the offset
 		 * is in arg_spec->val_off. We first fetch register contents
 		 * from pt_regs, then do another user-space probe read to
 		 * fetch argument value itself.
@@ -198,7 +198,7 @@ int bpf_usdt_arg(struct pt_regs *ctx, __u64 arg_num, long *res)
 /* Retrieve user-specified cookie value provided during attach as
  * bpf_usdt_opts.usdt_cookie. This serves the same purpose as BPF cookie
  * returned by bpf_get_attach_cookie(). Libbpf's support for USDT is itself
- * utilizaing BPF cookies internally, so user can't use BPF cookie directly
+ * utilizing BPF cookies internally, so user can't use BPF cookie directly
  * for USDT programs and has to use bpf_usdt_cookie() API instead.
  */
 static inline __noinline
diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index c5acf2824fcc..99a7c614c7b1 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -108,7 +108,7 @@
  * code through spec map. This allows BPF applications to quickly fetch the
  * actual value at runtime using a simple BPF-side code.
  *
- * With basics out of the way, let's go over less immeditately obvious aspects
+ * With basics out of the way, let's go over less immediately obvious aspects
  * of supporting USDTs.
  *
  * First, there is no special USDT BPF program type. It is actually just
@@ -189,14 +189,14 @@
 #define USDT_NOTE_TYPE 3
 #define USDT_NOTE_NAME "stapsdt"
 
-/* should match exactly enum __bpf_usdt_arg_type from bpf_usdt.bpf.h */
+/* should match exactly enum __bpf_usdt_arg_type from usdt.bpf.h */
 enum usdt_arg_type {
 	USDT_ARG_CONST,
 	USDT_ARG_REG,
 	USDT_ARG_REG_DEREF,
 };
 
-/* should match exactly struct __bpf_usdt_arg_spec from bpf_usdt.bpf.h */
+/* should match exactly struct __bpf_usdt_arg_spec from usdt.bpf.h */
 struct usdt_arg_spec {
 	__u64 val_off;
 	enum usdt_arg_type arg_type;
@@ -328,9 +328,9 @@ static int sanity_check_usdt_elf(Elf *elf, const char *path)
 		return -EBADF;
 	}
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	endianness = ELFDATA2LSB;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	endianness = ELFDATA2MSB;
 #else
 # error "Unrecognized __BYTE_ORDER__"
@@ -843,7 +843,7 @@ static int bpf_link_usdt_detach(struct bpf_link *link)
 						   sizeof(*new_free_ids));
 		/* If we couldn't resize free_spec_ids, we'll just leak
 		 * a bunch of free IDs; this is very unlikely to happen and if
-		 * system is so exausted on memory, it's the least of user's
+		 * system is so exhausted on memory, it's the least of user's
 		 * concerns, probably.
 		 * So just do our best here to return those IDs to usdt_manager.
 		 */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 2/3] libbpf: Make BPF-side of USDT support work on big-endian machines
  2022-04-07 21:44 [PATCH bpf-next 0/3] Add USDT support for s390 Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 1/3] libbpf: Minor style improvements in USDT code Ilya Leoshkevich
@ 2022-04-07 21:44 ` Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 3/3] libbpf: Add s390-specific USDT arg spec parsing logic Ilya Leoshkevich
  2022-04-08 14:10 ` [PATCH bpf-next 0/3] Add USDT support for s390 patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ilya Leoshkevich @ 2022-04-07 21:44 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev
  Cc: bpf, Ilya Leoshkevich

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>
---
 tools/lib/bpf/usdt.bpf.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/lib/bpf/usdt.bpf.h b/tools/lib/bpf/usdt.bpf.h
index 420d743734e1..881a2422a8ef 100644
--- 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, __u64 arg_num, long *res)
 		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;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 3/3] libbpf: Add s390-specific USDT arg spec parsing logic
  2022-04-07 21:44 [PATCH bpf-next 0/3] Add USDT support for s390 Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 1/3] libbpf: Minor style improvements in USDT code Ilya Leoshkevich
  2022-04-07 21:44 ` [PATCH bpf-next 2/3] libbpf: Make BPF-side of USDT support work on big-endian machines Ilya Leoshkevich
@ 2022-04-07 21:44 ` Ilya Leoshkevich
  2022-04-08 14:10 ` [PATCH bpf-next 0/3] Add USDT support for s390 patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ilya Leoshkevich @ 2022-04-07 21:44 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev
  Cc: bpf, Ilya Leoshkevich

The logic is superficially similar to that of x86, but the small
differences (no need for register table and dynamic allocation of
register names, no $ sign before constants) make maintaining a common
implementation too burdensome. Therefore simply add a s390x-specific
version of parse_usdt_arg().

Note that while bcc supports index registers, this patch does not. This
should not be a problem in most cases, since s390 uses a default value
"nor" for STAP_SDT_ARG_CONSTRAINT.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/lib/bpf/usdt.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index 99a7c614c7b1..da145724e8c0 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -1269,6 +1269,63 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec
 	return len;
 }
 
+#elif defined(__s390x__)
+
+/* Do not support __s390__ for now, since user_pt_regs is broken with -m31. */
+
+static int parse_usdt_arg(const char *arg_str, int arg_num,
+			  struct usdt_arg_spec *arg)
+{
+	unsigned int reg;
+	int sz, len;
+	long off;
+
+	if (sscanf(arg_str, " %d @ %ld ( %%r%u ) %n", &sz, &off, &reg, &len) == 3) {
+		/* Memory dereference case, e.g., -2@-28(%r15) */
+		arg->arg_type = USDT_ARG_REG_DEREF;
+		arg->val_off = off;
+		if (reg > 15) {
+			pr_warn("usdt: unrecognized register '%%r%u'\n", reg);
+			return -EINVAL;
+		}
+		arg->reg_off = offsetof(user_pt_regs, gprs[reg]);
+	} else if (sscanf(arg_str, " %d @ %%r%u %n", &sz, &reg, &len) == 2) {
+		/* Register read case, e.g., -8@%r0 */
+		arg->arg_type = USDT_ARG_REG;
+		arg->val_off = 0;
+		if (reg > 15) {
+			pr_warn("usdt: unrecognized register '%%r%u'\n", reg);
+			return -EINVAL;
+		}
+		arg->reg_off = offsetof(user_pt_regs, gprs[reg]);
+	} else if (sscanf(arg_str, " %d @ %ld %n", &sz, &off, &len) == 2) {
+		/* Constant value case, e.g., 4@71 */
+		arg->arg_type = USDT_ARG_CONST;
+		arg->val_off = off;
+		arg->reg_off = -1;
+	} else {
+		pr_warn("usdt: unrecognized arg #%d spec '%s'\n", arg_num,
+			arg_str);
+		return -EINVAL;
+	}
+
+	arg->arg_signed = sz < 0;
+	if (sz < 0)
+		sz = -sz;
+
+	switch (sz) {
+	case 1: case 2: case 4: case 8:
+		arg->arg_bitshift = 64 - sz * 8;
+		break;
+	default:
+		pr_warn("usdt: unsupported arg #%d (spec '%s') size: %d\n",
+			arg_num, arg_str, sz);
+		return -EINVAL;
+	}
+
+	return len;
+}
+
 #else
 
 static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 0/3] Add USDT support for s390
  2022-04-07 21:44 [PATCH bpf-next 0/3] Add USDT support for s390 Ilya Leoshkevich
                   ` (2 preceding siblings ...)
  2022-04-07 21:44 ` [PATCH bpf-next 3/3] libbpf: Add s390-specific USDT arg spec parsing logic Ilya Leoshkevich
@ 2022-04-08 14:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-08 14:10 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: ast, daniel, andrii.nakryiko, hca, gor, borntraeger, agordeev, bpf

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu,  7 Apr 2022 23:44:08 +0200 you wrote:
> This series adds USDT support for s390, making the "usdt" test pass
> there. Patch 1 is a collection of minor cleanups, patch 2 adds
> BPF-side support, patch 3 adds userspace-side support.
> 
> Ilya Leoshkevich (3):
>   libbpf: Minor style improvements in USDT code
>   libbpf: Make BPF-side of USDT support work on big-endian machines
>   libbpf: Add s390-specific USDT arg spec parsing logic
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/3] libbpf: Minor style improvements in USDT code
    https://git.kernel.org/bpf/bpf-next/c/e1b6df598aa8
  - [bpf-next,2/3] libbpf: Make BPF-side of USDT support work on big-endian machines
    https://git.kernel.org/bpf/bpf-next/c/6f403d9d5306
  - [bpf-next,3/3] libbpf: Add s390-specific USDT arg spec parsing logic
    https://git.kernel.org/bpf/bpf-next/c/bd022685bd44

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-08 14:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 21:44 [PATCH bpf-next 0/3] Add USDT support for s390 Ilya Leoshkevich
2022-04-07 21:44 ` [PATCH bpf-next 1/3] libbpf: Minor style improvements in USDT code Ilya Leoshkevich
2022-04-07 21:44 ` [PATCH bpf-next 2/3] libbpf: Make BPF-side of USDT support work on big-endian machines Ilya Leoshkevich
2022-04-07 21:44 ` [PATCH bpf-next 3/3] libbpf: Add s390-specific USDT arg spec parsing logic Ilya Leoshkevich
2022-04-08 14:10 ` [PATCH bpf-next 0/3] Add USDT support for s390 patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).