All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 2/2] bpf: Reduce branch predictor flush and move it out of pack_mutex
Date: Thu, 03 Dec 2026 14:55:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-248028@kernel.org> (raw)
In-Reply-To: <b9e8f1d2f3f419bd739f8b54ba22ccbd677e0a9e.1796304466.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: high-order kzalloc_flex() in alloc_new_pack() exceeds
  costly order
--

commit ffc40b7484a2a688a0e417b3e1c0e5493a3fce98
Author: Xu Kuohai <xukuohai@huawei.com>

bpf: Reduce branch predictor flush and move it out of pack_mutex

This commit switches branch predictor dirty tracking in the BPF prog pack
allocator from per-pack to per-chunk via a dirty_map bitmap, and moves the
predictor flush out from under pack_mutex into a separate pack_flush_mutex.

> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 4c908133011df..143fa134fea55 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c

[ ... ]

> @@ -1235,16 +1242,16 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_ins
>  	struct bpf_prog_pack *pack;
>  	int err;
>  
> -	pack = kzalloc_flex(*pack, bitmap, BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT));
> +	pack = kzalloc_flex(*pack, bitmap, 2 * BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT));
>  	if (!pack)
>  		return NULL;
> +	pack->dirty_map = pack->bitmap + BITS_TO_LONGS(BPF_PROG_CHUNK_COUNT);
>  	pack->ptr = bpf_jit_alloc_exec(BPF_PROG_PACK_SIZE);
>  	if (!pack->ptr)
>  		goto out;
>  	bitmap_zero(pack->bitmap, BPF_PROG_PACK_SIZE / BPF_PROG_CHUNK_SIZE);
> +	bitmap_fill(pack->dirty_map, BPF_PROG_CHUNK_COUNT);

[Severity: Medium]
Can doubling the bitmap array in kzalloc_flex() cause compaction stalls
under pack_mutex or spurious -ENOMEM failures?

On 4 KiB-page systems, each bitmap is 4 KiB * num_possible_nodes().
Doubling it pushes this contiguous GFP_KERNEL allocation past
KMALLOC_MAX_CACHE_SIZE to order-2 pages (16 KiB) on 1-node hosts, and from
order 3 to order 4 (64 KiB, above PAGE_ALLOC_COSTLY_ORDER) on 4-node hosts.

Under physical fragmentation, an order-4 GFP_KERNEL allocation triggers
direct compaction under pack_mutex and fails with -ENOMEM without reclaim
retries, even when bpf_jit_alloc_exec() would succeed via vmalloc order-0
fallback.  This is also paid when bpf_pred_flush_enabled is false.

Both alloc_new_pack() and bpf_prog_pack_free() run in sleepable context
under pack_mutex alongside bpf_jit_free_exec().  Would kvzalloc_flex() and
kvfree() avoid these high-order allocation failures?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796304466.git.xukuohai@huawei.com?part=2

  reply	other threads:[~2026-12-03 14:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:09 [PATCH bpf-next v2 0/2] bpf: Move IPIs out of pack_mutex and reduce IBPB flushes Xu Kuohai
2026-12-03 14:09 ` [PATCH bpf-next v2 1/2] bpf: Invalidate freed prog pack memory without holding pack_mutex Xu Kuohai
2026-12-03 14:09 ` [PATCH bpf-next v2 2/2] bpf: Reduce branch predictor flush and move it out of pack_mutex Xu Kuohai
2026-12-03 14:55   ` sashiko-bot [this message]
2026-12-03 15:15   ` bot+bpf-ci
2026-12-04  3:40 ` [PATCH bpf-next v2 0/2] bpf: Move IPIs out of pack_mutex and reduce IBPB flushes patchwork-bot+netdevbpf

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-248028@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 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.