summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/include/x86_64
diff options
context:
space:
mode:
authorAaron Lewis <aaronlewis@google.com>2023-04-05 03:45:17 +0300
committerSean Christopherson <seanjc@google.com>2023-04-11 20:19:03 +0300
commitb213812d3f4c29502d46f82e40a82cf959670e58 (patch)
tree4b6ddecec98e61a0b14d83524234d52f35795e3d /tools/testing/selftests/kvm/include/x86_64
parent55cd57b596e86140503214eafc8fb62c9c544e8f (diff)
downloadlinux-b213812d3f4c29502d46f82e40a82cf959670e58.tar.xz
KVM: selftests: Move XGETBV and XSETBV helpers to common code
The instructions XGETBV and XSETBV are useful to other tests. Move them to processor.h to make them more broadly available. No functional change intended. Reviewed-by: Jim Mattson <jmattson@google.com> Signed-off-by: Aaron Lewis <aaronlewis@google.com> Reviewed-by: Mingwei Zhang <mizhang@google.com> [sean: reword shortlog] Reviewed-by: Aaron Lewis <aaronlewis@google.com> Tested-by: Aaron Lewis <aaronlewis@google.com> Link: https://lore.kernel.org/r/20230405004520.421768-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include/x86_64')
-rw-r--r--tools/testing/selftests/kvm/include/x86_64/processor.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 3538fa6db72d..f6061fe7057f 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -510,6 +510,24 @@ static inline void set_cr4(uint64_t val)
__asm__ __volatile__("mov %0, %%cr4" : : "r" (val) : "memory");
}
+static inline u64 xgetbv(u32 index)
+{
+ u32 eax, edx;
+
+ __asm__ __volatile__("xgetbv;"
+ : "=a" (eax), "=d" (edx)
+ : "c" (index));
+ return eax | ((u64)edx << 32);
+}
+
+static inline void xsetbv(u32 index, u64 value)
+{
+ u32 eax = value;
+ u32 edx = value >> 32;
+
+ __asm__ __volatile__("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
+}
+
static inline struct desc_ptr get_gdt(void)
{
struct desc_ptr gdt;