qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Jason Wang <jasowang@redhat.com>
Subject: [PULL 15/35] vhost: correctly detect the enabling IOMMU
Date: Sat, 4 Sep 2021 17:36:39 -0400	[thread overview]
Message-ID: <20210904213506.486886-16-mst@redhat.com> (raw)
In-Reply-To: <20210904213506.486886-1-mst@redhat.com>

From: Jason Wang <jasowang@redhat.com>

Vhost used to compare the dma_as against the address_space_memory to
detect whether the IOMMU is enabled or not. This might not work well
since the virito-bus may call get_dma_as if VIRTIO_F_IOMMU_PLATFORM is
set without an actual IOMMU enabled when device is plugged. In the
case of PCI where pci_get_address_space() is used, the bus master as
is returned. So vhost actually tries to enable device IOTLB even if
the IOMMU is not enabled. This will lead a lots of unnecessary
transactions between vhost and Qemu and will introduce a huge drop of
the performance.

For PCI, an ideal approach is to use pci_device_iommu_address_space()
just for get_dma_as. But Qemu may choose to initialize the IOMMU after
the virtio-pci which lead a wrong address space is returned during
device plugged. So this patch switch to use transport specific way via
iommu_enabled() to detect the IOMMU during vhost start. In this case,
we are fine since we know the IOMMU is initialized correctly.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20210804034803.1644-4-jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index e21e144510..b4b29413e6 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -315,7 +315,7 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)
      * does not have IOMMU, there's no need to enable this feature
      * which may cause unnecessary IOTLB miss/update trnasactions.
      */
-    return vdev->dma_as != &address_space_memory &&
+    return virtio_bus_device_iommu_enabled(vdev) &&
            virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
 }
 
-- 
MST



  parent reply	other threads:[~2021-09-04 22:00 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 21:35 [PULL 00/35] pc,pci,virtio: fixes, cleanups Michael S. Tsirkin
2021-09-04 21:35 ` [PULL 01/35] vhost-vdpa: Do not send empty IOTLB update batches Michael S. Tsirkin
2021-09-04 21:35 ` [PULL 02/35] hw/virtio: Fix leak of host-notifier memory-region Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 03/35] vhost: make SET_VRING_ADDR, SET_FEATURES send replies Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 04/35] hw/acpi: define PIIX4 acpi pci hotplug property strings at a single place Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 05/35] q35: catch invalid cpu hotplug configuration Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need Michael S. Tsirkin
2021-09-06  9:58   ` Philippe Mathieu-Daudé
2021-09-06 10:03     ` Ani Sinha
2021-09-06 10:24       ` Philippe Mathieu-Daudé
2021-09-06 10:49         ` Ani Sinha
2021-09-07  5:55           ` Ani Sinha
2021-09-07  6:13             ` Philippe Mathieu-Daudé
2021-09-07  6:34               ` Ani Sinha
2021-09-07  9:49                 ` Ani Sinha
2022-07-19 16:12   ` Peter Maydell
2022-07-19 16:21     ` Peter Maydell
2022-07-20 18:37     ` Ani Sinha
2022-07-20 21:34       ` Peter Maydell
2022-07-20 22:13         ` Ani Sinha
2022-07-21 10:51           ` BB
2022-07-21 12:35           ` Dr. David Alan Gilbert
2022-07-25 17:57             ` Ani Sinha
2021-09-04 21:36 ` [PULL 07/35] hw/virtio: move vhost_set_backend_type() to vhost.c Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 08/35] vhost-user: add missing space in error message Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 09/35] acpi: Delete broken ACPI_GED_X86 macro Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 10/35] Use PCI_HOST_BRIDGE macro Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 11/35] virtio-balloon: don't start free page hinting if postcopy is possible Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 12/35] virtio-balloon: free page hinting cleanups Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 13/35] virtio-bus: introduce iommu_enabled() Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 14/35] virtio-pci: implement iommu_enabled() Michael S. Tsirkin
2021-09-04 21:36 ` Michael S. Tsirkin [this message]
2021-09-04 21:36 ` [PULL 16/35] hw/i386/acpi-build: Get NUMA information from struct NumaState Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 17/35] hw/pci: remove all references to find_i440fx function Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 18/35] hw/acpi: use existing references to pci device struct within functions Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 19/35] MAINTAINERS: Added myself as a reviewer for acpi/smbios subsystem Michael S. Tsirkin
2021-09-04 21:36 ` [PULL 20/35] hw/virtio: Document virtio_queue_packed_empty_rcu is called within RCU Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 21/35] hw/virtio: Remove NULL check in virtio_free_region_cache() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 22/35] hw/virtio: Add flatview update in vhost_user_cleanup() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 23/35] tests/vhost-user-bridge.c: Sanity check socket path length Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 24/35] tests/vhost-user-bridge.c: Fix typo in help message Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 25/35] vhost-vdpa: remove unused variable "acked_features" Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 26/35] vhost-vdpa: correctly return err in vhost_vdpa_set_backend_cap() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 27/35] vhost_net: remove the meaningless assignment in vhost_net_start_one() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 28/35] vhost: use unsigned int for nvqs Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 29/35] vhost_net: do not assume nvqs is always 2 Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 30/35] vhost-vdpa: remove the unnecessary check in vhost_vdpa_add() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 31/35] vhost-vdpa: don't cleanup twice " Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 32/35] vhost-vdpa: fix leaking of vhost_net " Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 33/35] vhost-vdpa: tweak the error label " Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 34/35] vhost-vdpa: fix the wrong assertion in vhost_vdpa_init() Michael S. Tsirkin
2021-09-04 21:37 ` [PULL 35/35] vhost-vdpa: remove the unncessary queue_index assignment Michael S. Tsirkin
2021-09-06  9:41 ` [PULL 00/35] pc,pci,virtio: fixes, cleanups Peter Maydell

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=20210904213506.486886-16-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).