From nobody Tue Apr 7 05:41:09 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 8733C18AFE for ; Mon, 16 Mar 2026 11:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773660558; cv=none; b=eZzQUpXVXdypZ1o0e4Xid0TktGZzNp8k151m20d4F4sg4Nxpc8SCaW6b8E1kzdC2f+qJTmN+C05lLtwGLFhsRtiVHikx7bSXLdcUF+TB/SxCtS94/V8GyW6m32AS8cP0RZbnA4px8LXE77DmDip6ZFjdVp/00XTGX5GH801NaRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773660558; c=relaxed/simple; bh=X6NpjHI33SxFJZtV58lEW1oBuVxFCOVbuRWaUibfXDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k2BK6+3IVOCefRVDrGZQ1EXI+ZpNjgPPJYLDaPkshfFp8uvkvQFuJW5BwSNrr+2ndcKL5v4em7zNmmehiytvK3F4EGZzn3tBjUdUwPat0GdKTI3bTp2uZ/HJ8z9LvJmkEelPdLUUb+IZvvev68ep2VXn9w7DySU0++1P70Y+S54= 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=UDIu095M; arc=none smtp.client-ip=209.85.215.174 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.b="UDIu095M" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c739d32b72cso3073256a12.2 for ; Mon, 16 Mar 2026 04:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773660557; x=1774265357; 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; bh=Xcdf8NjYRYFE5tIQAMhp6zvGC7XeDqC/XeKloLYP+1w=; b=UDIu095M5+CBbIhot34O5IZt9TCm4RWOVJCY3mcOFpqfQr2ymU2SO5wrOagnpN2Jr5 Dpo09el23CakLIboz9Ow6mxjyZ8pryC8v2BJu7VHlKLCrTrxUwlqqyxJpvdvIIROo+7e ubq4iXRbNjuVygDfDCHz8xbBAynkTOJgbXn8xu1hArezT3yLzoTAmGNG/iAMv6kieDcW v3FzqsvJagorsYPfufdfVbya/eUOOgapaT3eC8ok0u06pnGZozdXxjDXhZb8R4+MDm7C twfxUa6tIAB0C0bg2lEExfHcqmkXPGUH34o/3hqmCyEVQ5cPztDSEZGcaMLEBcO+7W3e sXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773660557; x=1774265357; 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; bh=Xcdf8NjYRYFE5tIQAMhp6zvGC7XeDqC/XeKloLYP+1w=; b=U9R82Pp+4SKcx2Z5gfqHmGZVtXiiRR0No9ES7ldhgUbpWFlwTfCbPdNsAsQ5Tf08gN d3UlN5P0acVJyCP5e8x4Q8613FlLOHZwCJIQhZ/88vZs2MnzemLE+KNABLmBSGUulJwe A3RLfkFgSBZ1mKKO6VKXogO8vHv4Yn7DFLMeW7xBF1pKylidykb0hgZ+RTXkjmPlChWv +i1lACmgydTjMSG7oJmkZXawlWSCrc/lvTjld0Ut0kqQSSizfGyATiKdnIh0qC6H4Ffd 6h5BtOc8BECMjwEnqEeHqPdl5JFXOKzL89rTg7SKgMs/ahmFrdgnRy4NMEYFBZQoxrJz TM4g== X-Forwarded-Encrypted: i=1; AJvYcCVhvjW2MHBXCRzYUWqyhP2hlf9fus5ZFLvs8RTFDxO4UAsxPApbaSeXIIjCJqDWxDI38dzKLiB0HXFAx4Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+2wApv544hN2epTP2xD1le/Z3ZrszhvowuxrC39alsIw/TECb 8DVaVOUNSue99Je7fDGyoZX0Y60eQFbPnvhL4hF+MjKF57G/XpjLxc69 X-Gm-Gg: ATEYQzwEg4bEvYxbLXKH8/UghvgF9jaDJW6hLREET8WzRi9RQTBlUwgLElY5kncbA4j TFVR2WXB2rHQc9v0cw9wtP33xI9RgxZx6eWtj9fzOs0jxw5zpgmfGhRJyCp9gpJQTP2i2Swt5DX xFYYjuYO6Yy76S3Pg8x8uhnKinfx6fP118EUzGLN9gtrVHFPFS0AN9sVLnwXHfX1dAPZPLK6vbC f9MimwqgAjfj989zVdw6x4V2t7YPM8JYdJROuYzd8xJRDAjA5aEMApynstLSmbcQklw6r/Y6vZs 4qEeOOBhZGpaS2JVJJC4AjsN/+9eJJOApvZ47SSr5n8P3CEzBKWVTKCKz3agg/dC4hhv2WcM9rc bPRLgkyjzP3N3j/EFnyzZZ5KJSC95XT3LjemnbAboEF85PSU5vHIA5kRX++HSdltp35kncDlr3u 6DtSqj0gvYQ7opjBsOkV7jPe03i9od7r2Etmndv55VZKJ+OgONNhIQe9o= X-Received: by 2002:a05:6a21:6317:b0:398:a060:a967 with SMTP id adf61e73a8af0-398eca11578mr11470604637.11.1773660556858; Mon, 16 Mar 2026 04:29:16 -0700 (PDT) Received: from localhost.localdomain ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7401588ecesm4684940a12.32.2026.03.16.04.29.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 16 Mar 2026 04:29:16 -0700 (PDT) From: Chengkaitao To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, chengkaitao@kylinos.cn, linux-kselftest@vger.kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v8 3/8] bpf: Introduce the bpf_list_del kfunc. Date: Mon, 16 Mar 2026 19:28:38 +0800 Message-ID: <20260316112843.78657-4-pilgrimtao@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316112843.78657-1-pilgrimtao@gmail.com> References: <20260316112843.78657-1-pilgrimtao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kaitao Cheng If a user holds ownership of a node in the middle of a list, they can directly remove it from the list without strictly adhering to deletion rules from the head or tail. We have added an additional parameter bpf_list_head *head to bpf_list_del, as the verifier requires the head parameter to check whether the lock is being held. This is typically paired with bpf_refcount. After calling bpf_list_del, it is generally necessary to drop the reference to the list node twice to prevent reference count leaks. Signed-off-by: Kaitao Cheng --- kernel/bpf/helpers.c | 11 +++++++++++ kernel/bpf/verifier.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index e87b263c5fe6..dac346eb1e2f 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2437,6 +2437,8 @@ static struct bpf_list_node *__bpf_list_del(struct bp= f_list_head *head, */ if (unlikely(!h->next)) INIT_LIST_HEAD(h); + + /* verifier to guarantee n is a list node rather than the head */ if (list_empty(h)) return NULL; =20 @@ -2463,6 +2465,14 @@ __bpf_kfunc struct bpf_list_node *bpf_list_pop_back(= struct bpf_list_head *head) return __bpf_list_del(head, h->prev); } =20 +__bpf_kfunc struct bpf_list_node *bpf_list_del(struct bpf_list_head *head, + struct bpf_list_node *node) +{ + struct bpf_list_node_kern *kn =3D (void *)node; + + return __bpf_list_del(head, &kn->list_head); +} + __bpf_kfunc struct bpf_list_node *bpf_list_front(struct bpf_list_head *hea= d) { struct list_head *h =3D (struct list_head *)head; @@ -4549,6 +4559,7 @@ BTF_ID_FLAGS(func, bpf_list_push_front_impl) BTF_ID_FLAGS(func, bpf_list_push_back_impl) BTF_ID_FLAGS(func, bpf_list_pop_front, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_list_pop_back, KF_ACQUIRE | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_list_del, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_list_front, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_list_back, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_task_acquire, KF_ACQUIRE | KF_RCU | KF_RET_NULL) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 64c1f8343dfa..e928ad4290c7 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12508,6 +12508,7 @@ enum special_kfunc_type { KF_bpf_list_push_back_impl, KF_bpf_list_pop_front, KF_bpf_list_pop_back, + KF_bpf_list_del, KF_bpf_list_front, KF_bpf_list_back, KF_bpf_cast_to_kern_ctx, @@ -12568,6 +12569,7 @@ BTF_ID(func, bpf_list_push_front_impl) BTF_ID(func, bpf_list_push_back_impl) BTF_ID(func, bpf_list_pop_front) BTF_ID(func, bpf_list_pop_back) +BTF_ID(func, bpf_list_del) BTF_ID(func, bpf_list_front) BTF_ID(func, bpf_list_back) BTF_ID(func, bpf_cast_to_kern_ctx) @@ -12644,6 +12646,7 @@ static const enum special_kfunc_type bpf_list_api_k= funcs[] =3D { KF_bpf_list_push_back_impl, KF_bpf_list_pop_front, KF_bpf_list_pop_back, + KF_bpf_list_del, KF_bpf_list_front, KF_bpf_list_back, }; @@ -12652,6 +12655,7 @@ static const enum special_kfunc_type bpf_list_api_k= funcs[] =3D { static const enum special_kfunc_type bpf_list_node_api_kfuncs[] =3D { KF_bpf_list_push_front_impl, KF_bpf_list_push_back_impl, + KF_bpf_list_del, }; =20 /* Kfuncs that take an rbtree node argument (bpf_rb_node *). */ --=20 2.50.1 (Apple Git-155)