kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: ensure APICv is considered inactive if there is no APIC
@ 2021-11-30 12:37 Paolo Bonzini
  2021-11-30 13:05 ` Ignat Korchagin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paolo Bonzini @ 2021-11-30 12:37 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: Ignat Korchagin

kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel
local APIC, however kvm_apicv_activated might still be true if there are
no reasons to disable APICv; in fact it is quite likely that there is none
because APICv is inhibited by specific configurations of the local APIC
and those configurations cannot be programmed.  This triggers a WARN:

   WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu));

To avoid this, introduce another cause for APICv inhibition, namely the
absence of an in-kernel local APIC.  This cause is enabled by default,
and is dropped by either KVM_CREATE_IRQCHIP or the enabling of
KVM_CAP_IRQCHIP_SPLIT.

Reported-by: Ignat Korchagin <ignat@cloudflare.com>
Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/svm/avic.c         | 1 +
 arch/x86/kvm/vmx/vmx.c          | 1 +
 arch/x86/kvm/x86.c              | 9 +++++----
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 6ac61f85e07b..860ed500580c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1036,6 +1036,7 @@ struct kvm_x86_msr_filter {
 #define APICV_INHIBIT_REASON_PIT_REINJ  4
 #define APICV_INHIBIT_REASON_X2APIC	5
 #define APICV_INHIBIT_REASON_BLOCKIRQ	6
+#define APICV_INHIBIT_REASON_ABSENT	7
 
 struct kvm_arch {
 	unsigned long n_used_mmu_pages;
diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index affc0ea98d30..5a55a78e2f50 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -900,6 +900,7 @@ int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq,
 bool svm_check_apicv_inhibit_reasons(ulong bit)
 {
 	ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
+			  BIT(APICV_INHIBIT_REASON_ABSENT) |
 			  BIT(APICV_INHIBIT_REASON_HYPERV) |
 			  BIT(APICV_INHIBIT_REASON_NESTED) |
 			  BIT(APICV_INHIBIT_REASON_IRQWIN) |
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 1fadec8cbf96..ca1fd93c1dc9 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7525,6 +7525,7 @@ static void hardware_unsetup(void)
 static bool vmx_check_apicv_inhibit_reasons(ulong bit)
 {
 	ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
+			  BIT(APICV_INHIBIT_REASON_ABSENT) |
 			  BIT(APICV_INHIBIT_REASON_HYPERV) |
 			  BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0ee1a039b490..e0aa4dd53c7f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
 		smp_wmb();
 		kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
 		kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
+		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
 		r = 0;
 split_irqchip_unlock:
 		mutex_unlock(&kvm->lock);
@@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		/* Write kvm->irq_routing before enabling irqchip_in_kernel. */
 		smp_wmb();
 		kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
+		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
 	create_irqchip_unlock:
 		mutex_unlock(&kvm->lock);
 		break;
@@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm)
 {
 	init_rwsem(&kvm->arch.apicv_update_lock);
 
-	if (enable_apicv)
-		clear_bit(APICV_INHIBIT_REASON_DISABLE,
-			  &kvm->arch.apicv_inhibit_reasons);
-	else
+	set_bit(APICV_INHIBIT_REASON_ABSENT,
+		&kvm->arch.apicv_inhibit_reasons);
+	if (!enable_apicv)
 		set_bit(APICV_INHIBIT_REASON_DISABLE,
 			&kvm->arch.apicv_inhibit_reasons);
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: ensure APICv is considered inactive if there is no APIC
  2021-11-30 12:37 [PATCH] KVM: ensure APICv is considered inactive if there is no APIC Paolo Bonzini
@ 2021-11-30 13:05 ` Ignat Korchagin
  2021-11-30 20:39 ` Sean Christopherson
  2021-12-03  2:17 ` Wanpeng Li
  2 siblings, 0 replies; 5+ messages in thread
From: Ignat Korchagin @ 2021-11-30 13:05 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm

