From d83f46d189a26fa32434139954d264326f199a45 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 6 Apr 2021 12:03:30 +0800 Subject: virtio-pci: compat page aligned ATS Commit 4c70875372b8 ("pci: advertise a page aligned ATS") advertises the page aligned via ATS capability (RO) to unbrek recent Linux IOMMU drivers since 5.2. But it forgot the compat the capability which breaks the migration from old machine type: (qemu) qemu-kvm: get_pci_config_device: Bad config data: i=0x104 read: 0 device: 20 cmask: ff wmask: 0 w1cmask:0 This patch introduces a new parameter "x-ats-page-aligned" for virtio-pci device and turns it on for machine type which is newer than 5.1. Cc: Michael S. Tsirkin Cc: Peter Xu Cc: Dr. David Alan Gilbert Cc: qemu-stable@nongnu.org Fixes: 4c70875372b8 ("pci: advertise a page aligned ATS") Signed-off-by: Jason Wang Message-Id: <20210406040330.11306-1-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pcie.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'hw/pci') diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index a733e2fb87..fd0fa157e8 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -963,16 +963,18 @@ void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num) pci_set_quad(dev->config + offset + pci_dsn_cap, ser_num); } -void pcie_ats_init(PCIDevice *dev, uint16_t offset) +void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned) { pcie_add_capability(dev, PCI_EXT_CAP_ID_ATS, 0x1, offset, PCI_EXT_CAP_ATS_SIZEOF); dev->exp.ats_cap = offset; - /* Invalidate Queue Depth 0, Page Aligned Request 1 */ - pci_set_word(dev->config + offset + PCI_ATS_CAP, - PCI_ATS_CAP_PAGE_ALIGNED); + /* Invalidate Queue Depth 0 */ + if (aligned) { + pci_set_word(dev->config + offset + PCI_ATS_CAP, + PCI_ATS_CAP_PAGE_ALIGNED); + } /* STU 0, Disabled by default */ pci_set_word(dev->config + offset + PCI_ATS_CTRL, 0); -- cgit v1.2.3-55-g7522