Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/rtas: Introduce rtas_get_sensor_fast() for IRQ handlers

The EPOW interrupt handler uses rtas_get_sensor(), which in turn
uses rtas_busy_delay() to wait for RTAS becoming ready in case it
is necessary. But rtas_busy_delay() is annotated with might_sleep()
and thus may not be used by interrupts handlers like the EPOW handler!
This leads to the following BUG when CONFIG_DEBUG_ATOMIC_SLEEP is
enabled:

BUG: sleeping function called from invalid context at arch/powerpc/kernel/rtas.c:496
in_atomic(): 1, irqs_disabled(): 1, pid: 0, name: swapper/1
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.2.0-rc2-thuth #6
Call Trace:
[c00000007ffe7b90] [c000000000807670] dump_stack+0xa0/0xdc (unreliable)
[c00000007ffe7bc0] [c0000000000e1f14] ___might_sleep+0x134/0x180
[c00000007ffe7c20] [c00000000002aec0] rtas_busy_delay+0x30/0xd0
[c00000007ffe7c50] [c00000000002bde4] rtas_get_sensor+0x74/0xe0
[c00000007ffe7ce0] [c000000000083264] ras_epow_interrupt+0x44/0x450
[c00000007ffe7d90] [c000000000120260] handle_irq_event_percpu+0xa0/0x300
[c00000007ffe7e70] [c000000000120524] handle_irq_event+0x64/0xc0
[c00000007ffe7eb0] [c000000000124dbc] handle_fasteoi_irq+0xec/0x260
[c00000007ffe7ef0] [c00000000011f4f0] generic_handle_irq+0x50/0x80
[c00000007ffe7f20] [c000000000010f3c] __do_irq+0x8c/0x200
[c00000007ffe7f90] [c0000000000236cc] call_do_irq+0x14/0x24
[c00000007e6f39e0] [c000000000011144] do_IRQ+0x94/0x110
[c00000007e6f3a30] [c000000000002594] hardware_interrupt_common+0x114/0x180

Fix this issue by introducing a new rtas_get_sensor_fast() function
that does not use rtas_busy_delay() - and thus can only be used for
sensors that do not cause a BUSY condition - known as "fast" sensors.

The EPOW sensor is defined to be "fast" in sPAPR - mpe.

Fixes: 587f83e8dd50 ("powerpc/pseries: Use rtas_get_sensor in RAS code")
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Thomas Huth and committed by
Michael Ellerman
1c2cb594 9ef03193

+20 -1
+1
arch/powerpc/include/asm/rtas.h
··· 343 343 extern void rtas_halt(void); 344 344 extern void rtas_os_term(char *str); 345 345 extern int rtas_get_sensor(int sensor, int index, int *state); 346 + extern int rtas_get_sensor_fast(int sensor, int index, int *state); 346 347 extern int rtas_get_power_level(int powerdomain, int *level); 347 348 extern int rtas_set_power_level(int powerdomain, int level, int *setlevel); 348 349 extern bool rtas_indicator_present(int token, int *maxindex);
+17
arch/powerpc/kernel/rtas.c
··· 585 585 } 586 586 EXPORT_SYMBOL(rtas_get_sensor); 587 587 588 + int rtas_get_sensor_fast(int sensor, int index, int *state) 589 + { 590 + int token = rtas_token("get-sensor-state"); 591 + int rc; 592 + 593 + if (token == RTAS_UNKNOWN_SERVICE) 594 + return -ENOENT; 595 + 596 + rc = rtas_call(token, 2, 2, state, sensor, index); 597 + WARN_ON(rc == RTAS_BUSY || (rc >= RTAS_EXTENDED_DELAY_MIN && 598 + rc <= RTAS_EXTENDED_DELAY_MAX)); 599 + 600 + if (rc < 0) 601 + return rtas_error_rc(rc); 602 + return rc; 603 + } 604 + 588 605 bool rtas_indicator_present(int token, int *maxindex) 589 606 { 590 607 int proplen, count, i;
+2 -1
arch/powerpc/platforms/pseries/ras.c
··· 189 189 int state; 190 190 int critical; 191 191 192 - status = rtas_get_sensor(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, &state); 192 + status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, 193 + &state); 193 194 194 195 if (state > 3) 195 196 critical = 1; /* Time Critical */