iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Intel IOMMU patch to reprocess RMRR info
@ 2012-09-18 16:49 Tom Mingarelli
       [not found] ` <20120918164955.12296.28799.sendpatchset-jP8EmR9A9vELnkn81s9yt/egYHeGw8Jk@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Tom Mingarelli @ 2012-09-18 16:49 UTC (permalink / raw)
  To: Alex Williamson,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Linda Knippers,
	Shuah Khan, Don Dutile
  Cc: Tom Mingarelli

When a 32bit PCI device is removed from the SI Domain, the RMRR information
for this device becomes invalid and needs to be reprocessed to avoid DMA
Read errors. These errors are evidenced by the Present bit being cleared in
the device's context entry. Fixing this problem with an enhancement to process
the RMRR info when the device is assigned to another domain. The Bus Master bit
is cleared during the move to another domain and during the reprocessing of
the RMRR info so no DMA can take place at this time.
----
PATCH v1: https://lkml.org/lkml/2012/6/15/204

drivers/iommu/intel-iommu.c |   47 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 3 deletions(-)

Signed-off-by: Thomas Mingarelli <thomas.mingarelli-VXdhtT5mjnY@public.gmane.org>

diff -up ./drivers/iommu/intel-iommu.c.ORIG ./drivers/iommu/intel-iommu.c
--- ./drivers/iommu/intel-iommu.c.ORIG	2012-09-18 09:58:25.147976889 -0500
+++ ./drivers/iommu/intel-iommu.c	2012-09-18 10:39:43.286672765 -0500
@@ -2706,11 +2706,39 @@ static int iommu_dummy(struct pci_dev *p
 	return pdev->dev.archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO;
 }
 
+static int reprocess_rmrr(struct device *dev)
+{
+	struct dmar_rmrr_unit *rmrr;
+	struct pci_dev *pdev;
+	int i, ret;
+
+	pdev = to_pci_dev(dev);
+
+	for_each_rmrr_units(rmrr) {
+		for (i = 0; i < rmrr->devices_cnt; i++) {
+			/*
+			 * Here we are just concerned with
+			 * finding the one device that was
+			 * removed from the si_domain and
+			 * re-evaluating its RMRR info.
+			 */
+			if (rmrr->devices[i] != pdev)
+				continue;
+			pr_info("IOMMU: Reprocess RMRR information for device %s.\n",
+				pci_name(pdev));
+			ret = iommu_prepare_rmrr_dev(rmrr, pdev);
+			if (ret)
+				pr_err("IOMMU: Reprocessing RMRR reserved region for device failed");
+		}
+	}
+return 0;
+}
+
 /* Check if the pdev needs to go through non-identity map and unmap process.*/
 static int iommu_no_mapping(struct device *dev)
 {
 	struct pci_dev *pdev;
-	int found;
+	int found, current_bus_master;
 
 	if (unlikely(dev->bus != &pci_bus_type))
 		return 1;
@@ -2731,9 +2759,22 @@ static int iommu_no_mapping(struct devic
 			 * 32 bit DMA is removed from si_domain and fall back
 			 * to non-identity mapping.
 			 */
-			domain_remove_one_dev_info(si_domain, pdev);
 			printk(KERN_INFO "32bit %s uses non-identity mapping\n",
-			       pci_name(pdev));
+				pci_name(pdev));
+			/*
+			 * If a device gets this far we need to clear the Bus
+			 * Master bit before we start moving devices from domain
+			 * to domain. We will also reset the Bus Master bit
+			 * after reprocessing the RMRR info. However, we only
+			 * do both the clearing and setting if needed.
+			 */
+			current_bus_master = pdev->is_busmaster;
+			if (current_bus_master)
+				pci_clear_master(pdev);
+			domain_remove_one_dev_info(si_domain, pdev);
+			reprocess_rmrr(dev);
+			if (current_bus_master)
+				pci_set_master(pdev);
 			return 0;
 		}
 	} else {

^ permalink raw reply	[flat|nested] 26+ messages in thread
* [PATCH v2] Intel IOMMU patch to reprocess RMRR info
@ 2012-09-18 17:27 Tom Mingarelli
  0 siblings, 0 replies; 26+ messages in thread
From: Tom Mingarelli @ 2012-09-18 17:27 UTC (permalink / raw)
  To: Alex Williamson, David Woodhouse, Don Dutile
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Shuah Khan,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Tom Mingarelli

When a 32bit PCI device is removed from the SI Domain, the RMRR information
for this device becomes invalid and needs to be reprocessed to avoid DMA
Read errors. These errors are evidenced by the Present bit being cleared in
the device's context entry. Fixing this problem with an enhancement to process
the RMRR info when the device is assigned to another domain. The Bus Master bit
is cleared during the move to another domain and during the reprocessing of
the RMRR info so no DMA can take place at this time.
----
PATCH v1: https://lkml.org/lkml/2012/6/15/204

drivers/iommu/intel-iommu.c |   47 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 3 deletions(-)

Signed-off-by: Thomas Mingarelli <thomas.mingarelli-VXdhtT5mjnY@public.gmane.org>

diff -up ./drivers/iommu/intel-iommu.c.ORIG ./drivers/iommu/intel-iommu.c
--- ./drivers/iommu/intel-iommu.c.ORIG	2012-09-18 09:58:25.147976889 -0500
+++ ./drivers/iommu/intel-iommu.c	2012-09-18 10:39:43.286672765 -0500
@@ -2706,11 +2706,39 @@ static int iommu_dummy(struct pci_dev *p
 	return pdev->dev.archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO;
 }
 
+static int reprocess_rmrr(struct device *dev)
+{
+	struct dmar_rmrr_unit *rmrr;
+	struct pci_dev *pdev;
+	int i, ret;
+
+	pdev = to_pci_dev(dev);
+
+	for_each_rmrr_units(rmrr) {
+		for (i = 0; i < rmrr->devices_cnt; i++) {
+			/*
+			 * Here we are just concerned with
+			 * finding the one device that was
+			 * removed from the si_domain and
+			 * re-evaluating its RMRR info.
+			 */
+			if (rmrr->devices[i] != pdev)
+				continue;
+			pr_info("IOMMU: Reprocess RMRR information for device %s.\n",
+				pci_name(pdev));
+			ret = iommu_prepare_rmrr_dev(rmrr, pdev);
+			if (ret)
+				pr_err("IOMMU: Reprocessing RMRR reserved region for device failed");
+		}
+	}
+return 0;
+}
+
 /* Check if the pdev needs to go through non-identity map and unmap process.*/
 static int iommu_no_mapping(struct device *dev)
 {
 	struct pci_dev *pdev;
-	int found;
+	int found, current_bus_master;
 
 	if (unlikely(dev->bus != &pci_bus_type))
 		return 1;
@@ -2731,9 +2759,22 @@ static int iommu_no_mapping(struct devic
 			 * 32 bit DMA is removed from si_domain and fall back
 			 * to non-identity mapping.
 			 */
-			domain_remove_one_dev_info(si_domain, pdev);
 			printk(KERN_INFO "32bit %s uses non-identity mapping\n",
-			       pci_name(pdev));
+				pci_name(pdev));
+			/*
+			 * If a device gets this far we need to clear the Bus
+			 * Master bit before we start moving devices from domain
+			 * to domain. We will also reset the Bus Master bit
+			 * after reprocessing the RMRR info. However, we only
+			 * do both the clearing and setting if needed.
+			 */
+			current_bus_master = pdev->is_busmaster;
+			if (current_bus_master)
+				pci_clear_master(pdev);
+			domain_remove_one_dev_info(si_domain, pdev);
+			reprocess_rmrr(dev);
+			if (current_bus_master)
+				pci_set_master(pdev);
 			return 0;
 		}
 	} else {

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: [PATCH v2] Intel IOMMU patch to reprocess RMRR info
@ 2012-09-28 15:52 David Woodhouse
       [not found] ` <uh6q9m8bwu6c2jov69m2aivu.1348847561292-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: David Woodhouse @ 2012-09-28 15:52 UTC (permalink / raw)
  To: Alex Williamson, Joerg Roedel
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Khan, Shuah,
	Mingarelli, Thomas


