[kvm-unit-tests RFC v2 06/18] x86 TDX: Bypass wrmsr simulation on some specific MSRs

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

 



From: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx>

In TDX scenario, some MSRs are initialized with expected value and not
expected to be changed in TD-guest.

Writing to MSR_IA32_TSC, MSR_IA32_APICBASE, MSR_EFER in TD-guest
triggers #VE. In #VE handler these MSR accesses are simulated with
tdvmcall. But in current TDX host side implementation, they are bypassed
and return failure.

In order to let test cases touching those MSRs run smoothly, bypass
writing to those MSRs in #VE handler just like writing succeed.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx>
Reviewed-by: Yu Zhang <yu.c.zhang@xxxxxxxxx>
Link: https://lore.kernel.org/r/20220303071907.650203-6-zhenzhong.duan@xxxxxxxxx
Signed-off-by: Qian Wen <qian.wen@xxxxxxxxx>
---
 lib/x86/tdx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/x86/tdx.c b/lib/x86/tdx.c
index 4f8bbad7..3909e283 100644
--- a/lib/x86/tdx.c
+++ b/lib/x86/tdx.c
@@ -144,8 +144,23 @@ static int read_msr(struct ex_regs *regs, struct ve_info *ve)
 	return ve_instr_len(ve);
 }
 
+static bool tdx_is_bypassed_msr(u32 index)
+{
+	switch (index) {
+	case MSR_IA32_TSC:
+	case MSR_IA32_APICBASE:
+	case MSR_EFER:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static int write_msr(struct ex_regs *regs, struct ve_info *ve)
 {
+	if (tdx_is_bypassed_msr(regs->rcx))
+		goto finish_wrmsr;
+
 	struct tdx_module_args args = {
 		.r10 = TDX_HYPERCALL_STANDARD,
 		.r11 = hcall_func(EXIT_REASON_MSR_WRITE),
@@ -161,6 +176,7 @@ static int write_msr(struct ex_regs *regs, struct ve_info *ve)
 	if (__tdx_hypercall(&args))
 		return -EIO;
 
+finish_wrmsr:
 	return ve_instr_len(ve);
 }
 
-- 
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