mirror of
https://github.com/torvalds/linux.git
synced 2024-12-24 20:01:55 +00:00
af_unix: Move spin_lock() in manage_oob().
When OOB skb has been already consumed, manage_oob() returns the next skb if exists. In such a case, we need to fall back to the else branch below. Then, we want to keep holding spin_lock(&sk->sk_receive_queue.lock). Let's move it out of if-else branch and add lightweight check before spin_lock() for major use cases without OOB skb. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20240905193240.17565-4-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
beb2c5f19b
commit
a0264a9f51
@ -2657,9 +2657,12 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
|
|||||||
struct sk_buff *read_skb = NULL, *unread_skb = NULL;
|
struct sk_buff *read_skb = NULL, *unread_skb = NULL;
|
||||||
struct unix_sock *u = unix_sk(sk);
|
struct unix_sock *u = unix_sk(sk);
|
||||||
|
|
||||||
if (!unix_skb_len(skb)) {
|
if (likely(unix_skb_len(skb) && skb != READ_ONCE(u->oob_skb)))
|
||||||
spin_lock(&sk->sk_receive_queue.lock);
|
return skb;
|
||||||
|
|
||||||
|
spin_lock(&sk->sk_receive_queue.lock);
|
||||||
|
|
||||||
|
if (!unix_skb_len(skb)) {
|
||||||
if (copied && (!u->oob_skb || skb == u->oob_skb)) {
|
if (copied && (!u->oob_skb || skb == u->oob_skb)) {
|
||||||
skb = NULL;
|
skb = NULL;
|
||||||
} else if (flags & MSG_PEEK) {
|
} else if (flags & MSG_PEEK) {
|
||||||
@ -2670,14 +2673,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
|
|||||||
__skb_unlink(read_skb, &sk->sk_receive_queue);
|
__skb_unlink(read_skb, &sk->sk_receive_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock(&sk->sk_receive_queue.lock);
|
goto unlock;
|
||||||
|
|
||||||
consume_skb(read_skb);
|
|
||||||
return skb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&sk->sk_receive_queue.lock);
|
|
||||||
|
|
||||||
if (skb != u->oob_skb)
|
if (skb != u->oob_skb)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
@ -2698,6 +2696,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
|
|||||||
unlock:
|
unlock:
|
||||||
spin_unlock(&sk->sk_receive_queue.lock);
|
spin_unlock(&sk->sk_receive_queue.lock);
|
||||||
|
|
||||||
|
consume_skb(read_skb);
|
||||||
kfree_skb(unread_skb);
|
kfree_skb(unread_skb);
|
||||||
|
|
||||||
return skb;
|
return skb;
|
||||||
|
Loading…
Reference in New Issue
Block a user