From: sashiko-bot@kernel.org
To: "Eric Curtin" <ericcurtin17@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RFC PATCH v2 09/43] bpf: Do not embed page-aligned members in struct bpf_ringbuf
Date: Wed, 02 Dec 2026 02:34:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-244669@kernel.org> (raw)
In-Reply-To: <20261201015240.1017259-10-ericcurtin17@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bpf: unreferenced enum page_size_enum omitted from vmlinux
BTF
- [Medium] bpf: pointer conversion in struct bpf_ringbuf breaks
check_ringbuf() selftest
--
commit 459a31118167667b9c22651aaa45f157fe2327bb
Author: Ryan Roberts <ryan.roberts@arm.com>
bpf: Do not embed page-aligned members in struct bpf_ringbuf
This commit replaces page-aligned embedded fields in struct bpf_ringbuf
with pointers to the position and data pages, and updates enum
page_size_enum in kernel/bpf/core.c for boot-time page size selection.
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 6742f5be86586..dc3d62671a9dc 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -97,9 +97,16 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
> return NULL;
> }
>
> -/* tell bpf programs that include vmlinux.h kernel's PAGE_SIZE */
> +/*
> + * tell bpf programs that include vmlinux.h kernel's PAGE_SIZE. __PAGE_SIZE is
> + * only known for compile-time PAGE_SIZE builds, the limits are always known.
> + */
> enum page_size_enum {
> + __PAGE_SIZE_MIN = PAGE_SIZE_MIN,
> + __PAGE_SIZE_MAX = PAGE_SIZE_MAX,
> +#if PAGE_SIZE_MIN == PAGE_SIZE_MAX
> __PAGE_SIZE = PAGE_SIZE
> +#endif
> };
>
> struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flags)
> @@ -108,7 +115,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag
> struct bpf_prog_aux *aux;
> struct bpf_prog *fp;
>
> - size = round_up(size, __PAGE_SIZE);
> + size = round_up(size, PAGE_SIZE);
> fp = __vmalloc(size, gfp_flags);
> if (fp == NULL)
> return NULL;
[Severity: Medium]
Does replacing __PAGE_SIZE with PAGE_SIZE here cause enum page_size_enum
to be omitted from vmlinux BTF?
fe5064158c56 ("bpf: Tell bpf programs kernel's PAGE_SIZE") used
__PAGE_SIZE in bpf_prog_alloc_no_stats() to keep the enum referenced so
the compiler emits it into DWARF debug info. With no remaining reference
to enum page_size_enum or its enumerators in kernel/bpf/core.c, the
compiler strips the unused enum and pahole does not emit __PAGE_SIZE_MIN,
__PAGE_SIZE_MAX or __PAGE_SIZE into vmlinux BTF or vmlinux.h, breaking
in-tree BPF programs and selftests that rely on __PAGE_SIZE. Adding
BTF_TYPE_EMIT(enum page_size_enum) in bpf_prog_alloc_no_stats() would
preserve the BTF type emission.
> diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
> index 447863ece26a3..9f9fab60e0c90 100644
> --- a/kernel/bpf/ringbuf.c
> +++ b/kernel/bpf/ringbuf.c
[ ... ]
> @@ -72,11 +72,11 @@ struct bpf_ringbuf {
> * validate each sample to ensure that they're correctly formatted, and
> * fully contained within the ring buffer.
> */
> - unsigned long consumer_pos __aligned(PAGE_SIZE);
> - unsigned long producer_pos __aligned(PAGE_SIZE);
> - unsigned long pending_pos;
> - unsigned long overwrite_pos; /* position after the last overwritten record */
> - char data[] __aligned(PAGE_SIZE);
> + unsigned long *consumer_pos;
> + unsigned long *producer_pos;
> + unsigned long *pending_pos;
> + unsigned long *overwrite_pos; /* position after the last overwritten record */
> + char *data;
> };
[Severity: Medium]
Does changing consumer_pos and producer_pos to pointers break the map_ptr
BPF selftest?
tools/testing/selftests/bpf/progs/map_ptr_kern.c still declares them as
unsigned long scalars and compares them directly:
tools/testing/selftests/bpf/progs/map_ptr_kern.c:check_ringbuf() {
...
rb = ringbuf->rb;
VERIFY(rb);
VERIFY(rb->consumer_pos == 0);
VERIFY(rb->producer_pos == 128 + BPF_RINGBUF_HDR_SZ);
...
}
Because the kernel BTF types of consumer_pos and producer_pos are now
BTF_KIND_PTR rather than BTF_KIND_INT, CO-RE field relocation fails when
loading map_ptr_kern.c, and check_ringbuf() needs to dereference the
pointers via bpf_core_read() or bpf_probe_read_kernel().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201015240.1017259-1-ericcurtin17@gmail.com?part=9
next prev parent reply other threads:[~2026-12-02 2:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 09/43] bpf: Do not embed page-aligned members in struct bpf_ringbuf Eric Curtin
2026-12-02 2:34 ` sashiko-bot [this message]
2026-12-01 10:41 ` [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Lorenzo Stoakes (ARM)
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=sashiko-outbox-244669@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=ericcurtin17@gmail.com \
--cc=sashiko-reviews@lists.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