Skip to contentSkip to conversation

xen-netback: synchronisation between core driver and netback

PATCH Superseded Wei Liu 4 participants 45 messages Aug 8, 2014 – Aug 11, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v2 cover xen-netback: synchronisation between core driver and netback

The zero-copy netback has far more interactions with core network driver than the old copying backend. One significant thing is that netback now relies on a callback from core driver to correctly release resources.

However correct synchronisation between core driver and netback is missing. Currently netback relies on a loop to wait for core driver to release resources. This is proven not enough and erronous recently, partly due to code structure, partly due to missing synchronisation. Short-live domains like OpenMirage unikernels can easily trigger race in backend, rendering backend unresponsive.

This patch series aims to slove this issue by introducing proper synchronisation between core driver and netback.

Wei.

Change in v2: fix Zoltan's email address in commit message

Wei Liu (3):
xen-netback: move NAPI add/remove calls
xen-netback: don't stop dealloc kthread too early
xen-netback: remove loop waiting function

 drivers/net/xen-netback/common.h    |    5 +++
 drivers/net/xen-netback/interface.c |   57 +++++++++++++++--------------------
 drivers/net/xen-netback/netback.c   |   24 ++++++++++++---
 3 files changed, 49 insertions(+), 37 deletions(-)
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH v2 1/3 xen-netback: move NAPI add/remove calls

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +8 -4
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
 	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
 	return 0;
 }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 	wake_up_process(queue->task);
 	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
 	return 0;
 
 err_rx_unbind:
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}
+
+	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
 
 		if (queue->task) {
 			del_timer_sync(&queue->rx_stalled);
@@ -708,7 +713,6 @@ void xenvif_disconnect(struct xenvif *vif)
 void xenvif_deinit_queue(struct xenvif_queue *queue)
 {
 	free_xenballooned_pages(MAX_PENDING_REQS, queue->mmap_pages);
-	netif_napi_del(&queue->napi);
 }
 
 void xenvif_free(struct xenvif *vif)
Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH v2 1/3 xen-netback: move NAPI add/remove calls

In reply to Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +8 -4
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
 	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
 	return 0;
 }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 	wake_up_process(queue->task);
 	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
 	return 0;
 
 err_rx_unbind:
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}
+
+	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
 
 		if (queue->task) {
 			del_timer_sync(&queue->rx_stalled);
@@ -708,7 +713,6 @@ void xenvif_disconnect(struct xenvif *vif)
 void xenvif_deinit_queue(struct xenvif_queue *queue)
 {
 	free_xenballooned_pages(MAX_PENDING_REQS, queue->mmap_pages);
-	netif_napi_del(&queue->napi);
 }
 
 void xenvif_free(struct xenvif *vif)
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Hello.

Quoted 3 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove

netif_napi_{add|del}()?

Quoted 1 line

to _connect and _disconnect so that they reside togother

Together.

Quoted 5 lines

with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>

WBR, Sergei

#4 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Wei Liu

Hello.

Quoted 3 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove

netif_napi_{add|del}()?

Quoted 1 line

to _connect and _disconnect so that they reside togother

Together.

Quoted 5 lines

with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>

WBR, Sergei

author
#5 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 8 lines · Sergei Shtylyov

Hello.

Quoted 3 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove

Quoted 6 lines
   netif_napi_{add|del}()?
Quoted 1 line

to _connect and _disconnect so that they reside togother

Together.

Thanks, I will fix these issues.

Wei.

author
#6 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Sergei Shtylyov
Quoted 8 lines · Sergei Shtylyov

Hello.

Quoted 3 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove

Quoted 6 lines
   netif_napi_{add|del}()?
Quoted 1 line

to _connect and _disconnect so that they reside togother

Together.

Thanks, I will fix these issues.

Wei.

#7 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Wei Liu
Quoted 37 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
 	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
 	return 0;
 }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 	wake_up_process(queue->task);
 	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
 	return 0;
 
 err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

David

#8 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Wei Liu
Quoted 37 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
 	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
 	return 0;
 }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 	wake_up_process(queue->task);
 	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
 	return 0;
 
 err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

David

#9 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 47 lines · David Vrabel
Quoted 37 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
  drivers/net/xen-netback/interface.c |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
  	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
  	return 0;
  }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
  	wake_up_process(queue->task);
  	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
  	return 0;
 
  err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
  	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
  		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

Quoted 5 lines

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

And that's how they are ordered. The idea for having the netif_napi_del as a separate loop came from me: it could be more efficient to start tearing down all the NAPI instances first, so by the time we stop the dealloc thread, it is likely it already done most of the work. But now I realized that netif_napi_del just delete the instance from a list, the real thing happens in xenvif_carrier_off: xenvif_down calls napi_disable on all queues, and it waits until all the work is done. So it doesn't makes sense to have the netif_napi_del in a separate loop any more.

Quoted 3 lines

David

#10 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to David Vrabel
Quoted 47 lines · David Vrabel
Quoted 37 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
  drivers/net/xen-netback/interface.c |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
  	init_timer(&queue->rx_stalled);
 
-	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-			XENVIF_NAPI_WEIGHT);
-
  	return 0;
  }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
  	wake_up_process(queue->task);
  	wake_up_process(queue->dealloc_task);
 
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+
  	return 0;
 
  err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
  	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
  		queue = &vif->queues[queue_index];
