Re: [PATCH] kvm/x86 : Remove redundant pic_in_kernel

From: Paolo Bonzini
Date: Mon May 11 2020 - 09:50:33 EST


On 11/05/20 13:21, 彭浩(Richard) wrote:
> pic_in_kernel() and irqchip_kernel() have the same implementation.
>
> Signed-off-by: Peng Hao <richard.peng@xxxxxxxx>

Thanks for the patch, this is interesting! And there is also
ioapic_in_kernel. However, the three functions are used in different
cases, for example ioapic_in_kernel before accessing kvm->arch.vioapic.
So the right thing to do would be to keep the functions, but change
them to just return irqchip_kernel(kvm).

Paolo

> ---
> arch/x86/kvm/irq.h | 9 ---------
> arch/x86/kvm/x86.c | 6 +++---
> 2 files changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h
> index f173ab6..3ad07ca 100644
> --- a/arch/x86/kvm/irq.h
> +++ b/arch/x86/kvm/irq.h
> @@ -66,15 +66,6 @@ void kvm_pic_destroy(struct kvm *kvm);
> int kvm_pic_read_irq(struct kvm *kvm);
> void kvm_pic_update_irq(struct kvm_pic *s);
>
> -static inline int pic_in_kernel(struct kvm *kvm)
> -{
> -int mode = kvm->arch.irqchip_mode;
> -
> -/* Matches smp_wmb() when setting irqchip_mode */
> -smp_rmb();
> -return mode == KVM_IRQCHIP_KERNEL;
> -}
> -
> static inline int irqchip_split(struct kvm *kvm)
> {
> int mode = kvm->arch.irqchip_mode;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d786c7d..559053f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3710,7 +3710,7 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
> * With in-kernel LAPIC, we only use this to inject EXTINT, so
> * fail for in-kernel 8259.
> */
> -if (pic_in_kernel(vcpu->kvm))
> +if (irqchip_kernel(vcpu->kvm))
> return -ENXIO;
>
> if (vcpu->arch.pending_external_vector != -1)
> @@ -7622,7 +7622,7 @@ static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt)
> static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu)
> {
> return vcpu->run->request_interrupt_window &&
> -likely(!pic_in_kernel(vcpu->kvm));
> +likely(!irqchip_kernel(vcpu->kvm));
> }
>
> static void post_kvm_run_save(struct kvm_vcpu *vcpu)
> @@ -7634,7 +7634,7 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu)
> kvm_run->cr8 = kvm_get_cr8(vcpu);
> kvm_run->apic_base = kvm_get_apic_base(vcpu);
> kvm_run->ready_for_interrupt_injection =
> -pic_in_kernel(vcpu->kvm) ||
> +irqchip_kernel(vcpu->kvm) ||
> kvm_vcpu_ready_for_interrupt_injection(vcpu);
> }
>
> --
> 2.7.4