All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP
@ 2022-12-12 18:45 Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 1/9] irq: Add msi_device_has_isolated_msi() Jason Gunthorpe
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

[ This would be for v6.3, the series depends on a bunch of stuff in
linux-next. I would be happy to merge it through the iommfd tree ]

Currently the kernel has two ways to signal the "isolated MSI" concept
that IOMMU_CAP_INTR_REMAP and irq_domain_check_msi_remap() both lay claim
to.

Harmonize these into a single irq_domain based check under
msi_device_has_isolated_msi().

In real HW "isolated MSI" is implemented in a few different ways:

 - x86 uses "interrupt remapping" which is a block that sits between
   the device and APIC, that can "remap" the MSI MemWr. AMD uses per-RID
   tables to implement isolation while Intel stores the authorized RID in
   each IRTE entry. Part of the remapping is discarding, HW will not
   forward MSIs that don't positively match the tables.

 - ARM GICv3 ITS integrates the concept of an out-of-band "device ID"
   directly into the interrupt controller logic. The tables the GIC checks
   that determine how to deliver the interrupt through the ITS device table
   and interrupt translation tables allow limiting which interrupts device
   IDs can trigger.

 - S390 has unconditionally claimed it has isolated MSI through the iommu
   driver. This is a weaker version of the other arches in that it only
   works between "gisa" domains. See zpci_set_airq() and

    https://lore.kernel.org/r/31af8174-35e9-ebeb-b9ef-74c90d4bfd93@linux.ibm.com/

After this series the "isolated MSI" is tagged based only on the
irq_domains that the interrupt travels through. For x86 enabling interrupt
remapping causes IR irq_domains to be installed in the path, and they can
carry the IRQ_DOMAIN_FLAG_ISOLATED_MSI. For ARM the GICv3 ITS itself
already sets the flag when it is running in a isolated mode, and S390
simply sets it always through an arch hook since it doesn't use
irq_domains at all.

This removes the intrusion of IRQ subsystem information into the iommu
drivers. Linux's iommu_domains abstraction has no bearing at all on the
security of MSI. Even if HW linked to the IOMMU may implement the security
on x86 implementations, Linux models that HW through the irq_domain, not
the iommu_domain.

This is on github: https://github.com/jgunthorpe/linux/commits/secure_msi

v2:
 - Rename secure_msi to isolated_msi
 - Add iommu_group_has_isolated_msi() as a core function to support
   VFIO/iommufd. It checks that the group has a consisent isolated_msi
   to catch driver bugs.
 - Revise comment and commit messages for clarity
 - Drop the VFIO iteration patch since iommu_group_has_isolated_msi() just
   does it.
 - Link to Matthew's discussion about S390 and explain it is less secure
v1: https://lore.kernel.org/r/0-v1-9e466539c244+47b5-secure_msi_jgg@nvidia.com

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Jason Gunthorpe (9):
  irq: Add msi_device_has_isolated_msi()
  iommu: Add iommu_group_has_isolated_msi()
  vfio/type1: Convert to iommu_group_has_isolated_msi()
  iommufd: Convert to msi_device_has_isolated_msi()
  irq: Remove unused irq_domain_check_msi_remap() code
  irq: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI
  iommu/x86: Replace IOMMU_CAP_INTR_REMAP with
    IRQ_DOMAIN_FLAG_ISOLATED_MSI
  irq/s390: Add arch_is_isolated_msi() for s390
  iommu: Remove IOMMU_CAP_INTR_REMAP

 arch/s390/include/asm/msi.h         | 17 +++++++++++++
 drivers/iommu/amd/iommu.c           |  5 ++--
 drivers/iommu/intel/iommu.c         |  2 --
 drivers/iommu/intel/irq_remapping.c |  3 ++-
 drivers/iommu/iommu.c               | 23 +++++++++++++++++
 drivers/iommu/iommufd/device.c      |  4 +--
 drivers/iommu/s390-iommu.c          |  2 --
 drivers/irqchip/irq-gic-v3-its.c    |  4 +--
 drivers/vfio/vfio_iommu_type1.c     | 16 +++---------
 include/linux/iommu.h               |  2 +-
 include/linux/irqdomain.h           | 29 +++------------------
 include/linux/msi.h                 | 17 +++++++++++++
 kernel/irq/irqdomain.c              | 39 -----------------------------
 kernel/irq/msi.c                    | 27 ++++++++++++++++++++
 14 files changed, 99 insertions(+), 91 deletions(-)
 create mode 100644 arch/s390/include/asm/msi.h


