mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-23 04:17:58 +07:00
4bcb4ad663
Since at least the beginning of the git era we've declared our TLB
exception handling functions inconsistently. They're actually functions,
but we declare them as arrays of u32 where each u32 is an encoded
instruction. This has always been the case for arch/mips/mm/tlbex.c, and
has also been true for arch/mips/kernel/traps.c since commit
86a1708a9d
("MIPS: Make tlb exception handler definitions and
declarations match.") which aimed for consistency but did so by
consistently making the our C code inconsistent with our assembly.
This is all usually harmless, but when using GCC 7 or newer to build a
kernel targeting microMIPS (ie. CONFIG_CPU_MICROMIPS=y) it becomes
problematic. With microMIPS bit 0 of the program counter indicates the
ISA mode. When bit 0 is zero instructions are decoded using the standard
MIPS32 or MIPS64 ISA. When bit 0 is one instructions are decoded using
microMIPS. This means that function pointers become odd - their least
significant bit is one for microMIPS code. We work around this in cases
where we need to access code using loads & stores with our
msk_isa16_mode() macro which simply clears bit 0 of the value it is
given:
#define msk_isa16_mode(x) ((x) & ~0x1)
For example we do this for our TLB load handler in
build_r4000_tlb_load_handler():
u32 *p = (u32 *)msk_isa16_mode((ulong)handle_tlbl);
We then write code to p, expecting it to be suitably aligned (our LEAF
macro aligns functions on 4 byte boundaries, so (ulong)handle_tlbl will
give a value one greater than a multiple of 4 - ie. the start of a
function on a 4 byte boundary, with the ISA mode bit 0 set).
This worked fine up to GCC 6, but GCC 7 & onwards is smart enough to
presume that handle_tlbl which we declared as an array of u32s must be
aligned sufficiently that bit 0 of its address will never be set, and as
a result optimize out msk_isa16_mode(). This leads to p having an
address with bit 0 set, and when we go on to attempt to store code at
that address we take an address error exception due to the unaligned
memory access.
This leads to an exception prior to the kernel having configured its own
exception handlers, so we jump to whatever handlers the bootloader
configured. In the case of QEMU this results in a silent hang, since it
has no useful general exception vector.
Fix this by consistently declaring our TLB-related functions as
functions. For handle_tlbl(), handle_tlbs() & handle_tlbm() we do this
in asm/tlbex.h & we make use of the existing declaration of
tlbmiss_handler_setup_pgd() in asm/mmu_context.h. Our TLB handler
generation code in arch/mips/mm/tlbex.c is adjusted to deal with these
definitions, in most cases simply by casting the function pointers to
u32 pointers.
This allows us to include asm/mmu_context.h in arch/mips/mm/tlbex.c to
get the definitions of tlbmiss_handler_setup_pgd & pgd_current, removing
some needless duplication. Consistently using msk_isa16_mode() on
function pointers means we no longer need the
tlbmiss_handler_setup_pgd_start symbol so that is removed entirely.
Now that we're declaring our functions as functions GCC stops optimizing
out msk_isa16_mode() & a microMIPS kernel built with either GCC 7.3.0 or
8.1.0 boots successfully.
Signed-off-by: Paul Burton <paul.burton@mips.com>
37 lines
977 B
C
37 lines
977 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_TLBEX_H
|
|
#define __ASM_TLBEX_H
|
|
|
|
#include <asm/uasm.h>
|
|
|
|
/*
|
|
* Write random or indexed TLB entry, and care about the hazards from
|
|
* the preceding mtc0 and for the following eret.
|
|
*/
|
|
enum tlb_write_entry {
|
|
tlb_random,
|
|
tlb_indexed
|
|
};
|
|
|
|
extern int pgd_reg;
|
|
|
|
void build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
|
|
unsigned int tmp, unsigned int ptr);
|
|
void build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr);
|
|
void build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr);
|
|
void build_update_entries(u32 **p, unsigned int tmp, unsigned int ptep);
|
|
void build_tlb_write_entry(u32 **p, struct uasm_label **l,
|
|
struct uasm_reloc **r,
|
|
enum tlb_write_entry wmode);
|
|
|
|
extern void handle_tlbl(void);
|
|
extern char handle_tlbl_end[];
|
|
|
|
extern void handle_tlbs(void);
|
|
extern char handle_tlbs_end[];
|
|
|
|
extern void handle_tlbm(void);
|
|
extern char handle_tlbm_end[];
|
|
|
|
#endif /* __ASM_TLBEX_H */
|