Race condition on device add hanling in xl devd
Subsystems (2)
Hi,
I've found a race condition with handling new devices in driver domain. xl devd calls hotplug script when new device is detected in xenstore. At the same time, asynchronously, kernel create actual backend device (vif in my case). In rare circumstances (especially under high system load) it may happen that hotplug script is executed before kernel create the device, and the hotplug script fails. When hotplug scripts were called by udev, that race didn't existed as udev was informed about the device by the kernel.
I'm not sure if the race applies to backend in dom0 - haven't happened to me, but that doesn't really prove anything.
Can you remind me why in driver domain xl devd is used now, instead of udev?
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
The setup:
- Xen 4.8.4, but I believe the same would happen in xen-unstable
- Linux 4.19.2 (dom0), Linux 4.14.74 (domU)
- problem happens when starting a domU with network backend in another domU
- happen more often when Xen run nested in KVM (-> slow), but happened to me on bare metal too
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Marek Marczykowski-Górecki
Hi,
I've found a race condition with handling new devices in driver domain. xl devd calls hotplug script when new device is detected in xenstore. At the same time, asynchronously, kernel create actual backend device (vif in my case). In rare circumstances (especially under high system load) it may happen that hotplug script is executed before kernel create the device, and the hotplug script fails. When hotplug scripts were called by udev, that race didn't existed as udev was informed about the device by the kernel.
I'm not sure if the race applies to backend in dom0 - haven't happened to me, but that doesn't really prove anything.
Quoted 2 lines
Can you remind me why in driver domain xl devd is used now, instead of udev?
udev is Linux specific, while the current code works for Linux, NetBSD and FreeBSD.
Quoted 5 lines
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Roger Pau Monné
Quoted 13 lines · Marek Marczykowski-Górecki
Hi,
I've found a race condition with handling new devices in driver domain. xl devd calls hotplug script when new device is detected in xenstore. At the same time, asynchronously, kernel create actual backend device (vif in my case). In rare circumstances (especially under high system load) it may happen that hotplug script is executed before kernel create the device, and the hotplug script fails. When hotplug scripts were called by udev, that race didn't existed as udev was informed about the device by the kernel.
I'm not sure if the race applies to backend in dom0 - haven't happened to me, but that doesn't really prove anything.Quoted 2 lines
Can you remind me why in driver domain xl devd is used now, instead of udev?
udev is Linux specific, while the current code works for Linux, NetBSD and FreeBSD.
Quoted 5 lines
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
Quoted 8 lines
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for /sys/class/net/$vif to a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.
It may be some bug in nested virtualization in KVM...
Quoted 3 lines
Thanks, Roger.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Marek Marczykowski-Górecki
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Marek Marczykowski-Górecki
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
Quoted 8 lines
Quoted 2 lines
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for
/sys/class/net/$vifto a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Marek Marczykowski-Górecki
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
Quoted 8 lines
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for
/sys/class/net/$vifto a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.
Quoted 5 lines
Quoted 1 line
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 24 lines · Marek Marczykowski-Górecki
Quoted 23 lines · Roger Pau Monné
Quoted 21 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Marek Marczykowski-Górecki
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
Quoted 8 lines
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for
/sys/class/net/$vifto a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.It may be some bug in nested virtualization in KVM...
Quoted 7 lines
Quoted 3 lines
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see frontend_changed).
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
Thanks, Roger.
---8<---
drivers/net/xen-netback/xenbus.c +8 -1
@@ -427,6 +427,10 @@ static int netback_probe(struct xenbus_device *dev,if (err) goto fail; + err =xenbus_switch_state (dev, XenbusStateInitWait); +if (err) + goto fail; +return 0 ; abort_transaction:
@@ -650,7 +654,10 @@ static void frontend_changed(struct xenbus_device *dev,switch (frontend_state) {case XenbusStateInitialising: -set_backend_state (be, XenbusStateInitWait); +if (dev->state == XenbusStateClosed) { +pr_info ("%s: prepare for reconnect\n" , dev->nodename); +set_backend_state (be, XenbusStateInitWait); + }break ;case XenbusStateInitialised:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 56 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 13:06
To: Marek Marczykowski-Górecki <[email protected]>
Cc: xen-devel <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xl devdQuoted 2 lines · Marek Marczykowski-Górecki
Quoted 1 line · Roger Pau Monné
On Mon, Dec 17, 2018 at 01:00:01PM +0100, Marek Marczykowski-Górecki
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Roger Pau Monné
Quoted 1 line
On Sun, Dec 16, 2018 at 02:47:43AM +0100, Marek Marczykowski-
Quoted 1 line · Górecki
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
A workaround could be implemented in hotplug script itself -
wait for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the device there. I'm not sure how proper solution could look
like. Some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
synchronization between xl devd and the kernel (like xl devd
monitoring
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
uevents)?
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed
by
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've
added
Quoted 1 line
Quoted 1 line
Quoted 1 line
a loop waiting for
/sys/class/net/$vifto a hotplug script, but ittimed
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
out (5s). I don't see _any_ kernel messages related to the device.
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).
Quoted 5 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
IIRC there is a good reason why netback doesn't want the hotplug script to run before moving into state 2... the script adds the vif to the bridge and, if this is done on the 1 -> 2 transition then you may end up with a load of vifs sat on the bridge for which there is no frontend (at least yet, but maybe never)... so the bridge wastes time in every packet sent to such a vif.
Paul
Quoted 31 lines
Thanks, Roger.
---8<---drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0
-0
netback/xenbus.c
indexcd51492ae6c2..791c2c0b788f100644drivers/net/xen-netback/xenbus.c +8
-1@@ -427,6 +427,10 @@ static int netback_probe(struct xenbus_device *dev,if (err) goto fail; + err =xenbus_switch_state (dev, XenbusStateInitWait); +if (err) + goto fail; +return 0 ; abort_transaction:@@ -650,7 +654,10 @@ static void frontend_changed(struct xenbus_device *dev, switch (frontend_state) {case XenbusStateInitialising: -set_backend_state (be, XenbusStateInitWait); +if (dev->state == XenbusStateClosed) { +pr_info ("%s: prepare for reconnect\n" , dev->nodename); +set_backend_state (be, XenbusStateInitWait); + }break ;
Quoted 1 line
case XenbusStateInitialised:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Roger Pau Monné
Quoted 28 lines · Marek Marczykowski-Górecki
Quoted 26 lines · Roger Pau Monné
Quoted 13 lines · Marek Marczykowski-Górecki
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Marek Marczykowski-Górecki
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
Quoted 8 lines
Quoted 2 lines
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for
/sys/class/net/$vifto a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Quoted 8 lines
Quoted 3 lines
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).
Isn't frontend_changed guaranteed to be called after netback_probe?
Quoted 36 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
Thanks, Roger.
---8<---drivers/net/xen-netback/xenbus.c +8
-1@@ -427,6 +427,10 @@ static int netback_probe(struct xenbus_device *dev,if (err) goto fail; + err =xenbus_switch_state (dev, XenbusStateInitWait); +if (err) + goto fail; +return 0 ; abort_transaction:@@ -650,7 +654,10 @@ static void frontend_changed(struct xenbus_device *dev,switch (frontend_state) {case XenbusStateInitialising: -set_backend_state (be, XenbusStateInitWait); +if (dev->state == XenbusStateClosed) { +pr_info ("%s: prepare for reconnect\n" , dev->nodename); +set_backend_state (be, XenbusStateInitWait); + }break ;case XenbusStateInitialised:
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 56 lines · Paul Durrant
Quoted 56 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 13:06
To: Marek Marczykowski-Górecki <[email protected]>
Cc: xen-devel <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xl devdQuoted 2 lines · Marek Marczykowski-Górecki
Quoted 1 line · Roger Pau Monné
On Mon, Dec 17, 2018 at 01:00:01PM +0100, Marek Marczykowski-Górecki
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Roger Pau Monné
Quoted 1 line
On Sun, Dec 16, 2018 at 02:47:43AM +0100, Marek Marczykowski-
Quoted 1 line · Górecki
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
A workaround could be implemented in hotplug script itself -
wait for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the device there. I'm not sure how proper solution could look
like. Some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
synchronization between xl devd and the kernel (like xl devd
monitoring
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
uevents)?
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed
by
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've
added
Quoted 1 line
Quoted 1 line
Quoted 1 line
a loop waiting for
/sys/class/net/$vifto a hotplug script, but ittimed
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
out (5s). I don't see _any_ kernel messages related to the device.
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).
Quoted 7 lines
Quoted 5 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
IIRC there is a good reason why netback doesn't want the hotplug script to run before moving into state 2... the script adds the vif to the bridge and, if this is done on the 1 -> 2 transition then you may end up with a load of vifs sat on the bridge for which there is no frontend (at least yet, but maybe never)... so the bridge wastes time in every packet sent to such a vif.
I don't think netback has ever waited for a frontend before running hotplug scripts.
In the udev times the hotplug script would be run upon vif creation, which happens in netback_probe, and when launching hotplug scripts from libxl the script is executed when the backend changes to state 2, which happens almost immediately because netback switches to state 2 when the frotnend is in state 1 which is the initial frontend state.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 88 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 14:32
To: Paul Durrant <[email protected]>
Cc: Marek Marczykowski-Górecki <[email protected]>; xen- devel <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xl devdQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 13:06
To: Marek Marczykowski-Górecki <[email protected]>
Cc: xen-devel <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xldevd
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · Marek Marczykowski-Górecki
Quoted 1 line · Roger Pau Monné
On Mon, Dec 17, 2018 at 01:00:01PM +0100, Marek Marczykowski-
Górecki
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Roger Pau Monné
Quoted 1 line
On Sun, Dec 16, 2018 at 02:47:43AM +0100, Marek Marczykowski-
Quoted 1 line · Górecki
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
A workaround could be implemented in hotplug script itself -
wait for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the device there. I'm not sure how proper solution could
look
Quoted 6 lines
Quoted 6 lines
like. Some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
synchronization between xl devd and the kernel (like xl devd
monitoring
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
uevents)?
There's already a synchronization mechanism, libxl waits for
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
backend to switch to state 2 (XenbusStateInitWait) before
running
Quoted 6 lines
Quoted 6 lines
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything
needed
Quoted 4 lines
Quoted 4 lines
by
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else.
I've
Quoted 2 lines
Quoted 2 lines
added
Quoted 1 line
Quoted 1 line
Quoted 1 line
a loop waiting for
/sys/class/net/$vifto a hotplug script, butit
Quoted 2 lines
Quoted 2 lines
timed
Quoted 1 line
Quoted 1 line
Quoted 1 line
out (5s). I don't see _any_ kernel messages related to the
device.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even
less
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).Quoted 7 lines
Quoted 5 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
IIRC there is a good reason why netback doesn't want the hotplug script
to run before moving into state 2... the script adds the vif to the bridge and, if this is done on the 1 -> 2 transition then you may end up with a load of vifs sat on the bridge for which there is no frontend (at least yet, but maybe never)... so the bridge wastes time in every packet sent to such a vif.
Quoted 9 lines
I don't think netback has ever waited for a frontend before running hotplug scripts.
In the udev times the hotplug script would be run upon vif creation, which happens in
netback_probe, and when launching hotplug scripts from libxl the script is executed when the backend changes to state 2, which happens almost immediately because netback switches to state 2 when the frotnend is in state 1 which is the initial frontend state.
I suspect I must be remembering a XenServer-specific hack^Wpatch then. I'd have to dig... it's been a while since I messed with the netif state model, which is of course different the blkif state model.
Paul
Quoted 1 line
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 34 lines · Marek Marczykowski-Górecki
Quoted 33 lines · Roger Pau Monné
Quoted 31 lines · Marek Marczykowski-Górecki
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Roger Pau Monné
Quoted 4 lines · Marek Marczykowski-Górecki
A workaround could be implemented in hotplug script itself - wait for the device there. I'm not sure how proper solution could look like. Some synchronization between xl devd and the kernel (like xl devd monitoring uevents)?
Quoted 8 lines
There's already a synchronization mechanism, libxl waits for the backend to switch to state 2 (XenbusStateInitWait) before running the hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything needed by the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else. I've added a loop waiting for
/sys/class/net/$vifto a hotplug script, but it timed out (5s). I don't see _any_ kernel messages related to the device.Quoted 5 lines
Quoted 1 line
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even less startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
Quoted 6 lines
Quoted 4 lines
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).Isn't
frontend_changedguaranteed to be called afternetback_probe?
Yes, that seems to be correct, in which case the patch is moot. The otherend watch is only setup after calling the probe driver method in xenbus_dev_probe.
Do you think you can add some instrumentation code to netback in order to figure out what's going on? Interesting events would be backend switching to state 2 and vif creation (xenvif_alloc and the call to register_netdev AFAICT).
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 91 lines · Paul Durrant
Quoted 91 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 14:32
To: Paul Durrant <[email protected]>
Cc: Marek Marczykowski-Górecki <[email protected]>; xen- devel <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xl devdQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 13:06
To: Marek Marczykowski-Górecki <[email protected]>
Cc: xen-devel <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xldevd
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · Marek Marczykowski-Górecki
Quoted 1 line · Roger Pau Monné
On Mon, Dec 17, 2018 at 01:00:01PM +0100, Marek Marczykowski-
Górecki
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Roger Pau Monné
Quoted 1 line
On Sun, Dec 16, 2018 at 02:47:43AM +0100, Marek Marczykowski-
Quoted 1 line · Górecki
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
A workaround could be implemented in hotplug script itself -
wait for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the device there. I'm not sure how proper solution could
look
Quoted 6 lines
Quoted 6 lines
like. Some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
synchronization between xl devd and the kernel (like xl devd
monitoring
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
uevents)?
There's already a synchronization mechanism, libxl waits for
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
backend to switch to state 2 (XenbusStateInitWait) before
running
Quoted 6 lines
Quoted 6 lines
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything
needed
Quoted 4 lines
Quoted 4 lines
by
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else.
I've
Quoted 2 lines
Quoted 2 lines
added
Quoted 1 line
Quoted 1 line
Quoted 1 line
a loop waiting for
/sys/class/net/$vifto a hotplug script, butit
Quoted 2 lines
Quoted 2 lines
timed
Quoted 1 line
Quoted 1 line
Quoted 1 line
out (5s). I don't see _any_ kernel messages related to the
device.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even
less
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).Quoted 7 lines
Quoted 5 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
IIRC there is a good reason why netback doesn't want the hotplug script
to run before moving into state 2... the script adds the vif to the bridge and, if this is done on the 1 -> 2 transition then you may end up with a load of vifs sat on the bridge for which there is no frontend (at least yet, but maybe never)... so the bridge wastes time in every packet sent to such a vif.
I don't think netback has ever waited for a frontend before running hotplug scripts.
Quoted 8 lines
Quoted 6 lines
In the udev times the hotplug script would be run upon vif creation, which happens in
netback_probe, and when launching hotplug scripts from libxl the script is executed when the backend changes to state 2, which happens almost immediately because netback switches to state 2 when the frotnend is in state 1 which is the initial frontend state.I suspect I must be remembering a XenServer-specific hack^Wpatch then. I'd have to dig... it's been a while since I messed with the netif state model, which is of course different the blkif state model.
Quite likely. With udev scripts is was feasible to only execute hotplug scripts for vifs with an attached frontend.
With libxl this is not possible, since hotplug scripts are run during domain creation, at which point the guest is completely paused.
I'm not that familiar with bridges and vifs, but maybe the vifs status can be set to offline until there's a frontend attached in order to reduce the bridge distributor load? (if that's not already the case).
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 104 lines · Roger Pau Monné
Quoted 91 lines · Paul Durrant
Quoted 91 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 14:32
To: Paul Durrant <[email protected]>
Cc: Marek Marczykowski-Górecki <[email protected]>; xen- devel <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xl devdQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 17 December 2018 13:06
To: Marek Marczykowski-Górecki <[email protected]>
Cc: xen-devel <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: Re: [Xen-devel] Race condition on device add hanling in xldevd
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · Marek Marczykowski-Górecki
Quoted 1 line · Roger Pau Monné
On Mon, Dec 17, 2018 at 01:00:01PM +0100, Marek Marczykowski-
Górecki
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines · Roger Pau Monné
Quoted 1 line
On Sun, Dec 16, 2018 at 02:47:43AM +0100, Marek Marczykowski-
Quoted 1 line · Górecki
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
A workaround could be implemented in hotplug script itself -
wait for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the device there. I'm not sure how proper solution could
look
Quoted 6 lines
Quoted 6 lines
like. Some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
synchronization between xl devd and the kernel (like xl devd
monitoring
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
uevents)?
There's already a synchronization mechanism, libxl waits for
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
backend to switch to state 2 (XenbusStateInitWait) before
running
Quoted 6 lines
Quoted 6 lines
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hotplug scripts [0].
Maybe netback sets state 2 before creating the backend device?
It looks to me like the backend needs to be sure everything
needed
Quoted 4 lines
Quoted 4 lines
by
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the hotplug script is in place before switching to state 2.
I've done some more tests and I think that's something else.
I've
Quoted 2 lines
Quoted 2 lines
added
Quoted 1 line
Quoted 1 line
Quoted 1 line
a loop waiting for
/sys/class/net/$vifto a hotplug script, butit
Quoted 2 lines
Quoted 2 lines
timed
Quoted 1 line
Quoted 1 line
Quoted 1 line
out (5s). I don't see _any_ kernel messages related to the
device.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It may be some bug in nested virtualization in KVM...
In your message you said you have also observed this behavior when running on bare metal, so it's likely not related to nested virtualization?
Yes, but on bare metal is so hard to reproduce (like 0.1% or even
less
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
startups), I'm not really sure if that was the same problem, as the problem doesn't leave that much logs...
I'm not very familiar with netback, but I think it's indeed possible for netback to switch to state 2 without having created the vif. Netback switching from state 1 -> 2 seems to be solely controlled by the frontend state (see
frontend_changed).Quoted 7 lines
Quoted 5 lines
I think the patch below could solve this issue, but I haven't even compile tested it, could you give it a spin?
I would also like to hear the opinion of netback maintainers, since I might be completely wrong.
IIRC there is a good reason why netback doesn't want the hotplug script
to run before moving into state 2... the script adds the vif to the bridge and, if this is done on the 1 -> 2 transition then you may end up with a load of vifs sat on the bridge for which there is no frontend (at least yet, but maybe never)... so the bridge wastes time in every packet sent to such a vif.
I don't think netback has ever waited for a frontend before running hotplug scripts.
Quoted 8 lines
Quoted 6 lines
In the udev times the hotplug script would be run upon vif creation, which happens in
netback_probe, and when launching hotplug scripts from libxl the script is executed when the backend changes to state 2, which happens almost immediately because netback switches to state 2 when the frotnend is in state 1 which is the initial frontend state.I suspect I must be remembering a XenServer-specific hack^Wpatch then. I'd have to dig... it's been a while since I messed with the netif state model, which is of course different the blkif state model.
Quite likely. With udev scripts is was feasible to only execute hotplug scripts for vifs with an attached frontend.
Quoted 6 lines
With libxl this is not possible, since hotplug scripts are run during domain creation, at which point the guest is completely paused.
I'm not that familiar with bridges and vifs, but maybe the vifs status can be set to offline until there's a frontend attached in order to reduce the bridge distributor load? (if that's not already the case).
I've found was the problem, and with some definition of "race condition" it could be named this way.
The problem is that for some reason xenstore watch on device add sometimes does not fire in xl devd. But then, when libxl in dom0 timeouts and remove the device, the xenstore watch in xl devd fire and hotplug script is called. At this point device is already gone, so it fails. xl devd then quickly calls hotplug script the second time, for device removal.
I have no idea why this xenstore watch do not fire, but triggering a no-op write into watched path (to trigger the watch again) workarounds the problem. I use a xenstore watch in dom0 for that[1] - which works. I suspect something related to KVM nested virtualization (lost interrupt?)...
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Roger Pau Monné
Quoted 1 line · Paul Durrant
I suspect I must be remembering a XenServer-specific hack^Wpatch then. I'd have to dig... it's been a while since I messed with the netif state model, which is of course different the blkif state model.
Quite likely. With udev scripts is was feasible to only execute hotplug scripts for vifs with an attached frontend.
Quoted 6 lines
With libxl this is not possible, since hotplug scripts are run during domain creation, at which point the guest is completely paused.
I'm not that familiar with bridges and vifs, but maybe the vifs status can be set to offline until there's a frontend attached in order to reduce the bridge distributor load? (if that's not already the case).
I've found was the problem, and with some definition of "race condition" it could be named this way.
The problem is that for some reason xenstore watch on device add sometimes does not fire in xl devd. But then, when libxl in dom0 timeouts and remove the device, the xenstore watch in xl devd fire and hotplug script is called. At this point device is already gone, so it fails. xl devd then quickly calls hotplug script the second time, for device removal.
Quoted 5 lines
I have no idea why this xenstore watch do not fire, but triggering a no-op write into watched path (to trigger the watch again) workarounds the problem. I use a xenstore watch in dom0 for that[1] - which works. I suspect something related to KVM nested virtualization (lost interrupt?)...
That's very weird, could you try to run xenstored in dom0 with trace enabled [0] in order to try to figure out what's happening?
I assume this only happens when running nested in KVM?
Thanks, Roger.
[0] http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/hotplug/Linux/launch-xenstore.in
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 24 lines · Roger Pau Monné
Quoted 23 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Roger Pau Monné
Quoted 1 line · Paul Durrant
I suspect I must be remembering a XenServer-specific hack^Wpatch then. I'd have to dig... it's been a while since I messed with the netif state model, which is of course different the blkif state model.
Quite likely. With udev scripts is was feasible to only execute hotplug scripts for vifs with an attached frontend.
Quoted 6 lines
With libxl this is not possible, since hotplug scripts are run during domain creation, at which point the guest is completely paused.
I'm not that familiar with bridges and vifs, but maybe the vifs status can be set to offline until there's a frontend attached in order to reduce the bridge distributor load? (if that's not already the case).
I've found was the problem, and with some definition of "race condition" it could be named this way.
The problem is that for some reason xenstore watch on device add sometimes does not fire in xl devd. But then, when libxl in dom0 timeouts and remove the device, the xenstore watch in xl devd fire and hotplug script is called. At this point device is already gone, so it fails. xl devd then quickly calls hotplug script the second time, for device removal.
Quoted 8 lines
Quoted 5 lines
I have no idea why this xenstore watch do not fire, but triggering a no-op write into watched path (to trigger the watch again) workarounds the problem. I use a xenstore watch in dom0 for that[1] - which works. I suspect something related to KVM nested virtualization (lost interrupt?)...
That's very weird, could you try to run xenstored in dom0 with trace enabled [0] in order to try to figure out what's happening?
I've tried already, but it was way too slow (remember it's nested KVM, it doesn't really improve the performance). I hit multiple timeouts even without hitting this problem. Unfortunately I don't have logs from that experiment anymore.
I can try again...
Quoted 1 line
I assume this only happens when running nested in KVM?
I'd say so. I'm not entirely sure, because I've seen similar symptoms on bare metal Xen too in the past, but I think it could be a different problem and also I haven't seen it in past 3 months.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel