All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Marchevsky <davemarchevsky@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Rik van Riel <riel@surriel.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>, Yonghong Song <yhs@fb.com>,
	<kernel-team@fb.com>, Dave Marchevsky <davemarchevsky@fb.com>
Subject: [RFC PATCH bpf-next 0/5] bpf: add get_reg_val helper
Date: Thu, 12 May 2022 00:43:16 -0700	[thread overview]
Message-ID: <20220512074321.2090073-1-davemarchevsky@fb.com> (raw)

Currently, BPF programs can access register values from struct pt_regs.
Fetching other registers is not supported. For some usecases this limits
the usefulness of BPF programs. This series adds a helper meant to
fetch any register value for the architecture the program is running on.

Concrete motivating usecase: Tracing programs often attach to User
Statically-Defined Tracing (USDT) probes, which can pass arguments using
registers. The registers used to pass arguments for a specific probe are
determined at compile-time. 

Although general-purpose registers which can be accessed via pt_regs are 
usually chosen, register pressure can cause others to be used. Recently
we saw this happening in a Fedora libpthread library [0], where a xmm
register was used. Similarly, floating-point arguments in USDTs will
result in use of xmm register [1]. Since there is no way to access the
registers used to pass these arguments, BPF programs can't use them.

Another usecase: rdtsc access.

Initially the helper was meant to narrowly address the USDT xmm usecase
but conversation with Andrii highlighted the usefulness of a more
general helper. Although only x86 SSE reg fetching is added in this
patchset, the path forward for adding other register sets and
architectures should be clear.

Feedback from someone familiar with s390 or other arch regarding whether
the helper would be usable for other archs in current form would be
appreciated.


Summary of patches:

Patch 1 moves a header so fpregs_state_valid helper can be used.

Patches 2 and 3 contain the meat of the kernel- and libbpf-side
changes, respectively. Libbpf-side changes add use of the helper to usdt
lib in order to address USDT xmm issue that originally prompted this
work.

Patches 4 and 5 add tests.

Submitted as RFC for early feedback while failing usdt12 prog
verification is addressed (see patch 3).

  [0] - https://github.com/iovisor/bcc/pull/3880
	[1] - https://github.com/iovisor/bcc/issues/3875

Dave Marchevsky (5):
  x86/fpu: Move context.h to include/asm
  bpf: add get_reg_val helper
  libbpf: usdt lib wiring of xmm reads
  selftests/bpf: Add test for USDT parse of xmm reg
  selftests/bpf: get_reg_val test exercising fxsave fetch

 .../x86/{kernel => include/asm}/fpu/context.h |   2 +
 arch/x86/kernel/fpu/core.c                    |   2 +-
 arch/x86/kernel/fpu/regset.c                  |   2 +-
 arch/x86/kernel/fpu/signal.c                  |   2 +-
 arch/x86/kernel/fpu/xstate.c                  |   2 +-
 include/linux/bpf.h                           |   1 +
 include/uapi/linux/bpf.h                      |  40 +++++
 kernel/trace/bpf_trace.c                      | 148 ++++++++++++++++++
 kernel/trace/bpf_trace.h                      |   1 +
 net/bpf/bpf_dummy_struct_ops.c                |  13 ++
 tools/include/uapi/linux/bpf.h                |  40 +++++
 tools/lib/bpf/usdt.bpf.h                      |  36 +++--
 tools/lib/bpf/usdt.c                          |  51 +++++-
 tools/testing/selftests/bpf/Makefile          |   8 +-
 .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  13 ++
 tools/testing/selftests/bpf/prog_tests/usdt.c |  49 ++++++
 .../selftests/bpf/progs/test_urandom_usdt.c   |  37 +++++
 tools/testing/selftests/bpf/test_progs.c      |   7 +
 tools/testing/selftests/bpf/urandom_read.c    |   3 +
 .../selftests/bpf/urandom_read_lib_xmm.c      |  62 ++++++++
 20 files changed, 499 insertions(+), 20 deletions(-)
 rename arch/x86/{kernel => include/asm}/fpu/context.h (96%)
 create mode 100644 tools/testing/selftests/bpf/urandom_read_lib_xmm.c

-- 
2.30.2


             reply	other threads:[~2022-05-12  7:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  7:43 Dave Marchevsky [this message]
2022-05-12  7:43 ` [RFC PATCH bpf-next 1/5] x86/fpu: Move context.h to include/asm Dave Marchevsky
2022-05-12 13:56   ` David Vernet
2022-05-14  0:44   ` Alexei Starovoitov
2022-05-12  7:43 ` [RFC PATCH bpf-next 2/5] bpf: add get_reg_val helper Dave Marchevsky
2022-05-12 15:29   ` David Vernet
2022-05-18  8:07     ` Dave Marchevsky
2022-05-14  0:41   ` Alexei Starovoitov
2022-05-18  7:35     ` Dave Marchevsky
2022-05-12  7:43 ` [RFC PATCH bpf-next 3/5] libbpf: usdt lib wiring of xmm reads Dave Marchevsky
2022-05-14  0:43   ` Alexei Starovoitov
2022-05-16 23:26   ` Andrii Nakryiko
2022-05-18  8:20     ` Dave Marchevsky
2022-05-12  7:43 ` [RFC PATCH bpf-next 4/5] selftests/bpf: Add test for USDT parse of xmm reg Dave Marchevsky
2022-05-16 23:31   ` Andrii Nakryiko
2022-05-17  1:17     ` Alexei Starovoitov
2022-05-18 23:56       ` Andrii Nakryiko
2022-05-12  7:43 ` [RFC PATCH bpf-next 5/5] selftests/bpf: get_reg_val test exercising fxsave fetch Dave Marchevsky
2022-05-12 17:47   ` Dave Marchevsky
2022-05-16 23:28   ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512074321.2090073-1-davemarchevsky@fb.com \
    --to=davemarchevsky@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=iii@linux.ibm.com \
    --cc=kernel-team@fb.com \
    --cc=riel@surriel.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.