@samitouri / QOSamiQemu / commits / 06fd6ae044

kvm/i8254: add support for confidential guest reset

A confidential guest reset involves closing the old virtual machine KVM file descriptor and opening a new one. Since its a new KVM fd, PIT needs to be re-initialized again. This is done with the help of a notifier which is invoked upon KVM vm file descriptor change during the confidential guest reset process. Signed-off-by: Ani Sinha <anisinha@redhat.com> Link: https://lore.kernel.org/r/20260225035000.385950-26-anisinha@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Ani Sinha committed Feb 25, 2026 at 09:19 UTC 06fd6ae04444530f5117df5d77ba9d12b70c58ba
2 files changed +24
hw/i386/kvm/i8254.c
+23
@@ -35,6 +35,7 @@
35 #include "hw/core/qdev-properties-system.h"
36 #include "system/kvm.h"
37 #include "target/i386/kvm/kvm_i386.h"
38 +#include "trace.h"
39 #include "qom/object.h"
40
41 #define KVM_PIT_REINJECT_BIT 0
@@ -52,6 +53,8 @@ struct KVMPITState {
53 LostTickPolicy lost_tick_policy;
54 bool vm_stopped;
55 int64_t kernel_clock_offset;
56 +
57 + NotifierWithReturn kvmpit_vmfd_change_notifier;
58 };
59
60 struct KVMPITClass {
@@ -203,6 +206,23 @@ static void kvm_pit_put(PITCommonState *pit)
206 }
207 }
208
209 +static int kvmpit_post_vmfd_change(NotifierWithReturn *notifier,
210 + void *data, Error** errp)
211 +{
212 + KVMPITState *s = container_of(notifier, KVMPITState,
213 + kvmpit_vmfd_change_notifier);
214 +
215 + /* we are not interested in pre vmfd change notification */
216 + if (((VmfdChangeNotifier *)data)->pre) {
217 + return 0;
218 + }
219 +
220 + do_pit_initialize(s, errp);
221 +
222 + trace_kvmpit_post_vmfd_change();
223 + return 0;
224 +}
225 +
226 static void kvm_pit_set_gate(PITCommonState *s, PITChannelState *sc, int val)
227 {
228 kvm_pit_get(s);
@@ -292,6 +312,9 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)
312
313 qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s);
314
315 + s->kvmpit_vmfd_change_notifier.notify = kvmpit_post_vmfd_change;
316 + kvm_vmfd_add_change_notifier(&s->kvmpit_vmfd_change_notifier);
317 +
318 kpc->parent_realize(dev, errp);
319 }
320
hw/i386/kvm/trace-events
+1
@@ -20,3 +20,4 @@ xenstore_reset_watches(void) ""
20 xenstore_watch_event(const char *path, const char *token) "path %s token %s"
21 xen_primary_console_create(void) ""
22 xen_primary_console_reset(int port) "port %u"
23 +kvmpit_post_vmfd_change(void) ""