xen/hvm kexec: unregister shutdown+sysrq watches during reboot
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Unregister the shutdown and sysrq watch during kexec. The watches can not be re-registered in the kexec kernel because they are still seen as busy by xenstore.
This and subsequent patches don't look right to me from a conceptual
pov: If the kexec attempt is due to a crash, the dying kernel should be doing as little as possible, and the new kernel should really do the cleanup. The more logic gets added to the shutdown path of the old kernel, the more likely it'll become that the kexec attempt will fail.
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Jan
Quoted 39 lines
Signed-off-by Olaf Hering <[email protected]>--- drivers/xen/manage.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)Index:
linux-3.0/drivers/xen/manage.c
===================================================================drivers/xen/manage.c +13
-0@@ -320,6 +320,18 @@ static int shutdown_event(struct notifiereturn NOTIFY_DONE ; } +static void xenbus_disable_shutdown_watcher (void ) +{ +unregister_xenbus_watch (&shutdown_watch); +#ifdef CONFIG_MAGIC_SYSRQ +unregister_xenbus_watch (&sysrq_watch); +#endif +} + +static struct syscore_ops xenbus_watcher_syscore_ops = { +.shutdown = xenbus_disable_shutdown_watcher, +}; +int xen_setup_shutdown_event (void ) {static struct notifier_block xenstore_notifier = {@@ -329,6 +341,7 @@ int xen_setup_shutdown_event(void)if (!xen_domain ())return -ENODEV ;register_xenstore_notifier (&xenstore_notifier); +register_syscore_ops (&xenbus_watcher_syscore_ops);return 0 ; }
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 10 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Unregister the shutdown and sysrq watch during kexec. The watches can not be re-registered in the kexec kernel because they are still seen as busy by xenstore.
This and subsequent patches don't look right to me from a conceptual
pov: If the kexec attempt is due to a crash, the dying kernel should be doing as little as possible, and the new kernel should really do the cleanup. The more logic gets added to the shutdown path of the old kernel, the more likely it'll become that the kexec attempt will fail.
kexec is about reboot, kdump is about crash handling. Both use different code paths.
The kexec code path is like a reboot without going through the firmware. The kdump kernel runs in its own memory range, so memory corruption does not appear to happen (with the sles11sp1 kernel + my kdump patch).
Quoted 3 lines
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot? And what about the event/irq handling? There is currently no way to check what virq is bound to what port, other than looping through all possible ports and see if one matches the requested virq.
Olaf
Quoted 13 lines · Olaf Hering
Quoted 10 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Unregister the shutdown and sysrq watch during kexec. The watches can not be re-registered in the kexec kernel because they are still seen as busy by xenstore.
This and subsequent patches don't look right to me from a conceptual
pov: If the kexec attempt is due to a crash, the dying kernel should be doing as little as possible, and the new kernel should really do the cleanup. The more logic gets added to the shutdown path of the old kernel, the more likely it'll become that the kexec attempt will fail.
Quoted 5 lines
kexec is about reboot, kdump is about crash handling. Both use different code paths.
The kexec code path is like a reboot without going through the firmware. The kdump kernel runs in its own memory range, so memory corruption does not appear to happen (with the sles11sp1 kernel + my kdump patch).
Getting into the kdump kernel is a kexec like operation though and shares many of the code paths, doesn't it?
Quoted 6 lines
Quoted 2 lines
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
Quoted 3 lines
And what about the event/irq handling? There is currently no way
to check what virq is bound to what port, other than looping through all possible ports and see if one matches the requested virq.
There is EVTCHNOP_reset but I'm not sure if it does too much. For example I'm not sure how the guest could recover event channels which are setup by the domain builder -- such as the xenstore event channel.
IIRC EVTCHNOP_reset was added to aid with kexec though -- so I must be missing something.
Ian.
Quoted 7 lines · Ian Campbell
Quoted 3 lines
And what about the event/irq handling? There is currently no way
to check what virq is bound to what port, other than looping through all possible ports and see if one matches the requested virq.There is
EVTCHNOP_resetbut I'm not sure if it does too much. For example I'm not sure how the guest could recover event channels which are setup by the domain builder -- such as the xenstore event channel.
EVTCHNOP_reset is currently only called from the toolstack, which is then able to re-setup things like the xenstore event channel for the guest.
-- Keir
Quoted 6 lines · Keir Fraser
Quoted 4 lines · Ian Campbell
Quoted 3 lines
And what about the event/irq handling? There is currently no way
to check what virq is bound to what port, other than looping through all possible ports and see if one matches the requested virq.
Quoted 6 lines
Quoted 3 lines
There is
EVTCHNOP_resetbut I'm not sure if it does too much. For example I'm not sure how the guest could recover event channels which are setup by the domain builder -- such as the xenstore event channel.
EVTCHNOP_resetis currently only called from the toolstack, which is then able to re-setup things like the xenstore event channel for the guest.
Oh, right. And toolstack isn't involved in kexec so that's not terribly helpful.
Ian.
Quoted 2 lines · Ian Campbell
Getting into the kdump kernel is a kexec like operation though and shares many of the code paths, doesn't it?
The big difference is that kdump is entered in an unreliable state, while kexec is a controlled reboot.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I wonder why xenstore knows that sysrq and shutdown nodes are busy, while the device, backend and state files can be watched twice.
Olaf
Quoted 7 lines · Olaf Hering
Quoted 2 lines · Ian Campbell
Getting into the kdump kernel is a kexec like operation though and shares many of the code paths, doesn't it?
The big difference is that kdump is entered in an unreliable state, while kexec is a controlled reboot.
Sure, but by handling the former you also solve the later, while the opposite is not true.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Quoted 5 lines
Quoted 2 lines
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I wonder why xenstore knows that sysrq and shutdown nodes are busy, while the device, backend and state files can be watched twice.
Do the precise path's watched differ subtly?
Oh, I see, xenstored only calls a watch a duplicate if both the path _and_ the token match. In the case of backend paths the token is a reference to the dynamically allocated per-device data structure. In the sysrq and shutdown case the token is a static global variable -- I suppose you are kexec'ing an identical kernel? I expect that if you kexec'd a subtly different kernel where these datastructures ended up at a different address you wouldn't get the EEXIST.
Ian.
Quoted 6 lines · Ian Campbell
Quoted 3 lines
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I poked around in the xenstore sources, there is appearently nothing that can be used to shutdown all. Or would calling XS_RELEASE do the trick?
Olaf
Quoted 11 lines · Olaf Hering
Quoted 6 lines · Ian Campbell
Quoted 3 lines
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I poked around in the xenstore sources, there is appearently nothing that can be used to shutdown all. Or would calling
XS_RELEASEdo the trick?
XS_INTRODUCE
K.
Quoted 6 lines
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Olaf Hering
Quoted 4 lines · Ian Campbell
Quoted 3 lines
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I poked around in the xenstore sources, there is appearently nothing that can be used to shutdown all. Or would calling
XS_RELEASEdo the trick?
XS_INTRODUCE
Unfortunately do_introduce() is not preprared for that.
On enter, conn->id contains the domain_id, so it errors out early. Later it compares domain->conn != conn and does not enter the correct path.
If I remove both checks the kexec appears to work ok. Is it save to remove both checks?
The only issue I havent figured out:
How to get the domid from within the kernel?
Olaf
tools/xenstore/xenstored_domain.c +2 -2
@@ -326,7 +326,7 @@ void do_introduce(struct connection *conreturn ; } -if (conn->id !=0 || !conn->can_write) { +if (!conn->can_write) {send_error (conn,EACCES );return ; }
@@ -365,7 +365,7 @@ void do_introduce(struct connection *contalloc_steal (domain->conn, domain);fire_watches (NULL ,"@introduceDomain" , false); - }else if ((domain->mfn == mfn) && (domain->conn != conn)) { + }else if (domain->mfn == mfn) {/* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port)xc_evtchn_unbind (xce_handle, domain->port);
Quoted 16 lines · Olaf Hering
Quoted 14 lines · Keir Fraser
Quoted 11 lines · Olaf Hering
Quoted 6 lines · Ian Campbell
Quoted 3 lines
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot?
Perhaps the xenstore protocol could be enhanced with a mechanism to clear all existing watches? A kernel could call that at start of day.
I poked around in the xenstore sources, there is appearently nothing that can be used to shutdown all. Or would calling
XS_RELEASEdo the trick?
Quoted 6 lines
Quoted 1 line
XS_INTRODUCEUnfortunately
do_introduce()is not preprared for that.On enter,
conn->idcontains thedomain_id, so it errors out early. Later it comparesdomain->conn!= conn and does not enter the correct path.
Oh of course you want to do it from *inside* the guest...
Quoted 2 lines
If I remove both checks the kexec appears to work ok. Is it save to remove both checks?
Hmm, no. Attached patch would be safer, give it a try.
And note that it is *dangerous* to reset the domain xenstore connection if there could be any other concurrent activity on the connection that could confuse the guest kernel. So doing the reset during kernel bringup might be safest, there you can do it in the kernel before the whole xenbus subsystem is fully up.
-- Keir
Quoted 18 lines
The only issue I havent figured out:
How to get the domid from within the kernel?Olaf
diff -r
42edf1481c57tools/xenstore/xenstored_domain.ctools/xenstore/xenstored_domain.c +1
-1@@ -326,7 +326,7 @@ void do_introduce(struct connection *conreturn ; } -if (conn->id !=0 || !conn->can_write) { +if (!conn->can_write) {send_error (conn,EACCES );return ; }
tools/xenstore/xenstored_domain.c void do_introduce(struct connection *con · line 371
Quoted 8 lines
tools/xenstore/xenstored_domain.c +1
-1@@ -365,7 +365,7 @@ void do_introduce(struct connection *contalloc_steal (domain->conn, domain);fire_watches (NULL ,"@introduceDomain" , false); - }else if ((domain->mfn == mfn) && (domain->conn != conn)) { + }else if (domain->mfn == mfn) {/* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port)xc_evtchn_unbind (xce_handle, domain->port);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 10 lines · Keir Fraser
Quoted 4 lines
Unfortunately
do_introduce()is not preprared for that.On enter,
conn->idcontains thedomain_id, so it errors out early. Later it comparesdomain->conn!= conn and does not enter the correct path.Oh of course you want to do it from *inside* the guest...
Quoted 2 lines
If I remove both checks the kexec appears to work ok. Is it save to remove both checks?
Quoted 7 lines
Hmm, no. Attached patch would be safer, give it a try.
And note that it is *dangerous* to reset the domain xenstore connection if there could be any other concurrent activity on the connection that could confuse the guest kernel. So doing the reset during kernel bringup might be safest, there you can do it in the kernel before the whole xenbus subsystem is fully up.
I sent a different xenstored patch which takes DOMID_SELF into account.
Olaf
Quoted 9 lines · Olaf Hering
Quoted 7 lines
Hmm, no. Attached patch would be safer, give it a try.
And note that it is *dangerous* to reset the domain xenstore connection if there could be any other concurrent activity on the connection that could confuse the guest kernel. So doing the reset during kernel bringup might be safest, there you can do it in the kernel before the whole xenbus subsystem is fully up.
I sent a different xenstored patch which takes
DOMID_SELFinto account.
Saw it, I'll give it a think over. I think it looks okay, I wonder whether DOMID_SELF handling should be pushed into find_domain_by_domid, but it's a minor detail really. I certainly support the approach. Hopefully we can get someone to similarly modify ocaml/xenstored too.
-- Keir
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Quoted 10 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Unregister the shutdown and sysrq watch during kexec. The watches can not be re-registered in the kexec kernel because they are still seen as busy by xenstore.
This and subsequent patches don't look right to me from a conceptual
pov: If the kexec attempt is due to a crash, the dying kernel should be doing as little as possible, and the new kernel should really do the cleanup. The more logic gets added to the shutdown path of the old kernel, the more likely it'll become that the kexec attempt will fail.
Quoted 3 lines
kexec is about reboot, kdump is about crash handling. Both use different code paths.
The kexec code path is like a reboot without going through the firmware.
Oh, I implied it would be kdump.
But then again xenstore state shouldn't matter wrt the purpose of the secondary kernel.
Quoted 2 lines
The kdump kernel runs in its own memory range, so memory corruption does not appear to happen (with the sles11sp1 kernel + my kdump patch).
It's also not clear to me what corruption there is - this would seem to imply that there should be information on certain addresses that were used in the old kernel to get passed to the new kernel, or get used to access guest memory from outside the guest. All of which sounds wrong.
Jan
Quoted 10 lines
Quoted 2 lines
If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
Are you suggesting that there have to be ways for a domU to query the state of its registered watches and shut them all down during very early boot? And what about the event/irq handling? There is currently no way to check what virq is bound to what port, other than looping through all possible ports and see if one matches the requested virq.
Olaf
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Unregister the shutdown and sysrq watch during kexec. The watches can not be re-registered in the kexec kernel because they are still seen as busy by xenstore.
Quoted 8 lines
This and subsequent patches don't look right to me from a conceptual
pov: If the kexec attempt is due to a crash, the dying kernel should be doing as little as possible, and the new kernel should really do the cleanup. The more logic gets added to the shutdown path of the old kernel, the more likely it'll become that the kexec attempt will fail.If this requires changes outside the kernel (e.g. state reset helpers in hypervisor or tools) - so be it.
I agree.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel