Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91CE1C83013 for ; Wed, 2 Jul 2025 07:18:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWrjA-00062e-Jx; Wed, 02 Jul 2025 03:17:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWrj8-00062R-Iw for qemu-devel@nongnu.org; Wed, 02 Jul 2025 03:17:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWrj4-0004Kr-Ui for qemu-devel@nongnu.org; Wed, 02 Jul 2025 03:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751440666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=iecUQKlR19Eeq6+NuFSZuu2ia1SJZmWENlL7bhUekB0=; b=X/b4gsigAXBZIx5ClQ/BzbuCiGxYV16E0l88wJ0zC6pZE1uh9f3wrezNgG/ZTJUBmQM2Cw YDny2W+YZa37xhliXNvP2axXBXjicsNX4uOdcoUy8tCvwieFzOnSfpk3VZKfSvkNeeuCu8 6GjQyVjFXmZIDi9vA6XklhRWdgnhLX0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632--OdSylOtPIWrSfuhgZd9aA-1; Wed, 02 Jul 2025 03:17:45 -0400 X-MC-Unique: -OdSylOtPIWrSfuhgZd9aA-1 X-Mimecast-MFC-AGG-ID: -OdSylOtPIWrSfuhgZd9aA_1751440664 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a4fac7fa27so1426691f8f.0 for ; Wed, 02 Jul 2025 00:17:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751440664; x=1752045464; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iecUQKlR19Eeq6+NuFSZuu2ia1SJZmWENlL7bhUekB0=; b=ZCWEZ4/eqM9oU2g+qS4fsk+IOvFUbDf/LukZP/L5NTO6xLDgsIBXt9nMYFQjvMjfPJ RppQPZIjM9bRLfEMp0f43cxWY+YccV9rBfXqo3LfT+EhR48w9q0zwSYKZJxozp+EWv61 klVNBDNOx2Y2nRO0DQqHkO+c/yFOwjM5rSyGJFzuwqIrbIJiHOPfYUMT8xNAeS16KqNE wvNQkcwquki1n9Zla0MLuedw6uesqlxJZvn7h3MsMXMlXnvRI7+AeuWETS3tSQJOJUAq vACcOaATt7PlhPGIOXOl/mSN6aGOYjHtJ0w4E4vU8F94Re4cKlKRyiHFXXsaK35rxjuM bItw== X-Forwarded-Encrypted: i=1; AJvYcCVNF9FF7G8MuUYMSPLfA/Xtnxcq5QJ4GnWF6s44ijqwVLruE/bGbCKNvet9cae28O3q7CbD/Y2APVMV@nongnu.org X-Gm-Message-State: AOJu0YyH9cY0ZdJx/w7NrKlw9dzz+SsSfM2loqyPdIkTlhKtdPxche0z tbdv/F7ki0QyX+71viF1N9j1JDXfnlRGz6Gy/W9dkrUlGe2yCbfQTKZxhz3QS1xyJx7/FP0mAq9 31mmgFITi7mhw57vm1WJpbhYnyz6Vp3xInY/+IwJyp7t+MNwfcv7M1vAk X-Gm-Gg: ASbGncs3NryUtmzjxW2JLtV/0vjonpLw9lFvXT77+fpWRHDKfa3bufc93f8i5HZogSq 4N6F+FD7kyeG3gbdrs9cyZF9pTN+x5I0ca8jgUx3HmTGkGjwEmWaY4Hvw9GAGBjH8rYsp4EuREH dsKcLNK9KWkhwiMIq3btntanqtViJljTKDLmQNLQ6inzJAh8Th4uTmmTnI+TmhwJDHIvraf8LYa Jb2zlKzsQxoDUsnNNwJH07wDt2rqaI6+ysvodMFlm9TZ11gMRXTkIK54JfG2bBnomvk2WwxrvTG FHolX01ilKr2TJgxqZOeizORaiM+N2zwGuUoLh1H6b66zx9ochQkDlbfTa8q X-Received: by 2002:a05:6000:2c11:b0:3a6:d255:7eda with SMTP id ffacd0b85a97d-3b20095cf70mr710497f8f.28.1751440663995; Wed, 02 Jul 2025 00:17:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9eib0tBf+PbyDFqdlhNJk0Sb3OYLGjitCw00PNNq6q8maqIUwM7dzEKL682lq/1oZ9ogCuA== X-Received: by 2002:a05:6000:2c11:b0:3a6:d255:7eda with SMTP id ffacd0b85a97d-3b20095cf70mr710462f8f.28.1751440663393; Wed, 02 Jul 2025 00:17:43 -0700 (PDT) Received: from ?IPV6:2a01:e0a:280:24f0:9db0:474c:ff43:9f5c? ([2a01:e0a:280:24f0:9db0:474c:ff43:9f5c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-453822c6b9fsm218133625e9.0.2025.07.02.00.17.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Jul 2025 00:17:42 -0700 (PDT) Message-ID: <0c98026c-fe97-454e-adcf-017cd4549d83@redhat.com> Date: Wed, 2 Jul 2025 09:17:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V5 18/38] vfio-pci: preserve MSI To: Steven Sistare Cc: Alex Williamson , Yi Liu , Eric Auger , Zhenzhong Duan , "Michael S. Tsirkin" , Marcel Apfelbaum , Peter Xu , Fabiano Rosas , qemu-devel@nongnu.org References: <1749569991-25171-1-git-send-email-steven.sistare@oracle.com> <1749569991-25171-19-git-send-email-steven.sistare@oracle.com> Content-Language: en-US, fr From: =?UTF-8?Q?C=C3=A9dric_Le_Goater?= Autocrypt: addr=clg@redhat.com; keydata= xsFNBFu8o3UBEADP+oJVJaWm5vzZa/iLgpBAuzxSmNYhURZH+guITvSySk30YWfLYGBWQgeo 8NzNXBY3cH7JX3/a0jzmhDc0U61qFxVgrPqs1PQOjp7yRSFuDAnjtRqNvWkvlnRWLFq4+U5t yzYe4SFMjFb6Oc0xkQmaK2flmiJNnnxPttYwKBPd98WfXMmjwAv7QfwW+OL3VlTPADgzkcqj 53bfZ4VblAQrq6Ctbtu7JuUGAxSIL3XqeQlAwwLTfFGrmpY7MroE7n9Rl+hy/kuIrb/TO8n0 ZxYXvvhT7OmRKvbYuc5Jze6o7op/bJHlufY+AquYQ4dPxjPPVUT/DLiUYJ3oVBWFYNbzfOrV RxEwNuRbycttMiZWxgflsQoHF06q/2l4ttS3zsV4TDZudMq0TbCH/uJFPFsbHUN91qwwaN/+ gy1j7o6aWMz+Ib3O9dK2M/j/O/Ube95mdCqN4N/uSnDlca3YDEWrV9jO1mUS/ndOkjxa34ia 70FjwiSQAsyIwqbRO3CGmiOJqDa9qNvd2TJgAaS2WCw/TlBALjVQ7AyoPEoBPj31K74Wc4GS Rm+FSch32ei61yFu6ACdZ12i5Edt+To+hkElzjt6db/UgRUeKfzlMB7PodK7o8NBD8outJGS tsL2GRX24QvvBuusJdMiLGpNz3uqyqwzC5w0Fd34E6G94806fwARAQABzSJDw6lkcmljIExl IEdvYXRlciA8Y2xnQHJlZGhhdC5jb20+wsGRBBMBCAA7FiEEoPZlSPBIlev+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hNmIFR3fcalYr+9gD uVKe8BVz4atMOoktmt0GWTOC8P4= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hello Steve, On 7/1/25 18:12, Steven Sistare wrote: > Hi Cedric, what do we need to do to get this patch in, and the patch "preserve INTx"? > Just review, or are there conflicts to resolve? I haven't looked at it yet. I will before the end of the week. I should send the last VFIO PR for QEMU 10.1 on Friday. On PTO next week. Thanks, C. > > - Steve > > On 6/10/2025 11:39 AM, Steve Sistare wrote: >> Save the MSI message area as part of vfio-pci vmstate, and preserve the >> interrupt and notifier eventfd's.  migrate_incoming loads the MSI data, >> then the vfio-pci post_load handler finds the eventfds in CPR state, >> rebuilds vector data structures, and attaches the interrupts to the new >> KVM instance. >> >> Signed-off-by: Steve Sistare >> --- >>   hw/vfio/pci.h              |  2 + >>   include/hw/vfio/vfio-cpr.h |  8 ++++ >>   hw/vfio/cpr.c              | 97 ++++++++++++++++++++++++++++++++++++++++++++++ >>   hw/vfio/pci.c              | 54 ++++++++++++++++++++++++-- >>   4 files changed, 158 insertions(+), 3 deletions(-) >> >> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h >> index 6e4840d..4d1203c 100644 >> --- a/hw/vfio/pci.h >> +++ b/hw/vfio/pci.h >> @@ -217,6 +217,8 @@ void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector, >>   void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev); >>   void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev); >>   bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error **errp); >> +void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev); >> +void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr); >>   uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); >>   void vfio_pci_write_config(PCIDevice *pdev, >> diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h >> index 8bf85b9..25e74ee 100644 >> --- a/include/hw/vfio/vfio-cpr.h >> +++ b/include/hw/vfio/vfio-cpr.h >> @@ -15,6 +15,7 @@ >>   struct VFIOContainer; >>   struct VFIOContainerBase; >>   struct VFIOGroup; >> +struct VFIOPCIDevice; >>   typedef struct VFIOContainerCPR { >>       Error *blocker; >> @@ -52,6 +53,13 @@ void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer, >>   bool vfio_cpr_ram_discard_register_listener( >>       struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); >> +void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, >> +                             int nr, int fd); >> +int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name, >> +                            int nr); >> +void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name, >> +                               int nr); >> + >>   extern const VMStateDescription vfio_cpr_pci_vmstate; >>   #endif /* HW_VFIO_VFIO_CPR_H */ >> diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c >> index fdbb58e..e467373 100644 >> --- a/hw/vfio/cpr.c >> +++ b/hw/vfio/cpr.c >> @@ -9,6 +9,8 @@ >>   #include "hw/vfio/vfio-device.h" >>   #include "hw/vfio/vfio-cpr.h" >>   #include "hw/vfio/pci.h" >> +#include "hw/pci/msix.h" >> +#include "hw/pci/msi.h" >>   #include "migration/cpr.h" >>   #include "qapi/error.h" >>   #include "system/runstate.h" >> @@ -40,6 +42,69 @@ void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer) >>       migration_remove_notifier(&bcontainer->cpr_reboot_notifier); >>   } >> +#define STRDUP_VECTOR_FD_NAME(vdev, name)   \ >> +    g_strdup_printf("%s_%s", (vdev)->vbasedev.name, (name)) >> + >> +void vfio_cpr_save_vector_fd(VFIOPCIDevice *vdev, const char *name, int nr, >> +                             int fd) >> +{ >> +    g_autofree char *fdname = STRDUP_VECTOR_FD_NAME(vdev, name); >> +    cpr_save_fd(fdname, nr, fd); >> +} >> + >> +int vfio_cpr_load_vector_fd(VFIOPCIDevice *vdev, const char *name, int nr) >> +{ >> +    g_autofree char *fdname = STRDUP_VECTOR_FD_NAME(vdev, name); >> +    return cpr_find_fd(fdname, nr); >> +} >> + >> +void vfio_cpr_delete_vector_fd(VFIOPCIDevice *vdev, const char *name, int nr) >> +{ >> +    g_autofree char *fdname = STRDUP_VECTOR_FD_NAME(vdev, name); >> +    cpr_delete_fd(fdname, nr); >> +} >> + >> +static void vfio_cpr_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors, >> +                                   bool msix) >> +{ >> +    int i, fd; >> +    bool pending = false; >> +    PCIDevice *pdev = &vdev->pdev; >> + >> +    vdev->nr_vectors = nr_vectors; >> +    vdev->msi_vectors = g_new0(VFIOMSIVector, nr_vectors); >> +    vdev->interrupt = msix ? VFIO_INT_MSIX : VFIO_INT_MSI; >> + >> +    vfio_pci_prepare_kvm_msi_virq_batch(vdev); >> + >> +    for (i = 0; i < nr_vectors; i++) { >> +        VFIOMSIVector *vector = &vdev->msi_vectors[i]; >> + >> +        fd = vfio_cpr_load_vector_fd(vdev, "interrupt", i); >> +        if (fd >= 0) { >> +            vfio_pci_vector_init(vdev, i); >> +            vfio_pci_msi_set_handler(vdev, i); >> +        } >> + >> +        if (vfio_cpr_load_vector_fd(vdev, "kvm_interrupt", i) >= 0) { >> +            vfio_pci_add_kvm_msi_virq(vdev, vector, i, msix); >> +        } else { >> +            vdev->msi_vectors[i].virq = -1; >> +        } >> + >> +        if (msix && msix_is_pending(pdev, i) && msix_is_masked(pdev, i)) { >> +            set_bit(i, vdev->msix->pending); >> +            pending = true; >> +        } >> +    } >> + >> +    vfio_pci_commit_kvm_msi_virq_batch(vdev); >> + >> +    if (msix) { >> +        memory_region_set_enabled(&pdev->msix_pba_mmio, pending); >> +    } >> +} >> + >>   /* >>    * The kernel may change non-emulated config bits.  Exclude them from the >>    * changed-bits check in get_pci_config_device. >> @@ -58,13 +123,45 @@ static int vfio_cpr_pci_pre_load(void *opaque) >>       return 0; >>   } >> +static int vfio_cpr_pci_post_load(void *opaque, int version_id) >> +{ >> +    VFIOPCIDevice *vdev = opaque; >> +    PCIDevice *pdev = &vdev->pdev; >> +    int nr_vectors; >> + >> +    if (msix_enabled(pdev)) { >> +        vfio_pci_msix_set_notifiers(vdev); >> +        nr_vectors = vdev->msix->entries; >> +        vfio_cpr_claim_vectors(vdev, nr_vectors, true); >> + >> +    } else if (msi_enabled(pdev)) { >> +        nr_vectors = msi_nr_vectors_allocated(pdev); >> +        vfio_cpr_claim_vectors(vdev, nr_vectors, false); >> + >> +    } else if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) { >> +        g_assert_not_reached();      /* completed in a subsequent patch */ >> +    } >> + >> +    return 0; >> +} >> + >> +static bool pci_msix_present(void *opaque, int version_id) >> +{ >> +    PCIDevice *pdev = opaque; >> + >> +    return msix_present(pdev); >> +} >> + >>   const VMStateDescription vfio_cpr_pci_vmstate = { >>       .name = "vfio-cpr-pci", >>       .version_id = 0, >>       .minimum_version_id = 0, >>       .pre_load = vfio_cpr_pci_pre_load, >> +    .post_load = vfio_cpr_pci_post_load, >>       .needed = cpr_incoming_needed, >>       .fields = (VMStateField[]) { >> +        VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice), >> +        VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, pci_msix_present), >>           VMSTATE_END_OF_LIST() >>       } >>   }; >> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c >> index 4cda6dc..b3dbb84 100644 >> --- a/hw/vfio/pci.c >> +++ b/hw/vfio/pci.c >> @@ -29,6 +29,7 @@ >>   #include "hw/pci/pci_bridge.h" >>   #include "hw/qdev-properties.h" >>   #include "hw/qdev-properties-system.h" >> +#include "hw/vfio/vfio-cpr.h" >>   #include "migration/vmstate.h" >>   #include "migration/cpr.h" >>   #include "qobject/qdict.h" >> @@ -57,13 +58,25 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev); >>   static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); >>   static void vfio_msi_disable_common(VFIOPCIDevice *vdev); >> +/* Create new or reuse existing eventfd */ >>   static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, >>                                  const char *name, int nr, Error **errp) >>   { >> -    int ret = event_notifier_init(e, 0); >> +    int fd = vfio_cpr_load_vector_fd(vdev, name, nr); >> +    int ret = 0; >> -    if (ret) { >> -        error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name); >> +    if (fd >= 0) { >> +        event_notifier_init_fd(e, fd); >> +    } else { >> +        ret = event_notifier_init(e, 0); >> +        if (ret) { >> +            error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name); >> +        } else { >> +            fd = event_notifier_get_fd(e); >> +            if (fd >= 0) { >> +                vfio_cpr_save_vector_fd(vdev, name, nr, fd); >> +            } >> +        } >>       } >>       return !ret; >>   } >> @@ -71,6 +84,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, >>   static void vfio_notifier_cleanup(VFIOPCIDevice *vdev, EventNotifier *e, >>                                     const char *name, int nr) >>   { >> +    vfio_cpr_delete_vector_fd(vdev, name, nr); >>       event_notifier_cleanup(e); >>   } >> @@ -394,6 +408,14 @@ static void vfio_msi_interrupt(void *opaque) >>       notify(&vdev->pdev, nr); >>   } >> +void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr) >> +{ >> +    VFIOMSIVector *vector = &vdev->msi_vectors[nr]; >> +    int fd = event_notifier_get_fd(&vector->interrupt); >> + >> +    qemu_set_fd_handler(fd, vfio_msi_interrupt, NULL, vector); >> +} >> + >>   /* >>    * Get MSI-X enabled, but no vector enabled, by setting vector 0 with an invalid >>    * fd to kernel. >> @@ -580,6 +602,15 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, >>       int ret; >>       bool resizing = !!(vdev->nr_vectors < nr + 1); >> +    /* >> +     * Ignore the callback from msix_set_vector_notifiers during resume. >> +     * The necessary subset of these actions is called from >> +     * vfio_cpr_claim_vectors during post load. >> +     */ >> +    if (cpr_is_incoming()) { >> +        return 0; >> +    } >> + >>       trace_vfio_msix_vector_do_use(vdev->vbasedev.name, nr); >>       vector = &vdev->msi_vectors[nr]; >> @@ -686,6 +717,12 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr) >>       } >>   } >> +void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev) >> +{ >> +    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, >> +                              vfio_msix_vector_release, NULL); >> +} >> + >>   void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev) >>   { >>       assert(!vdev->defer_kvm_irq_routing); >> @@ -2962,6 +2999,11 @@ static void vfio_register_err_notifier(VFIOPCIDevice *vdev) >>       fd = event_notifier_get_fd(&vdev->err_notifier); >>       qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); >> +    /* Do not alter irq_signaling during vfio_realize for cpr */ >> +    if (cpr_is_incoming()) { >> +        return; >> +    } >> + >>       if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, >>                                          VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { >>           error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); >> @@ -3029,6 +3071,12 @@ static void vfio_register_req_notifier(VFIOPCIDevice *vdev) >>       fd = event_notifier_get_fd(&vdev->req_notifier); >>       qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); >> +    /* Do not alter irq_signaling during vfio_realize for cpr */ >> +    if (cpr_is_incoming()) { >> +        vdev->req_enabled = true; >> +        return; >> +    } >> + >>       if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, >>                                          VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { >>           error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); >