x86: vmx: Expect multiple error codes on HOST_EFER corruption
PATCH 1/1 x86: vmx: Expect multiple error codes on HOST_EFER corruption
Extended HOST_EFER tests can fail with a different error code than the expected one, since the host address size bit is checked against EFER.LMA. This causes kvm-unit-tests to fail on bare metal. According to the SDM the errors are not ordered.
Expect either "invalid control" or "invalid host state" error-codes to allow the tests to pass. The fix somewhat relaxes the tests, as there are cases when only "invalid host state" is a valid instruction error, but doing the fix in this manner prevents intrusive changes.
--- x86/vmx_tests.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
x86/vmx_tests.c +23 -1
@@ -3407,6 +3407,27 @@ static void test_vmx_vmlaunch(u32 xerror) } } +/* +* Try to launch the current VMCS, and expect one of two possible +* errors (or success) codes. +*/ +static void test_vmx_vmlaunch2 (u32 xerror1,u32 xerror2) +{ +bool success =vmlaunch_succeeds (); +u32 vmx_inst_err; + +if (!xerror1 == !xerror2) +report (success == !xerror1,"vmlaunch %s" , + !xerror1 ?"succeeds" :"fails" ); + +if (!success && (xerror1 || xerror2)) { + vmx_inst_err =vmcs_read (VMX_INST_ERROR ); +report (vmx_inst_err == xerror1 || vmx_inst_err == xerror2, +"VMX inst error is %d or %d (actual %d)" , xerror1, + xerror2, vmx_inst_err); + } +} +static void test_vmx_invalid_controls (void ) {test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_CONTROL_FIELD );
@@ -6764,7 +6785,8 @@ static void test_efer_vmlaunch(u32 fld, bool ok)if (ok)test_vmx_vmlaunch (0 );else -test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ); +test_vmx_vmlaunch2 (VMXERR_ENTRY_INVALID_CONTROL_FIELD , +VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ); }else {if (ok) {enter_guest ();
Signature · 1 line
2.20.1
Quoted 50 lines · Nadav Amit
Extended
HOST_EFERtests can fail with a different error code than the expected one, since the host address size bit is checked against EFER.LMA. This causes kvm-unit-tests to fail on bare metal. According to the SDM the errors are not ordered.Expect either "invalid control" or "invalid host state" error-codes to allow the tests to pass. The fix somewhat relaxes the tests, as there are cases when only "invalid host state" is a valid instruction error, but doing the fix in this manner prevents intrusive changes.
Fixes a22d7b5534c2 ("x86: vmx_tests: extend HOST_EFER tests")Signed-off-by Nadav Amit <[email protected]>--- x86/vmx_tests.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)x86/vmx_tests.c +21
-0@@ -3407,6 +3407,27 @@ static void test_vmx_vmlaunch(u32 xerror) } } +/* +* Try to launch the current VMCS, and expect one of two possible +* errors (or success) codes. +*/ +static void test_vmx_vmlaunch2 (u32 xerror1,u32 xerror2) +{ +bool success =vmlaunch_succeeds (); +u32 vmx_inst_err; + +if (!xerror1 == !xerror2) +report (success == !xerror1,"vmlaunch %s" , + !xerror1 ?"succeeds" :"fails" ); + +if (!success && (xerror1 || xerror2)) { + vmx_inst_err =vmcs_read (VMX_INST_ERROR ); +report (vmx_inst_err == xerror1 || vmx_inst_err == xerror2, +"VMX inst error is %d or %d (actual %d)" , xerror1, + xerror2, vmx_inst_err); + } +} +static void test_vmx_invalid_controls (void ) {test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_CONTROL_FIELD );
x86/vmx_tests.c static void test_efer_vmlaunch(u32 fld, bool ok) · line 6792
Quoted 9 lines
x86/vmx_tests.c +2
-1@@ -6764,7 +6785,8 @@ static void test_efer_vmlaunch(u32 fld, bool ok)if (ok)test_vmx_vmlaunch (0 );else -test_vmx_vmlaunch (VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ); +test_vmx_vmlaunch2 (VMXERR_ENTRY_INVALID_CONTROL_FIELD , +VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ); }else {if (ok) {enter_guest ();
Queued, thanks.
Paolo