public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context
@ 2024-12-06 13:01 Luis Claudio R. Goncalves
  2024-12-09 14:20 ` Jason Gunthorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luis Claudio R. Goncalves @ 2024-12-06 13:01 UTC (permalink / raw)
  To: Thierry Reding, Krishna Reddy, Will Deacon, Robin Murphy,
	Joerg Roedel, Jonathan Hunter, linux-kernel, iommu,
	linux-arm-kernel, linux-tegra, Sebastian Andrzej Siewior,
	Steven Rostedt, linux-rt-devel

During boot some of the calls to tegra241_cmdqv_get_cmdq() will happen
in preemptible context. As this function calls smp_processor_id(), if
CONFIG_DEBUG_PREEMPT is enabled, these calls will trigger a series of
"BUG: using smp_processor_id() in preemptible" backtraces.

As tegra241_cmdqv_get_cmdq() only calls smp_processor_id() to use the
CPU number as a factor to balance out traffic on cmdq usage, it is safe
to use raw_smp_processor_id() here.

v2: Sebastian helped identify that the problem was not exclusive to kernels
    with PREEMPT_RT enabled. The delta between v1 and v2 is the description.

Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
 drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c
index fcd13d301fff6..3ea4369e838fe 100644
--- a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c
+++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c
@@ -339,7 +339,7 @@ tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu,
 	 * one CPU at a time can enter the process, while the others
 	 * will be spinning at the same lock.
 	 */
-	lidx = smp_processor_id() % cmdqv->num_lvcmdqs_per_vintf;
+	lidx = raw_smp_processor_id() % cmdqv->num_lvcmdqs_per_vintf;
 	vcmdq = vintf->lvcmdqs[lidx];
 	if (!vcmdq || !READ_ONCE(vcmdq->enabled))
 		return NULL;
-- 
2.47.0


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

* Re: [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context
  2024-12-06 13:01 [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context Luis Claudio R. Goncalves
@ 2024-12-09 14:20 ` Jason Gunthorpe
  2024-12-09 19:03 ` Nicolin Chen
  2024-12-10  0:17 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2024-12-09 14:20 UTC (permalink / raw)
  To: Luis Claudio R. Goncalves
  Cc: Thierry Reding, Krishna Reddy, Will Deacon, Robin Murphy,
	Joerg Roedel, Jonathan Hunter, linux-kernel, iommu,
	linux-arm-kernel, linux-tegra, Sebastian Andrzej Siewior,
	Steven Rostedt, linux-rt-devel

On Fri, Dec 06, 2024 at 10:01:14AM -0300, Luis Claudio R. Goncalves wrote:
> During boot some of the calls to tegra241_cmdqv_get_cmdq() will happen
> in preemptible context. As this function calls smp_processor_id(), if
> CONFIG_DEBUG_PREEMPT is enabled, these calls will trigger a series of
> "BUG: using smp_processor_id() in preemptible" backtraces.
> 
> As tegra241_cmdqv_get_cmdq() only calls smp_processor_id() to use the
> CPU number as a factor to balance out traffic on cmdq usage, it is safe
> to use raw_smp_processor_id() here.
> 
> v2: Sebastian helped identify that the problem was not exclusive to kernels
>     with PREEMPT_RT enabled. The delta between v1 and v2 is the description.
> 
> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
> ---
>  drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Makes sense

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason

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

* Re: [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context
  2024-12-06 13:01 [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context Luis Claudio R. Goncalves
  2024-12-09 14:20 ` Jason Gunthorpe
@ 2024-12-09 19:03 ` Nicolin Chen
  2024-12-10  0:17 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolin Chen @ 2024-12-09 19:03 UTC (permalink / raw)
  To: Luis Claudio R. Goncalves
  Cc: Thierry Reding, Krishna Reddy, Will Deacon, Robin Murphy,
	Joerg Roedel, Jonathan Hunter, linux-kernel, iommu,
	linux-arm-kernel, linux-tegra, Sebastian Andrzej Siewior,
	Steven Rostedt, linux-rt-devel

On Fri, Dec 06, 2024 at 10:01:14AM -0300, Luis Claudio R. Goncalves wrote:
> During boot some of the calls to tegra241_cmdqv_get_cmdq() will happen
> in preemptible context. As this function calls smp_processor_id(), if
> CONFIG_DEBUG_PREEMPT is enabled, these calls will trigger a series of
> "BUG: using smp_processor_id() in preemptible" backtraces.

Confirmed the BUG prints. Should we CC stable tree?

> As tegra241_cmdqv_get_cmdq() only calls smp_processor_id() to use the
> CPU number as a factor to balance out traffic on cmdq usage, it is safe
> to use raw_smp_processor_id() here.
> 
> v2: Sebastian helped identify that the problem was not exclusive to kernels
>     with PREEMPT_RT enabled. The delta between v1 and v2 is the description.
> 
> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>

Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>

Thanks
Nicolin

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

* Re: [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context
  2024-12-06 13:01 [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context Luis Claudio R. Goncalves
  2024-12-09 14:20 ` Jason Gunthorpe
  2024-12-09 19:03 ` Nicolin Chen
@ 2024-12-10  0:17 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2024-12-10  0:17 UTC (permalink / raw)
  To: Thierry Reding, Krishna Reddy, Robin Murphy, Joerg Roedel,
	Jonathan Hunter, linux-kernel, iommu, linux-arm-kernel,
	linux-tegra, Sebastian Andrzej Siewior, Steven Rostedt,
	linux-rt-devel, Luis Claudio R. Goncalves
  Cc: catalin.marinas, kernel-team, Will Deacon

On Fri, 06 Dec 2024 10:01:14 -0300, Luis Claudio R. Goncalves wrote:
> During boot some of the calls to tegra241_cmdqv_get_cmdq() will happen
> in preemptible context. As this function calls smp_processor_id(), if
> CONFIG_DEBUG_PREEMPT is enabled, these calls will trigger a series of
> "BUG: using smp_processor_id() in preemptible" backtraces.
> 
> As tegra241_cmdqv_get_cmdq() only calls smp_processor_id() to use the
> CPU number as a factor to balance out traffic on cmdq usage, it is safe
> to use raw_smp_processor_id() here.
> 
> [...]

Applied to will (for-joerg/arm-smmu/fixes), thanks!

[1/1] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context
      https://git.kernel.org/will/c/1f806218164d

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2024-12-10  0:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-06 13:01 [PATCH v2] iommu/tegra241-cmdqv: do not use smp_processor_id in preemptible context Luis Claudio R. Goncalves
2024-12-09 14:20 ` Jason Gunthorpe
2024-12-09 19:03 ` Nicolin Chen
2024-12-10  0:17 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox