Fix PM hibernation in Xen guests
Subsystems (11)
v3 cover Fix PM hibernation in Xen guests
Hello,
This series fixes PM hibernation for hvm guests running on xen hypervisor. The running guest could now be hibernated and resumed successfully at a later time. The fixes for PM hibernation are added to block and network device drivers i.e xen-blkfront and xen-netfront. Any other driver that needs to add S4 support if not already, can follow same method of introducing freeze/thaw/restore callbacks.
The patches had been tested against upstream kernel and xen4.11. Large scale testing is also done on Xen based Amazon EC2 instances. All this testing involved running memory exhausting workload in the background.
Doing guest hibernation does not involve any support from hypervisor and this way guest has complete control over its state. Infrastructure restrictions for saving up guest state can be overcome by guest initiated hibernation.
These patches were send out as RFC before and all the feedback had been incorporated in the patches. The last v1 & v2 could be found here:
[v1]: https://lkml.org/lkml/2020/5/19/1312
[v2]: https://lkml.org/lkml/2020/7/2/995
All comments and feedback from v2 had been incorporated in v3 series.
Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.
Testing How to:
---------------
1. Setup xen hypervisor on a physical machine[ I used Ubuntu 16.04 +upstream xen-4.11]
2. Bring up a HVM guest w/t kernel compiled with hibernation patches [I used ubuntu18.04 netboot bionic images and also Amazon Linux on-prem images].
3. Create a swap file size=RAM size
4. Update grub parameters and reboot
5. Trigger pm-hibernation from within the VM
Example:
Set up a file-backed swap space. Swap file size>=Total memory on the system sudo dd if=/dev/zero of=/swap bs=$(( 1024 * 1024 )) count=4096 # 4096MiB sudo chmod 600 /swap
sudo mkswap /swap
sudo swapon /swap
Update resume device/resume offset in grub if using swap file:
resume=/dev/xvda1 resume_offset=200704 no_console_suspend=1
Execute:
--------
sudo pm-hibernate
OR
echo disk > /sys/power/state && echo reboot > /sys/power/disk
Compute resume offset code:
"
#!/usr/bin/env python
import sys
import array
import fcntl
#swap file
f = open(sys.argv[1], 'r')
buf = array.array('L', [0])
#FIBMAP
ret = fcntl.ioctl(f.fileno(), 0x01, buf)
print buf[0]
"
Aleksei Besogonov (1):
PM / hibernate: update the resume offset on SNAPSHOT_SET_SWAP_AREA
Anchal Agarwal (4):
x86/xen: Introduce new function to map HYPERVISOR_shared_info on
Resume
x86/xen: save and restore steal clock during PM hibernation
xen: Introduce wrapper for save/restore sched clock offset
xen: Update sched clock offset to avoid system instability in
hibernation
Munehisa Kamata (5):
xen/manage: keep track of the on-going suspend mode
xenbus: add freeze/thaw/restore callbacks support x86/xen: add system core suspend and resume callbacks
xen-blkfront: add callbacks for PM suspend and hibernation
xen-netfront: add callbacks for PM suspend and hibernation
Thomas Gleixner (1):
genirq: Shutdown irq chips in suspend/resume during hibernation
arch/x86/xen/enlighten_hvm.c | 7 +++ arch/x86/xen/suspend.c | 63 ++++++++++++++++++++ arch/x86/xen/time.c | 15 ++++- arch/x86/xen/xen-ops.h | 3 + drivers/block/xen-blkfront.c | 122 ++++++++++++++++++++++++++++++++++++-- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++- drivers/xen/events/events_base.c | 1 + drivers/xen/manage.c | 46 ++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++----- include/linux/irq.h | 2 + include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 3 + kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 +++++++--- kernel/power/user.c | 7 ++- 16 files changed, 464 insertions(+), 34 deletions(-)
Signature · 1 line
2.16.6
PATCH v3 1/11 xen/manage: keep track of the on-going suspend mode
From: Munehisa Kamata <[email protected]>
Guest hibernation is different from xen suspend/resume/live migration. Xen save/restore does not use pm_ops as is needed by guest hibernation. Hibernation in guest follows ACPI path and is guest inititated , the hibernation image is saved within guest as compared to later modes which are xen toolstack assisted and image creation/storage is in control of hypervisor/host machine.
To differentiate between Xen suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new API to keep track of SHUTDOWN_SUSPEND state.
Introduce a simple function that keeps track of on-going suspend mode so that PM hibernation code can behave differently according to the current suspend mode.
Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquire pm_mutex.
Though, accquirng pm_mutex is still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to wait pm_mutex which is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.
[Anchal Agarwal: Changelog]:
RFC v1->v2: Code refactoring
v1->v2: Remove unused functions for PM SUSPEND/PM hibernation
v2->v3: Added logic to use existing pm_notifier to detect for ARM
and abort hibernation for ARM guests. Also removed different suspend_modes and simplified the code with using existing state variables for tracking Xen suspend. The notifier won't get registered for pvh dom0 either.
--- drivers/xen/manage.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 1 + 2 files changed, 47 insertions(+)
drivers/xen/manage.c +46 -0
@@ -14,6 +14,7 @@#include <linux/freezer.h> #include <linux/syscore_ops.h> #include <linux/export.h> +#include <linux/suspend.h> #include <xen/xen.h> #include <xen/xenbus.h>
@@ -40,6 +41,11 @@ enum shutdown_state {/* Ignore multiple shutdown requests. */ static enum shutdown_state shutting_down =SHUTDOWN_INVALID ; +bool is_xen_suspend (void ) +{ +return shutting_down ==SHUTDOWN_SUSPEND ; +} +struct suspend_info {int cancelled; };
@@ -99,6 +105,8 @@ static void do_suspend(void)int err;struct suspend_info si; +lock_system_sleep (); + shutting_down =SHUTDOWN_SUSPEND ; err =freeze_processes ();
@@ -162,6 +170,8 @@ static void do_suspend(void)thaw_processes (); out: shutting_down =SHUTDOWN_INVALID ; + + unlock_system_sleep(); }#endif /* CONFIG_HIBERNATE_CALLBACKS */
@@ -387,3 +397,39 @@ int xen_setup_shutdown_event(void)EXPORT_SYMBOL_GPL (xen_setup_shutdown_event);subsys_initcall (xen_setup_shutdown_event); + +static int xen_pm_notifier (struct notifier_block *notifier, +unsigned long pm_event,void *unused) +{ +int ret; + +switch (pm_event) { +case PM_SUSPEND_PREPARE : +case PM_HIBERNATION_PREPARE : +/* Guest hibernation is not supported for aarch64 currently*/ +if (IS_ENABLED (CONFIG_ARM64 )) { + ret =NOTIFY_BAD ; +break ; + } +case PM_RESTORE_PREPARE : +case PM_POST_SUSPEND : +case PM_POST_HIBERNATION : +case PM_POST_RESTORE : +default : + ret =NOTIFY_OK ; + } +return ret; +}; + +static struct notifier_block xen_pm_notifier_block = { + .notifier_call = xen_pm_notifier +}; + +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ; +return register_pm_notifier (&xen_pm_notifier_block); +} + +subsys_initcall (xen_setup_pm_notifier);
include/xen/xen-ops.h +1 -0
@@ -40,6 +40,7 @@ u64 xen_steal_clock(int cpu);int xen_setup_shutdown_event (void ); +bool is_xen_suspend (void );extern unsigned long *xen_contiguous_bitmap;#if defined(CONFIG_XEN_PV ) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 )
Signature · 1 line
2.16.6
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 16 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Guest hibernation is different from xen suspend/resume/live migration. Xen save/restore does not use
pm_opsas is needed by guest hibernation. Hibernation in guest follows ACPI path and is guest inititated , the hibernation image is saved within guest as compared to later modes which are xen toolstack assisted and image creation/storage is in control of hypervisor/host machine.
To differentiate between Xen suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new API to keep track ofSHUTDOWN_SUSPENDstate.
Introduce a simple function that keeps track of on-going suspend mode so that PM hibernation code can behave differently according to the current suspend mode.
Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquirepm_mutex.
lock_system_sleep() is not taking this mutex.
Quoted 7 lines
Though, accquirng
pm_mutexis still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to waitpm_mutexwhich is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.
Is it Xen's shutdown or suspend code that needs to address this? (Or I may not understand what the problem is that you are describing)
Quoted 5 lines
drivers/xen/manage.c +4
-0+ +static int xen_pm_notifier (struct notifier_block *notifier, +unsigned long pm_event,void *unused) +{
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 413
Quoted 10 lines
drivers/xen/manage.c +10
-0+int ret; + +switch (pm_event) { +case PM_SUSPEND_PREPARE : +case PM_HIBERNATION_PREPARE : +/* Guest hibernation is not supported for aarch64 currently*/ +if (IS_ENABLED (CONFIG_ARM64 )) { + ret =NOTIFY_BAD ; +break ; + }
Indentation.
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 422
Quoted 9 lines
drivers/xen/manage.c +9
-0+case PM_RESTORE_PREPARE : +case PM_POST_SUSPEND : +case PM_POST_HIBERNATION : +case PM_POST_RESTORE : +default : + ret =NOTIFY_OK ; + } +return ret; +};
This whole routine now is
if (IS_ENABLED(CONFIG_ARM64)) return NOTIFY_BAD; return NOTIFY_OK;
isn't it?
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 9 lines
drivers/xen/manage.c +9
-0+ +static struct notifier_block xen_pm_notifier_block = { + .notifier_call = xen_pm_notifier +}; + +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;
I don't think this works anymore.
In the past your notifier would set suspend_mode (or something) but now it really doesn't do anything except reports an error in some (ARM) cases.
So I think you should move this check into the notifier.
(And BTW I still think PM_SUSPEND_PREPARE should return an error too. The fact that we are using "suspend" in xen routine names is irrelevant)
-boris
Quoted 3 lines
drivers/xen/manage.c +3
-0+return register_pm_notifier (&xen_pm_notifier_block); +} +
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 23 lines · On Sun, Sep 13, 2020 at 11:43:30AM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 16 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Guest hibernation is different from xen suspend/resume/live migration. Xen save/restore does not use
pm_opsas is needed by guest hibernation. Hibernation in guest follows ACPI path and is guest inititated , the hibernation image is saved within guest as compared to later modes which are xen toolstack assisted and image creation/storage is in control of hypervisor/host machine.
To differentiate between Xen suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new API to keep track ofSHUTDOWN_SUSPENDstate.
Introduce a simple function that keeps track of on-going suspend mode so that PM hibernation code can behave differently according to the current suspend mode.
Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquirepm_mutex.
Quoted 2 lines
lock_system_sleep()is not taking this mutex.
Yes, I just realized that the commit 55f2503c ("PM / reboot: Eliminate race between reboot and suspend") changed its name to system_transition_mutex. I think I missed that change somehow and assumed its still pm_mutex. Will fix the description.
Quoted 11 lines
Quoted 8 lines
Though, accquirng
pm_mutexis still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to waitpm_mutexwhich is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.
Quoted 3 lines
Is it Xen's shutdown or suspend code that needs to address this? (Or I may not understand what the problem is that you are describing)
Its Xen suspend code I think. If we do not take the system_transition_mutex in do_suspend then if hibernation is triggered in parallel to xen suspend there could be issues. Now this is still theoretical in my case and I havent been able to reproduce such a race. So the approach the original author took was to take this lock which to me seems right.
And its Xen suspend and not Xen Shutdown. So basically if this scenario happens I am of the view one of other will fail to occur then how do we recover or avoid this at all.
Does that answer your question?
Quoted 30 lines
Quoted 6 lines
drivers/xen/manage.c +4
-0+ +static int xen_pm_notifier (struct notifier_block *notifier, +unsigned long pm_event,void *unused) +{drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 413
Quoted 10 lines
drivers/xen/manage.c +10
-0+int ret; + +switch (pm_event) { +case PM_SUSPEND_PREPARE : +case PM_HIBERNATION_PREPARE : +/* Guest hibernation is not supported for aarch64 currently*/ +if (IS_ENABLED (CONFIG_ARM64 )) { + ret =NOTIFY_BAD ; +break ; + }Indentation.
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 422
Quoted 9 lines
drivers/xen/manage.c +9
-0+case PM_RESTORE_PREPARE : +case PM_POST_SUSPEND : +case PM_POST_HIBERNATION : +case PM_POST_RESTORE : +default : + ret =NOTIFY_OK ; + } +return ret; +};
Quoted 9 lines
This whole routine now is
if (IS_ENABLED(CONFIG_ARM64)) return NOTIFY_BAD; return NOTIFY_OK;isn't it?
Yes.
Quoted 13 lines
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 10 lines
drivers/xen/manage.c +9
-0+ +static struct notifier_block xen_pm_notifier_block = { + .notifier_call = xen_pm_notifier +}; + +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;I don't think this works anymore.
What do you mean?
The first check is for xen domain types and other is for architecture support. The reason I put this check here is because I wanted to segregate the two. I do not want to register this notifier at all for !hmv guest and also if its an initial control domain.
The arm check only lands in notifier because once hibernate() api is called -> calls pm_notifier_call_chain for PM_HIBERNATION_PREPARE this will fail for aarch64.
Once we have support for aarch64 this notifier can go away altogether.
Is there any other reason I may be missing why we should move this check to notifier?
Quoted 10 lines
In the past your notifier would set
suspend_mode(or something) but now it really doesn't do anything except reports an error in some (ARM) cases.So I think you should move this check into the notifier.
(And BTW I still think
PM_SUSPEND_PREPAREshould return an error too. The fact that we are using "suspend" in xen routine names is irrelevant)
I may have send "not-updated" version of the notifier's function change.
+ switch (pm_event) {
+ case PM_HIBERNATION_PREPARE:
+ /* Guest hibernation is not supported for aarch64 currently*/
+ if (IS_ENABLED(CONFIG_ARM64)) {
+ ret = NOTIFY_BAD;
+ break;
+ }
+ case PM_RESTORE_PREPARE: + case PM_POST_RESTORE: + case PM_POST_HIBERNATION: + default:
+ ret = NOTIFY_OK;
+ }
With the above path PM_SUSPEND_PREPARE will go all together. Does that resolves this issue? I wanted to get rid of all SUSPEND_* as they are not needed here clearly.
The only reason I kept it there is if someone tries to trigger hibernation on ARM instances they should get an error. As I am not sure about the current behavior. There may be a better way to not invoke hibernation on ARM DomU's and get rid of this block all together.
Again, sorry for sending in the half baked fix. My workspace switch may have caused the error.
Quoted 5 lines
-boris
Anchal
Quoted 5 lines
Quoted 5 lines
drivers/xen/manage.c +3
-0+return register_pm_notifier (&xen_pm_notifier_block); +} +
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 14 lines · Anchal Agarwal
Quoted 13 lines · On Sun, Sep 13, 2020 at 11:43:30AM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 6 lines · Anchal Agarwal
Though, accquirng
pm_mutexis still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to waitpm_mutexwhich is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.
Quoted 6 lines
Quoted 3 lines
Is it Xen's shutdown or suspend code that needs to address this? (Or I may not understand what the problem is that you are describing)
Its Xen suspend code I think. If we do not take the
system_transition_mutexindo_suspendthen if hibernation is triggered in parallel to xen suspend there could be issues.
But you *are* taking this mutex to avoid this exact race, aren't you?
Quoted 28 lines
Now this is still theoretical in my case and I havent been able
to reproduce such a race. So the approach the original author took was to take this lock which to me seems right.
And its Xen suspend and not Xen Shutdown. So basically if this scenario happens I am of the view one of other will fail to occur then how do we recover or avoid this at all.Does that answer your question?
Quoted 7 lines
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 5 lines
drivers/xen/manage.c +5
-0+ +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;I don't think this works anymore.
What do you mean?
The first check is for xen domain types and other is for architecture support. The reason I put this check here is because I wanted to segregate the two. I do not want to register this notifier at all for !hmv guest and also if its an initial control domain.
The arm check only lands in notifier because oncehibernate()api is called -> callspm_notifier_call_chainforPM_HIBERNATION_PREPAREthis will fail for aarch64.
Once we have support for aarch64 this notifier can go away altogether.
Quoted 2 lines
Is there any other reason I may be missing why we should move this check to notifier?
Not registering this notifier is equivalent to having it return NOTIFY_OK.
In your earlier versions just returning NOTIFY_OK was not sufficient for hibernation to proceed since the notifier would also need to set suspend_mode appropriately. But now your notifier essentially filters out unsupported configurations. And so if it is not called your configuration (e.g. PV domain) will be considered supported.
Quoted 12 lines
Quoted 7 lines
In the past your notifier would set
suspend_mode(or something) but now it really doesn't do anything except reports an error in some (ARM) cases.So I think you should move this check into the notifier. (And BTW I still think
PM_SUSPEND_PREPAREshould return an error too. The fact that we are using "suspend" in xen routine names is irrelevant)I may have send "not-updated" version of the notifier's function change.
drivers/xen/manage.c +3
-0+switch (pm_event) { +case PM_HIBERNATION_PREPARE : +/* Guest hibernation is not supported for aarch64 currently*/
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 420
Quoted 10 lines
drivers/xen/manage.c +10
-0+if (IS_ENABLED (CONFIG_ARM64 )) { + ret =NOTIFY_BAD ; +break ; + } +case PM_RESTORE_PREPARE : +case PM_POST_RESTORE : +case PM_POST_HIBERNATION : +default : + ret =NOTIFY_OK ; + }
There is no difference on x86 between this code and what you sent earlier. In both instances PM_SUSPEND_PREPARE will return NOTIFY_OK.
On ARM this code will allow suspend to proceed (which is not what we want).
-boris
Quoted 20 lines
With the above path
PM_SUSPEND_PREPAREwill go all together. Does that resolves this issue? I wanted to get rid of all SUSPEND_* as they are not needed here clearly.
The only reason I kept it there is if someone tries to trigger hibernation on ARM instances they should get an error. As I am not sure about the current behavior. There may be a better way to not invoke hibernation on ARM DomU's and get rid of this block all together.Again, sorry for sending in the half baked fix. My workspace switch may have caused the error.
Quoted 4 lines
-boris
Anchal
Quoted 4 lines
Quoted 4 lines
drivers/xen/manage.c +3
-0+return register_pm_notifier (&xen_pm_notifier_block); +} +
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 22 lines · On Mon, Sep 14, 2020 at 08:24:22PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 17 lines · Anchal Agarwal
Quoted 16 lines · On Sun, Sep 13, 2020 at 11:43:30AM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 6 lines · Anchal Agarwal
Though, accquirng
pm_mutexis still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to waitpm_mutexwhich is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.Is it Xen's shutdown or suspend code that needs to address this? (Or I may not understand what the problem is that you are describing)
Quoted 6 lines
Quoted 3 lines
Its Xen suspend code I think. If we do not take the
system_transition_mutexindo_suspendthen if hibernation is triggered in parallel to xen suspend there could be issues.But you *are* taking this mutex to avoid this exact race, aren't you?
yes, in that case this race should not occur and either one of it should fail gracefully.
Quoted 30 lines
Quoted 30 lines
Now this is still theoretical in my case and I havent been able
to reproduce such a race. So the approach the original author took was to take this lock which to me seems right.
And its Xen suspend and not Xen Shutdown. So basically if this scenario happens I am of the view one of other will fail to occur then how do we recover or avoid this at all.Does that answer your question?
Quoted 7 lines
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 5 lines
drivers/xen/manage.c +5
-0+ +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;I don't think this works anymore.
What do you mean?
The first check is for xen domain types and other is for architecture support. The reason I put this check here is because I wanted to segregate the two. I do not want to register this notifier at all for !hmv guest and also if its an initial control domain.
The arm check only lands in notifier because oncehibernate()api is called -> callspm_notifier_call_chainforPM_HIBERNATION_PREPAREthis will fail for aarch64.
Once we have support for aarch64 this notifier can go away altogether.
Quoted 6 lines
Quoted 2 lines
Is there any other reason I may be missing why we should move this check to notifier?
Not registering this notifier is equivalent to having it return
NOTIFY_OK.
How is that different from current behavior?
Quoted 7 lines
In your earlier versions just returning
NOTIFY_OKwas not sufficient for hibernation to proceed since the notifier would also need to setsuspend_modeappropriately. But now your notifier essentially filters out unsupported configurations. And so if it is not called your configuration (e.g. PV domain) will be considered supported.
I am sorry if I am having a bit of hard time understanding this. How will it be considered supported when its not even registered? My understanding is if its not registered, it will not land in notifier call chain which is invoked in pm_notifier_call_chain().
As Roger, mentioned in last series none of this should be a part of PVH dom0 hibernation as its not tested but this series should also not break anything. If I register this notifier for PVH dom0 and return error later that will alter the current behavior right?
If a pm_notifier for pvh dom0 is not registered then it will not land in the notifier call chain and system will work as before this series. If I look for unsupported configurations, then !hvm domain is also one but we filter that out at the beginning and don't even bother about it.
Unless you mean guest running VMs itself? [Trying to read between the lines may not be the case though]
Quoted 25 lines
Quoted 13 lines
Quoted 8 lines
In the past your notifier would set
suspend_mode(or something) but now it really doesn't do anything except reports an error in some (ARM) cases.So I think you should move this check into the notifier. (And BTW I still think
PM_SUSPEND_PREPAREshould return an error too. The fact that we are using "suspend" in xen routine names is irrelevant)I may have send "not-updated" version of the notifier's function change.
drivers/xen/manage.c +3
-0+switch (pm_event) { +case PM_HIBERNATION_PREPARE : +/* Guest hibernation is not supported for aarch64 currently*/ drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 420
Quoted 10 lines
drivers/xen/manage.c +10
-0+if (IS_ENABLED (CONFIG_ARM64 )) { + ret =NOTIFY_BAD ; +break ; + } +case PM_RESTORE_PREPARE : +case PM_POST_RESTORE : +case PM_POST_HIBERNATION : +default : + ret =NOTIFY_OK ; + }
Quoted 6 lines
There is no difference on x86 between this code and what you sent earlier. In both instances
PM_SUSPEND_PREPAREwill returnNOTIFY_OK.On ARM this code will allow suspend to proceed (which is not what we want).
Ok, I think I may have overlooked arm code. I will fix that.
Quoted 3 lines
-boris
Thanks,
Anchal
Quoted 21 lines
Quoted 21 lines
With the above path
PM_SUSPEND_PREPAREwill go all together. Does that resolves this issue? I wanted to get rid of all SUSPEND_* as they are not needed here clearly.
The only reason I kept it there is if someone tries to trigger hibernation on ARM instances they should get an error. As I am not sure about the current behavior. There may be a better way to not invoke hibernation on ARM DomU's and get rid of this block all together.Again, sorry for sending in the half baked fix. My workspace switch may have caused the error.
Quoted 4 lines
-boris
Anchal
Quoted 4 lines
Quoted 4 lines
drivers/xen/manage.c +3
-0+return register_pm_notifier (&xen_pm_notifier_block); +} +
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 35 lines
Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 9 lines
drivers/xen/manage.c +5
-0+ +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;I don't think this works anymore.
What do you mean?
The first check is for xen domain types and other is for architecture support. The reason I put this check here is because I wanted to segregate the two. I do not want to register this notifier at all for !hmv guest and also if its an initial control domain.
The arm check only lands in notifier because oncehibernate()api is called -> callspm_notifier_call_chainforPM_HIBERNATION_PREPAREthis will fail for aarch64.
Once we have support for aarch64 this notifier can go away altogether.Quoted 6 lines
Quoted 2 lines
Is there any other reason I may be missing why we should move this check to notifier?
Not registering this notifier is equivalent to having it return
NOTIFY_OK.How is that different from current behavior?
Quoted 7 lines
In your earlier versions just returning
NOTIFY_OKwas not sufficient for hibernation to proceed since the notifier would also need to setsuspend_modeappropriately. But now your notifier essentially filters out unsupported configurations. And so if it is not called your configuration (e.g. PV domain) will be considered supported.
Quoted 4 lines
I am sorry if I am having a bit of hard time understanding this. How will it be considered supported when its not even registered? My understanding is if its not registered, it will not land in notifier call chain which is invoked in
pm_notifier_call_chain().
Returning an error from xen_setup_pm_notifier() doesn't have any effect on whether hibernation will start. It's the notifier that can stop it.
Quoted 6 lines
As Roger, mentioned in last series none of this should be a part of PVH dom0 hibernation as its not tested but this series should also not break anything. If I register this notifier for PVH dom0 and return error later that will alter the current behavior right?
Quoted 7 lines
If a
pm_notifierfor pvh dom0 is not registered then it will not land in the notifier call chain and system will work as before this series. If I look for unsupported configurations, then !hvm domain is also one but we filter that out at the beginning and don't even bother about it.Unless you mean guest running VMs itself? [Trying to read between the lines may not be the case though]
In hibernate():
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1,
&nr_calls);
if (error) {
nr_calls--;
goto Exit;
}Is you don't have notifier registered (as will be the case with PV domains and dom0) you won't get an error and proceed with hibernation. (And now I actually suspect it didn't work even with your previous patches)
But something like this I think will do what you want:
static int xen_pm_notifier(struct notifier_block *notifier,
unsigned long pm_event, void *unused)
{
if (IS_ENABLED(CONFIG_ARM64) ||
!xen_hvm_domain() || xen_initial_domain() ||
(pm_event == PM_SUSPEND_PREPARE)) {
if ((pm_event == PM_SUSPEND_PREPARE) || (pm_event ==
PM_HIBERNATION_PREPARE))
pr_warn("%s is not supported for this guest",
(pm_event == PM_SUSPEND_PREPARE) ?
"Suspend" : "Hibernation");
return NOTIFY_BAD;
return NOTIFY_OK;}
static int xen_setup_pm_notifier(void)
{
return register_pm_notifier(&xen_pm_notifier_block);
}I tried to see if there is a way to prevent hibernation without using notifiers (like having a global flag or something) but didn't find anything obvious. Perhaps others can point to a simpler way of doing this.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 37 lines · On Tue, Sep 15, 2020 at 03:58:45PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 33 lines
Quoted 19 lines
Quoted 19 lines
Quoted 9 lines
drivers/xen/manage.c int xen_setup_shutdown_event(void) · line 431
Quoted 7 lines
drivers/xen/manage.c +5
-0+ +static int xen_setup_pm_notifier (void ) +{ +if (!xen_hvm_domain () ||xen_initial_domain ()) +return -ENODEV ;I don't think this works anymore.
What do you mean?
The first check is for xen domain types and other is for architecture support. The reason I put this check here is because I wanted to segregate the two. I do not want to register this notifier at all for !hmv guest and also if its an initial control domain.
The arm check only lands in notifier because oncehibernate()api is called -> callspm_notifier_call_chainforPM_HIBERNATION_PREPAREthis will fail for aarch64.
Once we have support for aarch64 this notifier can go away altogether.Quoted 6 lines
Quoted 2 lines
Is there any other reason I may be missing why we should move this check to notifier?
Not registering this notifier is equivalent to having it return
NOTIFY_OK.How is that different from current behavior?
Quoted 7 lines
In your earlier versions just returning
NOTIFY_OKwas not sufficient for hibernation to proceed since the notifier would also need to setsuspend_modeappropriately. But now your notifier essentially filters out unsupported configurations. And so if it is not called your configuration (e.g. PV domain) will be considered supported.
Quoted 9 lines
Quoted 4 lines
I am sorry if I am having a bit of hard time understanding this. How will it be considered supported when its not even registered? My understanding is if its not registered, it will not land in notifier call chain which is invoked in
pm_notifier_call_chain().Returning an error from
xen_setup_pm_notifier()doesn't have any effect on whether hibernation will start. It's the notifier that can stop it.
I actually got that point where we have to return an error for certain scenarios to fail.
What I was trying to understand a scenario is if there is no notifier involved and xen_initial_domain() is true what should happen when hibernation is triggered on such domain?
After my changes yes, it should not be able to proceed as you suggested below when hibernation is triggered from within Xen guest.
Quoted 51 lines
Quoted 6 lines
As Roger, mentioned in last series none of this should be a part of PVH dom0 hibernation as its not tested but this series should also not break anything. If I register this notifier for PVH dom0 and return error later that will alter the current behavior right?
Quoted 7 lines
If a
pm_notifierfor pvh dom0 is not registered then it will not land in the notifier call chain and system will work as before this series. If I look for unsupported configurations, then !hvm domain is also one but we filter that out at the beginning and don't even bother about it.Unless you mean guest running VMs itself? [Trying to read between the lines may not be the case though]
In
hibernate():error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1,
&nr_calls); if (error) { nr_calls--; goto Exit; }Is you don't have notifier registered (as will be the case with PV domains and dom0) you won't get an error and proceed with hibernation. (And now I actually suspect it didn't work even with your previous patches)
But something like this I think will do what you want:
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused){
if (IS_ENABLED(CONFIG_ARM64) || !xen_hvm_domain() || xen_initial_domain() || (pm_event == PM_SUSPEND_PREPARE)) { if ((pm_event == PM_SUSPEND_PREPARE) || (pm_event == PM_HIBERNATION_PREPARE)) pr_warn("%s is not supported for this guest", (pm_event == PM_SUSPEND_PREPARE) ? "Suspend" : "Hibernation"); return NOTIFY_BAD; return NOTIFY_OK;
Quoted 8 lines
}
static int
xen_setup_pm_notifier(void){ return register_pm_notifier(&xen_pm_notifier_block); }
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct notifier_block *notifier,
unsigned long pm_event, void *unused)
{
int ret = NOTIFY_OK;
if (!xen_hvm_domain() || xen_initial_domain())
ret = NOTIFY_BAD;
if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE))
ret = NOTIFY_BAD;
return ret;
}Quoted 8 lines
I tried to see if there is a way to prevent hibernation without using notifiers (like having a global flag or something) but didn't find anything obvious. Perhaps others can point to a simpler way of doing this.
-boris
-Anchal
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 7 lines · Anchal Agarwal
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused)
Quoted 9 lines
{
int ret = NOTIFY_OK;
if (!xen_hvm_domain() || xen_initial_domain())
ret = NOTIFY_BAD;
if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE))
ret = NOTIFY_BAD;
return ret;
}This will allow PM suspend to proceed on x86.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 19 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 14 lines · Anchal Agarwal
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused){ int ret = NOTIFY_OK; if (!xen_hvm_domain() || xen_initial_domain()) ret = NOTIFY_BAD; if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE)) ret = NOTIFY_BAD;
Quoted 6 lines
Quoted 2 lines
return ret; }This will allow PM suspend to proceed on x86.
Right!! Missed it.
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it. I seem to have lost your email in my inbox hence covering the question here.
Quoted 4 lines
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 25 lines · Anchal Agarwal
Quoted 24 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 16 lines · Anchal Agarwal
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused){ int ret = NOTIFY_OK; if (!xen_hvm_domain() || xen_initial_domain()) ret = NOTIFY_BAD; if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE)) ret = NOTIFY_BAD; return ret; }
Quoted 7 lines
Quoted 1 line
This will allow PM suspend to proceed on x86.
Right!! Missed it.
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it. I seem to have lost your email in my inbox hence covering the question here.Quoted 2 lines
Can I add your Reviewed-by or Signed-off-by to it?
Quoted 3 lines
Quoted 2 lines
-boris
-Anchal
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 21 lines · Anchal Agarwal
Quoted 20 lines · Anchal Agarwal
Quoted 19 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 14 lines · Anchal Agarwal
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused){ int ret = NOTIFY_OK; if (!xen_hvm_domain() || xen_initial_domain()) ret = NOTIFY_BAD; if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE)) ret = NOTIFY_BAD;
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
return ret; }This will allow PM suspend to proceed on x86.
Right!! Missed it.
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.
So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
Quoted 4 lines
Quoted 3 lines
I seem to have lost your email
in my inbox hence covering the question here.Quoted 1 line
Can I add your Reviewed-by or Signed-off-by to it?
Are you asking me to add my R-b to the broken code above?
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 30 lines · On Fri, Sep 25, 2020 at 04:02:58PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 25 lines · Anchal Agarwal
Quoted 24 lines · Anchal Agarwal
Quoted 23 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 16 lines · Anchal Agarwal
Thanks for the above suggestion. You are right I didn't find a way to declare a global state either. I just broke the above check in 2 so that once we have support for ARM we should be able to remove aarch64 condition easily. Let me know if I am missing nay corner cases with this one.
static int xen_pm_notifier(struct
notifier_block*notifier,
unsigned longpm_event, void *unused){ int ret = NOTIFY_OK; if (!xen_hvm_domain() || xen_initial_domain()) ret = NOTIFY_BAD; if(IS_ENABLED(CONFIG_ARM64) && (pm_event == PM_SUSPEND_PREPARE || pm_event == HIBERNATION_PREPARE)) ret = NOTIFY_BAD; return ret; }
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
This will allow PM suspend to proceed on x86.
Right!! Missed it.
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
I do want to fix it and did do some debugging earlier this year just haven't
gotten back to it. Also, wanted to understand if the issue is a blocker to this
series?
I had some theories when debugging around this like if the random base address picked by kaslr for the resuming kernel mismatches the suspended kernel and just jogging my memory, I didn't find that as the case. Another hunch was if physical address of registered vcpu info at boot is different from what suspended kernel has and that can cause CPU's to get stuck when coming online. The issue was only reproducible 3% of the time out of 3000 runs hence its hard to just reproduce this.
Moreover, I also wanted to get an insight on if hibernation works correctly with KASLR generally and its only Xen causing the issue?
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
I seem to have lost your email
in my inbox hence covering the question here.Quoted 1 line
Can I add your Reviewed-by or Signed-off-by to it?
Are you asking me to add my R-b to the broken code above?
Of course not!! After its fixed.
Well can forget it for now then!
Quoted 3 lines
-boris
Thanks,
Anchal
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 14 lines · Anchal Agarwal
Quoted 12 lines · On Fri, Sep 25, 2020 at 04:02:58PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 7 lines · Anchal Agarwal
Quoted 6 lines · Anchal Agarwal
Quoted 5 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
On 9/21/20 5:54 PM, Anchal Agarwal wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.
So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
I do want to fix it and did do some debugging earlier this year just haven't gotten back to it. Also, wanted to understand if the issue is a blocker to this series?
Integrating code with known bugs is less than ideal.
3% failure for this feature seems to be a manageable number from the reproducability perspective --- you should be able to script this and each iteration should take way under a minute, no?
Quoted 4 lines
I had some theories when debugging around this like if the random base address picked by kaslr for the resuming kernel mismatches the suspended kernel and just jogging my memory, I didn't find that as the case. Another hunch was if physical address of registered vcpu info at boot is different from what suspended kernel has and that can cause CPU's to get stuck when coming online.
I'd think if this were the case you'd have 100% failure rate. And we are also re-registering vcpu info on xen restore and I am not aware of any failures due to KASLR.
Quoted 5 lines
The issue was only
reproducible 3% of the time out of 3000 runs hence its hard to just reproduce this.Moreover, I also wanted to get an insight on if hibernation works correctly with KASLR generally and its only Xen causing the issue?
With KASLR being on by default I'd be surprised if it didn't.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 22 lines · On Mon, Sep 28, 2020 at 02:49:56PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 17 lines · Anchal Agarwal
Quoted 16 lines · On Fri, Sep 25, 2020 at 04:02:58PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 10 lines · Anchal Agarwal
Quoted 9 lines · Anchal Agarwal
Quoted 8 lines · On Tue, Sep 22, 2020 at 12:18:05PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
On 9/21/20 5:54 PM, Anchal Agarwal wrote:
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
I do want to fix it and did do some debugging earlier this year just haven't gotten back to it. Also, wanted to understand if the issue is a blocker to this series?
Integrating code with known bugs is less than ideal.
So for this series to be accepted, KASLR needs to be fixed along with other comments of course?
Quoted 4 lines
3% failure for this feature seems to be a manageable number from the reproducability perspective --- you should be able to script this and each iteration should take way under a minute, no?
Yes it should be doable. The % is not constant here that's the max I have seen. Also, if at worse it takes a min per run and I have to run 2000-3000 runs to produce failure that will still be slower. I have to dig in to see if I can find a better way.
Quoted 8 lines
Quoted 4 lines
I had some theories when debugging around this like if the random base address picked by kaslr for the resuming kernel mismatches the suspended kernel and just jogging my memory, I didn't find that as the case. Another hunch was if physical address of registered vcpu info at boot is different from what suspended kernel has and that can cause CPU's to get stuck when coming online.
I'd think if this were the case you'd have 100% failure rate. And we are also re-registering vcpu info on xen restore and I am not aware of any failures due to KASLR.
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
Quoted 10 lines
Quoted 6 lines
The issue was only
reproducible 3% of the time out of 3000 runs hence its hard to just reproduce this.Moreover, I also wanted to get an insight on if hibernation works correctly with KASLR generally and its only Xen causing the issue?
With KASLR being on by default I'd be surprised if it didn't.
Thant makes it xen specific then. Also, I have not seen the issue on KVM based instances.
Quoted 3 lines
-boris
- Anchal
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.
So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I do want to fix it and did do some debugging earlier this year just haven't gotten back to it. Also, wanted to understand if the issue is a blocker to this series?
Integrating code with known bugs is less than ideal.
So for this series to be accepted, KASLR needs to be fixed along with other comments of course?
Yes, please.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I had some theories when debugging around this like if the random base address picked by kaslr for the resuming kernel mismatches the suspended kernel and just jogging my memory, I didn't find that as the case. Another hunch was if physical address of registered vcpu info at boot is different from what suspended kernel has and that can cause CPU's to get stuck when coming online.
Quoted 7 lines
Quoted 2 lines
I'd think if this were the case you'd have 100% failure rate. And we are also re-registering vcpu info on xen restore and I am not aware of any failures due to KASLR.
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 29 lines · On Thu, Oct 01, 2020 at 08:43:58AM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Also, wrt KASLR stuff, that issue is still seen sometimes but I haven't had bandwidth to dive deep into the issue and fix it.
So what's the plan there? You first mentioned this issue early this year and judged by your response it is not clear whether you will ever spend time looking at it.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I do want to fix it and did do some debugging earlier this year just haven't gotten back to it. Also, wanted to understand if the issue is a blocker to this series?
Integrating code with known bugs is less than ideal.
So for this series to be accepted, KASLR needs to be fixed along with other comments of course?
Yes, please.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I had some theories when debugging around this like if the random base address picked by kaslr for the resuming kernel mismatches the suspended kernel and just jogging my memory, I didn't find that as the case. Another hunch was if physical address of registered vcpu info at boot is different from what suspended kernel has and that can cause CPU's to get stuck when coming online.
I'd think if this were the case you'd have 100% failure rate. And we are also re-registering vcpu info on xen restore and I am not aware of any failures due to KASLR.
Quoted 9 lines
Quoted 5 lines
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
Hi Boris,
Apologies for picking this up after last year.
I did some dive deep on the above statement and that is indeed the case that's happening. I did some debugging around KASLR and hibernation using reboot mode.
I observed in my debug prints that whenever vcpu_info* address for secondary vcpu assigned in xen_vcpu_setup at boot is different than what is in the image, resume gets stuck for that vcpu in bringup_cpu(). That means we have different addresses for &per_cpu(xen_vcpu_info, cpu) at boot and after control jumps into the image.
I failed to get any prints after it got stuck in bringup_cpu() and
I do not have an option to send a sysrq signal to the guest or rather get a kdump.
This change is not observed in every hibernate-resume cycle. I am not sure if this is a bug or an
expected behavior.
Also, I am contemplating the idea that it may be a bug in xen code getting triggered only when
KASLR is enabled but I do not have substantial data to prove that.
Is this a coincidence that this always happens for 1st vcpu?
Moreover, since hypervisor is not aware that guest is hibernated and it looks like a regular shutdown to dom0 during reboot mode, will re-registering vcpu_info for secondary vcpu's even plausible? I could definitely use some advice to debug this further.
Some printk's from my debugging:
At Boot:
xen_vcpu_setup: xen_have_vcpu_info_placement=1 cpu=1, vcpup=0xffff9e548fa560e0, info.mfn=3996246 info.offset=224,
Image Loads:
It ends up in the condition:
xen_vcpu_setup()
{
...
if (xen_hvm_domain()) {
if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu))
return 0; }
...
}
xen_vcpu_setup: checking mfn on resume cpu=1, info.mfn=3934806 info.offset=224, &per_cpu(xen_vcpu_info, cpu)=0xffff9d7240a560e0
This is tested on c4.2xlarge [8vcpu 15GB mem] instance with 5.10 kernel running in the guest.
Thanks,
Anchal.
Quoted 4 lines
-boris
Boris Ostrovsky
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 17 lines · Anchal Agarwal
Quoted 8 lines
Quoted 5 lines
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
Hi Boris,
Apologies for picking this up after last year.
I did some dive deep on the above statement and that is indeed the case that's happening. I did some debugging around KASLR and hibernation using reboot mode.
I observed in my debug prints that whenever vcpu_info* address for secondary vcpu assigned inxen_vcpu_setupat boot is different than what is in the image, resume gets stuck for that vcpu inbringup_cpu(). That means we have different addresses for &per_cpu(xen_vcpu_info, cpu) at boot and after control jumps into the image.
Quoted 2 lines
I failed to get any prints after it got stuck in
bringup_cpu()and
I do not have an option to send a sysrq signal to the guest or rather get a kdump.
xenctx and xen-hvmctx might be helpful.
Quoted 7 lines
This change is not observed in every hibernate-resume cycle. I am not sure if this is a bug or an
expected behavior.
Also, I am contemplating the idea that it may be a bug in xen code getting triggered only when
KASLR is enabled but I do not have substantial data to prove that.
Is this a coincidence that this always happens for 1st vcpu?
Moreover, since hypervisor is not aware that guest is hibernated and it looks like a regular shutdown to dom0 during reboot mode, will re-registeringvcpu_infofor secondary vcpu's even plausible?
I think I am missing how this is supposed to work (maybe we've talked about this but it's been many months since then). You hibernate the guest and it writes the state to swap. The guest is then shut down? And what's next? How do you wake it up?
-boris
Quoted 31 lines
I could definitely use some advice to debug this further.
Some printk's from my debugging:
At Boot:
xen_vcpu_setup: xen_have_vcpu_info_placement=1 cpu=1, vcpup=0xffff9e548fa560e0, info.mfn=3996246 info.offset=224,Image Loads:
It ends up in the condition:
xen_vcpu_setup()
{
...if (xen_hvm_domain()) { if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu)) return 0;}
...
}
xen_vcpu_setup: checking mfn on resume cpu=1, info.mfn=3934806 info.offset=224, &per_cpu(xen_vcpu_info, cpu)=0xffff9d7240a560e0This is tested on c4.2xlarge [8vcpu 15GB mem] instance with 5.10 kernel running in the guest.
Thanks,
Anchal.Quoted 3 lines
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 38 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 17 lines · Anchal Agarwal
Quoted 8 lines
Quoted 5 lines
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
Hi Boris,
Apologies for picking this up after last year.
I did some dive deep on the above statement and that is indeed the case that's happening. I did some debugging around KASLR and hibernation using reboot mode.
I observed in my debug prints that whenever vcpu_info* address for secondary vcpu assigned inxen_vcpu_setupat boot is different than what is in the image, resume gets stuck for that vcpu inbringup_cpu(). That means we have different addresses for &per_cpu(xen_vcpu_info, cpu) at boot and after control jumps into the image.Quoted 2 lines
I failed to get any prints after it got stuck in
bringup_cpu()and
I do not have an option to send a sysrq signal to the guest or rather get a kdump.xenctx and xen-hvmctx might be helpful.
Quoted 7 lines
This change is not observed in every hibernate-resume cycle. I am not sure if this is a bug or an
expected behavior.
Also, I am contemplating the idea that it may be a bug in xen code getting triggered only when
KASLR is enabled but I do not have substantial data to prove that.
Is this a coincidence that this always happens for 1st vcpu?
Moreover, since hypervisor is not aware that guest is hibernated and it looks like a regular shutdown to dom0 during reboot mode, will re-registeringvcpu_infofor secondary vcpu's even plausible?
Quoted 5 lines
I think I am missing how this is supposed to work (maybe we've talked about this but it's been many months since then). You hibernate the guest and it writes the state to swap. The guest is then shut down? And what's next? How do you wake it up?
-boris
To resume a guest, guest boots up as the fresh guest and then software_resume() is called which if finds a stored hibernation image, quiesces the devices and loads the memory contents from the image. The control then transfers to the targeted kernel. This further disables non boot cpus,sycore_suspend/resume callbacks are invoked which sets up the shared_info, pvclock, grant tables etc. Since the vcpu_info pointer for each non-boot cpu is already registered, the hypercall does not happen again when bringing up the non boot cpus. This leads to inconsistencies as pointed
out earlier when KASLR is enabled.
Thanks,
Anchal
Quoted 33 lines
Quoted 33 lines
I could definitely use some advice to debug this further.
Some printk's from my debugging:
At Boot:
xen_vcpu_setup: xen_have_vcpu_info_placement=1 cpu=1, vcpup=0xffff9e548fa560e0, info.mfn=3996246 info.offset=224,Image Loads:
It ends up in the condition:
xen_vcpu_setup()
{
...if (xen_hvm_domain()) { if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu)) return 0;}
...
}
xen_vcpu_setup: checking mfn on resume cpu=1, info.mfn=3934806 info.offset=224, &per_cpu(xen_vcpu_info, cpu)=0xffff9d7240a560e0This is tested on c4.2xlarge [8vcpu 15GB mem] instance with 5.10 kernel running in the guest.
Thanks,
Anchal.Quoted 3 lines
-boris
Boris Ostrovsky
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 41 lines · Anchal Agarwal
Quoted 35 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 16 lines · Anchal Agarwal
Quoted 7 lines
Quoted 5 lines
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
Hi Boris,
Apologies for picking this up after last year.
I did some dive deep on the above statement and that is indeed the case that's happening. I did some debugging around KASLR and hibernation using reboot mode.
I observed in my debug prints that whenever vcpu_info* address for secondary vcpu assigned inxen_vcpu_setupat boot is different than what is in the image, resume gets stuck for that vcpu inbringup_cpu(). That means we have different addresses for &per_cpu(xen_vcpu_info, cpu) at boot and after control jumps into the image.Quoted 2 lines
I failed to get any prints after it got stuck in
bringup_cpu()and
I do not have an option to send a sysrq signal to the guest or rather get a kdump.xenctx and xen-hvmctx might be helpful.
Quoted 7 lines
This change is not observed in every hibernate-resume cycle. I am not sure if this is a bug or an
expected behavior.
Also, I am contemplating the idea that it may be a bug in xen code getting triggered only when
KASLR is enabled but I do not have substantial data to prove that.
Is this a coincidence that this always happens for 1st vcpu?
Moreover, since hypervisor is not aware that guest is hibernated and it looks like a regular shutdown to dom0 during reboot mode, will re-registeringvcpu_infofor secondary vcpu's even plausible?Quoted 5 lines
I think I am missing how this is supposed to work (maybe we've talked about this but it's been many months since then). You hibernate the guest and it writes the state to swap. The guest is then shut down? And what's next? How do you wake it up?
-boris
Quoted 8 lines
To resume a guest, guest boots up as the fresh guest and then
software_resume()is called which if finds a stored hibernation image, quiesces the devices and loads the memory contents from the image. The control then transfers to the targeted kernel. This further disables non boot cpus,sycore_suspend/resume callbacks are invoked which sets up theshared_info, pvclock, grant tables etc. Since thevcpu_infopointer for each non-boot cpu is already registered, the hypercall does not happen again when bringing up the non boot cpus. This leads to inconsistencies as pointed
out earlier when KASLR is enabled.
I'd think the 'if' condition in the code fragment below should always fail since hypervisor is creating new guest, resulting in the hypercall. Just like in the case of save/restore.
Do you call xen_vcpu_info_reset() on resume? That will re-initialize per_cpu(xen_vcpu). Maybe you need to add this to xen_syscore_resume().
-boris
Quoted 35 lines
Thanks,
AnchalQuoted 32 lines
Quoted 32 lines
I could definitely use some advice to debug this further.
Some printk's from my debugging:
At Boot:
xen_vcpu_setup: xen_have_vcpu_info_placement=1 cpu=1, vcpup=0xffff9e548fa560e0, info.mfn=3996246 info.offset=224,Image Loads:
It ends up in the condition:
xen_vcpu_setup()
{
...if (xen_hvm_domain()) { if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu)) return 0;}
...
}
xen_vcpu_setup: checking mfn on resume cpu=1, info.mfn=3934806 info.offset=224, &per_cpu(xen_vcpu_info, cpu)=0xffff9d7240a560e0This is tested on c4.2xlarge [8vcpu 15GB mem] instance with 5.10 kernel running in the guest.
Thanks,
Anchal.Quoted 3 lines
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 56 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 41 lines · Anchal Agarwal
Quoted 35 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 16 lines · Anchal Agarwal
Quoted 7 lines
Quoted 5 lines
What I meant there wrt VCPU info was that VCPU info is not unregistered during hibernation, so Xen still remembers the old physical addresses for the VCPU information, created by the booting kernel. But since the hibernation kernel may have different physical addresses for VCPU info and if mismatch happens, it may cause issues with resume. During hibernation, the VCPU info register hypercall is not invoked again.
I still don't think that's the cause but it's certainly worth having a look.
Hi Boris,
Apologies for picking this up after last year.
I did some dive deep on the above statement and that is indeed the case that's happening. I did some debugging around KASLR and hibernation using reboot mode.
I observed in my debug prints that whenever vcpu_info* address for secondary vcpu assigned inxen_vcpu_setupat boot is different than what is in the image, resume gets stuck for that vcpu inbringup_cpu(). That means we have different addresses for &per_cpu(xen_vcpu_info, cpu) at boot and after control jumps into the image.Quoted 2 lines
I failed to get any prints after it got stuck in
bringup_cpu()and
I do not have an option to send a sysrq signal to the guest or rather get a kdump.xenctx and xen-hvmctx might be helpful.
Quoted 7 lines
This change is not observed in every hibernate-resume cycle. I am not sure if this is a bug or an
expected behavior.
Also, I am contemplating the idea that it may be a bug in xen code getting triggered only when
KASLR is enabled but I do not have substantial data to prove that.
Is this a coincidence that this always happens for 1st vcpu?
Moreover, since hypervisor is not aware that guest is hibernated and it looks like a regular shutdown to dom0 during reboot mode, will re-registeringvcpu_infofor secondary vcpu's even plausible?Quoted 5 lines
I think I am missing how this is supposed to work (maybe we've talked about this but it's been many months since then). You hibernate the guest and it writes the state to swap. The guest is then shut down? And what's next? How do you wake it up?
-boris
Quoted 8 lines
To resume a guest, guest boots up as the fresh guest and then
software_resume()is called which if finds a stored hibernation image, quiesces the devices and loads the memory contents from the image. The control then transfers to the targeted kernel. This further disables non boot cpus,sycore_suspend/resume callbacks are invoked which sets up theshared_info, pvclock, grant tables etc. Since thevcpu_infopointer for each non-boot cpu is already registered, the hypercall does not happen again when bringing up the non boot cpus. This leads to inconsistencies as pointed
out earlier when KASLR is enabled.
Quoted 2 lines
I'd think the 'if' condition in the code fragment below should always fail since hypervisor is creating new guest, resulting in the hypercall. Just like in the case of save/restore.
That only fails during boot but not after the control jumps into the image. The
non boot cpus are brought offline(freeze_secondary_cpus) and then online via cpu hotplug path. In that case xen_vcpu_setup doesn't invokes the hypercall again.
Quoted 3 lines
Do you call
xen_vcpu_info_reset()on resume? That will re-initializeper_cpu(xen_vcpu). Maybe you need to add this toxen_syscore_resume().
Yes coincidentally I did. It fails the registration of vcpu_info with error -22. Basically because nobody unregistered them and xen does not know that guest hibernated in first place.
Moreover, syscore_resume is also called during hibernation path i.e after Image is created. Everything is resumed and thawed back before final writing of the image and then a machine shutdown. So syscore_resume can only invoke xen_vcpu_info_reset when it is actually resuming from image. I had ben able to use in_suspend variable to detect that luckily.
Another line of thought is something what kexec does to come around this problem
is to abuse soft_reset and issue it during syscore_resume or may be before the image get loaded. I haven't experimented with that yet as I am assuming there has to be a way to re-register vcpus during resume.
Thanks,
Anchal
Quoted 43 lines
-boris
Quoted 39 lines
Thanks,
AnchalQuoted 36 lines
Quoted 36 lines
I could definitely use some advice to debug this further.
Some printk's from my debugging:
At Boot:
xen_vcpu_setup: xen_have_vcpu_info_placement=1 cpu=1, vcpup=0xffff9e548fa560e0, info.mfn=3996246 info.offset=224,Image Loads:
It ends up in the condition:
xen_vcpu_setup()
{
...if (xen_hvm_domain()) { if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu)) return 0;}
...
}
xen_vcpu_setup: checking mfn on resume cpu=1, info.mfn=3934806 info.offset=224, &per_cpu(xen_vcpu_info, cpu)=0xffff9d7240a560e0This is tested on c4.2xlarge [8vcpu 15GB mem] instance with 5.10 kernel running in the guest.
Thanks,
Anchal.Quoted 3 lines
-boris
Boris Ostrovsky
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 2 lines · Anchal Agarwal
That only fails during boot but not after the control jumps into the image. The
non boot cpus are broughtoffline(freeze_secondary_cpus)and then online via cpu hotplug path. In that casexen_vcpu_setupdoesn't invokes the hypercall again.
OK, that makes sense --- by that time VCPUs have already been registered. What I don't understand though is why resume doesn't fail every time --- xen_vcpu and xen_vcpu_info should be different practically always, shouldn't they? Do you observe successful resumes when the hypercall fails?
Quoted 4 lines
Another line of thought is something what kexec does to come around this problem
is to abusesoft_resetand issue it duringsyscore_resumeor may be before the image get loaded. I haven't experimented with that yet as I am assuming there has to be a way to re-register vcpus during resume.
Right, that sounds like it should work.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 4 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 9 lines
Quoted 2 lines · Anchal Agarwal
That only fails during boot but not after the control jumps into the image. The
non boot cpus are broughtoffline(freeze_secondary_cpus)and then online via cpu hotplug path. In that casexen_vcpu_setupdoesn't invokes the hypercall again.OK, that makes sense --- by that time VCPUs have already been registered. What I don't understand though is why resume doesn't fail every time ---
xen_vcpuandxen_vcpu_infoshould be different practically always, shouldn't they? Do you observe successful resumes when the hypercall fails?
The resume won't fail because in the image the xen_vcpu and xen_vcpu_info are same. These are the same values that got in there during saving of the hibernation image. So whatever xen_vcpu got as a value during boot time registration on resume is essentially lost once the jump into the saved kernel image happens. Interesting part is if KASLR is not enabled boot time vcpup mfn is same as in the image.
Once you enable KASLR this value changes sometimes and whenever that happens resume gets stuck. Does that make sense?
No it does not resume successfully if hypercall fails because I was trying to explicitly reset vcpu and invoke hypercall.
I am just wondering why does restore logic fails to work here or probably I am missing a critical piece here.
Quoted 8 lines
Quoted 4 lines
Another line of thought is something what kexec does to come around this problem
is to abusesoft_resetand issue it duringsyscore_resumeor may be before the image get loaded. I haven't experimented with that yet as I am assuming there has to be a way to re-register vcpus during resume.Right, that sounds like it should work.
You mean soft reset or re-register vcpu?
-Anchal
Quoted 4 lines
-boris
Boris Ostrovsky
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 7 lines · Anchal Agarwal
Quoted 1 line · Boris Ostrovsky
The resume won't fail because in the image the
xen_vcpuandxen_vcpu_infoare same. These are the same values that got in there during saving of the hibernation image. So whateverxen_vcpugot as a value during boot time registration on resume is essentially lost once the jump into the saved kernel image happens. Interesting part is if KASLR is not enabled boot time vcpup mfn is same as in the image.
Do you start the your guest right after you've hibernated it? What happens if you create (and keep running) a few other guests in-between? mfn would likely be different then I'd think.
Quoted 7 lines
Once you enable KASLR this value changes sometimes and whenever that happens resume gets stuck. Does that make sense?
No it does not resume successfully if hypercall fails because I was trying to explicitly reset vcpu and invoke hypercall.
I am just wondering why does restore logic fails to work here or probably I am missing a critical piece here.
If you are not using KASLR then xen_vcpu_info is at the same address every time you boot. So whatever you registered before hibernating stays the same when you boot second time and register again, and so successful comparison in xen_vcpu_setup() works. (Mostly by chance.)
But if KASLR is on then this comparison not failing should cause xen_vcpu pointer in the loaded image to become bogus because xen_vcpu is now registered for a different xen_vcpu_info address during boot.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Another line of thought is something what kexec does to come around this problem
is to abusesoft_resetand issue it duringsyscore_resumeor may be before the image get loaded. I haven't experimented with that yet as I am assuming there has to be a way to re-register vcpus during resume.Right, that sounds like it should work.
You mean soft reset or re-register vcpu?
Doing something along the lines of a soft reset. It should allow you to re-register. Not sure how you can use it without Xen changes though.
-boris
Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 7 lines · Boris Ostrovsky
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 2 lines · Anchal Agarwal
Quoted 1 line · Boris Ostrovsky
Quoted 10 lines
Quoted 5 lines
The resume won't fail because in the image the
xen_vcpuandxen_vcpu_infoare same. These are the same values that got in there during saving of the hibernation image. So whateverxen_vcpugot as a value during boot time registration on resume is essentially lost once the jump into the saved kernel image happens. Interesting part is if KASLR is not enabled boot time vcpup mfn is same as in the image.Do you start the your guest right after you've hibernated it? What happens if you create (and keep running) a few other guests in-between? mfn would likely be different then I'd think.
Yes, I just run it in loops on a single guest and I am able to see the issue in 20-40 iterations sometime may be sooner. Yeah, you could be right and this could definitely happen more often depending what's happening on dom0 side.
Quoted 11 lines
Quoted 7 lines
Once you enable KASLR this value changes sometimes and whenever that happens resume gets stuck. Does that make sense?
No it does not resume successfully if hypercall fails because I was trying to explicitly reset vcpu and invoke hypercall.
I am just wondering why does restore logic fails to work here or probably I am missing a critical piece here.If you are not using KASLR then
xen_vcpu_infois at the same address every time you boot. So whatever you registered before hibernating stays the same when you boot second time and register again, and so successful comparison inxen_vcpu_setup()works. (Mostly by chance.)
That's what I thought so too.
Quoted 3 lines
But if KASLR is on then this comparison not failing should cause
xen_vcpupointer in the loaded image to become bogus becausexen_vcpuis now registered for a differentxen_vcpu_infoaddress during boot.
The reason for that I think is once you jump into the image that information is getting lost. But there is some residue somewhere that's causing the resume to fail. I haven't been able to pinpoint the exact field value that may be causing that issue.
Correct me if I am wrong here, but even if hypothetically I put a hack to tell the kernel somehow re-register vcpu it won't pass because there is no hypercall to unregister it in first place? Can the resumed kernel use the new values in that case [Now this is me just throwing wild guesses!!]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Another line of thought is something what kexec does to come around this problem
is to abusesoft_resetand issue it duringsyscore_resumeor may be before the image get loaded. I haven't experimented with that yet as I am assuming there has to be a way to re-register vcpus during resume.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Right, that sounds like it should work.
You mean soft reset or re-register vcpu?
Doing something along the lines of a soft reset. It should allow you to re-register. Not sure how you can use it without Xen changes though.
No not without xen changes. It won't work. I will have xen changes in place to test that on our infrastructure.
--
Anchal
Quoted 4 lines
-boris
Boris Ostrovsky
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
Quoted 8 lines · Anchal Agarwal
Quoted 2 lines · Boris Ostrovsky
But if KASLR is on then this comparison not failing should cause
xen_vcpupointer in the loaded image to become bogus becausexen_vcpuis now registered for a differentxen_vcpu_infoaddress during boot.The reason for that I think is once you jump into the image that information is getting lost. But there is some residue somewhere that's causing the resume to fail. I haven't been able to pinpoint the exact field value that may be causing that issue.
xen_vcpu now points to address which is not where the hypervisor thinks vcpu_info should be.
Quoted 3 lines
Correct me if I am wrong here, but even if hypothetically I put a hack to tell the kernel somehow re-register vcpu it won't pass because there is no hypercall to unregister it in first place?
Right. You will be shown the door in map_vcpu_info():
if ( !mfn_eq(v->vcpu_info_mfn, INVALID_MFN) ) return -EINVAL;
Quoted 2 lines
Can the resumed kernel use the new values in that case [Now this is me just throwing wild guesses!!]
I don't think so --- hypervisor is now pointing to a random location in your image.
-boris
[email protected]
reviewerRe: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode
In reply to Anchal AgarwalQuoted 33 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Guest hibernation is different from xen suspend/resume/live migration. Xen save/restore does not use
pm_opsas is needed by guest hibernation. Hibernation in guest follows ACPI path and is guest inititated , the hibernation image is saved within guest as compared to later modes which are xen toolstack assisted and image creation/storage is in control of hypervisor/host machine.
To differentiate between Xen suspend and PM hibernation, keep track of the on-going suspend mode by mainly using a new API to keep track ofSHUTDOWN_SUSPENDstate.
Introduce a simple function that keeps track of on-going suspend mode so that PM hibernation code can behave differently according to the current suspend mode.
Since Xen suspend doesn't have corresponding PM event, its main logic is modfied to acquirepm_mutex.Though, accquirng
pm_mutexis still right thing to do, we may see deadlock if PM hibernation is interrupted by Xen suspend. PM hibernation depends on xenwatch thread to process xenbus state transactions, but the thread will sleep to waitpm_mutexwhich is already held by PM hibernation context in the scenario. Xen shutdown code may need some changes to avoid the issue.[Anchal Agarwal: Changelog]:
RFCv1->v2: Code refactoring
v1->v2: Remove unused functions for PM SUSPEND/PM hibernation
v2->v3: Added logic to use existingpm_notifierto detect for ARM
and abort hibernation for ARM guests. Also removed differentsuspend_modesand simplified the code with using existing state variables for tracking Xen suspend. The notifier won't get registered for pvh dom0 either.
Quoted 2 lines
Signed-off-by Anchal Agarwal <[email protected]>Signed-off-by Munehisa Kamata <[email protected]>
BTW, just to make sure --- Thomas' comments about commit message format (SoB order, no changelog, etc) apply to all patches, not just #5.
-boris
PATCH v3 2/11 xenbus: add freeze/thaw/restore callbacks support
In reply to Anchal AgarwalFrom: Munehisa Kamata <[email protected]>
Since commit b3e96c0c7562 ("xen: use freeze/restore/thaw PM events for suspend/resume/chkpt"), xenbus uses PMSG_FREEZE, PMSG_THAW and PMSG_RESTORE events for Xen suspend. However, they're actually assigned to xenbus_dev_suspend(), xenbus_dev_cancel() and xenbus_dev_resume() respectively, and only suspend and resume callbacks are supported at driver level. To support PM suspend and PM hibernation, modify the bus level PM callbacks to invoke not only device driver's suspend/resume but also freeze/thaw/restore.
Note that we'll use freeze/restore callbacks even for PM suspend whereas suspend/resume callbacks are normally used in the case, becausae the existing xenbus device drivers already have suspend/resume callbacks specifically designed for Xen suspend. So we can allow the device drivers to keep the existing callbacks wihtout modification.
[Anchal Agarwal: Changelog]:
RFC v1->v2: Refactored the callbacks code
v1->v2: Use dev_warn instead of pr_warn, naming/initialization
conventions
v2->v3: Fixed is_xen_suspend naming convention--- drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++++++++++------ include/xen/xenbus.h | 3 ++ 2 files changed, 84 insertions(+), 15 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +81 -15
@@ -50,6 +50,7 @@#include <linux/io.h> #include <linux/slab.h> #include <linux/module.h> +#include <linux/suspend.h> #include <asm/page.h> #include <asm/xen/hypervisor.h>
@@ -599,16 +600,33 @@ int xenbus_dev_suspend(struct device *dev)struct xenbus_driver *drv;struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); +bool xen_suspend =is_xen_suspend ();DPRINTK ("%s" , xdev->nodename);if (dev->driver ==NULL )return 0 ; drv =to_xenbus_driver (dev->driver); -if (drv->suspend) - err = drv->suspend (xdev); -if (err) -dev_warn (dev,"suspend failed: %i\n" , err); +if (xen_suspend) { +if (drv->suspend) + err = drv->suspend (xdev); + }else { +if (drv->freeze) { + err = drv->freeze (xdev); +if (!err) { +free_otherend_watch (xdev); +free_otherend_details (xdev); +return 0 ; + } + } + } + +if (err) { +dev_warn (&xdev->dev,"%s %s failed: %d\n" , xen_suspend ? +"suspend" :"freeze" , xdev->nodename, err); +return err; + } +return 0 ; }EXPORT_SYMBOL_GPL (xenbus_dev_suspend);
@@ -619,6 +637,7 @@ int xenbus_dev_resume(struct device *dev)struct xenbus_driver *drv;struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); +bool xen_suspend =is_xen_suspend ();DPRINTK ("%s" , xdev->nodename);
@@ -627,23 +646,34 @@ int xenbus_dev_resume(struct device *dev) drv =to_xenbus_driver (dev->driver); err =talk_to_otherend (xdev);if (err) { -dev_warn (dev,"resume (talk_to_otherend) failed: %i\n" , err); +dev_warn (&xdev->dev,"%s (talk_to_otherend) %s failed: %d\n" , + xen_suspend ?"resume" :"restore" , + xdev->nodename, err);return err; } - xdev->state = XenbusStateInitialising; +if (xen_suspend) { + xdev->state = XenbusStateInitialising; +if (drv->resume) + err = drv->resume (xdev); + }else { +if (drv->restore) + err = drv->restore (xdev); + } -if (drv->resume) { - err = drv->resume (xdev); -if (err) { -dev_warn (dev,"resume failed: %i\n" , err); -return err; - } +if (err) { +dev_warn (&xdev->dev,"%s %s failed: %d\n" , + xen_suspend ?"resume" :"restore" , + xdev->nodename, err); +return err; } err =watch_otherend (xdev);if (err) { -dev_warn (dev,"resume (watch_otherend) failed: %d\n" , err); +dev_warn (&xdev->dev,"%s (watch_otherend) %s failed: %d.\n" , + xen_suspend ?"resume" :"restore" , + xdev->nodename, err); +return err; }
@@ -653,8 +683,44 @@ EXPORT_SYMBOL_GPL(xenbus_dev_resume);int xenbus_dev_cancel (struct device *dev) { -/* Do nothing */ -DPRINTK ("cancel" ); +int err; +struct xenbus_driver *drv; +struct xenbus_device *xendev =to_xenbus_device (dev); +bool xen_suspend =is_xen_suspend (); + +if (xen_suspend) { +/* Do nothing */ +DPRINTK ("cancel" ); +return 0 ; + } + +DPRINTK ("%s" , xendev->nodename); + +if (dev->driver ==NULL ) +return 0 ; + drv =to_xenbus_driver (dev->driver); + err =talk_to_otherend (xendev); +if (err) { +dev_warn (&xendev->dev,"thaw (talk_to_otherend) %s failed: %d.\n" , + xendev->nodename, err); +return err; + } + +if (drv->thaw) { + err = drv->thaw (xendev); +if (err) { +dev_warn (&xendev->dev,"thaw %s failed: %d\n" , xendev->nodename, err); +return err; + } + } + + err =watch_otherend (xendev); +if (err) { +dev_warn (&xendev->dev,"thaw (watch_otherend) %s failed: %d.\n" , + xendev->nodename, err); +return err; + } +return 0 ; }EXPORT_SYMBOL_GPL (xenbus_dev_cancel);
include/xen/xenbus.h +3 -0
@@ -104,6 +104,9 @@ struct xenbus_driver {int (*remove)(struct xenbus_device *dev);int (*suspend)(struct xenbus_device *dev);int (*resume)(struct xenbus_device *dev); +int (*freeze)(struct xenbus_device *dev); +int (*thaw)(struct xenbus_device *dev); +int (*restore)(struct xenbus_device *dev);int (*uevent)(struct xenbus_device *,struct kobj_uevent_env *);struct device_driver driver;int (*read_otherend_details)(struct xenbus_device *dev);
Signature · 1 line
2.16.6
[email protected]
reviewerRe: [PATCH v3 02/11] xenbus: add freeze/thaw/restore callbacks support
Quoted 11 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Since commit
b3e96c0c7562("xen: use freeze/restore/thaw PM events for suspend/resume/chkpt"), xenbus usesPMSG_FREEZE,PMSG_THAWandPMSG_RESTOREevents for Xen suspend. However, they're actually assigned toxenbus_dev_suspend(),xenbus_dev_cancel()andxenbus_dev_resume()respectively, and only suspend and resume callbacks are supported at driver level. To support PM suspend and PM hibernation, modify the bus level PM callbacks to invoke not only device driver's suspend/resume but also freeze/thaw/restore.
Quoted 4 lines
Note that we'll use freeze/restore callbacks even for PM suspend whereas suspend/resume callbacks are normally used in the case, becausae the existing xenbus device drivers already have suspend/resume callbacks specifically designed for Xen suspend.
Something is wrong with this sentence. Or with my brain --- I can't quite parse this.
And please be consistent with "PM suspend" vs. "PM hibernation".
Quoted 15 lines
So we can allow the device
drivers to keep the existing callbacks wihtout modification.drivers/xen/xenbus/xenbus_probe.c +1
-0@@ -599,16 +600,33 @@ int xenbus_dev_suspend(struct device *dev)struct xenbus_driver *drv;struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); +bool xen_suspend =is_xen_suspend ();DPRINTK ("%s" , xdev->nodename);if (dev->driver ==NULL )return 0 ;
drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_suspend(struct device *dev) · line 614
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +5
-4drv =to_xenbus_driver (dev->driver); -if (drv->suspend) - err = drv->suspend (xdev); -if (err) -dev_warn (dev,"suspend failed: %i\n" , err); +if (xen_suspend) { +if (drv->suspend) + err = drv->suspend (xdev); + }else { +if (drv->freeze) {
'else if' (to avoid extra indent level). In xenbus_dev_resume() too.
drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_suspend(struct device *dev)
Quoted 11 lines
drivers/xen/xenbus/xenbus_probe.c +11
-0+ err = drv->freeze (xdev); +if (!err) { +free_otherend_watch (xdev); +free_otherend_details (xdev); +return 0 ; + } + } + } + +if (err) { + dev_warn(&xdev->dev,
Is there a reason why you replaced dev with xdev->dev (here and elsewhere)?
Quoted 8 lines
drivers/xen/xenbus/xenbus_probe.c +4
-0"%s %s failed: %d\n" , xen_suspend ? + "suspend" : "freeze", xdev->nodename, err); +return err; + } +
drivers/xen/xenbus/xenbus_probe.c EXPORT_SYMBOL_GPL(xenbus_dev_resume); · line 688
Quoted 8 lines
drivers/xen/xenbus/xenbus_probe.c +3
-2@@ -653,8 +683,44 @@ EXPORT_SYMBOL_GPL(xenbus_dev_resume);int xenbus_dev_cancel (struct device *dev) { -/* Do nothing */ -DPRINTK ("cancel" ); +int err; +struct xenbus_driver *drv; +struct xenbus_device *xendev =to_xenbus_device (dev);
xdev for consistency please.
Review EXPORT_SYMBOL_GPL(xenbus_dev_resume); · line 689
Quoted 1 line
(quoted diff) +1
-0+ bool xen_suspend = is_xen_suspend();
No need for this, you use it only once anyway.
-boris
Re: [PATCH v3 02/11] xenbus: add freeze/thaw/restore callbacks support
Quoted 16 lines · On Sun, Sep 13, 2020 at 12:11:47PM -0400, [email protected] wrote:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 11 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Since commit
b3e96c0c7562("xen: use freeze/restore/thaw PM events for suspend/resume/chkpt"), xenbus usesPMSG_FREEZE,PMSG_THAWandPMSG_RESTOREevents for Xen suspend. However, they're actually assigned toxenbus_dev_suspend(),xenbus_dev_cancel()andxenbus_dev_resume()respectively, and only suspend and resume callbacks are supported at driver level. To support PM suspend and PM hibernation, modify the bus level PM callbacks to invoke not only device driver's suspend/resume but also freeze/thaw/restore.
Quoted 9 lines
Quoted 4 lines
Note that we'll use freeze/restore callbacks even for PM suspend whereas suspend/resume callbacks are normally used in the case, becausae the existing xenbus device drivers already have suspend/resume callbacks specifically designed for Xen suspend.
Something is wrong with this sentence. Or with my brain --- I can't quite parse this.
The message is trying to say that that freeze/thaw/restore callbacks will be used for both PM SUSPEND and PM HIBERNATION. Since, we are only focussing on PM hibernation, I will remove all wordings of PM suspend from this message to avoid confusion. I left it there in case someone wants to pick it up in future knowing framework is already present.
Quoted 3 lines
And please be consistent with "PM suspend" vs. "PM hibernation".
I should remove PM suspend from everywhere since the mode is not tested for.
Quoted 44 lines
Quoted 16 lines
So we can allow the device
drivers to keep the existing callbacks wihtout modification.drivers/xen/xenbus/xenbus_probe.c +1
-0@@ -599,16 +600,33 @@ int xenbus_dev_suspend(struct device *dev)struct xenbus_driver *drv;struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); +bool xen_suspend =is_xen_suspend ();DPRINTK ("%s" , xdev->nodename);if (dev->driver ==NULL )return 0 ;drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_suspend(struct device *dev) · line 614
Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +5
-4drv =to_xenbus_driver (dev->driver); -if (drv->suspend) - err = drv->suspend (xdev); -if (err) -dev_warn (dev,"suspend failed: %i\n" , err); +if (xen_suspend) { +if (drv->suspend) + err = drv->suspend (xdev); + }else { +if (drv->freeze) {'else if' (to avoid extra indent level). In
xenbus_dev_resume()too.drivers/xen/xenbus/xenbus_probe.c int xenbus_dev_suspend(struct device *dev)
Quoted 11 lines
drivers/xen/xenbus/xenbus_probe.c +11
-0+ err = drv->freeze (xdev); +if (!err) { +free_otherend_watch (xdev); +free_otherend_details (xdev); +return 0 ; + } + } + } + +if (err) { + dev_warn(&xdev->dev,
Quoted 3 lines
Is there a reason why you replaced dev with
xdev->dev(here and elsewhere)?
Nope, they should be same. We can use dev here too. I should probably just use dev.
Quoted 9 lines
Quoted 9 lines
drivers/xen/xenbus/xenbus_probe.c +4
-0"%s %s failed: %d\n" , xen_suspend ? + "suspend" : "freeze", xdev->nodename, err); +return err; + } +@@ -653,8 +683,44 @@ EXPORT_SYMBOL_GPL(xenbus_dev_resume);
Quoted 11 lines
drivers/xen/xenbus/xenbus_probe.c EXPORT_SYMBOL_GPL(xenbus_dev_resume); · line 688
Quoted 7 lines
drivers/xen/xenbus/xenbus_probe.c +3
-2int xenbus_dev_cancel (struct device *dev) { -/* Do nothing */ -DPRINTK ("cancel" ); +int err; +struct xenbus_driver *drv; +struct xenbus_device *xendev =to_xenbus_device (dev);xdev for consistency please.
Yes this I left unchanged, it should be consistent with xdev.
Quoted 9 lines
Review EXPORT_SYMBOL_GPL(xenbus_dev_resume); · line 689
Quoted 2 lines
(quoted diff) +1
-0+ bool xen_suspend = is_xen_suspend();No need for this, you use it only once anyway.
-boris
Thanks,
Anchal
Quoted 1 line
PATCH v3 3/11 x86/xen: Introduce new function to map HYPERVISOR_shared_info on Resume
In reply to Anchal AgarwalIntroduce a small function which re-uses shared page's PA allocated during guest initialization time in reserve_shared_info() and not allocate new page during resume flow.
It also does the mapping of shared_info_page by calling xen_hvm_init_shared_info() to use the function.
Changelog:v1->v2: Remove extra check for shared_info_pfn to be NULL
--- arch/x86/xen/enlighten_hvm.c | 6 ++++++ arch/x86/xen/xen-ops.h | 1 + 2 files changed, 7 insertions(+)
arch/x86/xen/enlighten_hvm.c +6 -0
@@ -29,6 +29,12 @@static unsigned long shared_info_pfn; +void xen_hvm_map_shared_info (void ) +{ +xen_hvm_init_shared_info (); + HYPERVISOR_shared_info =__va (PFN_PHYS (shared_info_pfn)); +} +void xen_hvm_init_shared_info (void ) {struct xen_add_to_physmap xatp;
arch/x86/xen/xen-ops.h +1 -0
@@ -53,6 +53,7 @@ void xen_enable_sysenter(void);void xen_enable_syscall (void );void xen_vcpu_restore (void ); +void xen_hvm_map_shared_info (void );void xen_hvm_init_shared_info (void );void xen_unplug_emulated_devices (void );
Signature · 1 line
2.16.6
PATCH v3 4/11 x86/xen: add system core suspend and resume callbacks
In reply to Anchal AgarwalFrom: Munehisa Kamata <[email protected]>
Add Xen PVHVM specific system core callbacks for PM hibernation support. The callbacks suspend and resume Xen primitives like shared_info, pvclock and grant table. These syscore_ops are specifically for domU hibernation. xen_suspend() calls syscore_suspend() during Xen suspend operation however, during xen suspend lock_system_sleep() lock is taken and thus system cannot trigger hibernation. These system core callbacks will be called only from the hibernation context.
[Anchal Agarwal: Changelog]:v1->v2: Edit commit message
Fixed syscore_suspend() to call gnntab_suspend Removed suspend mode check in syscore_suspend()/ syscore_resume()v2->v3: Re-introduced check for xen suspend mode to avoid
syscore osp callbacks getting executed during xen suspend/resume
--- arch/x86/xen/enlighten_hvm.c | 1 + arch/x86/xen/suspend.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ include/xen/xen-ops.h | 2 ++ 3 files changed, 58 insertions(+)
arch/x86/xen/enlighten_hvm.c +1 -0
@@ -216,6 +216,7 @@ static void __init xen_hvm_guest_init(void)if (xen_feature (XENFEAT_hvm_callback_vector)) xen_have_vector_callback =1 ; +xen_setup_syscore_ops ();xen_hvm_smp_init ();WARN_ON (xen_cpuhp_setup (xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));xen_unplug_emulated_devices ();
arch/x86/xen/suspend.c +55 -0
75 lines not on this page · raw message
include/xen/xen-ops.h +2 -0
@@ -41,6 +41,8 @@ u64 xen_steal_clock(int cpu);int xen_setup_shutdown_event (void );bool is_xen_suspend (void ); +void xen_setup_syscore_ops (void ); +extern unsigned long *xen_contiguous_bitmap;#if defined(CONFIG_XEN_PV ) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 )
Signature · 1 line
2.16.6
[email protected]
reviewerRe: [PATCH v3 04/11] x86/xen: add system core suspend and resume callbacks
Quoted 11 lines · Anchal Agarwal
From: Munehisa Kamata <[email protected]>
Add Xen PVHVM specific system core callbacks for PM hibernation support. The callbacks suspend and resume Xen primitives like
shared_info, pvclock and grant table. Thesesyscore_opsare specifically for domU hibernation.xen_suspend()callssyscore_suspend()during Xen suspend operation however, during xen suspendlock_system_sleep()lock is taken and thus system cannot trigger hibernation. These system core callbacks will be called only from the hibernation context.
Well, they can be called from Xen suspend too, which is why you have the checks in the beginning.
-boris
PATCH v3 5/11 genirq: Shutdown irq chips in suspend/resume during hibernation
In reply to Anchal AgarwalMany legacy device drivers do not implement power management (PM) functions which means that interrupts requested by these drivers stay in active state when the kernel is hibernated.
This does not matter on bare metal and on most hypervisors because the interrupt is restored on resume without any noticable side effects as it stays connected to the same physical or virtual interrupt line.
The XEN interrupt mechanism is different as it maintains a mapping between the Linux interrupt number and a XEN event channel. If the interrupt stays active on hibernation this mapping is preserved but there is unfortunately no guarantee that on resume the same event channels are reassigned to these devices. This can result in event channel conflicts which prevent the affected devices from being restored correctly.
One way to solve this would be to add the necessary power management functions to all affected legacy device drivers, but that's a questionable effort which does not provide any benefits on non-XEN environments.
The least intrusive and most efficient solution is to provide a mechanism which allows the core interrupt code to tear down these interrupts on hibernation and bring them back up again on resume. This allows the XEN event channel mechanism to assign an arbitrary event channel on resume without affecting the functionality of these devices.
Fortunately all these device interrupts are handled by a dedicated XEN interrupt chip so the chip can be marked that all interrupts connected to it are handled this way. This is pretty much in line with the other interrupt chip specific quirks, e.g. IRQCHIP_MASK_ON_SUSPEND.
Add a new quirk flag IRQCHIP_SHUTDOWN_ON_SUSPEND and add support for it the core interrupt suspend/resume paths.
Changelog:v1->v2: Corrected the author's name to tglx@
--- drivers/xen/events/events_base.c | 1 + include/linux/irq.h | 2 ++ kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 ++++++++++++++++++++++--------- 5 files changed, 27 insertions(+), 10 deletions(-)
drivers/xen/events/events_base.c +1 -0
@@ -1611,6 +1611,7 @@ static struct irq_chip xen_pirq_chip __read_mostly = { .irq_set_affinity = set_affinity_irq, .irq_retrigger = retrigger_dynirq, + .flags = IRQCHIP_SHUTDOWN_ON_SUSPEND, };static struct irq_chip xen_percpu_chip__read_mostly = {
include/linux/irq.h +2 -0
@@ -555,6 +555,7 @@ struct irq_chip {* IRQCHIP_EOI_THREADED: Chip requires eoi() on unmask in threaded mode * IRQCHIP_SUPPORTS_LEVEL_MSI Chip can provide two doorbells for Level MSIs * IRQCHIP_SUPPORTS_NMI: Chip can deliver NMIs, only for root irqchips +* IRQCHIP_SHUTDOWN_ON_SUSPEND: Shutdown non wake irqs in the suspend path */ enum {IRQCHIP_SET_TYPE_MASKED = (1 <<0 ),
@@ -566,6 +567,7 @@ enum {IRQCHIP_EOI_THREADED = (1 <<6 ),IRQCHIP_SUPPORTS_LEVEL_MSI = (1 <<7 ),IRQCHIP_SUPPORTS_NMI = (1 <<8 ), + IRQCHIP_SHUTDOWN_ON_SUSPEND = (1 << 9), };#include <linux/irqdesc.h>
kernel/irq/chip.c +1 -1
@@ -233,7 +233,7 @@ __irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force) }#endif -static int __irq_startup (struct irq_desc *desc) +int __irq_startup (struct irq_desc *desc) {struct irq_data *d =irq_desc_get_irq_data (desc);int ret =0 ;
kernel/irq/internals.h +1 -0
@@ -80,6 +80,7 @@ extern void __enable_irq(struct irq_desc *desc);extern int irq_activate (struct irq_desc *desc);extern int irq_activate_and_startup (struct irq_desc *desc,bool resend);extern int irq_startup (struct irq_desc *desc,bool resend,bool force); +extern int __irq_startup (struct irq_desc *desc);extern void irq_shutdown (struct irq_desc *desc);extern void irq_shutdown_and_deactivate (struct irq_desc *desc);
kernel/irq/pm.c +22 -9
@@ -85,16 +85,25 @@ static bool suspend_device_irq(struct irq_desc *desc) } desc->istate |=IRQS_SUSPENDED ; -__disable_irq (desc); -/* -* Hardware which has no wakeup source configuration facility -* requires that the non wakeup interrupts are masked at the -* chip level. The chip implementation indicates that with -* IRQCHIP_MASK_ON_SUSPEND. +* Some irq chips (e.g. XEN PIRQ) require a full shutdown on suspend +* as some of the legacy drivers(e.g. floppy) do nothing during the +* suspend path */ -if (irq_desc_get_chip (desc)->flags &IRQCHIP_MASK_ON_SUSPEND ) -mask_irq (desc); +if (irq_desc_get_chip (desc)->flags &IRQCHIP_SHUTDOWN_ON_SUSPEND ) { +irq_shutdown (desc); + }else { +__disable_irq (desc); + +/* +* Hardware which has no wakeup source configuration facility +* requires that the non wakeup interrupts are masked at the +* chip level. The chip implementation indicates that with +* IRQCHIP_MASK_ON_SUSPEND. +*/ +if (irq_desc_get_chip (desc)->flags &IRQCHIP_MASK_ON_SUSPEND ) +mask_irq (desc); + }return true; }
@@ -152,7 +161,11 @@ static void resume_irq(struct irq_desc *desc)irq_state_set_masked (desc); resume: desc->istate &= ~IRQS_SUSPENDED ; -__enable_irq (desc); + +if (irq_desc_get_chip (desc)->flags &IRQCHIP_SHUTDOWN_ON_SUSPEND ) +__irq_startup (desc); +else +__enable_irq (desc); }static void resume_irqs (bool want_early)
Signature · 1 line
2.16.6
Re: [PATCH v3 05/11] genirq: Shutdown irq chips in suspend/resume during hibernation
Quoted 5 lines · Thomas Gleixner
Add a new quirk flag
IRQCHIP_SHUTDOWN_ON_SUSPENDand add support for it the core interrupt suspend/resume paths.Changelog:
v1->v2: Corrected the author's name to tglx@
Can you please move that Changelog part below the --- seperator next time because that's really not part of the final commit messaage and the maintainer has then to strip it off manually
Quoted 2 lines
Signed-off-by Anchal Agarwal <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>
These SOB lines are just wrongly ordered as they suggest:
Anchal has authored the patch and Thomas transported it
which is clearly not the case. So the right order is:
And that needs another tweak at the top of the change log. The first line in the mail body wants to be:
From: Thomas Gleixner <[email protected]>
followed by an empty new line before the actual changelog text starts. That way the attribution of the patch when applying it will be correct.
Documentation/process/ is there for a reason and following the few simple rules to get that straight is not rocket science.
Thanks,
tglx
Re: [PATCH v3 05/11] genirq: Shutdown irq chips in suspend/resume during hibernation
Quoted 8 lines · Thomas Gleixner
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 3 lines · Thomas Gleixner
Add a new quirk flag
IRQCHIP_SHUTDOWN_ON_SUSPENDand add support for it the core interrupt suspend/resume paths.
Quoted 7 lines
Quoted 2 lines
Changelog:
v1->v2: Corrected the author's name to tglx@Can you please move that Changelog part below the --- seperator next time because that's really not part of the final commit messaage and the maintainer has then to strip it off manually
Ack.
Quoted 9 lines
Quoted 2 lines
Signed-off-by Anchal Agarwal <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>These SOB lines are just wrongly ordered as they suggest:
Anchal has authored the patch and Thomas transported it
which is clearly not the case. So the right order is:
I must admit I wasn't aware of that. Will fix.
Quoted 7 lines
Signed-off-by Thomas Gleixner <[email protected]>Signed-off-by Anchal Agarwal <[email protected]>And that needs another tweak at the top of the change log. The first line in the mail body wants to be:
From: Thomas Gleixner <[email protected]>
Yes I accidentally missed that in this patch.
Others have that line on all the patches and even v2 for this patch has. Will fix.
Quoted 5 lines
followed by an empty new line before the actual changelog text starts. That way the attribution of the patch when applying it will be correct.
Quoted 8 lines
Documentation/process/is there for a reason and following the few simple rules to get that straight is not rocket science.Thanks,
tglx
Anchal
Re: [PATCH v3 05/11] genirq: Shutdown irq chips in suspend/resume during hibernation
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
followed by an empty new line before the actual changelog text starts. That way the attribution of the patch when applying it will be correct.
The way he sent it attribution will be correct as he managed to get his MTU to send out the mail claiming to be from you. But yes, it needs the second From line, _and_ the first from line needs to be fixed to be from him.
Re: [PATCH v3 05/11] genirq: Shutdown irq chips in suspend/resume during hibernation
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
followed by an empty new line before the actual changelog text starts. That way the attribution of the patch when applying it will be correct.
The way he sent it attribution will be correct as he managed to get his MTU to send out the mail claiming to be from you.
Which is even worse as that spammed my inbox with mail delivery rejects for SPF and whatever violations. And those came mostly from Amazon servers which sent out that wrong stuff in the first place ....
Quoted 2 lines
But yes, it needs the second From line, _and_ the first from line needs to be fixed to be from him.
Thanks,
tglx
PATCH v3 6/11 xen-blkfront: add callbacks for PM suspend and hibernation
In reply to Anchal AgarwalFrom: Munehisa Kamata <[email protected]>
S4 power transisiton states are much different than xen suspend/resume. Former is visible to the guest and frontend drivers should be aware of the state transistions and should be able to take appropriate actions when needed. In transition to S4 we need to make sure that at least all the in-flight blkif requests get completed, since they probably contain bits of the guest's memory image and that's not going to get saved any other way. Hence, re-issuing of in-flight requests as in case of xen resume will not work here. This is in contrast to xen-suspend where we need to freeze with as little processing as possible to avoid dirtying RAM late in the migration cycle and we know that in-flight data can wait.
Add freeze, thaw and restore callbacks for PM suspend and hibernation support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND events, need to implement these xenbus_driver callbacks. The freeze handler stops block-layer queue and disconnect the frontend from the backend while freeing ring_info and associated resources. Before disconnecting from the backend, we need to prevent any new IO from being queued and wait for existing IO to complete. Freeze/unfreeze of the queues will guarantee that there are no requests in use on the shared ring. However, for sanity we should check state of the ring before disconnecting to make sure that there are no outstanding requests to be processed on the ring. The restore handler re-allocates ring_info, unquiesces and unfreezes the queue and re-connect to the backend, so that rest of the kernel can continue to use the block device transparently.
Note:For older backends,if a backend doesn't have commit'12ea729645ace' xen/blkback: unmap all persistent grants when frontend gets disconnected, the frontend may see massive amount of grant table warning when freeing resources.
[ 36.852659] deferring g.e. 0xf9 (pfn 0xffffffffffffffff) [ 36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
In this case, persistent grants would need to be disabled.
[Anchal Agarwal: Changelog]:
RFC v1->v2: Removed timeout per request before disconnect during
blkfront freeze.
Added queue freeze/quiesce to the blkfront_freeze Code cleanup
RFC v2->v3: None
RFC v3->v1: Code cleanup, Refractoring
v1->v2: * remove err variable in blkfront_freeze
* BugFix: error handling if rings are still busy after queue freeze/quiesce and returnign driver to connected state
* add TODO if blkback fails to disconnect on freeze
* Code formatting
--- drivers/block/xen-blkfront.c | 122 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 4 deletions(-)
drivers/block/xen-blkfront.c +118 -4
@@ -48,6 +48,8 @@#include <linux/list.h> #include <linux/workqueue.h> #include <linux/sched/mm.h> +#include <linux/completion.h> +#include <linux/delay.h> #include <xen/xen.h> #include <xen/xenbus.h>
@@ -80,6 +82,8 @@ enum blkif_state {BLKIF_STATE_DISCONNECTED ,BLKIF_STATE_CONNECTED ,BLKIF_STATE_SUSPENDED , +BLKIF_STATE_FREEZING , + BLKIF_STATE_FROZEN, }; struct grant {
@@ -219,6 +223,7 @@ struct blkfront_infostruct list_head requests;struct bio_list bio_list;struct list_head info_list; +struct completion wait_backend_disconnected; };static unsigned int nr_minors;
@@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size, info->sector_size = sector_size; info->physical_sector_size = physical_sector_size;blkif_set_queue_limits (info); +init_completion (&info->wait_backend_disconnected);return 0 ; }
@@ -1353,6 +1359,8 @@ static void blkif_free(struct blkfront_info *info, int suspend)unsigned int i;struct blkfront_ring_info *rinfo; +if (info->connected ==BLKIF_STATE_FREEZING ) + goto free_rings;/* Prevent new requests being issued until we fix things up. */ info->connected = suspend ?BLKIF_STATE_SUSPENDED :BLKIF_STATE_DISCONNECTED ;
@@ -1360,6 +1368,7 @@ static void blkif_free(struct blkfront_info *info, int suspend)if (info->rq)blk_mq_stop_hw_queues (info->rq); +free_rings:for_each_rinfo (info, rinfo, i)blkif_free_ring (rinfo);
@@ -1563,8 +1572,10 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)struct blkfront_ring_info *rinfo = (struct blkfront_ring_info *)dev_id;struct blkfront_info *info = rinfo->dev_info; -if (unlikely (info->connected !=BLKIF_STATE_CONNECTED )) +if (unlikely (info->connected !=BLKIF_STATE_CONNECTED && + info->connected !=BLKIF_STATE_FREEZING )) {return IRQ_HANDLED ; + }spin_lock_irqsave (&rinfo->ring_lock, flags); again:
@@ -2027,6 +2038,7 @@ static int blkif_recover(struct blkfront_info *info)struct bio *bio;unsigned int segs;struct blkfront_ring_info *rinfo; +bool frozen = info->connected ==BLKIF_STATE_FROZEN ;blkfront_gather_backend_features (info);/* Reset limits changed by blk_mq_update_nr_hw_queues(). */
@@ -2049,6 +2061,9 @@ static int blkif_recover(struct blkfront_info *info)kick_pending_request_queues (rinfo); } +if (frozen) +return 0 ; +list_for_each_entry_safe (req, n, &info->requests, queuelist) {/* Requeue pending requests (flush or discard) */ list_del_init (&req->queuelist);
@@ -2365,6 +2380,7 @@ static void blkfront_connect(struct blkfront_info *info)return ;case BLKIF_STATE_SUSPENDED : +case BLKIF_STATE_FROZEN :/* * If we are recovering from suspension, we need to wait * for the backend to announce it's features before
@@ -2482,12 +2498,37 @@ static void blkback_changed(struct xenbus_device *dev,break ;case XenbusStateClosed: -if (dev->state == XenbusStateClosed) +if (dev->state == XenbusStateClosed) { +if (info->connected ==BLKIF_STATE_FREEZING ) { +blkif_free (info,0 ); + info->connected =BLKIF_STATE_FROZEN ; +complete (&info->wait_backend_disconnected); + }break ; + } +/* +* We receive backend's Closed again while thawing +* or restoring and it causes thawing or restoring to fail. +* During blkfront_restore, backend is still in Closed state +* and we receive backend as closed here while frontend's +* dev->state is set to XenBusStateInitialized. +* Ignore such unexpected state regardless of the backend's +* state. +*/ +if (info->connected ==BLKIF_STATE_FROZEN ) { +dev_dbg (&dev->dev,"Thawing/Restoring, ignore the backend's Closed state: %s" , + dev->nodename); +break ; + } +/* fall through */ case XenbusStateClosing: -if (info) -blkfront_closing (info); +if (info) { +if (info->connected ==BLKIF_STATE_FREEZING ) +xenbus_frontend_closed (dev); +else +blkfront_closing (info); + }break ; } }
@@ -2631,6 +2672,76 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)mutex_unlock (&blkfront_mutex); } +static int blkfront_freeze (struct xenbus_device *dev) +{ +unsigned int i; +struct blkfront_info *info =dev_get_drvdata (&dev->dev); +struct blkfront_ring_info *rinfo; +/* This would be reasonable timeout as used in xenbus_dev_shutdown() */ +unsigned int timeout =5 *HZ ; +unsigned long flags; + + info->connected =BLKIF_STATE_FREEZING ; + +blk_mq_freeze_queue (info->rq); +blk_mq_quiesce_queue (info->rq); + +for_each_rinfo (info, rinfo, i) { +/* No more gnttab callback work. */ +gnttab_cancel_free_callback (&rinfo->callback); +/* Flush gnttab callback work. Must be done with no locks held. */ +flush_work (&rinfo->work); + } + +for_each_rinfo (info, rinfo, i) { +spin_lock_irqsave (&rinfo->ring_lock, flags); +if (RING_FULL (&rinfo->ring) || +RING_HAS_UNCONSUMED_RESPONSES (&rinfo->ring)) { +spin_unlock_irqrestore (&rinfo->ring_lock, flags); +xenbus_dev_error (dev, -EBUSY ,"Hibernation Failed. The ring is still busy" ); + info->connected =BLKIF_STATE_CONNECTED ; +blk_mq_unquiesce_queue (info->rq); +blk_mq_unfreeze_queue (info->rq); +return -EBUSY ; + } +spin_unlock_irqrestore (&rinfo->ring_lock, flags); + } +/* Kick the backend to disconnect */ +xenbus_switch_state (dev, XenbusStateClosing); + +/* +* We don't want to move forward before the frontend is diconnected +* from the backend cleanly. +* TODO:Handle timeout by falling back to the normal +* disconnect path and just wait for the backend to close before +* reconnecting. Bring the system back to its original state by +* failing hibernation gracefully. +*/ + timeout =wait_for_completion_timeout (&info->wait_backend_disconnected, + timeout); +if (!timeout) { +xenbus_dev_error (dev, -EBUSY ,"Freezing timed out;" +"the device may become inconsistent state" ); +return -EBUSY ; + } + +return 0 ; +} + +static int blkfront_restore (struct xenbus_device *dev) +{ +struct blkfront_info *info =dev_get_drvdata (&dev->dev); +int err; + + err =talk_to_blkback (dev, info); +if (!err) { +blk_mq_update_nr_hw_queues (&info->tag_set, info->nr_rings); +blk_mq_unquiesce_queue (info->rq); +blk_mq_unfreeze_queue (info->rq); + } +return err; +} +static const struct block_device_operations xlvbd_block_fops = { .owner =THIS_MODULE ,
@@ -2654,6 +2765,9 @@ static struct xenbus_driver blkfront_driver = { .resume = blkfront_resume, .otherend_changed = blkback_changed, .is_ready = blkfront_is_ready, + .freeze = blkfront_freeze, + .thaw = blkfront_restore, + .restore = blkfront_restore, };static void purge_persistent_grants (struct blkfront_info *info)
Signature · 1 line
2.16.6
PATCH v3 7/11 xen-netfront: add callbacks for PM suspend and hibernation
In reply to Anchal AgarwalFrom: Munehisa Kamata <[email protected]>
Add freeze, thaw and restore callbacks for PM suspend and hibernation support. The freeze handler simply disconnects the frotnend from the backend and frees resources associated with queues after disabling the net_device from the system. The restore handler just changes the frontend state and let the xenbus handler to re-allocate the resources and re-connect to the backend. This can be performed transparently to the rest of the system. The handlers are used for both PM suspend and hibernation so that we can keep the existing suspend/resume callbacks for Xen suspend without modification. Freezing netfront devices is normally expected to finish within a few hundred milliseconds, but it can rarely take more than 5 seconds and hit the hard coded timeout, it would depend on backend state which may be congested and/or have complex configuration. While it's rare case, longer default timeout seems a bit more reasonable here to avoid hitting the timeout. Also, make it configurable via module parameter so that we can cover broader setups than what we know currently.
[Anchal Agarwal: Changelog]:RFCv1->RFCv2: Variable name fix and checkpatch.pl fixes] v2->v3: Resolved merge conflicts
--- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-)
drivers/net/xen-netfront.c +95 -1
@@ -47,6 +47,7 @@#include <linux/bpf.h> #include <net/page_pool.h> #include <linux/bpf_trace.h> +#include <linux/completion.h> #include <xen/xen.h> #include <xen/xenbus.h>
@@ -59,6 +60,12 @@#include <xen/interface/memory.h> #include <xen/interface/grant_table.h> +enum netif_freeze_state { +NETIF_FREEZE_STATE_UNFROZEN , +NETIF_FREEZE_STATE_FREEZING , +NETIF_FREEZE_STATE_FROZEN , +}; +/* Module parameters */ #define MAX_QUEUES_DEFAULT 8static unsigned int xennet_max_queues;
@@ -68,6 +75,12 @@ MODULE_PARM_DESC(max_queues,#define XENNET_TIMEOUT (5 * HZ) +static unsigned int netfront_freeze_timeout_secs =10 ; +module_param_named (freeze_timeout_secs, + netfront_freeze_timeout_secs, uint,0644 ); +MODULE_PARM_DESC (freeze_timeout_secs, +"timeout when freezing netfront device in seconds" ); +static const struct ethtool_ops xennet_ethtool_ops;struct netfront_cb {
@@ -174,6 +187,9 @@ struct netfront_info {bool netfront_xdp_enabled;atomic_t rx_gso_checksum_fixup; + +int freeze_state; +struct completion wait_backend_disconnected; };struct netfront_rx_info {
@@ -798,6 +814,21 @@ static int xennet_close(struct net_device *dev)return 0 ; } +static int xennet_disable_interrupts (struct net_device *dev) +{ +struct netfront_info *np =netdev_priv (dev); +unsigned int num_queues = dev->real_num_tx_queues; +unsigned int queue_index; +struct netfront_queue *queue; + +for (queue_index =0 ; queue_index < num_queues; ++queue_index) { + queue = &np->queues[queue_index]; +disable_irq (queue->tx_irq); +disable_irq (queue->rx_irq); + } +return 0 ; +} +static void xennet_move_rx_slot (struct netfront_queue *queue,struct sk_buff *skb,grant_ref_t ref) {
@@ -1532,6 +1563,8 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev) np->queues =NULL ; +init_completion (&np->wait_backend_disconnected); + err = -ENOMEM ; np->rx_stats = netdev_alloc_pcpu_stats(struct netfront_stats);if (np->rx_stats ==NULL )
@@ -2084,6 +2117,50 @@ static int xennet_create_queues(struct netfront_info *info,return 0 ; } +static int netfront_freeze (struct xenbus_device *dev) +{ +struct netfront_info *info =dev_get_drvdata (&dev->dev); +unsigned long timeout = netfront_freeze_timeout_secs *HZ ; +int err =0 ; + +xennet_disable_interrupts (info->netdev); + +netif_device_detach (info->netdev); + + info->freeze_state =NETIF_FREEZE_STATE_FREEZING ; + +/* Kick the backend to disconnect */ +xenbus_switch_state (dev, XenbusStateClosing); + +/* We don't want to move forward before the frontend is diconnected +* from the backend cleanly. +*/ + timeout =wait_for_completion_timeout (&info->wait_backend_disconnected, + timeout); +if (!timeout) { + err = -EBUSY ; +xenbus_dev_error (dev, err,"Freezing timed out;" +"the device may become inconsistent state" ); +return err; + } + +/* Tear down queues */ +xennet_disconnect_backend (info); +xennet_destroy_queues (info); + + info->freeze_state =NETIF_FREEZE_STATE_FROZEN ; + +return err; +} + +static int netfront_restore (struct xenbus_device *dev) +{ +/* Kick the backend to re-connect */ +xenbus_switch_state (dev, XenbusStateInitialising); + +return 0 ; +} +/* Common code used when first setting up, and when resuming. */ static int talk_to_netback (struct xenbus_device *dev,struct netfront_info *info)
@@ -2302,6 +2379,8 @@ static int xennet_connect(struct net_device *dev)spin_unlock_bh (&queue->rx_lock); } + np->freeze_state =NETIF_FREEZE_STATE_UNFROZEN ; +return 0 ; }
@@ -2339,10 +2418,22 @@ static void netback_changed(struct xenbus_device *dev,break ;case XenbusStateClosed: -if (dev->state == XenbusStateClosed) +if (dev->state == XenbusStateClosed) { +/* dpm context is waiting for the backend */ +if (np->freeze_state ==NETIF_FREEZE_STATE_FREEZING ) +complete (&np->wait_backend_disconnected);break ; + }/* Fall through - Missed the backend's CLOSING state. */ case XenbusStateClosing: +/* We may see unexpected Closed or Closing from the backend. +* Just ignore it not to prevent the frontend from being +* re-connected in the case of PM suspend or hibernation. +*/ +if (np->freeze_state ==NETIF_FREEZE_STATE_FROZEN && + dev->state == XenbusStateInitialising) { +break ; + }xenbus_frontend_closed (dev);break ; }
@@ -2505,6 +2596,9 @@ static struct xenbus_driver netfront_driver = { .probe = netfront_probe, .remove = xennet_remove, .resume = netfront_resume, + .freeze = netfront_freeze, + .thaw = netfront_restore, + .restore = netfront_restore, .otherend_changed = netback_changed, };
Signature · 1 line
2.16.6
PATCH v3 8/11 x86/xen: save and restore steal clock during PM hibernation
In reply to Anchal AgarwalSave/restore steal times in syscore suspend/resume during PM hibernation. Commit '5e25f5db6abb9: ("xen/time: do not decrease steal time after live migration on xen")' fixes xen guest steal time handling during migration. A similar issue is seen during PM hibernation.
Currently, steal time accounting code in scheduler expects steal clock callback to provide monotonically increasing value. If the accounting code receives a smaller value than previous one, it uses a negative value to calculate steal time and results in incorrectly updated idle and steal time accounting. This breaks userspace tools which read /proc/stat.
top - 08:05:35 up 2:12, 3 users, load average: 0.00, 0.07, 0.23
Tasks: 80 total, 1 running, 79 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,30100.0%id, 0.0%wa, 0.0%hi, 0.0%si,-1253874204672.0%st
This can actually happen when a Xen PVHVM guest gets restored from hibernation, because such a restored guest is just a fresh domain from Xen perspective and the time information in runstate info starts over from scratch.
Changelog:v1->v2: Removed patches that introduced new function calls for saving/restoring
sched clock offset and using existing ones that are used during LM
--- arch/x86/xen/suspend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/suspend.c +2 -1
@@ -99,6 +99,7 @@ static int xen_syscore_suspend(void)gnttab_suspend (); +xen_manage_runstate_time (-1 ); xrfp.domid =DOMID_SELF ; xrfp.gpfn =__pa (HYPERVISOR_shared_info) >>PAGE_SHIFT ;
@@ -119,7 +120,7 @@ static void xen_syscore_resume(void)xen_hvm_map_shared_info ();pvclock_resume (); - +xen_manage_runstate_time (0 );gnttab_resume (); }
Signature · 1 line
2.16.6
PATCH v3 9/11 xen: Introduce wrapper for save/restore sched clock offset
In reply to Anchal AgarwalIntroduce wrappers for save/restore xen_sched_clock_offset to be used by PM hibernation code to avoid system instability during resume.
--- arch/x86/xen/time.c | 15 +++++++++++++-- arch/x86/xen/xen-ops.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-)
arch/x86/xen/time.c +13 -2
@@ -387,12 +387,23 @@ static const struct pv_time_ops xen_time_ops __initconst = {static struct pvclock_vsyscall_time_info *xen_clock__read_mostly ;static u64 xen_clock_value_saved; +/*This is needed to maintain a monotonic clock value during PM hibernation */ +void xen_save_sched_clock_offset (void ) +{ + xen_clock_value_saved =xen_clocksource_read () - xen_sched_clock_offset; +} + +void xen_restore_sched_clock_offset (void ) +{ + xen_sched_clock_offset =xen_clocksource_read () - xen_clock_value_saved; +} +void xen_save_time_memory_area (void ) {struct vcpu_register_time_memory_area t;int ret; - xen_clock_value_saved =xen_clocksource_read () - xen_sched_clock_offset; +xen_save_sched_clock_offset ();if (!xen_clock)return ;
@@ -435,7 +446,7 @@ void xen_restore_time_memory_area(void) out:/* Need pvclock_resume() before using xen_clocksource_read(). */ pvclock_resume (); - xen_sched_clock_offset =xen_clocksource_read () - xen_clock_value_saved; +xen_restore_sched_clock_offset (); }static void xen_setup_vsyscall_time_info (void )
arch/x86/xen/xen-ops.h +2 -0
@@ -69,6 +69,8 @@ void xen_save_time_memory_area(void);void xen_restore_time_memory_area (void );void xen_init_time_ops (void );void xen_hvm_init_time_ops (void ); +void xen_save_sched_clock_offset (void ); +void xen_restore_sched_clock_offset (void );irqreturn_t xen_debug_interrupt (int irq,void *dev_id);
Signature · 1 line
2.16.6
PATCH v3 10/11 xen: Update sched clock offset to avoid system instability in hibernation
In reply to Anchal AgarwalSave/restore xen_sched_clock_offset in syscore suspend/resume during PM hibernation. Commit '867cefb4cb1012: ("xen: Fix x86 sched_clock() interface for xen")' fixes xen guest time handling during migration. A similar issue is seen during PM hibernation when system runs CPU intensive workload. Post resume pvclock resets the value to 0 however, xen sched_clock_offset is never updated. System instability is seen during resume from hibernation when system is under heavy CPU load. Since xen_sched_clock_offset is not updated, system does not see the monotonic clock value and the scheduler would then think that heavy CPU hog tasks need more time in CPU, causing the system to freeze
--- arch/x86/xen/suspend.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/x86/xen/suspend.c +8 -1
@@ -98,8 +98,9 @@ static int xen_syscore_suspend(void)return 0 ;gnttab_suspend (); -xen_manage_runstate_time (-1 ); +xen_save_sched_clock_offset (); + xrfp.domid =DOMID_SELF ; xrfp.gpfn =__pa (HYPERVISOR_shared_info) >>PAGE_SHIFT ;
@@ -120,6 +121,12 @@ static void xen_syscore_resume(void)xen_hvm_map_shared_info ();pvclock_resume (); + +/* +* Restore xen_sched_clock_offset during resume to maintain +* monotonic clock value +*/ +xen_restore_sched_clock_offset ();xen_manage_runstate_time (0 );gnttab_resume (); }
Signature · 1 line
2.16.6
[email protected]
reviewerRe: [PATCH v3 10/11] xen: Update sched clock offset to avoid system instability in hibernation
Quoted 10 lines · Anchal Agarwal
Save/restore
xen_sched_clock_offsetin syscore suspend/resume during PM hibernation. Commit '867cefb4cb1012: ("xen: Fix x86sched_clock()interface for xen")' fixes xen guest time handling during migration. A similar issue is seen during PM hibernation when system runs CPU intensive workload. Post resume pvclock resets the value to 0 however, xensched_clock_offsetis never updated. System instability is seen during resume from hibernation when system is under heavy CPU load. Sincexen_sched_clock_offsetis not updated, system does not see the monotonic clock value and the scheduler would then think that heavy CPU hog tasks need more time in CPU, causing the system to freeze
I don't think you need to explain why non-monotonic clocks are bad. (and, in fact, the same applies to commit message in patch 8)
Quoted 22 lines
Signed-off-by Anchal Agarwal <[email protected]>--- arch/x86/xen/suspend.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)arch/x86/xen/suspend.c +2
-1@@ -98,8 +98,9 @@ static int xen_syscore_suspend(void)return 0 ;gnttab_suspend (); -xen_manage_runstate_time (-1 ); +xen_save_sched_clock_offset (); + xrfp.domid =DOMID_SELF ; xrfp.gpfn =__pa (HYPERVISOR_shared_info) >>PAGE_SHIFT ;
arch/x86/xen/suspend.c static void xen_syscore_resume(void) · line 128
Quoted 8 lines
arch/x86/xen/suspend.c +5
-0@@ -120,6 +121,12 @@ static void xen_syscore_resume(void)xen_hvm_map_shared_info ();pvclock_resume (); + +/* +* Restore xen_sched_clock_offset during resume to maintain +* monotonic clock value +*/
I'd drop this comment, we know what the call does.
-boris
Quoted 4 lines
arch/x86/xen/suspend.c +1
-0+xen_restore_sched_clock_offset ();xen_manage_runstate_time (0 );gnttab_resume (); }
PATCH v3 11/11 PM / hibernate: update the resume offset on SNAPSHOT_SET_SWAP_AREA
In reply to Anchal AgarwalFrom: Aleksei Besogonov <[email protected]>
The SNAPSHOT_SET_SWAP_AREA is supposed to be used to set the hibernation offset on a running kernel to enable hibernating to a swap file. However, it doesn't actually update the swsusp_resume_block variable. As a result, the hibernation fails at the last step (after all the data is written out) in the validation of the swap signature in mark_swapfiles().
Before this patch, the command line processing was the only place where swsusp_resume_block was set.
[Anchal Agarwal: Changelog: Resolved patch conflict as code fragmented to snapshot_set_swap_area]
--- kernel/power/user.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/power/user.c +5 -2
@@ -242,9 +242,12 @@ static int snapshot_set_swap_area(struct snapshot_data *data,return -EINVAL ; } data->swap =swap_type_of (swdev, offset, &bdev); -if (data->swap <0 ) +if (data->swap <0 ) {return -ENODEV ; - + }else { + swsusp_resume_device = swdev; + swsusp_resume_block = offset; + } data->bd_inode = bdev->bd_inode;bdput (bdev);return 0 ;
Signature · 1 line
2.16.6
Quoted 106 lines · Anchal Agarwal
Hello,
This series fixes PM hibernation for hvm guests running on xen hypervisor. The running guest could now be hibernated and resumed successfully at a later time. The fixes for PM hibernation are added to block and network device drivers i.e xen-blkfront and xen-netfront. Any other driver that needs to add S4 support if not already, can follow same method of introducing freeze/thaw/restore callbacks.
The patches had been tested against upstream kernel and xen4.11. Large scale testing is also done on Xen based Amazon EC2 instances. All this testing involved running memory exhausting workload in the background.Doing guest hibernation does not involve any support from hypervisor and this way guest has complete control over its state. Infrastructure restrictions for saving up guest state can be overcome by guest initiated hibernation.
These patches were send out as RFC before and all the feedback had been incorporated in the patches. The last v1 & v2 could be found here:
[v1]: https://lkml.org/lkml/2020/5/19/1312
[v2]: https://lkml.org/lkml/2020/7/2/995
All comments and feedback from v2 had been incorporated in v3 series.Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.Testing How to:
---------------
1. Setup xen hypervisor on a physical machine[ I used Ubuntu 16.04 +upstream xen-4.11]
2. Bring up a HVM guest w/t kernel compiled with hibernation patches [I used ubuntu18.04 netboot bionic images and also Amazon Linux on-prem images].
3. Create a swap file size=RAM size
4. Update grub parameters and reboot
5. Trigger pm-hibernation from within the VMExample:
Set up a file-backed swap space. Swap file size>=Total memory on the system sudo dd if=/dev/zero of=/swap bs=$(( 1024 * 1024 )) count=4096 # 4096MiB sudo chmod 600 /swap
sudo mkswap /swap
sudo swapon /swapUpdate resume device/resume offset in grub if using swap file:
resume=/dev/xvda1 resume_offset=200704 no_console_suspend=1Execute:
--------
sudo pm-hibernate
OR
echo disk >/sys/power/state&& echo reboot >/sys/power/diskCompute resume offset code:
"
#!/usr/bin/env python
import sys
import array
import fcntl#swap file
f =open(sys.argv[1], 'r')
buf =array.array('L', [0])#FIBMAP
ret =fcntl.ioctl(f.fileno(), 0x01, buf)
print buf[0]
"Aleksei Besogonov (1):
PM / hibernate: update the resume offset onSNAPSHOT_SET_SWAP_AREAAnchal Agarwal (4):
x86/xen: Introduce new function to mapHYPERVISOR_shared_infoon
Resume
x86/xen: save and restore steal clock during PM hibernation
xen: Introduce wrapper for save/restore sched clock offset
xen: Update sched clock offset to avoid system instability in
hibernationMunehisa Kamata (5):
xen/manage: keep track of the on-going suspend mode
xenbus: add freeze/thaw/restore callbacks support x86/xen: add system core suspend and resume callbacks
xen-blkfront: add callbacks for PM suspend and hibernation
xen-netfront: add callbacks for PM suspend and hibernationThomas Gleixner (1):
genirq: Shutdown irq chips in suspend/resume during hibernationarch/x86/xen/enlighten_hvm.c | 7 +++ arch/x86/xen/suspend.c | 63 ++++++++++++++++++++ arch/x86/xen/time.c | 15 ++++- arch/x86/xen/xen-ops.h | 3 + drivers/block/xen-blkfront.c | 122 ++++++++++++++++++++++++++++++++++++-- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++- drivers/xen/events/events_base.c | 1 + drivers/xen/manage.c | 46 ++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++-----
Quoted 12 lines
include/linux/irq.h | 2 + include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 3 + kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 +++++++--- kernel/power/user.c | 7 ++- 16 files changed, 464 insertions(+), 34 deletions(-)Signature · 1 line
2.16.6
A gentle ping on the series in case there is any more feedback or can we plan to merge this? I can then send the series with minor fixes pointed by tglx@
Thanks,
Anchal
Rafael J. Wysocki
maintainerQuoted 117 lines · Anchal Agarwal
Quoted 115 lines · Anchal Agarwal
Hello,
This series fixes PM hibernation for hvm guests running on xen hypervisor. The running guest could now be hibernated and resumed successfully at a later time. The fixes for PM hibernation are added to block and network device drivers i.e xen-blkfront and xen-netfront. Any other driver that needs to add S4 support if not already, can follow same method of introducing freeze/thaw/restore callbacks.
The patches had been tested against upstream kernel and xen4.11. Large scale testing is also done on Xen based Amazon EC2 instances. All this testing involved running memory exhausting workload in the background.Doing guest hibernation does not involve any support from hypervisor and this way guest has complete control over its state. Infrastructure restrictions for saving up guest state can be overcome by guest initiated hibernation.
These patches were send out as RFC before and all the feedback had been incorporated in the patches. The last v1 & v2 could be found here:
[v1]: https://lkml.org/lkml/2020/5/19/1312
[v2]: https://lkml.org/lkml/2020/7/2/995
All comments and feedback from v2 had been incorporated in v3 series.Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.Testing How to:
---------------
1. Setup xen hypervisor on a physical machine[ I used Ubuntu 16.04 +upstream xen-4.11]
2. Bring up a HVM guest w/t kernel compiled with hibernation patches [I used ubuntu18.04 netboot bionic images and also Amazon Linux on-prem images].
3. Create a swap file size=RAM size
4. Update grub parameters and reboot
5. Trigger pm-hibernation from within the VMExample:
Set up a file-backed swap space. Swap file size>=Total memory on the system sudo dd if=/dev/zero of=/swap bs=$(( 1024 * 1024 )) count=4096 # 4096MiB sudo chmod 600 /swap
sudo mkswap /swap
sudo swapon /swapUpdate resume device/resume offset in grub if using swap file:
resume=/dev/xvda1 resume_offset=200704 no_console_suspend=1Execute:
--------
sudo pm-hibernate
OR
echo disk >/sys/power/state&& echo reboot >/sys/power/diskCompute resume offset code:
"
#!/usr/bin/env python
import sys
import array
import fcntl#swap file
f =open(sys.argv[1], 'r')
buf =array.array('L', [0])#FIBMAP
ret =fcntl.ioctl(f.fileno(), 0x01, buf)
print buf[0]
"Aleksei Besogonov (1):
PM / hibernate: update the resume offset onSNAPSHOT_SET_SWAP_AREAAnchal Agarwal (4):
x86/xen: Introduce new function to mapHYPERVISOR_shared_infoon
Resume
x86/xen: save and restore steal clock during PM hibernation
xen: Introduce wrapper for save/restore sched clock offset
xen: Update sched clock offset to avoid system instability in
hibernationMunehisa Kamata (5):
xen/manage: keep track of the on-going suspend mode
xenbus: add freeze/thaw/restore callbacks support x86/xen: add system core suspend and resume callbacks
xen-blkfront: add callbacks for PM suspend and hibernation
xen-netfront: add callbacks for PM suspend and hibernationThomas Gleixner (1):
genirq: Shutdown irq chips in suspend/resume during hibernationarch/x86/xen/enlighten_hvm.c | 7 +++ arch/x86/xen/suspend.c | 63 ++++++++++++++++++++ arch/x86/xen/time.c | 15 ++++- arch/x86/xen/xen-ops.h | 3 + drivers/block/xen-blkfront.c | 122 ++++++++++++++++++++++++++++++++++++-- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++- drivers/xen/events/events_base.c | 1 + drivers/xen/manage.c | 46 ++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++----- include/linux/irq.h | 2 + include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 3 + kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 +++++++--- kernel/power/user.c | 7 ++- 16 files changed, 464 insertions(+), 34 deletions(-)
Quoted 5 lines
Quoted 3 lines
--
2.16.6A gentle ping on the series in case there is any more feedback or can we plan to merge this? I can then send the series with minor fixes pointed by tglx@
Some more time, please!
Quoted 122 lines · Rafael J. Wysocki
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 117 lines · Anchal Agarwal
Quoted 115 lines · Anchal Agarwal
Hello,
This series fixes PM hibernation for hvm guests running on xen hypervisor. The running guest could now be hibernated and resumed successfully at a later time. The fixes for PM hibernation are added to block and network device drivers i.e xen-blkfront and xen-netfront. Any other driver that needs to add S4 support if not already, can follow same method of introducing freeze/thaw/restore callbacks.
The patches had been tested against upstream kernel and xen4.11. Large scale testing is also done on Xen based Amazon EC2 instances. All this testing involved running memory exhausting workload in the background.Doing guest hibernation does not involve any support from hypervisor and this way guest has complete control over its state. Infrastructure restrictions for saving up guest state can be overcome by guest initiated hibernation.
These patches were send out as RFC before and all the feedback had been incorporated in the patches. The last v1 & v2 could be found here:
[v1]: https://lkml.org/lkml/2020/5/19/1312
[v2]: https://lkml.org/lkml/2020/7/2/995
All comments and feedback from v2 had been incorporated in v3 series.Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.Testing How to:
---------------
1. Setup xen hypervisor on a physical machine[ I used Ubuntu 16.04 +upstream xen-4.11]
2. Bring up a HVM guest w/t kernel compiled with hibernation patches [I used ubuntu18.04 netboot bionic images and also Amazon Linux on-prem images].
3. Create a swap file size=RAM size
4. Update grub parameters and reboot
5. Trigger pm-hibernation from within the VMExample:
Set up a file-backed swap space. Swap file size>=Total memory on the system sudo dd if=/dev/zero of=/swap bs=$(( 1024 * 1024 )) count=4096 # 4096MiB sudo chmod 600 /swap
sudo mkswap /swap
sudo swapon /swapUpdate resume device/resume offset in grub if using swap file:
resume=/dev/xvda1 resume_offset=200704 no_console_suspend=1Execute:
--------
sudo pm-hibernate
OR
echo disk >/sys/power/state&& echo reboot >/sys/power/diskCompute resume offset code:
"
#!/usr/bin/env python
import sys
import array
import fcntl#swap file
f =open(sys.argv[1], 'r')
buf =array.array('L', [0])#FIBMAP
ret =fcntl.ioctl(f.fileno(), 0x01, buf)
print buf[0]
"Aleksei Besogonov (1):
PM / hibernate: update the resume offset onSNAPSHOT_SET_SWAP_AREAAnchal Agarwal (4):
x86/xen: Introduce new function to mapHYPERVISOR_shared_infoon
Resume
x86/xen: save and restore steal clock during PM hibernation
xen: Introduce wrapper for save/restore sched clock offset
xen: Update sched clock offset to avoid system instability in
hibernationMunehisa Kamata (5):
xen/manage: keep track of the on-going suspend mode
xenbus: add freeze/thaw/restore callbacks support x86/xen: add system core suspend and resume callbacks
xen-blkfront: add callbacks for PM suspend and hibernation
xen-netfront: add callbacks for PM suspend and hibernationThomas Gleixner (1):
genirq: Shutdown irq chips in suspend/resume during hibernationarch/x86/xen/enlighten_hvm.c | 7 +++ arch/x86/xen/suspend.c | 63 ++++++++++++++++++++ arch/x86/xen/time.c | 15 ++++- arch/x86/xen/xen-ops.h | 3 + drivers/block/xen-blkfront.c | 122 ++++++++++++++++++++++++++++++++++++-- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++- drivers/xen/events/events_base.c | 1 + drivers/xen/manage.c | 46 ++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++----- include/linux/irq.h | 2 + include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 3 + kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 +++++++--- kernel/power/user.c | 7 ++- 16 files changed, 464 insertions(+), 34 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
--
2.16.6A gentle ping on the series in case there is any more feedback or can we plan to merge this? I can then send the series with minor fixes pointed by tglx@
Some more time, please!
Sure happy to answer any more questions and fix more BUGS!!
--
Anchal
Quoted 129 lines · Anchal Agarwal
Quoted 128 lines · Rafael J. Wysocki
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 122 lines · Anchal Agarwal
Quoted 115 lines · Anchal Agarwal
Hello,
This series fixes PM hibernation for hvm guests running on xen hypervisor. The running guest could now be hibernated and resumed successfully at a later time. The fixes for PM hibernation are added to block and network device drivers i.e xen-blkfront and xen-netfront. Any other driver that needs to add S4 support if not already, can follow same method of introducing freeze/thaw/restore callbacks.
The patches had been tested against upstream kernel and xen4.11. Large scale testing is also done on Xen based Amazon EC2 instances. All this testing involved running memory exhausting workload in the background.Doing guest hibernation does not involve any support from hypervisor and this way guest has complete control over its state. Infrastructure restrictions for saving up guest state can be overcome by guest initiated hibernation.
These patches were send out as RFC before and all the feedback had been incorporated in the patches. The last v1 & v2 could be found here:
[v1]: https://lkml.org/lkml/2020/5/19/1312
[v2]: https://lkml.org/lkml/2020/7/2/995
All comments and feedback from v2 had been incorporated in v3 series.Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.Testing How to:
---------------
1. Setup xen hypervisor on a physical machine[ I used Ubuntu 16.04 +upstream xen-4.11]
2. Bring up a HVM guest w/t kernel compiled with hibernation patches [I used ubuntu18.04 netboot bionic images and also Amazon Linux on-prem images].
3. Create a swap file size=RAM size
4. Update grub parameters and reboot
5. Trigger pm-hibernation from within the VMExample:
Set up a file-backed swap space. Swap file size>=Total memory on the system sudo dd if=/dev/zero of=/swap bs=$(( 1024 * 1024 )) count=4096 # 4096MiB sudo chmod 600 /swap
sudo mkswap /swap
sudo swapon /swapUpdate resume device/resume offset in grub if using swap file:
resume=/dev/xvda1 resume_offset=200704 no_console_suspend=1Execute:
--------
sudo pm-hibernate
OR
echo disk >/sys/power/state&& echo reboot >/sys/power/diskCompute resume offset code:
"
#!/usr/bin/env python
import sys
import array
import fcntl#swap file
f =open(sys.argv[1], 'r')
buf =array.array('L', [0])#FIBMAP
ret =fcntl.ioctl(f.fileno(), 0x01, buf)
print buf[0]
"Aleksei Besogonov (1):
PM / hibernate: update the resume offset onSNAPSHOT_SET_SWAP_AREAAnchal Agarwal (4):
x86/xen: Introduce new function to mapHYPERVISOR_shared_infoon
Resume
x86/xen: save and restore steal clock during PM hibernation
xen: Introduce wrapper for save/restore sched clock offset
xen: Update sched clock offset to avoid system instability in
hibernationMunehisa Kamata (5):
xen/manage: keep track of the on-going suspend mode
xenbus: add freeze/thaw/restore callbacks support x86/xen: add system core suspend and resume callbacks
xen-blkfront: add callbacks for PM suspend and hibernation
xen-netfront: add callbacks for PM suspend and hibernationThomas Gleixner (1):
genirq: Shutdown irq chips in suspend/resume during hibernationarch/x86/xen/enlighten_hvm.c | 7 +++ arch/x86/xen/suspend.c | 63 ++++++++++++++++++++ arch/x86/xen/time.c | 15 ++++- arch/x86/xen/xen-ops.h | 3 + drivers/block/xen-blkfront.c | 122 ++++++++++++++++++++++++++++++++++++-- drivers/net/xen-netfront.c | 96 +++++++++++++++++++++++++++++- drivers/xen/events/events_base.c | 1 + drivers/xen/manage.c | 46 ++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 96 +++++++++++++++++++++++++----- include/linux/irq.h | 2 + include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 3 + kernel/irq/chip.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/pm.c | 31 +++++++--- kernel/power/user.c | 7 ++- 16 files changed, 464 insertions(+), 34 deletions(-)Quoted 3 lines
--
2.16.6A gentle ping on the series in case there is any more feedback or can we plan to merge this? I can then send the series with minor fixes pointed by tglx@
Quoted 7 lines
Quoted 2 lines
Some more time, please!
Sure happy to answer any more questions and fix more BUGS!!
--
Anchal
A gentle ping on this one again!
--
Anchal
[email protected]
reviewerQuoted 5 lines · Anchal Agarwal
Known issues:
1.KASLR causes intermittent hibernation failures. VM fails to resumes and has to be restarted. I will investigate this issue separately and shouldn't be a blocker for this patch series.
Is there any change in status for this? This has been noted since January.
-boris
Quoted 7 lines
2. During hibernation, I observed sometimes that freezing of tasks fails due to busy XFS workqueuei[xfs-cil/xfs-sync]. This is also intermittent may be 1 out of 200 runs and hibernation is aborted in this case. Re-trying hibernation may work. Also, this is a known issue with hibernation and some filesystems like XFS has been discussed by the community for years with not an effectve resolution at this point.