From nobody Mon Dec 1 23:07:04 2025 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (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 0402D312836 for ; Wed, 26 Nov 2025 18:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183453; cv=none; b=VbEZhMNECdo69KvX1ugALV6KAYxhsDuT4EMZpgfPddb68qLnyRS1QV2AVFlp4DqBiIaHADrFbVfwuKA8qwYLCPtZvfNpEZfSaGe4Cvp/pDZJXrKDB/LeI4FFG8RL4rmXRULeyCj073EfBGPOrKMw+6yYV4sjgIsyCY5lZsnUf6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183453; c=relaxed/simple; bh=44wvrjsJsA56OuYSPS9rS3D1Jv0o0ZdFIoHQwFGkRDc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VO5txcdblg1PRv4qC+lJOvAw1ih/zK5XkxNfzIVuMuqr9rpiiQVIDvPc8QPaVy70GxtF8Sh5wXoqYTtYbJgBzvY/qypBujhValFX0UDhkhIQhElGGp+3KvNhWNKoqvtC9a/8xUXxtDcuR2akrOBMtq9z5X6K4FO11lukWsqId/A= 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=hlcQvjOl; arc=none smtp.client-ip=74.125.224.52 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="hlcQvjOl" Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-6420c0cf4abso98691d50.1 for ; Wed, 26 Nov 2025 10:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1764183451; x=1764788251; 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=252XjyR+0lgh5x/2v3DurnNqDLZdTdfYV2jUwplovA0=; b=hlcQvjOlT/nt6c3sIr0osj95aOONwCwkDR2AQGaI/Q+Dmn58eA387QpfdzPhXPGCOB vESovq0hqFkRQSHx3N9TFtRKVoCPhg8LW4W3ee6ftCSR5DuTTf6wP7YJnLYcD5C1C5B2 sci2wf+8W0demdIhB9JqEcn9z4iig9tHyDknHg8GPlziaD8xjdhnkcHM+U4EhcqypR4O aLzX6JSSUOJxCkYKoJAhVDlqq4EAhNdLSoPatbr6lcTg7Pgp6Saf9FsNx3rrqoZCyXqk WJvD4XYo6oIJQc5smg7Hu8MJPLmXoUo9HNIye2exQsJNaO5NoYFGSqWI2APMdJDsXuKn rQkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764183451; x=1764788251; 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=252XjyR+0lgh5x/2v3DurnNqDLZdTdfYV2jUwplovA0=; b=P2Wy64NbY22F0IuSvXCUjJlJ7TA14xJy5hyGubIrH1yTEF3Ay9soyb0xP2ACP4y20x 2XP0Q8/Oi3oUlBc5ib8pBFNO3CaGufg4VOhTstnswCP3KnRq43Vf8od0o0kKo3KWKUHW kM0uG0iGNYucgCIfFmoYY2bcmzr5ELthiH1DJCQh1ps/LkPHuBOTzWO4BmNr5IvFHZt0 1c/bQ8n8cMl0V6wV/VuRp20rZ3vv3trAe7Og4zZBhWSUALSTx2Sc0J2pAV3Kz/W79ovd HaMjtzmIOsyEwMZsXa6h0AZUY95EEui/OKf7+oym29OyyfypI+YYI+5YkEnWOAD83Pfw hRiw== X-Forwarded-Encrypted: i=1; AJvYcCWbGSBz7WdVNkEqsfd+HYet/SV50t0iK35jv1W3WWgI9oPqBWFhR7QV881M7hsMoPhF5zCXVuQlqBuzpDU=@vger.kernel.org X-Gm-Message-State: AOJu0YzZbQo8+n2/QoIWVFVwwYt9PVR8rCsUBCofRoC70x65i2GcUAu4 v7PZ4MeVdgSk0UuuxaUf+lLn1jCP7iUUdS+Ot8+rGAn8FQpXWtqQNlmuJMYBQihvH+U= X-Gm-Gg: ASbGncsq15LxzzuwXZXAZGUD+F3tqvRAXfr1o6SqEuRFmuWQUMBdkq5dSw7X6Qn3PUp hjB+lzcjPQYzPYI/BuN/yrkHCD2CqMYqc9VIe36O7fB2kijwNsgguAqpLU2yJB6/TyEIc0iiWzS UsWptK6PDlEotANE1HLBDTm2DpAG/QZ2HY2J0IdOJJsO1SKHe8Zl5hX7DKfiMEVMoV+ZbvE7zkz 2TdyEaWTnEuFbfDh3ShPaGlXoSoH02cnlnF77MZZIFAU/371D/q4xr+cNQDpT1T5jqL17pstkas a5TukeWmauo3nr1SGJHDyKez7DTTt3RdxEjdXhbpuXjjXpeFNJRGq8TeMsqPAupwZ96V3XFKVJJ C8m9jPtg99mg9GkQsiJlkZb2DOTy0H4SInkzcdheo5Cvj6GsZ328iPSmrXLpQsh8gUlgDIqCiKi Xi6eR1GCfcDuTsunc5h/cKzJfelgzFOGNDKGr34oOBVhZlhJdwV1Pb/fMZ6X6LFmTstsfpzz5IH Dea/TnQF9sMkJArNw== X-Google-Smtp-Source: AGHT+IHu24upDOl7ro9ofRNY1haZ/Bs6YtgAgi3REfJFG6MqRROVjAAPoCaKTsxQrfJqTFs30v63Ng== X-Received: by 2002:a05:690e:784:b0:63f:b590:2e9 with SMTP id 956f58d0204a3-64302aa4865mr11760784d50.21.1764183450703; Wed, 26 Nov 2025 10:57:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 10:57:30 -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 1/3] list: add primitives for private list manipulations Date: Wed, 26 Nov 2025 13:57:23 -0500 Message-ID: <20251126185725.4164769-2-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" Linux recently added an ability to add private members to structs (i.e. __private) and access them via ACCESS_PRIVATE(). This ensures that those members are only accessible by the subsystem which owns the struct type, and not to the object owner. However, struct list_head often needs to be placed into the private section to be manipulated privately by the subsystem. Add macros to support private list manipulations in . Signed-off-by: Pasha Tatashin --- Documentation/core-api/list.rst | 9 ++ include/linux/list_private.h | 256 ++++++++++++++++++++++++++++++++ 2 files changed, 265 insertions(+) create mode 100644 include/linux/list_private.h diff --git a/Documentation/core-api/list.rst b/Documentation/core-api/list.= rst index 86873ce9adbf..241464ca0549 100644 --- a/Documentation/core-api/list.rst +++ b/Documentation/core-api/list.rst @@ -774,3 +774,12 @@ Full List API =20 .. kernel-doc:: include/linux/list.h :internal: + +Private List API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/linux/list_private.h + :doc: Private List Primitives + +.. kernel-doc:: include/linux/list_private.h + :internal: diff --git a/include/linux/list_private.h b/include/linux/list_private.h new file mode 100644 index 000000000000..6f93d54e797a --- /dev/null +++ b/include/linux/list_private.h @@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ +#ifndef _LINUX_LIST_PRIVATE_H +#define _LINUX_LIST_PRIVATE_H + +/** + * DOC: Private List Primitives + * + * Provides a set of list primitives identical in function to those in + * ````, but designed for cases where the embedded + * ``&struct list_head`` is private member. + */ + +#include +#include + +#define __list_private_offset(type, member) \ + ((size_t)(&ACCESS_PRIVATE(((type *)0), member))) + +/** + * list_private_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the identifier passed to ACCESS_PRIVATE. + */ +#define list_private_entry(ptr, type, member) ({ \ + const struct list_head *__mptr =3D (ptr); \ + (type *)((char *)__mptr - __list_private_offset(type, member)); \ +}) + +/** + * list_private_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the identifier passed to ACCESS_PRIVATE. + */ +#define list_private_first_entry(ptr, type, member) \ + list_private_entry((ptr)->next, type, member) + +/** + * list_private_last_entry - get the last element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the identifier passed to ACCESS_PRIVATE. + */ +#define list_private_last_entry(ptr, type, member) \ + list_private_entry((ptr)->prev, type, member) + +/** + * list_private_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_private_next_entry(pos, member) \ + list_private_entry(ACCESS_PRIVATE(pos, member).next, typeof(*(pos)), memb= er) + +/** + * list_private_next_entry_circular - get the next element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the last element (return the first element). + * Note, that list is expected to be not empty. + */ +#define list_private_next_entry_circular(pos, head, member) \ + (list_is_last(&ACCESS_PRIVATE(pos, member), head) ? \ + list_private_first_entry(head, typeof(*(pos)), member) : \ + list_private_next_entry(pos, member)) + +/** + * list_private_prev_entry - get the prev element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_private_prev_entry(pos, member) \ + list_private_entry(ACCESS_PRIVATE(pos, member).prev, typeof(*(pos)), memb= er) + +/** + * list_prev_entry_circular - get the prev element in list + * @pos: the type * to cursor. + * @head: the list head to take the element from. + * @member: the name of the list_head within the struct. + * + * Wraparound if pos is the first element (return the last element). + * Note, that list is expected to be not empty. + */ +#define list_private_prev_entry_circular(pos, head, member) \ + (list_is_first(&ACCESS_PRIVATE(pos, member), head) ? \ + list_private_last_entry(head, typeof(*(pos)), member) : \ + list_private_prev_entry(pos, member)) + +/** + * list_private_entry_is_head - test if the entry points to the head of th= e list + * @pos: the type * to cursor + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_private_entry_is_head(pos, head, member) \ + list_is_head(&ACCESS_PRIVATE(pos, member), (head)) + +/** + * list_private_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_private_for_each_entry(pos, head, member) \ + for (pos =3D list_private_first_entry(head, typeof(*pos), member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_next_entry(pos, member)) + +/** + * list_private_for_each_entry_reverse - iterate backwards over list of gi= ven type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_private_for_each_entry_reverse(pos, head, member) \ + for (pos =3D list_private_last_entry(head, typeof(*pos), member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_prev_entry(pos, member)) + +/** + * list_private_for_each_entry_continue - continue iteration over list of = given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_private_for_each_entry_continue(pos, head, member) \ + for (pos =3D list_private_next_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_next_entry(pos, member)) + +/** + * list_private_for_each_entry_continue_reverse - iterate backwards from t= he given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_private_for_each_entry_continue_reverse(pos, head, member) \ + for (pos =3D list_private_prev_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_prev_entry(pos, member)) + +/** + * list_private_for_each_entry_from - iterate over list of given type from= the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_private_for_each_entry_from(pos, head, member) \ + for (; !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_next_entry(pos, member)) + +/** + * list_private_for_each_entry_from_reverse - iterate backwards over list = of given type + * from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, continuing from current posi= tion. + */ +#define list_private_for_each_entry_from_reverse(pos, head, member) \ + for (; !list_private_entry_is_head(pos, head, member); \ + pos =3D list_private_prev_entry(pos, member)) + +/** + * list_private_for_each_entry_safe - iterate over list of given type safe= against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_private_for_each_entry_safe(pos, n, head, member) \ + for (pos =3D list_private_first_entry(head, typeof(*pos), member), \ + n =3D list_private_next_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D n, n =3D list_private_next_entry(n, member)) + +/** + * list_private_for_each_entry_safe_continue - continue list iteration saf= e against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_private_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos =3D list_private_next_entry(pos, member), \ + n =3D list_private_next_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D n, n =3D list_private_next_entry(n, member)) + +/** + * list_private_for_each_entry_safe_from - iterate over list from current = point safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_private_for_each_entry_safe_from(pos, n, head, member) \ + for (n =3D list_private_next_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D n, n =3D list_private_next_entry(n, member)) + +/** + * list_private_for_each_entry_safe_reverse - iterate backwards over list = safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_private_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos =3D list_private_last_entry(head, typeof(*pos), member), \ + n =3D list_private_prev_entry(pos, member); \ + !list_private_entry_is_head(pos, head, member); \ + pos =3D n, n =3D list_private_prev_entry(n, member)) + +/** + * list_private_safe_reset_next - reset a stale list_for_each_entry_safe l= oop + * @pos: the loop cursor used in the list_for_each_entry_safe loop + * @n: temporary storage used in list_for_each_entry_safe + * @member: the name of the list_head within the struct. + * + * list_safe_reset_next is not safe to use in general if the list may be + * modified concurrently (eg. the lock is dropped in the loop body). An + * exception to this is if the cursor element (pos) is pinned in the list, + * and list_safe_reset_next is called after re-taking the lock and before + * completing the current iteration of the loop body. + */ +#define list_private_safe_reset_next(pos, n, member) \ + n =3D list_private_next_entry(pos, member) + +#endif /* _LINUX_LIST_PRIVATE_H */ --=20 2.52.0.487.g5c8c507ade-goog From nobody Mon Dec 1 23:07:04 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 From nobody Mon Dec 1 23:07:04 2025 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (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 41B8833F363 for ; Wed, 26 Nov 2025 18:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183455; cv=none; b=jJOMW6YUX+3wESsy/nZsbaCdz9lBMZ5JkX6BeC42dT+k4i7n2XI9Radtjb3I1dgd/dNksnxOzdtZ15x3TMGcx7sNrmKyaXuKP23r4C4nGM5ygetBsGSpKwbWBEZ57Gtqe8rEL7l/QMFmB6DL3IW8raZduvNAyba4lrDp6vXR+Ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764183455; c=relaxed/simple; bh=fbBtS9Y1mVSWtFYG8bC2W6XeZU0LP5uWZoGlle1YCdE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EjEBpoXvZN/junpkiJN8fMBZy898VqKiGlbbnzQ7wIzleDK1OO5tCgajxPbF7dMoX2tTQz+icJ5ogo8oAkdHSW91l7huiKoL3KtKS/cjlrDqzEXPIcS8RWL25AE3kjE7KNFEXVAMBf/P9haAAKaGCf+p6b3dNPIEmvJPvoFos6o= 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=JhlnHQOZ; arc=none smtp.client-ip=74.125.224.41 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="JhlnHQOZ" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-6432842cafdso88019d50.2 for ; Wed, 26 Nov 2025 10:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1764183453; x=1764788253; 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=1oylsZzHxgSZmbIVeALsxMTslnUgs+7hP6L3oGrSRE4=; b=JhlnHQOZturhy5G/GJ0fhe9qMittRwsPeWh6j5Q93uqDTmREGR+ypzagN2Q8/LKWXW hwcmDzL62lyAAfiYnfiQU5w2C/eEbfa8PQFzH9UquzQq2wXMBQDa2mGLA8f65NAkLjqv CYXclpApm/kAd45RqgoZVv+01mf2Wr/8jDhmbjW5isVqxjeJtFScTF6tDDrADrbtkSUz vpD5q/1CDhH6pi6u0mHVnSsLqPbDzXCzWFOSsoZWhSPdxLcbayIeNS9XXGD5vAczihiR gZuo/oF+4koYg1R7YRL/9gaGSz2qr80nk7h9HEylexqaNjNy3MfN0Q91jvUNrfd96sHN LG7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764183453; x=1764788253; 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=1oylsZzHxgSZmbIVeALsxMTslnUgs+7hP6L3oGrSRE4=; b=oOeVYlmKpyFXTQkXDAofu4QWlGEzh0OwNaIu9SqomQhamjV5S+OUa1rROnD+p6GsMg 6AS6VWOy983jLAsD3rJQ6vBz73MogDi/YjwrzY5soC5IlqcWZV1xCFMGetYLpmXnJnvR 6E9KrxUR+MPWW/b0OphJHTJvY6y53daiXVNaJIn4bjQvAA0yN8gplmQY1wgj29QE2V2j JH7gnliKPAf1WZUSzXoufadRSZNn2lg2id8SSEMFhafJq7LEEkfFRX/9B/WUb3sR3146 LnIeJ3Td7rm8AruaJK3g2V3M0bRSgbYlAQ5CLgpzl6OdS9/YXHMNrH0eQ54qAM0I15O5 eYDQ== X-Forwarded-Encrypted: i=1; AJvYcCWgQOJj+l9qjAanIPIiMR5Ylp6HnsSG2mcFZuZcbAe/Xh99+JSx7MMJGLfmnuBVrumyR53N4VFbaNdN+PI=@vger.kernel.org X-Gm-Message-State: AOJu0YzlU8KDes5ydyk7LpwLYNmP3aRd5F7HVbh1C39olpGs4mtfaU+1 4Xk0AKKWwSggd9RJRtSYMvZEUE6DMexiV69muxyy+pgeUy+pfpBeGw2yBRixePgICdM= X-Gm-Gg: ASbGncvmoSiYTcsi2kIPQy6Njq6b3t+yGC6zPHmnfyXIBGIGwwxlUSqfDwOvRz9rZfc iClYtjtJtctkJ6xBs3CpnEo3J5ESTb1e79BEQfEbejZmn57sjWlNlTN4iOyiL4Ez1cJ2vU80+8d vRwNzBJqcMBXIpb0Uz8yKHRY+5UsBOjjJsoao9gAa9fQFDI0fJ84/+03vWyMTJE7L9FcouNDXpM tONmF8I/da/mkzuMEsM4Yjj6fKT1P/Dfjr55v0V/s3XuENdYIAiWqrphSNgwcrjA6r2M1JygR5P xfxWP4Kd4EB/sHsNPMjUd/OAeXya/l1ajkrfHlm/V0Edol4i8LWAGjCw4sr8zDhhMUWdjJXdqvP IBXDexNC/VwajEp4gsQMIxJEDgeKtVPBp4riyvHcL3Y0ff0bgycWug4AMPw40ilaNW1stvhJTty mr2iODMnE36pHn6s/qz65U4wOkkqGXGV4M4FRcjC6fXYmryDezG/7zHZIPkppkKt+cGkQMeLobm eLNWBU= X-Google-Smtp-Source: AGHT+IGh8g5413JLIZ5YQT+ZmThIIEoq9as1A69vg1Sj/F5GWrIm6uWyotiHcJrmkWo4Rj0KSPIvqA== X-Received: by 2002:a53:d84e:0:b0:640:db91:33d4 with SMTP id 956f58d0204a3-64302aafecfmr11761450d50.26.1764183453023; Wed, 26 Nov 2025 10:57:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 10:57:32 -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 3/3] liveupdate: luo_file: Use private list Date: Wed, 26 Nov 2025 13:57:25 -0500 Message-ID: <20251126185725.4164769-4-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" Switch LUO to use the private list iterators. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_file.c | 7 ++++--- kernel/liveupdate/luo_internal.h | 7 ------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index ddff87917b21..c3af22fc2fd8 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -104,6 +104,7 @@ #include #include #include +#include #include #include #include @@ -273,7 +274,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u6= 4 token, int fd) goto err_fput; =20 err =3D -ENOENT; - luo_list_for_each_private(fh, &luo_file_handler_list, list) { + list_private_for_each_entry(fh, &luo_file_handler_list, list) { if (fh->ops->can_preserve(fh, file)) { err =3D 0; break; @@ -757,7 +758,7 @@ int luo_file_deserialize(struct luo_file_set *file_set, bool handler_found =3D false; struct luo_file *luo_file; =20 - luo_list_for_each_private(fh, &luo_file_handler_list, list) { + list_private_for_each_entry(fh, &luo_file_handler_list, list) { if (!strcmp(fh->compatible, file_ser[i].compatible)) { handler_found =3D true; break; @@ -832,7 +833,7 @@ int liveupdate_register_file_handler(struct liveupdate_= file_handler *fh) return -EBUSY; =20 /* Check for duplicate compatible strings */ - luo_list_for_each_private(fh_iter, &luo_file_handler_list, list) { + list_private_for_each_entry(fh_iter, &luo_file_handler_list, list) { if (!strcmp(fh_iter->compatible, fh->compatible)) { pr_err("File handler registration failed: Compatible string '%s' alread= y registered.\n", fh->compatible); diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index c8973b543d1d..3f1e0c94637e 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -40,13 +40,6 @@ static inline int luo_ucmd_respond(struct luo_ucmd *ucmd, */ #define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__) =20 -/* Mimics list_for_each_entry() but for private list head entries */ -#define luo_list_for_each_private(pos, head, member) \ - for (struct list_head *__iter =3D (head)->next; \ - __iter !=3D (head) && \ - ({ pos =3D container_of(__iter, typeof(*(pos)), member); 1; }); \ - __iter =3D __iter->next) - /** * struct luo_file_set - A set of files that belong to the same sessions. * @files_list: An ordered list of files associated with this session, it = is --=20 2.52.0.487.g5c8c507ade-goog