Message ID | 20230526221712.317287-13-oliver.upton@linux.dev (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm64: Handle PSCI calls in userspace | expand |
Hi Oliver, I have a play with this series, the guest always hang when hotplug two more cpus, it seems the kvm_cpu_continue_vm forget to continue the current cpu. On 5/27/23 06:17, Oliver Upton wrote: > Pausing the VM from a vCPU thread is perilous with the current helpers, > as it waits indefinitely for a signal that never comes when invoked from > a vCPU thread. Instead, add a helper for pausing the VM from a vCPU, > working around the issue by explicitly marking the caller as paused > before proceeding. > > Signed-off-by: Oliver Upton <oliver.upton@linux.dev> > --- > include/kvm/kvm-cpu.h | 3 +++ > kvm-cpu.c | 15 +++++++++++++++ > 2 files changed, 18 insertions(+) > > diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h > index 0f16f8d6e872..9a4901bf94ca 100644 > --- a/include/kvm/kvm-cpu.h > +++ b/include/kvm/kvm-cpu.h > @@ -29,4 +29,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu); > void kvm_cpu__arch_nmi(struct kvm_cpu *cpu); > void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task); > > +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu); > +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu); > + > #endif /* KVM__KVM_CPU_H */ > diff --git a/kvm-cpu.c b/kvm-cpu.c > index 7dec08894cd3..9eb857b859c3 100644 > --- a/kvm-cpu.c > +++ b/kvm-cpu.c > @@ -141,6 +141,21 @@ void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task) > mutex_unlock(&task_lock); > } > > +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu) > +{ > + /* > + * Mark the calling vCPU as paused to avoid waiting indefinitely for a > + * signal exit. > + */ > + vcpu->paused = true; > + kvm__pause(vcpu->kvm); > +} > + > +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu) > +{ Here should add: vcpu->paused = false; > + kvm__continue(vcpu->kvm); > +} > + > int kvm_cpu__start(struct kvm_cpu *cpu) > { > sigset_t sigset;
Hi Shaoqin, On Fri, Jun 09, 2023 at 06:59:53PM +0800, Shaoqin Huang wrote: > Hi Oliver, > > I have a play with this series, the guest always hang when hotplug two more > cpus, it seems the kvm_cpu_continue_vm forget to continue the current cpu. Thanks for testing the series out. Heh, a bit of a silly bug on my part, sorry about that. > > +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu) > > +{ > > + /* > > + * Mark the calling vCPU as paused to avoid waiting indefinitely for a > > + * signal exit. > > + */ > > + vcpu->paused = true; > > + kvm__pause(vcpu->kvm); > > +} > > + > > +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu) > > +{ > Here should add: > vcpu->paused = false; > > + kvm__continue(vcpu->kvm); > > +} > > + LGTM, I'll stick this in v2. > > int kvm_cpu__start(struct kvm_cpu *cpu) > > { > > sigset_t sigset; > > -- > Shaoqin >
diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h index 0f16f8d6e872..9a4901bf94ca 100644 --- a/include/kvm/kvm-cpu.h +++ b/include/kvm/kvm-cpu.h @@ -29,4 +29,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu); void kvm_cpu__arch_nmi(struct kvm_cpu *cpu); void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task); +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu); +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu); + #endif /* KVM__KVM_CPU_H */ diff --git a/kvm-cpu.c b/kvm-cpu.c index 7dec08894cd3..9eb857b859c3 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -141,6 +141,21 @@ void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task) mutex_unlock(&task_lock); } +void kvm_cpu__pause_vm(struct kvm_cpu *vcpu) +{ + /* + * Mark the calling vCPU as paused to avoid waiting indefinitely for a + * signal exit. + */ + vcpu->paused = true; + kvm__pause(vcpu->kvm); +} + +void kvm_cpu__continue_vm(struct kvm_cpu *vcpu) +{ + kvm__continue(vcpu->kvm); +} + int kvm_cpu__start(struct kvm_cpu *cpu) { sigset_t sigset;
Pausing the VM from a vCPU thread is perilous with the current helpers, as it waits indefinitely for a signal that never comes when invoked from a vCPU thread. Instead, add a helper for pausing the VM from a vCPU, working around the issue by explicitly marking the caller as paused before proceeding. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> --- include/kvm/kvm-cpu.h | 3 +++ kvm-cpu.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)