linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/vt-d: fix iommu pasid memory alloc & max pasid err
@ 2025-08-30 13:07 Guanghui Feng
  2025-09-01  7:28 ` Baolu Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Guanghui Feng @ 2025-08-30 13:07 UTC (permalink / raw)
  To: dwmw2, baolu.lu, joro, will, robin.murphy
  Cc: iommu, linux-kernel, alikernel-developer

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.

Signed-off-by: Guanghui Feng <guanghuifeng@linux.alibaba.com>
---
 drivers/iommu/intel/pasid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index 52f678975da7..9969913b600b 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -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))
-- 
2.43.7


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

* Re: [PATCH] iommu/vt-d: fix iommu pasid memory alloc & max pasid err
  2025-08-30 13:07 [PATCH] iommu/vt-d: fix iommu pasid memory alloc & max pasid err Guanghui Feng
@ 2025-09-01  7:28 ` Baolu Lu
  2025-09-02 16:28   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Baolu Lu @ 2025-09-01  7:28 UTC (permalink / raw)
  To: Guanghui Feng, dwmw2, joro, will, robin.murphy
  Cc: iommu, linux-kernel, alikernel-developer

On 8/30/25 21:07, Guanghui Feng wrote:
> 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.

Do you see any specific issues if the changes described in this patch
are lacking?

> 
> Signed-off-by: Guanghui Feng <guanghuifeng@linux.alibaba.com>
> ---
>   drivers/iommu/intel/pasid.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
> index 52f678975da7..9969913b600b 100644
> --- a/drivers/iommu/intel/pasid.c
> +++ b/drivers/iommu/intel/pasid.c
> @@ -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.

>   	if (!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.

> +	pasid_table->max_pasid = 1 << (order + PASID_PDE_SHIFT - 3);
>   	info->pasid_table = pasid_table;
>   
>   	if (!ecap_coherent(info->iommu->ecap))

Thanks,
baolu

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

* Re: [PATCH] iommu/vt-d: fix iommu pasid memory alloc & max pasid err
  2025-09-01  7:28 ` Baolu Lu
@ 2025-09-02 16:28   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2025-09-02 16:28 UTC (permalink / raw)
  To: Baolu Lu
  Cc: Guanghui Feng, dwmw2, joro, will, robin.murphy, iommu,
	linux-kernel, alikernel-developer

On Mon, Sep 01, 2025 at 03:28:29PM +0800, Baolu Lu wrote:
> On 8/30/25 21:07, Guanghui Feng wrote:
> > 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.
> 
> Do you see any specific issues if the changes described in this patch
> are lacking?
> 
> > 
> > Signed-off-by: Guanghui Feng <guanghuifeng@linux.alibaba.com>
> > ---
> >   drivers/iommu/intel/pasid.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
> > index 52f678975da7..9969913b600b 100644
> > --- a/drivers/iommu/intel/pasid.c
> > +++ b/drivers/iommu/intel/pasid.c
> > @@ -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

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

end of thread, other threads:[~2025-09-02 16:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-30 13:07 [PATCH] iommu/vt-d: fix iommu pasid memory alloc & max pasid err Guanghui Feng
2025-09-01  7:28 ` Baolu Lu
2025-09-02 16:28   ` Jason Gunthorpe

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