+		netif_napi_del(&queue->napi);
+	}

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

Quoted 5 lines

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

And that's how they are ordered. The idea for having the netif_napi_del as a separate loop came from me: it could be more efficient to start tearing down all the NAPI instances first, so by the time we stop the dealloc thread, it is likely it already done most of the work. But now I realized that netif_napi_del just delete the instance from a list, the real thing happens in xenvif_carrier_off: xenvif_down calls napi_disable on all queues, and it waits until all the work is done. So it doesn't makes sense to have the netif_napi_del in a separate loop any more.

Quoted 3 lines

David

#11 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 50 lines · Zoltan Kiss
Quoted 49 lines · David Vrabel
Quoted 39 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
  drivers/net/xen-netback/interface.c |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
      init_timer(&queue->rx_stalled);
 
-    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-            XENVIF_NAPI_WEIGHT);
-
      return 0;
  }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue,
 unsigned long tx_ring_ref,
      wake_up_process(queue->task);
      wake_up_process(queue->dealloc_task);
 
+    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+            XENVIF_NAPI_WEIGHT);
+
      return 0;
 

err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
      for (queue_index = 0; queue_index < num_queues; ++queue_index) {
          queue = &vif->queues[queue_index];
+        netif_napi_del(&queue->napi);
+    }

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

Quoted 6 lines
Quoted 5 lines

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

And that's how they are ordered.

No, it isn't. Did you mistakenly look at netfront which is correctly ordered already?

You must unbind the irq handler before calling netif_napi_del() or an interrupt may occur and the handler may call napi_schedule() with a deleted instance.

David

#12 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Zoltan Kiss
Quoted 50 lines · Zoltan Kiss
Quoted 49 lines · David Vrabel
Quoted 39 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
  drivers/net/xen-netback/interface.c |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
      init_timer(&queue->rx_stalled);
 
-    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-            XENVIF_NAPI_WEIGHT);
-
      return 0;
  }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue,
 unsigned long tx_ring_ref,
      wake_up_process(queue->task);
      wake_up_process(queue->dealloc_task);
 
+    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+            XENVIF_NAPI_WEIGHT);
+
      return 0;
 

err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
      for (queue_index = 0; queue_index < num_queues; ++queue_index) {
          queue = &vif->queues[queue_index];
+        netif_napi_del(&queue->napi);
+    }

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

Quoted 6 lines
Quoted 5 lines

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

And that's how they are ordered.

No, it isn't. Did you mistakenly look at netfront which is correctly ordered already?

You must unbind the irq handler before calling netif_napi_del() or an interrupt may occur and the handler may call napi_schedule() with a deleted instance.

David

#13 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 56 lines · David Vrabel
Quoted 55 lines · Zoltan Kiss
Quoted 54 lines · David Vrabel
Quoted 39 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
   drivers/net/xen-netback/interface.c |   12 ++++++++----
   1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
       init_timer(&queue->rx_stalled);
 
-    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-            XENVIF_NAPI_WEIGHT);
-
       return 0;
   }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue,
 unsigned long tx_ring_ref,
       wake_up_process(queue->task);
       wake_up_process(queue->dealloc_task);
 
+    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+            XENVIF_NAPI_WEIGHT);
+
       return 0;
 

err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
       for (queue_index = 0; queue_index < num_queues; ++queue_index) {
           queue = &vif->queues[queue_index];
+        netif_napi_del(&queue->napi);
+    }

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

Quoted 8 lines
Quoted 1 line

And that's how they are ordered.

No, it isn't. Did you mistakenly look at netfront which is correctly ordered already?

You must unbind the irq handler before calling netif_napi_del() or an interrupt may occur and the handler may call napi_schedule() with a deleted instance.

I think xenvif_carrier_off (which call xenvif_down) does that. It is right before this new napi_del in xenvif_disconnect.

Zoli

#14 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to David Vrabel
Quoted 56 lines · David Vrabel
Quoted 55 lines · Zoltan Kiss
Quoted 54 lines · David Vrabel
Quoted 39 lines · Wei Liu

Originally napi_add was in init_queue and napi_del was in deinit_queue, while kthreads were handled in _connect and _disconnect. Move napi_add and napi_remove to _connect and _disconnect so that they reside togother with kthread operations.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
   drivers/net/xen-netback/interface.c |   12 ++++++++----
   1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/xen-netback/interface.c +3 -3
index 48a55cd..fdb4fca 100644
@@ -528,9 +528,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
 
       init_timer(&queue->rx_stalled);
 
-    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
-            XENVIF_NAPI_WEIGHT);
-
       return 0;
   }
 
@@ -618,6 +615,9 @@ int xenvif_connect(struct xenvif_queue *queue,
 unsigned long tx_ring_ref,
       wake_up_process(queue->task);
       wake_up_process(queue->dealloc_task);
 
+    netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+            XENVIF_NAPI_WEIGHT);
+
       return 0;
 

err_rx_unbind:

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 679

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -675,6 +675,11 @@ void xenvif_disconnect(struct xenvif *vif)
 
       for (queue_index = 0; queue_index < num_queues; ++queue_index) {
           queue = &vif->queues[queue_index];
+        netif_napi_del(&queue->napi);
+    }

Why have you added an additional loop over all the queues? The ordering looks wrong as well. I think you want

