iommu/vt-d: fix iommu pasid memory alloc & max pasid err
Subsystems (2)
PATCH 1/1 iommu/vt-d: fix iommu pasid memory alloc & max pasid err
When intel_pasid_alloc_table allocates memory for Scalable Mode PASID directories, the specified memory page order is incorrect, and an additional PAGE_SHIFT is added. There is also an error in calculating the maximum number of supported PASID directories. In the revised implementation, 1 << (order + PASID_PDE_SHIFT - 3) represents the memory occupied by the Scalable Mode PASID directory, divided by 8 to represent the number of PASID directories, and then multiplied by the number of (1 << PASID_PDE_SHIFT) entries in each PASID directory.
--- drivers/iommu/intel/pasid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/pasid.c +2 -2
@@ -61,14 +61,14 @@ int intel_pasid_alloc_table(struct device *dev) size = max_pasid >> (PASID_PDE_SHIFT -3 ); order = size ?get_order (size) :0 ; dir =iommu_alloc_pages_node_sz (info->iommu->node,GFP_KERNEL , -1 << (order +PAGE_SHIFT )); +1 << order);if (!dir) {kfree (pasid_table);return -ENOMEM ; } pasid_table->table = dir; - pasid_table->max_pasid =1 << (order +PAGE_SHIFT +3 ); + pasid_table->max_pasid =1 << (order +PASID_PDE_SHIFT -3 ); info->pasid_table = pasid_table;if (!ecap_coherent (info->iommu->ecap))
Signature · 1 line
2.43.7
Baolu Lu
maintainerQuoted 8 lines · Guanghui Feng
When
intel_pasid_alloc_tableallocates memory for Scalable Mode PASID directories, the specified memory page order is incorrect, and an additionalPAGE_SHIFTis added. There is also an error in calculating the maximum number of supported PASID directories. In the revised implementation, 1 << (order +PASID_PDE_SHIFT- 3) represents the memory occupied by the Scalable Mode PASID directory, divided by 8 to represent the number of PASID directories, and then multiplied by the number of (1 <<PASID_PDE_SHIFT) entries in each PASID directory.
Do you see any specific issues if the changes described in this patch are lacking?
Quoted 11 lines
Signed-off-by Guanghui Feng <[email protected]>--- drivers/iommu/intel/pasid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/intel/pasid.c +0
-0
drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 64
Quoted 5 lines
drivers/iommu/intel/pasid.c +1
-1@@ -61,14 +61,14 @@ int intel_pasid_alloc_table(struct device *dev) size = max_pasid >> (PASID_PDE_SHIFT -3 ); order = size ?get_order (size) :0 ; dir =iommu_alloc_pages_node_sz (info->iommu->node,GFP_KERNEL , -1 << (order +PAGE_SHIFT )); +1 << order);
This converts the order to the allocation size.
drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 71
Quoted 7 lines
drivers/iommu/intel/pasid.c +0
-1if (!dir) {kfree (pasid_table);return -ENOMEM ; } pasid_table->table = dir; - pasid_table->max_pasid =1 << (order +PAGE_SHIFT +3 );
With this code, I can get the pasid_table->max_pasid equal to 0x100000 if the device supports PASID, which is what I expect.
drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 74
Quoted 4 lines
drivers/iommu/intel/pasid.c +1
-0+ pasid_table->max_pasid =1 << (order +PASID_PDE_SHIFT -3 ); info->pasid_table = pasid_table;if (!ecap_coherent (info->iommu->ecap))
Thanks,
baolu
Quoted 19 lines · Baolu Lu
Quoted 8 lines · Guanghui Feng
When
intel_pasid_alloc_tableallocates memory for Scalable Mode PASID directories, the specified memory page order is incorrect, and an additionalPAGE_SHIFTis added. There is also an error in calculating the maximum number of supported PASID directories. In the revised implementation, 1 << (order +PASID_PDE_SHIFT- 3) represents the memory occupied by the Scalable Mode PASID directory, divided by 8 to represent the number of PASID directories, and then multiplied by the number of (1 <<PASID_PDE_SHIFT) entries in each PASID directory.Do you see any specific issues if the changes described in this patch are lacking?
Quoted 6 lines
Signed-off-by Guanghui Feng <[email protected]>--- drivers/iommu/intel/pasid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines
drivers/iommu/intel/pasid.c int intel_pasid_alloc_table(struct device *dev) · line 64
Quoted 10 lines
drivers/iommu/intel/pasid.c +1
-1@@ -61,14 +61,14 @@ int intel_pasid_alloc_table(struct device *dev) size = max_pasid >> (PASID_PDE_SHIFT -3 ); order = size ?get_order (size) :0 ; dir =iommu_alloc_pages_node_sz (info->iommu->node,GFP_KERNEL , -1 << (order +PAGE_SHIFT )); +1 << order);This converts the order to the allocation size.
Yeah, I don't understand this patch at all,
iommu_alloc_pages_node_sz() takes bytes and get_order(size) returns order.
bytes == 1 << (get_order(size) + PAGE_SHIFT)
Is correct
So why is this being changed?
Jason