Skip to content

Commit 88fd1cb

Browse files
jognessdavem330
authored andcommitted
af_packet: TPACKET_V3: fix fill status rwlock imbalance
After @blk_fill_in_prog_lock is acquired there is an early out vnet situation that can occur. In that case, the rwlock needs to be released. Also, since @blk_fill_in_prog_lock is only acquired when @tp_version is exactly TPACKET_V3, only release it on that exact condition as well. And finally, add sparse annotation so that it is clearer that prb_fill_curr_block() and prb_clear_blk_fill_status() are acquiring and releasing @blk_fill_in_prog_lock, respectively. sparse is still unable to understand the balance, but the warnings are now on a higher level that make more sense. Fixes: 632ca50 ("af_packet: TPACKET_V3: replace busy-wait loop") Signed-off-by: John Ogness <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 94c7eb5 commit 88fd1cb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

net/packet/af_packet.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ static int prb_queue_frozen(struct tpacket_kbdq_core *pkc)
941941
}
942942

943943
static void prb_clear_blk_fill_status(struct packet_ring_buffer *rb)
944+
__releases(&pkc->blk_fill_in_prog_lock)
944945
{
945946
struct tpacket_kbdq_core *pkc = GET_PBDQC_FROM_RB(rb);
946947

@@ -989,6 +990,7 @@ static void prb_fill_curr_block(char *curr,
989990
struct tpacket_kbdq_core *pkc,
990991
struct tpacket_block_desc *pbd,
991992
unsigned int len)
993+
__acquires(&pkc->blk_fill_in_prog_lock)
992994
{
993995
struct tpacket3_hdr *ppd;
994996

@@ -2286,8 +2288,11 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
22862288
if (do_vnet &&
22872289
virtio_net_hdr_from_skb(skb, h.raw + macoff -
22882290
sizeof(struct virtio_net_hdr),
2289-
vio_le(), true, 0))
2291+
vio_le(), true, 0)) {
2292+
if (po->tp_version == TPACKET_V3)
2293+
prb_clear_blk_fill_status(&po->rx_ring);
22902294
goto drop_n_account;
2295+
}
22912296

22922297
if (po->tp_version <= TPACKET_V2) {
22932298
packet_increment_rx_head(po, &po->rx_ring);
@@ -2393,7 +2398,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
23932398
__clear_bit(slot_id, po->rx_ring.rx_owner_map);
23942399
spin_unlock(&sk->sk_receive_queue.lock);
23952400
sk->sk_data_ready(sk);
2396-
} else {
2401+
} else if (po->tp_version == TPACKET_V3) {
23972402
prb_clear_blk_fill_status(&po->rx_ring);
23982403
}
23992404

0 commit comments

Comments
 (0)