浏览代码

vhost: lock receive queue, not the socket

vhost takes a sock lock to try and prevent
the skb from being pulled from the receive queue
after skb_peek.  However this is not the right lock to use for that,
sk_receive_queue.lock is. Fix that up.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Jason Wang 14 年之前
父节点
当前提交
783e398854
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      drivers/vhost/net.c

+ 4 - 3
drivers/vhost/net.c

@@ -213,12 +213,13 @@ static int peek_head_len(struct sock *sk)
 {
 {
 	struct sk_buff *head;
 	struct sk_buff *head;
 	int len = 0;
 	int len = 0;
+	unsigned long flags;
 
 
-	lock_sock(sk);
+	spin_lock_irqsave(&sk->sk_receive_queue.lock, flags);
 	head = skb_peek(&sk->sk_receive_queue);
 	head = skb_peek(&sk->sk_receive_queue);
-	if (head)
+	if (likely(head))
 		len = head->len;
 		len = head->len;
-	release_sock(sk);
+	spin_unlock_irqrestore(&sk->sk_receive_queue.lock, flags);
 	return len;
 	return len;
 }
 }