All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/platform/uv: Dont use smp_processor_id while preemptible
@ 2022-09-22 20:00 Mike Travis
  2022-09-22 20:59 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Travis @ 2022-09-22 20:00 UTC (permalink / raw)
  To: Borislav Petkov, Dave Hansen, Ingo Molnar, Thomas Gleixner,
	Steve Wahl, x86
  Cc: Mike Travis, Dimitri Sivanich, stable, Andy Shevchenko,
	Darren Hart, H. Peter Anvin, Russ Anderson, linux-kernel,
	platform-driver-x86

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.

Signed-off-by: Mike Travis <mike.travis@hpe.com>
Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
Reviewed-by: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: stable@vger.kernel.org
---
v2: modify patch description, add Cc:stable tag
---
 arch/x86/platform/uv/uv_time.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/uv/uv_time.c b/arch/x86/platform/uv/uv_time.c
index 54663f3e00cb..094190814a28 100644
--- a/arch/x86/platform/uv/uv_time.c
+++ b/arch/x86/platform/uv/uv_time.c
@@ -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.26.2


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

* Re: [PATCH v2] x86/platform/uv: Dont use smp_processor_id while preemptible
  2022-09-22 20:00 [PATCH v2] x86/platform/uv: Dont use smp_processor_id while preemptible Mike Travis
@ 2022-09-22 20:59 ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-09-22 20:59 UTC (permalink / raw)
  To: Mike Travis
  Cc: Borislav Petkov, Dave Hansen, Ingo Molnar, Thomas Gleixner,
	Steve Wahl, x86, Dimitri Sivanich, stable, Andy Shevchenko,
	Darren Hart, H. Peter Anvin, Russ Anderson, linux-kernel,
	platform-driver-x86

On Thu, Sep 22, 2022 at 11:01 PM Mike Travis <mike.travis@hpe.com> wrote:
>
> 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.

...

> Signed-off-by: Mike Travis <mike.travis@hpe.com>
> Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
> Reviewed-by: Dimitri Sivanich <dimitri.sivanich@hpe.com>
> Cc: stable@vger.kernel.org

No kernel version? No Fixes tag?

...

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

-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH v2] x86/platform/uv: Dont use smp_processor_id while preemptible
@ 2022-05-23 16:45 Mike Travis
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Travis @ 2022-05-23 16:45 UTC (permalink / raw)
  To: Borislav Petkov, Dave Hansen, Ingo Molnar, Thomas Gleixner,
	Steve Wahl, x86
  Cc: Mike Travis, Dimitri Sivanich, stable, Andy Shevchenko,
	Darren Hart, H. Peter Anvin, Russ Anderson, linux-kernel,
	platform-driver-x86

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

Signed-off-by: Mike Travis <mike.travis@hpe.com>
Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
Reviewed-by: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: stable@vger.kernel.org
---
v2: Add Cc: stable tag
---
 arch/x86/platform/uv/uv_time.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/uv/uv_time.c b/arch/x86/platform/uv/uv_time.c
index 54663f3e00cb..094190814a28 100644
--- a/arch/x86/platform/uv/uv_time.c
+++ b/arch/x86/platform/uv/uv_time.c
@@ -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.26.2


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

end of thread, other threads:[~2022-09-22 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 20:00 [PATCH v2] x86/platform/uv: Dont use smp_processor_id while preemptible Mike Travis
2022-09-22 20:59 ` Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2022-05-23 16:45 Mike Travis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.