Skip to contentSkip to conversation

KVM: nVMX: VMWRITE emulation: remove unnecessary check for compatibility mode

PATCH In review Eugene Korenevsky 2 participants 2 messages Aug 20, 2015 – Sep 7, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 5/5 KVM: nVMX: VMWRITE emulation: remove unnecessary check for compatibility mode

VMWRITE instruction is not valid in compatibility mode. This is checked by nested_vmx_check_permission() function which throws #UD if CS.L=0. The additional check in is_64_bit_mode() for CS.L=0 is useless. We should check only EFER.LMA=1 which is done by is_long_mode().

---
 arch/x86/kvm/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx.c +1 -1
index f39e24f..12bdaae 100644
@@ -7034,7 +7034,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
 		field_value = kvm_register_readl(vcpu,
 			(((vmx_instruction_info) >> 3) & 0xf));
 	else {
-		mem_op_size = is_64_bit_mode(vcpu) ? 8 : 4;
+		mem_op_size = is_long_mode(vcpu) ? 8 : 4;
 		if (get_vmx_mem_address(vcpu, exit_qualification,
 		    vmx_instruction_info, false, mem_op_size, &gva))
 			return 1;
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 3 lines · Eugene Korenevsky

VMWRITE instruction is not valid in compatibility mode. This is checked by nested_vmx_check_permission() function which throws #UD if CS.L=0. The additional check in is_64_bit_mode() for CS.L=0 is useless.

This is true, and it matches what handle_vmread does, on the other hand is_long_mode is generally used to test page table type.

I think it's clearer if you change handle_vmread to use is_64_bit_mode instead.

Paolo

Quoted 21 lines

We should check only EFER.LMA=1 which is done by is_long_mode().

---
 arch/x86/kvm/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx.c +1 -2
index f39e24f..12bdaae 100644
@@ -7034,7 +7034,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
 		field_value = kvm_register_readl(vcpu,
 			(((vmx_instruction_info) >> 3) & 0xf));
 	else {
-		mem_op_size = is_64_bit_mode(vcpu) ? 8 : 4;
+		mem_op_size = is_long_mode(vcpu) ? 8 : 4;
 		if (get_vmx_mem_address(vcpu, exit_qualification,
 		    vmx_instruction_info, false, mem_op_size, &gva))
 			return 1;
-- 2.1.4