qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, Jason Wang <jasowang@redhat.com>,
	Wei.Huang2@amd.com, dgilbert@redhat.com, peterx@redhat.com,
	Sriyash.Caculo@amd.com, pbonzini@redhat.com, chao.gao@intel.com
Subject: [PATCH 1/3] virtio-bus: introduce iommu_enabled()
Date: Wed,  4 Aug 2021 11:48:01 +0800	[thread overview]
Message-ID: <20210804034803.1644-2-jasowang@redhat.com> (raw)
In-Reply-To: <20210804034803.1644-1-jasowang@redhat.com>

This patch introduce a new method for the virtio-bus for the transport
to report whether or not the IOMMU is enabled for the device.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio-bus.c         | 14 ++++++++++++++
 include/hw/virtio/virtio-bus.h |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index 859978d248..d23db98c56 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -325,6 +325,20 @@ static char *virtio_bus_get_fw_dev_path(DeviceState *dev)
     return NULL;
 }
 
+bool virtio_bus_device_iommu_enabled(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+
+    if (!klass->iommu_enabled) {
+        return false;
+    }
+
+    return klass->iommu_enabled(qbus->parent);
+}
+
 static void virtio_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *bus_class = BUS_CLASS(klass);
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index ef8abe49c5..7ab8c9dab0 100644
--- a/include/hw/virtio/virtio-bus.h
+++ b/include/hw/virtio/virtio-bus.h
@@ -93,6 +93,7 @@ struct VirtioBusClass {
      */
     bool has_variable_vring_alignment;
     AddressSpace *(*get_dma_as)(DeviceState *d);
+    bool (*iommu_enabled)(DeviceState *d);
 };
 
 struct VirtioBusState {
@@ -154,5 +155,6 @@ void virtio_bus_release_ioeventfd(VirtioBusState *bus);
 int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign);
 /* Tell the bus that the ioeventfd handler is no longer required. */
 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n);
-
+/* Whether the IOMMU is enabled for this device */
+bool virtio_bus_device_iommu_enabled(VirtIODevice *vdev);
 #endif /* VIRTIO_BUS_H */
-- 
2.25.1



  reply	other threads:[~2021-08-04  3:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04  3:48 [PATCH 0/3] Disable vhost device IOTLB is IOMMU is not enabled Jason Wang
2021-08-04  3:48 ` Jason Wang [this message]
2021-08-04  3:48 ` [PATCH 2/3] virtio-pci: implement iommu_enabled() Jason Wang
2021-08-04  3:48 ` [PATCH 3/3] vhost: correctly detect the enabling IOMMU Jason Wang
2021-08-04  5:57 ` [PATCH 0/3] Disable vhost device IOTLB is IOMMU is not enabled Chao Gao
2021-08-04 16:08 ` Peter Xu
2021-08-05  1:46   ` Jason Wang
2021-08-05  3:08     ` Peter Xu
2021-08-05  7:26       ` Caculo, Sriyash
2021-09-02  5:46 ` Jason Wang

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=20210804034803.1644-2-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=Sriyash.Caculo@amd.com \
    --cc=Wei.Huang2@amd.com \
    --cc=chao.gao@intel.com \
    --cc=dgilbert@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --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).