* [PATCH v2 bpf-next 0/1] libbpf: usdt aarch64 support
@ 2022-04-11 15:21 Alan Maguire
2022-04-11 15:21 ` [PATCH v2 bpf-next] libbpf: usdt aarch64 arg parsing support Alan Maguire
0 siblings, 1 reply; 3+ messages in thread
From: Alan Maguire @ 2022-04-11 15:21 UTC (permalink / raw)
To: andrii, ast, daniel
Cc: iii, kafai, songliubraving, yhs, john.fastabend, kpsingh, netdev,
bpf, Alan Maguire
USDT support [1] requires architecture-specific handling for translating
from argument strings describing each probe argument to appropriate values
that can be made available to the BPF program. Determining value size,
whether it refers to a dereference (and if there is an offset from the
register value), a register value or a constant all have to be parsed
slightly differently for different architectures. Details of format
handling for the aarch64 case are in patch 1.
Changes since v1:
- dropped patch refactoring all arch-specific parsing (Andrii)
- reworked sscanf()s to separate the two register dereference cases,
made register parsing match [a-z0-9] in all cases (Andrii)
[1] https://lore.kernel.org/bpf/20220404234202.331384-1-andrii@kernel.org/
Alan Maguire (1):
libbpf: usdt aarch64 arg parsing support
tools/lib/bpf/usdt.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
--
1.8.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 bpf-next] libbpf: usdt aarch64 arg parsing support
2022-04-11 15:21 [PATCH v2 bpf-next 0/1] libbpf: usdt aarch64 support Alan Maguire
@ 2022-04-11 15:21 ` Alan Maguire
2022-04-11 22:40 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 3+ messages in thread
From: Alan Maguire @ 2022-04-11 15:21 UTC (permalink / raw)
To: andrii, ast, daniel
Cc: iii, kafai, songliubraving, yhs, john.fastabend, kpsingh, netdev,
bpf, Alan Maguire
Parsing of USDT arguments is architecture-specific; on aarch64 it is
relatively easy since registers used are x[0-31], sp. Format is
slightly different compared to x86_64; forms are
- "size @ [ reg[,offset] ]" for dereferences, for example
"-8 @ [ sp, 76 ]" ; " -4 @ [ sp ]"
- "size @ reg" for register values; for example
"-4@x0"
- "size @ value" for raw values; for example
"-8@1"
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
tools/lib/bpf/usdt.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index acf2d99..934c253 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -1324,6 +1324,82 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec
return len;
}
+#elif defined(__aarch64__)
+
+static int calc_pt_regs_off(const char *reg_name)
+{
+ int reg_num;
+
+ if (sscanf(reg_name, "x%d", ®_num) == 1) {
+ if (reg_num >= 0 && reg_num < 31)
+ return offsetof(struct user_pt_regs, regs[reg_num]);
+ } else if (strcmp(reg_name, "sp") == 0) {
+ return offsetof(struct user_pt_regs, sp);
+ }
+ pr_warn("usdt: unrecognized register '%s'\n", reg_name);
+ return -ENOENT;
+}
+
+static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg)
+{
+ char *reg_name = NULL;
+ int arg_sz, len, reg_off;
+ long off;
+
+ if (sscanf(arg_str, " %d @ \[ %m[a-z0-9], %ld ] %n", &arg_sz, ®_name, &off, &len) == 3) {
+ /* Memory dereference case, e.g., -4@[sp, 96] */
+ arg->arg_type = USDT_ARG_REG_DEREF;
+ arg->val_off = off;
+ reg_off = calc_pt_regs_off(reg_name);
+ free(reg_name);
+ if (reg_off < 0)
+ return reg_off;
+ arg->reg_off = reg_off;
+ } else if (sscanf(arg_str, " %d @ \[ %m[a-z0-9] ] %n", &arg_sz, ®_name, &len) == 2) {
+ /* Memory dereference case, e.g., -4@[sp] */
+ arg->arg_type = USDT_ARG_REG_DEREF;
+ arg->val_off = 0;
+ reg_off = calc_pt_regs_off(reg_name);
+ free(reg_name);
+ if (reg_off < 0)
+ return reg_off;
+ arg->reg_off = reg_off;
+ } else if (sscanf(arg_str, " %d @ %ld %n", &arg_sz, &off, &len) == 2) {
+ /* Constant value case, e.g., 4@5 */
+ arg->arg_type = USDT_ARG_CONST;
+ arg->val_off = off;
+ arg->reg_off = 0;
+ } else if (sscanf(arg_str, " %d @ %m[a-z0-9] %n", &arg_sz, ®_name, &len) == 2) {
+ /* Register read case, e.g., -8@x4 */
+ arg->arg_type = USDT_ARG_REG;
+ arg->val_off = 0;
+ reg_off = calc_pt_regs_off(reg_name);
+ free(reg_name);
+ if (reg_off < 0)
+ return reg_off;
+ arg->reg_off = reg_off;
+ } else {
+ pr_warn("usdt: unrecognized arg #%d spec '%s'\n", arg_num, arg_str);
+ return -EINVAL;
+ }
+
+ arg->arg_signed = arg_sz < 0;
+ if (arg_sz < 0)
+ arg_sz = -arg_sz;
+
+ switch (arg_sz) {
+ case 1: case 2: case 4: case 8:
+ arg->arg_bitshift = 64 - arg_sz * 8;
+ break;
+ default:
+ pr_warn("usdt: unsupported arg #%d (spec '%s') size: %d\n",
+ arg_num, arg_str, arg_sz);
+ return -EINVAL;
+ }
+
+ return len;
+}
+
#else
static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 bpf-next] libbpf: usdt aarch64 arg parsing support
2022-04-11 15:21 ` [PATCH v2 bpf-next] libbpf: usdt aarch64 arg parsing support Alan Maguire
@ 2022-04-11 22:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-11 22:40 UTC (permalink / raw)
To: Alan Maguire
Cc: andrii, ast, daniel, iii, kafai, songliubraving, yhs,
john.fastabend, kpsingh, netdev, bpf
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 11 Apr 2022 16:21:36 +0100 you wrote:
> Parsing of USDT arguments is architecture-specific; on aarch64 it is
> relatively easy since registers used are x[0-31], sp. Format is
> slightly different compared to x86_64; forms are
>
> - "size @ [ reg[,offset] ]" for dereferences, for example
> "-8 @ [ sp, 76 ]" ; " -4 @ [ sp ]"
> - "size @ reg" for register values; for example
> "-4@x0"
> - "size @ value" for raw values; for example
> "-8@1"
>
> [...]
Here is the summary with links:
- [v2,bpf-next] libbpf: usdt aarch64 arg parsing support
https://git.kernel.org/bpf/bpf-next/c/0f8619929c57
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] 3+ messages in thread
end of thread, other threads:[~2022-04-11 22:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-11 15:21 [PATCH v2 bpf-next 0/1] libbpf: usdt aarch64 support Alan Maguire
2022-04-11 15:21 ` [PATCH v2 bpf-next] libbpf: usdt aarch64 arg parsing support Alan Maguire
2022-04-11 22:40 ` 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).