From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org,
Xiangfei Ma <xiangfeix.ma@intel.com>,
Yan Zhao <yan.y.zhao@intel.com>,
Sean Christopherson <seanjc@google.com>
Subject: [PATCH 1/2] nVMX: Ensure host's PAT is loaded at the end of all VMX tests
Date: Wed, 5 Jun 2024 15:45:26 -0700 [thread overview]
Message-ID: <20240605224527.2907272-2-seanjc@google.com> (raw)
In-Reply-To: <20240605224527.2907272-1-seanjc@google.com>
Load the host's original PAT on VM-Exit by default in all VMX tests, and
manually write PAT with the original value in the test that verifies all
legal PAT values can be loaded via HOST_PAT. Failure to (re)load the
correct host PAT results in all tests that run after test_load_host_pat()
using UC memtype for all memory.
Opportunistically fix a message goof for the ENT_LOAD_PAT=0 case.
Reported-by: Xiangfei Ma <xiangfeix.ma@intel.com>
Cc: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
x86/vmx.c | 4 +++-
x86/vmx_tests.c | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/x86/vmx.c b/x86/vmx.c
index 9f08c096..c803eaa6 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -1126,6 +1126,8 @@ static void init_vmcs_host(void)
vmcs_write(HOST_CR4, read_cr4());
vmcs_write(HOST_SYSENTER_EIP, (u64)(&entry_sysenter));
vmcs_write(HOST_SYSENTER_CS, KERNEL_CS);
+ if (ctrl_exit_rev.clr & EXI_LOAD_PAT)
+ vmcs_write(HOST_PAT, rdmsr(MSR_IA32_CR_PAT));
/* 26.2.3 */
vmcs_write(HOST_SEL_CS, KERNEL_CS);
@@ -1247,7 +1249,7 @@ int init_vmcs(struct vmcs **vmcs)
/* All settings to pin/exit/enter/cpu
control fields should be placed here */
ctrl_pin |= PIN_EXTINT | PIN_NMI | PIN_VIRT_NMI;
- ctrl_exit = EXI_LOAD_EFER | EXI_HOST_64;
+ ctrl_exit = EXI_LOAD_EFER | EXI_HOST_64 | EXI_LOAD_PAT;
ctrl_enter = (ENT_LOAD_EFER | ENT_GUEST_64);
/* DIsable IO instruction VMEXIT now */
ctrl_cpu[0] &= (~(CPU_IO | CPU_IO_BITMAP));
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 22e8812a..8a17dd90 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7233,6 +7233,7 @@ static void test_guest_efer(void)
static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
u64 ctrl_bit)
{
+ u64 pat_msr_saved = rdmsr(MSR_IA32_CR_PAT);
u32 ctrl_saved = vmcs_read(ctrl_field);
u64 pat_saved = vmcs_read(field);
u64 i, val;
@@ -7252,7 +7253,7 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
report_prefix_pop();
} else { // GUEST_PAT
- test_guest_state("ENT_LOAD_PAT enabled", false,
+ test_guest_state("ENT_LOAD_PAT disabled", false,
val, "GUEST_PAT");
}
}
@@ -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
--
2.45.1.467.gbab1589fc0-goog
next prev parent reply other threads:[~2024-06-05 22:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 22:45 [PATCH 0/2] nVMX: Ensure host's PAT stays sane Sean Christopherson
2024-06-05 22:45 ` Sean Christopherson [this message]
2024-06-11 1:40 ` [PATCH 1/2] nVMX: Ensure host's PAT is loaded at the end of all VMX tests Yan Zhao
2024-06-11 1:47 ` Sean Christopherson
2024-06-11 2:03 ` Yan Zhao
2024-06-05 22:45 ` [PATCH 2/2] nVMX: Verify KVM actually loads the value in HOST_PAT into the PAT MSR Sean Christopherson
2024-06-05 23:03 ` [PATCH 0/2] nVMX: Ensure host's PAT stays sane Sean Christopherson
2024-06-12 1:18 ` Sean Christopherson
2024-06-12 1:47 ` Yan Zhao
2024-06-12 1:50 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240605224527.2907272-2-seanjc@google.com \
--to=seanjc@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=xiangfeix.ma@intel.com \
--cc=yan.y.zhao@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox