All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390: preempt: Fix preempt_count initialization
@ 2021-07-07 16:33 Valentin Schneider
  2021-07-08 14:17 ` Heiko Carstens
  0 siblings, 1 reply; 4+ messages in thread
From: Valentin Schneider @ 2021-07-07 16:33 UTC (permalink / raw)
  To: linux-kernel, linux-s390
  Cc: Guenter Roeck, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Frederic Weisbecker, Alexey Kardashevskiy,
	Peter Zijlstra, Ingo Molnar

S390's init_idle_preempt_count(p, cpu) doesn't actually let us initialize the
preempt_count of the requested CPU's idle task: it unconditionally writes
to the current CPU's. This clearly conflicts with idle_threads_init(),
which intends to initialize *all* the idle tasks, including their
preempt_count (or their CPU's, if the arch uses a per-CPU preempt_count).

Unfortunately, it seems the way s390 does things doesn't let us initialize
every possible CPU's preempt_count early on, as the pages where this
resides are only allocated when a CPU is brought up and are freed when it
is brought down.

Let the arch-specific code set a CPU's preempt_count when its lowcore is
allocated, and turn init_idle_preempt_count() into an empty stub.

Fixes: f1a0a376ca0c ("sched/core: Initialize the idle task with preemption disabled")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
---
 arch/s390/include/asm/preempt.h | 16 ++++------------
 arch/s390/kernel/setup.c        |  1 +
 arch/s390/kernel/smp.c          |  1 +
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/s390/include/asm/preempt.h b/arch/s390/include/asm/preempt.h
index 23ff51be7e29..d9d5350cc3ec 100644
--- a/arch/s390/include/asm/preempt.h
+++ b/arch/s390/include/asm/preempt.h
@@ -29,12 +29,6 @@ static inline void preempt_count_set(int pc)
 				  old, new) != old);
 }
 
-#define init_task_preempt_count(p)	do { } while (0)
-
-#define init_idle_preempt_count(p, cpu)	do { \
-	S390_lowcore.preempt_count = PREEMPT_DISABLED; \
-} while (0)
-
 static inline void set_preempt_need_resched(void)
 {
 	__atomic_and(~PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
@@ -88,12 +82,6 @@ static inline void preempt_count_set(int pc)
 	S390_lowcore.preempt_count = pc;
 }
 
-#define init_task_preempt_count(p)	do { } while (0)
-
-#define init_idle_preempt_count(p, cpu)	do { \
-	S390_lowcore.preempt_count = PREEMPT_DISABLED; \
-} while (0)
-
 static inline void set_preempt_need_resched(void)
 {
 }
@@ -130,6 +118,10 @@ static inline bool should_resched(int preempt_offset)
 
 #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
 
+#define init_task_preempt_count(p)	do { } while (0)
+/* Deferred to CPU bringup time */
+#define init_idle_preempt_count(p, cpu)	do { } while (0)
+
 #ifdef CONFIG_PREEMPTION
 extern void preempt_schedule(void);
 #define __preempt_schedule() preempt_schedule()
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 5aab59ad5688..382d73da134c 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -466,6 +466,7 @@ static void __init setup_lowcore_dat_off(void)
 	lc->br_r1_trampoline = 0x07f1;	/* br %r1 */
 	lc->return_lpswe = gen_lpswe(__LC_RETURN_PSW);
 	lc->return_mcck_lpswe = gen_lpswe(__LC_RETURN_MCCK_PSW);
+	lc->preempt_count = PREEMPT_DISABLED;
 
 	set_prefix((u32)(unsigned long) lc);
 	lowcore_ptr[0] = lc;
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index 111909aeb8d2..1fb483e06a64 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -219,6 +219,7 @@ static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
 	lc->br_r1_trampoline = 0x07f1;	/* br %r1 */
 	lc->return_lpswe = gen_lpswe(__LC_RETURN_PSW);
 	lc->return_mcck_lpswe = gen_lpswe(__LC_RETURN_MCCK_PSW);
+	lc->preempt_count = PREEMPT_DISABLED;
 	if (nmi_alloc_per_cpu(lc))
 		goto out_stack;
 	lowcore_ptr[cpu] = lc;
-- 
2.25.1


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

* Re: [PATCH] s390: preempt: Fix preempt_count initialization
  2021-07-07 16:33 [PATCH] s390: preempt: Fix preempt_count initialization Valentin Schneider
@ 2021-07-08 14:17 ` Heiko Carstens
  2021-07-08 14:19   ` Vasily Gorbik
  0 siblings, 1 reply; 4+ messages in thread
From: Heiko Carstens @ 2021-07-08 14:17 UTC (permalink / raw)
  To: Valentin Schneider
  Cc: linux-kernel, linux-s390, Guenter Roeck, Vasily Gorbik,
	Christian Borntraeger, Frederic Weisbecker, Alexey Kardashevskiy,
	Peter Zijlstra, Ingo Molnar

On Wed, Jul 07, 2021 at 05:33:38PM +0100, Valentin Schneider wrote:
> S390's init_idle_preempt_count(p, cpu) doesn't actually let us initialize the
> preempt_count of the requested CPU's idle task: it unconditionally writes
> to the current CPU's. This clearly conflicts with idle_threads_init(),
> which intends to initialize *all* the idle tasks, including their
> preempt_count (or their CPU's, if the arch uses a per-CPU preempt_count).
> 
> Unfortunately, it seems the way s390 does things doesn't let us initialize
> every possible CPU's preempt_count early on, as the pages where this
> resides are only allocated when a CPU is brought up and are freed when it
> is brought down.
> 
> Let the arch-specific code set a CPU's preempt_count when its lowcore is
> allocated, and turn init_idle_preempt_count() into an empty stub.
> 
> Fixes: f1a0a376ca0c ("sched/core: Initialize the idle task with preemption disabled")
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> ---
>  arch/s390/include/asm/preempt.h | 16 ++++------------
>  arch/s390/kernel/setup.c        |  1 +
>  arch/s390/kernel/smp.c          |  1 +
>  3 files changed, 6 insertions(+), 12 deletions(-)

Reviewed-by: Heiko Carstens <hca@linux.ibm.com>

Vasily, can you pick this one up, please?

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

* Re: [PATCH] s390: preempt: Fix preempt_count initialization
  2021-07-08 14:17 ` Heiko Carstens