1. unbind from irqhandler
2. napi del
3. stop task
4. stop dealloc task
5. unmap frontend rings.

Quoted 8 lines
Quoted 1 line

And that's how they are ordered.

No, it isn't. Did you mistakenly look at netfront which is correctly ordered already?

You must unbind the irq handler before calling netif_napi_del() or an interrupt may occur and the handler may call napi_schedule() with a deleted instance.

I think xenvif_carrier_off (which call xenvif_down) does that. It is right before this new napi_del in xenvif_disconnect.

Zoli

author
#15 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Wei.

author
#16 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Zoltan Kiss

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Wei.

#17 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 2 lines · Wei Liu

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Not for now. But I would prefer it if it was re-ordered. And similarly in xenvif_down(), irq_disable() should be before napi_disable().

David

#18 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to Wei Liu
Quoted 2 lines · Wei Liu

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Not for now. But I would prefer it if it was re-ordered. And similarly in xenvif_down(), irq_disable() should be before napi_disable().

David

author
#19 lore raw

Re: [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

Quoted 7 lines · David Vrabel
Quoted 2 lines · Wei Liu

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Not for now. But I would prefer it if it was re-ordered. And similarly in xenvif_down(), irq_disable() should be before napi_disable().

Something for another day then. In any case, even if napi_disable goes before irq_disable, it's still safe if a tx interrupt takes place in between. napi_schedule has no effect on a disabled instance.

Wei.

Quoted 1 line

David

author
#20 lore raw

Re: [Xen-devel] [PATCH net v2 1/3] xen-netback: move NAPI add/remove calls

In reply to David Vrabel
Quoted 7 lines · David Vrabel
Quoted 2 lines · Wei Liu

In short, there's no need to reorder disconnect logic and no need have a dedicated loop for netif_napi_del.

Not for now. But I would prefer it if it was re-ordered. And similarly in xenvif_down(), irq_disable() should be before napi_disable().

Something for another day then. In any case, even if napi_disable goes before irq_disable, it's still safe if a tx interrupt takes place in between. napi_schedule has no effect on a disabled instance.

Wei.

Quoted 1 line

David

author
#21 lore raw

PATCH v2 2/3 xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu

Reference count the number of packets in host stack, so that we don't stop the deallocation thread too early. If not, we can end up with xenvif_free permanently waiting for deallocation thread to unmap grefs.

---
 drivers/net/xen-netback/common.h    |    5 +++++
 drivers/net/xen-netback/interface.c |   16 ++++++++++++++++
 drivers/net/xen-netback/netback.c   |   24 ++++++++++++++++++++----
 3 files changed, 41 insertions(+), 4 deletions(-)
drivers/net/xen-netback/common.h +5 -0
index ef3026f..d9b7f85 100644
@@ -165,6 +165,8 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	u16 dealloc_ring[MAX_PENDING_REQS];
 	struct task_struct *dealloc_task;
 	wait_queue_head_t dealloc_wq;
+	wait_queue_head_t inflight_wq;
+	atomic_t inflight_packets;
 
 	/* Use kthread for guest RX */
 	struct task_struct *task;
@@ -329,4 +331,7 @@ extern unsigned int xenvif_max_queues;
 extern struct dentry *xen_netback_dbg_root;
 #endif
 
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue);
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue);
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +16 -0
index fdb4fca..6488801 100644
@@ -43,6 +43,17 @@
 #define XENVIF_QUEUE_LENGTH 32
 #define XENVIF_NAPI_WEIGHT  64
 
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue)
+{
+	atomic_inc(&queue->inflight_packets);
+}
+
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue)
+{
+	if (atomic_dec_and_test(&queue->inflight_packets))
+		wake_up(&queue->inflight_wq);
+}
+
 static inline void xenvif_stop_queue(struct xenvif_queue *queue)
 {
 	struct net_device *dev = queue->vif->dev;
@@ -561,6 +572,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 
 	init_waitqueue_head(&queue->wq);
 	init_waitqueue_head(&queue->dealloc_wq);
+	init_waitqueue_head(&queue->inflight_wq);
+	atomic_set(&queue->inflight_packets, 0);
 
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +20 -4
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}
+
 /* Find the containing VIF's structure from a pointer in pending_tx_info array
  */
 static inline struct xenvif_queue *ubuf_to_queue(const struct ubuf_info *ubuf)
@@ -1525,10 +1537,13 @@ static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff *s
 	/* remove traces of mapped pages and frag_list */
 	skb_frag_list_init(skb);
 	uarg = skb_shinfo(skb)->destructor_arg;
+	/* See comment on set_skb_zerocopy */
+	if (uarg->callback == xenvif_zerocopy_callback)
+		xenvif_inc_inflight_packets(queue);
 	uarg->callback(uarg, true);
 	skb_shinfo(skb)->destructor_arg = NULL;
 
-	skb_shinfo(nskb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	set_skb_zerocopy(queue, nskb);
 	kfree_skb(nskb);
 
 	return 0;
@@ -1589,7 +1604,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 				if (net_ratelimit())
 					netdev_err(queue->vif->dev,
 						   "Not enough memory to consolidate frag_list!\n");
-				skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+				set_skb_zerocopy(queue, skb);
 				kfree_skb(skb);
 				continue;
 			}