On Tue, Nov 30, 2021 at 12:37 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel
> local APIC, however kvm_apicv_activated might still be true if there are
> no reasons to disable APICv; in fact it is quite likely that there is none
> because APICv is inhibited by specific configurations of the local APIC
> and those configurations cannot be programmed.  This triggers a WARN:
>
>    WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu));
>
> To avoid this, introduce another cause for APICv inhibition, namely the
> absence of an in-kernel local APIC.  This cause is enabled by default,
> and is dropped by either KVM_CREATE_IRQCHIP or the enabling of
> KVM_CAP_IRQCHIP_SPLIT.
>
> Reported-by: Ignat Korchagin <ignat@cloudflare.com>
> Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22)
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/include/asm/kvm_host.h | 1 +
>  arch/x86/kvm/svm/avic.c         | 1 +
>  arch/x86/kvm/vmx/vmx.c          | 1 +
>  arch/x86/kvm/x86.c              | 9 +++++----
>  4 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 6ac61f85e07b..860ed500580c 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1036,6 +1036,7 @@ struct kvm_x86_msr_filter {
>  #define APICV_INHIBIT_REASON_PIT_REINJ  4
>  #define APICV_INHIBIT_REASON_X2APIC    5
>  #define APICV_INHIBIT_REASON_BLOCKIRQ  6
> +#define APICV_INHIBIT_REASON_ABSENT    7
>
>  struct kvm_arch {
>         unsigned long n_used_mmu_pages;
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index affc0ea98d30..5a55a78e2f50 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -900,6 +900,7 @@ int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq,
>  bool svm_check_apicv_inhibit_reasons(ulong bit)
>  {
>         ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
> +                         BIT(APICV_INHIBIT_REASON_ABSENT) |
>                           BIT(APICV_INHIBIT_REASON_HYPERV) |
>                           BIT(APICV_INHIBIT_REASON_NESTED) |
>                           BIT(APICV_INHIBIT_REASON_IRQWIN) |
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1fadec8cbf96..ca1fd93c1dc9 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -7525,6 +7525,7 @@ static void hardware_unsetup(void)
>  static bool vmx_check_apicv_inhibit_reasons(ulong bit)
>  {
>         ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
> +                         BIT(APICV_INHIBIT_REASON_ABSENT) |
>                           BIT(APICV_INHIBIT_REASON_HYPERV) |
>                           BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0ee1a039b490..e0aa4dd53c7f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>                 smp_wmb();
>                 kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
>                 kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
> +               kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
>                 r = 0;
>  split_irqchip_unlock:
>                 mutex_unlock(&kvm->lock);
> @@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
>                 /* Write kvm->irq_routing before enabling irqchip_in_kernel. */
>                 smp_wmb();
>                 kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
> +               kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
>         create_irqchip_unlock:
>                 mutex_unlock(&kvm->lock);
>                 break;
> @@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm)
>  {
>         init_rwsem(&kvm->arch.apicv_update_lock);
>
> -       if (enable_apicv)
> -               clear_bit(APICV_INHIBIT_REASON_DISABLE,
> -                         &kvm->arch.apicv_inhibit_reasons);
> -       else
> +       set_bit(APICV_INHIBIT_REASON_ABSENT,
> +               &kvm->arch.apicv_inhibit_reasons);
> +       if (!enable_apicv)
>                 set_bit(APICV_INHIBIT_REASON_DISABLE,
>                         &kvm->arch.apicv_inhibit_reasons);
>  }
> --
> 2.31.1
>

Tested-by: Ignat Korchagin <ignat@cloudflare.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: ensure APICv is considered inactive if there is no APIC
  2021-11-30 12:37 [PATCH] KVM: ensure APICv is considered inactive if there is no APIC Paolo Bonzini
  2021-11-30 13:05 ` Ignat Korchagin
@ 2021-11-30 20:39 ` Sean Christopherson
  2021-11-30 21:08   ` Maxim Levitsky
  2021-12-03  2:17 ` Wanpeng Li
  2 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2021-11-30 20:39 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, Ignat Korchagin

On Tue, Nov 30, 2021, Paolo Bonzini wrote:
> kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel
> local APIC, however kvm_apicv_activated might still be true if there are
> no reasons to disable APICv; in fact it is quite likely that there is none
> because APICv is inhibited by specific configurations of the local APIC
> and those configurations cannot be programmed.  This triggers a WARN:
> 
>    WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu));
> 
> To avoid this, introduce another cause for APICv inhibition, namely the
> absence of an in-kernel local APIC.  This cause is enabled by default,
> and is dropped by either KVM_CREATE_IRQCHIP or the enabling of
> KVM_CAP_IRQCHIP_SPLIT.
> 
> Reported-by: Ignat Korchagin <ignat@cloudflare.com>
> Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22)
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0ee1a039b490..e0aa4dd53c7f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>  		smp_wmb();
>  		kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
>  		kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
> +		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
>  		r = 0;
>  split_irqchip_unlock:
>  		mutex_unlock(&kvm->lock);
> @@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
>  		/* Write kvm->irq_routing before enabling irqchip_in_kernel. */
>  		smp_wmb();
>  		kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
> +		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);

