From: Quentin Monnet <quentin@isovalent.com>
To: Eduard Zingerman <eddyz87@gmail.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Alan Maguire <alan.maguire@oracle.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Kernel Team <kernel-team@fb.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [RFC v3 0/3] use preserve_static_offset in bpf uapi headers
Date: Wed, 3 Jan 2024 13:06:03 +0000 [thread overview]
Message-ID: <525d324d-bc06-469f-8533-33b2da35f3df@isovalent.com> (raw)
In-Reply-To: <e912efb0f87d91037c8b33ad1821f17fd7b3ddde.camel@gmail.com>
2023-12-20 20:19 UTC+0000 ~ Eduard Zingerman <eddyz87@gmail.com>
> On Wed, 2023-12-20 at 11:20 -0800, Alexei Starovoitov wrote:
>> On Wed, Dec 20, 2023 at 5:34 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
>>> This RFC does not handle type pt_regs used for kprobes/
>>> This type is defined in architecture specific headers like
>>> arch/x86/include/asm/ptrace.h and is hidden behind typedef
>>> bpf_user_pt_regs_t in include/uapi/asm-generic/bpf_perf_event.h.
>>> There are two ways to handle struct pt_regs:
>>> 1. Modify all architecture specific ptrace.h files to use __bpf_ctx;
>>> 2. Add annotated forward declaration for pt_regs in
>>> include/uapi/asm-generic/bpf_perf_event.h, e.g. as follows:
>>>
>>> #if __has_attribute(preserve_static_offset) && defined(__bpf__)
>>> #define __bpf_ctx __attribute__((preserve_static_offset))
>>> #else
>>> #define __bpf_ctx
>>> #endif
>>>
>>> struct __bpf_ctx pt_regs;
>>>
>>> #undef __bpf_ctx
>>>
>>> #include <linux/ptrace.h>
>>>
>>> /* Export kernel pt_regs structure */
>>> typedef struct pt_regs bpf_user_pt_regs_t;
>>>
>>> Unfortunately, it might be the case that option (2) is not sufficient,
>>> as at-least BPF selftests access pt_regs either via vmlinux.h or by
>>> directly including ptrace.h.
>>>
>>> If option (1) is to be implemented, it feels unreasonable to continue
>>> copying definition of __bpf_ctx macro from file to file.
>>> Given absence of common uapi exported headers between bpf.h and
>>> bpf_perf_event.h/ptrace.h, it looks like a new uapi header would have
>>> to be added, e.g. include/uapi/bpf_compiler.h.
>>> For the moment this header would contain only the definition for
>>> __bpf_ctx, and would be included in bpf.h, nf_bpf_link.h and
>>> architecture specific ptrace.h.
>>>
>>> Please advise.
>>
>> I'm afraid option 1 is a non starter. bpf quirks cannot impose
>> such heavy tax on the kernel.
>>
>> Option 2 is equally hacky.
>>
>> I think we should do what v2 did and hard code pt_regs in bpftool.
>
> I agree on (1).
> As for (2), I use the same hack in current patch for bpftool to avoid
> hacking main logic of BPF dump, it works and is allowed by C language
> standard (albeit in vague terms, but example is present).
> Unfortunately (2) does not propagate to vmlinux.h.
>
> Quentin, Alan, what do you think about hard-coding only pt_regs?
It sounds like an acceptable compromise.
Quentin
prev parent reply other threads:[~2024-01-03 13:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 13:34 [RFC v3 0/3] use preserve_static_offset in bpf uapi headers Eduard Zingerman
2023-12-20 13:34 ` [RFC v3 1/3] bpf: Mark virtual BPF context structures as preserve_static_offset Eduard Zingerman
2023-12-20 13:34 ` [RFC v3 2/3] bpftool: add attribute preserve_static_offset for context types Eduard Zingerman
2023-12-20 13:34 ` [RFC v3 3/3] selftests/bpf: verify bpftool emits preserve_static_offset Eduard Zingerman
2023-12-20 19:20 ` [RFC v3 0/3] use preserve_static_offset in bpf uapi headers Alexei Starovoitov
2023-12-20 20:19 ` Eduard Zingerman
2024-01-03 13:06 ` Quentin Monnet [this message]
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=525d324d-bc06-469f-8533-33b2da35f3df@isovalent.com \
--to=quentin@isovalent.com \
--cc=alan.maguire@oracle.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox