Skip to contentSkip to conversation

iommu/tegra241-cmdqv: do not call smp_processor_id in preemptible context

PATCH Superseded Luis Claudio R. Goncalves 2 participants 3 messages Nov 19, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/tegra241-cmdqv: do not call smp_processor_id in preemptible context

With PREEMPT_RT enabled some of the calls to tegra241_cmdqv_get_cmdq() during boot will happen in preemptible context. As this function calls smp_processor_id(), these calls will trigger a "BUG: using smp_processor_id() in preemptible" backtrace if DEBUG_PREEMPT is enabled.

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.

---
 drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c +1 -1
index fcd13d301fff6..3ea4369e838fe 100644
@@ -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;
Signature · 1 line
2.47.0
#1 lore raw
Quoted 4 lines · Luis Claudio R. Goncalves

With PREEMPT_RT enabled some of the calls to tegra241_cmdqv_get_cmdq() during boot will happen in preemptible context. As this function calls smp_processor_id(), these calls will trigger a "BUG: using smp_processor_id() in preemptible" backtrace if DEBUG_PREEMPT is enabled.

If this is only on PREEMPT_RT, where is the disabled preemption coming from on !PREEMPT_RT?

Quoted 5 lines

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.

Sebastian

#2 lore raw
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Luis Claudio R. Goncalves

With PREEMPT_RT enabled some of the calls to tegra241_cmdqv_get_cmdq() during boot will happen in preemptible context. As this function calls smp_processor_id(), these calls will trigger a "BUG: using smp_processor_id() in preemptible" backtrace if DEBUG_PREEMPT is enabled.

If this is only on PREEMPT_RT, where is the disabled preemption coming from on !PREEMPT_RT?

You are correct. This is not exclusive to PREEMPT_RT, also happens with the stock kernel. I ran more tests and this time I made sure DEBUG_PREEMPT was enabled. That was enough to reproduce the problem.

Quoted 8 lines
Quoted 5 lines

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.

Sebastian

---end quoted text---