@ 2021-07-08 14:19   ` Vasily Gorbik
  0 siblings, 0 replies; 4+ messages in thread
From: Vasily Gorbik @ 2021-07-08 14:19 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Valentin Schneider, linux-kernel, linux-s390, Guenter Roeck,
	Christian Borntraeger, Frederic Weisbecker, Alexey Kardashevskiy,
	Peter Zijlstra, Ingo Molnar

On Thu, Jul 08, 2021 at 04:17:10PM +0200, Heiko Carstens wrote:
> On Wed, Jul 07, 2021 at 05:33:38PM +0100, Valentin Schneider wrote:
> > S390's init_idle_preempt_count(p, cpu) doesn't actually let us initialize the
> > preempt_count of the requested CPU's idle task: it unconditionally writes
> > to the current CPU's. This clearly conflicts with idle_threads_init(),
> > which intends to initialize *all* the idle tasks, including their
> > preempt_count (or their CPU's, if the arch uses a per-CPU preempt_count).
> > 
> > Unfortunately, it seems the way s390 does things doesn't let us initialize
> > every possible CPU's preempt_count early on, as the pages where this
> > resides are only allocated when a CPU is brought up and are freed when it
> > is brought down.
> > 
> > Let the arch-specific code set a CPU's preempt_count when its lowcore is
> > allocated, and turn init_idle_preempt_count() into an empty stub.
> > 
> > Fixes: f1a0a376ca0c ("sched/core: Initialize the idle task with preemption disabled")
> > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> > ---
> >  arch/s390/include/asm/preempt.h | 16 ++++------------
> >  arch/s390/kernel/setup.c        |  1 +
> >  arch/s390/kernel/smp.c          |  1 +
> >  3 files changed, 6 insertions(+), 12 deletions(-)
> 
> Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
> 
> Vasily, can you pick this one up, please?

Will pick it up right away for rc1, thanks!

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

* Re: [PATCH] s390: preempt: Fix preempt_count initialization
@ 2021-07-07 19:42 Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2021-07-07 19:42 UTC (permalink / raw)
  To: Valentin Schneider
  Cc: linux-kernel, linux-s390, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Frederic Weisbecker, Alexey Kardashevskiy,
	Peter Zijlstra, Ingo Molnar

On Wed, Jul 07, 2021 at 05:33:38PM +0100, Valentin Schneider wrote:
> S390's init_idle_preempt_count(p, cpu) doesn't actually let us initialize the
> preempt_count of the requested CPU's idle task: it unconditionally writes
> to the current CPU's. This clearly conflicts with idle_threads_init(),
> which intends to initialize *all* the idle tasks, including their
> preempt_count (or their CPU's, if the arch uses a per-CPU preempt_count).
> 
> Unfortunately, it seems the way s390 does things doesn't let us initialize
> every possible CPU's preempt_count early on, as the pages where this
> resides are only allocated when a CPU is brought up and are freed when it
> is brought down.
> 
> Let the arch-specific code set a CPU's preempt_count when its lowcore is
> allocated, and turn init_idle_preempt_count() into an empty stub.
> 
> Fixes: f1a0a376ca0c ("sched/core: Initialize the idle task with preemption disabled")
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

Guenter

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

end of thread, other threads:[~2021-07-08 14:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 16:33 [PATCH] s390: preempt: Fix preempt_count initialization Valentin Schneider
2021-07-08 14:17 ` Heiko Carstens
2021-07-08 14:19   ` Vasily Gorbik
2021-07-07 19:42 Guenter Roeck

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.