Page MenuHomeFreeBSD

D61940.1795510242.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61940.1795510242.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
@@ -772,8 +772,12 @@
* and it is for one EPTP of L1 at a time. It is emptied when L1 comes with
* another EPTP, when L1 executes INVEPT, when it is full, and when EPT01 has
* changed: every change that takes something away from the pmap counts up
- * pm_eptgen and gets the vCPUs out of the guest. L1's tables are not
- * write-protected: L1 has to use INVEPT after a change, as on a CPU.
+ * pm_eptgen and gets the vCPUs out of the guest. A change that only clears
+ * an accessed flag, which the page daemon makes all the time, is also
+ * counted in pm_eptgen_ad and leaves the tree as it is; L2's accesses do not
+ * set the flag again, so its pages look less used to the page daemon. L1's
+ * tables are not write-protected: L1 has to use INVEPT after a change, as on
+ * a CPU.
*/
struct nested_ept {
uint64_t **page; /* the tree's pages; 0 is the root */
@@ -781,7 +785,7 @@
u_int nused; /* in the tree */
uint64_t eptp; /* of vmcs02 */
uint64_t eptp12; /* L1's EPTP that the tree is for */
- long gen; /* pm_eptgen when it was emptied */
+ long gen; /* nested_ept01_gen() when emptied */
cpuset_t clean; /* CPUs that have nothing old cached */
};
@@ -821,6 +825,20 @@
CPU_ZERO(&ept->clean);
}
+/*
+ * The generation of EPT01 that the tree depends on: pm_eptgen without the
+ * changes that only cleared an accessed flag. pm_eptgen is read first and
+ * pm_eptgen_ad is counted up first, so a change is never missed.
+ */
+static long
+nested_ept01_gen(pmap_t pmap)
+{
+ long gen;
+
+ gen = atomic_load_acq_long(&pmap->pm_eptgen);
+ return (gen - atomic_load_acq_long(&pmap->pm_eptgen_ad));
+}
+
/* The vCPU's tree, for L1's EPTP. The vCPU is frozen: this may sleep. */
static struct nested_ept *
nested_ept_get(struct vmx_nested *nested, uint64_t eptp12)
@@ -1259,7 +1277,7 @@
}
/* Read the generation before EPT01 itself. */
- gen = atomic_load_acq_long(&pmap->pm_eptgen);
+ gen = nested_ept01_gen(pmap);
if (gen != ept->gen) {
ept->gen = gen;
nested_ept_reset(ept);
@@ -1344,7 +1362,7 @@
if (!vcpu->nested->ept_active)
return;
- gen = atomic_load_long(&pmap->pm_eptgen);
+ gen = nested_ept01_gen(pmap);
if (gen != ept->gen) {
ept->gen = gen;
nested_ept_reset(ept);

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 24, 8:50 AM (22 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41951164
Default Alt Text
D61940.1795510242.diff (2 KB)

Event Timeline