From: Andrea Righi <arighi@nvidia.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Josh Don <joshdon@google.com>,
Vineeth Pillai <vineethrp@google.com>,
Balbir Singh <balbirs@nvidia.com>,
Shameer Kolothum <skolothumtho@nvidia.com>,
Himadri Chhaya-Shailesh <himadrics@protonmail.com>,
NchangRoy <royfru44@gmail.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 0/5] bpf: Expose pinned arenas as sized bpffs files
Date: Mon, 19 Oct 2026 10:44:38 +0200 [thread overview]
Message-ID: <atXYdpDukXObjE69@gpd4> (raw)
In-Reply-To: <DM6HVNSP3USV.AJSWS289Z3I9@gmail.com>
Hi Alexei,
On Fri, Oct 16, 2026 at 07:03:55PM +0000, Alexei Starovoitov wrote:
> On Sun, Oct 11, 2026 at 12:45 AM Andrea Righi <arighi@nvidia.com> wrote:
> > The guest scheduler can create its own arena and allocate pages from
> > that NUMA node. Those guest physical pages are backed by the host arena,
> > so host and guest BPF programs can access the same memory through their
> > respective arenas.
>
> in addition to what Josh said...
>
> That node is ordinary RAM for the guest.
> When the guest scheduler exits arena_map_free() does __free_page() and
> the page goes back to the guest's buddy allocator. Nobody tells the host.
> The host prog keeps writing at that offset into whatever the guest
> allocates there next.
> NO_FREE in the guest doesn't help. It covers the kfunc only.
Right, that's a design problem, NO_FREE only protects the host side, the
guest side lifetime is not covered at all, so the host can corrupt guest
memory after the guest scheduler exits.
>
> Patch 5 needs a 16M node (256M on ppc) to get one page into the guest
> arena. Arena is 4G at most and it's one arena per prog, so that's
> 256 guests per host scheduler.
Agreed, the memory block granularity makes the NUMA node approach
wasteful and doesn't scale.
>
> The NUMA node is a way to avoid teaching arena to use pages that it
> didn't allocate. I think that's the missing piece in either model:
> host allocates -> guest arena is populated from a BAR,
> guest allocates -> host arena is populated from pinned guest pages.
> As Josh said the BAR is needed for the doorbell anyway.
>
> If arena can do that, can the host side take the pages from memfd
> with memfd_pin_folios() like udmabuf does ?
> VMM can map memfd at any address and offset already.
> Then no need for NO_FREE, EXPORT, sized file in bpffs, 2nd kind of vma
> in arena, etc.
Agreed, this is much simpler and it covers both models. Mapping the BAR
linearly into the guest arena also gives both sides a fixed rendezvous
point (offset 0 of the memfd is a known address in both arenas), which
removes the out-of-band offset discovery that the selftest does via
/proc/self/pagemap.
I'll drop NO_FREE, EXPORT and the bpffs changes and rework the series
around arena_map_ext_pages() + bpf_arena_import_memfd(), starting from
your patch.
Essentially the plan is:
1) host: bpf_arena_import_memfd() (based on your patch),
2) guest: populate the guest arena from a BAR using
arena_map_ext_pages() (in QEMU, ivshmem-plain with the same memfd
as memory backend, so no VMM changes),
3) convert the two-guest selftest to this path.
>
> The loader does memfd_create() or opens a file in tmpfs, calls
> bpf_arena_import_memfd(&arena, addr, cnt, fd, off) from a syscall prog
> and gives the same file to QEMU the way patch 5 does with the pin.
> The imported pages stay until the arena is freed, so it's NO_FREE for
> the shared part only. libarena keeps working in the rest of the arena.
That's fine for a single long-running guest, but with VMs coming and
going the host arena would only grow (this was also Josh's concern about
the high watermark). Would it be ok with an explicit release of an
imported range (clear the ptes, flush, set rt_own back, unpin the
folios)? A BPF prog touching a released range would then hit the usual
arena fault handling, like any unallocated page.
> arena_map_ext_pages() is what a BAR in the guest or pinned guest pages
> in the pvsched model would call.
For the BAR case the guest needs struct pages for the BAR memory
(memremap_pages() / ZONE_DEVICE or similar) to go through
arena_map_ext_pages(). I'll look into the least invasive way to do that.
> What is missing: user space has to mmap the memfd to see these pages.
> The arena vma gives SIGBUS there.
I think that's acceptable for the hint channel: the userspace side of
the scheduler can mmap the memfd (or the BAR in the guest) separately
and use offsets.
Thanks,
-Andrea
next prev parent reply other threads:[~2026-10-19 8:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 22:45 Andrea Righi
2026-10-10 22:45 ` [PATCH 1/5] bpf: Add an arena flag to retain allocated pages Andrea Righi
2026-10-10 22:45 ` [PATCH 2/5] bpf: Expose pinned arenas as sized bpffs files Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
2026-10-10 22:45 ` [PATCH 3/5] docs/bpf: Document pinned arena file mappings Andrea Righi
2026-10-10 23:19 ` bot+bpf-ci
2026-10-10 22:45 ` [PATCH 4/5] selftests/bpf: Test " Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
2026-10-10 22:46 ` [PATCH 5/5] selftests/bpf: Test two-way arena access with two guests Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
2026-10-15 17:50 ` [PATCH bpf-next 0/5] bpf: Expose pinned arenas as sized bpffs files Josh Don
2026-10-19 8:17 ` Andrea Righi
2026-10-16 19:03 ` Alexei Starovoitov
2026-10-16 19:52 ` Andrii Nakryiko
2026-10-18 0:52 ` Alexei Starovoitov
2026-10-19 8:49 ` Andrea Righi
2026-10-19 16:19 ` Andrii Nakryiko
2026-10-19 16:58 ` Alexei Starovoitov
2026-10-19 8:44 ` Andrea Righi [this message]
2026-10-19 19:32 ` Alexei Starovoitov
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=atXYdpDukXObjE69@gpd4 \
--to=arighi@nvidia.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=balbirs@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=himadrics@protonmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshdon@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=royfru44@gmail.com \
--cc=skolothumtho@nvidia.com \
--cc=song@kernel.org \
--cc=vineethrp@google.com \
--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
all inboxes | Powered by JetHome®