[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABgObfby+9JNwrJnjPRp6pty05CqRUfKBA3AB=TNwq4q0KjBTg@mail.gmail.com>
Date: Wed, 30 Nov 2022 17:48:51 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Space Meyer <spm@...gle.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
kpsingh@...nel.org
Subject: Re: [PATCH] KVM: Deal with nested sleeps in kvm_vcpu_block()
On Wed, Nov 30, 2022 at 5:20 PM Space Meyer <spm@...gle.com> wrote:
> Previously this code assumed nothing would mess with current->state
> between the set_current_state() and schedule(). However the call to
> kvm_vcpu_check_block() in between might end up requiring locks or other
> actions, which would change current->state
This would be a bug (in particular kvm_arch_vcpu_runnable() and
kvm_cpu_has_pending_timer() should not need any lock). Do you
have a specific call stack in mind?
Paolo
>
> Signed-off-by: Space Meyer <spm@...gle.com>
> ---
> virt/kvm/kvm_main.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index fab4d37905785..64e10d73f2a92 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -32,6 +32,7 @@
> #include <linux/sched/signal.h>
> #include <linux/sched/mm.h>
> #include <linux/sched/stat.h>
> +#include <linux/wait.h>
> #include <linux/cpumask.h>
> #include <linux/smp.h>
> #include <linux/anon_inodes.h>
> @@ -3426,6 +3427,7 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu)
> */
> bool kvm_vcpu_block(struct kvm_vcpu *vcpu)
> {
> + DEFINE_WAIT_FUNC(vcpu_block_wait, woken_wake_function);
> struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
> bool waited = false;
>
> @@ -3437,13 +3439,11 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu)
> preempt_enable();
>
> for (;;) {
> - set_current_state(TASK_INTERRUPTIBLE);
> -
> if (kvm_vcpu_check_block(vcpu) < 0)
> break;
>
> waited = true;
> - schedule();
> + wait_woken(&vcpu_block_wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
> }
>
> preempt_disable();
> --
> 2.38.1.584.g0f3c55d4c2-goog
>
Powered by blists - more mailing lists