Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178002981
D62064.1795737658.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D62064.1795737658.diff
View Options
diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h
--- a/sys/amd64/include/vmm.h
+++ b/sys/amd64/include/vmm.h
@@ -135,6 +135,8 @@
uint32_t exc_errcode; \
struct savefpu *guestfpu; /* (a,i) guest fpu state */ \
uint64_t guest_xcr0; /* (i) guest %xcr0 register */ \
+ uint32_t guest_pkru; /* (i) guest PKRU register */ \
+ uint32_t host_pkru; /* (x) host PKRU while in guest */ \
struct vm_exit exitinfo; /* (x) exit reason and collateral */ \
cpuset_t exitinfo_cpuset; /* (x) storage for vmexit handlers */ \
uint64_t nextrip; /* (x) next instruction to execute */ \
diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -250,6 +250,7 @@
vcpu->extint_pending = 0;
vcpu->exception_pending = 0;
vcpu->guest_xcr0 = XFEATURE_ENABLED_X87;
+ vcpu->guest_pkru = 0;
fpu_save_area_reset(vcpu->guestfpu);
vmm_stat_init(vcpu->stats);
}
@@ -699,6 +700,17 @@
* the FPU to trap any access by the host.
*/
fpu_disable();
+
+ /*
+ * PKRU is switched with the thread, not with the FPU state, and
+ * neither VMX nor SVM switches it on entry and exit. Give the
+ * guest its own value.
+ */
+ if (fpu_pku_enabled()) {
+ vcpu->host_pkru = rdpkru();
+ if (vcpu->guest_pkru != vcpu->host_pkru)
+ wrpkru(vcpu->guest_pkru);
+ }
}
static void
@@ -708,6 +720,13 @@
if ((rcr0() & CR0_TS) == 0)
panic("fpu emulation not enabled in host!");
+ /* save guest PKRU and restore the host thread's */
+ if (fpu_pku_enabled()) {
+ vcpu->guest_pkru = rdpkru();
+ if (vcpu->guest_pkru != vcpu->host_pkru)
+ wrpkru(vcpu->host_pkru);
+ }
+
/* save guest XCR0 and restore host XCR0 */
if (rcr4() & CR4_XSAVE) {
vcpu->guest_xcr0 = rxcr(0);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 27, 12:00 AM (10 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42026383
Default Alt Text
D62064.1795737658.diff (1 KB)
Attached To
Mode
D62064: vmm: Switch PKRU around guest execution
Attached
Detach File
Event Timeline