base-commit: 644f4ef9a6ea0e0c65f949bd6b80857d4223c476
-- 
2.38.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 1/9] irq: Add msi_device_has_isolated_msi()
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
@ 2022-12-12 18:45 ` Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi() Jason Gunthorpe
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

This will replace irq_domain_check_msi_remap() in following patches.

The new API makes it more clear what "msi_remap" actually means from a
functional perspective instead of identifying an implementation specific
HW feature.

Isolated MSI means that HW modeled by an irq_domain on the path from the
initiating device to the CPU will validate that the MSI message specifies
an interrupt number that the device is authorized to trigger. This must
block devices from triggering interrupts they are not authorized to
trigger.  Currently authorization means the MSI vector is one assigned to
the device.

This is interesting for securing VFIO use cases where a rouge MSI (eg
created by abusing a normal PCI MemWr DMA) must not allow the VFIO
userspace to impact outside its security domain, eg userspace triggering
interrupts on kernel drivers, a VM triggering interrupts on the
hypervisor, or a VM triggering interrupts on another VM.

As this is actually modeled as a per-irq_domain property, not a global
platform property, correct the interface to accept the device parameter
and scan through only the part of the irq_domains hierarchy originating
from the source device.

Locate the new code in msi.c as it naturally only works with
CONFIG_GENERIC_MSI_IRQ, which also requires CONFIG_IRQ_DOMAIN and
IRQ_DOMAIN_HIERARCHY.

Cc: Eric Auger <eric.auger@redhat.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Tomasz Nowicki <tomasz.nowicki@caviumnetworks.com>
Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 include/linux/msi.h | 13 +++++++++++++
 kernel/irq/msi.c    | 27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/linux/msi.h b/include/linux/msi.h
index a112b913fff949..e8a3f3a8a7f427 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -649,6 +649,19 @@ int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int vir
 void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int virq,
 				     unsigned int nvec);
 void *platform_msi_get_host_data(struct irq_domain *domain);
+
+bool msi_device_has_isolated_msi(struct device *dev);
+#else /* CONFIG_GENERIC_MSI_IRQ */
+static inline bool msi_device_has_isolated_msi(struct device *dev)
+{
+	/*
+	 * Arguably if the platform does not enable MSI support then it has
+	 * "isolated MSI", as an interrupt controller that cannot receive MSIs
+	 * is inherently isolated by our definition. As nobody seems to needs
+	 * this be conservative and return false anyhow.
+	 */
+	return false;
+}
 #endif /* CONFIG_GENERIC_MSI_IRQ */
 
 /* PCI specific interfaces */
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index bd4d4dd626b4bd..1c6811e145f170 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1622,3 +1622,30 @@ struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain)
 {
 	return (struct msi_domain_info *)domain->host_data;
 }
+
+/**
+ * msi_device_has_isolated_msi - True if the device has isolated MSI
+ * @dev: The device to check
+ *
+ * Isolated MSI means that HW modeled by an irq_domain on the path from the
+ * initiating device to the CPU will validate that the MSI message specifies an
+ * interrupt number that the device is authorized to trigger. This must block
+ * devices from triggering interrupts they are not authorized to trigger.
+ * Currently authorization means the MSI vector is one assigned to the device.
+ *
+ * This is interesting for securing VFIO use cases where a rouge MSI (eg created
+ * by abusing a normal PCI MemWr DMA) must not allow the VFIO userspace to
+ * impact outside its security domain, eg userspace triggering interrupts on
+ * kernel drivers, a VM triggering interrupts on the hypervisor, or a VM
+ * triggering interrupts on another VM.
+ */
+bool msi_device_has_isolated_msi(struct device *dev)
+{
+	struct irq_domain *domain = dev_get_msi_domain(dev);
+
+	for (; domain; domain = domain->parent)
+		if (domain->flags & IRQ_DOMAIN_FLAG_MSI_REMAP)
+			return true;
+	return false;
+}
+EXPORT_SYMBOL_GPL(msi_device_has_isolated_msi);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi()
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 1/9] irq: Add msi_device_has_isolated_msi() Jason Gunthorpe
@ 2022-12-12 18:45 ` Jason Gunthorpe
  2022-12-13 14:37   ` Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 3/9] vfio/type1: Convert to iommu_group_has_isolated_msi() Jason Gunthorpe
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

Compute the isolated_msi over all the devices in the IOMMU group because
iommufd and vfio both need to know that the entire group is isolated
before granting access to it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 25 +++++++++++++++++++++++++
 include/linux/iommu.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index d69ebba81bebd8..adb3f655bf5709 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1881,6 +1881,31 @@ bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
 }
 EXPORT_SYMBOL_GPL(device_iommu_capable);
 
+/**
+ * iommu_group_has_isolated_msi() - Compute msi_device_has_isolated_msi()
+ *       for a group
+ * @group: Group to query
+ *
+ * IOMMU groups should not have differing values of
+ * msi_device_has_isolated_msi() for devices in a group. However nothing
+ * directly prevents this, so ensure mistakes don't result in isolation failures
+ * by checking that all the devices are the same.
+ */
+bool iommu_group_has_isolated_msi(struct iommu_group *group)
+{
+	struct group_device *group_dev;
+	bool ret = true;
+
+	mutex_lock(&group->mutex);
+	list_for_each_entry(group_dev, &group->devices, list)
+		ret &= msi_device_has_isolated_msi(group_dev->dev) ||
+		       device_iommu_capable(group_dev->dev,
+					    IOMMU_CAP_INTR_REMAP);
+	mutex_unlock(&group->mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(iommu_group_has_isolated_msi);
+
 /**
  * iommu_set_fault_handler() - set a fault handler for an iommu domain
  * @domain: iommu domain
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 1690c334e51631..1753e819a63250 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -455,6 +455,7 @@ static inline const struct iommu_ops *dev_iommu_ops(struct device *dev)
 extern int bus_iommu_probe(struct bus_type *bus);
 extern bool iommu_present(struct bus_type *bus);
 extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap);
+extern bool iommu_group_has_isolated_msi(struct iommu_group *group);
 extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
 extern struct iommu_group *iommu_group_get_by_id(int id);
 extern void iommu_domain_free(struct iommu_domain *domain);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 3/9] vfio/type1: Convert to iommu_group_has_isolated_msi()
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 1/9] irq: Add msi_device_has_isolated_msi() Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi() Jason Gunthorpe
@ 2022-12-12 18:45 ` Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 4/9] iommufd: Convert to msi_device_has_isolated_msi() Jason Gunthorpe
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

