]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/testing/selftests/kvm/include/vmx.h
kvm: selftests: add test for nested state save/restore
[linux.git] / tools / testing / selftests / kvm / include / vmx.h
index 9caaf56696a4d963979030599395c40375e0191e..54e6020d06384af433d2e39d17ca1be78a39ce8c 100644 (file)
@@ -380,6 +380,30 @@ static inline int vmptrld(uint64_t vmcs_pa)
        return ret;
 }
 
+static inline int vmptrst(uint64_t *value)
+{
+       uint64_t tmp;
+       uint8_t ret;
+
+       __asm__ __volatile__("vmptrst %[value]; setna %[ret]"
+               : [value]"=m"(tmp), [ret]"=rm"(ret)
+               : : "cc", "memory");
+
+       *value = tmp;
+       return ret;
+}
+
+/*
+ * A wrapper around vmptrst that ignores errors and returns zero if the
+ * vmptrst instruction fails.
+ */
+static inline uint64_t vmptrstz(void)
+{
+       uint64_t value = 0;
+       vmptrst(&value);
+       return value;
+}
+
 /*
  * No guest state (e.g. GPRs) is established by this vmlaunch.
  */
@@ -444,6 +468,15 @@ static inline int vmresume(void)
        return ret;
 }
 
+static inline void vmcall(void)
+{
+       /* Currently, L1 destroys our GPRs during vmexits.  */
+       __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : :
+                            "rax", "rbx", "rcx", "rdx",
+                            "rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
+                            "r13", "r14", "r15");
+}
+
 static inline int vmread(uint64_t encoding, uint64_t *value)
 {
        uint64_t tmp;