[-- Attachment #1.1: Type: text/plain, Size: 2665 bytes --]


HP may have been shipping such things 'for a while' but it's never actually worked right, yes? This thread is about the patch that's intended to *fix* that?

If they could just manage to make their firmware-owned DMA appear to be from a different PCIe device/function from the one the OS gets to own, that would make things "just work", right? Hell, their laptops already have Ricoh multi-function devices that do their DMA  from the 'wrong' function.... take that concept and make it useful...

If the DMA could be hidden from the IOMMU altogether, all the better. But at least coming from its own dedicated devfn would avoid the issues this patch attempts to solve.



-- 
dwmw2

(Apologies for HTML and top-posting; Android mailer is broken.)Alex Williamson <alex.williamson@redhat.com> wrote:On Fri, 2012-09-28 at 14:52 +0200, Joerg Roedel wrote:
> On Fri, Sep 28, 2012 at 06:40:08AM -0600, Alex Williamson wrote:
> > On Fri, 2012-09-28 at 11:43 +0200, Joerg Roedel wrote:
> 
> > > I don't think so. The concept of RMRR is just not defined well enough
> > > (like the concept of unity mappings on the AMD side which is similar to
> > >  RMRR). The definition says, that any memory region must be mapped at
> > > any time for the device. But that is not true (at least I have no
> > > counter-example yet). The right definition would be, that the RMRR
> > > regions are only necessary as long as the operating system does not
> > > control the particular device. And assigning a device to a guest also
> > > counts a 'taking control over the device'.
> > 
> > I think HP folks would be very unhappy with that definition.  As David
> > indicates, that's how things like USB use RMRR, but the actual
> > definition in the spec leaves much more room for abuse.  Thanks,
> 
> To my experience, for a hardware designer, existing software overrides
> any Spec because it is much worse to break existing software than it is
> to break a Spec :) So, unless we break existing hardware/firmware, I
> still suggest that we use the assumption that OS controlled devices do
> not need RMRR/unity-mapped regions anymore.