@@ -1609,7 +1624,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 				   "Can't setup checksum in net_tx_action\n");
 			/* We have to set this flag to trigger the callback */
 			if (skb_shinfo(skb)->destructor_arg)
-				skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+				set_skb_zerocopy(queue, skb);
 			kfree_skb(skb);
 			continue;
 		}
@@ -1641,7 +1656,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 		 * skb. E.g. the __pskb_pull_tail earlier can do such thing.
 		 */
 		if (skb_shinfo(skb)->destructor_arg) {
-			skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+			set_skb_zerocopy(queue, skb);
 			queue->stats.tx_zerocopy_sent++;
 		}
 
@@ -1681,6 +1696,7 @@ void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success)
 		queue->stats.tx_zerocopy_success++;
 	else
 		queue->stats.tx_zerocopy_fail++;
+	xenvif_dec_inflight_packets(queue);
 }
 
 static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)
Signature · 1 line
1.7.10.4
author
#22 lore raw

PATCH v2 2/3 xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu

Reference count the number of packets in host stack, so that we don't stop the deallocation thread too early. If not, we can end up with xenvif_free permanently waiting for deallocation thread to unmap grefs.

---
 drivers/net/xen-netback/common.h    |    5 +++++
 drivers/net/xen-netback/interface.c |   16 ++++++++++++++++
 drivers/net/xen-netback/netback.c   |   24 ++++++++++++++++++++----
 3 files changed, 41 insertions(+), 4 deletions(-)
drivers/net/xen-netback/common.h +5 -0
index ef3026f..d9b7f85 100644
@@ -165,6 +165,8 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	u16 dealloc_ring[MAX_PENDING_REQS];
 	struct task_struct *dealloc_task;
 	wait_queue_head_t dealloc_wq;
+	wait_queue_head_t inflight_wq;
+	atomic_t inflight_packets;
 
 	/* Use kthread for guest RX */
 	struct task_struct *task;
@@ -329,4 +331,7 @@ extern unsigned int xenvif_max_queues;
 extern struct dentry *xen_netback_dbg_root;
 #endif
 
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue);
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue);
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +16 -0
index fdb4fca..6488801 100644
@@ -43,6 +43,17 @@
 #define XENVIF_QUEUE_LENGTH 32
 #define XENVIF_NAPI_WEIGHT  64
 
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue)
+{
+	atomic_inc(&queue->inflight_packets);
+}
+
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue)
+{
+	if (atomic_dec_and_test(&queue->inflight_packets))
+		wake_up(&queue->inflight_wq);
+}
+
 static inline void xenvif_stop_queue(struct xenvif_queue *queue)
 {
 	struct net_device *dev = queue->vif->dev;
@@ -561,6 +572,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 
 	init_waitqueue_head(&queue->wq);
 	init_waitqueue_head(&queue->dealloc_wq);
+	init_waitqueue_head(&queue->inflight_wq);
+	atomic_set(&queue->inflight_packets, 0);
 
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +20 -4
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}
+
 /* Find the containing VIF's structure from a pointer in pending_tx_info array
  */
 static inline struct xenvif_queue *ubuf_to_queue(const struct ubuf_info *ubuf)
@@ -1525,10 +1537,13 @@ static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff *s
 	/* remove traces of mapped pages and frag_list */
 	skb_frag_list_init(skb);
 	uarg = skb_shinfo(skb)->destructor_arg;
+	/* See comment on set_skb_zerocopy */
+	if (uarg->callback == xenvif_zerocopy_callback)
+		xenvif_inc_inflight_packets(queue);
 	uarg->callback(uarg, true);
 	skb_shinfo(skb)->destructor_arg = NULL;
 
-	skb_shinfo(nskb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	set_skb_zerocopy(queue, nskb);
 	kfree_skb(nskb);
 
 	return 0;
@@ -1589,7 +1604,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 				if (net_ratelimit())
 					netdev_err(queue->vif->dev,
 						   "Not enough memory to consolidate frag_list!\n");
-				skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+				set_skb_zerocopy(queue, skb);
 				kfree_skb(skb);
 				continue;
 			}
@@ -1609,7 +1624,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 				   "Can't setup checksum in net_tx_action\n");
 			/* We have to set this flag to trigger the callback */
 			if (skb_shinfo(skb)->destructor_arg)
-				skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+				set_skb_zerocopy(queue, skb);
 			kfree_skb(skb);
 			continue;
 		}
@@ -1641,7 +1656,7 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
 		 * skb. E.g. the __pskb_pull_tail earlier can do such thing.
 		 */
 		if (skb_shinfo(skb)->destructor_arg) {
-			skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+			set_skb_zerocopy(queue, skb);
 			queue->stats.tx_zerocopy_sent++;
 		}
 
@@ -1681,6 +1696,7 @@ void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success)
 		queue->stats.tx_zerocopy_success++;
 	else
 		queue->stats.tx_zerocopy_fail++;
+	xenvif_dec_inflight_packets(queue);
 }
 
 static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)
Signature · 1 line
1.7.10.4
#23 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 3 lines · Wei Liu

Reference count the number of packets in host stack, so that we don't stop the deallocation thread too early. If not, we can end up with xenvif_free permanently waiting for deallocation thread to unmap grefs.

[...]

Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
@@ -43,6 +43,17 @@
 #define XENVIF_QUEUE_LENGTH 32
 #define XENVIF_NAPI_WEIGHT  64
 

drivers/net/xen-netback/interface.c line 55

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue)
+{
+	atomic_inc(&queue->inflight_packets);
+}
+
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue)
+{
+	if (atomic_dec_and_test(&queue->inflight_packets))
+		wake_up(&queue->inflight_wq);
+}

You don't need these wrappers if you remove the inflight_wq (see below).

Quoted 13 lines
drivers/net/xen-netback/interface.c +2 -0
 static inline void xenvif_stop_queue(struct xenvif_queue *queue)
 {
 	struct net_device *dev = queue->vif->dev;
@@ -561,6 +572,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 
 	init_waitqueue_head(&queue->wq);
 	init_waitqueue_head(&queue->dealloc_wq);
+	init_waitqueue_head(&queue->inflight_wq);
+	atomic_set(&queue->inflight_packets, 0);
 
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 13 lines
drivers/net/xen-netback/interface.c +1 -0
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +1 -0
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as

drivers/net/xen-netback/netback.c static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue, · line 120

Quoted 10 lines
drivers/net/xen-netback/netback.c +10 -0
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}

This name makes this look like a core function instead of a netback specific one.

I would suggest a pair of functions:

xenvif_skb_zerocopy_prepare()
xenvif_skb_zerocopy_complete()

Or similar.

David

#24 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu
Quoted 3 lines · Wei Liu

Reference count the number of packets in host stack, so that we don't stop the deallocation thread too early. If not, we can end up with xenvif_free permanently waiting for deallocation thread to unmap grefs.

[...]

Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
@@ -43,6 +43,17 @@
 #define XENVIF_QUEUE_LENGTH 32
 #define XENVIF_NAPI_WEIGHT  64
 

drivers/net/xen-netback/interface.c line 55

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+void xenvif_inc_inflight_packets(struct xenvif_queue *queue)
+{
+	atomic_inc(&queue->inflight_packets);
+}
+
+void xenvif_dec_inflight_packets(struct xenvif_queue *queue)
+{
+	if (atomic_dec_and_test(&queue->inflight_packets))
+		wake_up(&queue->inflight_wq);
+}

You don't need these wrappers if you remove the inflight_wq (see below).

Quoted 13 lines
drivers/net/xen-netback/interface.c +2 -0
 static inline void xenvif_stop_queue(struct xenvif_queue *queue)
 {
 	struct net_device *dev = queue->vif->dev;
@@ -561,6 +572,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 
 	init_waitqueue_head(&queue->wq);
 	init_waitqueue_head(&queue->dealloc_wq);
+	init_waitqueue_head(&queue->inflight_wq);
+	atomic_set(&queue->inflight_packets, 0);
 
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 5 lines
drivers/net/xen-netback/interface.c +2 -0
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 13 lines
drivers/net/xen-netback/interface.c +1 -0
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +1 -0
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as

drivers/net/xen-netback/netback.c static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue, · line 120

Quoted 10 lines
drivers/net/xen-netback/netback.c +10 -0
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}

This name makes this look like a core function instead of a netback specific one.

I would suggest a pair of functions:

xenvif_skb_zerocopy_prepare()
xenvif_skb_zerocopy_complete()

Or similar.

David

author
#25 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

?

Quoted 27 lines
Quoted 13 lines
drivers/net/xen-netback/interface.c +1 -0
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +1 -0
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as

drivers/net/xen-netback/netback.c static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue, · line 120

Quoted 10 lines
drivers/net/xen-netback/netback.c +10 -0
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}

This name makes this look like a core function instead of a netback specific one.

Quoted 5 lines

I would suggest a pair of functions:

xenvif_skb_zerocopy_prepare()
xenvif_skb_zerocopy_complete()

This will do.

Wei.

Quoted 3 lines

Or similar.

David

author
#26 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

?

