All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: cpuidle: Disable preemption before get_lppaca function call in pseries_idle_probe function
@ 2017-07-20 17:57 Victor Aoqui
  2017-07-20 21:21 ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Victor Aoqui @ 2017-07-20 17:57 UTC (permalink / raw)
  To: rjw, daniel.lezcano, benh, paulus, mpe, linux-pm, linuxppc-dev,
	linux-kernel
  Cc: ltc-interlock, victora, victora, mauricfo

When CONFIG_PREEMPT=y, the following warning shows up:

BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
caller is pseries_processor_idle_init+0x58/0x21c

This warning shows up because preemption cannot occur when using
get_paca(), otherwise the paca_struct it points to may be the wrong one
just after.

For this reason, preemption needs to be disabled before
lppaca_shared_proc(get_lppaca()).

Signed-off-by: Victor Aoqui <victora@linux.vnet.ibm.com>
---
 drivers/cpuidle/cpuidle-pseries.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index e9b3853..d6dda8c 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -233,12 +233,16 @@ static int pseries_cpuidle_driver_init(void)
  */
 static int pseries_idle_probe(void)
 {
+	int retval;
 
 	if (cpuidle_disable != IDLE_NO_OVERRIDE)
 		return -ENODEV;
 
 	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
-		if (lppaca_shared_proc(get_lppaca())) {
+		preempt_disable();
+		retval = lppaca_shared_proc(get_lppaca());
+		preempt_enable();
+		if (retval) {
 			cpuidle_state_table = shared_states;
 			max_idle_state = ARRAY_SIZE(shared_states);
 		} else {
-- 
1.8.3.1

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

* Re: [PATCH] drivers: cpuidle: Disable preemption before get_lppaca function call in pseries_idle_probe function
  2017-07-20 17:57 [PATCH] drivers: cpuidle: Disable preemption before get_lppaca function call in pseries_idle_probe function Victor Aoqui
@ 2017-07-20 21:21 ` Benjamin Herrenschmidt
  2017-08-01 12:28   ` Victor Aoqui
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-20 21:21 UTC (permalink / raw)
  To: Victor Aoqui, rjw, daniel.lezcano, paulus, mpe, linux-pm,
	linuxppc-dev, linux-kernel
  Cc: ltc-interlock, victora, mauricfo

On Thu, 2017-07-20 at 14:57 -0300, Victor Aoqui wrote:
> When CONFIG_PREEMPT=y, the following warning shows up:
> 
> BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
> caller is pseries_processor_idle_init+0x58/0x21c
> 
> This warning shows up because preemption cannot occur when using
> get_paca(), otherwise the paca_struct it points to may be the wrong one
> just after.
> 
> For this reason, preemption needs to be disabled before
> lppaca_shared_proc(get_lppaca()).

Also chekc the generated assembly. We had all sort of interesting
issues where gcc would copy the paca pointer or the lppaca pointer
to a GPR *outside* of the preempt disabled section...

In that specific case it's not a big deal but overall, I am not
comfortable with PREEMPT on powerpc until we do something a bit
more drastic...

I would like to remove all such direct accesses to paca, instead have a
"new" get_paca() written in asm that does the preempt disable then
returns the PACA in a GPR (not directly use r13, hide that from gcc),
and which is paired with a put_paca().

The few places where we want to directly access r13 should be hand
written in asm too to hide r13 from gcc, for accessing the irq_happened
in the fast path of local_irq_enable/disable/... we should do the same
with lock tokens.

Ben.

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

* Re: [PATCH] drivers: cpuidle: Disable preemption before get_lppaca function call in pseries_idle_probe function
  2017-07-20 21:21 ` Benjamin Herrenschmidt
@ 2017-08-01 12:28   ` Victor Aoqui
  0 siblings, 0 replies; 3+ messages in thread
From: Victor Aoqui @ 2017-08-01 12:28 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: rjw, daniel.lezcano, paulus, mpe, linux-pm, linuxppc-dev,
	linux-kernel, ltc-interlock, victora, mauricfo

Em 2017-07-20 18:21, Benjamin Herrenschmidt escreveu:
> On Thu, 2017-07-20 at 14:57 -0300, Victor Aoqui wrote:
>> When CONFIG_PREEMPT=y, the following warning shows up:
>> 
>> BUG: using smp_processor_id() in preemptible [00000000] code: 
>> swapper/0/1
>> caller is pseries_processor_idle_init+0x58/0x21c
>> 
>> This warning shows up because preemption cannot occur when using
>> get_paca(), otherwise the paca_struct it points to may be the wrong 
>> one
>> just after.
>> 
>> For this reason, preemption needs to be disabled before
>> lppaca_shared_proc(get_lppaca()).
> 
> Also chekc the generated assembly. We had all sort of interesting
> issues where gcc would copy the paca pointer or the lppaca pointer
> to a GPR *outside* of the preempt disabled section...
> 
> In that specific case it's not a big deal but overall, I am not
> comfortable with PREEMPT on powerpc until we do something a bit
> more drastic...
> 
> I would like to remove all such direct accesses to paca, instead have a
> "new" get_paca() written in asm that does the preempt disable then
> returns the PACA in a GPR (not directly use r13, hide that from gcc),
> and which is paired with a put_paca().
> 
> The few places where we want to directly access r13 should be hand
> written in asm too to hide r13 from gcc, for accessing the irq_happened
> in the fast path of local_irq_enable/disable/... we should do the same
> with lock tokens.
> 
> Ben.

Hi Benjamin,

Sorry for the delay. I was a little bit busy last days.
I took note of your comments and I will work on those changes.
I will let you know soon when it's done.

Thanks

-- 
Victor Aoqui

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

end of thread, other threads:[~2017-08-01 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-20 17:57 [PATCH] drivers: cpuidle: Disable preemption before get_lppaca function call in pseries_idle_probe function Victor Aoqui
2017-07-20 21:21 ` Benjamin Herrenschmidt
2017-08-01 12:28   ` Victor Aoqui

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.