Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177784482
D61803.1795276194.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D61803.1795276194.diff
View Options
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
@@ -873,29 +873,32 @@
}
/*
- * Enter a 4 KB page for L2's address 'gpa'. Returns false if the tree is
- * full; '*old' is what was there.
+ * Enter a page of 4 KB ('leaf' 0) or 2 MB ('leaf' 1) for L2's address
+ * 'gpa'. Returns false if the tree is full; '*old' is what was there.
*/
static bool
nested_ept_install(struct nested_ept *ept, uint64_t gpa, uint64_t pte,
- uint64_t *old)
+ int leaf, uint64_t *old)
{
uint64_t *entry, *table, *page;
int lvl;
table = ept->page[0];
- for (lvl = 3; lvl > 0; lvl--) {
+ for (lvl = 3; lvl > leaf; lvl--) {
entry = &table[EPT_INDEX(gpa, lvl)];
- if ((*entry & EPT_RWX) == 0) {
+ /* Also in the place of a 2 MB page, for a part of it. */
+ if ((*entry & EPT_RWX) == 0 || (*entry & EPT_PS) != 0) {
page = nested_ept_page(ept);
if (page == NULL)
return (false);
+ if ((*entry & EPT_PS) != 0)
+ CPU_ZERO(&ept->clean);
/* The leaves decide what is allowed. */
*entry = vtophys(page) | EPT_RWX;
}
table = (uint64_t *)PHYS_TO_DMAP(EPT_ADDR(*entry));
}
- entry = &table[EPT_INDEX(gpa, 0)];
+ entry = &table[EPT_INDEX(gpa, leaf)];
*old = *entry;
*entry = pte;
return (true);
@@ -903,11 +906,11 @@
/*
* The entry of EPT01 that maps L1's address 'gpa', with the pmap locked: a
- * page of 4 KB, 2 MB or 1 GB. '*pa' is where the 4 KB around 'gpa' are.
- * Returns NULL if nothing is mapped there.
+ * page of 4 KB, 2 MB or 1 GB. '*pa' is where the 4 KB around 'gpa' are,
+ * '*lvlp' the level of the entry. Returns NULL if nothing is mapped there.
*/
static uint64_t *
-nested_ept01_leaf(pmap_t pmap, uint64_t gpa, vm_paddr_t *pa)
+nested_ept01_leaf(pmap_t pmap, uint64_t gpa, vm_paddr_t *pa, int *lvlp)
{
uint64_t *entry, *table;
int lvl;
@@ -917,6 +920,7 @@
entry = &table[EPT_INDEX(gpa, lvl)];
if ((*entry & EPT_RWX) == 0)
return (NULL);
+ *lvlp = lvl;
if (lvl == 0) {
*pa = EPT_ADDR(*entry);
return (entry);
@@ -962,11 +966,11 @@
* 29.3.3): an entry that is not present ends the walk with an EPT
* violation, one that is set up wrongly, for what L1 is offered, with an
* EPT misconfiguration. '*perm' is what all the entries allow, '*leafp'
- * the last entry.
+ * the last entry and '*lvlp' its level.
*/
static enum nested_ept_walk
nested_ept12_walk(struct vmx_vcpu *vcpu, uint64_t eptp, uint64_t gpa,
- uint64_t *gpa1, int *perm, uint64_t *leafp)
+ uint64_t *gpa1, int *perm, uint64_t *leafp, int *lvlp)
{
uint64_t entry, mask, rsvd, table;
int lvl, type;
@@ -998,6 +1002,7 @@
return (EPT12_MISCONFIG);
*gpa1 = EPT_ADDR(entry) | (gpa & mask);
*leafp = entry;
+ *lvlp = lvl;
return (EPT12_OK);
}
table = EPT_ADDR(entry);
@@ -1045,10 +1050,10 @@
nested_l2_read(struct vmx_vcpu *vcpu, uint64_t gpa, void *buf, size_t len)
{
uint64_t gpa1, leaf;
- int perm;
+ int lvl, perm;
return (nested_ept12_walk(vcpu, vcpu->nested->ept->eptp12, gpa,
- &gpa1, &perm, &leaf) == EPT12_OK && (perm & EPT_R) != 0 &&
+ &gpa1, &perm, &leaf, &lvl) == EPT12_OK && (perm & EPT_R) != 0 &&
nested_copy(vcpu, gpa1, buf, len, false));
}
@@ -1200,10 +1205,10 @@
struct vmx_nested_l2exit *exit = &nested->exit;
struct nested_ept *ept = nested->ept;
pmap_t pmap = vcpu->vmx->pmap;
- uint64_t ad, gpa1, *leaf, leaf12, old, pte, pte01;
+ uint64_t ad, gpa, gpa1, *leaf, leaf12, old, pte, pte01;
vm_paddr_t pa;
long gen;
- int need, perm, tries;
+ int lvl01, lvl12, need, perm, tries;
bool ad12;
/*
@@ -1215,7 +1220,7 @@
if (ad12 && (exit->qual & (1 << 7 | 1 << 8)) == 1 << 7)
need |= EPT_W;
switch (nested_ept12_walk(vcpu, ept->eptp12, exit->gpa, &gpa1,
- &perm, &leaf12)) {
+ &perm, &leaf12, &lvl12)) {
case EPT12_MISCONFIG:
exit->reason = EXIT_REASON_EPT_MISCONFIG;
exit->qual = 0;
@@ -1252,7 +1257,7 @@
}
for (tries = 0;; tries++) {
PMAP_LOCK(pmap);
- leaf = nested_ept01_leaf(pmap, gpa1, &pa);
+ leaf = nested_ept01_leaf(pmap, gpa1, &pa, &lvl01);
if (leaf != NULL && (need & ~*leaf) == 0)
break;
PMAP_UNLOCK(pmap);
@@ -1266,6 +1271,18 @@
}
}
pte01 = *leaf;
+ /*
+ * A page of 2 MB if both L1 and the host have one there: fewer VM
+ * exits to fill the tree with, which counts every time it has been
+ * emptied. L1's 2 MB are then 2 MB in a row for the host as well.
+ */
+ gpa = exit->gpa;
+ if (lvl12 >= 1 && lvl01 >= 1) {
+ lvl12 = 1;
+ gpa &= ~(uint64_t)PDRMASK;
+ pa = (pa & ~(vm_paddr_t)PDRMASK) | EPT_PS;
+ } else
+ lvl12 = 0;
pte = pa | (perm & pte01 & EPT_RWX) |
(pte01 & (EPT_MEMTYPE | EPT_IPAT));
/*
@@ -1279,9 +1296,9 @@
atomic_set_long(leaf, ad);
}
PMAP_UNLOCK(pmap);
- if (!nested_ept_install(ept, exit->gpa, pte, &old)) {
+ if (!nested_ept_install(ept, gpa, pte, lvl12, &old)) {
nested_ept_reset(ept);
- (void)nested_ept_install(ept, exit->gpa, pte, &old);
+ (void)nested_ept_install(ept, gpa, pte, lvl12, &old);
}
/* A translation that the CPUs may have cached has changed. */
if ((old & EPT_RWX) != 0)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 3:49 PM (21 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41890742
Default Alt Text
D61803.1795276194.diff (5 KB)
Attached To
Mode
D61803: vmm: Use 2 MB pages in the EPT of nested VMX
Attached
Detach File
Event Timeline