From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: "Zhengxiao.zx@alibaba-inc.com" <Zhengxiao.zx@alibaba-inc.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"Liu, Yi L" <yi.l.liu@intel.com>,
"cjia@nvidia.com" <cjia@nvidia.com>,
"eskultet@redhat.com" <eskultet@redhat.com>,
"Yang, Ziye" <ziye.yang@intel.com>,
"cohuck@redhat.com" <cohuck@redhat.com>,
"shuangtai.tst@alibaba-inc.com" <shuangtai.tst@alibaba-inc.com>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"Wang, Zhi A" <zhi.a.wang@intel.com>,
"mlevitsk@redhat.com" <mlevitsk@redhat.com>,
"pasic@linux.ibm.com" <pasic@linux.ibm.com>,
"aik@ozlabs.ru" <aik@ozlabs.ru>,
Kirti Wankhede <kwankhede@nvidia.com>,
"eauger@redhat.com" <eauger@redhat.com>,
"felipe@nutanix.com" <felipe@nutanix.com>,
"jonathan.davies@nutanix.com" <jonathan.davies@nutanix.com>,
"Zhao, Yan Y" <yan.y.zhao@intel.com>,
"Liu, Changpeng" <changpeng.liu@intel.com>,
"Ken.Xue@amd.com" <Ken.Xue@amd.com>
Subject: Re: [Qemu-devel] [PATCH v7 04/13] vfio: Add save and load functions for VFIO PCI devices
Date: Fri, 23 Aug 2019 10:26:33 +0100 [thread overview]
Message-ID: <20190823092633.GB2784@work-vm> (raw)
In-Reply-To: <AADFC41AFE54684AB9EE6CBC0274A5D19D543525@SHSMSX104.ccr.corp.intel.com>
* Tian, Kevin (kevin.tian@intel.com) wrote:
> > From: Dr. David Alan Gilbert [mailto:dgilbert@redhat.com]
> > Sent: Friday, August 23, 2019 3:13 AM
> >
> > * Kirti Wankhede (kwankhede@nvidia.com) wrote:
> > >
> > >
> > > On 8/22/2019 3:02 PM, Dr. David Alan Gilbert wrote:
> > > > * Kirti Wankhede (kwankhede@nvidia.com) wrote:
> > > >> Sorry for delay to respond.
> > > >>
> > > >> On 7/11/2019 5:37 PM, Dr. David Alan Gilbert wrote:
> > > >>> * Kirti Wankhede (kwankhede@nvidia.com) wrote:
> > > >>>> These functions save and restore PCI device specific data - config
> > > >>>> space of PCI device.
> > > >>>> Tested save and restore with MSI and MSIX type.
> > > >>>>
> > > >>>> Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> > > >>>> Reviewed-by: Neo Jia <cjia@nvidia.com>
> > > >>>> ---
> > > >>>> hw/vfio/pci.c | 114
> > ++++++++++++++++++++++++++++++++++++++++++
> > > >>>> include/hw/vfio/vfio-common.h | 2 +
> > > >>>> 2 files changed, 116 insertions(+)
> > > >>>>
> > > >>>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> > > >>>> index de0d286fc9dd..5fe4f8076cac 100644
> > > >>>> --- a/hw/vfio/pci.c
> > > >>>> +++ b/hw/vfio/pci.c
> > > >>>> @@ -2395,11 +2395,125 @@ static Object
> > *vfio_pci_get_object(VFIODevice *vbasedev)
> > > >>>> return OBJECT(vdev);
> > > >>>> }
> > > >>>>
> > > >>>> +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;
> > > >>>> + int i;
> > > >>>> +
> > > >>>> + for (i = 0; i < PCI_ROM_SLOT; i++) {
> > > >>>> + uint32_t bar;
> > > >>>> +
> > > >>>> + bar = pci_default_read_config(pdev, PCI_BASE_ADDRESS_0 + i *
> > 4, 4);
> > > >>>> + qemu_put_be32(f, bar);
> > > >>>> + }
> > > >>>> +
> > > >>>> + qemu_put_be32(f, vdev->interrupt);
> > > >>>> + if (vdev->interrupt == VFIO_INT_MSI) {
> > > >>>> + uint32_t msi_flags, msi_addr_lo, msi_addr_hi = 0, msi_data;
> > > >>>> + bool msi_64bit;
> > > >>>> +
> > > >>>> + msi_flags = pci_default_read_config(pdev, pdev->msi_cap +
> > PCI_MSI_FLAGS,
> > > >>>> + 2);
> > > >>>> + msi_64bit = (msi_flags & PCI_MSI_FLAGS_64BIT);
> > > >>>> +
> > > >>>> + msi_addr_lo = pci_default_read_config(pdev,
> > > >>>> + pdev->msi_cap + PCI_MSI_ADDRESS_LO, 4);
> > > >>>> + qemu_put_be32(f, msi_addr_lo);
> > > >>>> +
> > > >>>> + if (msi_64bit) {
> > > >>>> + msi_addr_hi = pci_default_read_config(pdev,
> > > >>>> + pdev->msi_cap + PCI_MSI_ADDRESS_HI,
> > > >>>> + 4);
> > > >>>> + }
> > > >>>> + qemu_put_be32(f, msi_addr_hi);
> > > >>>> +
> > > >>>> + msi_data = pci_default_read_config(pdev,
> > > >>>> + pdev->msi_cap + (msi_64bit ? PCI_MSI_DATA_64 :
> > PCI_MSI_DATA_32),
> > > >>>> + 2);
> > > >>>> + qemu_put_be32(f, msi_data);
> > > >>>> + } else if (vdev->interrupt == VFIO_INT_MSIX) {
> > > >>>> + uint16_t offset;
> > > >>>> +
> > > >>>> + /* save enable bit and maskall bit */
> > > >>>> + offset = pci_default_read_config(pdev,
> > > >>>> + pdev->msix_cap + PCI_MSIX_FLAGS + 1, 2);
> > > >>>> + qemu_put_be16(f, offset);
> > > >>>> + msix_save(pdev, f);
> > > >>>> + }
> > > >>>> + pci_cmd = pci_default_read_config(pdev, PCI_COMMAND, 2);
> > > >>>> + qemu_put_be16(f, pci_cmd);
> > > >>>> +}
> > > >>>> +
> > > >>>> +static void vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
> > > >>>> +{
> > > >>>> + VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice,
> > vbasedev);
> > > >>>> + PCIDevice *pdev = &vdev->pdev;
> > > >>>> + uint32_t interrupt_type;
> > > >>>> + uint32_t msi_flags, msi_addr_lo, msi_addr_hi = 0, msi_data;
> > > >>>> + uint16_t pci_cmd;
> > > >>>> + bool msi_64bit;
> > > >>>> + int i;
> > > >>>> +
> > > >>>> + /* retore pci bar configuration */
> > > >>>> + pci_cmd = pci_default_read_config(pdev, PCI_COMMAND, 2);
> > > >>>> + vfio_pci_write_config(pdev, PCI_COMMAND,
> > > >>>> + pci_cmd & (!(PCI_COMMAND_IO |
> > PCI_COMMAND_MEMORY)), 2);
> > > >>>> + for (i = 0; i < PCI_ROM_SLOT; i++) {
> > > >>>> + uint32_t bar = qemu_get_be32(f);
> > > >>>> +
> > > >>>> + vfio_pci_write_config(pdev, PCI_BASE_ADDRESS_0 + i * 4, bar, 4);
> > > >>>> + }
> > > >>>
> > > >>> Is it possible to validate the bar's at all? We just had a bug on a
> > > >>> virtual device where one version was asking for a larger bar than the
> > > >>> other; our validation caught this in some cases so we could tell that
> > > >>> the guest had a BAR that was aligned at the wrong alignment.
>
> I'm a bit confused here. Did you mean that src and dest include
> different versions of the virtual device which implements different
> BAR size? If that is the case, shouldn't the migration fail at the start
> when doing compatibility check?
It was a mistake where the destination had accidentally changed the BAR
size; checking the alignment was the only check that failed.
> > > >>>
> > > >>
> > > >> "Validate the bars" does that means validate size of bars?
> > > >
> > > > I meant validate the address programmed into the BAR against the size,
> > > > assuming you know the size; e.g. if it's a 128MB BAR, then make sure the
> > > > address programmed in is 128MB aligned.
> > > >
> > >
> > > If this validation fails, migration resume should fail, right?
> >
> > Yes I think so; if you've got a device that wants 128MB alignment and
> > someone gives you a non-aligned address, who knows what will happen.
>
> If misalignment is really caused by the guest, shouldn't we just follow
> the hardware behavior, i.e. hard-wiring the lower bits to 0 before
> updating the cfg space?
That should already happen on the source; but when loading a migration
stream I try and be very untrusting; so it's good to check that the
destination devices idea of the BAR matches what the register has.
Dave
> Thanks
> Kevin
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2019-08-23 9:28 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-09 9:49 [Qemu-devel] [PATCH v7 00/13] Add migration support for VFIO device Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 01/13] vfio: KABI for migration interface Kirti Wankhede
2019-07-16 20:56 ` Alex Williamson
2019-07-17 11:55 ` Cornelia Huck
2019-07-23 12:13 ` Cornelia Huck
2019-08-21 20:32 ` Kirti Wankhede
2019-08-21 20:31 ` Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 02/13] vfio: Add function to unmap VFIO region Kirti Wankhede
2019-07-16 16:29 ` Cornelia Huck
2019-07-18 18:54 ` Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 03/13] vfio: Add vfio_get_object callback to VFIODeviceOps Kirti Wankhede
2019-07-16 16:32 ` Cornelia Huck
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 04/13] vfio: Add save and load functions for VFIO PCI devices Kirti Wankhede
2019-07-11 12:07 ` Dr. David Alan Gilbert
2019-08-22 4:50 ` Kirti Wankhede
2019-08-22 9:32 ` Dr. David Alan Gilbert
2019-08-22 19:10 ` Kirti Wankhede
2019-08-22 19:13 ` Dr. David Alan Gilbert
2019-08-22 23:57 ` Tian, Kevin
2019-08-23 9:26 ` Dr. David Alan Gilbert [this message]
2019-08-23 9:49 ` Tian, Kevin
2019-07-16 21:14 ` Alex Williamson
2019-07-17 9:10 ` Dr. David Alan Gilbert
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 05/13] vfio: Add migration region initialization and finalize function Kirti Wankhede
2019-07-16 21:37 ` Alex Williamson
2019-07-18 20:19 ` Kirti Wankhede
2019-07-23 12:52 ` Cornelia Huck
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 06/13] vfio: Add VM state change handler to know state of VM Kirti Wankhede
2019-07-11 12:13 ` Dr. David Alan Gilbert
2019-07-11 19:14 ` Kirti Wankhede
2019-07-22 8:23 ` Yan Zhao
2019-08-20 20:31 ` Kirti Wankhede
2019-07-16 22:03 ` Alex Williamson
2019-07-22 8:37 ` Yan Zhao
2019-08-20 20:33 ` Kirti Wankhede
2019-08-23 1:32 ` Yan Zhao
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 07/13] vfio: Add migration state change notifier Kirti Wankhede
2019-07-17 2:25 ` Yan Zhao
2019-08-20 20:24 ` Kirti Wankhede
2019-08-23 0:54 ` Yan Zhao
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 08/13] vfio: Register SaveVMHandlers for VFIO device Kirti Wankhede
2019-07-22 8:34 ` Yan Zhao
2019-08-20 20:33 ` Kirti Wankhede
2019-08-23 1:23 ` Yan Zhao
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 09/13] vfio: Add save state functions to SaveVMHandlers Kirti Wankhede
2019-07-12 2:44 ` Yan Zhao
2019-07-18 18:45 ` Kirti Wankhede
2019-07-17 2:50 ` Yan Zhao
2019-08-20 20:30 ` Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 10/13] vfio: Add load " Kirti Wankhede
2019-07-12 2:52 ` Yan Zhao
2019-07-18 19:00 ` Kirti Wankhede
2019-07-22 3:20 ` Yan Zhao
2019-07-22 19:07 ` Alex Williamson
2019-07-22 21:50 ` Yan Zhao
2019-08-20 20:35 ` Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 11/13] vfio: Add function to get dirty page list Kirti Wankhede
2019-07-12 0:33 ` Yan Zhao
2019-07-18 18:39 ` Kirti Wankhede
2019-07-19 1:24 ` Yan Zhao
2019-07-22 8:39 ` Yan Zhao
2019-08-20 20:34 ` Kirti Wankhede
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 12/13] vfio: Add vfio_listerner_log_sync to mark dirty pages Kirti Wankhede
2019-07-23 13:18 ` Cornelia Huck
2019-07-09 9:49 ` [Qemu-devel] [PATCH v7 13/13] vfio: Make vfio-pci device migration capable Kirti Wankhede
2019-07-11 2:55 ` [Qemu-devel] [PATCH v7 00/13] Add migration support for VFIO device Yan Zhao
2019-07-11 10:50 ` Dr. David Alan Gilbert
2019-07-11 11:47 ` Yan Zhao
2019-07-11 16:23 ` Dr. David Alan Gilbert
2019-07-11 19:08 ` Kirti Wankhede
2019-07-12 0:32 ` Yan Zhao
2019-07-18 18:32 ` Kirti Wankhede
2019-07-19 1:23 ` Yan Zhao
2019-07-24 11:32 ` Dr. David Alan Gilbert
2019-07-12 17:42 ` Dr. David Alan Gilbert
2019-07-15 0:35 ` Yan Zhao
2019-07-12 0:14 ` Yan Zhao
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=20190823092633.GB2784@work-vm \
--to=dgilbert@redhat.com \
--cc=Ken.Xue@amd.com \
--cc=Zhengxiao.zx@alibaba-inc.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=changpeng.liu@intel.com \
--cc=cjia@nvidia.com \
--cc=cohuck@redhat.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=mlevitsk@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--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=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).