From nobody Wed Feb 11 04:18:38 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 7E0C02C0F72 for ; Mon, 9 Feb 2026 02:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770605595; cv=none; b=A0gBGDT639iWpKLHeWYNCi99Cn3ZkE+sSzZBcUjrqSOdgfWW5JtyXcARQKtLgk9KBh3GNWlU/8in56sXtBBZCgMfpuDqhisl6TVYv4Fc9+u9dCSdS02ea4AN1ql0UixilL7F542oS/481gHa8VhMDRcTf+2qwgJWsstoabC3m8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770605595; c=relaxed/simple; bh=RmGHUe45I4K7MVIz7OBicUcd2G4lg/Tg0QEzkQLAcIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=udoZlMH03xTiVNRVXWcfHyPkssWgP8lXKPxBkj/trwlq741u6ZbmavLV8RrzlJ2N96hFJWxa/qtRaTRKPO/W9gWvj1xrfrzdalEnqEVAoEVsscz1etz/Be4PAzdD7XB3YSI2F0I3FVFB6HmdP0JVrtY4iKWiZLEeX+0ZRBDjbBk= 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=ndrhTPjc; arc=none smtp.client-ip=209.85.216.53 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="ndrhTPjc" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-354bb7d2cb1so887042a91.0 for ; Sun, 08 Feb 2026 18:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770605595; x=1771210395; 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=UoKEL4fx2cXbp8ykQKKpnwt29v9mHhKU5fa9H902sH4=; b=ndrhTPjcGnmVExHoGlvd9h1lvagktFJhVEIcp10SGBmVCRoXzwZEjbWgwRjgojwsNh 863/XVcbY+EdMslqju7Q06Dg24QEA2Yb8eBwJCu+wHUcYFtiG8dkvyUvSqcVoOvSgrtI 0DT5WBeZcfqCxpaWtZ2S18uDTMKQy0eGtmskYZ7R7kCoPrTZ11xJ/RHFXs73ucIGdCvM GgYllMBnicJGDdaVtRsVLgLrtx+f12aLNoHcbk2cZdA4PBr0udufkWYWIzoUAP9W/Vnh ZJfmSFut+G7SImvqeZK3Y9fzHbT0HWjkQCMHcNgaXzeTfdH9+iCffOa0IbP9i9Qbx8kb aOVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770605595; x=1771210395; 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=UoKEL4fx2cXbp8ykQKKpnwt29v9mHhKU5fa9H902sH4=; b=gxTCQNUTb5wcwnUzYbYP3JwbZW+c1dJg1jh3NeZ302ZGHbbqAtoW0o80YpAry6s84t McaWVsm63PIn6w/lTbqUuDux39q9EXQLOdjR2ACQU4gg0b59xtVYb1Lhs0orafk3Cgxj fpss/8OVHAkYd4ggWksvp5b8BOOQ7UCPd+rROyiy3CCxyG8Y2wwV16HpaNtdhGIgO9v7 hZxkUty0jNicDkJXDaMVhpA9dTzStG5TD54fi4pbely2lBADwgO3lYw15O3QUEERPd8r 0Xvv9g2mrl9YRycCgJG6EVqpnIbNAMpZcW4MwS97K/8fMHk9647OvUaQNyM0TdncTyNL Ox3g== X-Forwarded-Encrypted: i=1; AJvYcCUA4hYIJdqscJIrk5l992H9nLU2CHIJfTBZCtQP3YN8t4xY30diq82vrJ2aXCafxQ/qLneresnwaLCbxX8=@vger.kernel.org X-Gm-Message-State: AOJu0YzOxg4CgxpnWo5EicuyZQAO6GzpnOnvU+D1k+KnpCKqCMGz6U4L nnlFlICJUOOlk1RTX0YAWHFn6KredVmGGc0nEBDEA84UIoUasXIkcFru X-Gm-Gg: AZuq6aI3SvZbno+lewhQcfP0eo27v58/sPSaD2dCsuHnn9gUp/B5VmaITm77HYaZbfC g+LsFYVeyi6u1QTfLj4I0QmIKlEZAKcHlI5gd4Hfan1cyVJSZRkCyKMuejUU730bxtnYBp1ncW3 YF5RvVI6ZKc9ENAsaEsyBw5VNBA72DiUjt2DFa/+Mua49BoWk8l+ZJnvZBa/3TjJx75dD4Yf0WR /qtqE7ZqPbErQh/w1UMRhYp9WAFwNAEgKHkf2/n/fWKjNq4vi0MPSkkFi1ipmHeArCH297tEscm W8wnJMNWYG4o7jTnobZWJwzfnDG3qP7t7WfTakVPqvSt+Gsf5rxZGzKT1R0RWWQINQ6Z0dhalQi nMwmg2c1nDFz/bOV2poEfDBrm4InRzrtww8J53coKsLk35NeZinelRL+Pknd55mfDo677qLXe0y 3nQuTCil2YCdquoPb+RWmg+x/YiYzN37M/Q7n9yju5BI+/iOGo8Hn6 X-Received: by 2002:a17:90b:2682:b0:349:162d:ae0c with SMTP id 98e67ed59e1d1-354b2f6219amr8689322a91.4.1770605594812; Sun, 08 Feb 2026 18:53:14 -0800 (PST) Received: from localhost.localdomain ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35621177896sm6302649a91.15.2026.02.08.18.53.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 08 Feb 2026 18:53:14 -0800 (PST) From: Chengkaitao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, 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 Cc: chengkaitao@kylinos.cn, leon.hwang@linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 2/2] selftests/bpf: Add test cases for bpf_list_del Date: Mon, 9 Feb 2026 10:52:50 +0800 Message-ID: <20260209025250.55750-3-pilgrimtao@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260209025250.55750-1-pilgrimtao@gmail.com> References: <20260209025250.55750-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 Add a node to both an rbtree and a list, retrieve the node from the rbtree, use the obtained node pointer to remove it from the list, and finally free the node. Signed-off-by: Kaitao Cheng --- .../testing/selftests/bpf/bpf_experimental.h | 11 +++++ .../selftests/bpf/progs/refcounted_kptr.c | 41 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 2cd9165c7348..6d8175abc590 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -99,6 +99,17 @@ extern struct bpf_list_node *bpf_list_pop_front(struct b= pf_list_head *head) __ks */ extern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head)= __ksym; =20 +/* Description + * Remove 'node' from the BPF linked list with head 'head'. + * The node must be in the list. Caller receives ownership of the + * removed node and must release it with bpf_obj_drop. + * Returns + * Pointer to the removed bpf_list_node, or NULL if 'node' is NULL + * or not in the list. + */ +extern struct bpf_list_node *bpf_list_del(struct bpf_list_head *head, + struct bpf_list_node *node) __ksym; + /* Description * Remove 'node' from rbtree with root 'root' * Returns diff --git a/tools/testing/selftests/bpf/progs/refcounted_kptr.c b/tools/te= sting/selftests/bpf/progs/refcounted_kptr.c index 1aca85d86aeb..2cb6dd73db7a 100644 --- a/tools/testing/selftests/bpf/progs/refcounted_kptr.c +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr.c @@ -367,6 +367,47 @@ long insert_rbtree_and_stash__del_tree_##rem_tree(void= *ctx) \ INSERT_STASH_READ(true, "insert_stash_read: remove from tree"); INSERT_STASH_READ(false, "insert_stash_read: don't remove from tree"); =20 +/* Insert node_data into both rbtree and list, remove from tree, then remo= ve + * from list via bpf_list_del using the node obtained from the tree. + */ +SEC("tc") +__description("test_bpf_list_del: remove an arbitrary node from the list") +__success __retval(0) +long test_bpf_list_del(void *ctx) +{ + long err; + struct bpf_rb_node *rb; + struct bpf_list_node *l; + struct node_data *n; + + err =3D __insert_in_tree_and_list(&head, &root, &lock); + if (err) + return err; + + bpf_spin_lock(&lock); + rb =3D bpf_rbtree_first(&root); + if (!rb) { + bpf_spin_unlock(&lock); + return -4; + } + + rb =3D bpf_rbtree_remove(&root, rb); + bpf_spin_unlock(&lock); + if (!rb) + return -5; + n =3D container_of(rb, struct node_data, r); + + bpf_spin_lock(&lock); + l =3D bpf_list_del(&head, &n->l); + bpf_spin_unlock(&lock); + bpf_obj_drop(n); + if (!l) + return -6; + + bpf_obj_drop(container_of(l, struct node_data, l)); + return 0; +} + SEC("tc") __success long rbtree_refcounted_node_ref_escapes(void *ctx) --=20 2.50.1 (Apple Git-155)