Re: [PATCH 1/2] nVMX: Ensure host's PAT is loaded at the end of all VMX tests

From: Sean Christopherson
Date: Mon Jun 10 2024 - 21:48:06 EST


On Tue, Jun 11, 2024, Yan Zhao wrote:
> On Wed, Jun 05, 2024 at 03:45:26PM -0700, Sean Christopherson wrote:
> > @@ -7274,6 +7275,8 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
> > error = 0;
> >
> > test_vmx_vmlaunch(error);
> > + wrmsr(MSR_IA32_CR_PAT, pat_msr_saved);
> > +
> > report_prefix_pop();
> >
> > } else { // GUEST_PAT
>
> Is it possible that ENT_LOAD_PAT of GUEST_PAT is tested when there's no support of
> EXI_LOAD_PAT of HOST_PAT?
> Then
> wrmsr(MSR_IA32_CR_PAT, pat_msr_saved);
> is also required in this case?

Heh, in theory, yeah, a nested setup could create such a monstrosity. It's easy
enough to handle, so I guess why not? Though I'm tempted to assert instead,
because practically speaking this code will never be hit, and thus never validated.

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 2063ee90..ffe7064c 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7288,6 +7288,9 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
error = (i == 0x2 || i == 0x3 || i >= 0x8);
test_guest_state("ENT_LOAD_PAT enabled", !!error,
val, "GUEST_PAT");
+
+ if (!(ctrl_exit_rev.clr & EXI_LOAD_PAT))
+ wrmsr(MSR_IA32_CR_PAT, pat_msr_saved);
}

}