Trivially use the new API.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_iommu_type1.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 23c24fe98c00d4..393b27a3bd87ee 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -37,7 +37,6 @@
 #include <linux/vfio.h>
 #include <linux/workqueue.h>
 #include <linux/notifier.h>
-#include <linux/irqdomain.h>
 #include "vfio.h"
 
 #define DRIVER_VERSION  "0.2"
@@ -2160,12 +2159,6 @@ static void vfio_iommu_iova_insert_copy(struct vfio_iommu *iommu,
 	list_splice_tail(iova_copy, iova);
 }
 
-/* Redundantly walks non-present capabilities to simplify caller */
-static int vfio_iommu_device_capable(struct device *dev, void *data)
-{
-	return device_iommu_capable(dev, (enum iommu_cap)data);
-}
-
 static int vfio_iommu_domain_alloc(struct device *dev, void *data)
 {
 	struct iommu_domain **domain = data;
@@ -2180,7 +2173,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 	struct vfio_iommu *iommu = iommu_data;
 	struct vfio_iommu_group *group;
 	struct vfio_domain *domain, *d;
-	bool resv_msi, msi_remap;
+	bool resv_msi;
 	phys_addr_t resv_msi_base = 0;
 	struct iommu_domain_geometry *geo;
 	LIST_HEAD(iova_copy);
@@ -2278,11 +2271,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 	INIT_LIST_HEAD(&domain->group_list);
 	list_add(&group->next, &domain->group_list);
 
-	msi_remap = irq_domain_check_msi_remap() ||
-		    iommu_group_for_each_dev(iommu_group, (void *)IOMMU_CAP_INTR_REMAP,
-					     vfio_iommu_device_capable);
-
-	if (!allow_unsafe_interrupts && !msi_remap) {
+	if (!allow_unsafe_interrupts &&
+	    !iommu_group_has_isolated_msi(iommu_group)) {
 		pr_warn("%s: No interrupt remapping support.  Use the module param \"allow_unsafe_interrupts\" to enable VFIO IOMMU support on this platform\n",
 		       __func__);
 		ret = -EPERM;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 4/9] iommufd: Convert to msi_device_has_isolated_msi()
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (2 preceding siblings ...)
  2022-12-12 18:45 ` [PATCH iommufd v2 3/9] vfio/type1: Convert to iommu_group_has_isolated_msi() Jason Gunthorpe
@ 2022-12-12 18:45 ` Jason Gunthorpe
  2022-12-12 18:45 ` [PATCH iommufd v2 5/9] irq: Remove unused irq_domain_check_msi_remap() code Jason Gunthorpe
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

Trivially use the new API.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommufd/device.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
index 29ff97f756bc42..3e61cc5e61af8f 100644
--- a/drivers/iommu/iommufd/device.c
+++ b/drivers/iommu/iommufd/device.c
@@ -4,7 +4,6 @@
 #include <linux/iommufd.h>
 #include <linux/slab.h>
 #include <linux/iommu.h>
-#include <linux/irqdomain.h>
 
 #include "io_pagetable.h"
 #include "iommufd_private.h"
@@ -169,8 +168,7 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev,
 	 * operation from the device (eg a simple DMA) cannot trigger an
 	 * interrupt outside this iommufd context.
 	 */
-	if (!device_iommu_capable(idev->dev, IOMMU_CAP_INTR_REMAP) &&
-	    !irq_domain_check_msi_remap()) {
+	if (!iommu_group_has_isolated_msi(idev->group)) {
 		if (!allow_unsafe_interrupts)
 			return -EPERM;
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 5/9] irq: Remove unused irq_domain_check_msi_remap() code
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (3 preceding siblings ...)
  2022-12-12 18:45 ` [PATCH iommufd v2 4/9] iommufd: Convert to msi_device_has_isolated_msi() Jason Gunthorpe
@ 2022-12-12 18:45 ` Jason Gunthorpe
  2022-12-12 18:46 ` [PATCH iommufd v2 6/9] irq: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI Jason Gunthorpe
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:45 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

After converting the users of irq_domain_check_msi_remap() it and the
helpers are no longer needed.

The new version does not require all the #ifdef helpers and inlines
because CONFIG_GENERIC_MSI_IRQ always requires CONFIG_IRQ_DOMAIN and
IRQ_DOMAIN_HIERARCHY.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 include/linux/irqdomain.h | 23 -----------------------
 kernel/irq/irqdomain.c    | 39 ---------------------------------------
 2 files changed, 62 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index a372086750ca55..b04ce03d3bb69f 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -276,7 +276,6 @@ struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode,
 					    void *host_data);
 extern struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
 						   enum irq_domain_bus_token bus_token);
-extern bool irq_domain_check_msi_remap(void);
 extern void irq_set_default_host(struct irq_domain *host);
 extern struct irq_domain *irq_get_default_host(void);
 extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
