Skip to contentSkip to conversation

iommu/vt-d: Handle memory shortage on pasid table allocation

PATCH Applied Lu Baolu 4 participants 5 messages Sep 1, 2018 – Sep 25, 2018 IOMMU

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Handle memory shortage on pasid table allocation

Pasid table memory allocation could return failure due to memory shortage. Limit the pasid table size to 1MiB because current 8MiB contiguous physical memory allocation can be hard to come by. W/o a PASID table, the device could continue to work with only shared virtual memory impacted. So, let's go ahead with context mapping even the memory allocation for pasid table failed.

Fixes cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces")
Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
Reported-and-tested-by Pelton Kyle D <[email protected]>
---
 drivers/iommu/intel-iommu.c | 6 +++---
 drivers/iommu/intel-pasid.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
index 5f3f10cf9d9d..bedc801b06a0 100644
@@ -2540,9 +2540,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
 	if (dev && dev_is_pci(dev) && info->pasid_supported) {
 		ret = intel_pasid_alloc_table(dev);
 		if (ret) {
-			__dmar_remove_one_dev_info(info);
-			spin_unlock_irqrestore(&device_domain_lock, flags);
-			return NULL;
+			pr_warn("No pasid table for %s, pasid disabled\n",
+				dev_name(dev));
+			info->pasid_supported = 0;
 		}
 	}
 	spin_unlock_irqrestore(&device_domain_lock, flags);
drivers/iommu/intel-pasid.h +1 -1
index 1c05ed6fc5a5..1fb5e12b029a 100644
@@ -11,7 +11,7 @@
 #define __INTEL_PASID_H
 
 #define PASID_MIN			0x1
-#define PASID_MAX			0x100000
+#define PASID_MAX			0x20000
 
 struct pasid_entry {
 	u64 val;
Signature · 1 line
2.17.1
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Lu Baolu

Pasid table memory allocation could return failure due to memory shortage. Limit the pasid table size to 1MiB because current 8MiB contiguous physical memory allocation can be hard to come by. W/o a PASID table, the device could continue to work with only shared virtual memory impacted. So, let's go ahead with context mapping even the memory allocation for pasid table failed.

Fixes cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces")
Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>

This fixes the issue I was seeing, thanks!

#2 lore raw
In reply to Lu Baolu
Quoted 8 lines · Lu Baolu

Pasid table memory allocation could return failure due to memory shortage. Limit the pasid table size to 1MiB because current 8MiB contiguous physical memory allocation can be hard to come by. W/o a PASID table, the device could continue to work with only shared virtual memory impacted. So, let's go ahead with context mapping even the memory allocation for pasid table failed.

Fixes cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces")

Although this reduces the changes of failure, ideally we should remove any trace of ecs support. We officially have no products that support it officially, and our latest spec does deprecate ECS feature.

Quoted 43 lines
Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
Reported-and-tested-by Pelton Kyle D <[email protected]>
---
 drivers/iommu/intel-iommu.c | 6 +++---
 drivers/iommu/intel-pasid.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
index 5f3f10cf9d9d..bedc801b06a0 100644
@@ -2540,9 +2540,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
 	if (dev && dev_is_pci(dev) && info->pasid_supported) {
 		ret = intel_pasid_alloc_table(dev);
 		if (ret) {
-			__dmar_remove_one_dev_info(info);
-			spin_unlock_irqrestore(&device_domain_lock, flags);
-			return NULL;
+			pr_warn("No pasid table for %s, pasid disabled\n",
+				dev_name(dev));
+			info->pasid_supported = 0;
 		}
 	}
 	spin_unlock_irqrestore(&device_domain_lock, flags);
drivers/iommu/intel-pasid.h +1 -1
index 1c05ed6fc5a5..1fb5e12b029a 100644
@@ -11,7 +11,7 @@
 #define __INTEL_PASID_H
 
 #define PASID_MIN			0x1
-#define PASID_MAX			0x100000
+#define PASID_MAX			0x20000
 
 struct pasid_entry {
 	u64 val;
Signature · 1 line
2.17.1
author
#3 lore raw

Hi Ashok,

Quoted 8 lines · Ashok
Quoted 7 lines · Lu Baolu

Pasid table memory allocation could return failure due to memory shortage. Limit the pasid table size to 1MiB because current 8MiB contiguous physical memory allocation can be hard to come by. W/o a PASID table, the device could continue to work with only shared virtual memory impacted. So, let's go ahead with context mapping even the memory allocation for pasid table failed.

Quoted 5 lines
Quoted 1 line
Fixes cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces")

Although this reduces the changes of failure, ideally we should remove any trace of ecs support. We officially have no products that support it officially, and our latest spec does deprecate ECS feature.

The spec update has been posted here.

https://lkml.org/lkml/2018/8/30/27

This is a fix for regression caused by cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces"), where the maximum of pasid table was changed from 1MiB to 8MiB and stopping programming context entry once the pasid table memory allocations is failed. This regression was found on some internal pre-production devices.

Best regards,
Lu Baolu

Quoted 45 lines
Quoted 44 lines
Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
Reported-and-tested-by Pelton Kyle D <[email protected]>
---
  drivers/iommu/intel-iommu.c | 6 +++---
  drivers/iommu/intel-pasid.h | 2 +-
  2 files changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
index 5f3f10cf9d9d..bedc801b06a0 100644
@@ -2540,9 +2540,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
  	if (dev && dev_is_pci(dev) && info->pasid_supported) {
  		ret = intel_pasid_alloc_table(dev);
  		if (ret) {
-			__dmar_remove_one_dev_info(info);
-			spin_unlock_irqrestore(&device_domain_lock, flags);
-			return NULL;
+			pr_warn("No pasid table for %s, pasid disabled\n",
+				dev_name(dev));
+			info->pasid_supported = 0;
  		}
  	}
  	spin_unlock_irqrestore(&device_domain_lock, flags);
drivers/iommu/intel-pasid.h +1 -1
index 1c05ed6fc5a5..1fb5e12b029a 100644
@@ -11,7 +11,7 @@
  #define __INTEL_PASID_H
 
  #define PASID_MIN			0x1
-#define PASID_MAX			0x100000
+#define PASID_MAX			0x20000
 
  struct pasid_entry {
  	u64 val;
Signature · 1 line
2.17.1
maintainer Applied
#4 lore raw
In reply to Lu Baolu
Quoted 13 lines · Lu Baolu

Pasid table memory allocation could return failure due to memory shortage. Limit the pasid table size to 1MiB because current 8MiB contiguous physical memory allocation can be hard to come by. W/o a PASID table, the device could continue to work with only shared virtual memory impacted. So, let's go ahead with context mapping even the memory allocation for pasid table failed.

Fixes cc580e41260d ("iommu/vt-d: Per PCI device pasid table interfaces")
Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
Reported-and-tested-by Pelton Kyle D <[email protected]>
Quoted 4 lines
---
 drivers/iommu/intel-iommu.c | 6 +++---
 drivers/iommu/intel-pasid.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

Applied, thanks.