All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: bpf@vger.kernel.org, sched-ext@lists.linux.dev,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [PATCH 2/5] bpf: Allow importing memfd pages into an arena
Date: Wed, 02 Dec 2026 18:51:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-246494@kernel.org> (raw)
In-Reply-To: <20261202182648.2239421-3-arighi@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: redundant TLB flushes, PTE walks, and VMA zaps in
  arena_free_range()
--

commit d96cf4c4916f7758809e32ec47ce01b90e4ddf99
Author: Andrea Righi <arighi@nvidia.com>

bpf: Allow importing memfd pages into an arena

This commit allows BPF arenas to map externally supplied pages and adds the
bpf_arena_import_memfd() kfunc to pin and import pages from memfd, tmpfs,
or hugetlbfs files into an arena.

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index ebe4ac74f2196..3721001fa1a16 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
[ ... ]
> @@ -1019,9 +1113,12 @@ static int arena_free_range(struct bpf_arena *arena, long uaddr, long page_cnt)
>  	u64 full_uaddr = clear_lo32(arena->user_vm_start) + uaddr;
>  	long kaddr = bpf_arena_get_kern_vm_start(arena) + uaddr;
>  	long pgoff = compute_pgoff(arena, uaddr);
> +	long first = pgoff, last = pgoff + page_cnt - 1;
> +	struct arena_import *imp, *tmp;
>  	struct clear_range_data cdata;
>  	struct llist_node *pos, *t;
>  	LLIST_HEAD(free_pages);
> +	LIST_HEAD(imports);
>  	unsigned long flags;
>  	struct page *page;
>  	int ret;
> @@ -1042,6 +1139,15 @@ static int arena_free_range(struct bpf_arena *arena, long uaddr, long page_cnt)
>  		return 0;
>  	}
>  
> +	/* Imports are released whole, also the ones that are only partly in the range */
> +	while ((imp = arena_import_it_iter_first(&arena->imports, pgoff, pgoff + page_cnt - 1))) {
> +		first = min(first, IMPORT_START(imp));
> +		last = max(last, IMPORT_LAST(imp));
> +		arena_import_it_remove(imp, &arena->imports);
> +		arena_unmap_import(arena, imp);
> +		list_add(&imp->head, &imports);
> +	}
> +
>  	cdata.arena = arena;
>  	cdata.free_pages = &free_pages;
>  	/* clear ptes and collect struct pages */
> @@ -1059,6 +1165,8 @@ static int arena_free_range(struct bpf_arena *arena, long uaddr, long page_cnt)
>  
>  	/* ensure no stale TLB entries */
>  	flush_tlb_kernel_range(kaddr, kaddr + (page_cnt * PAGE_SIZE));
> +	list_for_each_entry(imp, &imports, head)
> +		arena_flush_import(arena, imp);
>  
>  	if (page_cnt > 1)
>  		/* bulk zap if multiple pages being freed */

[Severity: Medium]
Does freeing a range that overlaps imported pages issue redundant TLB
shootdowns, duplicate PTE walks, and unnecessary VMA zaps?

Because the freed range and any overlapping imports form a single
contiguous range [first, last], flushing [kaddr, kaddr + page_cnt *
PAGE_SIZE) and then calling arena_flush_import() for each import issues
overlapping cross-CPU TLB shootdowns instead of one flush across [first,
last].  Similarly, arena_map_destroy() calls arena_flush_import() inside
its per-import loop rather than unmapping all imports and flushing once.

In addition, calling arena_unmap_import() before
apply_to_existing_page_range() walks and clears the overlapping import
PTEs twice under arena->spinlock, and when page_cnt > 1, zap_pages() still
takes arena->lock and mmap_read_lock() across all user VMAs even when
free_pages is empty because only imported pages (which are never faulted
into arena user VMAs) were unmapped.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202182648.2239421-1-arighi@nvidia.com?part=2

  reply	other threads:[~2026-12-02 18:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 18:23 [PATCH v3 bpf-next 0/5] bpf: Import external pages into an arena Andrea Righi
2026-12-02 18:23 ` [PATCH 1/5] dax: Declare inode_dax() in linux/dax.h Andrea Righi
2026-12-02 18:23 ` [PATCH 2/5] bpf: Allow importing memfd pages into an arena Andrea Righi
2026-12-02 18:51   ` sashiko-bot [this message]
2026-12-02 18:23 ` [PATCH 3/5] bpf: Let kernel code import " Andrea Righi
2026-12-02 18:41   ` sashiko-bot
2026-12-02 18:23 ` [PATCH 4/5] bpf: Allow importing device-dax " Andrea Righi
2026-12-02 18:23 ` [PATCH 5/5] selftests/bpf: Test importing " Andrea Righi
2026-12-02 18:42   ` sashiko-bot

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-246494@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@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 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.