Blech, kvm_request_apicv_update() is very counter-intuitive, true == clear. :-/
Wrappers along the lines of kvm_{set,clear}_apicv_inhibit() would help a lot, and
would likely avoid a handful of newlines as well.  I'll send a patch on top of this,
unless you want to do it while pushing this one out.

>  	create_irqchip_unlock:
>  		mutex_unlock(&kvm->lock);
>  		break;
> @@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm)
>  {
>  	init_rwsem(&kvm->arch.apicv_update_lock);
>  
> -	if (enable_apicv)
> -		clear_bit(APICV_INHIBIT_REASON_DISABLE,
> -			  &kvm->arch.apicv_inhibit_reasons);
> -	else
> +	set_bit(APICV_INHIBIT_REASON_ABSENT,
> +		&kvm->arch.apicv_inhibit_reasons);

Nit, this one fits on a single line.

> +	if (!enable_apicv)
>  		set_bit(APICV_INHIBIT_REASON_DISABLE,
>  			&kvm->arch.apicv_inhibit_reasons);
>  }
> -- 
> 2.31.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: ensure APICv is considered inactive if there is no APIC
  2021-11-30 20:39 ` Sean Christopherson
@ 2021-11-30 21:08   ` Maxim Levitsky
  0 siblings, 0 replies; 5+ messages in thread
From: Maxim Levitsky @ 2021-11-30 21:08 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: linux-kernel, kvm, Ignat Korchagin

On Tue, 2021-11-30 at 20:39 +0000, Sean Christopherson wrote:
> On Tue, Nov 30, 2021, Paolo Bonzini wrote:
> > kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel
> > local APIC, however kvm_apicv_activated might still be true if there are
> > no reasons to disable APICv; in fact it is quite likely that there is none
> > because APICv is inhibited by specific configurations of the local APIC
> > and those configurations cannot be programmed.  This triggers a WARN:
> > 
> >    WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu));
> > 
> > To avoid this, introduce another cause for APICv inhibition, namely the
> > absence of an in-kernel local APIC.  This cause is enabled by default,
> > and is dropped by either KVM_CREATE_IRQCHIP or the enabling of
> > KVM_CAP_IRQCHIP_SPLIT.
> > 
> > Reported-by: Ignat Korchagin <ignat@cloudflare.com>
> > Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22)
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>
> 
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 0ee1a039b490..e0aa4dd53c7f 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> >  		smp_wmb();
> >  		kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
> >  		kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
> > +		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
> >  		r = 0;
> >  split_irqchip_unlock:
> >  		mutex_unlock(&kvm->lock);
> > @@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
> >  		/* Write kvm->irq_routing before enabling irqchip_in_kernel. */
> >  		smp_wmb();
> >  		kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
> > +		kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
> 
> Blech, kvm_request_apicv_update() is very counter-intuitive, true == clear. :-/
> Wrappers along the lines of kvm_{set,clear}_apicv_inhibit() would help a lot, and
> would likely avoid a handful of newlines as well.  I'll send a patch on top of this,
> unless you want to do it while pushing this one out.

100% agree that kvm_request_apicv_update() is very counter-intuitive!

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

Best regards,
	Maxim Levitsky

> 
> >  	create_irqchip_unlock:
> >  		mutex_unlock(&kvm->lock);
> >  		break;
> > @@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm)
> >  {
> >  	init_rwsem(&kvm->arch.apicv_update_lock);
> >  
> > -	if (enable_apicv)
> > -		clear_bit(APICV_INHIBIT_REASON_DISABLE,
> > -			  &kvm->arch.apicv_inhibit_reasons);
> > -	else
> > +	set_bit(APICV_INHIBIT_REASON_ABSENT,
> > +		&kvm->arch.apicv_inhibit_reasons);
> 
> Nit, this one fits on a single line.
> 
> > +	if (!enable_apicv)
> >  		set_bit(APICV_INHIBIT_REASON_DISABLE,
> >  			&kvm->arch.apicv_inhibit_reasons);
> >  }
> > -- 
> > 2.31.1
> > 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: ensure APICv is considered inactive if there is no APIC
  2021-11-30 12:37 [PATCH] KVM: ensure APICv is considered inactive if there is no APIC Paolo Bonzini
  2021-11-30 13:05 ` Ignat Korchagin
  2021-11-30 20:39 ` Sean Christopherson
