From nobody Mon Dec 1 23:36:40 2025 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (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 0E01433E354 for ; Wed, 26 Nov 2025 18:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183454; cv=none; b=t6Z5vH9Dqr7FDLtvIXz07uIgC7VzCr/pBsInISnfSbp6iQ8hlX3Mv4sbXIMTMXPeOemxnhZYq6/ymQxJYtzLuTKJPWNxo46H5Sptl/rsJTDxvc0ZxbUG+Q+4nMF1sfqyC5kLduutvhWLIzGC99iM8k/iKAhkDD9tlQsCaMv/B4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183454; c=relaxed/simple; bh=de05t6Uooi6dbGpHaHB0GbWiclzXkAC6UDgDYumpOAQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bnD3ntfdtN8fztfmihclMkyl0nULMVEqdsc+B/laz4++RdeEP/slbeEe8rm7wnq/C7jFxL6Ks1JSPYbFc0eHa8MHDa/jO1o7slPq8vi3UT047Ok+ASRAXgXTKtuMAwdbbtulXJq1pq9PMxmE+/mto0+GyTeKHB8Zlot0qOZ2e4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=UAbsUlK3; arc=none smtp.client-ip=74.125.224.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UAbsUlK3" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-6432842cafdso87996d50.2 for ; Wed, 26 Nov 2025 10:57:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1764183452; x=1764788252; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3EVogAUf9sZwvrZ2BPOSnajNqljKd+lPUBpF9BuiigE=; b=UAbsUlK3q0d1GcjmxxvZbR3rjY8z7tVQFc6ZlZ4i03Zol0TTlRxaQeigoNbvw4rDkS HnJz7a9itSXRaPZ7sWBGMoKmoOiF99FxIp4Dho5n39chdS9LpPjMp4uDt1kUcyxxg3Xb tuYH0dYLaCMZxXgNYfGK7n0wx81T66u1iqrTYpHlzQD8Kl3e3Xxd0Se0Jl01sMxGwAhj V//JWuSz7ksz6DQmJzSGLSHIkvPghMQVE4bvKlTCkGaiAkF3uaxK3wdxDuUFjoAN1IBb jDcqLUj6xsebYtgWm3WPhGtoVy7Mv5E2g/FKPg119fi5DFUTuF3ZTOVf8Z9lgD9QqROp l3wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764183452; x=1764788252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=3EVogAUf9sZwvrZ2BPOSnajNqljKd+lPUBpF9BuiigE=; b=csq1MFv9b+wQ2oWtlminCzHRngSHYmTJk5oxU7gfzhdVW94lKfTBNPW0r9pVtedWHT rhShULtksVbWHp9a1uCYmgpcoIJW/sAfsQ88F75GYwNotjNIBvRw9MXJzo1yOpoNUkxB jdSlP753+lpHw5Wj4r8fCchzSPeBXbRK/eVD0UHJ17mfN0SB0VqQ5lE8stJUpTmUBdyG FM4HYMxP8mumvx//k4w5NrS2Rz4P2DXTBYTQWu7L3h6YXFI23Ap5nB4ZchwRMgLOyMta XefwY/1FhfTE1CpW7cMC9QimAEGmdkMd/uUIQefKnLY376IHRbTO5iBS+ohnsdbK94Wx dIcA== X-Forwarded-Encrypted: i=1; AJvYcCWhYQurNQSNYeevOfbfjI7v5rYFqt+m4aavQGtlq9CPI4P5R3SgYE96/lXSGRnXGGdGkOhfrdWFlatLRWE=@vger.kernel.org X-Gm-Message-State: AOJu0YwfbRg5GXr273k8qOpTYs+qXzwRZQ8qkpgwffUw3bzH2vbo7ALI GGTmMm578S33hufK1Hi6GBIlR8+PNv4g3nuEoqC1xhNQVIJ2l85lWYnrUirHGsdBnwE= X-Gm-Gg: ASbGnctAGIEvM1V9Y7um4kA8nxKMeiajHdFDm9q+wNEmKvsM2iUdPz+puZBniZh7Pc8 9Zhnr3qUugsWc3Vm6khhFEDYcCFWt7d0fXTENpfeMXb16pJDhFkgntfSB8nabby8S8LKIRkwa2C 78zJ/PXH/Lm1/q1AfziIkPoAoY+pQyZjv5fsyJy0vNEKH1HOMGrVMQZo+TplY/T4rjGeqJhLrqX YsIVHeuq6guUwMHwzrpIZwb+t6R1H8nxZMyabygd8GUbJVhOPtKOQTSV/Ii3LDa454fzDzuqiKs C99P+2Tjyx/Jg4QhPdpaUIVH8IlGYjePuSwQ7eXfFCgrAAD/xzxJt2thehsiqPA1PpmSSByfGvY M6o4t7Qs38WcBP0VKrgsfnbEZxsCrMcEv0SrloAW5DLKwySIQ/fEQ+QSNXtFq2aGcyHgLeUXLnA 24hW8S0n+fQcyS+BDZUqsIopVsrWbz/dLUkYP3ULtz8yytFvQUbGKCHJClYBqavLtwD4rHmha00 0SQuy0= X-Google-Smtp-Source: AGHT+IGolbW5+rjOQ0Yye2rYIz9onkgz5B5ar70qXCIQenbc39w0zKLELoUeY+9t55wUha7BmD2pxQ== X-Received: by 2002:a05:690e:1542:20b0:642:836:1048 with SMTP id 956f58d0204a3-64302a8f272mr13099532d50.2.1764183451962; Wed, 26 Nov 2025 10:57:31 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-643259fd696sm2960753d50.7.2025.11.26.10.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 10:57:31 -0800 (PST) From: Pasha Tatashin To: corbet@lwn.net, pasha.tatashin@soleen.com, nicolas.frattaroli@collabora.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, kees@kernel.org, davidgow@google.com, pmladek@suse.com, tamird@gmail.com, raemoar63@gmail.com, ebiggers@kernel.org, diego.daniel.professional@gmail.com, rppt@kernel.org, pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, dmatlack@google.com, rientjes@google.com Subject: [PATCH v1 2/3] list: add kunit test for private list primitives Date: Wed, 26 Nov 2025 13:57:24 -0500 Message-ID: <20251126185725.4164769-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog In-Reply-To: <20251126185725.4164769-1-pasha.tatashin@soleen.com> References: <20251126185725.4164769-1-pasha.tatashin@soleen.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" Add a KUnit test suite for the new private list primitives. The test defines a struct with a __private list_head and exercises every macro defined in . This ensures that the macros correctly handle the ACCESS_PRIVATE() abstraction and compile without warnings when acting on private members, verifying that qualifiers are stripped and offsets are calculated correctly. Signed-off-by: Pasha Tatashin Reviewed-by: David Gow --- lib/Kconfig.debug | 14 +++++++ lib/tests/Makefile | 1 + lib/tests/list-private-test.c | 76 +++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 lib/tests/list-private-test.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 42143686151f..fa9388726182 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2788,6 +2788,20 @@ config LIST_KUNIT_TEST =20 If unsure, say N. =20 +config LIST_PRIVATE_KUNIT_TEST + tristate "KUnit Test for Kernel Private Linked-list structures" if !KUNIT= _ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This builds the KUnit test for the private linked-list primitives + defined in include/linux/list_private.h. + + These primitives allow manipulation of list_head members that are + marked as private and require special accessors (ACCESS_PRIVATE) + to strip qualifiers or handle encapsulation. + + If unsure, say N. + config HASHTABLE_KUNIT_TEST tristate "KUnit Test for Kernel Hashtable structures" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/lib/tests/Makefile b/lib/tests/Makefile index 601dba4b7d96..62a7f115f622 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_TEST_IOV_ITER) +=3D kunit_iov_iter.o obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) +=3D is_signed_type_kunit.o obj-$(CONFIG_KPROBES_SANITY_TEST) +=3D test_kprobes.o obj-$(CONFIG_LIST_KUNIT_TEST) +=3D list-test.o +obj-$(CONFIG_LIST_PRIVATE_KUNIT_TEST) +=3D list-private-test.o obj-$(CONFIG_KFIFO_KUNIT_TEST) +=3D kfifo_kunit.o obj-$(CONFIG_TEST_LIST_SORT) +=3D test_list_sort.o obj-$(CONFIG_LINEAR_RANGES_TEST) +=3D test_linear_ranges.o diff --git a/lib/tests/list-private-test.c b/lib/tests/list-private-test.c new file mode 100644 index 000000000000..3bd62939ae67 --- /dev/null +++ b/lib/tests/list-private-test.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit compilation/smoke test for Private list primitives. + * + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ +#include +#include + +/* + * This forces compiler to warn if you access it directly, because list + * primitives expect (struct list_head *), not (volatile struct list_head = *). + */ +#undef __private +#define __private volatile + +/* Redefine ACCESS_PRIVATE for this test. */ +#undef ACCESS_PRIVATE +#define ACCESS_PRIVATE(p, member) \ + (*((struct list_head *)((unsigned long)&((p)->member)))) + +struct list_test_struct { + int data; + struct list_head __private list; +}; + +static void list_private_compile_test(struct kunit *test) +{ + struct list_test_struct entry; + struct list_test_struct *pos, *n; + LIST_HEAD(head); + + INIT_LIST_HEAD(&ACCESS_PRIVATE(&entry, list)); + list_add(&ACCESS_PRIVATE(&entry, list), &head); + pos =3D &entry; + + pos =3D list_private_entry(&ACCESS_PRIVATE(&entry, list), struct list_tes= t_struct, list); + pos =3D list_private_first_entry(&head, struct list_test_struct, list); + pos =3D list_private_last_entry(&head, struct list_test_struct, list); + pos =3D list_private_next_entry(pos, list); + pos =3D list_private_prev_entry(pos, list); + pos =3D list_private_next_entry_circular(pos, &head, list); + pos =3D list_private_prev_entry_circular(pos, &head, list); + + if (list_private_entry_is_head(pos, &head, list)) + return; + + list_private_for_each_entry(pos, &head, list) { } + list_private_for_each_entry_reverse(pos, &head, list) { } + list_private_for_each_entry_continue(pos, &head, list) { } + list_private_for_each_entry_continue_reverse(pos, &head, list) { } + list_private_for_each_entry_from(pos, &head, list) { } + list_private_for_each_entry_from_reverse(pos, &head, list) { } + + list_private_for_each_entry_safe(pos, n, &head, list) + list_private_safe_reset_next(pos, n, list); + list_private_for_each_entry_safe_continue(pos, n, &head, list) { } + list_private_for_each_entry_safe_from(pos, n, &head, list) { } + list_private_for_each_entry_safe_reverse(pos, n, &head, list) { } +} + +static struct kunit_case list_private_test_cases[] =3D { + KUNIT_CASE(list_private_compile_test), + {}, +}; + +static struct kunit_suite list_private_test_module =3D { + .name =3D "list-private-kunit-test", + .test_cases =3D list_private_test_cases, +}; + +kunit_test_suite(list_private_test_module); + +MODULE_DESCRIPTION("KUnit compilation test for private list primitives"); +MODULE_LICENSE("GPL"); --=20 2.52.0.487.g5c8c507ade-goog