public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org,
	pabeni@redhat.com, edumazet@google.com, fw@strlen.de,
	horms@kernel.org
Subject: [PATCH net 12/14] rculist: add list_splice_rcu() for private lists
Date: Thu, 16 Apr 2026 03:30:59 +0200	[thread overview]
Message-ID: <20260416013101.221555-13-pablo@netfilter.org> (raw)
In-Reply-To: <20260416013101.221555-1-pablo@netfilter.org>

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 <paulmck@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/linux/rculist.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 2abba7552605..e3bc44225692 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -261,6 +261,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.47.3


  parent reply	other threads:[~2026-04-16  1:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16  1:30 [PATCH net 00/14] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 01/14] netfilter: nft_fwd_netdev: use recursion counter in neigh egress path Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 02/14] netfilter: nf_conntrack_sip: add bounds-checked port parsing helper Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 03/14] netfilter: arp_tables: fix IEEE1394 ARP payload parsing in arp_packet_match() Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 04/14] netfilter: nfnetlink_osf: fix divide-by-zero in OSF_WSS_MODULO Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 05/14] netfilter: nft_osf: restrict it to ipv4 Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 06/14] netfilter: nf_flow_table_ip: Introduce nf_flow_vlan_push() Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 07/14] netfilter: conntrack: remove sprintf usage Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 08/14] netfilter: xtables: restrict several matches to inet family Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 09/14] netfilter: nat: use kfree_rcu to release ops Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 10/14] ipvs: fix MTU check for GSO packets in tunnel mode Pablo Neira Ayuso
2026-04-16  1:30 ` [PATCH net 11/14] netfilter: nf_tables: use list_del_rcu for netlink hooks Pablo Neira Ayuso
2026-04-16  1:30 ` Pablo Neira Ayuso [this message]
2026-04-16  1:31 ` [PATCH net 13/14] netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase Pablo Neira Ayuso
2026-04-16  1:31 ` [PATCH net 14/14] netfilter: nf_tables: add hook transactions for device deletions Pablo Neira Ayuso
2026-04-16 11:36   ` Paolo Abeni
2026-04-16  7:25 ` [PATCH net 00/14] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2026-04-16 10:20   ` Pablo Neira Ayuso
2026-04-16 10:40     ` Florian Westphal
2026-04-16 12:49       ` Fernando Fernandez Mancera
2026-04-16 13:14         ` Florian Westphal
2026-04-16 13:37           ` Fernando Fernandez Mancera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260416013101.221555-13-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox