On Tue, Jan 27, 2026 at 10:48 AM Ani Sinha <[email protected]> wrote: > > Once the vcpu file descriptors changed after confidential guest reset, the > local apic needs to be reinitialized. This change adds a callback from the > vcpu fd change notifiers to reinitialize local apic for kvm x86.
This change is not necessary as kvm_apic_reset() does the same thing as a part of the reset process. Will drop this patch in next spin up. > > Signed-off-by: Ani Sinha <[email protected]> > --- > hw/i386/kvm/apic.c | 13 +++++++++++++ > include/hw/i386/apic_internal.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c > index 82355f0463..f6f8ac2764 100644 > --- a/hw/i386/kvm/apic.c > +++ b/hw/i386/kvm/apic.c > @@ -229,6 +229,16 @@ static void kvm_apic_reset(APICCommonState *s) > run_on_cpu(CPU(s->cpu), kvm_apic_put, RUN_ON_CPU_HOST_PTR(s)); > } > > +static int apic_vcpufd_change_handler(NotifierWithReturn *n, > + void *data, Error** errp) { > + APICCommonState *s = container_of(n, APICCommonState, > + vcpufd_change_notifier); > + > + run_on_cpu(CPU(s->cpu), kvm_apic_put, RUN_ON_CPU_HOST_PTR(s)); > + > + return 0; > +} > + > static void kvm_apic_realize(DeviceState *dev, Error **errp) > { > APICCommonState *s = APIC_COMMON(dev); > @@ -238,6 +248,9 @@ static void kvm_apic_realize(DeviceState *dev, Error > **errp) > > assert(kvm_has_gsi_routing()); > msi_nonbroken = true; > + > + s->vcpufd_change_notifier.notify = apic_vcpufd_change_handler; > + kvm_vcpufd_add_change_notifier(&s->vcpufd_change_notifier); > } > > static void kvm_apic_unrealize(DeviceState *dev) > diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h > index 4a62fdceb4..ffe5815e7f 100644 > --- a/include/hw/i386/apic_internal.h > +++ b/include/hw/i386/apic_internal.h > @@ -189,6 +189,7 @@ struct APICCommonState { > hwaddr vapic_paddr; /* note: persistence via kvmvapic */ > bool legacy_instance_id; > uint32_t extended_log_dest; > + NotifierWithReturn vcpufd_change_notifier; > }; > > typedef struct VAPICState { > -- > 2.42.0 >
