Skip to contentSkip to conversation

x86/platform/uv: Dont use smp_processor_id while preemptible

PATCH In review Mike Travis 2 participants 2 messages Sep 22, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/platform/uv: Dont use smp_processor_id while preemptible

To avoid a "BUG: using smp_processor_id() in preemptible" debug warning message, disable preemption around use of the processor id. This code sequence merely decides which portal that this CPU uses to read the RTC. It does this to avoid thrashing the cache but even if preempted it still reads the same time from the single RTC clock.

---
v2: modify patch description, add Cc:stable tag

---
 arch/x86/platform/uv/uv_time.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/platform/uv/uv_time.c +6 -3
index 54663f3e00cb..094190814a28 100644
@@ -275,14 +275,17 @@ static int uv_rtc_unset_timer(int cpu, int force)
  */
 static u64 uv_read_rtc(struct clocksource *cs)
 {
-	unsigned long offset;
+	unsigned long offset, time;
+	unsigned int cpu = get_cpu();
 
 	if (uv_get_min_hub_revision_id() == 1)
 		offset = 0;
 	else
-		offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
+		offset = (uv_cpu_blade_processor_id(cpu) * L1_CACHE_BYTES) % PAGE_SIZE;
 
-	return (u64)uv_read_local_mmr(UVH_RTC | offset);
+	time = (u64)uv_read_local_mmr(UVH_RTC | offset);
+	put_cpu();
+	return time;
 }
 
 /*
Signature · 1 line
2.26.2
#1 lore raw
Quoted 6 lines · Mike Travis

To avoid a "BUG: using smp_processor_id() in preemptible" debug warning message, disable preemption around use of the processor id. This code sequence merely decides which portal that this CPU uses to read the RTC. It does this to avoid thrashing the cache but even if preempted it still reads the same time from the single RTC clock.

...

Quoted 4 lines

No kernel version? No Fixes tag?

...

arch/x86/platform/uv/uv_time.c static int uv_rtc_unset_timer(int cpu, int force) · line 284

Quoted 2 lines
arch/x86/platform/uv/uv_time.c +1 -1
-               offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
+               offset = (uv_cpu_blade_processor_id(cpu) * L1_CACHE_BYTES) % PAGE_SIZE;

Perhaps it can be transformed to use offset_in_page() at the same time.

Signature · 2 lines
With Best Regards,
Andy Shevchenko