Re: [RFC PATCH v5 102/104] KVM: TDX: Add methods to ignore accesses to CPU state

From: Xiaoyao Li
Date: Tue Apr 12 2022 - 05:28:44 EST


On 4/12/2022 2:52 PM, Paolo Bonzini wrote:
On 4/12/22 08:49, Xiaoyao Li wrote:

+void tdx_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg)
+{
+    kvm_register_mark_available(vcpu, reg);
+    switch (reg) {
+    case VCPU_REGS_RSP:
+    case VCPU_REGS_RIP:
+    case VCPU_EXREG_PDPTR:
+    case VCPU_EXREG_CR0:
+    case VCPU_EXREG_CR3:
+    case VCPU_EXREG_CR4:
+        break;
+    default:
+        KVM_BUG_ON(1, vcpu->kvm);
+        break;
+    }
+}

Isaku,

We missed one case that some GPRs are accessible by KVM/userspace for TDVMCALL exit.

If a register is not in the VMX_REGS_LAZY_LOAD_SET it will never be passed to tdx_cache_reg.  As far as I understand those TDVMCALL registers do not include either RSP or RIP.

Sorry, I should not keep the code snippet of tdx_cache_reg() as reference to mislead you and other people.

I just want to remind that in the certain case of TDVMCALL, GPRs might be accessible.

Paolo