* [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work
@ 2015-08-04 14:40 Ross Lagerwall
2015-08-04 14:42 ` Wei Liu
2015-08-07 6:43 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Ross Lagerwall @ 2015-08-04 14:40 UTC (permalink / raw)
To: netdev; +Cc: xen-devel, Wei Liu, Ian Campbell, Ross Lagerwall
Waking the dealloc thread before decrementing inflight_packets is racy
because it means the thread may go to sleep before inflight_packets is
decremented. If kthread_stop() has already been called, the dealloc
thread may wait forever with nothing to wake it. Instead, wake the
thread only after decrementing inflight_packets.
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
Changed in V2: Move wakeup into zerocopy_complete function.
drivers/net/xen-netback/interface.c | 6 ++++++
drivers/net/xen-netback/netback.c | 1 -
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 1a83e19..28577a3 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -61,6 +61,12 @@ void xenvif_skb_zerocopy_prepare(struct xenvif_queue *queue,
void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue)
{
atomic_dec(&queue->inflight_packets);
+
+ /* Wake the dealloc thread _after_ decrementing inflight_packets so
+ * that if kthread_stop() has already been called, the dealloc thread
+ * does not wait forever with nothing to wake it.
+ */
+ wake_up(&queue->dealloc_wq);
}
int xenvif_schedulable(struct xenvif *vif)
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 7d50711..09ffda4 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1536,7 +1536,6 @@ void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success)
smp_wmb();
queue->dealloc_prod++;
} while (ubuf);
- wake_up(&queue->dealloc_wq);
spin_unlock_irqrestore(&queue->callback_lock, flags);
if (likely(zerocopy_success))
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work
2015-08-04 14:40 [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work Ross Lagerwall
@ 2015-08-04 14:42 ` Wei Liu
2015-08-07 6:43 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2015-08-04 14:42 UTC (permalink / raw)
To: Ross Lagerwall; +Cc: netdev, xen-devel, Wei Liu, Ian Campbell
On Tue, Aug 04, 2015 at 03:40:59PM +0100, Ross Lagerwall wrote:
> Waking the dealloc thread before decrementing inflight_packets is racy
> because it means the thread may go to sleep before inflight_packets is
> decremented. If kthread_stop() has already been called, the dealloc
> thread may wait forever with nothing to wake it. Instead, wake the
> thread only after decrementing inflight_packets.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
> ---
> Changed in V2: Move wakeup into zerocopy_complete function.
>
> drivers/net/xen-netback/interface.c | 6 ++++++
> drivers/net/xen-netback/netback.c | 1 -
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
> index 1a83e19..28577a3 100644
> --- a/drivers/net/xen-netback/interface.c
> +++ b/drivers/net/xen-netback/interface.c
> @@ -61,6 +61,12 @@ void xenvif_skb_zerocopy_prepare(struct xenvif_queue *queue,
> void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue)
> {
> atomic_dec(&queue->inflight_packets);
> +
> + /* Wake the dealloc thread _after_ decrementing inflight_packets so
> + * that if kthread_stop() has already been called, the dealloc thread
> + * does not wait forever with nothing to wake it.
> + */
> + wake_up(&queue->dealloc_wq);
> }
>
> int xenvif_schedulable(struct xenvif *vif)
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 7d50711..09ffda4 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -1536,7 +1536,6 @@ void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success)
> smp_wmb();
> queue->dealloc_prod++;
> } while (ubuf);
> - wake_up(&queue->dealloc_wq);
> spin_unlock_irqrestore(&queue->callback_lock, flags);
>
> if (likely(zerocopy_success))
> --
> 2.1.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work
2015-08-04 14:40 [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work Ross Lagerwall
2015-08-04 14:42 ` Wei Liu
@ 2015-08-07 6:43 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-08-07 6:43 UTC (permalink / raw)
To: ross.lagerwall; +Cc: netdev, xen-devel, wei.liu2, ian.campbell
From: Ross Lagerwall <ross.lagerwall@citrix.com>
Date: Tue, 4 Aug 2015 15:40:59 +0100
> Waking the dealloc thread before decrementing inflight_packets is racy
> because it means the thread may go to sleep before inflight_packets is
> decremented. If kthread_stop() has already been called, the dealloc
> thread may wait forever with nothing to wake it. Instead, wake the
> thread only after decrementing inflight_packets.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
> ---
> Changed in V2: Move wakeup into zerocopy_complete function.
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-07 6:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-04 14:40 [PATCH v2] xen/netback: Wake dealloc thread after completing zerocopy work Ross Lagerwall
2015-08-04 14:42 ` Wei Liu
2015-08-07 6:43 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).