Quoted 27 lines
Quoted 13 lines
drivers/net/xen-netback/interface.c +1 -0
+
 		if (queue->dealloc_task) {
 			kthread_stop(queue->dealloc_task);
 			queue->dealloc_task = NULL;
drivers/net/xen-netback/netback.c +1 -0
index 4734472..d2f0c7d7 100644
@@ -107,6 +107,18 @@ static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 #define callback_param(vif, pending_idx) \
 	(vif->pending_tx_info[pending_idx].callback_struct)
 
+/* This function is used to set SKBTX_DEV_ZEROCOPY as well as

drivers/net/xen-netback/netback.c static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue, · line 120

Quoted 10 lines
drivers/net/xen-netback/netback.c +10 -0
+ * increasing the inflight counter. We need to increase the inflight
+ * counter because core driver calls into xenvif_zerocopy_callback
+ * which calls xenvif_dec_inflight_packets.
+ */
+static void set_skb_zerocopy(struct xenvif_queue *queue,
+			     struct sk_buff *skb)
+{
+	skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+	xenvif_inc_inflight_packets(queue);
+}

This name makes this look like a core function instead of a netback specific one.

Quoted 5 lines

I would suggest a pair of functions:

xenvif_skb_zerocopy_prepare()
xenvif_skb_zerocopy_complete()

This will do.

Wei.

Quoted 3 lines

Or similar.

David

#27 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}

And cleaning it up a bit (the while() could be a for(;;)).

David

#28 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}

And cleaning it up a bit (the while() could be a for(;;)).

David

#29 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
  	if (tx_evtchn == rx_evtchn) {
  		/* feature-split-event-channels == 0 */
drivers/net/xen-netback/interface.c +0 -0
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
  			queue->task = NULL;
  		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

   while (atomic_read(&queue->inflight_packets) !=0)
   	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
                || !kthread_should_stop()) {
             [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
     /* Dealloc thread must remain running if there are any inflight
      * packets so it can properly dealloc them when they complete.
      */
     return atomic_read(&queue->inflight_packets) == 0
         && kthread_should_stop();
}
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
wait_event_interruptible(queue->dealloc_wq,
tx_dealloc_work_todo(queue) || kthread_should_stop());
- if (kthread_should_stop())
+ if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
break;

xenvif_tx_dealloc_action(queue);
---
If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

#30 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel
Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
  	if (tx_evtchn == rx_evtchn) {
  		/* feature-split-event-channels == 0 */
drivers/net/xen-netback/interface.c +0 -0
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
  			queue->task = NULL;
  		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

   while (atomic_read(&queue->inflight_packets) !=0)
   	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
                || !kthread_should_stop()) {
             [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
     /* Dealloc thread must remain running if there are any inflight
      * packets so it can properly dealloc them when they complete.
      */
     return atomic_read(&queue->inflight_packets) == 0
         && kthread_should_stop();
}
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
wait_event_interruptible(queue->dealloc_wq,
tx_dealloc_work_todo(queue) || kthread_should_stop());
- if (kthread_should_stop())
+ if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
break;

xenvif_tx_dealloc_action(queue);
---
If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

author
#31 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)

 {
        struct xenvif_queue *queue = data;

- while (!kthread_should_stop()) {

+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

- if (kthread_should_stop())
+ if (kthread_should_stop() &&
+ !atomic_read(&queue->inflight_packets) &&
+ !tx_dealloc_work_todo(queue))

                        break;
 
                xenvif_tx_dealloc_action(queue);
                cond_resched();
        }

- /* Unmap anything remaining*/
- if (tx_dealloc_work_todo(queue))
- xenvif_tx_dealloc_action(queue);
-

        return 0;

}

author
#32 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to Zoltan Kiss

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)

 {
        struct xenvif_queue *queue = data;

- while (!kthread_should_stop()) {

+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

- if (kthread_should_stop())
+ if (kthread_should_stop() &&
+ !atomic_read(&queue->inflight_packets) &&
+ !tx_dealloc_work_todo(queue))

                        break;
 
                xenvif_tx_dealloc_action(queue);
                cond_resched();
        }

- /* Unmap anything remaining*/
- if (tx_dealloc_work_todo(queue))
- xenvif_tx_dealloc_action(queue);
-

        return 0;

}

#33 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 25 lines · Wei Liu

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

Review int xenvif_dealloc_kthread(void *data) · line 2072

Quoted 8 lines
(quoted diff) +1 -1
@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)
 {
        struct xenvif_queue *queue = data;
 
-       while (!kthread_should_stop()) {
+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

This will never sleep if the thread is being stopped when there are packets in flight.

Review int xenvif_dealloc_kthread(void *data) · line 2076

Quoted 5 lines
(quoted diff) +3 -1
-               if (kthread_should_stop())
+               if (kthread_should_stop() &&
+                   !atomic_read(&queue->inflight_packets) &&
+                   !tx_dealloc_work_todo(queue))
                        break;

Moving the final dealloc into the loop adds a cond_resched() call. This is harmless but not really necessary when the thread is about to stop.

Review int xenvif_dealloc_kthread(void *data) · line 2082

Quoted 11 lines
(quoted diff) +0 -4
                xenvif_tx_dealloc_action(queue);
                cond_resched();
        }
 
-       /* Unmap anything remaining*/
-       if (tx_dealloc_work_todo(queue))
-               xenvif_tx_dealloc_action(queue);
-
        return 0;
 }

David

#34 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu
Quoted 25 lines · Wei Liu

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

Review int xenvif_dealloc_kthread(void *data) · line 2072

Quoted 8 lines
(quoted diff) +1 -1
@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)
 {
        struct xenvif_queue *queue = data;
 
-       while (!kthread_should_stop()) {
+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

This will never sleep if the thread is being stopped when there are packets in flight.

Review int xenvif_dealloc_kthread(void *data) · line 2076

Quoted 5 lines
(quoted diff) +3 -1
-               if (kthread_should_stop())
+               if (kthread_should_stop() &&
+                   !atomic_read(&queue->inflight_packets) &&
+                   !tx_dealloc_work_todo(queue))
                        break;

Moving the final dealloc into the loop adds a cond_resched() call. This is harmless but not really necessary when the thread is about to stop.

Review int xenvif_dealloc_kthread(void *data) · line 2082

Quoted 11 lines
(quoted diff) +0 -4
                xenvif_tx_dealloc_action(queue);
                cond_resched();
        }
 
-       /* Unmap anything remaining*/
-       if (tx_dealloc_work_todo(queue))
-               xenvif_tx_dealloc_action(queue);
-
        return 0;
 }

David

author
#35 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 29 lines · David Vrabel
Quoted 28 lines · Wei Liu

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

