From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796269134; b=fqEQkum87OIgKZ1U5x2EsKyTQW7p0021IQmrV0EYUfBXHYGUSKwhYHJgo8oVIpbFg0Lo jOEvBVXysbswv3izaRkCEBhonfY+zq4F6MX+3hP7ygp8NKyflTfR1C5OqsKwaHNyRvqeS GYmehPwHlpG4PQUCb+DE2UjUN6Uwegm1LVObugouJlEWRsEwUAc1Pz1wTb9L9rlTUWEoh RWQdDPE7gJZpMTmyVbCNnOtCYCNtlQ4cHTljRZBB21Dzcskw9srDwQ1CRq4VZNU6t4Vfb B/ksqMQKIA9WaybulxLL/uH69Dmo297Oih4cU6WVSrsxsifMYAGsvAGSmlNa5DkixCw== 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=mUk5AUcn6V6k2sQibNnw4nFjPAgCw+YtNcpsaR7ne91pDzgItk33WCXlryCqxyOMVsqK u6x7UJaDYfYGvvoI/fYS4oN1iSfdvklb3/rXLbd2lACl8mBZP1rmcG+KYWbVbR7JiR9dV SIOZt9bgT5vApp1/lreBS4RQY+RbhW0WBDL4CKedXgmbO4Z4fjksW2M8hELUwIXajsW0o 6V8f6wHpHHT3oRvarkP+GrLMU5ivl+UNUQXMJWlTeZ0ttHxleWN4/mPIjrcbNKTHZ3mqa LgkmEQbHFPnsR4XHbPkOnSBaovN+WJ7KD2Pan3Hud5ALcZhz5Po8OwyJsuzBkze3sKw== 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.170 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 27CA4606A32C for ; Thu, 3 Dec 2026 03:38:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 27CA4606A32C 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-f170.google.com with SMTP id 41be03b00d2f7-cde0daf3a2aso6067528a12.3 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=EwciVaLd05Bq5smJCiNfAE5+rCSPD5ojoS6rP7u54vNMMuoT/baTqb7RZ2EzoaFqIj a+vLgozeH4ZCCtmpZTHFHwJpiDLVG9PpzLc/TwULd7B8ankhZ3VYDYHueYQwSNuljsdt Z8Asbp2tkgmhr2n7qD+r7H96mPh41w6cYBeNuYs/cc7eqeHWfEuZn4yVtta4OknNKIGz n4tjH6eXdzw0WsYaQACCAxlmg8ocYZxFICkbxAph7kBxqSYNQ1W52ZyC3VHmLiyYvitU anEx+yQrMRezfqZJ6sMCAfX/0HG0aM4orH7aSP/7ocTujf9ppeKkuhJOsKeYFEemNxfo 2aSw== X-Forwarded-Encrypted: i=1; AL+hErHohQvzOX/wG2BpCSP3ODI0XyQNMIMMD20IRQ2JZ9VMWZWDQYjVs3HYTYx6JJ1XWx9HTjR2ggG4i5x7gNk=@vger.kernel.org X-Gm-Message-State: APuU4Z8INjHDmDR00ihO7Eg6UY4rvrJPuxBUTRYgwiYBDV0ivuOBhG9I 2U6V5xjkliZtyICexGihHFila3LnNi5W/ho7fjYn40K1lFOAkuzeIqV4 X-Gm-Gg: AZFdTZdWVgKEHSP0PCVFOuv5kba0OOiYI5CQLULeVsxScyGaYvurDpMW2gW5cacBsnX aeaGgkznRu59bXAYcVGoXlphETUYCaNU2Y63luxrE6iv12AyVgvUl91w1FU2cpHfZZIvH1ANe84 PfNMscwdT1AnDcZn8JR8716P7LCHjiRkjC0xJaYpnK4kl1dJETfFF2/RWjY2bf8+pyybF3GGSwy Gw4GObmJnHjaVuxL42XUD/FM9mW9t70A2C90Rla915qUm/IBCJ3e7j2aWpoGmE1i14eZeDk/TqA wt0F6ploe4vbp+AzPTLIj0wGlPV3JAB727uMkW+JpU1957Y+Pr4Oe5vwHPJVWQOmCTkTsUZ78sE wcJfyM6lm/d4yB1b0ijVVGe2p4FZRZ5UbqPdgjFnU/3jlm93fC5pREnf3dKadNKFoyP0f5OFy6/ 79iA7qckdwfpwiZaKoEDaGbwMXGmbllo7wlYEh4vZtEHqGk9Q1vJ+EZYoCKCQ/09Y5xazIgsZiU 3+aT+quyst4JForzEc54SiCrKkICoAanystxK/hC2f9rILwH/d7ZUrIVnKIagdpNiu5x+eMyC7n 4ts2udckp7zd0wpBdoLK0SqXAYwXBEa8ZNxXHV0gPXiALX50JcIalRcf9bP8JLwPpFzFct7eDn3 yXuYie8ss7Wtkle0ORyt/pa3iCVV1AaW+M/2F9mCrTd/LIQ9xmid+qD8= 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: linux-kernel@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.