Skip to contentSkip to conversation

xen/netback: avoid race in xenvif_rx_ring_slots_available()

PATCH In review Juergen Gross 4 participants 7 messages Feb 2, 2021 – Feb 5, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/netback: avoid race in xenvif_rx_ring_slots_available()

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")
---
 drivers/net/xen-netback/rx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/xen-netback/rx.c +8 -1
index b8febe1d1bfd..accc991d153f 100644
@@ -38,10 +38,15 @@ static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue)
 	RING_IDX prod, cons;
 	struct sk_buff *skb;
 	int needed;
+	unsigned long flags;
+
+	spin_lock_irqsave(&queue->rx_queue.lock, flags);
 
 	skb = skb_peek(&queue->rx_queue);
-	if (!skb)
+	if (!skb) {
+		spin_unlock_irqrestore(&queue->rx_queue.lock, flags);
 		return false;
+	}
 
 	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
 	if (skb_is_gso(skb))
@@ -49,6 +54,8 @@ static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue)
 	if (skb->sw_hash)
 		needed++;
 
+	spin_unlock_irqrestore(&queue->rx_queue.lock, flags);
+
 	do {
 		prod = queue->rx.sring->req_prod;
 		cons = queue->rx.req_cons;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 9 lines · Juergen Gross

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")

Appreciate a quick fix! Is this the only place that sort of race could happen now?

Igor

#2 lore raw
Quoted 6 lines · Igor Druzhinin
Quoted 5 lines · Juergen Gross

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Quoted 7 lines
Quoted 4 lines
Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")

Appreciate a quick fix! Is this the only place that sort of race could happen now?

I checked and didn't find any other similar problem.

Juergen

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Juergen Gross
Quoted 9 lines · Juergen Gross

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")
maintainer
#4 lore raw
In reply to Juergen Gross
Quoted 9 lines · On Tue, 2 Feb 2021 08:09:38 +0100 Juergen Gross wrote:

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")

Should we route this change via networking trees? I see the bug did not go through networking :)

#5 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Tue, 2 Feb 2021 08:09:38 +0100 Juergen Gross wrote:

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Quoted 8 lines
Quoted 4 lines
Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")

Should we route this change via networking trees? I see the bug did not go through networking :)

I'm fine with either networking or the Xen tree. It should be included in 5.11, though. So if you are willing to take it, please do so.

Juergen

maintainer
#6 lore raw
Quoted 12 lines · On Thu, 4 Feb 2021 06:32:32 +0100 Jürgen Groß wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Tue, 2 Feb 2021 08:09:38 +0100 Juergen Gross wrote:

Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held.

Fixes 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding")
Quoted 5 lines
Quoted 2 lines

Should we route this change via networking trees? I see the bug did not go through networking :)

I'm fine with either networking or the Xen tree. It should be included in 5.11, though. So if you are willing to take it, please do so.

All right, applied to net, it'll most likely hit Linus's tree on Tue.

Thanks!