diff mbox series

[02/29] KVM: nVMX: Check a single byte for VMCS "launched" in nested early checks

Message ID 20190118212037.24412-3-sean.j.christopherson@intel.com
State New, archived
Headers show
Series KVM: VMX: Move vCPU-run to proper asm sub-routine | expand

Commit Message

Sean Christopherson Jan. 18, 2019, 9:20 p.m. UTC
Nested early checks does a manual comparison of a VMCS' launched status
in its asm blob to execute the correct VM-Enter instruction, i.e.
VMLAUNCH vs. VMRESUME.  The launched flag is a bool, which is a typedef
of _Bool.  C99 does not define an exact size for _Bool, stating only
that is must be large enough to hold '0' and '1'.  Most, if not all,
compilers use a single byte for _Bool, including gcc[1].

The use of 'cmpl' instead of 'cmpb' was not deliberate, but rather the
result of a copy-paste as the asm blob was directly derived from the asm
blob for vCPU-run.

This has not caused any known problems, likely due to compilers aligning
variables to 4-byte or 8-byte boundaries and KVM zeroing out struct
vcpu_vmx during allocation.  I.e. vCPU-run accesses "junk" data, it just
happens to always be zero and so doesn't affect the result.

[1] https://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html

Fixes: 52017608da33 ("KVM: nVMX: add option to perform early consistency checks via H/W")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jim Mattson Jan. 18, 2019, 9:58 p.m. UTC | #1
On Fri, Jan 18, 2019 at 1:22 PM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> Nested early checks does a manual comparison of a VMCS' launched status
> in its asm blob to execute the correct VM-Enter instruction, i.e.
> VMLAUNCH vs. VMRESUME.  The launched flag is a bool, which is a typedef
> of _Bool.  C99 does not define an exact size for _Bool, stating only
> that is must be large enough to hold '0' and '1'.  Most, if not all,
> compilers use a single byte for _Bool, including gcc[1].
>
> The use of 'cmpl' instead of 'cmpb' was not deliberate, but rather the
> result of a copy-paste as the asm blob was directly derived from the asm
> blob for vCPU-run.
>
> This has not caused any known problems, likely due to compilers aligning
> variables to 4-byte or 8-byte boundaries and KVM zeroing out struct
> vcpu_vmx during allocation.  I.e. vCPU-run accesses "junk" data, it just
> happens to always be zero and so doesn't affect the result.
>
> [1] https://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html
>
> Fixes: 52017608da33 ("KVM: nVMX: add option to perform early consistency checks via H/W")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Konrad Rzeszutek Wilk Jan. 22, 2019, 8:26 a.m. UTC | #2
On Fri, Jan 18, 2019 at 01:20:10PM -0800, Sean Christopherson wrote:
> Nested early checks does a manual comparison of a VMCS' launched status
> in its asm blob to execute the correct VM-Enter instruction, i.e.
> VMLAUNCH vs. VMRESUME.  The launched flag is a bool, which is a typedef
> of _Bool.  C99 does not define an exact size for _Bool, stating only
> that is must be large enough to hold '0' and '1'.  Most, if not all,
> compilers use a single byte for _Bool, including gcc[1].
> 
> The use of 'cmpl' instead of 'cmpb' was not deliberate, but rather the
> result of a copy-paste as the asm blob was directly derived from the asm
> blob for vCPU-run.
> 
> This has not caused any known problems, likely due to compilers aligning
> variables to 4-byte or 8-byte boundaries and KVM zeroing out struct
> vcpu_vmx during allocation.  I.e. vCPU-run accesses "junk" data, it just
> happens to always be zero and so doesn't affect the result.
> 
> [1] https://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html
> 
> Fixes: 52017608da33 ("KVM: nVMX: add option to perform early consistency checks via H/W")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!
> ---
>  arch/x86/kvm/vmx/nested.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 3170e291215d..69920c2fa5db 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2760,7 +2760,7 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
>  		"add $%c[wordsize], %%" _ASM_SP "\n\t" /* un-adjust RSP */
>  
>  		/* Check if vmlaunch or vmresume is needed */
> -		"cmpl $0, %c[launched](%% " _ASM_CX")\n\t"
> +		"cmpb $0, %c[launched](%% " _ASM_CX")\n\t"
>  
>  		"call vmx_vmenter\n\t"
>  
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 3170e291215d..69920c2fa5db 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2760,7 +2760,7 @@  static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
 		"add $%c[wordsize], %%" _ASM_SP "\n\t" /* un-adjust RSP */
 
 		/* Check if vmlaunch or vmresume is needed */
-		"cmpl $0, %c[launched](%% " _ASM_CX")\n\t"
+		"cmpb $0, %c[launched](%% " _ASM_CX")\n\t"
 
 		"call vmx_vmenter\n\t"