Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01c445a4 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'soreuseport-mixed-v4-v6-fixes'



Craig Gallek says:

====================
Fixes for SO_REUSEPORT and mixed v4/v6 sockets

Recent changes to the datastructures associated with SO_REUSEPORT broke
an existing behavior when equivalent SO_REUSEPORT sockets are created
using both AF_INET and AF_INET6.  This patch series restores the previous
behavior and includes a test to validate it.

This series should be a trivial merge to stable kernels (if deemed
necessary), but will have conflicts in net-next.  The following patches
recently replaced the use of hlist_nulls with hlists for UDP and TCP
socket lists:
ca065d0c ("udp: no longer use SLAB_DESTROY_BY_RCU")
3b24d854 ("tcp/dccp: do not touch listener sk_refcnt under synflood")

If this series is accepted, I will send an RFC for the net-next change
to assist with the merge.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c5b5343c d6a61f80
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -98,6 +98,45 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
	if (!is_a_nulls(first))
		first->pprev = &n->next;
}

/**
 * hlist_nulls_add_tail_rcu
 * @n: the element to add to the hash list.
 * @h: the list to add to.
 *
 * Description:
 * Adds the specified element to the end of the specified hlist_nulls,
 * while permitting racing traversals.  NOTE: tail insertion requires
 * list traversal.
 *
 * The caller must take whatever precautions are necessary
 * (such as holding appropriate locks) to avoid racing
 * with another list-mutation primitive, such as hlist_nulls_add_head_rcu()
 * or hlist_nulls_del_rcu(), running on this same list.
 * However, it is perfectly legal to run concurrently with
 * the _rcu list-traversal primitives, such as
 * hlist_nulls_for_each_entry_rcu(), used to prevent memory-consistency
 * problems on Alpha CPUs.  Regardless of the type of CPU, the
 * list-traversal primitive must be guarded by rcu_read_lock().
 */
static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
					struct hlist_nulls_head *h)
{
	struct hlist_nulls_node *i, *last = NULL;

	for (i = hlist_nulls_first_rcu(h); !is_a_nulls(i);
	     i = hlist_nulls_next_rcu(i))
		last = i;

	if (last) {
		n->next = last->next;
		n->pprev = &last->next;
		rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
	} else {
		hlist_nulls_add_head_rcu(n, h);
	}
}

/**
 * hlist_nulls_for_each_entry_rcu - iterate over rcu list of given type
 * @tpos:	the type * to use as a loop cursor.
+5 −1
Original line number Diff line number Diff line
@@ -630,6 +630,10 @@ static inline void sk_add_node_rcu(struct sock *sk, struct hlist_head *list)

static inline void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list)
{
	if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport &&
	    sk->sk_family == AF_INET6)
		hlist_nulls_add_tail_rcu(&sk->sk_nulls_node, list);
	else
		hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list);
}

+7 −2
Original line number Diff line number Diff line
@@ -339,6 +339,11 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,

		hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
		spin_lock(&hslot2->lock);
		if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport &&
			sk->sk_family == AF_INET6)
			hlist_nulls_add_tail_rcu(&udp_sk(sk)->udp_portaddr_node,
						 &hslot2->head);
		else
			hlist_nulls_add_head_rcu(&udp_sk(sk)->udp_portaddr_node,
						 &hslot2->head);
		hslot2->count++;
+1 −0
Original line number Diff line number Diff line
@@ -3,3 +3,4 @@ psock_fanout
psock_tpacket
reuseport_bpf
reuseport_bpf_cpu
reuseport_dualstack
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ CFLAGS = -Wall -O2 -g

CFLAGS += -I../../../../usr/include/

NET_PROGS = socket psock_fanout psock_tpacket reuseport_bpf reuseport_bpf_cpu
NET_PROGS = socket psock_fanout psock_tpacket reuseport_bpf reuseport_bpf_cpu reuseport_dualstack

all: $(NET_PROGS)
%: %.c
Loading