xen-netfront: remove warning when unloading module
Subsystems (3)
PATCH 1/1 xen-netfront: remove warning when unloading module
When unloading module xen_netfront from guest, dmesg would output warning messages like below:
[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)
This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/xen-netfront.c +11 -0
@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +xennet_disconnect_backend (info);unregister_netdev (info->netdev);
Signature · 1 line
2.13.6
CC netfront maintainers.
Quoted 44 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +11
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +xennet_disconnect_backend (info);unregister_netdev (info->netdev);Signature · 1 line
2.13.6
Juergen Gross
maintainerQuoted 30 lines · Wei Liu
CC netfront maintainers.
Quoted 27 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +0
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename);
Quoted 10 lines
drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device *dev) · line 2142
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + }
I really don't like the busy waits.
Can't you use e.g. a wait queue and wait_event_interruptible() instead?
BTW: what happens if the device is already in closed state if you enter xennet_remove()? In case this is impossible, please add a comment to indicate you've thought about that case.
Other than that: you should run ./scripts/checkpatch.p1 against your patch to avoid common style problems.
Juergen
Quoted 44 lines · Juergen Gross
Quoted 30 lines · Wei Liu
CC netfront maintainers.
Quoted 27 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +0
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename);Quoted 10 lines
drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device *dev) · line 2142
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + }I really don't like the busy waits.
Quoted 1 line
Can't you use e.g. a wait queue and
wait_event_interruptible()instead?
I thought about using these, but I don't think the busy waits here are much of a problem because it's just unloading a kernel module, not a very repetitive action. But yes I can go for this approach on v2.
Quoted 4 lines
BTW: what happens if the device is already in closed state if you enter
xennet_remove()? In case this is impossible, please add a comment to indicate you've thought about that case.
Looks like this is the same problem Paul Durrant mentioned on his comment. I'll work on this as well on v2.
Thanks for the review and the help on IRC :-)
Quoted 44 lines · Juergen Gross
Quoted 30 lines · Wei Liu
CC netfront maintainers.
Quoted 27 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +0
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename);Quoted 10 lines
drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device *dev) · line 2142
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + }I really don't like the busy waits.
Quoted 1 line
Can't you use e.g. a wait queue and
wait_event_interruptible()instead?
I thought about using these, but I don't think the busy waits here are much of a problem because it's just unloading a kernel module, not a very repetitive action. But yes I can go for this approach on v2.
Quoted 4 lines
BTW: what happens if the device is already in closed state if you enter
xennet_remove()? In case this is impossible, please add a comment to indicate you've thought about that case.
Looks like this is the same problem Paul Durrant mentioned on his comment. I'll work on this as well on v2.
Thanks for the review and the help on IRC :-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Juergen Gross
maintainerQuoted 30 lines · Wei Liu
CC netfront maintainers.
Quoted 27 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +0
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename);
Quoted 10 lines
drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device *dev) · line 2142
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + }
I really don't like the busy waits.
Can't you use e.g. a wait queue and wait_event_interruptible() instead?
BTW: what happens if the device is already in closed state if you enter xennet_remove()? In case this is impossible, please add a comment to indicate you've thought about that case.
Other than that: you should run ./scripts/checkpatch.p1 against your patch to avoid common style problems.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
CC netfront maintainers.
Quoted 44 lines · Eduardo Otubo
When unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by manipulating both device states.
Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +11
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); +while (xenbus_read_driver_state (dev->otherend) != XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +xennet_disconnect_backend (info);unregister_netdev (info->netdev);Signature · 1 line
2.13.6
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 41 lines
-----Original Message-----
From: Eduardo Otubo [mailto:[email protected]]
Sent: 20 November 2017 10:41
To: [email protected]
Cc: [email protected]; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Eduardo Otubo <[email protected]>
Subject: [PATCH] xen-netfront: remove warning when unloading moduleWhen unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by
manipulating both device states.Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +2
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); + while (xenbus_read_driver_state(dev->otherend) !=
drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device · line 2145
Quoted 10 lines
drivers/net/xen-netfront.c +9
-0XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +
Waitiing for closing should be ok but waiting for closed is risky. As soon as a backend is in the closed state then a toolstack can completely remove the backend xenstore area, resulting a state of XenbusStateUnknown, which would cause your second loop to spin forever.
Paul
Quoted 5 lines
drivers/net/xen-netfront.c +0
-0xennet_disconnect_backend (info);
unregister_netdev(info->netdev);
--
2.13.6
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 54 lines · Paul Durrant
Quoted 41 lines
-----Original Message-----
From: Eduardo Otubo [mailto:[email protected]]
Sent: 20 November 2017 10:41
To: [email protected]
Cc: [email protected]; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Eduardo Otubo <[email protected]>
Subject: [PATCH] xen-netfront: remove warning when unloading moduleWhen unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by
manipulating both device states.Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +2
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); + while (xenbus_read_driver_state(dev->otherend) !=drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device · line 2145
Quoted 10 lines
drivers/net/xen-netfront.c +9
-0XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +Waitiing for closing should be ok but waiting for closed is risky. As soon as a backend is in the closed state then a toolstack can completely remove the backend xenstore area, resulting a state of XenbusStateUnknown, which would cause your second loop to spin forever.
Quoted 1 line
Paul
Well, that's a scenario I didn't foresee. I'll come up with a solution in order avoid this problem. Thanks for the review.
Quoted 7 lines
Quoted 6 lines
drivers/net/xen-netfront.c +0
-0xennet_disconnect_backend (info);
unregister_netdev(info->netdev);
--
2.13.6
Signature · 1 line
Eduardo Otubo
Quoted 54 lines · Paul Durrant
Quoted 41 lines
-----Original Message-----
From: Eduardo Otubo [mailto:[email protected]]
Sent: 20 November 2017 10:41
To: [email protected]
Cc: [email protected]; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Eduardo Otubo <[email protected]>
Subject: [PATCH] xen-netfront: remove warning when unloading moduleWhen unloading module
xen_netfrontfrom guest, dmesg would output warning messages like below:[ 105.236836] xen:grant_table: WARNING: g.e. 0x903 still in use! [ 105.236839] deferring g.e. 0x903 (pfn 0x35805)This problem relies on netfront and netback being out of sync. By the time netfront revokes the g.e.'s netback didn't have enough time to free all of them, hence displaying the warnings on dmesg.
The trick here is to make netfront to wait until netback frees all the g.e.'s and only then continue to cleanup for the module removal, and this is done by
manipulating both device states.Signed-off-by Eduardo Otubo <[email protected]>--- drivers/net/xen-netfront.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/xen-netfront.c +2
-0@@ -2130,6 +2130,17 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); +xenbus_switch_state (dev, XenbusStateClosing); + while (xenbus_read_driver_state(dev->otherend) !=drivers/net/xen-netfront.c static int xennet_remove(struct xenbus_device · line 2145
Quoted 10 lines
drivers/net/xen-netfront.c +9
-0XenbusStateClosing){ +cpu_relax (); +schedule (); + } +xenbus_switch_state (dev, XenbusStateClosed); +while (dev->xenbus_state != XenbusStateClosed){ +cpu_relax (); +schedule (); + } +Waitiing for closing should be ok but waiting for closed is risky. As soon as a backend is in the closed state then a toolstack can completely remove the backend xenstore area, resulting a state of XenbusStateUnknown, which would cause your second loop to spin forever.
Quoted 1 line
Paul
Well, that's a scenario I didn't foresee. I'll come up with a solution in order avoid this problem. Thanks for the review.
Quoted 7 lines
Quoted 6 lines
drivers/net/xen-netfront.c +0
-0xennet_disconnect_backend (info);
unregister_netdev(info->netdev);
--
2.13.6
Signature · 6 lines
Eduardo Otubo _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Eduardo,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on xen-tip/linux-next]
[also build test ERROR on v4.14 next-20171121]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Eduardo-Otubo/xen-netfront-remove-warning-when-unloading-module/20171122-163844 base: https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next config: x86_64-allmodconfig (attached as .config) compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers//net/xen-netfront.c: In function 'xennet_remove':
>> drivers//net/xen-netfront.c:2139:12: error: 'struct xenbus_device' has no member named 'xenbus_state'
while (dev->xenbus_state != XenbusStateClosed){
^~vim +2139 drivers//net/xen-netfront.c
2126
2127 static int xennet_remove(struct xenbus_device *dev)
2128 {
2129 struct netfront_info *info = dev_get_drvdata(&dev->dev);
2130
2131 dev_dbg(&dev->dev, "%s\n", dev->nodename);
2132
2133 xenbus_switch_state(dev, XenbusStateClosing);
2134 while (xenbus_read_driver_state(dev->otherend) != XenbusStateClosing){
2135 cpu_relax();
2136 schedule();
2137 }
2138 xenbus_switch_state(dev, XenbusStateClosed);
> 2139 while (dev->xenbus_state != XenbusStateClosed){ 2140 cpu_relax();
2141 schedule();
2142 }
2143
2144 xennet_disconnect_backend(info);
2145
2146 unregister_netdev(info->netdev);
2147
2148 if (info->queues)
2149 xennet_destroy_queues(info);
2150 xennet_free_netdev(info->netdev);
2151
2152 return 0;
2153 }
2154
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Eduardo,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on xen-tip/linux-next]
[also build test ERROR on v4.14 next-20171121]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Eduardo-Otubo/xen-netfront-remove-warning-when-unloading-module/20171122-163844 base: https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next config: x86_64-allmodconfig (attached as .config) compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers//net/xen-netfront.c: In function 'xennet_remove':
>> drivers//net/xen-netfront.c:2139:12: error: 'struct xenbus_device' has no member named 'xenbus_state'
while (dev->xenbus_state != XenbusStateClosed){
^~vim +2139 drivers//net/xen-netfront.c
2126
2127 static int xennet_remove(struct xenbus_device *dev)
2128 {
2129 struct netfront_info *info = dev_get_drvdata(&dev->dev);
2130
2131 dev_dbg(&dev->dev, "%s\n", dev->nodename);
2132
2133 xenbus_switch_state(dev, XenbusStateClosing);
2134 while (xenbus_read_driver_state(dev->otherend) != XenbusStateClosing){
2135 cpu_relax();
2136 schedule();
2137 }
2138 xenbus_switch_state(dev, XenbusStateClosed);
> 2139 while (dev->xenbus_state != XenbusStateClosed){ 2140 cpu_relax();
2141 schedule();
2142 }
2143
2144 xennet_disconnect_backend(info);
2145
2146 unregister_netdev(info->netdev);
2147
2148 if (info->queues)
2149 xennet_destroy_queues(info);
2150 xennet_free_netdev(info->netdev);
2151
2152 return 0;
2153 }
2154
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel