lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 22 May 2023 23:41:49 +0000
From:   "Huang, Kai" <kai.huang@...el.com>
To:     "pbonzini@...hat.com" <pbonzini@...hat.com>,
        "Christopherson,, Sean" <seanjc@...gle.com>
CC:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Gao, Chao" <chao.gao@...el.com>,
        "andrew.cooper3@...rix.com" <andrew.cooper3@...rix.com>
Subject: Re: [PATCH v3 09/18] x86/virt: KVM: Open code cpu_has_vmx() in KVM
 VMX

On Fri, 2023-05-12 at 16:50 -0700, Sean Christopherson wrote:
> Fold the raw CPUID check for VMX into kvm_is_vmx_supported(), its sole
> user.  Keep the check even though KVM also checks X86_FEATURE_VMX, as the
> intent is to provide a unique error message if VMX is unsupported by
> hardware, whereas X86_FEATURE_VMX may be clear due to firmware and/or
> kernel actions.
> 
> No functional change intended.
> 
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>

To be honest I am not sure the benefit of open coding, but this is a simple
check, so:

Reviewed-by: Kai Huang <kai.huang@...el.com>

> ---
>  arch/x86/include/asm/virtext.h | 10 ----------
>  arch/x86/kvm/vmx/vmx.c         |  2 +-
>  2 files changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h
> index aaed66249ccf..b1171a5ad452 100644
> --- a/arch/x86/include/asm/virtext.h
> +++ b/arch/x86/include/asm/virtext.h
> @@ -22,14 +22,6 @@
>  /*
>   * VMX functions:
>   */
> -
> -static inline int cpu_has_vmx(void)
> -{
> -	unsigned long ecx = cpuid_ecx(1);
> -	return test_bit(5, &ecx); /* CPUID.1:ECX.VMX[bit 5] -> VT */
> -}
> -
> -
>  /**
>   * cpu_vmxoff() - Disable VMX on the current CPU
>   *
> @@ -61,8 +53,6 @@ static inline int cpu_vmx_enabled(void)
>  }
>  
>  /** Disable VMX if it is enabled on the current CPU

Nit: looks the kdoc style comment (double **) can be removed.

> - *
> - * You shouldn't call this if cpu_has_vmx() returns 0.
>   */
>  static inline void __cpu_emergency_vmxoff(void)
>  {
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 76cdb189f1b5..f44f93772b4f 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -2721,7 +2721,7 @@ static bool kvm_is_vmx_supported(void)
>  {
>  	int cpu = raw_smp_processor_id();
>  
> -	if (!cpu_has_vmx()) {
> +	if (!(cpuid_ecx(1) & feature_bit(VMX))) {
>  		pr_err("VMX not supported by CPU %d\n", cpu);
>  		return false;
>  	}
> -- 
> 2.40.1.606.ga4b1b128d6-goog
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