vmm(4): expose PKU cpuid bit if in use on host.
authordv <dv@openbsd.org>
Mon, 30 Jan 2023 14:05:36 +0000 (14:05 +0000)
committerdv <dv@openbsd.org>
Mon, 30 Jan 2023 14:05:36 +0000 (14:05 +0000)
We are using {rd,wr}pkru instructions for saving and restoring the
PKRU, so tie the exposure of PKU feature bit to vmm having the
ability to properly handle the guest state.

sys/arch/amd64/amd64/vmm.c

index 55244ba..d8c8abc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vmm.c,v 1.336 2023/01/30 02:32:01 dv Exp $    */
+/*     $OpenBSD: vmm.c,v 1.337 2023/01/30 14:05:36 dv Exp $    */
 /*
  * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
  *
@@ -7035,6 +7035,14 @@ vmm_handle_cpuid(struct vcpu *vcpu)
                        *rbx = curcpu()->ci_feature_sefflags_ebx & VMM_SEFF0EBX_MASK;
                        *rcx = curcpu()->ci_feature_sefflags_ecx & VMM_SEFF0ECX_MASK;
                        *rdx = curcpu()->ci_feature_sefflags_edx & VMM_SEFF0EDX_MASK;
+                       /*
+                        * Only expose PKU support if we've detected it in use
+                        * on the host.
+                        */
+                       if (vmm_softc->pkru_enabled)
+                               *rcx |= SEFF0ECX_PKU;
+                       else
+                               *rcx &= ~SEFF0ECX_PKU;
                } else {
                        /* Unsupported subleaf */
                        DPRINTF("%s: function 0x07 (SEFF) unsupported subleaf "