mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, <bpf@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>
Subject: Re: [PATCH bpf-next 1/3] bpf: Move bpf_arch_text_invalidate() out of pack_mutex
Date: Thu, 03 Dec 2026 03:38:51 +0000	[thread overview]
Message-ID: <DNAS9J70GX93.1CVY6I5L2V9I2@gmail.com> (raw)
In-Reply-To: <8eca5da12269d64986653a069f02f07fc15720eb.1796223449.git.xukuohai@huawei.com>

On Wed, Dec 02, 2026 at 07:13 AM Xu Kuohai <xukuohai@huaweicloud.com> wrote:
>  	if (WARN_ONCE(!pack, "bpf_prog_pack bug\n"))
>  		goto out;
> +	mutex_unlock(&pack_mutex);

> +	mutex_lock(&pack_mutex);

can we invalidate before the first mutex_lock() ?
Then a free takes pack_mutex once.
Puranjay posted the same fix in that form, but it slipped through the cracks :(
https://lore.kernel.org/bpf/20261103142856.463063-3-puranjay@kernel.org/

On top of the series, core.c compiles on x86-64, but I didn't run it:

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 1ecf398..2a21470 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1454,12 +1454,16 @@ void bpf_prog_pack_free(void *ptr, u32 size)
 	unsigned int nbits;
 	unsigned long pos;
 
-	mutex_lock(&pack_mutex);
 	if (size > BPF_PROG_PACK_SIZE) {
 		bpf_jit_free_exec(ptr);
-		goto out;
+		return;
 	}
 
+	/* The caller owns the chunks until bitmap_clear() */
+	WARN_ONCE(bpf_arch_text_invalidate(ptr, size),
+		  "bpf_prog_pack bug: missing bpf_arch_text_invalidate?\n");
+
+	mutex_lock(&pack_mutex);
 	list_for_each_entry(tmp, &pack_list, list) {
 		if (ptr >= tmp->ptr && (tmp->ptr + BPF_PROG_PACK_SIZE) > ptr) {
 			pack = tmp;
@@ -1469,16 +1473,6 @@ void bpf_prog_pack_free(void *ptr, u32 size)
 
 	if (WARN_ONCE(!pack, "bpf_prog_pack bug\n"))
 		goto out;
-	mutex_unlock(&pack_mutex);
-
-	/*
-	 * The bits of this chunk are still set, so nobody can take the chunk
-	 * or free the pack, no need to hold the mutex.
-	 */
-	WARN_ONCE(bpf_arch_text_invalidate(ptr, size),
-		  "bpf_prog_pack bug: missing bpf_arch_text_invalidate?\n");
-
-	mutex_lock(&pack_mutex);
 
 	nbits = BPF_PROG_SIZE_TO_NBITS(size);
 	pos = ((unsigned long)ptr - (unsigned long)pack->ptr) >> BPF_PROG_CHUNK_SHIFT;

This fix doesn't depend on patches 2 and 3.

  reply	other threads:[~2026-12-03  3:38 UTC|newest]

Thread overview: 8+ 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-03  3:38   ` Alexei Starovoitov [this message]
2026-12-03  7:16     ` 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:13 ` [PATCH bpf-next 3/3] bpf: Move branch predictor flush out of pack_mutex Xu Kuohai
2026-12-03  3:40   ` Alexei Starovoitov
2026-12-03 11:05     ` Xu Kuohai

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=DNAS9J70GX93.1CVY6I5L2V9I2@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=xukuohai@huaweicloud.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®