From: guenther Date: Wed, 31 Jan 2024 05:49:33 +0000 (+0000) Subject: Make wrpkru() consistent with rdpkru() by passing ecx as an argument. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7d13b9d97f0bb94501100f764f91d485a6d4c156;p=openbsd Make wrpkru() consistent with rdpkru() by passing ecx as an argument. ok mlarkin@ --- diff --git a/sys/arch/amd64/amd64/vmm_machdep.c b/sys/arch/amd64/amd64/vmm_machdep.c index 53f4424dc48..0bbd2a407bb 100644 --- a/sys/arch/amd64/amd64/vmm_machdep.c +++ b/sys/arch/amd64/amd64/vmm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm_machdep.c,v 1.15 2024/01/11 17:13:48 jan Exp $ */ +/* $OpenBSD: vmm_machdep.c,v 1.16 2024/01/31 05:49:33 guenther Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -4187,7 +4187,7 @@ vcpu_run_vmx(struct vcpu *vcpu, struct vm_run_params *vrp) /* Restore any guest PKRU state. */ if (vmm_softc->sc_md.pkru_enabled) - wrpkru(vcpu->vc_pkru); + wrpkru(0, vcpu->vc_pkru); ret = vmx_enter_guest(&vcpu->vc_control_pa, &vcpu->vc_gueststate, @@ -4197,7 +4197,7 @@ vcpu_run_vmx(struct vcpu *vcpu, struct vm_run_params *vrp) /* Restore host PKRU state. */ if (vmm_softc->sc_md.pkru_enabled) { vcpu->vc_pkru = rdpkru(0); - wrpkru(PGK_VALUE); + wrpkru(0, PGK_VALUE); } lidt(&idtr); @@ -6500,7 +6500,7 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp) /* Restore any guest PKRU state. */ if (vmm_softc->sc_md.pkru_enabled) - wrpkru(vcpu->vc_pkru); + wrpkru(0, vcpu->vc_pkru); KASSERT(vmcb->v_intercept1 & SVM_INTERCEPT_INTR); wrmsr(MSR_AMD_VM_HSAVE_PA, vcpu->vc_svm_hsa_pa); @@ -6511,7 +6511,7 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp) /* Restore host PKRU state. */ if (vmm_softc->sc_md.pkru_enabled) { vcpu->vc_pkru = rdpkru(0); - wrpkru(PGK_VALUE); + wrpkru(0, PGK_VALUE); } /* diff --git a/sys/arch/amd64/include/cpufunc.h b/sys/arch/amd64/include/cpufunc.h index 0db2d135380..563ccbfacc5 100644 --- a/sys/arch/amd64/include/cpufunc.h +++ b/sys/arch/amd64/include/cpufunc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpufunc.h,v 1.39 2023/01/30 02:32:01 dv Exp $ */ +/* $OpenBSD: cpufunc.h,v 1.40 2024/01/31 05:49:33 guenther Exp $ */ /* $NetBSD: cpufunc.h,v 1.3 2003/05/08 10:27:43 fvdl Exp $ */ /*- @@ -241,10 +241,10 @@ rdpkru(u_int ecx) } static __inline void -wrpkru(uint32_t pkru) +wrpkru(u_int ecx, uint32_t pkru) { - uint32_t ecx = 0, edx = 0; - __asm volatile("wrpkru" : : "a" (pkru), "c" (ecx), "d" (edx)); + uint32_t edx = 0; + asm volatile("wrpkru" : : "a" (pkru), "c" (ecx), "d" (edx)); } static __inline void