Skip to contentSkip to conversation

iommu/vt-d: Fix to flush cache of PASID directory table

PATCH Superseded Yanfei Xu 3 participants 6 messages Jun 15, 2023 – Jun 16, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yanfei Xu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix to flush cache of PASID directory table

Even the PCI devices don't support pasid capability, PASID table is mandatory for a PCI device in scalable mode. However flushing cache of pasid directory table for these devices are not taken after pasid table is allocated as the "size" of table is zero. Fix to assign it with a page size.

Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")
---
 drivers/iommu/intel/pasid.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/pasid.c +3 -1
index c5d479770e12..bde7df055865 100644
@@ -115,7 +115,9 @@ int intel_pasid_alloc_table(struct device *dev)
 				  intel_pasid_max_id);
 
 	size = max_pasid >> (PASID_PDE_SHIFT - 3);
-	order = size ? get_order(size) : 0;
+	if (!size)
+		size = PAGE_SIZE;
+	order = get_order(size);
 	pages = alloc_pages_node(info->iommu->node,
 				 GFP_KERNEL | __GFP_ZERO, order);
 	if (!pages) {
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 25 lines

-----Original Message-----
From: Yanfei Xu <[email protected]>
Sent: Thursday, June 15, 2023 3:16 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Xu, Yanfei <[email protected]>
Subject: [PATCH] iommu/vt-d: Fix to flush cache of PASID directory table

Even the PCI devices don't support pasid capability, PASID table is mandatory for a PCI device in scalable mode. However flushing cache of pasid directory table for these devices are not taken after pasid table is allocated as the "size" of table is zero. Fix to assign it with a page size.

Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")
---
 drivers/iommu/intel/pasid.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/pasid.c index renamed from drivers/iommu/intel/pasid.c +0 -0

c5d479770e12..bde7df055865 100644

drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 119

Quoted 6 lines
drivers/iommu/intel/pasid.c +2 -1
@@ -115,7 +115,9 @@ int intel_pasid_alloc_table(struct device *dev)
 				  intel_pasid_max_id);
 
 	size = max_pasid >> (PASID_PDE_SHIFT - 3);
-	order = size ? get_order(size) : 0;
+	if (!size)
+		size = PAGE_SIZE;

How about merging the logic of the above few lines into this one:
size = info->pasid_supported ? max_pasid >> (PASID_PDE_SHIFT - 3) : PAGE_SIZE;

Though the logic is about the same, the suggested one seems more intuitive.

Regards,
-Tina

Quoted 7 lines
drivers/iommu/intel/pasid.c +1 -1
+	order = get_order(size);
 	pages = alloc_pages_node(info->iommu->node,
 				 GFP_KERNEL | __GFP_ZERO, order);
 	if (!pages) {
--

2.34.1

author
#2 lore raw
Quoted 29 lines · Tina

Hi,

Quoted 27 lines

-----Original Message-----
From: Yanfei Xu <[email protected]>
Sent: Thursday, June 15, 2023 3:16 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Xu, Yanfei <[email protected]>
Subject: [PATCH] iommu/vt-d: Fix to flush cache of PASID directory table

Even the PCI devices don't support pasid capability, PASID table is mandatory for a PCI device in scalable mode. However flushing cache of pasid directory table for these devices are not taken after pasid table is allocated as the "size" of table is zero. Fix to assign it with a page size.

Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")
---
  drivers/iommu/intel/pasid.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/pasid.c index renamed from drivers/iommu/intel/pasid.c +0 -0

c5d479770e12..bde7df055865 100644

drivers/iommu/intel/pasid.c +0 -0
@@ -115,7 +115,9 @@ int intel_pasid_alloc_table(struct device *dev)
  				  intel_pasid_max_id);
 
Quoted 6 lines

drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 119

Quoted 4 lines
drivers/iommu/intel/pasid.c +2 -1
  	size = max_pasid >> (PASID_PDE_SHIFT - 3);
-	order = size ? get_order(size) : 0;
+	if (!size)
+		size = PAGE_SIZE;

How about merging the logic of the above few lines into this one:
size = info->pasid_supported ? max_pasid >> (PASID_PDE_SHIFT - 3) : PAGE_SIZE;

Yes, it would be more intuitive. But the prerequisite is if we can make sure that the value of max_pasid shifted is still greater than
0. I roughly went through the PCIE spec and didn't find out where defines the smallest PASID value for the PCIE device.

Thanks,
Yanfei

Quoted 12 lines

Though the logic is about the same, the suggested one seems more intuitive.

Regards,
-Tina

