xen-netback: drop SKB from internal queue if frontend is disconnected
Subsystems (2)
PATCH 1/1 xen-netback: drop SKB from internal queue if frontend is disconnected
In 88a810def7 ("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code from xenvif_disconnect to xenvif_free.
It can occur that frontend is disconnected while there's still SKB stuck in netback's rx_queue in rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.
Moving the ref counting back to xenvif_disconnect isn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.
This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
--- drivers/net/xen-netback/common.h | 1 + drivers/net/xen-netback/interface.c | 1 + drivers/net/xen-netback/netback.c | 13 +++++++++++++ 3 files changed, 15 insertions(+)
drivers/net/xen-netback/common.h +1 -0
@@ -66,6 +66,7 @@ struct xenvif {/* The shared rings and indexes. */ struct xen_netif_tx_back_ring tx;struct xen_netif_rx_back_ring rx; +bool ring_mapped;/* Frontend feature information. */ u8 can_sg:1;
drivers/net/xen-netback/interface.c +1 -0
@@ -271,6 +271,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, vif->dev = dev;INIT_LIST_HEAD (&vif->schedule_list);INIT_LIST_HEAD (&vif->notify_list); + vif->ring_mapped = false; vif->credit_bytes = vif->remaining_credit = ~0UL ; vif->credit_usec =0UL ;
drivers/net/xen-netback/netback.c +13 -0
@@ -720,6 +720,16 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) vif =netdev_priv (skb->dev); nr_frags =skb_shinfo (skb)->nr_frags; +/* In rare case that frontend is disconnected while +* there's still SKBs stuck in netback internal +* rx_queue, drop these SKBs. +*/ +if (unlikely (!vif->ring_mapped)) { +dev_kfree_skb (skb); +xenvif_put (vif); +continue ; + } + sco = (struct skb_cb_overlay *)skb->cb; sco->meta_slots_used =netbk_gop_skb (skb, &npo);
@@ -1864,6 +1874,8 @@ static int xen_netbk_kthread(void *data)void xen_netbk_unmap_frontend_rings (struct xenvif *vif) { + vif->ring_mapped = false; +if (vif->tx.sring)xenbus_unmap_ring_vfree (xenvif_to_xenbus_device (vif), vif->tx.sring);
@@ -1899,6 +1911,7 @@ int xen_netbk_map_frontend_rings(struct xenvif *vif,BACK_RING_INIT (&vif->rx, rxs,PAGE_SIZE ); vif->rx_req_cons_peek =0 ; + vif->ring_mapped = true;return 0 ;
Signature · 1 line
1.7.10.4
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.
Since this was a 3.10 specific backport that explains why this is also such?
Quoted 10 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.
Quoted 4 lines
This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.
Since this was a 3.10 specific backport that explains why this is also such?
Quoted 10 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.
Quoted 4 lines
This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.Since this was a 3.10 specific backport that explains why this is also such?
Yes.
Quoted 10 lines
Quoted 10 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.
Quoted 7 lines
Quoted 4 lines
This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
3.11 is long dead while 3.10 is LTS kernel. I don't think GregKH accepts patch for 3.11 anymore.
Wei.
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.Since this was a 3.10 specific backport that explains why this is also such?
Yes.
Quoted 10 lines
Quoted 10 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.
Quoted 7 lines
Quoted 4 lines
This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
3.11 is long dead while 3.10 is LTS kernel. I don't think GregKH accepts patch for 3.11 anymore.
Wei.
Quoted 10 lines · Wei Liu
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.Since this was a 3.10 specific backport that explains why this is also such?
Yes.
OK.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
3.11 is long dead while 3.10 is LTS kernel. I don't think GregKH accepts patch for 3.11 anymore.
Whether Greg would take a patch is orthogonal to whether the bug exists in 3.11 though. Someone might want to fix their own kernel locally for example...
Ian.
Quoted 10 lines · Wei Liu
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Wei Liu
In
88a810def7("xen-netback: fix refcnt unbalance for 3.10"), we moved the ref counting code fromxenvif_disconnecttoxenvif_free.Since this was a 3.10 specific backport that explains why this is also such?
Yes.
OK.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
It can occur that frontend is disconnected while there's still SKB stuck in netback's
rx_queuein rare case. When netback thread wakes up, it will try to write to an already unmapped ring, resulting in kernel oops.Moving the ref counting back to
xenvif_disconnectisn't an option as it reintroduces an old bug. Further more, writing into a dead frontend's ring and memory is just wrong. Dropping those SKBs seems to be a good strategy.This patch fixes that corner case: introduce a flag to indicate whether frontend ring is mapped. If the ring is unmapped, just drop those SKBs.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
3.11 is long dead while 3.10 is LTS kernel. I don't think GregKH accepts patch for 3.11 anymore.
Whether Greg would take a patch is orthogonal to whether the bug exists in 3.11 though. Someone might want to fix their own kernel locally for example...
Ian.
On Fri, Jul 11, 2014 at 02:30:51PM +0100, Ian Campbell wrote:
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
This bug only manifests in 3.10 kernel. Kernel >=3.12 doesn't have it.
What about 3.11?
Quoted 7 lines
Quoted 2 lines
3.11 is long dead while 3.10 is LTS kernel. I don't think GregKH accepts patch for 3.11 anymore.
Whether Greg would take a patch is orthogonal to whether the bug exists in 3.11 though. Someone might want to fix their own kernel locally for example...
To be clear, 3.11 doesn't have that fix which introduced this bug, because GregKH explictly rejected that fix as 3.11 was already dead at that time. So this patch is not applicable to 3.11 (whether 3.11 has some other bugs is another problem).
See <[email protected]> and the thread it's in.
Wei.
Quoted 1 line
Ian.
Quoted 6 lines · Wei Liu
drivers/net/xen-netback/netback.c +0
-0@@ -720,6 +720,16 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) vif =netdev_priv (skb->dev); nr_frags =skb_shinfo (skb)->nr_frags;
drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 731
Quoted 10 lines
drivers/net/xen-netback/netback.c +9
-0+/* In rare case that frontend is disconnected while +* there's still SKBs stuck in netback internal +* rx_queue, drop these SKBs. +*/ +if (unlikely (!vif->ring_mapped)) { +dev_kfree_skb (skb); +xenvif_put (vif); +continue ; + }
Is this racy? The ring may be unmapped after the test but before we put responses on it.
David
Quoted 6 lines · Wei Liu
drivers/net/xen-netback/netback.c +0
-0@@ -720,6 +720,16 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) vif =netdev_priv (skb->dev); nr_frags =skb_shinfo (skb)->nr_frags;
drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 731
Quoted 10 lines
drivers/net/xen-netback/netback.c +9
-0+/* In rare case that frontend is disconnected while +* there's still SKBs stuck in netback internal +* rx_queue, drop these SKBs. +*/ +if (unlikely (!vif->ring_mapped)) { +dev_kfree_skb (skb); +xenvif_put (vif); +continue ; + }
Is this racy? The ring may be unmapped after the test but before we put responses on it.
David
Quoted 8 lines · David Vrabel
Quoted 7 lines · Wei Liu
drivers/net/xen-netback/netback.c +0
-0@@ -720,6 +720,16 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) vif =netdev_priv (skb->dev); nr_frags =skb_shinfo (skb)->nr_frags;
Quoted 13 lines
drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 731
Quoted 9 lines
drivers/net/xen-netback/netback.c +9
-0+/* In rare case that frontend is disconnected while +* there's still SKBs stuck in netback internal +* rx_queue, drop these SKBs. +*/ +if (unlikely (!vif->ring_mapped)) { +dev_kfree_skb (skb); +xenvif_put (vif); +continue ; + }Is this racy? The ring may be unmapped after the test but before we put responses on it.
Hmm... there's still a window. Ignore this patch for now. I will need to look further into a ref-counting solution.
Wei.
Quoted 1 line
David
Quoted 8 lines · David Vrabel
Quoted 7 lines · Wei Liu
drivers/net/xen-netback/netback.c +0
-0@@ -720,6 +720,16 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) vif =netdev_priv (skb->dev); nr_frags =skb_shinfo (skb)->nr_frags;
Quoted 13 lines
drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 731
Quoted 9 lines
drivers/net/xen-netback/netback.c +9
-0+/* In rare case that frontend is disconnected while +* there's still SKBs stuck in netback internal +* rx_queue, drop these SKBs. +*/ +if (unlikely (!vif->ring_mapped)) { +dev_kfree_skb (skb); +xenvif_put (vif); +continue ; + }Is this racy? The ring may be unmapped after the test but before we put responses on it.
Hmm... there's still a window. Ignore this patch for now. I will need to look further into a ref-counting solution.
Wei.
Quoted 1 line
David