mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-09 06:14:34 +02:00
In 64-bit configurations calling any firmware entry points from a kernel
thread other than the initial one will result in a situation where the
stack has been placed in the XKPHYS 64-bit memory segment.
Consequently the stack pointer is no longer a 32-bit value and when the
32-bit firmware code called uses 32-bit ALU operations to manipulate the
stack pointer, the calculated result is incorrect (in fact in the 64-bit
MIPS ISA almost all 32-bit ALU operations will produce an unpredictable
result when executed on 64-bit data) and control goes astray.
This may happen when no final console driver has been enabled in the
configuration and consequently the initial console continues being used
late into bootstrap, or with an upcoming change that will switch the zs
driver to use a platform device, which in turn will make the console
handover happen only after other kernel threads have already been
started, and the kernel will hang at:
pid_max: default: 32768 minimum: 301
or somewhat later, but always before:
cblist_init_generic: Setting adjustable number of callback queues.
has been printed.
It seems that only the prom_printf() entry point is affected. Of all
the other entry points wired only rex_slot_address() and rex_gettcinfo()
are called from a kernel thread other than the initial one, specifically
kernel_init(), and they are leaf functions that do no business with the
stack, having worked with no issue ever since 64-bit support was added
for the platform back in 2002.
To address this issue then, arrange for the stack to be switched in the
o32 wrapper as required for prom_printf() only, by supplying call_o32()
with a pointer to a chunk of initdata space, which is placed in the
CKSEG0 32-bit compatibility segment, observing that prom_printf() is
only called from console output handler and therefore with the console
lock held, implying no need for this code to be reentrant.
Other firmware entry points may be called with interrupts enabled and no
lock held, and may therefore require that call_o32() be reentrant. They
trigger no issue at this point and "if it ain't broke, don't fix it," so
just leave them alone.
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.12+
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
142 lines
3.6 KiB
C
142 lines
3.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* init.c: PROM library initialisation code.
|
|
*
|
|
* Copyright (C) 1998 Harald Koerfgen
|
|
* Copyright (C) 2002, 2004, 2026 Maciej W. Rozycki
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/smp.h>
|
|
#include <linux/string.h>
|
|
#include <linux/types.h>
|
|
|
|
#include <asm/bootinfo.h>
|
|
#include <asm/cpu.h>
|
|
#include <asm/cpu-type.h>
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/dec/prom.h>
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
|
unsigned long o32_stk[O32_STK_SIZE] __initdata = { 0 };
|
|
#endif
|
|
|
|
int (*__rex_bootinit)(void);
|
|
int (*__rex_bootread)(void);
|
|
int (*__rex_getbitmap)(memmap *);
|
|
unsigned long *(*__rex_slot_address)(int);
|
|
void *(*__rex_gettcinfo)(void);
|
|
int (*__rex_getsysid)(void);
|
|
void (*__rex_clear_cache)(void);
|
|
|
|
int (*__prom_getchar)(void);
|
|
char *(*__prom_getenv)(char *);
|
|
int (*__prom_printf)(char *, ...);
|
|
|
|
int (*__pmax_open)(char*, int);
|
|
int (*__pmax_lseek)(int, long, int);
|
|
int (*__pmax_read)(int, void *, int);
|
|
int (*__pmax_close)(int);
|
|
|
|
|
|
/*
|
|
* Detect which PROM the DECSTATION has, and set the callback vectors
|
|
* appropriately.
|
|
*/
|
|
static void __init which_prom(s32 magic, s32 *prom_vec)
|
|
{
|
|
/*
|
|
* No sign of the REX PROM's magic number means we assume a non-REX
|
|
* machine (i.e. we're on a DS2100/3100, DS5100 or DS5000/2xx)
|
|
*/
|
|
if (prom_is_rex(magic)) {
|
|
/*
|
|
* Set up prom abstraction structure with REX entry points.
|
|
*/
|
|
__rex_bootinit =
|
|
(void *)(long)*(prom_vec + REX_PROM_BOOTINIT);
|
|
__rex_bootread =
|
|
(void *)(long)*(prom_vec + REX_PROM_BOOTREAD);
|
|
__rex_getbitmap =
|
|
(void *)(long)*(prom_vec + REX_PROM_GETBITMAP);
|
|
__prom_getchar =
|
|
(void *)(long)*(prom_vec + REX_PROM_GETCHAR);
|
|
__prom_getenv =
|
|
(void *)(long)*(prom_vec + REX_PROM_GETENV);
|
|
__rex_getsysid =
|
|
(void *)(long)*(prom_vec + REX_PROM_GETSYSID);
|
|
__rex_gettcinfo =
|
|
(void *)(long)*(prom_vec + REX_PROM_GETTCINFO);
|
|
__prom_printf =
|
|
(void *)(long)*(prom_vec + REX_PROM_PRINTF);
|
|
__rex_slot_address =
|
|
(void *)(long)*(prom_vec + REX_PROM_SLOTADDR);
|
|
__rex_clear_cache =
|
|
(void *)(long)*(prom_vec + REX_PROM_CLEARCACHE);
|
|
} else {
|
|
/*
|
|
* Set up prom abstraction structure with non-REX entry points.
|
|
*/
|
|
__prom_getchar = (void *)PMAX_PROM_GETCHAR;
|
|
__prom_getenv = (void *)PMAX_PROM_GETENV;
|
|
__prom_printf = (void *)PMAX_PROM_PRINTF;
|
|
__pmax_open = (void *)PMAX_PROM_OPEN;
|
|
__pmax_lseek = (void *)PMAX_PROM_LSEEK;
|
|
__pmax_read = (void *)PMAX_PROM_READ;
|
|
__pmax_close = (void *)PMAX_PROM_CLOSE;
|
|
}
|
|
}
|
|
|
|
void __init prom_init(void)
|
|
{
|
|
extern void dec_machine_halt(void);
|
|
static const char cpu_msg[] __initconst =
|
|
"Sorry, this kernel is compiled for a wrong CPU type!\n";
|
|
s32 argc = fw_arg0;
|
|
s32 *argv = (void *)fw_arg1;
|
|
u32 magic = fw_arg2;
|
|
s32 *prom_vec = (void *)fw_arg3;
|
|
|
|
/*
|
|
* Determine which PROM we have
|
|
* (and therefore which machine we're on!)
|
|
*/
|
|
which_prom(magic, prom_vec);
|
|
|
|
if (prom_is_rex(magic))
|
|
rex_clear_cache();
|
|
|
|
/* Register the early console. */
|
|
register_prom_console();
|
|
|
|
/* Were we compiled with the right CPU option? */
|
|
#if defined(CONFIG_CPU_R3000)
|
|
if ((current_cpu_type() == CPU_R4000SC) ||
|
|
(current_cpu_type() == CPU_R4400SC)) {
|
|
static const char r4k_msg[] __initconst =
|
|
"Please recompile with \"CONFIG_CPU_R4X00 = y\".\n";
|
|
printk(cpu_msg);
|
|
printk(r4k_msg);
|
|
dec_machine_halt();
|
|
}
|
|
#endif
|
|
|
|
#if defined(CONFIG_CPU_R4X00)
|
|
if ((current_cpu_type() == CPU_R3000) ||
|
|
(current_cpu_type() == CPU_R3000A)) {
|
|
static const char r3k_msg[] __initconst =
|
|
"Please recompile with \"CONFIG_CPU_R3000 = y\".\n";
|
|
printk(cpu_msg);
|
|
printk(r3k_msg);
|
|
dec_machine_halt();
|
|
}
|
|
#endif
|
|
|
|
prom_meminit(magic);
|
|
prom_identify_arch(magic);
|
|
prom_init_cmdline(argc, argv, magic);
|
|
}
|