@@ -559,13 +558,6 @@ static inline bool irq_domain_is_msi(struct irq_domain *domain)
 	return domain->flags & IRQ_DOMAIN_FLAG_MSI;
 }
 
-static inline bool irq_domain_is_msi_remap(struct irq_domain *domain)
-{
-	return domain->flags & IRQ_DOMAIN_FLAG_MSI_REMAP;
-}
-
-extern bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain);
-
 static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
 {
 	return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT;
@@ -611,17 +603,6 @@ static inline bool irq_domain_is_msi(struct irq_domain *domain)
 	return false;
 }
 
-static inline bool irq_domain_is_msi_remap(struct irq_domain *domain)
-{
-	return false;
-}
-
-static inline bool
-irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
-{
-	return false;
-}
-
 static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
 {
 	return false;
@@ -641,10 +622,6 @@ static inline struct irq_domain *irq_find_matching_fwnode(
 {
 	return NULL;
 }
-static inline bool irq_domain_check_msi_remap(void)
-{
-	return false;
-}
 #endif /* !CONFIG_IRQ_DOMAIN */
 
 #endif /* _LINUX_IRQDOMAIN_H */
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 8fe1da9614ee8d..10495495158210 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -436,31 +436,6 @@ struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
 }
 EXPORT_SYMBOL_GPL(irq_find_matching_fwspec);
 
-/**
- * irq_domain_check_msi_remap - Check whether all MSI irq domains implement
- * IRQ remapping
- *
- * Return: false if any MSI irq domain does not support IRQ remapping,
- * true otherwise (including if there is no MSI irq domain)
- */
-bool irq_domain_check_msi_remap(void)
-{
-	struct irq_domain *h;
-	bool ret = true;
-
-	mutex_lock(&irq_domain_mutex);
-	list_for_each_entry(h, &irq_domain_list, link) {
-		if (irq_domain_is_msi(h) &&
-		    !irq_domain_hierarchical_is_msi_remap(h)) {
-			ret = false;
-			break;
-		}
-	}
-	mutex_unlock(&irq_domain_mutex);
-	return ret;
-}
-EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap);
-
 /**
  * irq_set_default_host() - Set a "default" irq domain
  * @domain: default domain pointer
@@ -1815,20 +1790,6 @@ static void irq_domain_check_hierarchy(struct irq_domain *domain)
 	if (domain->ops->alloc)
 		domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
 }
-
-/**
- * irq_domain_hierarchical_is_msi_remap - Check if the domain or any
- * parent has MSI remapping support
- * @domain: domain pointer
- */
-bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
-{
-	for (; domain; domain = domain->parent) {
-		if (irq_domain_is_msi_remap(domain))
-			return true;
-	}
-	return false;
-}
 #else	/* CONFIG_IRQ_DOMAIN_HIERARCHY */
 /**
  * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 6/9] irq: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (4 preceding siblings ...)
  2022-12-12 18:45 ` [PATCH iommufd v2 5/9] irq: Remove unused irq_domain_check_msi_remap() code Jason Gunthorpe
@ 2022-12-12 18:46 ` Jason Gunthorpe
  2022-12-12 18:46 ` [PATCH iommufd v2 7/9] iommu/x86: Replace IOMMU_CAP_INTR_REMAP with IRQ_DOMAIN_FLAG_ISOLATED_MSI Jason Gunthorpe
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:46 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

What x86 calls "interrupt remapping" is one way to achieve isolated MSI,
make it clear this is talking about isolated MSI, no matter how it is
achieved. This matches the new driver facing API name of
msi_device_has_isolated_msi()

No functional change.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 4 ++--
 include/linux/irqdomain.h        | 6 ++++--
 kernel/irq/msi.c                 | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 973ede0197e36f..b4069f825a9b73 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -4692,7 +4692,7 @@ static bool __maybe_unused its_enable_quirk_socionext_synquacer(void *data)
 		}
 
 		/* the pre-ITS breaks isolation, so disable MSI remapping */
-		its->msi_domain_flags &= ~IRQ_DOMAIN_FLAG_MSI_REMAP;
+		its->msi_domain_flags &= ~IRQ_DOMAIN_FLAG_ISOLATED_MSI;
 		return true;
 	}
 	return false;
