From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E74F7CDB475 for ; Mon, 22 Jun 2026 08:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bFnA4MB3rhX4hW9kwKpEDdWQh6n3FEg0cpZAkJWsmhQ=; b=1lVzCX21hCt6xqSi7RdyyZB7J6 lTbL+SBZDPLd610Z2hYL0YsSZV29T1Dku5cbuN5Nd0bKUG6u3Obdtc0r7KrqfD1qFMHz+9yU9Djbq PkcV8arbrrJFoVLSdV71pPsIVSVnaJ3OtIpRPQWcWJxyBz29+LQNF6MXtBnakf2ggxkCtfe9ECymc vxlHpQqoddVdhlZ+Sv2KCC3QNmMopV5Kyv2p0/q9vhm+9tJS3U/z351VYAnhu+p5oSfZCQzRKoYMw ttiKOlKyaaSLDyg/2X0ZwrlerekMglCdrJKYKHtYR3uPOQOxYQn+3SWyJ+NRRqsV8LLoAQmnASZA8 1CFqyaEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wbaEz-00000004gTL-3bAQ; Mon, 22 Jun 2026 08:42:49 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wbaEx-00000004gSz-0DFo for kexec@lists.infradead.org; Mon, 22 Jun 2026 08:42:48 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-46255b269c2so3112286f8f.3 for ; Mon, 22 Jun 2026 01:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782117765; x=1782722565; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=bFnA4MB3rhX4hW9kwKpEDdWQh6n3FEg0cpZAkJWsmhQ=; b=o5tbopFQpGn9tWszPgiVlcWzdIvP0hgak5VQlDmBtVVXb9v4U3qr7Jw1C+3ai0DiWF TVHl7Vj+y4Xpgkbs5QadnEpWk8gZZjnRQrvLnrO+9NH+quYlkvDv6Y4QLn0acL1TQaZ5 3fLdpQfGSv9iWTFagKI3EOIx1brS0V6AZEqEe3QTuiU18YSZP5a/hd3gOvF+gqClFr2e siG4ln2XyCa1JE+qfiMClI9/0biSbCVJvGFrC7Vza5OTgNhfGc3JZcHmgNAW2oWH8c7J BT9+QS8asWewtDmr0KZ8nn8nsMb0WzqVWXoKBouTUSdXGyV7IhZ7k+4fb6PUjtQxG/lM YbUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782117765; x=1782722565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bFnA4MB3rhX4hW9kwKpEDdWQh6n3FEg0cpZAkJWsmhQ=; b=IrSWkJ1fS3gP3y4H2p6FL6NFeLkZeG1KprMjR6Mrxr2i+6FsICCBCb6TQGvcqQWv44 jFuf6bE/A0c7HlzmY0FAdpXJgIT7OhmcA+PhyfR5n1G83Cpq5sXoDsqP/pwEpN/eudiU 3ZHBsbm5WwxIEJLGITe1JIuPL2zDF5KxzLC2h5j3QSyjO45nF+ZYhcjj5fOz7U/O7KnU vAWerW9dNolVLAlaqGQegJigGjXmyd562xkdRMmuRwItDvvL1IZnWkgpYVkrkR0H3qhg N5FMrNX7R6UAxA8MLu+dVsYh7/DsjlsjJ4ts2ZwaumppMC8Ob8WE+VpsvXl2qZUkpt21 WOgw== X-Forwarded-Encrypted: i=1; AHgh+RovnXBSx+P73f8LceSVOgse0yHNe7zUb7VXJgLcfS9cXNrGUXzwFkCKbqJMCpGbNbyorkhQdg==@lists.infradead.org X-Gm-Message-State: AOJu0Yxe7r8W8GYwV4Tsk6sDVoFhcDcGdCJ7Z3Yhi+7aIiTYmX88n1BD eDY26QV/e8YsZdMRBQ1ARN6bCp6VgqMAkegAQxQbDEI1g2/6A5Pp5RPX X-Gm-Gg: AfdE7cm6sBGii4w/ExICQ4BZ8RJeOQsBAZ+29xoFDWFu0dgH4qYfYGhP7O6mKKf8g7x rg23he3LuQpbvlHhElRCsNOmE6yDsbDLha/kl3NdEdPaOmGtBuwtf9a4FgG2RFpZVcIEH/5mTQw EEF5FS5ufAUceiwm/Yz0fwn6euGxnKA+lRuU9QzJb2T6t0RfrGBDuvmdOhGFrtQJ5eyvUFodXU8 Ey1h2LgbFW91wNtmYfWZ60gYCU9T0DPAdlgkATK8H5aqAYiTjYHrZAAhOm5uO6VyoRwzclVZkbW 8DCVr4ysZvXziaEPXXQYZvjVe1gqHZRDtnIB/S48ZRgQVYXxtYiSJKH+Nwdnk4mmOo0aN446TlK /oz1ZcV9nIoNFf6036kzdR0aSOJa8CUcGRaSAwxmBZ3BCMiR8U0fFmtC/R9vx04r9djq3yg+gOq zN4hpQ3vhavYM2BoXb0uoM+tcBUMgz2Lu5k6hPWg/W3vu7StHOV59dJ1v9OAy+ X-Received: by 2002:a05:6000:2006:b0:460:1e5a:2267 with SMTP id ffacd0b85a97d-4650090b736mr21019711f8f.17.1782117764761; Mon, 22 Jun 2026 01:42:44 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46666c57afasm24839972f8f.29.2026.06.22.01.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 01:42:44 -0700 (PDT) Date: Mon, 22 Jun 2026 09:42:42 +0100 From: David Laight To: Kaitao Cheng Cc: Andrew Morton , David Hildenbrand , Jens Axboe , Tejun Heo , Alexander Viro , Christian Brauner , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Johannes Weiner , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Thomas Gleixner , Juri Lelli , Vincent Guittot , Paul Moore , Andy Shevchenko , "Paul E. McKenney" , Shakeel Butt , Christian =?UTF-8?B?S8O2bmln?= , David Howells , Simona Vetter , Randy Dunlap , Luca Ceresoli , Philipp Stanner , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, audit@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kexec@lists.infradead.org, live-patching@vger.kernel.org, linux-modules@vger.kernel.org, linux-crypto@vger.kernel.org, linux-pm@vger.kernel.org, rcu@vger.kernel.org, sched-ext@lists.linux.dev, linux-mm@kvack.org, virtualization@lists.linux.dev, damon@lists.linux.dev, llvm@lists.linux.dev, Kaitao Cheng Subject: Re: [PATCH v3 1/7] list: Add mutable iterator variants Message-ID: <20260622094242.64531b9a@pumpkin> In-Reply-To: <20260622040533.29824-2-kaitao.cheng@linux.dev> References: <20260622040533.29824-1-kaitao.cheng@linux.dev> <20260622040533.29824-2-kaitao.cheng@linux.dev> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260622_014247_147954_61F862B7 X-CRM114-Status: GOOD ( 30.39 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org On Mon, 22 Jun 2026 12:05:31 +0800 Kaitao Cheng wrote: > From: Kaitao Cheng > > The list_for_each*_safe() helpers are used when the loop body may > remove the current entry. Their API exposes the temporary cursor at > every call site, even though most users only need it for the iterator > implementation and never reference it in the loop body. > > Add *_mutable() variants for list and hlist iteration. The new helpers > support both forms: callers may keep passing an explicit temporary cursor > when they need to inspect or reset it, or omit it and let the helper use > a unique internal cursor. I'm not really sure 'mutable' means anything either. It is possible to make it valid for the loop body (or even other threads) to delete arbitrary list items - but that needs significant extra overheads. It might be worth doing something that doesn't need the extra variable, but there is little point doing all the churn just to rename things. > > This makes call sites that only mutate the list through the current entry > less noisy, while keeping the existing *_safe() helpers available for > compatibility. > > Signed-off-by: Kaitao Cheng > --- > include/linux/list.h | 269 +++++++++++++++++++++++++++++++++++++------ > 1 file changed, 231 insertions(+), 38 deletions(-) > > diff --git a/include/linux/list.h b/include/linux/list.h > index 09d979976b3b..1081def7cea9 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > > #include > > @@ -763,28 +764,72 @@ static inline void list_splice_tail_init(struct list_head *list, > #define list_for_each_prev(pos, head) \ > for (pos = (head)->prev; !list_is_head(pos, (head)); pos = pos->prev) > > -/** > - * list_for_each_safe - iterate over a list safe against removal of list entry > - * @pos: the &struct list_head to use as a loop cursor. > - * @n: another &struct list_head to use as temporary storage > - * @head: the head for your list. > +/* > + * list_for_each_safe is an old interface, use list_for_each_mutable instead. > */ > #define list_for_each_safe(pos, n, head) \ > for (pos = (head)->next, n = pos->next; \ > !list_is_head(pos, (head)); \ > pos = n, n = pos->next) > > +#define __list_for_each_mutable_internal(pos, tmp, head) \ > + for (typeof(pos) tmp = (pos = (head)->next)->next; \ Use auto > + !list_is_head(pos, (head)); \ > + pos = tmp, tmp = pos->next) > + > +#define __list_for_each_mutable1(pos, head) \ > + __list_for_each_mutable_internal(pos, __UNIQUE_ID(next), head) > + > +#define __list_for_each_mutable2(pos, next, head) \ > + list_for_each_safe(pos, next, head) > + > /** > - * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry > + * list_for_each_mutable - iterate over a list safe against entry removal > * @pos: the &struct list_head to use as a loop cursor. > - * @n: another &struct list_head to use as temporary storage > - * @head: the head for your list. > + * @...: either (head) or (next, head) > + * > + * next: another &struct list_head to use as optional temporary storage. > + * The temporary cursor is internal unless explicitly supplied by > + * the caller. > + * head: the head for your list. > + */ > +#define list_for_each_mutable(pos, ...) \ > + CONCATENATE(__list_for_each_mutable, COUNT_ARGS(__VA_ARGS__)) \ > + (pos, __VA_ARGS__) The variable argument count logic really just slows down compilation. Maybe there aren't enough copies of this code to make that significant. But just because you can do it doesn't mean it is a gooD idea. I'm also not sure it really adds anything to the readability. And, it you are going to make the middle argument optional there is no need to change the macro name. David