* [PATCHv1 net] xen-netback: release pending index before pushing Tx responses
@ 2015-02-24 11:17 David Vrabel
2015-02-24 12:03 ` Wei Liu
2015-02-24 21:24 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: David Vrabel @ 2015-02-24 11:17 UTC (permalink / raw)
To: netdev; +Cc: David Vrabel, xen-devel, Ian Campbell, Wei Liu
If the pending indexes are released /after/ pushing the Tx response
then a stale pending index may be used if a new Tx request is
immediately pushed by the frontend. The may cause various WARNINGs or
BUGs if the stale pending index is actually still in use.
Fix this by releasing the pending index before pushing the Tx
response.
The full barrier for the pending ring update is not required since the
the Tx response push already has a suitable write barrier.
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
drivers/net/xen-netback/netback.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index f7a31d2..c4d68d7 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -655,9 +655,15 @@ static void xenvif_tx_err(struct xenvif_queue *queue,
unsigned long flags;
do {
+ int notify;
+
spin_lock_irqsave(&queue->response_lock, flags);
make_tx_response(queue, txp, XEN_NETIF_RSP_ERROR);
+ RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->tx, notify);
spin_unlock_irqrestore(&queue->response_lock, flags);
+ if (notify)
+ notify_remote_via_irq(queue->tx_irq);
+
if (cons == end)
break;
txp = RING_GET_REQUEST(&queue->tx, cons++);
@@ -1649,17 +1655,28 @@ static void xenvif_idx_release(struct xenvif_queue *queue, u16 pending_idx,
{
struct pending_tx_info *pending_tx_info;
pending_ring_idx_t index;
+ int notify;
unsigned long flags;
pending_tx_info = &queue->pending_tx_info[pending_idx];
+
spin_lock_irqsave(&queue->response_lock, flags);
+
make_tx_response(queue, &pending_tx_info->req, status);
- index = pending_index(queue->pending_prod);
+
+ /* Release the pending index before pusing the Tx response so
+ * its available before a new Tx request is pushed by the
+ * frontend.
+ */
+ index = pending_index(queue->pending_prod++);
queue->pending_ring[index] = pending_idx;
- /* TX shouldn't use the index before we give it back here */
- mb();
- queue->pending_prod++;
+
+ RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->tx, notify);
+
spin_unlock_irqrestore(&queue->response_lock, flags);
+
+ if (notify)
+ notify_remote_via_irq(queue->tx_irq);
}
@@ -1669,7 +1686,6 @@ static void make_tx_response(struct xenvif_queue *queue,
{
RING_IDX i = queue->tx.rsp_prod_pvt;
struct xen_netif_tx_response *resp;
- int notify;
resp = RING_GET_RESPONSE(&queue->tx, i);
resp->id = txp->id;
@@ -1679,9 +1695,6 @@ static void make_tx_response(struct xenvif_queue *queue,
RING_GET_RESPONSE(&queue->tx, ++i)->status = XEN_NETIF_RSP_NULL;
queue->tx.rsp_prod_pvt = ++i;
- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->tx, notify);
- if (notify)
- notify_remote_via_irq(queue->tx_irq);
}
static struct xen_netif_rx_response *make_rx_response(struct xenvif_queue *queue,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCHv1 net] xen-netback: release pending index before pushing Tx responses
2015-02-24 11:17 [PATCHv1 net] xen-netback: release pending index before pushing Tx responses David Vrabel
@ 2015-02-24 12:03 ` Wei Liu
2015-02-24 21:24 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2015-02-24 12:03 UTC (permalink / raw)
To: David Vrabel; +Cc: netdev, xen-devel, Ian Campbell, Wei Liu
On Tue, Feb 24, 2015 at 11:17:59AM +0000, David Vrabel wrote:
> If the pending indexes are released /after/ pushing the Tx response
> then a stale pending index may be used if a new Tx request is
> immediately pushed by the frontend. The may cause various WARNINGs or
> BUGs if the stale pending index is actually still in use.
>
> Fix this by releasing the pending index before pushing the Tx
> response.
>
> The full barrier for the pending ring update is not required since the
> the Tx response push already has a suitable write barrier.
>
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv1 net] xen-netback: release pending index before pushing Tx responses
2015-02-24 11:17 [PATCHv1 net] xen-netback: release pending index before pushing Tx responses David Vrabel
2015-02-24 12:03 ` Wei Liu
@ 2015-02-24 21:24 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-02-24 21:24 UTC (permalink / raw)
To: david.vrabel; +Cc: netdev, xen-devel, ian.campbell, wei.liu2
From: David Vrabel <david.vrabel@citrix.com>
Date: Tue, 24 Feb 2015 11:17:59 +0000
> If the pending indexes are released /after/ pushing the Tx response
> then a stale pending index may be used if a new Tx request is
> immediately pushed by the frontend. The may cause various WARNINGs or
> BUGs if the stale pending index is actually still in use.
>
> Fix this by releasing the pending index before pushing the Tx
> response.
>
> The full barrier for the pending ring update is not required since the
> the Tx response push already has a suitable write barrier.
>
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Applied, thanks David.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-24 21:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-24 11:17 [PATCHv1 net] xen-netback: release pending index before pushing Tx responses David Vrabel
2015-02-24 12:03 ` Wei Liu
2015-02-24 21:24 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox