Article View: linux.kernel.netdev
Article #4207[PATCH bpf-next 28/38] bpf: Free what map_free() unlinks for sleepable readers
From: Alexei Starovoitov
Date: Sat, 17 Oct 2026 01:24
Date: Sat, 17 Oct 2026 01:24
53 lines
10507 bytes
10507 bytes
From: Josef Bacik <josef@toxicpanda.com>
bpf_local_storage_map_free() takes the elements of the map off the lists
of their owners, which are alive, and frees them, and the storage of an
owner with its last element, behind a plain RCU grace period. Nobody uses
the map any more, but the other maps of these owners are in use. A
sleepable program calls the get and delete helpers under
rcu_read_lock_trace() only. While it walks the list of an owner for its
own map, or is about to lock the storage, the element it stands on, or the
storage, can be freed under it.
Whatever else takes an element off the list of a live owner frees it
behind an RCU Tasks Trace grace period, which implies a plain one. Do so
in bpf_local_storage_map_free() as well. It waits for these callbacks
before it frees the map.
This does not help a sleepable program that hands an owner to the helpers
which nobody holds, and which may be gone by then.
Fixes: dcf456c9a095 ("bpf: Fix usage of trace RCU in local storage.")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
kernel/bpf/bpf_local_storage.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 7721834e4bff..f234f671e75f 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -431,13 +431,17 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,
* then freed after an RCU grace period. However, if destroy() and map_free() are
* racing or rqspinlock returns errors in unlikely situations (unlink != 2), free
* the selem only after both map_free() and destroy() see the selem.
+ *
+ * The owner that map_free() takes an selem from is alive: sleepable code, which
+ * is in no RCU read side critical section, may be walking its list for another
+ * map.
*/
if (unlink == 2 ||
atomic_cmpxchg(&selem->state, SELEM_UNLINKED, SELEM_TOFREE) == SELEM_UNLINKED)
- bpf_selem_free(selem, true);
+ bpf_selem_free(selem, !in_map_free);
if (free_storage)
- bpf_local_storage_free(local_storage, true);
+ bpf_local_storage_free(local_storage, !in_map_free);
}
void __bpf_local_storage_insert_cache(struct bpf_local_storage *local_storage,
--
2.55.0
Technical Details
Message-ID:
<20261017012451.364800-20-alexei.starovoitov@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347614-linux-kernel-netdev=dewy.ruReferences:
<20261017012058.355787-1-alexei.starovoitov@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347614-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next 28/38] bpf: Free what map_free() unlinks for sleepable readers
Date: Sat, 17 Oct 2026 01:24:41 +0000
Organization: Usenet Network
Message-ID: <20261017012451.364800-20-alexei.starovoitov@gmail.com>
References: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2935719"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dzcmG2PJaimIRijOQHz6cC58unM= sha256:3i25n38hfb65eqmiYDGdPtTf5Wa8SlYHRNBpX1QWYRg=
sha1:K4w+Ye9St9TaN2o+Zg4B8B96QtA= sha256:IxsC2FNT68H6s4UmiUZR1UmXr7o7thHVw26rfBzbZNw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 8CBCB11063F; Sat, 17 Oct 2026 04:32:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id UB2CF8uumQSK;
Sat, 17 Oct 2026 04:32:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-347614-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id EF15511064F; Sat, 17 Oct 2026 04:31:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id 418323F726; Sat, 17 Oct 2026 01:31:50 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D135353A6B;
Sat, 17 Oct 2026 01:31:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PS839tpC"
X-Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E1A225771
for <netdev@vger.kernel.org>; Sat, 17 Oct 2026 01:31:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792200707; cv=none; b=PX6uNLWnmcocnQxFTl7yNi6yp09JZ6Y+VukxSvJayA1cb/jUAGyByF5CIhHGfm7AR7IZ83U6NyVYpboC1KZa0H2Wh8Q1vUVeWmHTBmpmrV8m/pu3XlSidRDc3xKgvB2L2cGZbgppX6MFl6DYeODfQGHqsGwS28M9WlXiXziuQ+8=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792200707; c=relaxed/simple;
bh=xHL80ZEn5PAxaypyWxZhEUPjys++jnkou+5URLONSTA=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=atYEU2C2PgzecMxJP28bdxrS154KWEqngt2mYO2dAEaQM/ZvTiH/XEIdvUbLvEzcgy0MEVSzwhNAuLJcjXDWcqcS8f6seoU3+pwTSomubJxusIpZXou7Tcp693Mz0G/c9Ai2TP/PP57M1WpeWucBPeqBRyVnLASSX9SVXlr/rOo=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PS839tpC; arc=none smtp.client-ip=209.85.215.176
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-ca766c1c9ccso223454a12.0
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 18:31:45 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792200705; x=1792805505; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=ls4pTeNyhy+wNW5MbGiVA9pf5BYuGMXuZsBrKPxCtY0=;
b=PS839tpCQ3njfSM0kSXPnOpEHV4SLW1usk2wsJSjz5EM7RNc9g80iM1uRitYgr7cy3
aYnhOVke17eP/J/VtbOcXFcDzfLTEafiMJ4zhne7OqubW1+pMKuLWI431q/Skga4faRO
f61cDf1w7sa8mrSK8YnmF8ag0AWqIXNSoGQOU/DrQggv2g3bKyM9aYC/3pjnS9X4z9oa
VYZuL45JzAaBJ/cjN0qrjbxVeEufj6G0p2vrM8ipLaHMLIE2mz6N/d8UdqIXsTsF3jCf
8Dtld27kyP+Xjy8/kEgjBKeEcO3DqpLTibjeOJg6yLRfjhKh5z0eiTjfLpLQJ+aXANEI
N/ig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792200705; x=1792805505;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=ls4pTeNyhy+wNW5MbGiVA9pf5BYuGMXuZsBrKPxCtY0=;
b=2qY2Q2k4UXiGI+NFnUdCiCJu5vVyIpkR5DiqphIa+b01XIg8A54yYwLiGuy5DKDwK+
JH2HYM07M3QJlzCfcKuceoseuxcoNMTNFKqHyPHpRur0KX9MkBCd3QkIm5VuFCZVSNji
qKOOQwdhAHSNVp8rBUMlOX/tJ63Dv2SCb0Cxnq3/Kkm8qCHftgs+yY4k8A6fLFOFzXl7
39eEsTmVaHvVHR72ye7F1v3Xia7jZ5RJhKp9ilyIAlOWZFd1r5eD8oXofSlwPn9u4+uW
eXRaXCjGZPu2Z1F7VNjomvdoU8WkyA886fRvpWwz95MtUhDcLurD1u0aBhecNJk04sKZ
v3qg==
X-Forwarded-Encrypted: i=1; AKwUvBwsrpzv/T4MAnQ+9pRv201PA52YX3dz3yvJBdCwX2PfVCiE4lMzulqc9/w/1ukJy2A+3/Y/5Uw=@vger.kernel.org
X-Gm-Message-State: AFq9FYIYqCx7fLLmaChK9gNm+aXWLPaihXus1rhSf6pqvHslGxJkt824
pWLlpzzIVQYbksYByxRun9r5PJPqQuDL+oWaQWX852X6yVW+L2R/h/A0
X-Gm-Gg: AYBFou0mhGYuCDlzT9LCF59Rw63hXHMZk+4JCb38UbWO5KJSkXj+Oxte27q5dKhYJUz
QjO7ywbobzzUZ56AlJCu6cg/n3v6LN8iMgjREnbheo/ejHKfRSWYiYBl1G/43cB1LR6sf1wo5vc
Irrkq49oKt/rMnMuCunqbcOt3qo81I+G4BPEVv7TpnlM4bb11HyFi/Hy8uer2oRd91OJJNPPgT+
nD/IgE2NOkgtG4tuQQ5PsUW9p5JekC6Pd1oMV/f/aPM/yuaB1vF7F9ULHYNGXdumfLwXwJNiddM
aecCm9EYDpgN1U1RbcHXBvZWngjAa/ggxnhABqoPuMhVdTSeMYsCd4Fn2DqKpIuAXiWKnN08Okl
2b2wQS6YpUKpIcBLBvvhJ0GhDm4QuhvKp1gVSMOIq6+o5RewpYgQUNDw+Ozmvma7M8nzebbiN+9
rfxTepOLlhxsgz/JvJ/jCDqTG092dCsSjqg1trAACVy6YTDCpeo/32+7x+xHqUM5VoJltFKypUo
dJedMLLDaLt47wkp1Pt5QuC+BGJUneTIA61Dhino5DLezkt1FtBIaREMYh9/enpsp6vPtplDLRs
o/d+0g28beEHIstW7212YPoIGbGYyooAwbbJTjuuLUo=
X-Received: by 2002:a17:90a:c885:b0:3ac:9d14:feb1 with SMTP id 98e67ed59e1d1-3acef4e3427mr1246776a91.43.1792200704582;
Fri, 16 Oct 2026 18:31:44 -0700 (PDT)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.242])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3acc4872861sm6811277a91.7.2026.10.16.18.31.43
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 16 Oct 2026 18:31:43 -0700 (PDT)
X-Cc: daniel@iogearbox.net,
andrii@kernel.org,
eddyz87@gmail.com,
memxor@gmail.com,
netdev@vger.kernel.org,
josef@toxicpanda.com,
mason@kernel.org
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>