Skip to contentSkip to conversation

x86/platform/uv: Dont use smp_processor_id while preemptable

PATCH Superseded Mike Travis 3 participants 5 messages May 20, 2022 – May 26, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/platform/uv: Dont use smp_processor_id while preemptable

To avoid a "BUG: using smp_processor_id() in preemptible" debug warning message, disable preemption around use of the processor id.

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

Hi Mike,

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.

A git blame shows that this code has been around for quite a while; so presumably this should be backported to some of the stable kernel series ?

Maybe add an appropriate Cc: stable tag with the range of kernels this should be added to and/or add a Fixes: tag?

Regards,

Hans

Quoted 29 lines
---
 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;
 }
 
 /*
#2 lore raw

Thanks, I'll do that.

________________________________________
From: Hans de Goede <[email protected]>
Sent: Saturday, May 21, 2022 6:57 AM
To: Travis, Mike; Borislav Petkov; Dave Hansen; Ingo Molnar; Thomas Gleixner; Wahl, Steve; [email protected]
Cc: Sivanich, Dimitri; Andy Shevchenko; Darren Hart; H. Peter Anvin; Anderson, Russ; [email protected]; [email protected]
Subject: Re: [PATCH] x86/platform/uv: Dont use smp_processor_id while preemptable

Hi Mike,

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.

A git blame shows that this code has been around for quite a while; so presumably this should be backported to some of the stable kernel series ?

Maybe add an appropriate Cc: stable tag with the range of kernels this should be added to and/or add a Fixes: tag?

Regards,

Hans

Quoted 29 lines
---
 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;
 }
 
 /*
#3 lore raw
In reply to Mike Travis
Quoted 2 lines · Mike Travis

To avoid a "BUG: using smp_processor_id() in preemptible" debug warning message, disable preemption around use of the processor id.

I'm sure this gets rid of the warning. But, could you please take a quick look at the callers and ensure that they can handle if this read comes from another CPU?

In other words, what would actually go wrong if uv_read_rtc() got preempted in this region? What would this actually fix?

#4 lore raw

Dave Hansen <[email protected]> wrote:

Quoted 9 lines · Mike Travis

To avoid a "BUG: using smp_processor_id() in preemptible" debug warning message, disable preemption around use of the processor id.

I'm sure this gets rid of the warning. But, could you please take a quick look at the callers and ensure that they can handle if this read comes from another CPU?

In other words, what would actually go wrong if uv_read_rtc() got preempted in this region? What would this actually fix?

I talked with the author of this driver and among the preemption scenarios it always returns the same system time. And due to the round robin aspect of the request scheduling, getting an earlier time when a second CPU reads it's time is not possible. So getting rid of the debug warning message seems to be the only benefit from this patch.