From: dv Date: Mon, 30 Jan 2023 14:05:36 +0000 (+0000) Subject: vmm(4): expose PKU cpuid bit if in use on host. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ef14a9e8cae106563ff9ce15d913365f9ad3fa0e;p=openbsd vmm(4): expose PKU cpuid bit if in use on host. 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. --- diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 55244baa3e5..d8c8abc96f3 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -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 * @@ -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 "