Commit 3a2bb84e authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net/packet: remove locking from packet_rcv_has_room()

__packet_rcv_has_room() can now be run without lock being held.

po->pressure is only a non persistent hint, we can mark
all read/write accesses with READ_ONCE()/WRITE_ONCE()
to document the fact that the field could be written
without any synchronization.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2c51c627
...@@ -1260,15 +1260,13 @@ static int __packet_rcv_has_room(const struct packet_sock *po, ...@@ -1260,15 +1260,13 @@ static int __packet_rcv_has_room(const struct packet_sock *po,
static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb) static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
{ {
int ret; int pressure, ret;
bool has_room;
spin_lock_bh(&po->sk.sk_receive_queue.lock);
ret = __packet_rcv_has_room(po, skb); ret = __packet_rcv_has_room(po, skb);
has_room = ret == ROOM_NORMAL; pressure = ret != ROOM_NORMAL;
if (po->pressure == has_room)
po->pressure = !has_room; if (READ_ONCE(po->pressure) != pressure)
spin_unlock_bh(&po->sk.sk_receive_queue.lock); WRITE_ONCE(po->pressure, pressure);
return ret; return ret;
} }
...@@ -1353,7 +1351,7 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f, ...@@ -1353,7 +1351,7 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
i = j = min_t(int, po->rollover->sock, num - 1); i = j = min_t(int, po->rollover->sock, num - 1);
do { do {
po_next = pkt_sk(f->arr[i]); po_next = pkt_sk(f->arr[i]);
if (po_next != po_skip && !po_next->pressure && if (po_next != po_skip && !READ_ONCE(po_next->pressure) &&
packet_rcv_has_room(po_next, skb) == ROOM_NORMAL) { packet_rcv_has_room(po_next, skb) == ROOM_NORMAL) {
if (i != j) if (i != j)
po->rollover->sock = i; po->rollover->sock = i;
...@@ -3310,7 +3308,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -3310,7 +3308,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (skb == NULL) if (skb == NULL)
goto out; goto out;
if (pkt_sk(sk)->pressure) if (READ_ONCE(pkt_sk(sk)->pressure))
packet_rcv_has_room(pkt_sk(sk), NULL); packet_rcv_has_room(pkt_sk(sk), NULL);
if (pkt_sk(sk)->has_vnet_hdr) { if (pkt_sk(sk)->has_vnet_hdr) {
...@@ -4129,8 +4127,8 @@ static __poll_t packet_poll(struct file *file, struct socket *sock, ...@@ -4129,8 +4127,8 @@ static __poll_t packet_poll(struct file *file, struct socket *sock,
TP_STATUS_KERNEL)) TP_STATUS_KERNEL))
mask |= EPOLLIN | EPOLLRDNORM; mask |= EPOLLIN | EPOLLRDNORM;
} }
if (po->pressure && __packet_rcv_has_room(po, NULL) == ROOM_NORMAL) if (READ_ONCE(po->pressure) && __packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
po->pressure = 0; WRITE_ONCE(po->pressure, 0);
spin_unlock_bh(&sk->sk_receive_queue.lock); spin_unlock_bh(&sk->sk_receive_queue.lock);
spin_lock_bh(&sk->sk_write_queue.lock); spin_lock_bh(&sk->sk_write_queue.lock);
if (po->tx_ring.pg_vec) { if (po->tx_ring.pg_vec) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment