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

Configure Feed

Select the types of activity you want to include in your feed.

powerpc/rtas: Fall back to linear search on failed token->function lookup

Enabling any of the powerpc:rtas_* tracepoints at boot is likely to
result in an oops on RTAS platforms. For example, booting a QEMU
pseries model with 'trace_event=powerpc:rtas_input' in the command
line leads to:

BUG: Kernel NULL pointer dereference on read at 0x00000008
Oops: Kernel access of bad area, sig: 7 [#1]
NIP [c00000000004231c] do_enter_rtas+0x1bc/0x460
LR [c00000000004231c] do_enter_rtas+0x1bc/0x460
Call Trace:
do_enter_rtas+0x1bc/0x460 (unreliable)
rtas_call+0x22c/0x4a0
rtas_get_boot_time+0x80/0x14c
read_persistent_clock64+0x124/0x150
read_persistent_wall_and_boot_offset+0x28/0x58
timekeeping_init+0x70/0x348
start_kernel+0xa0c/0xc1c
start_here_common+0x1c/0x20

(This is preceded by a warning for the failed lookup in
rtas_token_to_function().)

This happens when __do_enter_rtas_trace() attempts a token to function
descriptor lookup before the xarray containing the mappings has been
set up.

Fall back to linear scan of the table if rtas_token_to_function_xarray
is empty.

Fixes: 24098f580e2b ("powerpc/rtas: add tracepoints around RTAS entry")
Reviewed-by: "Aneesh Kumar K.V (IBM)" <aneesh.kumar@kernel.org>
Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231212-papr-sys_rtas-vs-lockdown-v6-3-e9eafd0c8c6c@linux.ibm.com

authored by

Nathan Lynch and committed by
Michael Ellerman
669acc7e c500c6e7

+14 -4
+14 -4
arch/powerpc/kernel/rtas.c
··· 572 572 return NULL; 573 573 574 574 func = rtas_token_to_function_untrusted(token); 575 + if (func) 576 + return func; 577 + /* 578 + * Fall back to linear scan in case the reverse mapping hasn't 579 + * been initialized yet. 580 + */ 581 + if (xa_empty(&rtas_token_to_function_xarray)) { 582 + for_each_rtas_function(func) { 583 + if (func->token == token) 584 + return func; 585 + } 586 + } 575 587 576 - if (WARN_ONCE(!func, "unexpected failed lookup for token %d", token)) 577 - return NULL; 578 - 579 - return func; 588 + WARN_ONCE(true, "unexpected failed lookup for token %d", token); 589 + return NULL; 580 590 } 581 591 582 592 /* This is here deliberately so it's only used in this file */