Add KVM suspend/hibernate PM-notifier which lets architectures
to implement arch-specific VM suspend code. For instance, on x86
this sets PVCLOCK_GUEST_STOPPED on all the VCPUs.
Our case is that user puts the host system into sleep multiple
times a day (e.g. closes the laptop's lid) so we need a reliable
way to suspend VMs properly.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
arch/arm64/kvm/arm.c | 4 ++++
arch/mips/kvm/mips.c | 4 ++++
arch/powerpc/kvm/powerpc.c | 4 ++++
arch/s390/kvm/kvm-s390.c | 4 ++++
arch/x86/kvm/x86.c | 21 ++++++++++++++++++++
include/linux/kvm_host.h | 8 ++++++++
virt/kvm/kvm_main.c | 40 ++++++++++++++++++++++++++++++++++++++
7 files changed, 85 insertions(+)
From: Peter Zijlstra <peterz@infradead.org> Date: 2021-06-03 17:28:44
On Fri, Jun 04, 2021 at 01:43:15AM +0900, Sergey Senozhatsky wrote:
quoted hunk
Add KVM suspend/hibernate PM-notifier which lets architectures
to implement arch-specific VM suspend code. For instance, on x86
this sets PVCLOCK_GUEST_STOPPED on all the VCPUs.
Our case is that user puts the host system into sleep multiple
times a day (e.g. closes the laptop's lid) so we need a reliable
way to suspend VMs properly.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
arch/arm64/kvm/arm.c | 4 ++++
arch/mips/kvm/mips.c | 4 ++++
arch/powerpc/kvm/powerpc.c | 4 ++++
arch/s390/kvm/kvm-s390.c | 4 ++++
arch/x86/kvm/x86.c | 21 ++++++++++++++++++++
include/linux/kvm_host.h | 8 ++++++++
virt/kvm/kvm_main.c | 40 ++++++++++++++++++++++++++++++++++++++
7 files changed, 85 insertions(+)
On Fri, Jun 04, 2021 at 01:43:15AM +0900, Sergey Senozhatsky wrote:
[..]
quoted
+void kvm_arch_pm_notifier(struct kvm *kvm)
+{
+}
+
long kvm_arch_vm_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
{
What looks like you wants a __weak function.
True. Thanks for the suggestion.
I thought about it, but I recalled that tglx had __strong opinions
on __weak functions.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Paolo Bonzini <pbonzini@redhat.com> Date: 2021-06-04 07:17:56
On 04/06/21 02:39, Sergey Senozhatsky wrote:
quoted
quoted
+void kvm_arch_pm_notifier(struct kvm *kvm)
+{
+}
+
long kvm_arch_vm_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
{
What looks like you wants a __weak function.
True. Thanks for the suggestion.
I thought about it, but I recalled that tglx had __strong opinions
on __weak functions.
Alternatively, you can add a Kconfig symbol to virt/kvm/Kconfig and
select it from arch/x86/kvm.
Paolo
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Add KVM suspend/hibernate PM-notifier which lets architectures
to implement arch-specific VM suspend code. For instance, on x86
this sets PVCLOCK_GUEST_STOPPED on all the VCPUs.
Our case is that user puts the host system into sleep multiple
times a day (e.g. closes the laptop's lid) so we need a reliable
way to suspend VMs properly.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
arch/arm64/kvm/arm.c | 4 ++++
arch/mips/kvm/mips.c | 4 ++++
arch/powerpc/kvm/powerpc.c | 4 ++++
arch/s390/kvm/kvm-s390.c | 4 ++++
arch/x86/kvm/x86.c | 21 ++++++++++++++++++++
include/linux/kvm_host.h | 8 ++++++++
virt/kvm/kvm_main.c | 40 ++++++++++++++++++++++++++++++++++++++
7 files changed, 85 insertions(+)
@@ -962,6 +1000,7 @@ static struct kvm *kvm_create_vm(unsigned long type)mutex_unlock(&kvm_lock);preempt_notifier_inc();+kvm_init_pm_notifier(kvm);
You've probably thought it through and I didn't but wouldn't it be
easier to have one global pm_notifier call for KVM which would go
through the list of VMs instead of registering/deregistering a
pm_notifier call for every created/destroyed VM?
You've probably thought it through and I didn't but wouldn't it be
easier to have one global pm_notifier call for KVM which would go
through the list of VMs instead of registering/deregistering a
pm_notifier call for every created/destroyed VM?
That raises questions on the locking, i.e. if we can we take the
kvm_lock safely from the notifier.
Paolo
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-06-04 08:47:02
On Thu, 03 Jun 2021 17:43:15 +0100,
Sergey Senozhatsky [off-list ref] wrote:
quoted hunk
Add KVM suspend/hibernate PM-notifier which lets architectures
to implement arch-specific VM suspend code. For instance, on x86
this sets PVCLOCK_GUEST_STOPPED on all the VCPUs.
Our case is that user puts the host system into sleep multiple
times a day (e.g. closes the laptop's lid) so we need a reliable
way to suspend VMs properly.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
arch/arm64/kvm/arm.c | 4 ++++
arch/mips/kvm/mips.c | 4 ++++
arch/powerpc/kvm/powerpc.c | 4 ++++
arch/s390/kvm/kvm-s390.c | 4 ++++
arch/x86/kvm/x86.c | 21 ++++++++++++++++++++
include/linux/kvm_host.h | 8 ++++++++
virt/kvm/kvm_main.c | 40 ++++++++++++++++++++++++++++++++++++++
7 files changed, 85 insertions(+)
I'd certainly like to be able to opt out from this on architectures
that do not implement anything useful in the PM callbacks. Please
consider making this an independent config option that individual
archs can buy into.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
I'd certainly like to be able to opt out from this on architectures
that do not implement anything useful in the PM callbacks.
Well on the other hand PM-callbacks are harmless on those archs, they
won't overload the __weak function.
Please consider making this an independent config option that individual
archs can buy into.
Sure, I can take a look into this, but how is this better than __weak
function? (that's a real question)
[..]
quoted
+#ifdef CONFIG_PM
+static int kvm_pm_notifier_call(struct notifier_block *bl,
+ unsigned long state,
+ void *unused)
+{
+ struct kvm *kvm = container_of(bl, struct kvm, pm_notifier);
+
+ switch (state) {
+ case PM_HIBERNATION_PREPARE:
+ case PM_SUSPEND_PREPARE:
+ kvm_arch_pm_notifier(kvm);
How about passing the state to the notifier callback? I'd expect it to
be useful to do something on resume too.
For different states we can have different kvm_arch functions instead.
kvm_arch_pm_notifier() can be renamed to kvm_arch_suspend_notifier(),
so that we don't need to have `switch (state)` in every arch-code. Then
for resume/post resume states we can have kvm_arch_resume_notifier()
arch functions.
Nothing magical here. I want this to be executed first, before we suspend
ftrace, RCU and the like. Besides KVM is usually the last one to register
its PM callbacks, so there can be something on the notifier list that
returns NOTIFY_STOP_MASK in front of KVM PM-notifier list entry.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
You've probably thought it through and I didn't but wouldn't it be
easier to have one global pm_notifier call for KVM which would go
through the list of VMs instead of registering/deregistering a
pm_notifier call for every created/destroyed VM?
That raises questions on the locking, i.e. if we can we take the kvm_lock
safely from the notifier.
Right, I wanted to take the VM lock, rather than subsystem lock
(kvm_lock).
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
I'd certainly like to be able to opt out from this on architectures
that do not implement anything useful in the PM callbacks.
Well on the other hand PM-callbacks are harmless on those archs, they
won't overload the __weak function.
I don't care much for the callbacks. But struct kvm is bloated enough,
and I'd be happy not to have this structure embedded in it if I can
avoid it.
quoted
Please consider making this an independent config option that individual
archs can buy into.
Sure, I can take a look into this, but how is this better than __weak
function? (that's a real question)
Weak functions are OK AFAIC. More crud in struct kvm is what I'm not
OK with.
[..]
quoted
quoted
+#ifdef CONFIG_PM
+static int kvm_pm_notifier_call(struct notifier_block *bl,
+ unsigned long state,
+ void *unused)
+{
+ struct kvm *kvm = container_of(bl, struct kvm, pm_notifier);
+
+ switch (state) {
+ case PM_HIBERNATION_PREPARE:
+ case PM_SUSPEND_PREPARE:
+ kvm_arch_pm_notifier(kvm);
How about passing the state to the notifier callback? I'd expect it to
be useful to do something on resume too.
For different states we can have different kvm_arch functions instead.
kvm_arch_pm_notifier() can be renamed to kvm_arch_suspend_notifier(),
so that we don't need to have `switch (state)` in every arch-code. Then
for resume/post resume states we can have kvm_arch_resume_notifier()
arch functions.
I'd rather we keep an arch API that is similar to the one the rest of
the kernel has, instead of a flurry of small helpers that need to grow
each time someone adds a new PM state. A switch() in the arch-specific
implementation is absolutely fine.
Nothing magical here. I want this to be executed first, before we suspend
ftrace, RCU and the like. Besides KVM is usually the last one to register
its PM callbacks, so there can be something on the notifier list that
returns NOTIFY_STOP_MASK in front of KVM PM-notifier list entry.
Which begs the question: should arch-specific code be able to veto
suspend and return an error itself? Always returning NOTIFY_DONE seems
highly optimistic.
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Well on the other hand PM-callbacks are harmless on those archs, they
won't overload the __weak function.
I don't care much for the callbacks. But struct kvm is bloated enough,
and I'd be happy not to have this structure embedded in it if I can
avoid it.
Got it.
quoted
quoted
How about passing the state to the notifier callback? I'd expect it to
be useful to do something on resume too.
For different states we can have different kvm_arch functions instead.
kvm_arch_pm_notifier() can be renamed to kvm_arch_suspend_notifier(),
so that we don't need to have `switch (state)` in every arch-code. Then
for resume/post resume states we can have kvm_arch_resume_notifier()
arch functions.
I'd rather we keep an arch API that is similar to the one the rest of
the kernel has, instead of a flurry of small helpers that need to grow
each time someone adds a new PM state. A switch() in the arch-specific
implementation is absolutely fine.