kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL
@ 2020-01-27  6:04 Dan Carpenter
  2020-01-27  6:08 ` Dan Carpenter
  2020-01-27 18:12 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-01-27  6:04 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm

Hello Paolo Bonzini,

The patch e71ae535bc24: "KVM: x86: avoid incorrect writes to host
MSR_IA32_SPEC_CTRL" from Jan 20, 2020, leads to the following static
checker warning:

	arch/x86/kvm/vmx/vmx.c:2001 vmx_set_msr()
	warn: maybe use && instead of &

arch/x86/kvm/vmx/vmx.c
  1994                  vmx->msr_ia32_umwait_control = data;
  1995                  break;
  1996          case MSR_IA32_SPEC_CTRL:
  1997                  if (!msr_info->host_initiated &&
  1998                      !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
  1999                          return 1;
  2000  
  2001                  if (data & ~kvm_spec_ctrl_valid_bits(vcpu))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^

This seems wrong.  kvm_spec_ctrl_valid_bits() returns a bool so this
is either 0xffffffff or 0xfffffffe.  data is a u64.

  2002                          return 1;
  2003  
  2004                  vmx->spec_ctrl = data;
  2005                  if (!data)
  2006                          break;
  2007  
  2008                  /*
  2009                   * For non-nested:

regards,
dan carpenter

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

* Re: [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL
  2020-01-27  6:04 [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL Dan Carpenter
@ 2020-01-27  6:08 ` Dan Carpenter
  2020-01-27 18:12 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-01-27  6:08 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm

See also:

arch/x86/kvm/svm.c:4289 svm_set_msr() warn: maybe use && instead of &

regards,
dan carpenter



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

* Re: [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL
  2020-01-27  6:04 [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL Dan Carpenter
  2020-01-27  6:08 ` Dan Carpenter
@ 2020-01-27 18:12 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2020-01-27 18:12 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: pbonzini, kvm

On Mon, Jan 27, 2020 at 09:04:22AM +0300, Dan Carpenter wrote:
> Hello Paolo Bonzini,
> 
> The patch e71ae535bc24: "KVM: x86: avoid incorrect writes to host
> MSR_IA32_SPEC_CTRL" from Jan 20, 2020, leads to the following static
> checker warning:
> 
> 	arch/x86/kvm/vmx/vmx.c:2001 vmx_set_msr()
> 	warn: maybe use && instead of &
> 
> arch/x86/kvm/vmx/vmx.c
>   1994                  vmx->msr_ia32_umwait_control = data;
>   1995                  break;
>   1996          case MSR_IA32_SPEC_CTRL:
>   1997                  if (!msr_info->host_initiated &&
>   1998                      !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
>   1999                          return 1;
>   2000  
>   2001                  if (data & ~kvm_spec_ctrl_valid_bits(vcpu))
>                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> This seems wrong.  kvm_spec_ctrl_valid_bits() returns a bool so this
> is either 0xffffffff or 0xfffffffe.  data is a u64.
> 
>   2002                          return 1;
>   2003  
>   2004                  vmx->spec_ctrl = data;
>   2005                  if (!data)
>   2006                          break;
>   2007  
>   2008                  /*
>   2009                   * For non-nested:

Paolo already had to put on the cone of shame for this one :-)

https://lkml.kernel.org/r/6b725990-f0c2-6577-be7e-44e101e540b5@redhat.com

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

end of thread, other threads:[~2020-01-27 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-27  6:04 [bug report] KVM: x86: avoid incorrect writes to host MSR_IA32_SPEC_CTRL Dan Carpenter
2020-01-27  6:08 ` Dan Carpenter
2020-01-27 18:12 ` Sean Christopherson

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