From: Alex Williamson <alex.williamson@redhat.com>
To: Yan Zhao <yan.y.zhao@intel.com>
Cc: cohuck@redhat.com, cjia@nvidia.com, zhi.wang.linux@gmail.com,
aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com,
shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org,
peterx@redhat.com, Kirti Wankhede <kwankhede@nvidia.com>,
eauger@redhat.com, artemp@nvidia.com, yi.l.liu@intel.com,
quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com,
mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com,
zhi.a.wang@intel.com, mcrossley@nvidia.com, kevin.tian@intel.com,
dgilbert@redhat.com, changpeng.liu@intel.com,
eskultet@redhat.com, Ken.Xue@amd.com,
jonathan.davies@nutanix.com, pbonzini@redhat.com,
dnigam@nvidia.com
Subject: Re: [PATCH v28 03/17] vfio: Add save and load functions for VFIO PCI devices
Date: Sat, 24 Oct 2020 08:16:30 -0600 [thread overview]
Message-ID: <20201024081630.29d3a2bf@x1.home> (raw)
In-Reply-To: <20201024115327.GA11667@yzhao56-desk>
On Sat, 24 Oct 2020 19:53:39 +0800
Yan Zhao <yan.y.zhao@intel.com> wrote:
> hi
> when I migrating VFs, the PCI_COMMAND is not properly saved. and the
> target side would meet below bug
> root@tester:~# [ 189.360671] ++++++++++>> reset starts here: iavf_reset_task !!!
> [ 199.360798] iavf 0000:00:04.0: Reset never finished (0)
> [ 199.380504] kernel BUG at drivers/pci/msi.c:352!
> [ 199.382957] invalid opcode: 0000 [#1] SMP PTI
> [ 199.384855] CPU: 1 PID: 419 Comm: kworker/1:2 Tainted: G OE 5.0.0-13-generic #14-Ubuntu
> [ 199.388204] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
> [ 199.392401] Workqueue: events iavf_reset_task [iavf]
> [ 199.393586] RIP: 0010:free_msi_irqs+0x17b/0x1b0
> [ 199.394659] Code: 84 e1 fe ff ff 45 31 f6 eb 11 41 83 c6 01 44 39 73 14 0f 86 ce fe ff ff 8b 7b 10 44 01 f7 e8 3c 7a ba ff 48 83 78 70 00 74 e0 <0f> 0b 49 8d b5 b0 00 00 00 e8 07 27 bb ff e9 cf fe ff ff 48 8b 78
> [ 199.399056] RSP: 0018:ffffabd1006cfdb8 EFLAGS: 00010282
> [ 199.400302] RAX: ffff9e336d8a2800 RBX: ffff9e3333b006c0 RCX: 0000000000000000
> [ 199.402000] RDX: 0000000000000000 RSI: 0000000000000019 RDI: ffffffffbaa68100
> [ 199.403168] RBP: ffffabd1006cfde8 R08: ffff9e3375000248 R09: ffff9e3375000338
> [ 199.404343] R10: 0000000000000000 R11: ffffffffbaa68108 R12: ffff9e3374ef12c0
> [ 199.405526] R13: ffff9e3374ef1000 R14: 0000000000000000 R15: ffff9e3371f2d018
> [ 199.406702] FS: 0000000000000000(0000) GS:ffff9e3375b00000(0000) knlGS:0000000000000000
> [ 199.408027] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [ 199.408987] CR2: 00000000ffffffff CR3: 0000000033266000 CR4: 00000000000006e0
> [ 199.410155] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> [ 199.411321] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> [ 199.412437] Call Trace:
> [ 199.412750] pci_disable_msix+0xf3/0x120
> [ 199.413227] iavf_reset_interrupt_capability.part.40+0x19/0x40 [iavf]
> [ 199.413998] iavf_reset_task+0x4b3/0x9d0 [iavf]
> [ 199.414544] process_one_work+0x20f/0x410
> [ 199.415026] worker_thread+0x34/0x400
> [ 199.415486] kthread+0x120/0x140
> [ 199.415876] ? process_one_work+0x410/0x410
> [ 199.416380] ? __kthread_parkme+0x70/0x70
> [ 199.416864] ret_from_fork+0x35/0x40
>
> I fixed it with below patch.
>
>
> commit ad3efa0eeea7edb352294bfce35b904b8d3c759c
> Author: Yan Zhao <yan.y.zhao@intel.com>
> Date: Sat Oct 24 19:45:01 2020 +0800
>
> msix fix.
>
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index f63f15b553..92f71bf933 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2423,8 +2423,14 @@ const VMStateDescription vmstate_vfio_pci_config = {
> static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f)
> {
> VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> + PCIDevice *pdev = &vdev->pdev;
> + uint16_t pci_cmd;
> +
> + pci_cmd = pci_default_read_config(pdev, PCI_COMMAND, 2);
> + qemu_put_be16(f, pci_cmd);
>
> vmstate_save_state(f, &vmstate_vfio_pci_config, vdev, NULL);
> +
> }
>
> static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
> @@ -2432,6 +2438,10 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
> VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> PCIDevice *pdev = &vdev->pdev;
> int ret;
> + uint16_t pci_cmd;
> +
> + pci_cmd = qemu_get_be16(f);
> + vfio_pci_write_config(pdev, PCI_COMMAND, pci_cmd, 2);
>
> ret = vmstate_load_state(f, &vmstate_vfio_pci_config, vdev, 1);
> if (ret) {
>
We need to avoid this sort of ad-hoc stuffing random fields into the
config stream. The command register is already migrated in vconfig, it
only needs to be written through vfio:
vfio_pci_write_config(pdev, PCI_COMMAND,
pci_get_word(pdev->config, PCI_COMMAND), 2);
Thanks,
Alex
> On Fri, Oct 23, 2020 at 04:10:29PM +0530, Kirti Wankhede wrote:
> > Added functions to save and restore PCI device specific data,
> > specifically config space of PCI device.
> >
> > Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> > Reviewed-by: Neo Jia <cjia@nvidia.com>
> > ---
> > hw/vfio/pci.c | 48 +++++++++++++++++++++++++++++++++++++++++++
> > include/hw/vfio/vfio-common.h | 2 ++
> > 2 files changed, 50 insertions(+)
> >
> > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> > index bffd5bfe3b78..92cc25a5489f 100644
> > --- a/hw/vfio/pci.c
> > +++ b/hw/vfio/pci.c
> > @@ -41,6 +41,7 @@
> > #include "trace.h"
> > #include "qapi/error.h"
> > #include "migration/blocker.h"
> > +#include "migration/qemu-file.h"
> >
> > #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
> >
> > @@ -2401,11 +2402,58 @@ static Object *vfio_pci_get_object(VFIODevice *vbasedev)
> > return OBJECT(vdev);
> > }
> >
> > +static bool vfio_msix_present(void *opaque, int version_id)
> > +{
> > + PCIDevice *pdev = opaque;
> > +
> > + return msix_present(pdev);
> > +}
> > +
> > +const VMStateDescription vmstate_vfio_pci_config = {
> > + .name = "VFIOPCIDevice",
> > + .version_id = 1,
> > + .minimum_version_id = 1,
> > + .fields = (VMStateField[]) {
> > + VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice),
> > + VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, vfio_msix_present),
> > + VMSTATE_END_OF_LIST()
> > + }
> > +};
> > +
> > +static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f)
> > +{
> > + VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> > +
> > + vmstate_save_state(f, &vmstate_vfio_pci_config, vdev, NULL);
> > +}
> > +
> > +static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
> > +{
> > + VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> > + PCIDevice *pdev = &vdev->pdev;
> > + int ret;
> > +
> > + ret = vmstate_load_state(f, &vmstate_vfio_pci_config, vdev, 1);
> > + if (ret) {
> > + return ret;
> > + }
> > +
> > + if (msi_enabled(pdev)) {
> > + vfio_msi_enable(vdev);
> > + } else if (msix_enabled(pdev)) {
> > + vfio_msix_enable(vdev);
> > + }
> > +
> > + return ret;
> > +}
> > +
> > static VFIODeviceOps vfio_pci_ops = {
> > .vfio_compute_needs_reset = vfio_pci_compute_needs_reset,
> > .vfio_hot_reset_multi = vfio_pci_hot_reset_multi,
> > .vfio_eoi = vfio_intx_eoi,
> > .vfio_get_object = vfio_pci_get_object,
> > + .vfio_save_config = vfio_pci_save_config,
> > + .vfio_load_config = vfio_pci_load_config,
> > };
> >
> > int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
> > diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> > index fe99c36a693a..ba6169cd926e 100644
> > --- a/include/hw/vfio/vfio-common.h
> > +++ b/include/hw/vfio/vfio-common.h
> > @@ -120,6 +120,8 @@ struct VFIODeviceOps {
> > int (*vfio_hot_reset_multi)(VFIODevice *vdev);
> > void (*vfio_eoi)(VFIODevice *vdev);
> > Object *(*vfio_get_object)(VFIODevice *vdev);
> > + void (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f);
> > + int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f);
> > };
> >
> > typedef struct VFIOGroup {
> > --
> > 2.7.0
> >
>
next prev parent reply other threads:[~2020-10-24 14:17 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 10:40 [PATCH v28 00/17] Add migration support for VFIO devices Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 01/17] vfio: Add function to unmap VFIO region Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 02/17] vfio: Add vfio_get_object callback to VFIODeviceOps Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 03/17] vfio: Add save and load functions for VFIO PCI devices Kirti Wankhede
2020-10-24 11:53 ` Yan Zhao
2020-10-24 14:16 ` Alex Williamson [this message]
2020-10-24 19:48 ` Kirti Wankhede
2020-10-24 20:23 ` Alex Williamson
2020-10-25 4:26 ` Yan Zhao
2020-10-23 10:40 ` [PATCH v28 04/17] vfio: Add migration region initialization and finalize function Kirti Wankhede
2020-10-23 11:24 ` Cornelia Huck
2020-10-24 20:22 ` Kirti Wankhede
2020-10-23 16:52 ` Alex Williamson
2020-10-24 9:39 ` Kirti Wankhede
2020-10-24 14:21 ` Alex Williamson
2020-10-24 14:48 ` Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 05/17] vfio: Add VM state change handler to know state of VM Kirti Wankhede
2020-10-23 11:32 ` Cornelia Huck
2020-10-24 20:27 ` Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 06/17] vfio: Add migration state change notifier Kirti Wankhede
2020-10-23 11:45 ` Cornelia Huck
2020-10-23 10:40 ` [PATCH v28 07/17] vfio: Register SaveVMHandlers for VFIO device Kirti Wankhede
2020-10-23 12:18 ` Cornelia Huck
2020-10-24 11:26 ` Yan Zhao
2020-10-24 20:35 ` Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 08/17] vfio: Add save state functions to SaveVMHandlers Kirti Wankhede
2020-10-24 11:59 ` Yan Zhao
2020-10-23 10:40 ` [PATCH v28 09/17] vfio: Add load " Kirti Wankhede
2020-10-24 11:58 ` Yan Zhao
2020-10-23 10:40 ` [PATCH v28 10/17] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled Kirti Wankhede
2020-10-24 12:00 ` Yan Zhao
2020-10-23 10:40 ` [PATCH v28 11/17] vfio: Get migration capability flags for container Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 12/17] vfio: Add function to start and stop dirty pages tracking Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 13/17] vfio: Add vfio_listener_log_sync to mark dirty pages Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 14/17] vfio: Dirty page tracking when vIOMMU is enabled Kirti Wankhede
2020-10-24 11:56 ` Yan Zhao
2020-10-23 10:40 ` [PATCH v28 15/17] vfio: Add ioctl to get dirty pages bitmap during dma unmap Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 16/17] vfio: Make vfio-pci device migration capable Kirti Wankhede
2020-10-23 10:40 ` [PATCH v28 17/17] qapi: Add VFIO devices migration stats in Migration stats Kirti Wankhede
2020-10-24 16:56 ` [PATCH v28 00/17] Add migration support for VFIO devices Philippe Mathieu-Daudé
2020-10-24 17:48 ` Kirti Wankhede
2020-10-24 19:43 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201024081630.29d3a2bf@x1.home \
--to=alex.williamson@redhat.com \
--cc=Ken.Xue@amd.com \
--cc=Zhengxiao.zx@Alibaba-inc.com \
--cc=aik@ozlabs.ru \
--cc=armbru@redhat.com \
--cc=artemp@nvidia.com \
--cc=changpeng.liu@intel.com \
--cc=cjia@nvidia.com \
--cc=cohuck@redhat.com \
--cc=dgilbert@redhat.com \
--cc=dnigam@nvidia.com \
--cc=eauger@redhat.com \
--cc=eskultet@redhat.com \
--cc=felipe@nutanix.com \
--cc=jonathan.davies@nutanix.com \
--cc=kevin.tian@intel.com \
--cc=kwankhede@nvidia.com \
--cc=mcrossley@nvidia.com \
--cc=mlevitsk@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=shuangtai.tst@alibaba-inc.com \
--cc=yan.y.zhao@intel.com \
--cc=yi.l.liu@intel.com \
--cc=zhi.a.wang@intel.com \
--cc=zhi.wang.linux@gmail.com \
--cc=ziye.yang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).