[PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset

Ani Sinha posted 32 patches 4 weeks ago
[PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset
Posted by Ani Sinha 4 weeks ago
On confidential guests when the KVM virtual machine file descriptor changes as
a part of the reset process, event file descriptors needs to be reassociated
with the new KVM VM file descriptor. This is achieved with the help of a
callback handler that gets called when KVM VM file descriptor changes during
the confidential guest reset process.

This patch is untested on confidential guests and only exists for completeness.

Signed-off-by: Ani Sinha <anisinha@redhat.com>
---
 hw/hyperv/vmbus.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index c5bab5d245..947fb7f4f8 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -20,6 +20,7 @@
 #include "hw/hyperv/vmbus-bridge.h"
 #include "hw/core/sysbus.h"
 #include "exec/cpu-common.h"
+#include "system/kvm.h"
 #include "exec/target_page.h"
 #include "trace.h"
 
@@ -248,6 +249,12 @@ struct VMBus {
      * interrupt page
      */
     EventNotifier notifier;
+
+    /*
+     * Notifier to inform when vmfd is changed as a part of confidential guest
+     * reset mechanism.
+     */
+    NotifierWithReturn vmbus_vmfd_change_notifier;
 };
 
 static bool gpadl_full(VMBusGpadl *gpadl)
@@ -2347,6 +2354,26 @@ static void vmbus_dev_unrealize(DeviceState *dev)
     free_channels(vdev);
 }
 
+/*
+ * If the KVM fd changes because of VM reset in confidential guests,
+ * reassociate event fd with the new KVM fd.
+ */
+static int vmbus_handle_vmfd_change(NotifierWithReturn *notifier,
+                                    void *data, Error** errp)
+{
+    VMBus *vmbus = container_of(notifier, VMBus,
+                                vmbus_vmfd_change_notifier);
+    int ret = 0;
+    ret = hyperv_set_event_flag_handler(VMBUS_EVENT_CONNECTION_ID,
+                                            &vmbus->notifier);
+    /* if we are only using userland event handler, it may already exist */
+    if (ret != 0 && ret != -EEXIST) {
+        error_setg(errp, "hyperv set event handler failed with %d", ret);
+    }
+
+    return ret;
+}
+
 static const Property vmbus_dev_props[] = {
     DEFINE_PROP_UUID("instanceid", VMBusDevice, instanceid),
 };
@@ -2429,6 +2456,9 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
+    vmbus->vmbus_vmfd_change_notifier.notify = vmbus_handle_vmfd_change;
+    kvm_vmfd_add_change_notifier(&vmbus->vmbus_vmfd_change_notifier);
+
     return;
 
 clear_event_notifier:
-- 
2.42.0
Re: [PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset
Posted by Maciej S. Szmigiero 3 weeks, 5 days ago
On 12.01.2026 14:22, Ani Sinha wrote:
> On confidential guests when the KVM virtual machine file descriptor changes as
> a part of the reset process, event file descriptors needs to be reassociated
> with the new KVM VM file descriptor. This is achieved with the help of a
> callback handler that gets called when KVM VM file descriptor changes during
> the confidential guest reset process.
> 
> This patch is untested on confidential guests and only exists for completeness.
> 
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> ---
>   hw/hyperv/vmbus.c | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 

Quick question: is this patch set targeting QEMU 11.0 or which version?

Thanks,
Maciej
Re: [PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset
Posted by Daniel P. Berrangé 3 weeks, 5 days ago
On Wed, Jan 14, 2026 at 02:38:54PM +0100, Maciej S. Szmigiero wrote:
> On 12.01.2026 14:22, Ani Sinha wrote:
> > On confidential guests when the KVM virtual machine file descriptor changes as
> > a part of the reset process, event file descriptors needs to be reassociated
> > with the new KVM VM file descriptor. This is achieved with the help of a
> > callback handler that gets called when KVM VM file descriptor changes during
> > the confidential guest reset process.
> > 
> > This patch is untested on confidential guests and only exists for completeness.
> > 
> > Signed-off-by: Ani Sinha <anisinha@redhat.com>
> > ---
> >   hw/hyperv/vmbus.c | 30 ++++++++++++++++++++++++++++++
> >   1 file changed, 30 insertions(+)
> > 
> 
> Quick question: is this patch set targeting QEMU 11.0 or which version?

Patches are always assumed to be targetting current git master unless
the cover letter / subject line explicity says otherwise.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset
Posted by Maciej S. Szmigiero 3 weeks, 5 days ago
On 14.01.2026 14:42, Daniel P. Berrangé wrote:
> On Wed, Jan 14, 2026 at 02:38:54PM +0100, Maciej S. Szmigiero wrote:
>> On 12.01.2026 14:22, Ani Sinha wrote:
>>> On confidential guests when the KVM virtual machine file descriptor changes as
>>> a part of the reset process, event file descriptors needs to be reassociated
>>> with the new KVM VM file descriptor. This is achieved with the help of a
>>> callback handler that gets called when KVM VM file descriptor changes during
>>> the confidential guest reset process.
>>>
>>> This patch is untested on confidential guests and only exists for completeness.
>>>
>>> Signed-off-by: Ani Sinha <anisinha@redhat.com>
>>> ---
>>>    hw/hyperv/vmbus.c | 30 ++++++++++++++++++++++++++++++
>>>    1 file changed, 30 insertions(+)
>>>
>>
>> Quick question: is this patch set targeting QEMU 11.0 or which version?
> 
> Patches are always assumed to be targetting current git master unless
> the cover letter / subject line explicity says otherwise.

I was asking more what QEMU release the submitter thinks this patch set
will make rather than against which git tree it is based on but thanks anyway.
  
> With regards,
> Daniel

Thanks,
Maciej


Re: [PATCH v2 23/32] hw/hyperv/vmbus: add support for confidential guest reset
Posted by Ani Sinha 3 weeks, 4 days ago
On Wed, Jan 14, 2026 at 8:10 PM Maciej S. Szmigiero
<mail@maciej.szmigiero.name> wrote:
>
> On 14.01.2026 14:42, Daniel P. Berrangé wrote:
> > On Wed, Jan 14, 2026 at 02:38:54PM +0100, Maciej S. Szmigiero wrote:
> >> On 12.01.2026 14:22, Ani Sinha wrote:
> >>> On confidential guests when the KVM virtual machine file descriptor changes as
> >>> a part of the reset process, event file descriptors needs to be reassociated
> >>> with the new KVM VM file descriptor. This is achieved with the help of a
> >>> callback handler that gets called when KVM VM file descriptor changes during
> >>> the confidential guest reset process.
> >>>
> >>> This patch is untested on confidential guests and only exists for completeness.
> >>>
> >>> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> >>> ---
> >>>    hw/hyperv/vmbus.c | 30 ++++++++++++++++++++++++++++++
> >>>    1 file changed, 30 insertions(+)
> >>>
> >>
> >> Quick question: is this patch set targeting QEMU 11.0 or which version?
> >
> > Patches are always assumed to be targetting current git master unless
> > the cover letter / subject line explicity says otherwise.
>
> I was asking more what QEMU release the submitter thinks this patch set
> will make rather than against which git tree it is based on but thanks anyway.

Looking at https://wiki.qemu.org/Planning/11.0, I am not sure if we
will make it in 11.0 since the soft freeze is March 10. Perhaps 11.1