From: Matthew Rosato <mjrosato@linux.ibm.com>
To: qemu-s390x@nongnu.org
Cc: farman@linux.ibm.com, kvm@vger.kernel.org, pmorel@linux.ibm.com,
schnelle@linux.ibm.com, cohuck@redhat.com,
richard.henderson@linaro.org, thuth@redhat.com,
qemu-devel@nongnu.org, pasic@linux.ibm.com,
alex.williamson@redhat.com, mst@redhat.com, pbonzini@redhat.com,
david@redhat.com, borntraeger@linux.ibm.com
Subject: [PATCH v4 08/11] s390x/pci: use KVM-managed IOMMU for interpretation
Date: Mon, 14 Mar 2022 15:49:17 -0400 [thread overview]
Message-ID: <20220314194920.58888-9-mjrosato@linux.ibm.com> (raw)
In-Reply-To: <20220314194920.58888-1-mjrosato@linux.ibm.com>
When interpreting zPCI instructions, KVM will control the IOMMU mappings
in response to RPCIT instructions rather than relying on mapping ioctls
from userspace. Mark the vfio device in pre_plug so that the appropriate
iommu domain will be allocated on the host during VFIO_SET_IOMMU.
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
hw/s390x/s390-pci-bus.c | 11 +++++++++++
hw/s390x/s390-pci-vfio.c | 22 ++++++++++++++++++++++
include/hw/s390x/s390-pci-vfio.h | 5 +++++
3 files changed, 38 insertions(+)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 5043b8c85c..513a276711 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -950,6 +950,17 @@ static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
error_setg(errp, "multifunction not supported in s390");
return;
}
+ /*
+ * If we have a vfio-pci device that wishes to use interpretation
+ * we must update the host IOMMU domain ops.
+ */
+ if (s390_pci_kvm_zpciop_allowed() &&
+ object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+ if (s390_pci_set_kvm_iommu(s, dev)) {
+ error_setg(errp, "KVM IOMMU not available for interpretation");
+ return;
+ }
+ }
} else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index 4bf0a7e22d..7808e8d939 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -324,3 +324,25 @@ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
return;
}
+
+/*
+ * This function will determine if the specified VFIOPCIDevice is linked to a
+ * zPCI device that requests interpretation support. In this case, we must
+ * inform vfio that the KVM-managed IOMMU should be requested when the
+ * VFIO_SET_IOMMU ioctl is issued.
+ */
+int s390_pci_set_kvm_iommu(S390pciState *s, DeviceState *dev)
+{
+ VFIOPCIDevice *vdev = VFIO_PCI(dev);
+ S390PCIBusDevice *pbdev = s390_pci_find_dev_by_target(s, dev->id);
+
+ if (!pbdev) {
+ return -ENODEV;
+ }
+
+ if (pbdev->interp) {
+ vdev->kvm_managed_iommu = true;
+ }
+
+ return 0;
+}
diff --git a/include/hw/s390x/s390-pci-vfio.h b/include/hw/s390x/s390-pci-vfio.h
index 0c2e4b5175..5026f978c2 100644
--- a/include/hw/s390x/s390-pci-vfio.h
+++ b/include/hw/s390x/s390-pci-vfio.h
@@ -22,6 +22,7 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt);
bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh);
void s390_pci_get_clp_info(S390PCIBusDevice *pbdev);
+int s390_pci_set_kvm_iommu(S390pciState *s, DeviceState *dev);
#else
static inline bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
{
@@ -40,6 +41,10 @@ static inline bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev,
return false;
}
static inline void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { }
+static inline int s390_pci_set_kvm_iommu(S390pciState *s, DeviceState *dev)
+{
+ return -EINVAL;
+}
#endif
#endif
--
2.27.0
next prev parent reply other threads:[~2022-03-14 19:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 19:49 [PATCH v4 00/11] s390x/pci: zPCI interpretation support Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 01/11] Update linux headers Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 02/11] vfio: handle KVM-owned IOMMU requests Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 03/11] target/s390x: add zpci-interp to cpu models Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 04/11] s390x/pci: add routine to get host function handle from CLP info Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 05/11] s390x/pci: enable for load/store intepretation Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 06/11] s390x/pci: don't fence interpreted devices without MSI-X Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 07/11] s390x/pci: enable adapter event notification for interpreted devices Matthew Rosato
2022-03-14 19:49 ` Matthew Rosato [this message]
2022-03-14 19:49 ` [PATCH v4 09/11] s390x/pci: use I/O Address Translation assist when interpreting Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 10/11] s390x/pci: use dtsm provided from vfio capabilities for interpreted devices Matthew Rosato
2022-03-14 19:49 ` [PATCH v4 11/11] s390x/pci: let intercept devices have separate PCI groups Matthew Rosato
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=20220314194920.58888-9-mjrosato@linux.ibm.com \
--to=mjrosato@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=farman@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=pmorel@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=schnelle@linux.ibm.com \
--cc=thuth@redhat.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).