* [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG
@ 2017-03-02 12:54 Paul Durrant
2017-03-02 12:54 ` [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect() Paul Durrant
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Paul Durrant @ 2017-03-02 12:54 UTC (permalink / raw)
To: netdev, xen-devel; +Cc: Paul Durrant
Commit 9a6cdf52b85e "xen-netback: fix memory leaks on XenBus disconnect"
added missing code to fix a memory leak by calling vfree() in the
appropriate place.
Unfortunately subsequent commit f16f1df65f1c "xen-netback: protect
resource cleaning on XenBus disconnect" then wrapped this call to vfree()
in a spin lock, leading to a BUG due to incorrect context.
Patch #1 makes the existing code more readable
Patch #2 fixes the problem
Paul Durrant (2):
xen-netback: keep a local pointer for vif in backend_disconnect()
xen-netback: don't vfree() queues under spinlock
drivers/net/xen-netback/xenbus.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect()
2017-03-02 12:54 [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG Paul Durrant
@ 2017-03-02 12:54 ` Paul Durrant
2017-03-02 13:35 ` Wei Liu
2017-03-02 12:54 ` [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock Paul Durrant
2017-03-03 17:36 ` [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG David Miller
2 siblings, 1 reply; 7+ messages in thread
From: Paul Durrant @ 2017-03-02 12:54 UTC (permalink / raw)
To: netdev, xen-devel; +Cc: Paul Durrant, Wei Liu
This patch replaces use of 'be->vif' with 'vif' and hence generally
makes the function look tidier. No semantic change.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Wei Liu <wei.liu2@citrix.com>
---
drivers/net/xen-netback/xenbus.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index bb854f9..d82ddc9 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -492,24 +492,28 @@ static int backend_create_xenvif(struct backend_info *be)
static void backend_disconnect(struct backend_info *be)
{
- if (be->vif) {
+ struct xenvif *vif = be->vif;
+
+ if (vif) {
unsigned int queue_index;
- xen_unregister_watchers(be->vif);
+ xen_unregister_watchers(vif);
#ifdef CONFIG_DEBUG_FS
- xenvif_debugfs_delif(be->vif);
+ xenvif_debugfs_delif(vif);
#endif /* CONFIG_DEBUG_FS */
- xenvif_disconnect_data(be->vif);
- for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
- xenvif_deinit_queue(&be->vif->queues[queue_index]);
-
- spin_lock(&be->vif->lock);
- vfree(be->vif->queues);
- be->vif->num_queues = 0;
- be->vif->queues = NULL;
- spin_unlock(&be->vif->lock);
-
- xenvif_disconnect_ctrl(be->vif);
+ xenvif_disconnect_data(vif);
+ for (queue_index = 0;
+ queue_index < vif->num_queues;
+ ++queue_index)
+ xenvif_deinit_queue(&vif->queues[queue_index]);
+
+ spin_lock(&vif->lock);
+ vfree(vif->queues);
+ vif->num_queues = 0;
+ vif->queues = NULL;
+ spin_unlock(&vif->lock);
+
+ xenvif_disconnect_ctrl(vif);
}
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock
2017-03-02 12:54 [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG Paul Durrant
2017-03-02 12:54 ` [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect() Paul Durrant
@ 2017-03-02 12:54 ` Paul Durrant
2017-03-02 13:23 ` Juergen Gross
2017-03-02 13:35 ` Wei Liu
2017-03-03 17:36 ` [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG David Miller
2 siblings, 2 replies; 7+ messages in thread
From: Paul Durrant @ 2017-03-02 12:54 UTC (permalink / raw)
To: netdev, xen-devel; +Cc: Juergen Gross, Paul Durrant, Wei Liu
This leads to a BUG of the following form:
[ 174.512861] switch: port 2(vif3.0) entered disabled state
[ 174.522735] BUG: sleeping function called from invalid context at
/home/build/linux-linus/mm/vmalloc.c:1441
[ 174.523451] in_atomic(): 1, irqs_disabled(): 0, pid: 28, name: xenwatch
[ 174.524131] CPU: 1 PID: 28 Comm: xenwatch Tainted: G W
4.10.0upstream-11073-g4977ab6-dirty #1
[ 174.524819] Hardware name: MSI MS-7680/H61M-P23 (MS-7680), BIOS V17.0
03/14/2011
[ 174.525517] Call Trace:
[ 174.526217] show_stack+0x23/0x60
[ 174.526899] dump_stack+0x5b/0x88
[ 174.527562] ___might_sleep+0xde/0x130
[ 174.528208] __might_sleep+0x35/0xa0
[ 174.528840] ? _raw_spin_unlock_irqrestore+0x13/0x20
[ 174.529463] ? __wake_up+0x40/0x50
[ 174.530089] remove_vm_area+0x20/0x90
[ 174.530724] __vunmap+0x1d/0xc0
[ 174.531346] ? delete_object_full+0x13/0x20
[ 174.531973] vfree+0x40/0x80
[ 174.532594] set_backend_state+0x18a/0xa90
[ 174.533221] ? dwc_scan_descriptors+0x24d/0x430
[ 174.533850] ? kfree+0x5b/0xc0
[ 174.534476] ? xenbus_read+0x3d/0x50
[ 174.535101] ? xenbus_read+0x3d/0x50
[ 174.535718] ? xenbus_gather+0x31/0x90
[ 174.536332] ? ___might_sleep+0xf6/0x130
[ 174.536945] frontend_changed+0x6b/0xd0
[ 174.537565] xenbus_otherend_changed+0x7d/0x80
[ 174.538185] frontend_changed+0x12/0x20
[ 174.538803] xenwatch_thread+0x74/0x110
[ 174.539417] ? woken_wake_function+0x20/0x20
[ 174.540049] kthread+0xe5/0x120
[ 174.540663] ? xenbus_printf+0x50/0x50
[ 174.541278] ? __kthread_init_worker+0x40/0x40
[ 174.541898] ret_from_fork+0x21/0x2c
[ 174.548635] switch: port 2(vif3.0) entered disabled state
This patch defers the vfree() until after the spinlock is released.
Reported-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Juergen Gross <jgross@suse.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
drivers/net/xen-netback/xenbus.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index d82ddc9..d2d7cd9 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -496,6 +496,7 @@ static void backend_disconnect(struct backend_info *be)
if (vif) {
unsigned int queue_index;
+ struct xenvif_queue *queues;
xen_unregister_watchers(vif);
#ifdef CONFIG_DEBUG_FS
@@ -508,11 +509,13 @@ static void backend_disconnect(struct backend_info *be)
xenvif_deinit_queue(&vif->queues[queue_index]);
spin_lock(&vif->lock);
- vfree(vif->queues);
+ queues = vif->queues;
vif->num_queues = 0;
vif->queues = NULL;
spin_unlock(&vif->lock);
+ vfree(queues);
+
xenvif_disconnect_ctrl(vif);
}
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock
2017-03-02 12:54 ` [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock Paul Durrant
@ 2017-03-02 13:23 ` Juergen Gross
2017-03-02 13:35 ` Wei Liu
1 sibling, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2017-03-02 13:23 UTC (permalink / raw)
To: Paul Durrant, netdev, xen-devel; +Cc: Wei Liu
On 02/03/17 13:54, Paul Durrant wrote:
> This leads to a BUG of the following form:
>
> [ 174.512861] switch: port 2(vif3.0) entered disabled state
> [ 174.522735] BUG: sleeping function called from invalid context at
> /home/build/linux-linus/mm/vmalloc.c:1441
> [ 174.523451] in_atomic(): 1, irqs_disabled(): 0, pid: 28, name: xenwatch
> [ 174.524131] CPU: 1 PID: 28 Comm: xenwatch Tainted: G W
> 4.10.0upstream-11073-g4977ab6-dirty #1
> [ 174.524819] Hardware name: MSI MS-7680/H61M-P23 (MS-7680), BIOS V17.0
> 03/14/2011
> [ 174.525517] Call Trace:
> [ 174.526217] show_stack+0x23/0x60
> [ 174.526899] dump_stack+0x5b/0x88
> [ 174.527562] ___might_sleep+0xde/0x130
> [ 174.528208] __might_sleep+0x35/0xa0
> [ 174.528840] ? _raw_spin_unlock_irqrestore+0x13/0x20
> [ 174.529463] ? __wake_up+0x40/0x50
> [ 174.530089] remove_vm_area+0x20/0x90
> [ 174.530724] __vunmap+0x1d/0xc0
> [ 174.531346] ? delete_object_full+0x13/0x20
> [ 174.531973] vfree+0x40/0x80
> [ 174.532594] set_backend_state+0x18a/0xa90
> [ 174.533221] ? dwc_scan_descriptors+0x24d/0x430
> [ 174.533850] ? kfree+0x5b/0xc0
> [ 174.534476] ? xenbus_read+0x3d/0x50
> [ 174.535101] ? xenbus_read+0x3d/0x50
> [ 174.535718] ? xenbus_gather+0x31/0x90
> [ 174.536332] ? ___might_sleep+0xf6/0x130
> [ 174.536945] frontend_changed+0x6b/0xd0
> [ 174.537565] xenbus_otherend_changed+0x7d/0x80
> [ 174.538185] frontend_changed+0x12/0x20
> [ 174.538803] xenwatch_thread+0x74/0x110
> [ 174.539417] ? woken_wake_function+0x20/0x20
> [ 174.540049] kthread+0xe5/0x120
> [ 174.540663] ? xenbus_printf+0x50/0x50
> [ 174.541278] ? __kthread_init_worker+0x40/0x40
> [ 174.541898] ret_from_fork+0x21/0x2c
> [ 174.548635] switch: port 2(vif3.0) entered disabled state
>
> This patch defers the vfree() until after the spinlock is released.
>
> Reported-by: Juergen Gross <jgross@suse.com>
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect()
2017-03-02 12:54 ` [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect() Paul Durrant
@ 2017-03-02 13:35 ` Wei Liu
0 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-02 13:35 UTC (permalink / raw)
To: Paul Durrant; +Cc: netdev, Wei Liu, xen-devel
On Thu, Mar 02, 2017 at 12:54:25PM +0000, Paul Durrant wrote:
> This patch replaces use of 'be->vif' with 'vif' and hence generally
> makes the function look tidier. No semantic change.
>
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock
2017-03-02 12:54 ` [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock Paul Durrant
2017-03-02 13:23 ` Juergen Gross
@ 2017-03-02 13:35 ` Wei Liu
1 sibling, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-02 13:35 UTC (permalink / raw)
To: Paul Durrant; +Cc: Juergen Gross, netdev, Wei Liu, xen-devel
On Thu, Mar 02, 2017 at 12:54:26PM +0000, Paul Durrant wrote:
> This leads to a BUG of the following form:
>
> [ 174.512861] switch: port 2(vif3.0) entered disabled state
> [ 174.522735] BUG: sleeping function called from invalid context at
> /home/build/linux-linus/mm/vmalloc.c:1441
> [ 174.523451] in_atomic(): 1, irqs_disabled(): 0, pid: 28, name: xenwatch
> [ 174.524131] CPU: 1 PID: 28 Comm: xenwatch Tainted: G W
> 4.10.0upstream-11073-g4977ab6-dirty #1
> [ 174.524819] Hardware name: MSI MS-7680/H61M-P23 (MS-7680), BIOS V17.0
> 03/14/2011
> [ 174.525517] Call Trace:
> [ 174.526217] show_stack+0x23/0x60
> [ 174.526899] dump_stack+0x5b/0x88
> [ 174.527562] ___might_sleep+0xde/0x130
> [ 174.528208] __might_sleep+0x35/0xa0
> [ 174.528840] ? _raw_spin_unlock_irqrestore+0x13/0x20
> [ 174.529463] ? __wake_up+0x40/0x50
> [ 174.530089] remove_vm_area+0x20/0x90
> [ 174.530724] __vunmap+0x1d/0xc0
> [ 174.531346] ? delete_object_full+0x13/0x20
> [ 174.531973] vfree+0x40/0x80
> [ 174.532594] set_backend_state+0x18a/0xa90
> [ 174.533221] ? dwc_scan_descriptors+0x24d/0x430
> [ 174.533850] ? kfree+0x5b/0xc0
> [ 174.534476] ? xenbus_read+0x3d/0x50
> [ 174.535101] ? xenbus_read+0x3d/0x50
> [ 174.535718] ? xenbus_gather+0x31/0x90
> [ 174.536332] ? ___might_sleep+0xf6/0x130
> [ 174.536945] frontend_changed+0x6b/0xd0
> [ 174.537565] xenbus_otherend_changed+0x7d/0x80
> [ 174.538185] frontend_changed+0x12/0x20
> [ 174.538803] xenwatch_thread+0x74/0x110
> [ 174.539417] ? woken_wake_function+0x20/0x20
> [ 174.540049] kthread+0xe5/0x120
> [ 174.540663] ? xenbus_printf+0x50/0x50
> [ 174.541278] ? __kthread_init_worker+0x40/0x40
> [ 174.541898] ret_from_fork+0x21/0x2c
> [ 174.548635] switch: port 2(vif3.0) entered disabled state
>
> This patch defers the vfree() until after the spinlock is released.
>
> Reported-by: Juergen Gross <jgross@suse.com>
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG
2017-03-02 12:54 [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG Paul Durrant
2017-03-02 12:54 ` [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect() Paul Durrant
2017-03-02 12:54 ` [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock Paul Durrant
@ 2017-03-03 17:36 ` David Miller
2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2017-03-03 17:36 UTC (permalink / raw)
To: paul.durrant; +Cc: netdev, xen-devel
From: Paul Durrant <paul.durrant@citrix.com>
Date: Thu, 2 Mar 2017 12:54:24 +0000
> Commit 9a6cdf52b85e "xen-netback: fix memory leaks on XenBus disconnect"
> added missing code to fix a memory leak by calling vfree() in the
> appropriate place.
> Unfortunately subsequent commit f16f1df65f1c "xen-netback: protect
> resource cleaning on XenBus disconnect" then wrapped this call to vfree()
> in a spin lock, leading to a BUG due to incorrect context.
>
> Patch #1 makes the existing code more readable
> Patch #2 fixes the problem
Series applied, thanks.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-03-03 17:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-02 12:54 [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG Paul Durrant
2017-03-02 12:54 ` [PATCH net 1/2] xen-netback: keep a local pointer for vif in backend_disconnect() Paul Durrant
2017-03-02 13:35 ` Wei Liu
2017-03-02 12:54 ` [PATCH net 2/2] xen-netback: don't vfree() queues under spinlock Paul Durrant
2017-03-02 13:23 ` Juergen Gross
2017-03-02 13:35 ` Wei Liu
2017-03-03 17:36 ` [PATCH net 0/2] xen-netback: update memory leak fix to avoid BUG 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).