[RFC PATCH part-5 14/22] pkvm: x86: Add msr ops for pKVM hypervisor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add pkvm msr ops, avoid using Linux msr ops directly to remove the
dependency of link to EXTABLE.

Signed-off-by: Jason Chen CJ <jason.cj.chen@xxxxxxxxx>
---
 arch/x86/kvm/vmx/pkvm/hyp/cpu.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kvm/vmx/pkvm/hyp/cpu.h b/arch/x86/kvm/vmx/pkvm/hyp/cpu.h
index c49074292f7c..896c2984ffa6 100644
--- a/arch/x86/kvm/vmx/pkvm/hyp/cpu.h
+++ b/arch/x86/kvm/vmx/pkvm/hyp/cpu.h
@@ -13,6 +13,29 @@ static inline u64 pkvm_msr_read(u32 reg)
 	return (((u64)msrh << 32U) | msrl);
 }
 
+#define pkvm_rdmsr(msr, low, high)              \
+do {                                            \
+	u64 __val = pkvm_msr_read(msr);         \
+	(void)((low) = (u32)__val);             \
+	(void)((high) = (u32)(__val >> 32));    \
+} while (0)
+
+#define pkvm_rdmsrl(msr, val)                   \
+	((val) = pkvm_msr_read((msr)))
+
+static inline void pkvm_msr_write(u32 reg, u64 msr_val)
+{
+	asm volatile (" wrmsr " : : "c" (reg), "a" ((u32)msr_val), "d" ((u32)(msr_val >> 32U)));
+}
+
+#define pkvm_wrmsr(msr, low, high)              	\
+do {                                            	\
+	u64 __val = (u64)(high) << 32 | (u64)(low); 	\
+	pkvm_msr_write(msr, __val);             	\
+} while (0)
+
+#define pkvm_wrmsrl(msr, val)   pkvm_msr_write(msr, val)
+
 #ifdef CONFIG_PKVM_INTEL_DEBUG
 #include <linux/smp.h>
 static inline u64 get_pcpu_id(void)
-- 
2.25.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux