iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave
@ 2020-01-15  3:03 Lu Baolu
  2020-01-15  3:03 ` [PATCH 1/5] iommu/vt-d: Don't reject Host Bridge due to scope mismatch Lu Baolu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu

Hi Joerg,

Below patches have been piled up for v5.6 since v5.5-rc3. They
are mostly misc changes and cleanups.

 - Instead of aborting DMAR processing, mark firmware tainted
   if any RMRRs fail sanity check.
 - Check host bridge type correctly.
 - Allow devices with RMRRs to use identity domain.
 - Remove duplicated default identity domain treatment.

Please consider them for the iommu/vt-d branch.

Best regards,
-baolu

Barret Rhoden (2):
  iommu/vt-d: Mark firmware tainted if RMRR fails sanity check
  iommu/vt-d: Add RMRR base and end addresses sanity check

Lu Baolu (2):
  iommu/vt-d: Allow devices with RMRRs to use identity domain
  iommu/vt-d: Unnecessary to handle default identity domain

jimyan (1):
  iommu/vt-d: Don't reject Host Bridge due to scope mismatch

 drivers/iommu/dmar.c        |  2 +-
 drivers/iommu/intel-iommu.c | 47 ++++++++++++++++++-------------------
 2 files changed, 24 insertions(+), 25 deletions(-)

-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 1/5] iommu/vt-d: Don't reject Host Bridge due to scope mismatch
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
@ 2020-01-15  3:03 ` Lu Baolu
  2020-01-15  3:03 ` [PATCH 2/5] iommu/vt-d: Mark firmware tainted if RMRR fails sanity check Lu Baolu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: jimyan, iommu

From: jimyan <jimyan@baidu.com>

On a system with two host bridges(0000:00:00.0,0000:80:00.0), iommu
initialization fails with

    DMAR: Device scope type does not match for 0000:80:00.0

This is because the DMAR table reports this device as having scope 2
(ACPI_DMAR_SCOPE_TYPE_BRIDGE):

but the device has a type 0 PCI header:
80:00.0 Class 0600: Device 8086:2020 (rev 06)
00: 86 80 20 20 47 05 10 00 06 00 00 06 10 00 00 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 86 80 00 00
30: 00 00 00 00 90 00 00 00 00 00 00 00 00 01 00 00

VT-d works perfectly on this system, so there's no reason to bail out
on initialization due to this apparent scope mismatch. Add the class
0x06 ("PCI_BASE_CLASS_BRIDGE") as a heuristic for allowing DMAR
initialization for non-bridge PCI devices listed with scope bridge.

Signed-off-by: jimyan <jimyan@baidu.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/dmar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index fb30d5053664..613b7153905d 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -244,7 +244,7 @@ int dmar_insert_dev_scope(struct dmar_pci_notify_info *info,
 		     info->dev->hdr_type != PCI_HEADER_TYPE_NORMAL) ||
 		    (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE &&
 		     (info->dev->hdr_type == PCI_HEADER_TYPE_NORMAL &&
-		      info->dev->class >> 8 != PCI_CLASS_BRIDGE_OTHER))) {
+		      info->dev->class >> 16 != PCI_BASE_CLASS_BRIDGE))) {
 			pr_warn("Device scope type does not match for %s\n",
 				pci_name(info->dev));
 			return -EINVAL;
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 2/5] iommu/vt-d: Mark firmware tainted if RMRR fails sanity check
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
  2020-01-15  3:03 ` [PATCH 1/5] iommu/vt-d: Don't reject Host Bridge due to scope mismatch Lu Baolu
@ 2020-01-15  3:03 ` Lu Baolu
  2020-01-15  3:03 ` [PATCH 3/5] iommu/vt-d: Add RMRR base and end addresses " Lu Baolu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Barret Rhoden

From: Barret Rhoden <brho@google.com>

RMRR entries describe memory regions that are DMA targets for devices
outside the kernel's control.

RMRR entries that fail the sanity check are pointing to regions of
memory that the firmware did not tell the kernel are reserved or
otherwise should not be used.

Instead of aborting DMAR processing, this commit marks the firmware
as tainted. These RMRRs will still be identity mapped, otherwise,
some devices, e.x. graphic devices, will not work during boot.

Signed-off-by: Barret Rhoden <brho@google.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 9be6717c8286..0505731b9e47 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4458,12 +4458,16 @@ int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
 {
 	struct acpi_dmar_reserved_memory *rmrr;
 	struct dmar_rmrr_unit *rmrru;
-	int ret;
 
 	rmrr = (struct acpi_dmar_reserved_memory *)header;
-	ret = arch_rmrr_sanity_check(rmrr);
-	if (ret)
-		return ret;
+	if (arch_rmrr_sanity_check(rmrr))
+		WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
+			   "Your BIOS is broken; bad RMRR [%#018Lx-%#018Lx]\n"
+			   "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
+			   rmrr->base_address, rmrr->end_address,
+			   dmi_get_system_info(DMI_BIOS_VENDOR),
+			   dmi_get_system_info(DMI_BIOS_VERSION),
+			   dmi_get_system_info(DMI_PRODUCT_VERSION));
 
 	rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL);
 	if (!rmrru)
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 3/5] iommu/vt-d: Add RMRR base and end addresses sanity check
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
  2020-01-15  3:03 ` [PATCH 1/5] iommu/vt-d: Don't reject Host Bridge due to scope mismatch Lu Baolu
  2020-01-15  3:03 ` [PATCH 2/5] iommu/vt-d: Mark firmware tainted if RMRR fails sanity check Lu Baolu
@ 2020-01-15  3:03 ` Lu Baolu
  2020-01-15  3:03 ` [PATCH 4/5] iommu/vt-d: Allow devices with RMRRs to use identity domain Lu Baolu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Barret Rhoden

From: Barret Rhoden <brho@google.com>

The VT-d spec specifies requirements for the RMRR entries base and
end (called 'Limit' in the docs) addresses.

This commit will cause the DMAR processing to mark the firmware as
tainted if any RMRR entries that do not meet these requirements.

Signed-off-by: Barret Rhoden <brho@google.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 0505731b9e47..c6843642f462 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4454,13 +4454,24 @@ static void __init init_iommu_pm_ops(void)
 static inline void init_iommu_pm_ops(void) {}
 #endif	/* CONFIG_PM */
 
+static int rmrr_sanity_check(struct acpi_dmar_reserved_memory *rmrr)
+{
+	if (!IS_ALIGNED(rmrr->base_address, PAGE_SIZE) ||
+	    !IS_ALIGNED(rmrr->end_address + 1, PAGE_SIZE) ||
+	    rmrr->end_address <= rmrr->base_address ||
+	    arch_rmrr_sanity_check(rmrr))
+		return -EINVAL;
+
+	return 0;
+}
+
 int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
 {
 	struct acpi_dmar_reserved_memory *rmrr;
 	struct dmar_rmrr_unit *rmrru;
 
 	rmrr = (struct acpi_dmar_reserved_memory *)header;
-	if (arch_rmrr_sanity_check(rmrr))
+	if (rmrr_sanity_check(rmrr))
 		WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
 			   "Your BIOS is broken; bad RMRR [%#018Lx-%#018Lx]\n"
 			   "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 4/5] iommu/vt-d: Allow devices with RMRRs to use identity domain
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
                   ` (2 preceding siblings ...)
  2020-01-15  3:03 ` [PATCH 3/5] iommu/vt-d: Add RMRR base and end addresses " Lu Baolu
@ 2020-01-15  3:03 ` Lu Baolu
  2020-01-15  3:03 ` [PATCH 5/5] iommu/vt-d: Unnecessary to handle default " Lu Baolu
  2020-01-17  9:58 ` [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu

Since commit ea2447f700cab ("intel-iommu: Prevent devices with
RMRRs from being placed into SI Domain"), the Intel IOMMU driver
doesn't allow any devices with RMRR locked to use the identity
domain. This was added to to fix the issue where the RMRR info
for devices being placed in and out of the identity domain gets
lost. This identity maps all RMRRs when setting up the identity
domain, so that devices with RMRRs could also use it.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index c6843642f462..3446da5a2186 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2893,10 +2893,8 @@ static int __init si_domain_init(int hw)
 	}
 
 	/*
-	 * Normally we use DMA domains for devices which have RMRRs. But we
-	 * loose this requirement for graphic and usb devices. Identity map
-	 * the RMRRs for graphic and USB devices so that they could use the
-	 * si_domain.
+	 * Identity map the RMRRs so that devices with RMRRs could also use
+	 * the si_domain.
 	 */
 	for_each_rmrr_units(rmrr) {
 		for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt,
@@ -2904,9 +2902,6 @@ static int __init si_domain_init(int hw)
 			unsigned long long start = rmrr->base_address;
 			unsigned long long end = rmrr->end_address;
 
-			if (device_is_rmrr_locked(dev))
-				continue;
-
 			if (WARN_ON(end < start ||
 				    end >> agaw_to_width(si_domain->agaw)))
 				continue;
@@ -3045,9 +3040,6 @@ static int device_def_domain_type(struct device *dev)
 	if (dev_is_pci(dev)) {
 		struct pci_dev *pdev = to_pci_dev(dev);
 
-		if (device_is_rmrr_locked(dev))
-			return IOMMU_DOMAIN_DMA;
-
 		/*
 		 * Prevent any device marked as untrusted from getting
 		 * placed into the statically identity mapping domain.
@@ -3085,9 +3077,6 @@ static int device_def_domain_type(struct device *dev)
 				return IOMMU_DOMAIN_DMA;
 		} else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE)
 			return IOMMU_DOMAIN_DMA;
-	} else {
-		if (device_has_rmrr(dev))
-			return IOMMU_DOMAIN_DMA;
 	}
 
 	return (iommu_identity_mapping & IDENTMAP_ALL) ?
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 5/5] iommu/vt-d: Unnecessary to handle default identity domain
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
                   ` (3 preceding siblings ...)
  2020-01-15  3:03 ` [PATCH 4/5] iommu/vt-d: Allow devices with RMRRs to use identity domain Lu Baolu
@ 2020-01-15  3:03 ` Lu Baolu
  2020-01-17  9:58 ` [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2020-01-15  3:03 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu

The iommu default domain framework has been designed to take
care of setting identity default domain type. It's unnecessary
to handle this again in the VT-d driver. Hence, remove it.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 3446da5a2186..f1f812cb7b9d 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -387,7 +387,6 @@ static int intel_iommu_superpage = 1;
 static int iommu_identity_mapping;
 static int intel_no_bounce;
 
-#define IDENTMAP_ALL		1
 #define IDENTMAP_GFX		2
 #define IDENTMAP_AZALIA		4
 
@@ -3079,8 +3078,7 @@ static int device_def_domain_type(struct device *dev)
 			return IOMMU_DOMAIN_DMA;
 	}
 
-	return (iommu_identity_mapping & IDENTMAP_ALL) ?
-			IOMMU_DOMAIN_IDENTITY : 0;
+	return 0;
 }
 
 static void intel_iommu_init_qi(struct intel_iommu *iommu)
@@ -3424,9 +3422,6 @@ static int __init init_dmars(void)
 		iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH);
 	}
 
-	if (iommu_default_passthrough())
-		iommu_identity_mapping |= IDENTMAP_ALL;
-
 #ifdef CONFIG_INTEL_IOMMU_BROKEN_GFX_WA
 	dmar_map_gfx = 0;
 #endif
@@ -5038,7 +5033,7 @@ static int __init platform_optin_force_iommu(void)
 	 * map for all devices except those marked as being untrusted.
 	 */
 	if (dmar_disabled)
-		iommu_identity_mapping |= IDENTMAP_ALL;
+		iommu_set_default_passthrough(false);
 
 	dmar_disabled = 0;
 	no_iommu = 0;
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave
  2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
                   ` (4 preceding siblings ...)
  2020-01-15  3:03 ` [PATCH 5/5] iommu/vt-d: Unnecessary to handle default " Lu Baolu
@ 2020-01-17  9:58 ` Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2020-01-17  9:58 UTC (permalink / raw)
  To: Lu Baolu; +Cc: iommu

On Wed, Jan 15, 2020 at 11:03:54AM +0800, Lu Baolu wrote:
> Barret Rhoden (2):
>   iommu/vt-d: Mark firmware tainted if RMRR fails sanity check
>   iommu/vt-d: Add RMRR base and end addresses sanity check
> 
> Lu Baolu (2):
>   iommu/vt-d: Allow devices with RMRRs to use identity domain
>   iommu/vt-d: Unnecessary to handle default identity domain
> 
> jimyan (1):
>   iommu/vt-d: Don't reject Host Bridge due to scope mismatch
> 
>  drivers/iommu/dmar.c        |  2 +-
>  drivers/iommu/intel-iommu.c | 47 ++++++++++++++++++-------------------
>  2 files changed, 24 insertions(+), 25 deletions(-)

All queued to the x86/vt-d branch, thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2020-01-17  9:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15  3:03 [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Lu Baolu
2020-01-15  3:03 ` [PATCH 1/5] iommu/vt-d: Don't reject Host Bridge due to scope mismatch Lu Baolu
2020-01-15  3:03 ` [PATCH 2/5] iommu/vt-d: Mark firmware tainted if RMRR fails sanity check Lu Baolu
2020-01-15  3:03 ` [PATCH 3/5] iommu/vt-d: Add RMRR base and end addresses " Lu Baolu
2020-01-15  3:03 ` [PATCH 4/5] iommu/vt-d: Allow devices with RMRRs to use identity domain Lu Baolu
2020-01-15  3:03 ` [PATCH 5/5] iommu/vt-d: Unnecessary to handle default " Lu Baolu
2020-01-17  9:58 ` [PULL REQUEST] iommu/vt-d: patches for v5.6 - 2nd wave Joerg Roedel

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