Page MenuHomeFreeBSD

D61799.1795271257.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D61799.1795271257.diff

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
@@ -382,11 +382,13 @@
PINBASED_DEFAULT1, PINBASED_L1_MUST, PINBASED_L1_MAY);
/*
* The secondary controls: "enable EPT", which the CPU has because
- * the host needs it, and "enable VPID" if the CPU has it. All
- * types of INVVPID are offered, as they all do the same here.
+ * the host needs it, and "unrestricted guest" and "enable VPID" if
+ * the CPU has them. All types of INVVPID are offered, as they all
+ * do the same here.
*/
proc_may = PROCBASED_L1_MAY | PROCBASED_SECONDARY_CONTROLS;
- proc2 = PROCBASED2_ENABLE_EPT;
+ proc2 = PROCBASED2_ENABLE_EPT | (PROCBASED2_UNRESTRICTED_GUEST &
+ (rdmsr(MSR_VMX_PROCBASED_CTLS2) >> 32));
cap = VMX_EPT_CAP;
if (((rdmsr(MSR_VMX_PROCBASED_CTLS2) >> 32) &
PROCBASED2_ENABLE_VPID) != 0) {
@@ -1324,6 +1326,16 @@
return (true);
}
+/* Has L1 set "unrestricted guest" for L2? */
+static bool
+nested_unrestricted(struct vmx_nested *nested)
+{
+ return ((V12(nested, VMCS_PRI_PROC_BASED_CTLS) &
+ PROCBASED_SECONDARY_CONTROLS) != 0 &&
+ (V12(nested, VMCS_SEC_PROC_BASED_CTLS) &
+ PROCBASED2_UNRESTRICTED_GUEST) != 0);
+}
+
/* Has L1 set "enable VPID" for L2? */
static bool
nested_vpid(struct vmx_nested *nested)
@@ -1337,8 +1349,9 @@
/*
* The fields for the event to inject (SDM 27.2.1.3). The CPU checks them
* too when it enters vmcs02, but that is after the checks on L2's state
- * that are made here, and these come first. L1 has no unrestricted guest,
- * so L2 is in protected mode, and IA32_VMX_BASIC[56] is 0 for L1.
+ * that are made here, and these come first. IA32_VMX_BASIC[56] is 0 for
+ * L1. Only an unrestricted guest can be in real mode, where exceptions
+ * have no error code.
*/
static bool
nested_event_valid(struct vmx_nested *nested)
@@ -1361,9 +1374,11 @@
case VMCS_INTR_T_HWEXCEPTION:
if (vector > 31)
return (false);
- errcode = vector == IDT_DF || vector == IDT_TS ||
+ errcode = (vector == IDT_DF || vector == IDT_TS ||
vector == IDT_NP || vector == IDT_SS ||
- vector == IDT_GP || vector == IDT_PF || vector == IDT_AC;
+ vector == IDT_GP || vector == IDT_PF ||
+ vector == IDT_AC) && (!nested_unrestricted(nested) ||
+ (V12(nested, VMCS_GUEST_CR0) & CR0_PE) != 0);
break;
case VMCS_INTR_T_SWINTR:
case VMCS_INTR_T_PRIV_SWEXCEPTION:
@@ -1421,7 +1436,8 @@
(!nested_ctls_valid(V12(nested, VMCS_SEC_PROC_BASED_CTLS),
MSR_VMX_PROCBASED_CTLS2) || (nested_vpid(nested) &&
V12(nested, VMCS_VPID) == 0) || (nested_ept12(nested) &&
- !nested_eptp_valid(V12(nested, VMCS_EPTP)))))
+ !nested_eptp_valid(V12(nested, VMCS_EPTP))) ||
+ (nested_unrestricted(nested) && !nested_ept12(nested))))
return (VMXERR_ENTRY_CTLS);
/* The TPR shadow: the virtual-APIC page and the TPR threshold. */
if ((proc & PROCBASED_USE_TPR_SHADOW) != 0 &&
@@ -1536,11 +1552,18 @@
nested_check_guest_state(struct vmx_vcpu *vcpu, uint64_t *qual)
{
struct vmx_nested *nested = vcpu->nested;
- uint64_t link;
+ uint64_t cr0, link;
uint32_t revision;
*qual = EXIT_QUAL_ENTRY_NONE;
- if (!nested_cr0_valid(V12(nested, VMCS_GUEST_CR0)) ||
+ /* An unrestricted guest may have CR0.PE and CR0.PG clear. */
+ cr0 = V12(nested, VMCS_GUEST_CR0);
+ if (nested_unrestricted(nested)) {
+ if ((cr0 & (CR0_PE | CR0_PG)) == CR0_PG)
+ return (false);
+ cr0 |= CR0_PE | CR0_PG;
+ }
+ if (!nested_cr0_valid(cr0) ||
!nested_cr4_valid(V12(nested, VMCS_GUEST_CR4)))
return (false);
link = V12(nested, VMCS_LINK_POINTER);
@@ -1565,7 +1588,7 @@
struct vmx_nested *nested = vcpu->nested;
uint64_t cr, debugctl, dr7, efer, mask, mask12, pdpte[4], tsc_offset;
uint8_t *bitmap;
- uint32_t entry12, pin, proc, proc01;
+ uint32_t entry12, pin, proc, proc01, proc2;
u_int i;
entry12 = V12(nested, VMCS_ENTRY_CTLS);
@@ -1676,6 +1699,7 @@
* stands for all the VPIDs that L1 uses: what is cached for one of
* them must go when L1 comes with another one.
*/
+ proc2 = PROCBASED2_ENABLE_EPT;
nested->vpid_active = nested_vpid(nested) && nested->vpid02 != 0;
if (nested->vpid_active) {
if (nested->vpid12 != V12(nested, VMCS_VPID)) {
@@ -1683,10 +1707,11 @@
nested->vpid_flush = true;
}
vmcs_write(VMCS_VPID, nested->vpid02);
- vmcs_write(VMCS_SEC_PROC_BASED_CTLS, PROCBASED2_ENABLE_EPT |
- PROCBASED2_ENABLE_VPID);
- } else
- vmcs_write(VMCS_SEC_PROC_BASED_CTLS, PROCBASED2_ENABLE_EPT);
+ proc2 |= PROCBASED2_ENABLE_VPID;
+ }
+ if (nested_unrestricted(nested))
+ proc2 |= PROCBASED2_UNRESTRICTED_GUEST;
+ vmcs_write(VMCS_SEC_PROC_BASED_CTLS, proc2);
/* L2 runs on EPT02 if L1 uses EPT for it, and on L1's memory if not. */
vmcs_write(VMCS_EPTP, nested->ept_active ? nested->ept->eptp :
vcpu->vmx->eptp);

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 21, 2:27 PM (19 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41890643
Default Alt Text
D61799.1795271257.diff (4 KB)

Event Timeline