[PATCH v8 42/55] cpu: Don't set vcpu_dirty when guest_state_protected

Xiaoyao Li posted 55 patches 10 months, 1 week ago
[PATCH v8 42/55] cpu: Don't set vcpu_dirty when guest_state_protected
Posted by Xiaoyao Li 10 months, 1 week ago
QEMU calls kvm_arch_put_registers() when vcpu_dirty is true in
kvm_vcpu_exec(). However, for confidential guest, like TDX, putting
registers is disallowed due to guest state is protected.

Only set vcpu_dirty to true with guest state is not protected when
creating the vcpu.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
Changes in v7:
 - new patch to replace "i386/tdx: Don't get/put guest state for TDX VMs"
   in v6;
---
 accel/kvm/kvm-all.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 5835d840f3ad..9862d8ff1d38 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -466,7 +466,9 @@ int kvm_create_vcpu(CPUState *cpu)
 
     cpu->kvm_fd = kvm_fd;
     cpu->kvm_state = s;
-    cpu->vcpu_dirty = true;
+    if (!s->guest_state_protected) {
+        cpu->vcpu_dirty = true;
+    }
     cpu->dirty_pages = 0;
     cpu->throttle_us_per_full = 0;
 
-- 
2.34.1
Re: [PATCH v8 42/55] cpu: Don't set vcpu_dirty when guest_state_protected
Posted by Zhao Liu 9 months, 1 week ago
On Tue, Apr 01, 2025 at 09:01:52AM -0400, Xiaoyao Li wrote:
> Date: Tue,  1 Apr 2025 09:01:52 -0400
> From: Xiaoyao Li <xiaoyao.li@intel.com>
> Subject: [PATCH v8 42/55] cpu: Don't set vcpu_dirty when
>  guest_state_protected
> X-Mailer: git-send-email 2.34.1
> 
> QEMU calls kvm_arch_put_registers() when vcpu_dirty is true in
> kvm_vcpu_exec(). However, for confidential guest, like TDX, putting
> registers is disallowed due to guest state is protected.
> 
> Only set vcpu_dirty to true with guest state is not protected when
> creating the vcpu.
> 
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> Changes in v7:
>  - new patch to replace "i386/tdx: Don't get/put guest state for TDX VMs"
>    in v6;
> ---
>  accel/kvm/kvm-all.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>