From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/3] bpf: Change dirty tracking from packs to chunks
Date: Wed, 02 Dec 2026 15:55:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-246162@kernel.org> (raw)
In-Reply-To: <f827fa79d579e2eec234a0ae031ba917f8539f69.1796223449.git.xukuohai@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: stale dirty_map read when !arch_flush_needed in
bpf_prog_pack_alloc()
--
commit 811051fe76077420fa826110b71c4df5c0c494fd
Author: Xu Kuohai <xukuohai@huawei.com>
bpf: Change dirty tracking from packs to chunks
This commit switches predictor dirty tracking in the BPF prog pack
allocator from per-pack to per-chunk using a dirty_map bitmap on each
pack.
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 63bc7e7b95409..920c8cdaf2679 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
[ ... ]
> @@ -1304,16 +1345,23 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns, bool
> if (!static_branch_unlikely(&bpf_pred_flush_enabled))
> goto found_free_area;
> /*
> - * cBPF reuse of a dirty pack triggers a flush, so prefer a
> - * clean pack for cBPF. eBPF never flushes, so steer it to a
> - * dirty pack and keep clean packs free for cBPF.
> + * cBPF reuse of a dirty chunk triggers a flush, so prefer
> + * clean chunks for cBPF. eBPF never flushes, so steer it to
> + * dirty chunks and keep clean chunks free for cBPF.
> */
> - if (was_classic ^ pack->arch_flush_needed)
> + dirty_pos = find_next_bit(pack->dirty_map, pos + nbits, pos);
> + if (was_classic ^ (dirty_pos < pos + nbits))
> goto found_free_area;
> +
> if (!fallback_pack) {
> fallback_pack = pack;
> fallback_pos = pos;
> }
> +
> + /* Find clean chunks for cBPF or dirty chunks for eBPF */
> + pos = bpf_pack_find_area(pack, dirty_pos, nbits, was_classic);
> + if (pos < BPF_PROG_CHUNK_COUNT)
> + goto found_free_area;
> }
[Severity: Medium]
Does consulting pack->dirty_map here without checking
pack->arch_flush_needed misclassify clean packs that still hold stale
dirty bits?
When a flush runs, it sets p->arch_flush_needed = false across pack_list
without clearing p->dirty_map, deferring bitmap_zero() until the next
bpf_prog_pack_free() on each pack. Until a free happens in that pack,
pack->dirty_map retains stale 1 bits (including all bits set to 1 from
alloc_new_pack()).
If an earlier pack in pack_list has only dirty free chunks and becomes
fallback_pack, while a later pack has arch_flush_needed == false with
stale bits in dirty_map, a cBPF allocation treats the clean pack as
dirty, skips it, falls back to the dirty fallback_pack, and triggers an
unnecessary bpf_arch_pred_flush(). For eBPF, the stale bits make the
clean pack look dirty, steering eBPF allocations into clean packs instead
of saving them for cBPF. Checking pack->arch_flush_needed before
inspecting pack->dirty_map (treating all chunks in the pack as clean when
!pack->arch_flush_needed) would avoid acting on the stale bitmap.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796223449.git.xukuohai@huawei.com?part=2
next prev parent reply other threads:[~2026-12-02 15:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:13 [PATCH bpf-next 0/3] bpf: Move IPIs out of pack_mutex and reduce IBPB flushes Xu Kuohai
2026-12-02 15:13 ` [PATCH bpf-next 1/3] bpf: Move bpf_arch_text_invalidate() out of pack_mutex Xu Kuohai
2026-12-02 15:13 ` [PATCH bpf-next 2/3] bpf: Change dirty tracking from packs to chunks Xu Kuohai
2026-12-02 15:55 ` sashiko-bot [this message]
2026-12-02 15:13 ` [PATCH bpf-next 3/3] bpf: Move branch predictor flush out of pack_mutex Xu Kuohai
2026-12-02 15:57 ` 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-246162@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xukuohai@huaweicloud.com \
/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