Make wrpkru() consistent with rdpkru() by passing ecx as an argument.
authorguenther <guenther@openbsd.org>
Wed, 31 Jan 2024 05:49:33 +0000 (05:49 +0000)
committerguenther <guenther@openbsd.org>
Wed, 31 Jan 2024 05:49:33 +0000 (05:49 +0000)
ok mlarkin@

sys/arch/amd64/amd64/vmm_machdep.c
sys/arch/amd64/include/cpufunc.h

index 53f4424..0bbd2a4 100644 (file)
@@ -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 <mlarkin@openbsd.org>
  *
@@ -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);
                }
 
                /*
index 0db2d13..563ccbf 100644 (file)
@@ -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