(quoted diff) +0 -0
@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)
 {
        struct xenvif_queue *queue = data;
 
Quoted 9 lines

Review int xenvif_dealloc_kthread(void *data) · line 2072

Quoted 5 lines
(quoted diff) +1 -1
-       while (!kthread_should_stop()) {
+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

This will never sleep if the thread is being stopped when there are packets in flight.

Good catch.

author
#36 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel
Quoted 29 lines · David Vrabel
Quoted 28 lines · Wei Liu

On Mon, Aug 11, 2014 at 03:13:41PM +0100, Zoltan Kiss wrote:
[...]

Quoted 14 lines
Quoted 1 line

And cleaning it up a bit (the while() could be a for(;;)).

I would recommend this:
---

(quoted diff) +1 -2
@@ -2066,7 +2066,7 @@ int xenvif_dealloc_kthread(void *data)
 		wait_event_interruptible(queue->dealloc_wq,
 					 tx_dealloc_work_todo(queue) ||
 					 kthread_should_stop());
-		if (kthread_should_stop())
+		if (kthread_should_stop() && !atomic_read(&queue->inflight_packets))
 			break;
 
 		xenvif_tx_dealloc_action(queue);
---
Quoted 2 lines

If kthread_stop called, this will keep the main loop running until all callbacks are called. Then it proceeds to the exit branch, otherwise doesn't disrupt normal operation.

This snippet lacks change to while().

I would generally go for a shorter solution if the code is self-explanatory.

(quoted diff) +0 -0
@@ -2078,21 +2066,19 @@ int xenvif_dealloc_kthread(void *data)
 {
        struct xenvif_queue *queue = data;
 
Quoted 9 lines

Review int xenvif_dealloc_kthread(void *data) · line 2072

Quoted 5 lines
(quoted diff) +1 -1
-       while (!kthread_should_stop()) {
+       for (;;) {
                wait_event_interruptible(queue->dealloc_wq,
                                         tx_dealloc_work_todo(queue) ||
                                         kthread_should_stop());

This will never sleep if the thread is being stopped when there are packets in flight.

Good catch.

author
#37 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel
Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}
Quoted 2 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

Wei.

Quoted 1 line

David

author
#38 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel
Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}
Quoted 2 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

Wei.

Quoted 1 line

David

#39 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

Quoted 48 lines · Wei Liu
Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}
Quoted 6 lines
Quoted 2 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

kthread_stop() waits until the thread exits (like pthread_join()).

/**
* kthread_stop - stop a thread created by kthread_create().
* @k: thread created by kthread_create().
*
* Sets kthread_should_stop() for @k to return true, wakes it, and
* waits for it to exit.

David

#40 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to Wei Liu
Quoted 48 lines · Wei Liu
Quoted 47 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 1 line · David Vrabel

On 08/08/14 17:37, Wei Liu wrote:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
@@ -687,6 +700,9 @@ void xenvif_disconnect(struct xenvif *vif)
 			queue->task = NULL;
 		}
 
Quoted 6 lines

drivers/net/xen-netback/interface.c void xenvif_disconnect(struct xenvif *vif) · line 704

Quoted 2 lines
drivers/net/xen-netback/interface.c +2 -0
+		wait_event(queue->inflight_wq,
+			   atomic_read(&queue->inflight_packets) == 0);

Just make the dealloc task not stop unless it has deallocated all outstanding requests. There's no need for another wait queue here.

Quoted 4 lines

Are you suggesting something like

  while (atomic_read(&queue->inflight_packets) !=0)
  	schedule_timeout(SOME_TIMEOUT);

No. That would be awful!

Add the test to the kthread itself:

int xenvif_dealloc_kthread(void *data)

{
	struct xenvif_queue *queue = data;

	while (atomic_read(&queue->inflight_packets) > 0
               || !kthread_should_stop()) {
            [...]

etc.

Although, the main loop is a bit confused, so I suggest adding:

static bool xenvif_dealloc_thread_should_stop(struct xenvif_queue *q)

{
    /* Dealloc thread must remain running if there are any inflight
     * packets so it can properly dealloc them when they complete.
     */
    return atomic_read(&queue->inflight_packets) == 0
        && kthread_should_stop();
}
Quoted 6 lines
Quoted 2 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

kthread_stop() waits until the thread exits (like pthread_join()).

/**
* kthread_stop - stop a thread created by kthread_create().
* @k: thread created by kthread_create().
*
* Sets kthread_should_stop() for @k to return true, wakes it, and
* waits for it to exit.

David

author
#41 lore raw

Re: [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

On Mon, Aug 11, 2014 at 03:34:48PM +0100, David Vrabel wrote:
[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

Quoted 9 lines

kthread_stop() waits until the thread exits (like pthread_join()).

/**
* kthread_stop - stop a thread created by kthread_create().
* @k: thread created by kthread_create().
*
* Sets kthread_should_stop() for @k to return true, wakes it, and
* waits for it to exit.

Ah, misremeber the behaviour of kthread_stop. Sorry for the noise.

Wei.

Quoted 1 line

David

author
#42 lore raw

Re: [Xen-devel] [PATCH net v2 2/3] xen-netback: don't stop dealloc kthread too early

In reply to David Vrabel

On Mon, Aug 11, 2014 at 03:34:48PM +0100, David Vrabel wrote:
[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

And cleaning it up a bit (the while() could be a for(;;)).

Unfortunately this approach is bogus. If xenbus thread is not blocked it can free up various resources while dealloc thread is running -- queue can be gone under dealloc thread's feet.

Quoted 9 lines

kthread_stop() waits until the thread exits (like pthread_join()).

/**
* kthread_stop - stop a thread created by kthread_create().
* @k: thread created by kthread_create().
*
* Sets kthread_should_stop() for @k to return true, wakes it, and
* waits for it to exit.

Ah, misremeber the behaviour of kthread_stop. Sorry for the noise.

Wei.

Quoted 1 line

David

author
#43 lore raw

PATCH v2 3/3 xen-netback: remove loop waiting function

In reply to Wei Liu

The original implementation relies on a loop to check if all inflight packets are freed. Now we have proper reference counting, there's no need to use loop anymore.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   29 -----------------------------
 1 file changed, 29 deletions(-)
drivers/net/xen-netback/interface.c +0 -29
index 6488801..3bb1104 100644
@@ -659,25 +659,6 @@ void xenvif_carrier_off(struct xenvif *vif)
 	rtnl_unlock();
 }
 
-static void xenvif_wait_unmap_timeout(struct xenvif_queue *queue,
-				      unsigned int worst_case_skb_lifetime)
-{
-	int i, unmap_timeout = 0;
-
-	for (i = 0; i < MAX_PENDING_REQS; ++i) {
-		if (queue->grant_tx_handle[i] != NETBACK_INVALID_HANDLE) {
-			unmap_timeout++;
-			schedule_timeout(msecs_to_jiffies(1000));
-			if (unmap_timeout > worst_case_skb_lifetime &&
-			    net_ratelimit())
-				netdev_err(queue->vif->dev,
-					   "Page still granted! Index: %x\n",
-					   i);
-			i = -1;
-		}
-	}
-}
-
 void xenvif_disconnect(struct xenvif *vif)
 {
 	struct xenvif_queue *queue = NULL;
@@ -736,21 +717,11 @@ void xenvif_free(struct xenvif *vif)
 	struct xenvif_queue *queue = NULL;
 	unsigned int num_queues = vif->num_queues;
 	unsigned int queue_index;
-	/* Here we want to avoid timeout messages if an skb can be legitimately
-	 * stuck somewhere else. Realistically this could be an another vif's
-	 * internal or QDisc queue. That another vif also has this
-	 * rx_drain_timeout_msecs timeout, so give it time to drain out.
-	 * Although if that other guest wakes up just before its timeout happens
-	 * and takes only one skb from QDisc, it can hold onto other skbs for a
-	 * longer period.
-	 */
-	unsigned int worst_case_skb_lifetime = (rx_drain_timeout_msecs/1000);
 
 	unregister_netdev(vif->dev);
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
-		xenvif_wait_unmap_timeout(queue, worst_case_skb_lifetime);
 		xenvif_deinit_queue(queue);
 	}
 