HP has been shipping hardware that makes use of RMRRs for other purposes
for a while.

> Is HP doing anything in their firmware which would not work with that?

Yes, I'll let them fill in the details.

> For the USB controlers, they only generate DMA to the RMRR/unity-mapped
> region until the OS takes over control from the firmware. After
> the USB driver is initialized the RMRR region should not be necessary
> anymore.

I agree that was probably the intent, but vendors have found loopholes
as their opportunity to innovate.  Thanks,

Alex



[-- Attachment #1.2: Type: text/html, Size: 3232 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

end of thread, other threads:[~2012-09-28 19:35 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-18 16:49 [PATCH v2] Intel IOMMU patch to reprocess RMRR info Tom Mingarelli
     [not found] ` <20120918164955.12296.28799.sendpatchset-jP8EmR9A9vELnkn81s9yt/egYHeGw8Jk@public.gmane.org>
2012-09-18 17:46   ` Don Dutile
2012-09-27 20:36   ` Alex Williamson
     [not found]     ` <1348778200.2320.241.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-27 21:10       ` Mingarelli, Thomas
     [not found]         ` <9774516974AF5F4C8A2C3C69CD3412332338F452-KNyhpuZufFMSZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2012-09-27 21:34           ` Alex Williamson
     [not found]             ` <1348781647.2320.264.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-27 21:50               ` David Woodhouse
     [not found]                 ` <1348782605.2036.117.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28  9:46                   ` Joerg Roedel
     [not found]                     ` <20120928094625.GI10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 10:23                       ` David Woodhouse
     [not found]                         ` <1348827803.2036.121.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28 12:03                           ` Joerg Roedel
2012-09-27 21:50               ` Linda Knippers
     [not found]                 ` <5064CA2D.3030206-VXdhtT5mjnY@public.gmane.org>
2012-09-27 21:48                   ` Mingarelli, Thomas
2012-09-27 21:52                   ` Alex Williamson
2012-09-28  9:43               ` Joerg Roedel
     [not found]                 ` <20120928094301.GH10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 12:40                   ` Alex Williamson
     [not found]                     ` <1348836008.2320.284.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-09-28 12:52                       ` Joerg Roedel
     [not found]                         ` <20120928125246.GK10549-5C7GfCeVMHo@public.gmane.org>
2012-09-28 13:21                           ` Alex Williamson
  -- strict thread matches above, loose matches on Subject: below --
2012-09-18 17:27 Tom Mingarelli
2012-09-28 15:52 David Woodhouse
     [not found] ` <uh6q9m8bwu6c2jov69m2aivu.1348847561292-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org>
2012-09-28 16:30   ` Alex Williamson
2012-09-28 16:36   ` Linda Knippers
     [not found]     ` <5065D1F5.1090003-VXdhtT5mjnY@public.gmane.org>
2012-09-28 17:01       ` Joerg Roedel
     [not found]         ` <20120928170106.GE18962-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2012-09-28 17:06           ` Joerg Roedel
2012-09-28 17:28           ` Alex Williamson
2012-09-28 19:15       ` David Woodhouse
     [not found]         ` <1348859719.2036.128.camel-Fexsq3y4057IgHVZqg5X0TlWvGAXklZc@public.gmane.org>
2012-09-28 19:21           ` Mingarelli, Thomas
2012-09-28 19:35           ` Shuah Khan

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).