Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796269134; b=PELvbEuS73jx1+R5mDMDexTiAxamff/L67H+4Oq5+XB9+1qyIEE2zZjfO7+LZY8ntl3d Na0ZY1wIAsad45WX1/CH6wogaqeX5ulMXkHu0bV5bTWlYE34YHCq4E+1GeIZcU42xOloF eEc4ju8WuG2hs58/doEwvuuHRjvDDEoMsrK0SACOaf7pCCVb5M+Vnh1ZcAeM9j0C+BV1E jVOUdu7TrUwd9HeW+sj7z8gkfXauigexI82QFEbCRwKUvOtyUFof9/omGKlTnx7ly7IRh AQJwNaC7nXS/IOlhZSB5fuEOdtszGWXhzqlpV6f4mJgg8EVyjI4Ebk9g0MSmkwCd9Bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269134; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Content-Type:Date:Message-Id:Cc:Subject:From:To:In-Reply-To: References:Content-Transfer-Encoding:MIME-Version; bh=SJRvK0vNwCGOZhURpa7MMdGPseQj4RxYNWlKKtxViN8=; b=gE63jUB67NTxl8BOVEW7oDZO1Dl7V7I705L9B7I5E3TVQqBDkuI05g2T5r9SDe2CuucS 9cHN57DNH8wGEXj/SDXlpzwkD6faK0vbuA87FPK1fn9hovNB3U6Zb/PbOrmqh0JE6yEl+ I7081XgxAKr21tHTg+KK/tklk9UEjMvY8q072phUjOp7ZuL79UPiCI+jRZi4ji7Qg+mqg h+ad8mtHdDNMMsmcj8+IhJxaTLoFbydYSBuPzW7IvHWKPiZqcNY1JgMjcmJKLYOL+6hZ2 5O2N7TuVAvuJgucNqW+F4D+Axmn351ZztZvmvSiv/WqznsYVu9S9O9+siM1ZBqR9KHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Pj25nhEK; arc=none smtp.remote-ip=209.85.215.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D9B606A322 for ; Thu, 3 Dec 2026 03:38:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 25D9B606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Pj25nhEK Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cd61cef87f1so6958877a12.0 for ; Wed, 02 Dec 2026 19:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796269133; x=1796873933; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=SJRvK0vNwCGOZhURpa7MMdGPseQj4RxYNWlKKtxViN8=; b=Pj25nhEKzLPPCH87e1ZF8vu411bSZrE2Xl6OSpZ/1i8r3KoKu0YZyLyVSLpSykBi2g 5BGYenK/CuJmjoN8oMvzgKDQryX/vXqlbhiFHu4z6tmVvSDwwIwzNGiaXgL7Hxt2FSA0 2T3tHEcfyKboYtmLQWMcVJiGbFbLTJDFIT5cAbPeAou3QAltm+r4RR4JfcPNlAoJOsaj yMTdUH0mnLdD7vVunmmrxZVwS5pkzMjy00P2MjAclT1Bf/34s05O14jT259GayvGez/o IhKP1UisOHVh5vg/ha+CSoeP5iSeQGyYPbmOA/Mo9igcIrNjrYVFEPZXJVZElkPYBBaf aNuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796269133; x=1796873933; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SJRvK0vNwCGOZhURpa7MMdGPseQj4RxYNWlKKtxViN8=; b=bX2WVX112d82WcQQfcIRVl5Vc9BB2fldKvPKkUf1sy7AVQyt9+qxaDzfAePCyb4ya0 vXocIZC3AmtTpUrE+dX4/yVaAeQTZHOhpM6A0h/0YCyqC46Ov2d12wlBsR04YGNRfmF+ fDkf3JgjAPAHT8gF5C6fE0wb+ai0V1gcfd/2Tac9MJArvD+BGt/yUvwPhE3yKha9C5TG dXSoV9nyzlJgvc18VoXCQGlIxuwP4sxi3O0UNHpU7aOoHduOdMcY/5EPmAyjg+ffy0kc S5IC47omQLYyLAsWEHCwSXnNluC3MZKxOHz5zsm7JX8bvcK5M+B+dZ42YcgRBlSAb9rW NaXQ== X-Forwarded-Encrypted: i=1; AL+hErEizMHzfHjb49faFxUBOAqyhZp3z4ofuRV8K5/FIkbrKielpGnGDdiBppm51v9RLxgVSS8=@vger.kernel.org X-Gm-Message-State: APuU4Z/ZMpNKdE2JAmj0vv3SjhneBChXeaXpT9QVaeltTXOyzHzYp8mt i01lgkDgOtwcw0NgFM4Vx5qZHC7h7bUqjIcMYqZn9Kd816mmT42grAfR X-Gm-Gg: AZFdTZeUoDZ1Yg6R0gOIIF8NaIklYTXCexpvxI9MhXMueALI6RnQXmYJ1XFS5sSs7yd chqJT1ApHaw0MzpDal3dGGyDWV76Z5gl9EKzch89dt9Oskxt5BbPWByYjKIWAP1nqUUpFRd2AAy sxx8D1pWmemm6GbW0Lxrq0Xd79AwNTwElTu0GCnri1jTr8Ezz5kf1TesHm+EMViCfhCDEjPpDmi ySKv6tFObOTvebK1zI6ZZz/KkZTQwgf5sJJJotarR62I+8hSFzDQZutxbi3xgJjbehLZ3kz7j9h TGz4WzGdmF+bCETd+QTMu5ajHovEIV1Qed/PJk3mIlWOPAxkUerNSR2vG1O1XdbVAV9ylGNNsKI blUDcDJUOE1i69YqOp6ySDPg3jf6qKVKCbhFEffWmIjtydlqaCesMLDdd9Ymuc4FcfendSs5x7g UR0H/pUAwhSJQV7e8NU+laWQxF8tKcVTq7SKbb93GSRCwsVKmc275DLqjkwpZeJsCU24BKPSp+M n5UDcLSDoxLFvaPELB4cxwyOZfbS8Ci7SrRq75OLgW+9xOpmP55m3aEAkRqdxOOG7Frzpo9MFUl UGfPRupedeOdST5aT3uXxf8yB4/uJF7Glo0bmYFfg9OLJRU0yiFP1Z6k93lhKD++o3hFD2vWRCe T1W9uV3flV+SAja+pNV4AECYZ3iu/xtLT0Pk6oSl4F99LZekDTqS7MUw= X-Received: by 2002:a17:90b:4a88:b0:3b5:29e:11b0 with SMTP id 98e67ed59e1d1-3b5029e14a7mr23086479a91.17.1796269133087; Wed, 02 Dec 2026 19:38:53 -0800 (PST) Received: from localhost ([153.61.198.255]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c79a37b1sm2050300a91.16.2026.12.02.19.38.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 19:38:52 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Thu, 03 Dec 2026 03:38:51 +0000 Message-Id: Cc: "Daniel Borkmann" , "John Fastabend" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" Subject: Re: [PATCH bpf-next 1/3] bpf: Move bpf_arch_text_invalidate() out of pack_mutex From: "Alexei Starovoitov" To: "Xu Kuohai" , , In-Reply-To: <8eca5da12269d64986653a069f02f07fc15720eb.1796223449.git.xukuohai@huawei.com> References: <8eca5da12269d64986653a069f02f07fc15720eb.1796223449.git.xukuohai@huawei.com> Content-Transfer-Encoding: 8bit X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Wed, Dec 02, 2026 at 07:13 AM Xu Kuohai 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.