* Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
2022-04-19 21:01 [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Nicolin Chen
@ 2022-04-19 21:05 ` Robin Murphy
2022-04-19 23:10 ` Jason Gunthorpe
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2022-04-19 21:05 UTC (permalink / raw)
To: Nicolin Chen, jgg, will, joro, jean-philippe
Cc: jacob.jun.pan, baolu.lu, fenghua.yu, rikard.falkeborn,
linux-arm-kernel, iommu, linux-kernel, stable
On 2022-04-19 22:01, Nicolin Chen wrote:
> The arm_smmu_mm_invalidate_range function is designed to be called
> by mm core for Shared Virtual Addressing purpose between IOMMU and
> CPU MMU. However, the ways of two subsystems defining their "end"
> addresses are slightly different. IOMMU defines its "end" address
> using the last address of an address range, while mm core defines
> that using the following address of an address range:
>
> include/linux/mm_types.h:
> unsigned long vm_end;
> /* The first byte after our end address ...
>
> This mismatch resulted in an incorrect calculation for size so it
> failed to be page-size aligned. Further, it caused a dead loop at
> "while (iova < end)" check in __arm_smmu_tlb_inv_range function.
>
> This patch fixes the issue by doing the calculation correctly.
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> index 22ddd05bbdcd..c623dae1e115 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn,
> {
> struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn);
> struct arm_smmu_domain *smmu_domain = smmu_mn->domain;
> - size_t size = end - start + 1;
> + size_t size;
> +
> + /*
> + * The mm_types defines vm_end as the first byte after the end address,
> + * different from IOMMU subsystem using the last address of an address
> + * range. So do a simple translation here by calculating size correctly.
> + */
> + size = end - start;
>
> if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM))
> arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid,
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
2022-04-19 21:01 [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Nicolin Chen
2022-04-19 21:05 ` Robin Murphy
@ 2022-04-19 23:10 ` Jason Gunthorpe
2022-04-19 23:36 ` Nicolin Chen
2022-04-20 8:06 ` Jean-Philippe Brucker
2022-04-20 12:31 ` Will Deacon
3 siblings, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2022-04-19 23:10 UTC (permalink / raw)
To: Nicolin Chen
Cc: will, robin.murphy, joro, jean-philippe, jacob.jun.pan, baolu.lu,
fenghua.yu, rikard.falkeborn, linux-arm-kernel, iommu,
linux-kernel, stable
On Tue, Apr 19, 2022 at 02:01:58PM -0700, Nicolin Chen wrote:
> The arm_smmu_mm_invalidate_range function is designed to be called
> by mm core for Shared Virtual Addressing purpose between IOMMU and
> CPU MMU. However, the ways of two subsystems defining their "end"
> addresses are slightly different. IOMMU defines its "end" address
> using the last address of an address range, while mm core defines
> that using the following address of an address range:
>
> include/linux/mm_types.h:
> unsigned long vm_end;
> /* The first byte after our end address ...
>
> This mismatch resulted in an incorrect calculation for size so it
> failed to be page-size aligned. Further, it caused a dead loop at
> "while (iova < end)" check in __arm_smmu_tlb_inv_range function.
>
> This patch fixes the issue by doing the calculation correctly.
>
> Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> - size_t size = end - start + 1;
> + size_t size;
> +
> + /*
> + * The mm_types defines vm_end as the first byte after the end address,
> + * different from IOMMU subsystem using the last address of an address
> + * range. So do a simple translation here by calculating size correctly.
> + */
> + size = end - start;
I would skip the comment though
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
2022-04-19 23:10 ` Jason Gunthorpe
@ 2022-04-19 23:36 ` Nicolin Chen
0 siblings, 0 replies; 6+ messages in thread
From: Nicolin Chen @ 2022-04-19 23:36 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: will, robin.murphy, joro, jean-philippe, jacob.jun.pan, baolu.lu,
fenghua.yu, rikard.falkeborn, linux-arm-kernel, iommu,
linux-kernel, stable
On Tue, Apr 19, 2022 at 08:10:34PM -0300, Jason Gunthorpe wrote:
> > - size_t size = end - start + 1;
> > + size_t size;
> > +
> > + /*
> > + * The mm_types defines vm_end as the first byte after the end address,
> > + * different from IOMMU subsystem using the last address of an address
> > + * range. So do a simple translation here by calculating size correctly.
> > + */
> > + size = end - start;
>
> I would skip the comment though
It's a bit of highlight here to help us remember in the future,
per Robin's comments at my previous patch.
Thanks!
Nic
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
2022-04-19 21:01 [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Nicolin Chen
2022-04-19 21:05 ` Robin Murphy
2022-04-19 23:10 ` Jason Gunthorpe
@ 2022-04-20 8:06 ` Jean-Philippe Brucker
2022-04-20 12:31 ` Will Deacon
3 siblings, 0 replies; 6+ messages in thread
From: Jean-Philippe Brucker @ 2022-04-20 8:06 UTC (permalink / raw)
To: Nicolin Chen
Cc: jgg, will, robin.murphy, joro, jacob.jun.pan, baolu.lu,
fenghua.yu, rikard.falkeborn, linux-arm-kernel, iommu,
linux-kernel, stable
On Tue, Apr 19, 2022 at 02:01:58PM -0700, Nicolin Chen wrote:
> The arm_smmu_mm_invalidate_range function is designed to be called
> by mm core for Shared Virtual Addressing purpose between IOMMU and
> CPU MMU. However, the ways of two subsystems defining their "end"
> addresses are slightly different. IOMMU defines its "end" address
> using the last address of an address range, while mm core defines
> that using the following address of an address range:
>
> include/linux/mm_types.h:
> unsigned long vm_end;
> /* The first byte after our end address ...
>
> This mismatch resulted in an incorrect calculation for size so it
> failed to be page-size aligned. Further, it caused a dead loop at
> "while (iova < end)" check in __arm_smmu_tlb_inv_range function.
>
> This patch fixes the issue by doing the calculation correctly.
>
> Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Thanks for the fix, I guess we didn't catch this earlier because our test
platforms didn't support range invalidation, so __arm_smmu_tlb_inv_range()
would always use PAGE_SIZE as increment.
Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> index 22ddd05bbdcd..c623dae1e115 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn,
> {
> struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn);
> struct arm_smmu_domain *smmu_domain = smmu_mn->domain;
> - size_t size = end - start + 1;
> + size_t size;
> +
> + /*
> + * The mm_types defines vm_end as the first byte after the end address,
> + * different from IOMMU subsystem using the last address of an address
> + * range. So do a simple translation here by calculating size correctly.
> + */
> + size = end - start;
>
> if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM))
> arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid,
> --
> 2.17.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
2022-04-19 21:01 [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Nicolin Chen
` (2 preceding siblings ...)
2022-04-20 8:06 ` Jean-Philippe Brucker
@ 2022-04-20 12:31 ` Will Deacon
3 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2022-04-20 12:31 UTC (permalink / raw)
To: joro, jgg, robin.murphy, Nicolin Chen, jean-philippe
Cc: catalin.marinas, kernel-team, Will Deacon, stable, jacob.jun.pan,
linux-arm-kernel, fenghua.yu, iommu, rikard.falkeborn,
linux-kernel, baolu.lu
On Tue, 19 Apr 2022 14:01:58 -0700, Nicolin Chen wrote:
> The arm_smmu_mm_invalidate_range function is designed to be called
> by mm core for Shared Virtual Addressing purpose between IOMMU and
> CPU MMU. However, the ways of two subsystems defining their "end"
> addresses are slightly different. IOMMU defines its "end" address
> using the last address of an address range, while mm core defines
> that using the following address of an address range:
>
> [...]
Applied to will (for-joerg/arm-smmu/fixes), thanks!
[1/1] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
https://git.kernel.org/will/c/95d4782c34a6
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread