Skip to contentSkip to conversation

xen-netback: fix oopes during shutdown and error handling

PATCH In review David Vrabel 6 participants 26 messages Feb 14, 2013 – Feb 15, 2013

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/2 xen-netback: correctly return errors from netbk_count_requests()

In reply to David Vrabel

From: David Vrabel <[email protected]>

netbk_count_requests() could detect an error, call netbk_fatal_tx_error() but return 0. The vif may then be used afterwards (e.g., in a call to netbk_tx_error().

Since netbk_fatal_tx_error() could set vif->refcnt to 1, the vif may be freed immediately after the call to netbk_fatal_tx_error() (e.g., if the vif is also removed).

Netback thread Xenwatch thread
-------------------------------------------
netbk_fatal_tx_err() netback_remove()

                              xenvif_disconnect()
                                ...
                                free_netdev()

netbk_tx_err() Oops!

---
 drivers/net/xen-netback/netback.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/xen-netback/netback.c +4 -4
index 2b9520c..cd49ba9 100644
@@ -911,13 +911,13 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (frags >= work_to_do) {
 			netdev_err(vif->dev, "Need more frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -ENODATA;
 		}
 
 		if (unlikely(frags >= MAX_SKB_FRAGS)) {
 			netdev_err(vif->dev, "Too many frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -E2BIG;
 		}
 
 		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + frags),
@@ -925,7 +925,7 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (txp->size > first->size) {
 			netdev_err(vif->dev, "Frag is bigger than frame.\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EIO;
 		}
 
 		first->size -= txp->size;
@@ -935,7 +935,7 @@ static int netbk_count_requests(struct xenvif *vif,
 			netdev_err(vif->dev, "txp->offset: %x, size: %u\n",
 				 txp->offset, txp->size);
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EINVAL;
 		}
 	} while ((txp++)->flags & XEN_NETTXF_more_data);
 	return frags;
Signature · 1 line
1.7.2.5
#5 lore raw

PATCH 2/2 xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
Signature · 1 line
1.7.2.5
#0 lore raw

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

They are stable candidants.

David

#6 lore raw

PATCH 2/2 xen-netback: cancel the credit timer when taking the vif down

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 1/2 xen-netback: correctly return errors from netbk_count_requests()

In reply to David Vrabel

From: David Vrabel <[email protected]>

netbk_count_requests() could detect an error, call netbk_fatal_tx_error() but return 0. The vif may then be used afterwards (e.g., in a call to netbk_tx_error().

Since netbk_fatal_tx_error() could set vif->refcnt to 1, the vif may be freed immediately after the call to netbk_fatal_tx_error() (e.g., if the vif is also removed).

Netback thread Xenwatch thread
-------------------------------------------
netbk_fatal_tx_err() netback_remove()

                              xenvif_disconnect()
                                ...
                                free_netdev()

netbk_tx_err() Oops!

---
 drivers/net/xen-netback/netback.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/xen-netback/netback.c +4 -4
index 2b9520c..cd49ba9 100644
@@ -911,13 +911,13 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (frags >= work_to_do) {
 			netdev_err(vif->dev, "Need more frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -ENODATA;
 		}
 
 		if (unlikely(frags >= MAX_SKB_FRAGS)) {
 			netdev_err(vif->dev, "Too many frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -E2BIG;
 		}
 
 		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + frags),
@@ -925,7 +925,7 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (txp->size > first->size) {
 			netdev_err(vif->dev, "Frag is bigger than frame.\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EIO;
 		}
 
 		first->size -= txp->size;
@@ -935,7 +935,7 @@ static int netbk_count_requests(struct xenvif *vif,
 			netdev_err(vif->dev, "txp->offset: %x, size: %u\n",
 				 txp->offset, txp->size);
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EINVAL;
 		}
 	} while ((txp++)->flags & XEN_NETTXF_more_data);
 	return frags;
Signature · 1 line
1.7.2.5
#7 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

Quoted 7 lines

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Another less desired but simpler fix would be leave the timer alone but check for vif->netbk != NULL in the timer callback.

Wei.

Quoted 25 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
#8 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

Quoted 7 lines

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Another less desired but simpler fix would be leave the timer alone but check for vif->netbk != NULL in the timer callback.

Wei.

Quoted 25 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
#9 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

Quoted 20 lines · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

No. Deleted timers do not need to be reinitialized. The timer will be armed as usual with mod_timer() when credit is next exhausted.

David

#10 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to Wei Liu
Quoted 20 lines · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

No. Deleted timers do not need to be reinitialized. The timer will be armed as usual with mod_timer() when credit is next exhausted.

David

#11 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

Quoted 21 lines · David Vrabel
Quoted 20 lines · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

No. Deleted timers do not need to be reinitialized. The timer will be

What I really meant was to "rearm"...

Quoted 2 lines

armed as usual with mod_timer() when credit is next exhausted.

Ah, ok.

Wei.

#12 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel
Quoted 21 lines · David Vrabel
Quoted 20 lines · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

No. Deleted timers do not need to be reinitialized. The timer will be

What I really meant was to "rearm"...

Quoted 2 lines

armed as usual with mod_timer() when credit is next exhausted.

Ah, ok.

Wei.

#13 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

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

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Which gets us to another aspect of the original fix that I don't think was considered: Is there anything preventing the interface to be brought back up after fatal_tx_err() shut it down?

Jan

#16 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

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

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Which gets us to another aspect of the original fix that I don't think was considered: Is there anything preventing the interface to be brought back up after fatal_tx_err() shut it down?

Jan

#14 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to Jan Beulich
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Which gets us to another aspect of the original fix that I don't think was considered: Is there anything preventing the interface to be brought back up after fatal_tx_err() shut it down?

I don't think so. Code could / should not prevent host admin from doing anything he wants - even it is re-enabling a malicious vif. ;-)

Wei.

Quoted 2 lines

Jan

#15 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to Jan Beulich
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

You would need to reinitialize the timer in xenvif_up, given that user might ifconfig vifX.X down; ifconfig vifX.X up.

Which gets us to another aspect of the original fix that I don't think was considered: Is there anything preventing the interface to be brought back up after fatal_tx_err() shut it down?

I don't think so. Code could / should not prevent host admin from doing anything he wants - even it is re-enabling a malicious vif. ;-)

Wei.

Quoted 2 lines

Jan

Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] xen-netback: correctly return errors from netbk_count_requests()

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

netbk_count_requests() could detect an error, call netbk_fatal_tx_error() but return 0. The vif may then be used afterwards (e.g., in a call to netbk_tx_error().

Since netbk_fatal_tx_error() could set vif->refcnt to 1, the vif may be freed immediately after the call to netbk_fatal_tx_error() (e.g., if the vif is also removed).

Netback thread Xenwatch thread
-------------------------------------------
netbk_fatal_tx_err() netback_remove()

Quoted 8 lines
                              xenvif_disconnect()
                                ...
                                free_netdev()

netbk_tx_err() Oops!

Although I would like to add a Tested-by: Christopher too if possible.

David (M) this should go to stable please.

Quoted 42 lines
---
 drivers/net/xen-netback/netback.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/xen-netback/netback.c +4 -4
index 2b9520c..cd49ba9 100644
@@ -911,13 +911,13 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (frags >= work_to_do) {
 			netdev_err(vif->dev, "Need more frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -ENODATA;
 		}
 
 		if (unlikely(frags >= MAX_SKB_FRAGS)) {
 			netdev_err(vif->dev, "Too many frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -E2BIG;
 		}
 
 		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + frags),
@@ -925,7 +925,7 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (txp->size > first->size) {
 			netdev_err(vif->dev, "Frag is bigger than frame.\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EIO;
 		}
 
 		first->size -= txp->size;
@@ -935,7 +935,7 @@ static int netbk_count_requests(struct xenvif *vif,
 			netdev_err(vif->dev, "txp->offset: %x, size: %u\n",
 				 txp->offset, txp->size);
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EINVAL;
 		}
 	} while ((txp++)->flags & XEN_NETTXF_more_data);
 	return frags;
Acked-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] xen-netback: correctly return errors from netbk_count_requests()

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

netbk_count_requests() could detect an error, call netbk_fatal_tx_error() but return 0. The vif may then be used afterwards (e.g., in a call to netbk_tx_error().

Since netbk_fatal_tx_error() could set vif->refcnt to 1, the vif may be freed immediately after the call to netbk_fatal_tx_error() (e.g., if the vif is also removed).

Netback thread Xenwatch thread
-------------------------------------------
netbk_fatal_tx_err() netback_remove()

Quoted 8 lines
                              xenvif_disconnect()
                                ...
                                free_netdev()

netbk_tx_err() Oops!

Although I would like to add a Tested-by: Christopher too if possible.

David (M) this should go to stable please.

Quoted 42 lines
---
 drivers/net/xen-netback/netback.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/xen-netback/netback.c +4 -4
index 2b9520c..cd49ba9 100644
@@ -911,13 +911,13 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (frags >= work_to_do) {
 			netdev_err(vif->dev, "Need more frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -ENODATA;
 		}
 
 		if (unlikely(frags >= MAX_SKB_FRAGS)) {
 			netdev_err(vif->dev, "Too many frags\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -E2BIG;
 		}
 
 		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + frags),
@@ -925,7 +925,7 @@ static int netbk_count_requests(struct xenvif *vif,
 		if (txp->size > first->size) {
 			netdev_err(vif->dev, "Frag is bigger than frame.\n");
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EIO;
 		}
 
 		first->size -= txp->size;
@@ -935,7 +935,7 @@ static int netbk_count_requests(struct xenvif *vif,
 			netdev_err(vif->dev, "txp->offset: %x, size: %u\n",
 				 txp->offset, txp->size);
 			netbk_fatal_tx_err(vif);
-			return -frags;
+			return -EINVAL;
 		}
 	} while ((txp++)->flags & XEN_NETTXF_more_data);
 	return frags;
Acked-by on v1 2/2
#17 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

Quoted 7 lines

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Was this one also Reported-by Christopher S. Aker or was it just discovered in the process of investigating?

Another stable candidate please Dave.

Quoted 25 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
Acked-by on v1 2/2
#18 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to David Vrabel
Quoted 13 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

Quoted 7 lines

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Was this one also Reported-by Christopher S. Aker or was it just discovered in the process of investigating?

Another stable candidate please Dave.

Quoted 25 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -2
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 
#19 lore raw

Re: [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

Quoted 20 lines · Ian Campbell
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 7 lines
Quoted 1 line

Was this one also Reported-by Christopher S. Aker or was it just discovered in the process of investigating?

His bug report did prod me to look into this, so I think it is worth adding

Wei.

Quoted 34 lines

Another stable candidate please Dave.

Quoted 17 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -0
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }

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

Quoted 8 lines
drivers/net/xen-netback/interface.c +0 -2
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#20 lore raw

Re: [Xen-devel] [PATCH 2/2] xen-netback: cancel the credit timer when taking the vif down

In reply to Ian Campbell
Quoted 20 lines · Ian Campbell
Quoted 19 lines · David Vrabel

From: David Vrabel <[email protected]>

If the credit timer is left armed after calling xen_netbk_remove_xenvif(), then it may fire and attempt to schedule the vif which will then oops as vif->netbk == NULL.

This may happen both in the fatal error path and during normal disconnection from the front end.

The sequencing during shutdown is critical to ensure that: a) vif->netbk doesn't become unexpectedly NULL; and b) the net device/vif is not freed.

1. Mark as unschedulable (netif_carrier_off()).
2. Synchronously cancel the timer.
3. Remove the vif from the schedule list.
4. Remove it from it netback thread group.
5. Wait for vif->refcnt to become 0.

Quoted 7 lines
Quoted 1 line

Was this one also Reported-by Christopher S. Aker or was it just discovered in the process of investigating?

His bug report did prod me to look into this, so I think it is worth adding

Wei.

Quoted 34 lines

Another stable candidate please Dave.

Quoted 17 lines
---
 drivers/net/xen-netback/interface.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/xen-netback/interface.c +1 -0
index b8c5193..221f426 100644
@@ -132,6 +132,7 @@ static void xenvif_up(struct xenvif *vif)
 static void xenvif_down(struct xenvif *vif)
 {
 	disable_irq(vif->irq);
+	del_timer_sync(&vif->credit_timeout);
 	xen_netbk_deschedule_xenvif(vif);
 	xen_netbk_remove_xenvif(vif);
 }

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

Quoted 8 lines
drivers/net/xen-netback/interface.c +0 -2
@@ -363,8 +364,6 @@ void xenvif_disconnect(struct xenvif *vif)
 	atomic_dec(&vif->refcnt);
 	wait_event(vif->waiting_to_free, atomic_read(&vif->refcnt) == 0);
 
-	del_timer_sync(&vif->credit_timeout);
-
 	if (vif->irq)
 		unbind_from_irqhandler(vif->irq, vif);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

maintainer
#21 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Thu, 14 Feb 2013 13:18:56 +0000

Quoted 4 lines

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

They are stable candidants.

Both applied and queued up for -stable, thanks.

maintainer
#22 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Thu, 14 Feb 2013 13:18:56 +0000

Quoted 4 lines

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

They are stable candidants.

Both applied and queued up for -stable, thanks.

#23 lore raw
In reply to David Vrabel
Quoted 2 lines · David Vrabel

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

Quoted 2 lines · Ian Campbell

Although I would like to add a Tested-by: Christopher too if possible.

We are no longer able to trigger the last OOPs we provided by downing the vif. Further testing of the other issues will take time, but we're deploying a few patched hosts now.

Thanks!
-Chris

#24 lore raw
Quoted 9 lines · Christopher S. Aker
Quoted 2 lines · David Vrabel

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

Quoted 2 lines · Ian Campbell

Although I would like to add a Tested-by: Christopher too if possible.

Thank you!

Quoted 3 lines

We are no longer able to trigger the last OOPs we provided by downing the vif. Further testing of the other issues will take time, but we're deploying a few patched hosts now.

Great, please let me know how you get on.

Ian.

#25 lore raw
In reply to Christopher S. Aker
Quoted 9 lines · Christopher S. Aker
Quoted 2 lines · David Vrabel

These two netback patches fix oopes that may occur during shutdown or if a specific fatal error occurs.

Quoted 2 lines · Ian Campbell

Although I would like to add a Tested-by: Christopher too if possible.

Thank you!

Quoted 3 lines

We are no longer able to trigger the last OOPs we provided by downing the vif. Further testing of the other issues will take time, but we're deploying a few patched hosts now.

Great, please let me know how you get on.

Ian.