[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 08/11] s390x/pci: use KVM-managed IOMMU for interpretation
From: |
Matthew Rosato |
Subject: |
[PATCH v4 08/11] s390x/pci: use KVM-managed IOMMU for interpretation |
Date: |
Mon, 14 Mar 2022 15:49:17 -0400 |
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
- [PATCH v4 00/11] s390x/pci: zPCI interpretation support, Matthew Rosato, 2022/03/14
- [PATCH v4 01/11] Update linux headers, Matthew Rosato, 2022/03/14
- [PATCH v4 02/11] vfio: handle KVM-owned IOMMU requests, Matthew Rosato, 2022/03/14
- [PATCH v4 03/11] target/s390x: add zpci-interp to cpu models, Matthew Rosato, 2022/03/14
- [PATCH v4 04/11] s390x/pci: add routine to get host function handle from CLP info, Matthew Rosato, 2022/03/14
- [PATCH v4 05/11] s390x/pci: enable for load/store intepretation, Matthew Rosato, 2022/03/14
- [PATCH v4 06/11] s390x/pci: don't fence interpreted devices without MSI-X, Matthew Rosato, 2022/03/14
- [PATCH v4 07/11] s390x/pci: enable adapter event notification for interpreted devices, Matthew Rosato, 2022/03/14
- [PATCH v4 08/11] s390x/pci: use KVM-managed IOMMU for interpretation,
Matthew Rosato <=
- [PATCH v4 09/11] s390x/pci: use I/O Address Translation assist when interpreting, Matthew Rosato, 2022/03/14
- [PATCH v4 10/11] s390x/pci: use dtsm provided from vfio capabilities for interpreted devices, Matthew Rosato, 2022/03/14
- [PATCH v4 11/11] s390x/pci: let intercept devices have separate PCI groups, Matthew Rosato, 2022/03/14