Re: [patch 2/3] KVM: rename KVM_REQ_PENDING_TIMER to KVM_REQ_UNBLOCK

Marcelo Tosatti
2021-05-25T19:26:56Z

On Tue, May 25, 2021 at 03:14:33PM -0400, Peter Xu wrote:
> On Tue, May 25, 2021 at 10:41:17AM -0300, Marcelo Tosatti wrote:
> > KVM_REQ_UNBLOCK will be used to exit a vcpu from
> > its inner vcpu halt emulation loop.
> >
> > Rename KVM_REQ_PENDING_TIMER to KVM_REQ_UNBLOCK, switch
> > PowerPC to arch specific request bit.
> >
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> >
> > Index: kvm/include/linux/kvm_host.h
> > ===================================================================
> > --- kvm.orig/include/linux/kvm_host.h
> > +++ kvm/include/linux/kvm_host.h
> > @@ -146,7 +146,7 @@ static inline bool is_error_page(struct
> > */
> > #define KVM_REQ_TLB_FLUSH (0 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
> > #define KVM_REQ_MMU_RELOAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
> > -#define KVM_REQ_PENDING_TIMER 2
> > +#define KVM_REQ_UNBLOCK 2
> > #define KVM_REQ_UNHALT 3
> > #define KVM_REQUEST_ARCH_BASE 8
> >
> > Index: kvm/virt/kvm/kvm_main.c
> > ===================================================================
> > --- kvm.orig/virt/kvm/kvm_main.c
> > +++ kvm/virt/kvm/kvm_main.c
> > @@ -2794,6 +2794,8 @@ static int kvm_vcpu_check_block(struct k
> > goto out;
> > if (signal_pending(current))
> > goto out;
> > + if (kvm_check_request(KVM_REQ_UNBLOCK, vcpu))
> > + goto out;
> >
> > ret = 0;
> > out:
> > Index: kvm/Documentation/virt/kvm/vcpu-requests.rst
> > ===================================================================
> > --- kvm.orig/Documentation/virt/kvm/vcpu-requests.rst
> > +++ kvm/Documentation/virt/kvm/vcpu-requests.rst
> > @@ -118,10 +118,11 @@ KVM_REQ_MMU_RELOAD
> > necessary to inform each VCPU to completely refresh the tables. This
> > request is used for that.
> >
> > -KVM_REQ_PENDING_TIMER
> > +KVM_REQ_UNBLOCK
> >
> > This request may be made from a timer handler run on the host on behalf
> > - of a VCPU. It informs the VCPU thread to inject a timer interrupt.
> > + of a VCPU, or when device assignment is performed. It informs the VCPU to
> > + exit the vcpu halt inner loop.
> >
> > KVM_REQ_UNHALT
> >
> > Index: kvm/arch/powerpc/include/asm/kvm_host.h
> > ===================================================================
> > --- kvm.orig/arch/powerpc/include/asm/kvm_host.h
> > +++ kvm/arch/powerpc/include/asm/kvm_host.h
> > @@ -51,6 +51,7 @@
> > /* PPC-specific vcpu->requests bit members */
> > #define KVM_REQ_WATCHDOG KVM_ARCH_REQ(0)
> > #define KVM_REQ_EPR_EXIT KVM_ARCH_REQ(1)
> > +#define KVM_REQ_PENDING_TIMER KVM_ARCH_REQ(2)
> >
> > #include <linux/mmu_notifier.h>
> >
> > Index: kvm/arch/x86/kvm/lapic.c
> > ===================================================================
> > --- kvm.orig/arch/x86/kvm/lapic.c
> > +++ kvm/arch/x86/kvm/lapic.c
> > @@ -1657,7 +1657,7 @@ static void apic_timer_expired(struct kv
> > }
> >
> > atomic_inc(&apic->lapic_timer.pending);
> > - kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
> > + kvm_make_request(KVM_REQ_UNBLOCK, vcpu);
> > if (from_timer_fn)
> > kvm_vcpu_kick(vcpu);
> > }
>
> Pure question on the existing code: why do we need kvm_make_request() for
> timer? As I see kvm_vcpu_check_block() already checks explicitly for timers:
>
> static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu)
> {
> ...
> if (kvm_cpu_has_pending_timer(vcpu))
> goto out;
> ...
> }
>
> for x86:
>
> int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
> {
> if (lapic_in_kernel(vcpu))
> return apic_has_pending_timer(vcpu);
>
> return 0;
> }
>
> So wondering why we can drop the two references to KVM_REQ_PENDING_TIMER in x86
> directly..

See commit 06e05645661211b9eaadaf6344c335d2e80f0ba2