From nobody Thu Apr 9 13:32:15 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 F2EA9375ADD for ; Mon, 2 Mar 2026 12:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772455288; cv=none; b=F7P41R+jnD3opQB/Wt/mbX1ecfgu5qlhRBfj7qf2uyqA/2dy7wrIPZ8TuaBy2tMvL09LJLznpiBbJ7B8qWnfvjoGQpqEn5oaS3ld4Pwj8k3dpVk/UEUQWdk3dIA3ihP6VPeU8SMxk6BF6Ffe0DOMDIyoXwEsKuxD5sODWLbn69E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772455288; c=relaxed/simple; bh=7sRo4nVSCezbQYCJvvf3hIL9zJ9NiAOafmugyoPklZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M1ED91aV3ZHnHH0UOC+/HDixsJBdlW3UT1ioNOyKKXUiXusmEHHay06tKtZ9K7plHAJePUnd4XmacJ8PnZDXLwD550y9myEF2RN/nknZPP+3o64FmWcO5+YEczI3O9G1vyHh7aEhQwoxtD8hpCZnsaTv4itRQr6cv0VW5ppuWKA= 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=Tq6iNcMw; arc=none smtp.client-ip=209.85.214.175 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="Tq6iNcMw" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2ad4d639db3so19928235ad.0 for ; Mon, 02 Mar 2026 04:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772455286; x=1773060086; 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=aWf2v8BqqxkSzBu1cxjzyfYlLbJQrEJW5Zx/O8qgXUk=; b=Tq6iNcMw2e6aKqPi21Jz3tBpnP7q2rxyoK0WIKF23o5ZIDIv/HT3oYT3IRRxo6sMvM SrL0vDbXdkQTDN/EAKPJsRHJrA8pco+LIuimKgJTjSy/3NlVdX8ytlhax9XJtBQ8ktch bxSrQEI8s3kOuD0/+FDJjn7UfAXKJPz85mgABK7b1ZHgDPRgew8R3gpa1/s8L/Lw9gsN WV/TuY3OeSLXxX41H4KZU3uG8X4qgt12qXXX117G/V+42k3FVVbmfdE+l+9bnAXPOJBQ Xk3ObOlo4hHt2wWExAL3Uvv9WqSKEgbkOjr8CjtCZOGi2dBIA5MtRVBxW0LQO4KTx9ew VB8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772455286; x=1773060086; 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=aWf2v8BqqxkSzBu1cxjzyfYlLbJQrEJW5Zx/O8qgXUk=; b=imElGWCLylaUVf8F6AOsPCOV0dHzENfLiz/IBI152SF0ffQhf5mm15jIYABn3om8FZ 0EIMvActtNFQMwj3YjppeaaYAoOq58ZRiTbZ6pZH+mXUBMLotP5X8Hea8ghhEVFIJzzv TIXT9wYm38LMVBf0FUwg6C33lPzkOuvS0ipkciQt5DfWk4doBapemmqRlwScYivIXSlt MHEP2sUFEirhqSjmW6O0pLiSHmS6/QgMvv13jIH26eN4ZU2Tjeeag3ND6wd+mJnyGDJS oxEVPwNsX9jY1F/NzqxTm5Kx+8SdCds+MKxztXKB5M/IwDrdhZFjZPAjv+upVwM8UcUu FbRA== X-Forwarded-Encrypted: i=1; AJvYcCWbVhXrgWZ/NNLKBtcgJ954GkNfxDw2wczjOtywNZLeRWt/hR4IojUgNmwi6m/p7haVstfg+LtiUxXjLG8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk95vS21hGMRCUimKI/9h6MjG8VhAxgzR8pFaUPPuPhyFbecAY lYyp2bww2Ns6Ydvr1e/555Suh3eWWbANoU8obQpgUXvaJ8Qdk2Sl4Yl8 X-Gm-Gg: ATEYQzxZpT0aUDM0DujhMiqtilY5zD2lQV6I/CmCLldHXcvnERBzkN4qgV66PduXDqP iiY4cha3CDZ0dilBAhc84IcgM+lExXD5Kw7hCeZNUGTDuntkrRlR2+AFXPF4c04LIerfzOvndZO BZA9So9v1hzFm221+tWBxNNMMx3PeWEXUIl2VCft+I454K+pRQ0dJIX9rHdTcGMc1ndwhqbE6E7 S1zrt+psXfQqtHg8d+IpFK7oCcpoxh3KCTA2tyRqAur1hLmhcxOG5aKTGBUPatCJa07SeU/pEay TUaU9qmCib+/xZjc2qCfVAHUbDilMVmOqv98GoUpEk/42YeptIZ2Tt9sxgol33eWdDV6bsUFxhS NEpOOe1dyLChNexAzJYq7JmZplmzRwXObLWGxjtsgTJoouL9lc/fl232Dc42a9JOOYPVazqw+S3 0a0iTD3TiBctMhD6HKZOteo+i05wT1c089toHDbsok2N040Wb+IRruGFRJsPKurSdU X-Received: by 2002:a17:903:2289:b0:2a0:e223:f6e6 with SMTP id d9443c01a7336-2ae2e4d6622mr132178515ad.46.1772455286289; Mon, 02 Mar 2026 04:41:26 -0800 (PST) Received: from localhost.localdomain ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae3d1956absm67910225ad.14.2026.03.02.04.41.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 02 Mar 2026 04:41:26 -0800 (PST) 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 v3 6/6] selftests/bpf: Add test cases for bpf_list_is_first/is_last/empty Date: Mon, 2 Mar 2026 20:40:28 +0800 Message-ID: <20260302124028.82420-7-pilgrimtao@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260302124028.82420-1-pilgrimtao@gmail.com> References: <20260302124028.82420-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 Rename test_list_add_del to list_add_del_and_check and extend it to cover the new kfuncs: assert list non-empty after insert, assert is_first(n) and is_last(m_1) after bpf_list_add, and assert list empty after removing both nodes. Signed-off-by: Kaitao Cheng --- .../testing/selftests/bpf/bpf_experimental.h | 15 +++++++++++ .../selftests/bpf/progs/refcounted_kptr.c | 27 +++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 48106ea5dda8..2eb107e771ad 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -123,6 +123,21 @@ extern int bpf_list_add_impl(struct bpf_list_node *pre= v, struct bpf_list_node *n /* Convenience macro to wrap over bpf_list_add_impl */ #define bpf_list_add(prev, node) bpf_list_add_impl(prev, node, NULL, 0) =20 +/* Description + * Return true if 'node' is the first node in the list with head 'head'. + */ +extern bool bpf_list_is_first(struct bpf_list_head *head, struct bpf_list_= node *node) __ksym; + +/* Description + * Return true if 'node' is the last node in the list with head 'head'. + */ +extern bool bpf_list_is_last(struct bpf_list_head *head, struct bpf_list_n= ode *node) __ksym; + +/* Description + * Return true if the list with head 'head' has no entries. + */ +extern bool bpf_list_empty(struct bpf_list_head *head) __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 4d979f5ad9e8..6797c53f550e 100644 --- a/tools/testing/selftests/bpf/progs/refcounted_kptr.c +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr.c @@ -367,14 +367,14 @@ long insert_rbtree_and_stash__del_tree_##rem_tree(voi= d *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 one node in tree and list, remove it from tree, add a second - * node after it in list with bpf_list_add, then remove both nodes from - * list via bpf_list_del. +/* Insert one node in tree and list, remove it from tree, add a second node + * after it with bpf_list_add, check bpf_list_is_first/is_last/empty, then + * remove both nodes from list via bpf_list_del. */ SEC("tc") -__description("test_list_add_del: test bpf_list_add/del") +__description("list_add_del_and_check: test bpf_list_add/del/is_first/is_l= ast/empty") __success __retval(0) -long test_list_add_del(void *ctx) +long list_add_del_and_check(void *ctx) { long err =3D 0; struct bpf_rb_node *rb; @@ -386,6 +386,11 @@ long test_list_add_del(void *ctx) return err; =20 bpf_spin_lock(&lock); + if (bpf_list_empty(&head)) { + bpf_spin_unlock(&lock); + return -7; + } + rb =3D bpf_rbtree_first(&root); if (!rb) { bpf_spin_unlock(&lock); @@ -418,6 +423,14 @@ long test_list_add_del(void *ctx) return -8; } =20 + if (!bpf_list_is_first(&head, &n->l) || + !bpf_list_is_last(&head, &m_1->l)) { + bpf_spin_unlock(&lock); + bpf_obj_drop(n); + bpf_obj_drop(m_1); + return -9; + } + l =3D bpf_list_del(&n->l); l_1 =3D bpf_list_del(&m_1->l); bpf_spin_unlock(&lock); @@ -434,6 +447,10 @@ long test_list_add_del(void *ctx) else err =3D -6; =20 + bpf_spin_lock(&lock); + if (!bpf_list_empty(&head)) + err =3D -7; + bpf_spin_unlock(&lock); return err; } =20 --=20 2.50.1 (Apple Git-155)