linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN
@ 2020-09-11  9:31 Vitaly Kuznetsov
  2020-09-11 16:04 ` Sean Christopherson
  2020-09-11 17:25 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-09-11  9:31 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson,
	Dr . David Alan Gilbert, linux-kernel

Even without in-kernel LAPIC we should allow writing '0' to
MSR_KVM_ASYNC_PF_EN as we're not enabling the mechanism. In
particular, QEMU with 'kernel-irqchip=off' fails to start
a guest with

qemu-system-x86_64: error: failed to set MSR 0x4b564d02 to 0x0

Fixes: 9d3c447c72fb2 ("KVM: X86: Fix async pf caused null-ptr-deref")
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d39d6cf1d473..44a86f7f2397 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2730,9 +2730,6 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
 	if (data & 0x30)
 		return 1;
 
-	if (!lapic_in_kernel(vcpu))
-		return 1;
-
 	vcpu->arch.apf.msr_en_val = data;
 
 	if (!kvm_pv_async_pf_enabled(vcpu)) {
@@ -2741,6 +2738,9 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
 		return 0;
 	}
 
+	if (!lapic_in_kernel(vcpu))
+		return 1;
+
 	if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa,
 					sizeof(u64)))
 		return 1;
-- 
2.25.4


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

* Re: [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN
  2020-09-11  9:31 [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN Vitaly Kuznetsov
@ 2020-09-11 16:04 ` Sean Christopherson
  2020-09-11 17:27   ` Paolo Bonzini
  2020-09-11 17:25 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2020-09-11 16:04 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: kvm, Paolo Bonzini, Wanpeng Li, Jim Mattson,
	Dr . David Alan Gilbert, linux-kernel

On Fri, Sep 11, 2020 at 11:31:47AM +0200, Vitaly Kuznetsov wrote:
> Even without in-kernel LAPIC we should allow writing '0' to
> MSR_KVM_ASYNC_PF_EN as we're not enabling the mechanism. In
> particular, QEMU with 'kernel-irqchip=off' fails to start
> a guest with
> 
> qemu-system-x86_64: error: failed to set MSR 0x4b564d02 to 0x0
> 
> Fixes: 9d3c447c72fb2 ("KVM: X86: Fix async pf caused null-ptr-deref")
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d39d6cf1d473..44a86f7f2397 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2730,9 +2730,6 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
>  	if (data & 0x30)
>  		return 1;
>  
> -	if (!lapic_in_kernel(vcpu))
> -		return 1;
> -
>  	vcpu->arch.apf.msr_en_val = data;
>  
>  	if (!kvm_pv_async_pf_enabled(vcpu)) {
> @@ -2741,6 +2738,9 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
>  		return 0;
>  	}
>  
> +	if (!lapic_in_kernel(vcpu))

This doesn't actually verify that @data == 0.  kvm_pv_async_pf_enabled()
returns true iff KVM_ASYNC_PF_ENABLED and KVM_ASYNC_PF_DELIVERY_AS_INT are
set, e.g. this would allow setting one and not the other.  This also allows
userspace to set vcpu->arch.apf.msr_en_val to an unsupported value, i.e.
@data has already been propagated to the vcpu and isn't unwound.

Why not just pivot on @data when lapic_in_kernel() is false?  vcpu->arch.apic
is immutable so there's no need to update apf.msr_en_val in either direction.

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 539ea1cd6020..36969d5ec291 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2735,7 +2735,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
                return 1;

        if (!lapic_in_kernel(vcpu))
-               return 1;
+               return data ? 1 : 0;

        vcpu->arch.apf.msr_en_val = data;


> +		return 1;
> +
>  	if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa,
>  					sizeof(u64)))
>  		return 1;
> -- 
> 2.25.4
> 

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

* Re: [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN
  2020-09-11  9:31 [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN Vitaly Kuznetsov
  2020-09-11 16:04 ` Sean Christopherson
@ 2020-09-11 17:25 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-09-11 17:25 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson,
	Dr . David Alan Gilbert, linux-kernel

On 11/09/20 11:31, Vitaly Kuznetsov wrote:
> Even without in-kernel LAPIC we should allow writing '0' to
> MSR_KVM_ASYNC_PF_EN as we're not enabling the mechanism. In
> particular, QEMU with 'kernel-irqchip=off' fails to start
> a guest with
> 
> qemu-system-x86_64: error: failed to set MSR 0x4b564d02 to 0x0
> 
> Fixes: 9d3c447c72fb2 ("KVM: X86: Fix async pf caused null-ptr-deref")
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d39d6cf1d473..44a86f7f2397 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2730,9 +2730,6 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
>  	if (data & 0x30)
>  		return 1;
>  
> -	if (!lapic_in_kernel(vcpu))
> -		return 1;
> -
>  	vcpu->arch.apf.msr_en_val = data;
>  
>  	if (!kvm_pv_async_pf_enabled(vcpu)) {
> @@ -2741,6 +2738,9 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
>  		return 0;
>  	}
>  
> +	if (!lapic_in_kernel(vcpu))
> +		return 1;
> +
>  	if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa,
>  					sizeof(u64)))
>  		return 1;
> 

Queued, thanks.

Paolo


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

* Re: [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN
  2020-09-11 16:04 ` Sean Christopherson
@ 2020-09-11 17:27   ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-09-11 17:27 UTC (permalink / raw)
  To: Sean Christopherson, Vitaly Kuznetsov
  Cc: kvm, Wanpeng Li, Jim Mattson, Dr . David Alan Gilbert, linux-kernel

On 11/09/20 18:04, Sean Christopherson wrote:

> This doesn't actually verify that @data == 0.  kvm_pv_async_pf_enabled()
> returns true iff KVM_ASYNC_PF_ENABLED and KVM_ASYNC_PF_DELIVERY_AS_INT are
> set, e.g. this would allow setting one and not the other.  This also allows
> userspace to set vcpu->arch.apf.msr_en_val to an unsupported value, i.e.
> @data has already been propagated to the vcpu and isn't unwound.
> 
> Why not just pivot on @data when lapic_in_kernel() is false?  vcpu->arch.apic
> is immutable so there's no need to update apf.msr_en_val in either direction.
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 539ea1cd6020..36969d5ec291 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2735,7 +2735,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
>                 return 1;
> 
>         if (!lapic_in_kernel(vcpu))
> -               return 1;
> +               return data ? 1 : 0;
> 
>         vcpu->arch.apf.msr_en_val = data;
> 
> 
>> +		return 1;
>> +
>>  	if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa,
>>  					sizeof(u64)))
>>  		return 1;
>> -- 
>> 2.25.4
>>
> 

Committed this instead, though.

Paolo


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

end of thread, other threads:[~2020-09-11 17:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11  9:31 [PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN Vitaly Kuznetsov
2020-09-11 16:04 ` Sean Christopherson
2020-09-11 17:27   ` Paolo Bonzini
2020-09-11 17:25 ` Paolo Bonzini

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).