Quoted 7 lines
drivers/iommu/intel/pasid.c +1 -1
+	order = get_order(size);
  	pages = alloc_pages_node(info->iommu->node,
  				 GFP_KERNEL | __GFP_ZERO, order);
  	if (!pages) {
--

2.34.1

maintainer
#3 lore raw
In reply to Yanfei Xu
Quoted 5 lines · Yanfei Xu

Even the PCI devices don't support pasid capability, PASID table is mandatory for a PCI device in scalable mode. However flushing cache of pasid directory table for these devices are not taken after pasid table is allocated as the "size" of table is zero. Fix to assign it with a page size.

Documentation/process/submitting-patches.rst

Please add more information about

- Describe your problem.
- Any background of the problem?
- How your change fixes the problem.
...

Quoted 2 lines
Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")

Do you need a Cc stable?

Quoted 10 lines
---
  drivers/iommu/intel/pasid.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/pasid.c +0 -0
index c5d479770e12..bde7df055865 100644

drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 123

Quoted 10 lines
drivers/iommu/intel/pasid.c +3 -1
@@ -115,7 +115,9 @@ int intel_pasid_alloc_table(struct device *dev)
  				  intel_pasid_max_id);
 
  	size = max_pasid >> (PASID_PDE_SHIFT - 3);
-	order = size ? get_order(size) : 0;
+	if (!size)
+		size = PAGE_SIZE;
+	order = get_order(size);
  	pages = alloc_pages_node(info->iommu->node,
  				 GFP_KERNEL | __GFP_ZERO, order);
  	if (!pages) {

Is it similar to

drivers/iommu/intel/pasid.c +1 -1
index c5d479770e12..49fc5a038a14 100644
@@ -129,7 +129,7 @@ int intel_pasid_alloc_table(struct device *dev)
        info->pasid_table = pasid_table;
 
        if (!ecap_coherent(info->iommu->ecap))
-               clflush_cache_range(pasid_table->table, size);
+               clflush_cache_range(pasid_table->table, (1 << order) * PAGE_SIZE);
 
        return 0;
 }

?

Best regards,
baolu

author
#4 lore raw
Quoted 7 lines · Baolu Lu
Quoted 5 lines · Yanfei Xu

Even the PCI devices don't support pasid capability, PASID table is mandatory for a PCI device in scalable mode. However flushing cache of pasid directory table for these devices are not taken after pasid table is allocated as the "size" of table is zero. Fix to assign it with a page size.

Quoted 9 lines

Documentation/process/submitting-patches.rst

Please add more information about

- Describe your problem.
- Any background of the problem?
- How your change fixes the problem.
...

Got it! Will improve these in commit message.

Just noticed this when reading the iommu code, no actual problem encountered.

Quoted 4 lines
Quoted 2 lines
Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")

Do you need a Cc stable?

Yes, will add Cc: <[email protected]>

Quoted 6 lines
Quoted 6 lines

---
  drivers/iommu/intel/pasid.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
drivers/iommu/intel/pasid.c +0 -0
index c5d479770e12..bde7df055865 100644

drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 122

Quoted 9 lines
drivers/iommu/intel/pasid.c +3 -1
@@ -115,7 +115,9 @@ int intel_pasid_alloc_table(struct device *dev)
                     intel_pasid_max_id);
         size = max_pasid >> (PASID_PDE_SHIFT - 3);
-    order = size ? get_order(size) : 0;
+    if (!size)
+        size = PAGE_SIZE;
+    order = get_order(size);
       pages = alloc_pages_node(info->iommu->node,
                    GFP_KERNEL | __GFP_ZERO, order);
       if (!pages) {

Is it similar to

A little difference that real size may less than memory size calculated by order. But it is no effect. I think this is simpler.

Thanks,
Yanfei

Quoted 20 lines
drivers/iommu/intel/pasid.c +1 -1
index c5d479770e12..49fc5a038a14 100644
@@ -129,7 +129,7 @@ int intel_pasid_alloc_table(struct device *dev)
         info->pasid_table = pasid_table;
 
         if (!ecap_coherent(info->iommu->ecap))
-               clflush_cache_range(pasid_table->table, size);
+               clflush_cache_range(pasid_table->table, (1 << order) * 
 PAGE_SIZE);
 
         return 0;

 }

?

Best regards,
baolu

maintainer
#5 lore raw
Quoted 6 lines · Yanfei Xu
Quoted 4 lines
Quoted 2 lines
Fixes 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")

Do you need a Cc stable?

Yes, will add Cc: <[email protected]>

I was not asking you to Cc stable, just reminded you to consider whether your change fixes any real problem and that problem could also happen with stable kernels.

Best regards,
baolu