Signature · 1 line
1.7.10.4
author
#44 lore raw

PATCH v2 3/3 xen-netback: remove loop waiting function

In reply to Wei Liu

The original implementation relies on a loop to check if all inflight packets are freed. Now we have proper reference counting, there's no need to use loop anymore.

Cc Ian Campbell <[email protected]>
Cc Zoltan Kiss <[email protected]>
---
 drivers/net/xen-netback/interface.c |   29 -----------------------------
 1 file changed, 29 deletions(-)
drivers/net/xen-netback/interface.c +0 -29
index 6488801..3bb1104 100644
@@ -659,25 +659,6 @@ void xenvif_carrier_off(struct xenvif *vif)
 	rtnl_unlock();
 }
 
-static void xenvif_wait_unmap_timeout(struct xenvif_queue *queue,
-				      unsigned int worst_case_skb_lifetime)
-{
-	int i, unmap_timeout = 0;
-
-	for (i = 0; i < MAX_PENDING_REQS; ++i) {
-		if (queue->grant_tx_handle[i] != NETBACK_INVALID_HANDLE) {
-			unmap_timeout++;
-			schedule_timeout(msecs_to_jiffies(1000));
-			if (unmap_timeout > worst_case_skb_lifetime &&
-			    net_ratelimit())
-				netdev_err(queue->vif->dev,
-					   "Page still granted! Index: %x\n",
-					   i);
-			i = -1;
-		}
-	}
-}
-
 void xenvif_disconnect(struct xenvif *vif)
 {
 	struct xenvif_queue *queue = NULL;
@@ -736,21 +717,11 @@ void xenvif_free(struct xenvif *vif)
 	struct xenvif_queue *queue = NULL;
 	unsigned int num_queues = vif->num_queues;
 	unsigned int queue_index;
-	/* Here we want to avoid timeout messages if an skb can be legitimately
-	 * stuck somewhere else. Realistically this could be an another vif's
-	 * internal or QDisc queue. That another vif also has this
-	 * rx_drain_timeout_msecs timeout, so give it time to drain out.
-	 * Although if that other guest wakes up just before its timeout happens
-	 * and takes only one skb from QDisc, it can hold onto other skbs for a
-	 * longer period.
-	 */
-	unsigned int worst_case_skb_lifetime = (rx_drain_timeout_msecs/1000);
 
 	unregister_netdev(vif->dev);
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
-		xenvif_wait_unmap_timeout(queue, worst_case_skb_lifetime);
 		xenvif_deinit_queue(queue);
 	}
 
Signature · 1 line
1.7.10.4