Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178068185
D61942.1795885729.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D61942.1795885729.diff
View Options
diff --git a/sys/amd64/vmm/intel/vmx_msr.h b/sys/amd64/vmm/intel/vmx_msr.h
--- a/sys/amd64/vmm/intel/vmx_msr.h
+++ b/sys/amd64/vmm/intel/vmx_msr.h
@@ -32,6 +32,7 @@
struct vmx;
void vmx_msr_init(void);
+bool vmx_pat_valid(uint64_t val);
void vmx_msr_guest_init(struct vmx *vmx, struct vmx_vcpu *vcpu);
void vmx_msr_guest_enter_tsc_aux(struct vmx *vmx, struct vmx_vcpu *vcpu);
void vmx_msr_guest_enter(struct vmx_vcpu *vcpu);
diff --git a/sys/amd64/vmm/intel/vmx_msr.c b/sys/amd64/vmm/intel/vmx_msr.c
--- a/sys/amd64/vmm/intel/vmx_msr.c
+++ b/sys/amd64/vmm/intel/vmx_msr.c
@@ -221,8 +221,8 @@
return (false);
}
-static bool
-pat_valid(uint64_t val)
+bool
+vmx_pat_valid(uint64_t val)
{
int i, pa;
@@ -507,7 +507,7 @@
error = EINVAL; /* as before: for bhyve(8) to decide */
break;
case MSR_PAT:
- if (pat_valid(val))
+ if (vmx_pat_valid(val))
vcpu->guest_msrs[IDX_MSR_PAT] = val;
else
vm_inject_gp(vcpu->vcpu);
diff --git a/sys/amd64/vmm/intel/vmx_nested.c b/sys/amd64/vmm/intel/vmx_nested.c
--- a/sys/amd64/vmm/intel/vmx_nested.c
+++ b/sys/amd64/vmm/intel/vmx_nested.c
@@ -99,6 +99,7 @@
#include "vmcs.h"
#include "vmx.h"
#include "vmx_controls.h"
+#include "vmx_msr.h"
#include "vmx_nested.h"
static void nested_ept_free(struct vmx_nested *nested);
@@ -192,11 +193,12 @@
#define VM_EXIT_L1_MUST VM_EXIT_HOST_LMA
#define VM_EXIT_L1_MAY \
(VM_EXIT_SAVE_DEBUG_CONTROLS | VM_EXIT_ACKNOWLEDGE_INTERRUPT | \
- VM_EXIT_SAVE_EFER | VM_EXIT_LOAD_EFER)
+ VM_EXIT_SAVE_PAT | VM_EXIT_LOAD_PAT | VM_EXIT_SAVE_EFER | \
+ VM_EXIT_LOAD_EFER)
#define VM_ENTRY_L1_MUST 0
#define VM_ENTRY_L1_MAY \
(VM_ENTRY_LOAD_DEBUG_CONTROLS | VM_ENTRY_GUEST_LMA | \
- VM_ENTRY_LOAD_EFER)
+ VM_ENTRY_LOAD_PAT | VM_ENTRY_LOAD_EFER)
/* VM-instruction error numbers (SDM 31.4). */
#define VMXERR_VMCLEAR_ADDR 2
@@ -1973,6 +1975,9 @@
(efer & (EFER_LMA | EFER_LME)) != (EFER_LMA | EFER_LME))
return (VMXERR_ENTRY_HOST_STATE);
}
+ if ((V12(nested, VMCS_EXIT_CTLS) & VM_EXIT_LOAD_PAT) != 0 &&
+ !vmx_pat_valid(V12(nested, VMCS_HOST_IA32_PAT)))
+ return (VMXERR_ENTRY_HOST_STATE);
return (0);
}
@@ -2002,6 +2007,9 @@
if (!nested_cr0_valid(cr0) ||
!nested_cr4_valid(V12(nested, VMCS_GUEST_CR4)))
return (false);
+ if ((V12(nested, VMCS_ENTRY_CTLS) & VM_ENTRY_LOAD_PAT) != 0 &&
+ !vmx_pat_valid(V12(nested, VMCS_GUEST_IA32_PAT)))
+ return (false);
link = V12(nested, VMCS_LINK_POINTER);
if (link != ~0UL) {
*qual = EXIT_QUAL_ENTRY_LINK;
@@ -2219,6 +2227,12 @@
dr7 = V12(nested, VMCS_GUEST_DR7);
debugctl = V12(nested, VMCS_GUEST_IA32_DEBUGCTL);
}
+ /*
+ * bhyve keeps the guest's PAT as data only (vmx_msr.c), for L1 and L2
+ * alike: loading and saving it moves the value.
+ */
+ if ((entry12 & VM_ENTRY_LOAD_PAT) != 0)
+ vcpu->guest_msrs[IDX_MSR_PAT] = V12(nested, VMCS_GUEST_IA32_PAT);
if ((entry12 & VM_ENTRY_LOAD_EFER) != 0)
efer = V12(nested, VMCS_GUEST_IA32_EFER);
else if ((entry12 & VM_ENTRY_GUEST_LMA) != 0)
@@ -2640,6 +2654,8 @@
vmcs_write(VMCS_GUEST_CR4, vmx_fix_cr4(V12(nested, VMCS_HOST_CR4)));
vmcs_write(VMCS_CR4_SHADOW, V12(nested, VMCS_HOST_CR4));
vmcs_write(VMCS_GUEST_CR3, V12(nested, VMCS_HOST_CR3));
+ if ((V12(nested, VMCS_EXIT_CTLS) & VM_EXIT_LOAD_PAT) != 0)
+ vcpu->guest_msrs[IDX_MSR_PAT] = V12(nested, VMCS_HOST_IA32_PAT);
if ((V12(nested, VMCS_EXIT_CTLS) & VM_EXIT_LOAD_EFER) != 0)
efer = V12(nested, VMCS_HOST_IA32_EFER);
else
@@ -2739,6 +2755,9 @@
V12(nested, VMCS_GUEST_CR0) = cr0;
V12(nested, VMCS_GUEST_CR4) = cr4;
+ if ((exit12 & VM_EXIT_SAVE_PAT) != 0)
+ V12(nested, VMCS_GUEST_IA32_PAT) =
+ vcpu->guest_msrs[IDX_MSR_PAT];
if ((exit12 & VM_EXIT_SAVE_EFER) != 0)
V12(nested, VMCS_GUEST_IA32_EFER) = efer;
V12(nested, VMCS_ENTRY_CTLS) &= ~(uint64_t)VM_ENTRY_GUEST_LMA;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 28, 5:08 PM (9 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42012751
Default Alt Text
D61942.1795885729.diff (3 KB)
Attached To
Mode
D61942: vmm: Let L1 save and load IA32_PAT for L2
Attached
Detach File
Event Timeline