Better max VMCS field index test
cover Better max VMCS field index test
The first patch improves max VMCS field index search so an exact comparison would be possible. The second one does some cleanup.
Nadav Amit (2):
x86: vmx: Comprehensive max VMCS field search
x86: vmx: Remove max_index tracking in check_vmcs_field()
x86/vmx.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 x86: vmx: Comprehensive max VMCS field search
Search all VMCS fields when looking for the max VMCS field index. Perform the search backwards to save some time. Change the existing test to compare the maximum expected index (based on MSRs) is equal to the actual one. This improves the test that currently performs greater-equal comparison.
--- x86/vmx.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-)
x86/vmx.c +34 -4
@@ -348,6 +348,34 @@ static bool check_all_vmcs_fields(u8 cookie)return __check_all_vmcs_fields (cookie,NULL ); } +static u32 find_vmcs_max_index (void ) +{ +u32 idx, width, type, enc; +u64 actual; +int ret; + +/* scan backwards and stop when found */ +for (idx = (1 <<9 ) -1 ; idx >=0 ; idx--) { + +/* try all combinations of width and type */ +for (type =0 ; type < (1 <<2 ); type++) { +for (width =0 ; width < (1 <<2 ) ; width++) { + enc = (idx <<VMCS_FIELD_INDEX_SHIFT ) | + (type <<VMCS_FIELD_TYPE_SHIFT ) | + (width <<VMCS_FIELD_WIDTH_SHIFT ); + + ret =vmcs_read_checking (enc, &actual); +assert (!(ret &X86_EFLAGS_CF )); +if (!(ret &X86_EFLAGS_ZF )) +return idx; + } + } + } +/* some VMCS fields should exist */ +assert (0 ); +return 0 ; +} +static void test_vmwrite_vmread (void ) {struct vmcs *vmcs =alloc_page ();
@@ -358,11 +386,13 @@ static void test_vmwrite_vmread(void)assert (!make_vmcs_current (vmcs));set_all_vmcs_fields (0x42 ); -report (__check_all_vmcs_fields (0x42 , &max_index),"VMWRITE/VMREAD" ); +report (check_all_vmcs_fields (0x42 ),"VMWRITE/VMREAD" ); - vmcs_enum_max =rdmsr (MSR_IA32_VMX_VMCS_ENUM ) &VMCS_FIELD_INDEX_MASK ; -report (vmcs_enum_max >= max_index, -"VMX_VMCS_ENUM.MAX_INDEX expected at least: %x, actual: %x" , + vmcs_enum_max = (rdmsr (MSR_IA32_VMX_VMCS_ENUM ) &VMCS_FIELD_INDEX_MASK ) + >>VMCS_FIELD_INDEX_SHIFT ; + max_index =find_vmcs_max_index (); +report (vmcs_enum_max == max_index, +"VMX_VMCS_ENUM.MAX_INDEX expected: %x, actual: %x" , max_index, vmcs_enum_max);assert (!vmcs_clear (vmcs));
Signature · 1 line
2.17.1
PATCH 2/2 x86: vmx: Remove max_index tracking in check_vmcs_field()
In reply to Nadav AmitNow that comprehensive search for maximum VMCS field index is performed, the tracking of the maximum index in __check_vmcs_field() is no longer needed. Remove all the related logic accordingly.
--- x86/vmx.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
x86/vmx.c +3 -15
@@ -281,11 +281,10 @@ static void set_vmcs_field(struct vmcs_field *f, u8 cookie)vmcs_write (f->encoding,vmcs_field_value (f, cookie)); } -static bool check_vmcs_field (struct vmcs_field *f,u8 cookie,u32 *max_index) +static bool check_vmcs_field (struct vmcs_field *f,u8 cookie) {u64 expected;u64 actual; -u32 index;int ret;if (f->encoding ==VMX_INST_ERROR ) {
@@ -299,12 +298,6 @@ static bool check_vmcs_field(struct vmcs_field *f, u8 cookie, u32 *max_index)if (ret &X86_EFLAGS_ZF )return true; -if (max_index) { - index = f->encoding &VMCS_FIELD_INDEX_MASK ; -if (index > *max_index) - *max_index = index; - } -if (vmcs_field_readonly (f)) {printf ("Skipping read-only field %lx\n" , f->encoding);return true;
@@ -330,24 +323,19 @@ static void set_all_vmcs_fields(u8 cookie)set_vmcs_field (&vmcs_fields[i], cookie); } -static bool __check_all_vmcs_fields (u8 cookie,u32 *max_index) +static bool check_all_vmcs_fields (u8 cookie) {bool pass = true;int i;for (i =0 ; i <ARRAY_SIZE (vmcs_fields); i++) { -if (!check_vmcs_field (&vmcs_fields[i], cookie, max_index)) +if (!check_vmcs_field (&vmcs_fields[i], cookie)) pass = false; }return pass; } -static bool check_all_vmcs_fields (u8 cookie) -{ -return __check_all_vmcs_fields (cookie,NULL ); -} -static u32 find_vmcs_max_index (void ) {u32 idx, width, type, enc;
Signature · 1 line
2.17.1
Quoted 6 lines · Nadav Amit
The first patch improves max VMCS field index search so an exact comparison would be possible. The second one does some cleanup.
Cc Jim Mattson <[email protected]>Cc Sean Christopherson <[email protected]>
Quoted 7 lines
Nadav Amit (2):
x86: vmx: Comprehensive max VMCS field search
x86: vmx: Removemax_indextracking incheck_vmcs_field()x86/vmx.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-)
Queued, thanks.
Paolo