@@ -5074,7 +5074,7 @@ static int __init its_probe_one(struct resource *res,
 	its->cmd_write = its->cmd_base;
 	its->fwnode_handle = handle;
 	its->get_msi_base = its_irq_get_msi_base;
-	its->msi_domain_flags = IRQ_DOMAIN_FLAG_MSI_REMAP;
+	its->msi_domain_flags = IRQ_DOMAIN_FLAG_ISOLATED_MSI;
 
 	its_enable_quirks(its);
 
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index b04ce03d3bb69f..0a3e974b7288d0 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -192,8 +192,10 @@ enum {
 	/* Irq domain implements MSIs */
 	IRQ_DOMAIN_FLAG_MSI		= (1 << 4),
 
-	/* Irq domain implements MSI remapping */
-	IRQ_DOMAIN_FLAG_MSI_REMAP	= (1 << 5),
+	/*
+	 * Irq domain implements isolated MSI, see msi_device_has_isolated_msi()
+	 */
+	IRQ_DOMAIN_FLAG_ISOLATED_MSI	= (1 << 5),
 
 	/* Irq domain doesn't translate anything */
 	IRQ_DOMAIN_FLAG_NO_MAP		= (1 << 6),
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 1c6811e145f170..7c5579d3ea4f79 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1644,7 +1644,7 @@ bool msi_device_has_isolated_msi(struct device *dev)
 	struct irq_domain *domain = dev_get_msi_domain(dev);
 
 	for (; domain; domain = domain->parent)
-		if (domain->flags & IRQ_DOMAIN_FLAG_MSI_REMAP)
+		if (domain->flags & IRQ_DOMAIN_FLAG_ISOLATED_MSI)
 			return true;
 	return false;
 }
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 7/9] iommu/x86: Replace IOMMU_CAP_INTR_REMAP with IRQ_DOMAIN_FLAG_ISOLATED_MSI
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (5 preceding siblings ...)
  2022-12-12 18:46 ` [PATCH iommufd v2 6/9] irq: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI Jason Gunthorpe
@ 2022-12-12 18:46 ` Jason Gunthorpe
  2022-12-12 18:46 ` [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390 Jason Gunthorpe
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:46 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

On x86 platforms when the HW can support interrupt remapping the iommu
driver creates an irq_domain for the IR hardware and creates a child MSI
irq_domain.

When the global irq_remapping_enabled is set, the IR MSI domain is
assigned to the PCI devices (by intel_irq_remap_add_device(), or
amd_iommu_set_pci_msi_domain()) making those devices have the isolated MSI
property.

Due to how interrupt domains work, setting IRQ_DOMAIN_FLAG_ISOLATED_MSI on
the parent IR domain will cause all struct devices attached to it to
return true from msi_device_has_isolated_msi(). This replaces the
IOMMU_CAP_INTR_REMAP flag as all places using IOMMU_CAP_INTR_REMAP also
call msi_device_has_isolated_msi()

Set the flag and delete the cap.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/iommu.c           | 5 ++---
 drivers/iommu/intel/iommu.c         | 2 --
 drivers/iommu/intel/irq_remapping.c | 3 ++-
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 8d37d9087fab28..3c2840cf275a60 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2272,8 +2272,6 @@ static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
 	switch (cap) {
 	case IOMMU_CAP_CACHE_COHERENCY:
 		return true;
-	case IOMMU_CAP_INTR_REMAP:
-		return (irq_remapping_enabled == 1);
 	case IOMMU_CAP_NOEXEC:
 		return false;
 	case IOMMU_CAP_PRE_BOOT_PROTECTION:
@@ -3672,7 +3670,8 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu)
 	}
 
 	irq_domain_update_bus_token(iommu->ir_domain,  DOMAIN_BUS_AMDVI);
-	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
+	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT |
+				   IRQ_DOMAIN_FLAG_ISOLATED_MSI;
 
 	if (amd_iommu_np_cache)
 		iommu->ir_domain->msi_parent_ops = &virt_amdvi_msi_parent_ops;
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index ebe44a07c4b00e..8037a599ade0d6 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4453,8 +4453,6 @@ static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
 	switch (cap) {
 	case IOMMU_CAP_CACHE_COHERENCY:
 		return true;
-	case IOMMU_CAP_INTR_REMAP:
-		return irq_remapping_enabled == 1;
 	case IOMMU_CAP_PRE_BOOT_PROTECTION:
 		return dmar_platform_optin();
 	case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:
diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c
index a723f53ba472f9..95d218c5077947 100644
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -576,7 +576,8 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
 	}
 
 	irq_domain_update_bus_token(iommu->ir_domain,  DOMAIN_BUS_DMAR);
-	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
+	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT |
+				   IRQ_DOMAIN_FLAG_ISOLATED_MSI;
 
 	if (cap_caching_mode(iommu->cap))
 		iommu->ir_domain->msi_parent_ops = &virt_dmar_msi_parent_ops;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (6 preceding siblings ...)
  2022-12-12 18:46 ` [PATCH iommufd v2 7/9] iommu/x86: Replace IOMMU_CAP_INTR_REMAP with IRQ_DOMAIN_FLAG_ISOLATED_MSI Jason Gunthorpe
