BPF List
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: puranjay@kernel.org,bpf@vger.kernel.org
Cc: puranjay@kernel.org,puranjay12@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,memxor@gmail.com,kernel-team@meta.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v7 3/4] bpf: arena: make arena kfuncs any context safe
Date: Mon, 22 Dec 2025 19:27:13 +0000 (UTC)	[thread overview]
Message-ID: <dc0a81fe1debcd43ec9bdb440695bdf6d443a02080229dc1a2b60fa0eed00d18@mail.kernel.org> (raw)
In-Reply-To: <20251222190815.4112944-4-puranjay@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 2855 bytes --]

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 128efb68d47b..55d1e15725c7 100644

[ ... ]

> +static void arena_free_worker(struct work_struct *work)
> +{
> +	struct bpf_arena *arena = container_of(work, struct bpf_arena, free_work);
> +	struct llist_node *list, *pos, *t;
> +	struct arena_free_span *s;
> +	u64 arena_vm_start, user_vm_start;
> +	struct llist_head free_pages;
> +	struct page *page;
> +	unsigned long full_uaddr;
> +	long kaddr, page_cnt, pgoff;
> +	unsigned long flags;
> +
> +	if (raw_res_spin_lock_irqsave(&arena->spinlock, flags)) {
> +		schedule_work(work);
> +		return;
> +	}
> +
> +	init_llist_head(&free_pages);
> +	arena_vm_start = bpf_arena_get_kern_vm_start(arena);
> +	user_vm_start = bpf_arena_get_user_vm_start(arena);
> +
> +	list = llist_del_all(&arena->free_spans);
> +	llist_for_each(pos, list) {
> +		s = llist_entry(pos, struct arena_free_span, node);
> +		page_cnt = s->page_cnt;
> +		kaddr = arena_vm_start + s->uaddr;
> +		pgoff = compute_pgoff(arena, s->uaddr);
> +
> +		/* clear ptes and collect pages in free_pages llist */
> +		apply_to_existing_page_range(&init_mm, kaddr, page_cnt << PAGE_SHIFT,
> +					     apply_range_clear_cb, &free_pages);
> +
> +		range_tree_set(&arena->rt, pgoff, page_cnt);
> +	}
> +	raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
> +
> +	/* Iterate the list again without holding spinlock to do the tlb flush and zap_pages */
> +	llist_for_each_safe(pos, t, list) {
> +		s = llist_entry(pos, struct arena_free_span, node);
> +		page_cnt = s->page_cnt;
> +		full_uaddr = user_vm_start + s->uaddr;
                          ^^^^^^^^^^^^^^^^^^^^^^^

Is there a missing clear_lo32() call here? In arena_free_pages() the
sleepable path computes full_uaddr as:

    full_uaddr = clear_lo32(arena->user_vm_start) + uaddr;

But arena_free_worker() computes it as:

    full_uaddr = user_vm_start + s->uaddr;

Since s->uaddr is already the lower 32 bits (set from masked uaddr in
arena_free_pages()), and user_vm_start includes its own lower 32 bits,
this appears to produce the wrong address. For example, if user_vm_start
is 0x7f7d26200000 and s->uaddr is 0x26200000, this would give
0x7f7d4c400000 instead of the correct 0x7f7d26200000.

Should this be:

    full_uaddr = clear_lo32(user_vm_start) + s->uaddr;

to match the sleepable path?

> +		kaddr = arena_vm_start + s->uaddr;
> +
> +		/* ensure no stale TLB entries */
> +		flush_tlb_kernel_range(kaddr, kaddr + (page_cnt * PAGE_SIZE));
> +
> +		/* remove pages from user vmas */
> +		zap_pages(arena, full_uaddr, page_cnt);
> +
> +		kfree_nolock(s);
> +	}

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/20441598118

  reply	other threads:[~2025-12-22 19:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-22 19:08 [PATCH bpf-next v7 0/4] Remove KF_SLEEPABLE from arena kfuncs Puranjay Mohan
2025-12-22 19:08 ` [PATCH bpf-next v7 1/4] bpf: arena: populate vm_area without allocating memory Puranjay Mohan
2025-12-22 19:08 ` [PATCH bpf-next v7 2/4] bpf: arena: use kmalloc_nolock() in place of kvcalloc() Puranjay Mohan
2025-12-22 19:08 ` [PATCH bpf-next v7 3/4] bpf: arena: make arena kfuncs any context safe Puranjay Mohan
2025-12-22 19:27   ` bot+bpf-ci [this message]
2025-12-22 19:38     ` Puranjay Mohan
2025-12-22 19:08 ` [PATCH bpf-next v7 4/4] selftests: bpf: test non-sleepable arena allocations Puranjay Mohan

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=dc0a81fe1debcd43ec9bdb440695bdf6d443a02080229dc1a2b60fa0eed00d18@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=puranjay12@gmail.com \
    --cc=puranjay@kernel.org \
    --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