Adapt inv{vpid,ept} to return success or failure.
authordv <dv@openbsd.org>
Tue, 28 Nov 2023 00:17:48 +0000 (00:17 +0000)
committerdv <dv@openbsd.org>
Tue, 28 Nov 2023 00:17:48 +0000 (00:17 +0000)
ok mlarkin@

sys/arch/amd64/amd64/vmm_support.S
sys/arch/amd64/include/vmmvar.h

index 8b4d44b..7b7d9f2 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vmm_support.S,v 1.23 2023/04/14 23:56:57 dv Exp $     */
+/*     $OpenBSD: vmm_support.S,v 1.24 2023/11/28 00:17:48 dv Exp $     */
 /*
  * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
  *
@@ -129,9 +129,19 @@ ENTRY(vmread)
        lfence
 END(vmread)
 
+/*
+ * Intel SDM Vol 3C, 31.2 defines different "vmfail" types, but there's no
+ * need to distinguish between CF=1 and ZF=1 for invvpid or invept.
+ */
 ENTRY(invvpid)
        RETGUARD_SETUP(invvpid, r11)
        invvpid (%rsi), %rdi
+        jbe     invvpid_fail
+        xorq    %rax, %rax
+        jmp     invvpid_ret
+invvpid_fail:
+        movq    $1, %rax
+invvpid_ret:
        RETGUARD_CHECK(invvpid, r11)
        ret
        lfence
@@ -139,7 +149,13 @@ END(invvpid)
 
 ENTRY(invept)
        RETGUARD_SETUP(invept, r11)
-       invept (%rsi), %rdi
+       invept  (%rsi), %rdi
+        jbe     invept_fail
+        xorq    %rax, %rax
+        jmp     invept_ret
+invept_fail:
+        movq    $1, %rax
+invept_ret:
        RETGUARD_CHECK(invept, r11)
        ret
        lfence
index fe55eef..0047143 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vmmvar.h,v 1.94 2023/09/06 03:35:57 dv Exp $  */
+/*     $OpenBSD: vmmvar.h,v 1.95 2023/11/28 00:17:48 dv Exp $  */
 /*
  * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
  *
@@ -919,8 +919,8 @@ int vmptrld(paddr_t *);
 int    vmptrst(paddr_t *);
 int    vmwrite(uint64_t, uint64_t);
 int    vmread(uint64_t, uint64_t *);
-void   invvpid(uint64_t, struct vmx_invvpid_descriptor *);
-void   invept(uint64_t, struct vmx_invept_descriptor *);
+int    invvpid(uint64_t, struct vmx_invvpid_descriptor *);
+int    invept(uint64_t, struct vmx_invept_descriptor *);
 int    vmx_enter_guest(paddr_t *, struct vcpu_gueststate *, int, uint8_t);
 int    svm_enter_guest(uint64_t, struct vcpu_gueststate *,
     struct region_descriptor *);