@ 2022-12-12 18:46 ` Jason Gunthorpe
  2022-12-15  7:39   ` Tian, Kevin
  2022-12-19 16:16   ` Matthew Rosato
  2022-12-12 18:46 ` [PATCH iommufd v2 9/9] iommu: Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
  2022-12-15  7:39 ` [PATCH iommufd v2 0/9] " Tian, Kevin
  9 siblings, 2 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:46 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

s390 doesn't use irq_domains, so it has no place to set
IRQ_DOMAIN_FLAG_ISOLATED_MSI. Instead of continuing to abuse the iommu
subsystem to convey this information add a simple define which s390 can
make statically true. The define will cause msi_device_has_isolated() to
return true.

Remove IOMMU_CAP_INTR_REMAP from the s390 iommu driver.

Cc: Matthew Rosato <mjrosato@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Eric Farman <farman@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 arch/s390/include/asm/msi.h | 17 +++++++++++++++++
 drivers/iommu/s390-iommu.c  |  2 --
 include/linux/msi.h         |  6 +++++-
 kernel/irq/msi.c            |  2 +-
 4 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 arch/s390/include/asm/msi.h

diff --git a/arch/s390/include/asm/msi.h b/arch/s390/include/asm/msi.h
new file mode 100644
index 00000000000000..399343ed9ffbc6
--- /dev/null
+++ b/arch/s390/include/asm/msi.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_S390_MSI_H
+#define _ASM_S390_MSI_H
+#include <asm-generic/msi.h>
+
+/*
+ * Work around S390 not using irq_domain at all so we can't set
+ * IRQ_DOMAIN_FLAG_ISOLATED_MSI. See for an explanation how it works:
+ *
+ * https://lore.kernel.org/r/31af8174-35e9-ebeb-b9ef-74c90d4bfd93@linux.ibm.com/
+ *
+ * Note this is less isolated than the ARM/x86 versions as userspace can trigger
+ * MSI belonging to kernel devices within the same gisa.
+ */
+#define arch_is_isolated_msi() true
+
+#endif
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 3c071782f6f16d..c80f4728c0f307 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -44,8 +44,6 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
 	switch (cap) {
 	case IOMMU_CAP_CACHE_COHERENCY:
 		return true;
-	case IOMMU_CAP_INTR_REMAP:
-		return true;
 	default:
 		return false;
 	}
diff --git a/include/linux/msi.h b/include/linux/msi.h
index e8a3f3a8a7f427..5cbe6a9d27efd6 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -48,6 +48,10 @@ typedef struct arch_msi_msg_data {
 } __attribute__ ((packed)) arch_msi_msg_data_t;
 #endif
 
+#ifndef arch_is_isolated_msi
+#define arch_is_isolated_msi() false
+#endif
+
 /**
  * msi_msg - Representation of a MSI message
  * @address_lo:		Low 32 bits of msi message address
@@ -660,7 +664,7 @@ static inline bool msi_device_has_isolated_msi(struct device *dev)
 	 * is inherently isolated by our definition. As nobody seems to needs
 	 * this be conservative and return false anyhow.
 	 */
-	return false;
+	return arch_is_isolated_msi();
 }
 #endif /* CONFIG_GENERIC_MSI_IRQ */
 
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 7c5579d3ea4f79..3e46420a4f1a9f 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1646,6 +1646,6 @@ bool msi_device_has_isolated_msi(struct device *dev)
 	for (; domain; domain = domain->parent)
 		if (domain->flags & IRQ_DOMAIN_FLAG_ISOLATED_MSI)
 			return true;
-	return false;
+	return arch_is_isolated_msi();
 }
 EXPORT_SYMBOL_GPL(msi_device_has_isolated_msi);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH iommufd v2 9/9] iommu: Remove IOMMU_CAP_INTR_REMAP
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (7 preceding siblings ...)
  2022-12-12 18:46 ` [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390 Jason Gunthorpe
@ 2022-12-12 18:46 ` Jason Gunthorpe
  2022-12-15  7:39 ` [PATCH iommufd v2 0/9] " Tian, Kevin
  9 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-12 18:46 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

No iommu driver implements this any more, get rid of it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 4 +---
 include/linux/iommu.h | 1 -
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index adb3f655bf5709..b856bb3ae43fd8 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1898,9 +1898,7 @@ bool iommu_group_has_isolated_msi(struct iommu_group *group)
 
 	mutex_lock(&group->mutex);
 	list_for_each_entry(group_dev, &group->devices, list)
-		ret &= msi_device_has_isolated_msi(group_dev->dev) ||
-		       device_iommu_capable(group_dev->dev,
-					    IOMMU_CAP_INTR_REMAP);
+		ret &= msi_device_has_isolated_msi(group_dev->dev);
 	mutex_unlock(&group->mutex);
 	return ret;
 }
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 1753e819a63250..623ee6f8fdaa3b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -120,7 +120,6 @@ static inline bool iommu_is_dma_domain(struct iommu_domain *domain)
 
 enum iommu_cap {
 	IOMMU_CAP_CACHE_COHERENCY,	/* IOMMU_CACHE is supported */
-	IOMMU_CAP_INTR_REMAP,		/* IOMMU supports interrupt isolation */
 	IOMMU_CAP_NOEXEC,		/* IOMMU_NOEXEC flag */
 	IOMMU_CAP_PRE_BOOT_PROTECTION,	/* Firmware says it used the IOMMU for
 					   DMA protection and we should too */
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi()
  2022-12-12 18:45 ` [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi() Jason Gunthorpe
@ 2022-12-13 14:37   ` Jason Gunthorpe
  0 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2022-12-13 14:37 UTC (permalink / raw)
  To: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

On Mon, Dec 12, 2022 at 02:45:56PM -0400, Jason Gunthorpe wrote:
> +/**
> + * iommu_group_has_isolated_msi() - Compute msi_device_has_isolated_msi()
> + *       for a group
> + * @group: Group to query
> + *
> + * IOMMU groups should not have differing values of
> + * msi_device_has_isolated_msi() for devices in a group. However nothing
> + * directly prevents this, so ensure mistakes don't result in isolation failures
> + * by checking that all the devices are the same.
> + */
> +bool iommu_group_has_isolated_msi(struct iommu_group *group)
> +{
> +	struct group_device *group_dev;
> +	bool ret = true;
> +
> +	mutex_lock(&group->mutex);
> +	list_for_each_entry(group_dev, &group->devices, list)
> +		ret &= msi_device_has_isolated_msi(group_dev->dev) ||
> +		       device_iommu_capable(group_dev->dev,
> +					    IOMMU_CAP_INTR_REMAP);
> +	mutex_unlock(&group->mutex);

I thought I had let this sit long enough for 0-day to check it, but
nope, it needs a:

@@ -30,6 +30,7 @@
 #include <linux/cc_platform.h>
 #include <trace/events/iommu.h>
 #include <linux/sched/mm.h>
+#include <linux/msi.h>
 
 #include "dma-iommu.h"

For some configs

Jason

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390
  2022-12-12 18:46 ` [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390 Jason Gunthorpe
@ 2022-12-15  7:39   ` Tian, Kevin
  2023-01-05  0:13     ` Jason Gunthorpe
  2022-12-19 16:16   ` Matthew Rosato
  1 sibling, 1 reply; 15+ messages in thread
From: Tian, Kevin @ 2022-12-15  7:39 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, kvm, linux-s390, Marc Zyngier, Robin Murphy,
	Suravee Suthikulpanit, Sven Schnelle, Thomas Gleixner,
	Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Tuesday, December 13, 2022 2:46 AM
> @@ -660,7 +664,7 @@ static inline bool msi_device_has_isolated_msi(struct
> device *dev)
>  	 * is inherently isolated by our definition. As nobody seems to needs
>  	 * this be conservative and return false anyhow.

Also update the comment given the returned value is arch specific now.

>  	 */
> -	return false;
> +	return arch_is_isolated_msi();
>  }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP
  2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
                   ` (8 preceding siblings ...)
  2022-12-12 18:46 ` [PATCH iommufd v2 9/9] iommu: Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
@ 2022-12-15  7:39 ` Tian, Kevin
  9 siblings, 0 replies; 15+ messages in thread
From: Tian, Kevin @ 2022-12-15  7:39 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, kvm, linux-s390, Marc Zyngier, Robin Murphy,
	Suravee Suthikulpanit, Sven Schnelle, Thomas Gleixner,
	Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Matthew Rosato, Tomasz Nowicki, Will Deacon

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Tuesday, December 13, 2022 2:46 AM
> 
> v2:
>  - Rename secure_msi to isolated_msi
>  - Add iommu_group_has_isolated_msi() as a core function to support
>    VFIO/iommufd. It checks that the group has a consisent isolated_msi
>    to catch driver bugs.
>  - Revise comment and commit messages for clarity
>  - Drop the VFIO iteration patch since iommu_group_has_isolated_msi() just
>    does it.
>  - Link to Matthew's discussion about S390 and explain it is less secure

Looks good to me:

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390
  2022-12-12 18:46 ` [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390 Jason Gunthorpe
  2022-12-15  7:39   ` Tian, Kevin
@ 2022-12-19 16:16   ` Matthew Rosato
  1 sibling, 0 replies; 15+ messages in thread
From: Matthew Rosato @ 2022-12-19 16:16 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, Kevin Tian, kvm, linux-s390, Marc Zyngier,
	Robin Murphy, Suravee Suthikulpanit, Sven Schnelle,
	Thomas Gleixner, Will Deacon
  Cc: Bharat Bhushan, Christian Borntraeger, Eric Auger, Eric Farman,
	Marc Zyngier, Tomasz Nowicki, Will Deacon

On 12/12/22 1:46 PM, Jason Gunthorpe wrote:
> s390 doesn't use irq_domains, so it has no place to set
> IRQ_DOMAIN_FLAG_ISOLATED_MSI. Instead of continuing to abuse the iommu
> subsystem to convey this information add a simple define which s390 can
> make statically true. The define will cause msi_device_has_isolated() to
> return true.
> 
> Remove IOMMU_CAP_INTR_REMAP from the s390 iommu driver.
> 
> Cc: Matthew Rosato <mjrosato@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: Eric Farman <farman@linux.ibm.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>

Also sanity-tested on s390 (needed the previously-mentioned #include <linux/msi.h> added to drivers/iommu/iommu.c)

> ---
>  arch/s390/include/asm/msi.h | 17 +++++++++++++++++
>  drivers/iommu/s390-iommu.c  |  2 --
>  include/linux/msi.h         |  6 +++++-
>  kernel/irq/msi.c            |  2 +-
>  4 files changed, 23 insertions(+), 4 deletions(-)
>  create mode 100644 arch/s390/include/asm/msi.h
> 
> diff --git a/arch/s390/include/asm/msi.h b/arch/s390/include/asm/msi.h
> new file mode 100644
> index 00000000000000..399343ed9ffbc6
> --- /dev/null
> +++ b/arch/s390/include/asm/msi.h
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_S390_MSI_H
> +#define _ASM_S390_MSI_H
> +#include <asm-generic/msi.h>
> +
> +/*
> + * Work around S390 not using irq_domain at all so we can't set
> + * IRQ_DOMAIN_FLAG_ISOLATED_MSI. See for an explanation how it works:
> + *
> + * https://lore.kernel.org/r/31af8174-35e9-ebeb-b9ef-74c90d4bfd93@linux.ibm.com/
> + *
> + * Note this is less isolated than the ARM/x86 versions as userspace can trigger
> + * MSI belonging to kernel devices within the same gisa.
> + */
> +#define arch_is_isolated_msi() true
> +
> +#endif
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index 3c071782f6f16d..c80f4728c0f307 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -44,8 +44,6 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
>  	switch (cap) {
>  	case IOMMU_CAP_CACHE_COHERENCY:
>  		return true;
> -	case IOMMU_CAP_INTR_REMAP:
> -		return true;
>  	default:
>  		return false;
>  	}
> diff --git a/include/linux/msi.h b/include/linux/msi.h
> index e8a3f3a8a7f427..5cbe6a9d27efd6 100644
> --- a/include/linux/msi.h
> +++ b/include/linux/msi.h
> @@ -48,6 +48,10 @@ typedef struct arch_msi_msg_data {
>  } __attribute__ ((packed)) arch_msi_msg_data_t;
>  #endif
>  
> +#ifndef arch_is_isolated_msi
> +#define arch_is_isolated_msi() false
> +#endif
> +
>  /**
>   * msi_msg - Representation of a MSI message
>   * @address_lo:		Low 32 bits of msi message address
> @@ -660,7 +664,7 @@ static inline bool msi_device_has_isolated_msi(struct device *dev)
>  	 * is inherently isolated by our definition. As nobody seems to needs
>  	 * this be conservative and return false anyhow.
>  	 */
> -	return false;
> +	return arch_is_isolated_msi();
>  }
>  #endif /* CONFIG_GENERIC_MSI_IRQ */
>  
> diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
> index 7c5579d3ea4f79..3e46420a4f1a9f 100644
> --- a/kernel/irq/msi.c
> +++ b/kernel/irq/msi.c
> @@ -1646,6 +1646,6 @@ bool msi_device_has_isolated_msi(struct device *dev)
>  	for (; domain; domain = domain->parent)
>  		if (domain->flags & IRQ_DOMAIN_FLAG_ISOLATED_MSI)
>  			return true;
> -	return false;
> +	return arch_is_isolated_msi();
>  }
>  EXPORT_SYMBOL_GPL(msi_device_has_isolated_msi);


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390
  2022-12-15  7:39   ` Tian, Kevin
@ 2023-01-05  0:13     ` Jason Gunthorpe
  0 siblings, 0 replies; 15+ messages in thread
From: Jason Gunthorpe @ 2023-01-05  0:13 UTC (permalink / raw)
  To: Tian, Kevin
  Cc: Alexander Gordeev, Alex Williamson, Lu Baolu,
	Christian Borntraeger, Cornelia Huck, David Woodhouse,
	Gerald Schaefer, Vasily Gorbik, Heiko Carstens, iommu,
	Joerg Roedel, kvm, linux-s390, Marc Zyngier, Robin Murphy,
	Suravee Suthikulpanit, Sven Schnelle, Thomas Gleixner,
	Will Deacon, Bharat Bhushan, Christian Borntraeger, Eric Auger,
	Eric Farman, Marc Zyngier, Matthew Rosato, Tomasz Nowicki,
	Will Deacon

On Thu, Dec 15, 2022 at 07:39:25AM +0000, Tian, Kevin wrote:
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Tuesday, December 13, 2022 2:46 AM
> > @@ -660,7 +664,7 @@ static inline bool msi_device_has_isolated_msi(struct
> > device *dev)
> >  	 * is inherently isolated by our definition. As nobody seems to needs
> >  	 * this be conservative and return false anyhow.
> 
> Also update the comment given the returned value is arch specific
> now.

	/*
	 * Arguably if the platform does not enable MSI support then it has
	 * "isolated MSI", as an interrupt controller that cannot receive MSIs
	 * is inherently isolated by our definition. The default definition for
	 * arch_is_isolated_msi() is conservative and returns false anyhow.
	 */

Jason

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-01-05  0:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 18:45 [PATCH iommufd v2 0/9] Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
2022-12-12 18:45 ` [PATCH iommufd v2 1/9] irq: Add msi_device_has_isolated_msi() Jason Gunthorpe
2022-12-12 18:45 ` [PATCH iommufd v2 2/9] iommu: Add iommu_group_has_isolated_msi() Jason Gunthorpe
2022-12-13 14:37   ` Jason Gunthorpe
2022-12-12 18:45 ` [PATCH iommufd v2 3/9] vfio/type1: Convert to iommu_group_has_isolated_msi() Jason Gunthorpe
2022-12-12 18:45 ` [PATCH iommufd v2 4/9] iommufd: Convert to msi_device_has_isolated_msi() Jason Gunthorpe
2022-12-12 18:45 ` [PATCH iommufd v2 5/9] irq: Remove unused irq_domain_check_msi_remap() code Jason Gunthorpe
2022-12-12 18:46 ` [PATCH iommufd v2 6/9] irq: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI Jason Gunthorpe
2022-12-12 18:46 ` [PATCH iommufd v2 7/9] iommu/x86: Replace IOMMU_CAP_INTR_REMAP with IRQ_DOMAIN_FLAG_ISOLATED_MSI Jason Gunthorpe
2022-12-12 18:46 ` [PATCH iommufd v2 8/9] irq/s390: Add arch_is_isolated_msi() for s390 Jason Gunthorpe
2022-12-15  7:39   ` Tian, Kevin
2023-01-05  0:13     ` Jason Gunthorpe
2022-12-19 16:16   ` Matthew Rosato
2022-12-12 18:46 ` [PATCH iommufd v2 9/9] iommu: Remove IOMMU_CAP_INTR_REMAP Jason Gunthorpe
2022-12-15  7:39 ` [PATCH iommufd v2 0/9] " Tian, Kevin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.