@ 2021-12-03  2:17 ` Wanpeng Li
  2 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2021-12-03  2:17 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: LKML, kvm, Ignat Korchagin

On Wed, 1 Dec 2021 at 12:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel
> local APIC, however kvm_apicv_activated might still be true if there are
> no reasons to disable APICv; in fact it is quite likely that there is none
> because APICv is inhibited by specific configurations of the local APIC
> and those configurations cannot be programmed.  This triggers a WARN:
>
>    WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu));
>
> To avoid this, introduce another cause for APICv inhibition, namely the
> absence of an in-kernel local APIC.  This cause is enabled by default,
> and is dropped by either KVM_CREATE_IRQCHIP or the enabling of
> KVM_CAP_IRQCHIP_SPLIT.
>
> Reported-by: Ignat Korchagin <ignat@cloudflare.com>
> Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22)
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Wanpeng Li <wanpengli@tencent.com>

> ---
>  arch/x86/include/asm/kvm_host.h | 1 +
>  arch/x86/kvm/svm/avic.c         | 1 +
>  arch/x86/kvm/vmx/vmx.c          | 1 +
>  arch/x86/kvm/x86.c              | 9 +++++----
>  4 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 6ac61f85e07b..860ed500580c 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1036,6 +1036,7 @@ struct kvm_x86_msr_filter {
>  #define APICV_INHIBIT_REASON_PIT_REINJ  4
>  #define APICV_INHIBIT_REASON_X2APIC    5
>  #define APICV_INHIBIT_REASON_BLOCKIRQ  6
> +#define APICV_INHIBIT_REASON_ABSENT    7
>
>  struct kvm_arch {
>         unsigned long n_used_mmu_pages;
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index affc0ea98d30..5a55a78e2f50 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -900,6 +900,7 @@ int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq,
>  bool svm_check_apicv_inhibit_reasons(ulong bit)
>  {
>         ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
> +                         BIT(APICV_INHIBIT_REASON_ABSENT) |
>                           BIT(APICV_INHIBIT_REASON_HYPERV) |
>                           BIT(APICV_INHIBIT_REASON_NESTED) |
>                           BIT(APICV_INHIBIT_REASON_IRQWIN) |
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1fadec8cbf96..ca1fd93c1dc9 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -7525,6 +7525,7 @@ static void hardware_unsetup(void)
>  static bool vmx_check_apicv_inhibit_reasons(ulong bit)
>  {
>         ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
> +                         BIT(APICV_INHIBIT_REASON_ABSENT) |
>                           BIT(APICV_INHIBIT_REASON_HYPERV) |
>                           BIT(APICV_INHIBIT_REASON_BLOCKIRQ);
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0ee1a039b490..e0aa4dd53c7f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>                 smp_wmb();
>                 kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
>                 kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
> +               kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
>                 r = 0;
>  split_irqchip_unlock:
>                 mutex_unlock(&kvm->lock);
> @@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
>                 /* Write kvm->irq_routing before enabling irqchip_in_kernel. */
>                 smp_wmb();
>                 kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
> +               kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
>         create_irqchip_unlock:
>                 mutex_unlock(&kvm->lock);
>                 break;
> @@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm)
>  {
>         init_rwsem(&kvm->arch.apicv_update_lock);
>
> -       if (enable_apicv)
> -               clear_bit(APICV_INHIBIT_REASON_DISABLE,
> -                         &kvm->arch.apicv_inhibit_reasons);
> -       else
> +       set_bit(APICV_INHIBIT_REASON_ABSENT,
> +               &kvm->arch.apicv_inhibit_reasons);
> +       if (!enable_apicv)
>                 set_bit(APICV_INHIBIT_REASON_DISABLE,
>                         &kvm->arch.apicv_inhibit_reasons);
>  }
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-03  2:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 12:37 [PATCH] KVM: ensure APICv is considered inactive if there is no APIC Paolo Bonzini
2021-11-30 13:05 ` Ignat Korchagin
2021-11-30 20:39 ` Sean Christopherson
2021-11-30 21:08   ` Maxim Levitsky
2021-12-03  2:17 ` Wanpeng Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).