From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 09C8734FF48 for ; Wed, 4 Mar 2026 15:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772638996; cv=none; b=iNbhRwoCMjGmL/Q+9MdaAPYhxWq9NiJ5cpjCkNKrze2Qmvhyw9mIS98UiEHXsCL6CvuwwAzpaVG5uCF1J0J5LadtJcd8xkt+NwilSr+a4SaOGu2mQOik0PrntshRtZLAAWAQTMqfspNJrwq3QKiKc1VeG5IPmlzCoCwAfkXAs6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772638996; c=relaxed/simple; bh=8qECvAMQIaJBQwNMYa/jdZgoxh1N5I+/3F8YghqJ9PQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=iGbAHPPFR09ljbBoiSmF/F3bI9m2KmzZ78qTT2tVt+b4ts0fVOGPep35f7KMZISLvlu6ri/Q19wYDCvm4JrqNozsq5EDLG8k3HMaJSZkH0qUwQUUMPAgQNV0rAGVKh6B4cuMjYDrK+hhpmArLkTVWb6GFprnv9SSpN1ssqvwUl4= 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=kxzztYot; arc=none smtp.client-ip=209.85.221.54 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="kxzztYot" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-439bc14dcf4so2077950f8f.1 for ; Wed, 04 Mar 2026 07:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772638993; x=1773243793; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U0ikYOmTgcPaP2qaHYSHDWasHLTaPAYvwIqfm9N3sK4=; b=kxzztYotAZf0xZ5CFdrH4096LWMJNgmZywWCiPxKDABiSkji7ljju0Z2NSiU90fDj+ dfIwXIUSWQ1utr1pRI6pGKBNYHpsDDO2xG++ofwirHOimC1LAStP+99TOopSn8GHS9Cm 1K8iEgYLW44i15gZ1FM722RC9rE73CLKvGbgpn802t+GLepevOdBam53rNDQtpu9WzgV coUHe5F2675YFKuqu2jLDef/4DiEISOGegNX9enFYf1Xgmi2je/GKIdhTkmCaVXAsNNT 3hY0pY3DtTOzIePvOZiWi6giBtKt362Lp+N0bH+bM2ALykBug+zOa9EZxaGzVa0Ok+Cz Qo7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772638993; x=1773243793; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U0ikYOmTgcPaP2qaHYSHDWasHLTaPAYvwIqfm9N3sK4=; b=XdmAs1BFLjK+/I/iFcyX0DJdGnInLZzRgewWK9w1l/e7H0ZgoqcV6LdaLXMIxCI//b jmnDNEAuEeObZOVv1zQWmyUs3kJ4CJQn3QtWAQLNMORphxs50hFuBn+zJnbxg+GV34oS YUAZIRw8GlTuizZbIOFMSICZIhBZHOvdl5JMjqtbP9fOqNnWSyd6uy/fUJhPgGjcXx+P HixCqVzB7WSGkSJ7JBZyGKq99hdHEQtZ4W8cfMCGDtn1FGHNUs7g0e1p/4JHOhxfC4uC UXH0iQ9YQG7VSwE57bZL8D4InnZfAy7TPMGjLkMC++gPGD47VR1oA5RYodIzbeeeOKmF aW8A== X-Forwarded-Encrypted: i=1; AJvYcCXv8JLFoecnSTjMdJpghGbm46iqJXAoDZjSXV+l3D9Xl+QdbMYLMJIxCb/Ipv1nQMYMC73RylkWiAZjeVY=@vger.kernel.org X-Gm-Message-State: AOJu0YwWIwpW02z1ieaFlmQE8LW0Agg1izMVcqfUv9T2EjmAaZSLL0f8 Y7FobeD6Qb08ztBtXBJpnIBra7aj80hN9n0rHg+wDHRBKc+ENH4Q+O5y X-Gm-Gg: ATEYQzxfqKgWJNP8Yavoc7QyzbrsKs+Zje+XZYsDl77kgIgKQ6IWlkA3x2XFi8gtR9v iI7ng0ov/wC8Mad4vg35EDYLjK9eNcRpV2cyJAKjFnGZJmPDjubcAbrB4CgXPnc3LCGFAdC+t/b 6pKyNdd2k6u5jNDAcvEiufRYpo572klA0u1cN9Ypxkt+mJAg7w26xNZhn6pl+h6PreG+Y2zDzwo c2T+mHR0KZj3EO7HODSA628rIKSw5YW4Z5PwbQh0EKqWl6n3LVfhOsSk0NUC+kAVbUpzYhlvZ8n byLD3fGjJOqhfikCj53/Viqwx1TQd64jFrG8qOB3YamLAK2aNFYx89ynjv/yxsq6jXaBNUk6AcO V58qeSdP4i06I71HXiG3mSPV7udYHk+EdkTkkolftr56HUR9kaQlk5zWbDVgRvs+kNVzuqLnzkn 7A8OnDv515oE1AJZYNg/DZ9vjYUoXI5bpU1suotg== X-Received: by 2002:a5d:588a:0:b0:439:b79d:b9a6 with SMTP id ffacd0b85a97d-439c10adc38mr12284357f8f.11.1772638993132; Wed, 04 Mar 2026 07:43:13 -0800 (PST) Received: from localhost ([2a01:4b00:bd1f:f500:f867:fc8a:5174:5755]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439c2f7eca1sm10099102f8f.11.2026.03.04.07.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 07:43:12 -0800 (PST) From: Mykyta Yatsenko To: Chengkaitao , 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: Re: [PATCH v5 2/6] selftests/bpf: Add test cases for bpf_list_del In-Reply-To: <20260304031606.43884-3-pilgrimtao@gmail.com> References: <20260304031606.43884-1-pilgrimtao@gmail.com> <20260304031606.43884-3-pilgrimtao@gmail.com> Date: Wed, 04 Mar 2026 15:43:12 +0000 Message-ID: <87zf4ny50v.fsf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Chengkaitao writes: > 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. > > To verify the validity of bpf_list_del, also expect the verifier > to reject calls to bpf_list_del made without holding the spin_lock. > > Signed-off-by: Kaitao Cheng > --- > .../testing/selftests/bpf/bpf_experimental.h | 11 +++ > .../selftests/bpf/progs/refcounted_kptr.c | 71 +++++++++++++++++++ > 2 files changed, 82 insertions(+) > > diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h > index 4b7210c318dd..54ec9d307fdc 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 bpf_list_head *head) __ks > */ > extern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head) __ksym; > > +/* 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/testing/selftests/bpf/progs/refcounted_kptr.c > index 1aca85d86aeb..ac7672cfefb8 100644 > --- a/tools/testing/selftests/bpf/progs/refcounted_kptr.c > +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr.c > @@ -367,6 +367,77 @@ 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"); > > +/* Insert node_data into both rbtree and list, remove from tree, then remove > + * 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 = __insert_in_tree_and_list(&head, &root, &lock); > + if (err) > + return err; > + > + bpf_spin_lock(&lock); > + rb = bpf_rbtree_first(&root); > + if (!rb) { > + bpf_spin_unlock(&lock); > + return -4; > + } > + > + rb = bpf_rbtree_remove(&root, rb); > + if (!rb) { > + bpf_spin_unlock(&lock); > + return -5; > + } > + > + n = container_of(rb, struct node_data, r); > + l = 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") > +__failure __msg("bpf_spin_lock at off=32 must be held for bpf_list_head") > +long list_del_without_lock_fail(void *ctx) > +{ > + struct bpf_rb_node *rb; > + struct bpf_list_node *l; > + struct node_data *n; > + > + bpf_spin_lock(&lock); > + rb = bpf_rbtree_first(&root); > + if (!rb) { > + bpf_spin_unlock(&lock); > + return -4; Do we need to craft those error return codes in the program that is supposed to be rejected by verifier. Can we implement a minimal code that triggers the verifier error without all unnecessary noise. > + } > + > + rb = bpf_rbtree_remove(&root, rb); > + bpf_spin_unlock(&lock); > + if (!rb) > + return -5; > + > + n = container_of(rb, struct node_data, r); > + l = bpf_list_del(&head, &n->l); > + 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) > -- > 2.50.1 (Apple Git-155)