WSL2-Linux-Kernel/net/dccp
Jiri Olsa a57de0b433 net: adding memory barrier to the poll and receive callbacks
Adding memory barrier after the poll_wait function, paired with
receive callbacks. Adding fuctions sock_poll_wait and sk_has_sleeper
to wrap the memory barrier.

Without the memory barrier, following race can happen.
The race fires, when following code paths meet, and the tp->rcv_nxt
and __add_wait_queue updates stay in CPU caches.

CPU1                         CPU2

sys_select                   receive packet
  ...                        ...
  __add_wait_queue           update tp->rcv_nxt
  ...                        ...
  tp->rcv_nxt check          sock_def_readable
  ...                        {
  schedule                      ...
                                if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
                                        wake_up_interruptible(sk->sk_sleep)
                                ...
                             }

If there was no cache the code would work ok, since the wait_queue and
rcv_nxt are opposit to each other.

Meaning that once tp->rcv_nxt is updated by CPU2, the CPU1 either already
passed the tp->rcv_nxt check and sleeps, or will get the new value for
tp->rcv_nxt and will return with new data mask.
In both cases the process (CPU1) is being added to the wait queue, so the
waitqueue_active (CPU2) call cannot miss and will wake up CPU1.

The bad case is when the __add_wait_queue changes done by CPU1 stay in its
cache, and so does the tp->rcv_nxt update on CPU2 side.  The CPU1 will then
endup calling schedule and sleep forever if there are no more data on the
socket.

Calls to poll_wait in following modules were ommited:
	net/bluetooth/af_bluetooth.c
	net/irda/af_irda.c
	net/irda/irnet/irnet_ppp.c
	net/mac80211/rc80211_pid_debugfs.c
	net/phonet/socket.c
	net/rds/af_rds.c
	net/rfkill/core.c
	net/sunrpc/cache.c
	net/sunrpc/rpc_pipe.c
	net/tipc/socket.c

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-07-09 17:06:57 -07:00
..
ccids dccp ccid-3: Fix RFC reference 2009-01-11 00:17:22 -08:00
Kconfig dccp: Lockless integration of CCID congestion-control plugins 2009-01-04 21:42:53 -08:00
Makefile dccp: Integrate the TFRC library with DCCP 2009-01-04 21:45:33 -08:00
ackvec.c dccp: Set per-connection CCIDs via socket options 2008-11-23 16:02:31 -08:00
ackvec.h dccp: Minimise header option overhead in setting the MPS 2009-03-02 03:07:23 -08:00
ccid.c dccp: Integrate the TFRC library with DCCP 2009-01-04 21:45:33 -08:00
ccid.h dccp: Clean up ccid.c after integration of CCID plugins 2009-01-04 21:43:23 -08:00
dccp.h dccp: Do not let initial option overhead shrink the MPS 2009-03-02 03:07:23 -08:00
diag.c dccp_diag: LISTEN sockets don't have CCIDs 2008-12-17 16:08:01 -08:00
feat.c dccp: Debugging functions for feature negotiation 2009-01-21 14:34:05 -08:00
feat.h dccp: Debugging functions for feature negotiation 2009-01-21 14:34:05 -08:00
input.c dccp: Integrate the TFRC library with DCCP 2009-01-04 21:45:33 -08:00
ipv4.c net: skb->dst accessors 2009-06-03 02:51:04 -07:00
ipv6.c ipv6: Use correct data types for ICMPv6 type and code 2009-06-23 04:31:07 -07:00
ipv6.h Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
minisocks.c dccp: Implement both feature-local and feature-remote Sequence Window feature 2009-01-21 14:34:04 -08:00
options.c dccp: Debugging functions for feature negotiation 2009-01-21 14:34:05 -08:00
output.c net: adding memory barrier to the poll and receive callbacks 2009-07-09 17:06:57 -07:00
probe.c dccp: API to query the current TX/RX CCID 2008-11-23 16:04:59 -08:00
proto.c net: adding memory barrier to the poll and receive callbacks 2009-07-09 17:06:57 -07:00
sysctl.c dccp: Initialisation and type-checking of feature sysctls 2009-01-21 14:34:05 -08:00
timer.c dccp: Limit feature negotiation to connection setup phase 2008-11-12 00:42:58 -08:00