From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F5FE51EDE8; Wed, 30 Sep 2026 17:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789500; cv=none; b=E4rpP3cRbaOtARvF+3DUlaj5gsKLyRFYem7vne+r9b8QaZe/Egr5Td4jy33evZAjEJHj98kzu9U236rNr+l+tLhkt0fY3tBJ19+fojlBFOq+z7MszNS/M2y6JSJfGA3hZukFl5n/hp7MBoISwymqQqawrCkAb/heABhRha7aF7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789500; c=relaxed/simple; bh=NSmkMzzGvqdlMeJyfUsgP+46SsFJVPyRuhZv/++0HKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G//Xbu6eusa7NkH7PbvXfaegDa7fphzJXzbp0hKxN4zrV1hCN/lnGnB4RdPd0miCJfaUwQ4xn2lNLcDqL3cCi5Di6MEMiaq9FG8UXlb4aZNObIjQL0Fks06HtmH39pTgd6/E9lkw7QKgywyOCXJcgsYZuVxaxnVfjjq3Cty4o7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V1tKqWFf; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="V1tKqWFf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 897E71F000FF; Wed, 30 Sep 2026 17:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790789499; bh=Zj7QSJvTA6jlwO8w1UpfdVsZRNKfGtI7Zo/yamIJq2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V1tKqWFf6D4f2F8jkFOOxUr+r2zYxg+lj3OaX7ATHSILkSL8clhnMumF+59W3EYKt vJvJ73o+Xx3tByDs9WgBa+vaulKIqzov4WZnGip6XVzXpR+L7eMvsaCICIM0bLu4c5 dvEy1fr3p5MZqHUjGVZU4RmjeT/T0weBRbTiszvE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Paul E. McKenney" , Pablo Neira Ayuso , "Benjamin Robin (Schneider Electric)" , Sasha Levin Subject: [PATCH 6.12 454/877] rculist: add list_splice_rcu() for private lists Date: Wed, 30 Sep 2026 17:22:45 +0200 Message-ID: <20260930152424.476583694@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152414.738996857@linuxfoundation.org> References: <20260930152414.738996857@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pablo Neira Ayuso [ Upstream commit f902877b635551513729bdf9a8d1422c4aab7741 ] This patch adds a helper function, list_splice_rcu(), to safely splice a private (non-RCU-protected) list into an RCU-protected list. The function ensures that only the pointer visible to RCU readers (prev->next) is updated using rcu_assign_pointer(), while the rest of the list manipulations are performed with regular assignments, as the source list is private and not visible to concurrent RCU readers. This is useful for moving elements from a private list into a global RCU-protected list, ensuring safe publication for RCU readers. Subsystems with some sort of batching mechanism from userspace can benefit from this new function. The function __list_splice_rcu() has been added for clarity and to follow the same pattern as in the existing list_splice*() interfaces, where there is a check to ensure that the list to splice is not empty. Note that __list_splice_rcu() has no documentation for this reason. Reviewed-by: Paul E. McKenney Signed-off-by: Pablo Neira Ayuso Signed-off-by: Benjamin Robin (Schneider Electric) Signed-off-by: Sasha Levin --- include/linux/rculist.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/rculist.h b/include/linux/rculist.h index 14dfa6008467e..2e4d990f07ad4 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -207,6 +207,35 @@ static inline void list_replace_rcu(struct list_head *old, old->prev = LIST_POISON2; } +static inline void __list_splice_rcu(struct list_head *list, + struct list_head *prev, + struct list_head *next) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + + last->next = next; + first->prev = prev; + next->prev = last; + rcu_assign_pointer(list_next_rcu(prev), first); +} + +/** + * list_splice_rcu - splice a non-RCU list into an RCU-protected list, + * designed for stacks. + * @list: the non RCU-protected list to splice + * @head: the place in the existing RCU-protected list to splice + * + * The list pointed to by @head can be RCU-read traversed concurrently with + * this function. + */ +static inline void list_splice_rcu(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice_rcu(list, head, head->next); +} + /** * __list_splice_init_rcu - join an RCU-protected list into an existing list. * @list: the RCU-protected list to splice -- 2.53.0