Commit 92fab77b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'mips_5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux

Pull MIPS updates from Paul Burton:

 - A set of memblock initialization improvements thanks to Serge Semin,
   tidying up after our conversion from bootmem to memblock back in
   v4.20.

 - Our eBPF JIT the previously supported only MIPS64r2 through MIPS64r5
   is improved to also support MIPS64r6. Support for MIPS32 systems is
   introduced, with the caveat that it only works for programs that
   don't use 64 bit registers or operations - those will bail out & need
   to be interpreted.

 - Improvements to the allocation & configuration of our exception
   vector that should fix issues seen on some platforms using recent
   versions of U-Boot.

 - Some minor improvements to code generated for jump labels, along with
   enabling them by default for generic kernels.

* tag 'mips_5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux: (27 commits)
  mips: Manually call fdt_init_reserved_mem() method
  mips: Make sure dt memory regions are valid
  mips: Perform early low memory test
  mips: Dump memblock regions for debugging
  mips: Add reserve-nomap memory type support
  mips: Use memblock to reserve the __nosave memory range
  mips: Discard post-CMA-init foreach loop
  mips: Reserve memory for the kernel image resources
  MIPS: Remove duplicate EBase configuration
  MIPS: Sync icache for whole exception vector
  MIPS: Always allocate exception vector for MIPSr2+
  MIPS: Use memblock_phys_alloc() for exception vector
  mips: Combine memblock init and memory reservation loops
  mips: Discard rudiments from bootmem_init
  mips: Make sure kernel .bss exists in boot mem pool
  mips: vdso: drop unnecessary cc-ldoption
  Revert "MIPS: ralink: fix cpu clock of mt7621 and add dt clk devices"
  MIPS: generic: Enable CONFIG_JUMP_LABEL
  MIPS: jump_label: Use compact branches for >= r6
  MIPS: jump_label: Remove redundant nops
  ...
parents ef75bd71 3751cbda
...@@ -44,8 +44,7 @@ config MIPS ...@@ -44,8 +44,7 @@ config MIPS
select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES && 64BIT select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES && 64BIT
select HAVE_CBPF_JIT if (!64BIT && !CPU_MICROMIPS) select HAVE_EBPF_JIT if (!CPU_MICROMIPS)
select HAVE_EBPF_JIT if (64BIT && !CPU_MICROMIPS)
select HAVE_CONTEXT_TRACKING select HAVE_CONTEXT_TRACKING
select HAVE_COPY_THREAD_TLS select HAVE_COPY_THREAD_TLS
select HAVE_C_RECORDMCOUNT select HAVE_C_RECORDMCOUNT
...@@ -2474,7 +2473,6 @@ config SB1_PASS_2_1_WORKAROUNDS ...@@ -2474,7 +2473,6 @@ config SB1_PASS_2_1_WORKAROUNDS
depends on CPU_SB1 && CPU_SB1_PASS_2 depends on CPU_SB1 && CPU_SB1_PASS_2
default y default y
choice choice
prompt "SmartMIPS or microMIPS ASE support" prompt "SmartMIPS or microMIPS ASE support"
......
...@@ -26,6 +26,7 @@ CONFIG_MIPS_CPS=y ...@@ -26,6 +26,7 @@ CONFIG_MIPS_CPS=y
CONFIG_HIGHMEM=y CONFIG_HIGHMEM=y
CONFIG_NR_CPUS=16 CONFIG_NR_CPUS=16
CONFIG_MIPS_O32_FP64_SUPPORT=y CONFIG_MIPS_O32_FP64_SUPPORT=y
CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y CONFIG_MODULE_UNLOAD=y
CONFIG_TRIM_UNUSED_KSYMS=y CONFIG_TRIM_UNUSED_KSYMS=y
......
...@@ -92,6 +92,7 @@ extern unsigned long mips_machtype; ...@@ -92,6 +92,7 @@ extern unsigned long mips_machtype;
#define BOOT_MEM_ROM_DATA 2 #define BOOT_MEM_ROM_DATA 2
#define BOOT_MEM_RESERVED 3 #define BOOT_MEM_RESERVED 3
#define BOOT_MEM_INIT_RAM 4 #define BOOT_MEM_INIT_RAM 4
#define BOOT_MEM_NOMAP 5
/* /*
* A memory map that's built upon what was determined * A memory map that's built upon what was determined
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <linux/types.h> #include <linux/types.h>
#include <asm/isa-rev.h>
#define JUMP_LABEL_NOP_SIZE 4 #define JUMP_LABEL_NOP_SIZE 4
...@@ -21,15 +22,20 @@ ...@@ -21,15 +22,20 @@
#endif #endif
#ifdef CONFIG_CPU_MICROMIPS #ifdef CONFIG_CPU_MICROMIPS
#define B_INSN "b32" # define B_INSN "b32"
# define J_INSN "j32"
#elif MIPS_ISA_REV >= 6
# define B_INSN "bc"
# define J_INSN "bc"
#else #else
#define B_INSN "b" # define B_INSN "b"
# define J_INSN "j"
#endif #endif
static __always_inline bool arch_static_branch(struct static_key *key, bool branch) static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
{ {
asm_volatile_goto("1:\t" B_INSN " 2f\n\t" asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
"2:\tnop\n\t" "2:\t.insn\n\t"
".pushsection __jump_table, \"aw\"\n\t" ".pushsection __jump_table, \"aw\"\n\t"
WORD_INSN " 1b, %l[l_yes], %0\n\t" WORD_INSN " 1b, %l[l_yes], %0\n\t"
".popsection\n\t" ".popsection\n\t"
...@@ -42,8 +48,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran ...@@ -42,8 +48,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
{ {
asm_volatile_goto("1:\tj %l[l_yes]\n\t" asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
"nop\n\t"
".pushsection __jump_table, \"aw\"\n\t" ".pushsection __jump_table, \"aw\"\n\t"
WORD_INSN " 1b, %l[l_yes], %0\n\t" WORD_INSN " 1b, %l[l_yes], %0\n\t"
".popsection\n\t" ".popsection\n\t"
......
...@@ -86,14 +86,18 @@ Ip_u2u1(_ctcmsa); ...@@ -86,14 +86,18 @@ Ip_u2u1(_ctcmsa);
Ip_u2u1s3(_daddiu); Ip_u2u1s3(_daddiu);
Ip_u3u1u2(_daddu); Ip_u3u1u2(_daddu);
Ip_u1u2(_ddivu); Ip_u1u2(_ddivu);
Ip_u3u1u2(_ddivu_r6);
Ip_u1(_di); Ip_u1(_di);
Ip_u2u1msbu3(_dins); Ip_u2u1msbu3(_dins);
Ip_u2u1msbu3(_dinsm); Ip_u2u1msbu3(_dinsm);
Ip_u2u1msbu3(_dinsu); Ip_u2u1msbu3(_dinsu);
Ip_u1u2(_divu); Ip_u1u2(_divu);
Ip_u3u1u2(_divu_r6);
Ip_u1u2u3(_dmfc0); Ip_u1u2u3(_dmfc0);
Ip_u3u1u2(_dmodu);
Ip_u1u2u3(_dmtc0); Ip_u1u2u3(_dmtc0);
Ip_u1u2(_dmultu); Ip_u1u2(_dmultu);
Ip_u3u1u2(_dmulu);
Ip_u2u1u3(_drotr); Ip_u2u1u3(_drotr);
Ip_u2u1u3(_drotr32); Ip_u2u1u3(_drotr32);
Ip_u2u1(_dsbh); Ip_u2u1(_dsbh);
...@@ -131,6 +135,7 @@ Ip_u1u2u3(_mfc0); ...@@ -131,6 +135,7 @@ Ip_u1u2u3(_mfc0);
Ip_u1u2u3(_mfhc0); Ip_u1u2u3(_mfhc0);
Ip_u1(_mfhi); Ip_u1(_mfhi);
Ip_u1(_mflo); Ip_u1(_mflo);
Ip_u3u1u2(_modu);
Ip_u3u1u2(_movn); Ip_u3u1u2(_movn);
Ip_u3u1u2(_movz); Ip_u3u1u2(_movz);
Ip_u1u2u3(_mtc0); Ip_u1u2u3(_mtc0);
...@@ -139,6 +144,7 @@ Ip_u1(_mthi); ...@@ -139,6 +144,7 @@ Ip_u1(_mthi);
Ip_u1(_mtlo); Ip_u1(_mtlo);
Ip_u3u1u2(_mul); Ip_u3u1u2(_mul);
Ip_u1u2(_multu); Ip_u1u2(_multu);
Ip_u3u1u2(_mulu);
Ip_u3u1u2(_nor); Ip_u3u1u2(_nor);
Ip_u3u1u2(_or); Ip_u3u1u2(_or);
Ip_u2u1u3(_ori); Ip_u2u1u3(_ori);
...@@ -149,6 +155,8 @@ Ip_u2s3u1(_sb); ...@@ -149,6 +155,8 @@ Ip_u2s3u1(_sb);
Ip_u2s3u1(_sc); Ip_u2s3u1(_sc);
Ip_u2s3u1(_scd); Ip_u2s3u1(_scd);
Ip_u2s3u1(_sd); Ip_u2s3u1(_sd);
Ip_u3u1u2(_seleqz);
Ip_u3u1u2(_selnez);
Ip_u2s3u1(_sh); Ip_u2s3u1(_sh);
Ip_u2u1u3(_sll); Ip_u2u1u3(_sll);
Ip_u3u2u1(_sllv); Ip_u3u2u1(_sllv);
......
...@@ -55,9 +55,9 @@ enum spec_op { ...@@ -55,9 +55,9 @@ enum spec_op {
spec3_unused_op, spec4_unused_op, slt_op, sltu_op, spec3_unused_op, spec4_unused_op, slt_op, sltu_op,
dadd_op, daddu_op, dsub_op, dsubu_op, dadd_op, daddu_op, dsub_op, dsubu_op,
tge_op, tgeu_op, tlt_op, tltu_op, tge_op, tgeu_op, tlt_op, tltu_op,
teq_op, spec5_unused_op, tne_op, spec6_unused_op, teq_op, seleqz_op, tne_op, selnez_op,
dsll_op, spec7_unused_op, dsrl_op, dsra_op, dsll_op, spec5_unused_op, dsrl_op, dsra_op,
dsll32_op, spec8_unused_op, dsrl32_op, dsra32_op dsll32_op, spec6_unused_op, dsrl32_op, dsra32_op
}; };
/* /*
......
...@@ -58,15 +58,14 @@ resume_kernel: ...@@ -58,15 +58,14 @@ resume_kernel:
local_irq_disable local_irq_disable
lw t0, TI_PRE_COUNT($28) lw t0, TI_PRE_COUNT($28)
bnez t0, restore_all bnez t0, restore_all
need_resched:
LONG_L t0, TI_FLAGS($28) LONG_L t0, TI_FLAGS($28)
andi t1, t0, _TIF_NEED_RESCHED andi t1, t0, _TIF_NEED_RESCHED
beqz t1, restore_all beqz t1, restore_all
LONG_L t0, PT_STATUS(sp) # Interrupts off? LONG_L t0, PT_STATUS(sp) # Interrupts off?
andi t0, 1 andi t0, 1
beqz t0, restore_all beqz t0, restore_all
jal preempt_schedule_irq PTR_LA ra, restore_all
b need_resched j preempt_schedule_irq
#endif #endif
FEXPORT(ret_from_kernel_thread) FEXPORT(ret_from_kernel_thread)
......
...@@ -40,18 +40,38 @@ void arch_jump_label_transform(struct jump_entry *e, ...@@ -40,18 +40,38 @@ void arch_jump_label_transform(struct jump_entry *e,
{ {
union mips_instruction *insn_p; union mips_instruction *insn_p;
union mips_instruction insn; union mips_instruction insn;
long offset;
insn_p = (union mips_instruction *)msk_isa16_mode(e->code); insn_p = (union mips_instruction *)msk_isa16_mode(e->code);
/* Jump only works within an aligned region its delay slot is in. */
BUG_ON((e->target & ~J_RANGE_MASK) != ((e->code + 4) & ~J_RANGE_MASK));
/* Target must have the right alignment and ISA must be preserved. */ /* Target must have the right alignment and ISA must be preserved. */
BUG_ON((e->target & J_ALIGN_MASK) != J_ISA_BIT); BUG_ON((e->target & J_ALIGN_MASK) != J_ISA_BIT);
if (type == JUMP_LABEL_JMP) { if (type == JUMP_LABEL_JMP) {
if (!IS_ENABLED(CONFIG_CPU_MICROMIPS) && MIPS_ISA_REV >= 6) {
offset = e->target - ((unsigned long)insn_p + 4);
offset >>= 2;
/*
* The branch offset must fit in the instruction's 26
* bit field.
*/
WARN_ON((offset >= BIT(25)) ||
(offset < -(long)BIT(25)));
insn.j_format.opcode = bc6_op;
insn.j_format.target = offset;
} else {
/*
* Jump only works within an aligned region its delay
* slot is in.
*/
WARN_ON((e->target & ~J_RANGE_MASK) !=
((e->code + 4) & ~J_RANGE_MASK));
insn.j_format.opcode = J_ISA_BIT ? mm_j32_op : j_op; insn.j_format.opcode = J_ISA_BIT ? mm_j32_op : j_op;
insn.j_format.target = e->target >> J_RANGE_SHIFT; insn.j_format.target = e->target >> J_RANGE_SHIFT;
}
} else { } else {
insn.word = 0; /* nop */ insn.word = 0; /* nop */
} }
......
...@@ -41,13 +41,27 @@ char *mips_get_machine_name(void) ...@@ -41,13 +41,27 @@ char *mips_get_machine_name(void)
#ifdef CONFIG_USE_OF #ifdef CONFIG_USE_OF
void __init early_init_dt_add_memory_arch(u64 base, u64 size) void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{ {
return add_memory_region(base, size, BOOT_MEM_RAM); if (base >= PHYS_ADDR_MAX) {
pr_warn("Trying to add an invalid memory region, skipped\n");
return;
}
/* Truncate the passed memory region instead of type casting */
if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
size, base, PHYS_ADDR_MAX - base);
size = PHYS_ADDR_MAX - base;
}
add_memory_region(base, size, BOOT_MEM_RAM);
} }
int __init early_init_dt_reserve_memory_arch(phys_addr_t base, int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
phys_addr_t size, bool nomap) phys_addr_t size, bool nomap)
{ {
add_memory_region(base, size, BOOT_MEM_RESERVED); add_memory_region(base, size,
nomap ? BOOT_MEM_NOMAP : BOOT_MEM_RESERVED);
return 0; return 0;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/dma-contiguous.h> #include <linux/dma-contiguous.h>
#include <linux/decompress/generic.h> #include <linux/decompress/generic.h>
#include <linux/of_fdt.h> #include <linux/of_fdt.h>
#include <linux/of_reserved_mem.h>
#include <asm/addrspace.h> #include <asm/addrspace.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
...@@ -178,6 +179,7 @@ static bool __init __maybe_unused memory_region_available(phys_addr_t start, ...@@ -178,6 +179,7 @@ static bool __init __maybe_unused memory_region_available(phys_addr_t start,
in_ram = true; in_ram = true;
break; break;
case BOOT_MEM_RESERVED: case BOOT_MEM_RESERVED:
case BOOT_MEM_NOMAP:
if ((start >= start_ && start < end_) || if ((start >= start_ && start < end_) ||
(start < start_ && start + size >= start_)) (start < start_ && start + size >= start_))
free = false; free = false;
...@@ -213,6 +215,9 @@ static void __init print_memory_map(void) ...@@ -213,6 +215,9 @@ static void __init print_memory_map(void)
case BOOT_MEM_RESERVED: case BOOT_MEM_RESERVED:
printk(KERN_CONT "(reserved)\n"); printk(KERN_CONT "(reserved)\n");
break; break;
case BOOT_MEM_NOMAP:
printk(KERN_CONT "(nomap)\n");
break;
default: default:
printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type); printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
break; break;
...@@ -371,7 +376,6 @@ static void __init bootmem_init(void) ...@@ -371,7 +376,6 @@ static void __init bootmem_init(void)
static void __init bootmem_init(void) static void __init bootmem_init(void)
{ {
unsigned long reserved_end;
phys_addr_t ramstart = PHYS_ADDR_MAX; phys_addr_t ramstart = PHYS_ADDR_MAX;
int i; int i;
...@@ -382,10 +386,10 @@ static void __init bootmem_init(void) ...@@ -382,10 +386,10 @@ static void __init bootmem_init(void)
* will reserve the area used for the initrd. * will reserve the area used for the initrd.
*/ */
init_initrd(); init_initrd();
reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
memblock_reserve(PHYS_OFFSET, /* Reserve memory occupied by kernel. */
(reserved_end << PAGE_SHIFT) - PHYS_OFFSET); memblock_reserve(__pa_symbol(&_text),
__pa_symbol(&_end) - __pa_symbol(&_text));
/* /*
* max_low_pfn is not a number of pages. The number of pages * max_low_pfn is not a number of pages. The number of pages
...@@ -394,10 +398,7 @@ static void __init bootmem_init(void) ...@@ -394,10 +398,7 @@ static void __init bootmem_init(void)
min_low_pfn = ~0UL; min_low_pfn = ~0UL;
max_low_pfn = 0; max_low_pfn = 0;
/* /* Find the highest and lowest page frame numbers we have available. */
* Find the highest page frame number we have available
* and the lowest used RAM address
*/
for (i = 0; i < boot_mem_map.nr_map; i++) { for (i = 0; i < boot_mem_map.nr_map; i++) {
unsigned long start, end; unsigned long start, end;
...@@ -427,13 +428,6 @@ static void __init bootmem_init(void) ...@@ -427,13 +428,6 @@ static void __init bootmem_init(void)
max_low_pfn = end; max_low_pfn = end;
if (start < min_low_pfn) if (start < min_low_pfn)
min_low_pfn = start; min_low_pfn = start;
if (end <= reserved_end)
continue;
#ifdef CONFIG_BLK_DEV_INITRD
/* Skip zones before initrd and initrd itself */
if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
continue;
#endif
} }
if (min_low_pfn >= max_low_pfn) if (min_low_pfn >= max_low_pfn)
...@@ -474,6 +468,7 @@ static void __init bootmem_init(void) ...@@ -474,6 +468,7 @@ static void __init bootmem_init(void)
max_low_pfn = PFN_DOWN(HIGHMEM_START); max_low_pfn = PFN_DOWN(HIGHMEM_START);
} }
/* Install all valid RAM ranges to the memblock memory region */
for (i = 0; i < boot_mem_map.nr_map; i++) { for (i = 0; i < boot_mem_map.nr_map; i++) {
unsigned long start, end; unsigned long start, end;
...@@ -481,98 +476,38 @@ static void __init bootmem_init(void) ...@@ -481,98 +476,38 @@ static void __init bootmem_init(void)
end = PFN_DOWN(boot_mem_map.map[i].addr end = PFN_DOWN(boot_mem_map.map[i].addr
+ boot_mem_map.map[i].size); + boot_mem_map.map[i].size);
if (start <= min_low_pfn) if (start < min_low_pfn)
start = min_low_pfn; start = min_low_pfn;
if (start >= end)
continue;
#ifndef CONFIG_HIGHMEM #ifndef CONFIG_HIGHMEM
/* Ignore highmem regions if highmem is unsupported */
if (end > max_low_pfn) if (end > max_low_pfn)
end = max_low_pfn; end = max_low_pfn;
#endif
/*
* ... finally, is the area going away?
*/
if (end <= start) if (end <= start)
continue; continue;
#endif
memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0); memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
}
/*
* Register fully available low RAM pages with the bootmem allocator.
*/
for (i = 0; i < boot_mem_map.nr_map; i++) {
unsigned long start, end, size;
start = PFN_UP(boot_mem_map.map[i].addr);
end = PFN_DOWN(boot_mem_map.map[i].addr
+ boot_mem_map.map[i].size);
/* /* Reserve any memory except the ordinary RAM ranges. */
* Reserve usable memory.
*/
switch (boot_mem_map.map[i].type) { switch (boot_mem_map.map[i].type) {
case BOOT_MEM_RAM: case BOOT_MEM_RAM:
break; break;
case BOOT_MEM_INIT_RAM: case BOOT_MEM_NOMAP: /* Discard the range from the system. */
memory_present(0, start, end); memblock_remove(PFN_PHYS(start), PFN_PHYS(end - start));
continue;
default:
/* Not usable memory */
if (start > min_low_pfn && end < max_low_pfn)
memblock_reserve(boot_mem_map.map[i].addr,
boot_mem_map.map[i].size);
continue; continue;
default: /* Reserve the rest of the memory types at boot time */
memblock_reserve(PFN_PHYS(start), PFN_PHYS(end - start));
break;
} }
/* /*
* We are rounding up the start address of usable memory * In any case the added to the memblock memory regions
* and at the end of the usable range downwards. * (highmem/lowmem, available/reserved, etc) are considered
*/ * as present, so inform sparsemem about them.
if (start >= max_low_pfn)
continue;
if (start < reserved_end)
start = reserved_end;
if (end > max_low_pfn)
end = max_low_pfn;
/*
* ... finally, is the area going away?
*/ */
if (end <= start)
continue;
size = end - start;
/* Register lowmem ranges */
memory_present(0, start, end); memory_present(0, start, end);
} }
#ifdef CONFIG_RELOCATABLE
/*
* The kernel reserves all memory below its _end symbol as bootmem,
* but the kernel may now be at a much higher address. The memory
* between the original and new locations may be returned to the system.
*/
if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
unsigned long offset;
extern void show_kernel_relocation(const char *level);
offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
memblock_free(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
#if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
/*
* This information is necessary when debugging the kernel
* But is a security vulnerability otherwise!
*/
show_kernel_relocation(KERN_INFO);
#endif
}
#endif
/* /*
* Reserve initrd memory if needed. * Reserve initrd memory if needed.
*/ */
...@@ -781,7 +716,6 @@ static void __init request_crashkernel(struct resource *res) ...@@ -781,7 +716,6 @@ static void __init request_crashkernel(struct resource *res)
*/ */
static void __init arch_mem_init(char **cmdline_p) static void __init arch_mem_init(char **cmdline_p)
{ {
struct memblock_region *reg;
extern void plat_mem_setup(void); extern void plat_mem_setup(void);
/* /*
...@@ -809,6 +743,9 @@ static void __init arch_mem_init(char **cmdline_p) ...@@ -809,6 +743,9 @@ static void __init arch_mem_init(char **cmdline_p)
arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT, arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT, PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
BOOT_MEM_INIT_RAM); BOOT_MEM_INIT_RAM);
arch_mem_addpart(PFN_DOWN(__pa_symbol(&__bss_start)) << PAGE_SHIFT,
PFN_UP(__pa_symbol(&__bss_stop)) << PAGE_SHIFT,
BOOT_MEM_RAM);
pr_info("Determined physical RAM map:\n"); pr_info("Determined physical RAM map:\n");
print_memory_map(); print_memory_map();
...@@ -884,13 +821,16 @@ static void __init arch_mem_init(char **cmdline_p) ...@@ -884,13 +821,16 @@ static void __init arch_mem_init(char **cmdline_p)
plat_swiotlb_setup(); plat_swiotlb_setup();
dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
/* Tell bootmem about cma reserved memblock section */
for_each_memblock(reserved, reg)
if (reg->size != 0)
memblock_reserve(reg->base, reg->size);
reserve_bootmem_region(__pa_symbol(&__nosave_begin), /* Reserve for hibernation. */
__pa_symbol(&__nosave_end)); /* Reserve for hibernation */ memblock_reserve(__pa_symbol(&__nosave_begin),
__pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin));
fdt_init_reserved_mem();
memblock_dump_all();
early_memtest(PFN_PHYS(min_low_pfn), PFN_PHYS(max_low_pfn));
} }
static void __init resource_init(void) static void __init resource_init(void)
...@@ -935,6 +875,7 @@ static void __init resource_init(void) ...@@ -935,6 +875,7 @@ static void __init resource_init(void)
res->flags |= IORESOURCE_SYSRAM; res->flags |= IORESOURCE_SYSRAM;
break; break;
case BOOT_MEM_RESERVED: case BOOT_MEM_RESERVED:
case BOOT_MEM_NOMAP:
default: default:
res->name = "reserved"; res->name = "reserved";
} }
......
...@@ -2151,7 +2151,7 @@ static void configure_hwrena(void) ...@@ -2151,7 +2151,7 @@ static void configure_hwrena(void)
static void configure_exception_vector(void) static void configure_exception_vector(void)
{ {
if (cpu_has_veic || cpu_has_vint) { if (cpu_has_mips_r2_r6) {
unsigned long sr = set_c0_status(ST0_BEV); unsigned long sr = set_c0_status(ST0_BEV);
/* If available, use WG to set top bits of EBASE */ /* If available, use WG to set top bits of EBASE */
if (cpu_has_ebase_wg) { if (cpu_has_ebase_wg) {
...@@ -2163,6 +2163,8 @@ static void configure_exception_vector(void) ...@@ -2163,6 +2163,8 @@ static void configure_exception_vector(void)
} }
write_c0_ebase(ebase); write_c0_ebase(ebase);
write_c0_status(sr); write_c0_status(sr);
}
if (cpu_has_veic || cpu_has_vint) {
/* Setting vector spacing enables EI/VI mode */ /* Setting vector spacing enables EI/VI mode */
change_c0_intctl(0x3e0, VECTORSPACING); change_c0_intctl(0x3e0, VECTORSPACING);
} }
...@@ -2193,22 +2195,6 @@ void per_cpu_trap_init(bool is_boot_cpu) ...@@ -2193,22 +2195,6 @@ void per_cpu_trap_init(bool is_boot_cpu)
* o read IntCtl.IPFDC to determine the fast debug channel interrupt * o read IntCtl.IPFDC to determine the fast debug channel interrupt
*/ */
if (cpu_has_mips_r2_r6) { if (cpu_has_mips_r2_r6) {
/*
* We shouldn't trust a secondary core has a sane EBASE register
* so use the one calculated by the boot CPU.
*/
if (!is_boot_cpu) {
/* If available, use WG to set top bits of EBASE */
if (cpu_has_ebase_wg) {
#ifdef CONFIG_64BIT
write_c0_ebase_64(ebase | MIPS_EBASE_WG);
#else
write_c0_ebase(ebase | MIPS_EBASE_WG);
#endif
}
write_c0_ebase(ebase);
}
cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP; cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7; cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7; cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
...@@ -2284,19 +2270,27 @@ void __init trap_init(void) ...@@ -2284,19 +2270,27 @@ void __init trap_init(void)
extern char except_vec3_generic; extern char except_vec3_generic;
extern char except_vec4; extern char except_vec4;
extern char except_vec3_r4000; extern char except_vec3_r4000;
unsigned long i; unsigned long i, vec_size;
phys_addr_t ebase_pa;
check_wait(); check_wait();
if (cpu_has_veic || cpu_has_vint) { if (!cpu_has_mips_r2_r6) {
unsigned long size = 0x200 + VECTORSPACING*64; ebase = CAC_BASE;
phys_addr_t ebase_pa; ebase_pa = virt_to_phys((void *)ebase);
vec_size = 0x400;
ebase = (unsigned long) memblock_reserve(ebase_pa, vec_size);
memblock_alloc(size, 1 << fls(size)); } else {
if (!ebase) if (cpu_has_veic || cpu_has_vint)
vec_size = 0x200 + VECTORSPACING*64;
else
vec_size = PAGE_SIZE;
ebase_pa = memblock_phys_alloc(vec_size, 1 << fls(vec_size));
if (!ebase_pa)
panic("%s: Failed to allocate %lu bytes align=0x%x\n", panic("%s: Failed to allocate %lu bytes align=0x%x\n",
__func__, size, 1 << fls(size)); __func__, vec_size, 1 << fls(vec_size));
/* /*
* Try to ensure ebase resides in KSeg0 if possible. * Try to ensure ebase resides in KSeg0 if possible.
...@@ -2309,23 +2303,10 @@ void __init trap_init(void) ...@@ -2309,23 +2303,10 @@ void __init trap_init(void)
* EVA is special though as it allows segments to be rearranged * EVA is special though as it allows segments to be rearranged
* and to become uncached during cache error handling. * and to become uncached during cache error handling.
*/ */
ebase_pa = __pa(ebase);
if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000)) if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000))
ebase = CKSEG0ADDR(ebase_pa); ebase = CKSEG0ADDR(ebase_pa);
} else { else
ebase = CAC_BASE; ebase = (unsigned long)phys_to_virt(ebase_pa);
if (cpu_has_mips_r2_r6) {
if (cpu_has_ebase_wg) {
#ifdef CONFIG_64BIT
ebase = (read_c0_ebase_64() & ~0xfff);
#else
ebase = (read_c0_ebase() & ~0xfff);
#endif
} else {
ebase += (read_c0_ebase() & 0x3ffff000);
}
}
} }
if (cpu_has_mmips) { if (cpu_has_mmips) {
...@@ -2459,7 +2440,7 @@ void __init trap_init(void) ...@@ -2459,7 +2440,7 @@ void __init trap_init(void)
else else
set_handler(0x080, &except_vec3_generic, 0x80); set_handler(0x080, &except_vec3_generic, 0x80);
local_flush_icache_range(ebase, ebase + 0x400); local_flush_icache_range(ebase, ebase + vec_size);
sort_extable(__start___dbe_table, __stop___dbe_table); sort_extable(__start___dbe_table, __stop___dbe_table);
......
...@@ -1141,9 +1141,7 @@ enum emulation_result kvm_mips_emul_tlbwr(struct kvm_vcpu *vcpu) ...@@ -1141,9 +1141,7 @@ enum emulation_result kvm_mips_emul_tlbwr(struct kvm_vcpu *vcpu)
unsigned long pc = vcpu->arch.pc; unsigned long pc = vcpu->arch.pc;
int index; int index;
get_random_bytes(&index, sizeof(index)); index = prandom_u32_max(KVM_MIPS_GUEST_TLB_SIZE);
index &= (KVM_MIPS_GUEST_TLB_SIZE - 1);
tlb = &vcpu->arch.guest_tlb[index]; tlb = &vcpu->arch.guest_tlb[index];
kvm_mips_invalidate_guest_tlb(vcpu, tlb); kvm_mips_invalidate_guest_tlb(vcpu, tlb);
......
...@@ -76,14 +76,22 @@ static const struct insn insn_table[insn_invalid] = { ...@@ -76,14 +76,22 @@ static const struct insn insn_table[insn_invalid] = {
[insn_daddiu] = {M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_daddiu] = {M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM},
[insn_daddu] = {M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD}, [insn_daddu] = {M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD},
[insn_ddivu] = {M(spec_op, 0, 0, 0, 0, ddivu_op), RS | RT}, [insn_ddivu] = {M(spec_op, 0, 0, 0, 0, ddivu_op), RS | RT},
[insn_ddivu_r6] = {M(spec_op, 0, 0, 0, ddivu_ddivu6_op, ddivu_op),
RS | RT | RD},
[insn_di] = {M(cop0_op, mfmc0_op, 0, 12, 0, 0), RT}, [insn_di] = {M(cop0_op, mfmc0_op, 0, 12, 0, 0), RT},
[insn_dins] = {M(spec3_op, 0, 0, 0, 0, dins_op), RS | RT | RD | RE}, [insn_dins] = {M(spec3_op, 0, 0, 0, 0, dins_op), RS | RT | RD | RE},
[insn_dinsm] = {M(spec3_op, 0, 0, 0, 0, dinsm_op), RS | RT | RD | RE}, [insn_dinsm] = {M(spec3_op, 0, 0, 0, 0, dinsm_op), RS | RT | RD | RE},
[insn_dinsu] = {M(spec3_op, 0, 0, 0, 0, dinsu_op), RS | RT | RD | RE}, [insn_dinsu] = {M(spec3_op, 0, 0, 0, 0, dinsu_op), RS | RT | RD | RE},
[insn_divu] = {M(spec_op, 0, 0, 0, 0, divu_op), RS | RT}, [insn_divu] = {M(spec_op, 0, 0, 0, 0, divu_op), RS | RT},
[insn_divu_r6] = {M(spec_op, 0, 0, 0, divu_divu6_op, divu_op),
RS | RT | RD},
[insn_dmfc0] = {M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_dmfc0] = {M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET},
[insn_dmodu] = {M(spec_op, 0, 0, 0, ddivu_dmodu_op, ddivu_op),
RS | RT | RD},
[insn_dmtc0] = {M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_dmtc0] = {M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET},
[insn_dmultu] = {M(spec_op, 0, 0, 0, 0, dmultu_op), RS | RT}, [insn_dmultu] = {M(spec_op, 0, 0, 0, 0, dmultu_op), RS | RT},
[insn_dmulu] = {M(spec_op, 0, 0, 0, dmult_dmul_op, dmultu_op),
RS | RT | RD},
[insn_drotr] = {M(spec_op, 1, 0, 0, 0, dsrl_op), RT | RD | RE}, [insn_drotr] = {M(spec_op, 1, 0, 0, 0, dsrl_op), RT | RD | RE},
[insn_drotr32] = {M(spec_op, 1, 0, 0, 0, dsrl32_op), RT | RD | RE}, [insn_drotr32] = {M(spec_op, 1, 0, 0, 0, dsrl32_op), RT | RD | RE},
[insn_dsbh] = {M(spec3_op, 0, 0, 0, dsbh_op, dbshfl_op), RT | RD}, [insn_dsbh] = {M(spec3_op, 0, 0, 0, dsbh_op, dbshfl_op), RT | RD},
...@@ -132,12 +140,16 @@ static const struct insn insn_table[insn_invalid] = { ...@@ -132,12 +140,16 @@ static const struct insn insn_table[insn_invalid] = {
[insn_mfhc0] = {M(cop0_op, mfhc0_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mfhc0] = {M(cop0_op, mfhc0_op, 0, 0, 0, 0), RT | RD | SET},
[insn_mfhi] = {M(spec_op, 0, 0, 0, 0, mfhi_op), RD}, [insn_mfhi] = {M(spec_op, 0, 0, 0, 0, mfhi_op), RD},
[insn_mflo] = {M(spec_op, 0, 0, 0, 0, mflo_op), RD}, [insn_mflo] = {M(spec_op, 0, 0, 0, 0, mflo_op), RD},
[insn_modu] = {M(spec_op, 0, 0, 0, divu_modu_op, divu_op),
RS | RT | RD},
[insn_movn] = {M(spec_op, 0, 0, 0, 0, movn_op), RS | RT | RD}, [insn_movn] = {M(spec_op, 0, 0, 0, 0, movn_op), RS | RT | RD},
[insn_movz] = {M(spec_op, 0, 0, 0, 0, movz_op), RS | RT | RD}, [insn_movz] = {M(spec_op, 0, 0, 0, 0, movz_op), RS | RT | RD},
[insn_mtc0] = {M(cop0_op, mtc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mtc0] = {M(cop0_op, mtc_op, 0, 0, 0, 0), RT | RD | SET},
[insn_mthc0] = {M(cop0_op, mthc0_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mthc0] = {M(cop0_op, mthc0_op, 0, 0, 0, 0), RT | RD | SET},
[insn_mthi] = {M(spec_op, 0, 0, 0, 0, mthi_op), RS}, [insn_mthi] = {M(spec_op, 0, 0, 0, 0, mthi_op), RS},
[insn_mtlo] = {M(spec_op, 0, 0, 0, 0, mtlo_op), RS}, [insn_mtlo] = {M(spec_op, 0, 0, 0, 0, mtlo_op), RS},
[insn_mulu] = {M(spec_op, 0, 0, 0, multu_mulu_op, multu_op),
RS | RT | RD},
#ifndef CONFIG_CPU_MIPSR6 #ifndef CONFIG_CPU_MIPSR6
[insn_mul] = {M(spec2_op, 0, 0, 0, 0, mul_op), RS | RT | RD}, [insn_mul] = {M(spec2_op, 0, 0, 0, 0, mul_op), RS | RT | RD},
#else #else
...@@ -163,6 +175,8 @@ static const struct insn insn_table[insn_invalid] = { ...@@ -163,6 +175,8 @@ static const struct insn insn_table[insn_invalid] = {
[insn_scd] = {M6(spec3_op, 0, 0, 0, scd6_op), RS | RT | SIMM9}, [insn_scd] = {M6(spec3_op, 0, 0, 0, scd6_op), RS | RT | SIMM9},
#endif #endif
[insn_sd] = {M(sd_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_sd] = {M(sd_op, 0, 0, 0, 0, 0), RS | RT | SIMM},
[insn_seleqz] = {M(spec_op, 0, 0, 0, 0, seleqz_op), RS | RT | RD},
[insn_selnez] = {M(spec_op, 0, 0, 0, 0, selnez_op), RS | RT | RD},
[insn_sh] = {M(sh_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_sh] = {M(sh_op, 0, 0, 0, 0, 0), RS | RT | SIMM},
[insn_sll] = {M(spec_op, 0, 0, 0, 0, sll_op), RT | RD | RE}, [insn_sll] = {M(spec_op, 0, 0, 0, 0, sll_op), RT | RD | RE},
[insn_sllv] = {M(spec_op, 0, 0, 0, 0, sllv_op), RS | RT | RD}, [insn_sllv] = {M(spec_op, 0, 0, 0, 0, sllv_op), RS | RT | RD},
......
...@@ -50,21 +50,22 @@ enum opcode { ...@@ -50,21 +50,22 @@ enum opcode {
insn_beq, insn_beql, insn_bgez, insn_bgezl, insn_bgtz, insn_blez, insn_beq, insn_beql, insn_bgez, insn_bgezl, insn_bgtz, insn_blez,
insn_bltz, insn_bltzl, insn_bne, insn_break, insn_cache, insn_cfc1, insn_bltz, insn_bltzl, insn_bne, insn_break, insn_cache, insn_cfc1,
insn_cfcmsa, insn_ctc1, insn_ctcmsa, insn_daddiu, insn_daddu, insn_ddivu, insn_cfcmsa, insn_ctc1, insn_ctcmsa, insn_daddiu, insn_daddu, insn_ddivu,
insn_di, insn_dins, insn_dinsm, insn_dinsu, insn_divu, insn_dmfc0, insn_ddivu_r6, insn_di, insn_dins, insn_dinsm, insn_dinsu, insn_divu,
insn_dmtc0, insn_dmultu, insn_drotr, insn_drotr32, insn_dsbh, insn_dshd, insn_divu_r6, insn_dmfc0, insn_dmodu, insn_dmtc0, insn_dmultu,
insn_dsll, insn_dsll32, insn_dsllv, insn_dsra, insn_dsra32, insn_dsrav, insn_dmulu, insn_drotr, insn_drotr32, insn_dsbh, insn_dshd, insn_dsll,
insn_dsrl, insn_dsrl32, insn_dsrlv, insn_dsubu, insn_eret, insn_ext, insn_dsll32, insn_dsllv, insn_dsra, insn_dsra32, insn_dsrav, insn_dsrl,
insn_ins, insn_j, insn_jal, insn_jalr, insn_jr, insn_lb, insn_lbu, insn_dsrl32, insn_dsrlv, insn_dsubu, insn_eret, insn_ext, insn_ins,
insn_ld, insn_lddir, insn_ldpte, insn_ldx, insn_lh, insn_lhu, insn_j, insn_jal, insn_jalr, insn_jr, insn_lb, insn_lbu, insn_ld,
insn_ll, insn_lld, insn_lui, insn_lw, insn_lwu, insn_lwx, insn_mfc0, insn_lddir, insn_ldpte, insn_ldx, insn_lh, insn_lhu, insn_ll, insn_lld,
insn_mfhc0, insn_mfhi, insn_mflo, insn_movn, insn_movz, insn_mtc0, insn_lui, insn_lw, insn_lwu, insn_lwx, insn_mfc0, insn_mfhc0, insn_mfhi,
insn_mthc0, insn_mthi, insn_mtlo, insn_mul, insn_multu, insn_nor, insn_mflo, insn_modu, insn_movn, insn_movz, insn_mtc0, insn_mthc0,
insn_or, insn_ori, insn_pref, insn_rfe, insn_rotr, insn_sb, insn_mthi, insn_mtlo, insn_mul, insn_multu, insn_mulu, insn_nor,
insn_sc, insn_scd, insn_sd, insn_sh, insn_sll, insn_sllv, insn_or, insn_ori, insn_pref, insn_rfe, insn_rotr, insn_sb, insn_sc,
insn_slt, insn_slti, insn_sltiu, insn_sltu, insn_sra, insn_srav, insn_scd, insn_seleqz, insn_selnez, insn_sd, insn_sh, insn_sll,
insn_srl, insn_srlv, insn_subu, insn_sw, insn_sync, insn_syscall, insn_sllv, insn_slt, insn_slti, insn_sltiu, insn_sltu, insn_sra,
insn_tlbp, insn_tlbr, insn_tlbwi, insn_tlbwr, insn_wait, insn_wsbh, insn_srav, insn_srl, insn_srlv, insn_subu, insn_sw, insn_sync,
insn_xor, insn_xori, insn_yield, insn_syscall, insn_tlbp, insn_tlbr, insn_tlbwi, insn_tlbwr, insn_wait,
insn_wsbh, insn_xor, insn_xori, insn_yield,
insn_invalid /* insn_invalid must be last */ insn_invalid /* insn_invalid must be last */
}; };
...@@ -287,13 +288,17 @@ I_u2u1(_cfcmsa) ...@@ -287,13 +288,17 @@ I_u2u1(_cfcmsa)
I_u1u2(_ctc1) I_u1u2(_ctc1)
I_u2u1(_ctcmsa) I_u2u1(_ctcmsa)
I_u1u2(_ddivu) I_u1u2(_ddivu)
I_u3u1u2(_ddivu_r6)
I_u1u2u3(_dmfc0) I_u1u2u3(_dmfc0)
I_u3u1u2(_dmodu)
I_u1u2u3(_dmtc0) I_u1u2u3(_dmtc0)
I_u1u2(_dmultu) I_u1u2(_dmultu)
I_u3u1u2(_dmulu)
I_u2u1s3(_daddiu) I_u2u1s3(_daddiu)
I_u3u1u2(_daddu) I_u3u1u2(_daddu)
I_u1(_di); I_u1(_di);
I_u1u2(_divu) I_u1u2(_divu)
I_u3u1u2(_divu_r6)
I_u2u1(_dsbh); I_u2u1(_dsbh);
I_u2u1(_dshd); I_u2u1(_dshd);
I_u2u1u3(_dsll) I_u2u1u3(_dsll)
...@@ -327,6 +332,7 @@ I_u2s3u1(_lw) ...@@ -327,6 +332,7 @@ I_u2s3u1(_lw)
I_u2s3u1(_lwu) I_u2s3u1(_lwu)
I_u1u2u3(_mfc0) I_u1u2u3(_mfc0)
I_u1u2u3(_mfhc0) I_u1u2u3(_mfhc0)
I_u3u1u2(_modu)
I_u3u1u2(_movn) I_u3u1u2(_movn)
I_u3u1u2(_movz) I_u3u1u2(_movz)
I_u1(_mfhi) I_u1(_mfhi)
...@@ -337,6 +343,7 @@ I_u1(_mthi) ...@@ -337,6 +343,7 @@ I_u1(_mthi)
I_u1(_mtlo) I_u1(_mtlo)
I_u3u1u2(_mul) I_u3u1u2(_mul)
I_u1u2(_multu) I_u1u2(_multu)
I_u3u1u2(_mulu)
I_u3u1u2(_nor) I_u3u1u2(_nor)
I_u3u1u2(_or) I_u3u1u2(_or)
I_u2u1u3(_ori) I_u2u1u3(_ori)
...@@ -345,6 +352,8 @@ I_u2s3u1(_sb) ...@@ -345,6 +352,8 @@ I_u2s3u1(_sb)
I_u2s3u1(_sc) I_u2s3u1(_sc)
I_u2s3u1(_scd) I_u2s3u1(_scd)
I_u2s3u1(_sd) I_u2s3u1(_sd)
I_u3u1u2(_seleqz)
I_u3u1u2(_selnez)
I_u2s3u1(_sh) I_u2s3u1(_sh)
I_u2u1u3(_sll) I_u2u1u3(_sll)
I_u3u2u1(_sllv) I_u3u2u1(_sllv)
......
# MIPS networking code # MIPS networking code
obj-$(CONFIG_MIPS_CBPF_JIT) += bpf_jit.o bpf_jit_asm.o
obj-$(CONFIG_MIPS_EBPF_JIT) += ebpf_jit.o obj-$(CONFIG_MIPS_EBPF_JIT) += ebpf_jit.o
This diff is collapsed.
/*
* bpf_jib_asm.S: Packet/header access helper functions for MIPS/MIPS64 BPF
* compiler.
*
* Copyright (C) 2015 Imagination Technologies Ltd.
* Author: Markos Chandras <markos.chandras@imgtec.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*/
#include <asm/asm.h>
#include <asm/isa-rev.h>
#include <asm/regdef.h>
#include "bpf_jit.h"
/* ABI
*
* r_skb_hl skb header length
* r_skb_data skb data
* r_off(a1) offset register
* r_A BPF register A
* r_X PF register X
* r_skb(a0) *skb
* r_M *scratch memory
* r_skb_le skb length
* r_s0 Scratch register 0
* r_s1 Scratch register 1
*
* On entry:
* a0: *skb
* a1: offset (imm or imm + X)
*
* All non-BPF-ABI registers are free for use. On return, we only
* care about r_ret. The BPF-ABI registers are assumed to remain
* unmodified during the entire filter operation.
*/
#define skb a0
#define offset a1
#define SKF_LL_OFF (-0x200000) /* Can't include linux/filter.h in assembly */
/* We know better :) so prevent assembler reordering etc */
.set noreorder
#define is_offset_negative(TYPE) \
/* If offset is negative we have more work to do */ \
slti t0, offset, 0; \
bgtz t0, bpf_slow_path_##TYPE##_neg; \
/* Be careful what follows in DS. */
#define is_offset_in_header(SIZE, TYPE) \
/* Reading from header? */ \
addiu $r_s0, $r_skb_hl, -SIZE; \
slt t0, $r_s0, offset; \
bgtz t0, bpf_slow_path_##TYPE; \
LEAF(sk_load_word)
is_offset_negative(word)
FEXPORT(sk_load_word_positive)
is_offset_in_header(4, word)
/* Offset within header boundaries */
PTR_ADDU t1, $r_skb_data, offset
.set reorder
lw $r_A, 0(t1)
.set noreorder
#ifdef CONFIG_CPU_LITTLE_ENDIAN
# if MIPS_ISA_REV >= 2
wsbh t0, $r_A
rotr $r_A, t0, 16
# else
sll t0, $r_A, 24
srl t1, $r_A, 24
srl t2, $r_A, 8
or t0, t0, t1
andi t2, t2, 0xff00
andi t1, $r_A, 0xff00
or t0, t0, t2
sll t1, t1, 8
or $r_A, t0, t1
# endif
#endif
jr $r_ra
move $r_ret, zero
END(sk_load_word)
LEAF(sk_load_half)
is_offset_negative(half)
FEXPORT(sk_load_half_positive)
is_offset_in_header(2, half)
/* Offset within header boundaries */
PTR_ADDU t1, $r_skb_data, offset
lhu $r_A, 0(t1)
#ifdef CONFIG_CPU_LITTLE_ENDIAN
# if MIPS_ISA_REV >= 2
wsbh $r_A, $r_A
# else
sll t0, $r_A, 8
srl t1, $r_A, 8
andi t0, t0, 0xff00
or $r_A, t0, t1
# endif
#endif
jr $r_ra
move $r_ret, zero
END(sk_load_half)
LEAF(sk_load_byte)
is_offset_negative(byte)
FEXPORT(sk_load_byte_positive)
is_offset_in_header(1, byte)
/* Offset within header boundaries */
PTR_ADDU t1, $r_skb_data, offset
lbu $r_A, 0(t1)
jr $r_ra
move $r_ret, zero
END(sk_load_byte)
/*
* call skb_copy_bits:
* (prototype in linux/skbuff.h)
*
* int skb_copy_bits(sk_buff *skb, int offset, void *to, int len)
*
* o32 mandates we leave 4 spaces for argument registers in case
* the callee needs to use them. Even though we don't care about
* the argument registers ourselves, we need to allocate that space
* to remain ABI compliant since the callee may want to use that space.
* We also allocate 2 more spaces for $r_ra and our return register (*to).
*
* n64 is a bit different. The *caller* will allocate the space to preserve
* the arguments. So in 64-bit kernels, we allocate the 4-arg space for no
* good reason but it does not matter that much really.
*
* (void *to) is returned in r_s0
*
*/
#ifdef CONFIG_CPU_LITTLE_ENDIAN
#define DS_OFFSET(SIZE) (4 * SZREG)
#else
#define DS_OFFSET(SIZE) ((4 * SZREG) + (4 - SIZE))
#endif
#define bpf_slow_path_common(SIZE) \
/* Quick check. Are we within reasonable boundaries? */ \
LONG_ADDIU $r_s1, $r_skb_len, -SIZE; \
sltu $r_s0, offset, $r_s1; \
beqz $r_s0, fault; \
/* Load 4th argument in DS */ \
LONG_ADDIU a3, zero, SIZE; \
PTR_ADDIU $r_sp, $r_sp, -(6 * SZREG); \
PTR_LA t0, skb_copy_bits; \
PTR_S $r_ra, (5 * SZREG)($r_sp); \
/* Assign low slot to a2 */ \
PTR_ADDIU a2, $r_sp, DS_OFFSET(SIZE); \
jalr t0; \
/* Reset our destination slot (DS but it's ok) */ \
INT_S zero, (4 * SZREG)($r_sp); \
/* \
* skb_copy_bits returns 0 on success and -EFAULT \
* on error. Our data live in a2. Do not bother with \
* our data if an error has been returned. \
*/ \
/* Restore our frame */ \
PTR_L $r_ra, (5 * SZREG)($r_sp); \
INT_L $r_s0, (4 * SZREG)($r_sp); \
bltz v0, fault; \
PTR_ADDIU $r_sp, $r_sp, 6 * SZREG; \
move $r_ret, zero; \
NESTED(bpf_slow_path_word, (6 * SZREG), $r_sp)
bpf_slow_path_common(4)
#ifdef CONFIG_CPU_LITTLE_ENDIAN
# if MIPS_ISA_REV >= 2
wsbh t0, $r_s0
jr $r_ra
rotr $r_A, t0, 16
# else
sll t0, $r_s0, 24
srl t1, $r_s0, 24
srl t2, $r_s0, 8
or t0, t0, t1
andi t2, t2, 0xff00
andi t1, $r_s0, 0xff00
or t0, t0, t2
sll t1, t1, 8
jr $r_ra
or $r_A, t0, t1
# endif
#else
jr $r_ra
move $r_A, $r_s0
#endif
END(bpf_slow_path_word)
NESTED(bpf_slow_path_half, (6 * SZREG), $r_sp)
bpf_slow_path_common(2)
#ifdef CONFIG_CPU_LITTLE_ENDIAN
# if MIPS_ISA_REV >= 2
jr $r_ra
wsbh $r_A, $r_s0
# else
sll t0, $r_s0, 8
andi t1, $r_s0, 0xff00
andi t0, t0, 0xff00
srl t1, t1, 8
jr $r_ra
or $r_A, t0, t1
# endif
#else
jr $r_ra
move $r_A, $r_s0
#endif
END(bpf_slow_path_half)
NESTED(bpf_slow_path_byte, (6 * SZREG), $r_sp)
bpf_slow_path_common(1)
jr $r_ra
move $r_A, $r_s0
END(bpf_slow_path_byte)
/*
* Negative entry points
*/
.macro bpf_is_end_of_data
li t0, SKF_LL_OFF
/* Reading link layer data? */
slt t1, offset, t0
bgtz t1, fault
/* Be careful what follows in DS. */
.endm
/*
* call skb_copy_bits:
* (prototype in linux/filter.h)
*
* void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb,
* int k, unsigned int size)
*
* see above (bpf_slow_path_common) for ABI restrictions
*/
#define bpf_negative_common(SIZE) \
PTR_ADDIU $r_sp, $r_sp, -(6 * SZREG); \
PTR_LA t0, bpf_internal_load_pointer_neg_helper; \
PTR_S $r_ra, (5 * SZREG)($r_sp); \
jalr t0; \
li a2, SIZE; \
PTR_L $r_ra, (5 * SZREG)($r_sp); \
/* Check return pointer */ \
beqz v0, fault; \
PTR_ADDIU $r_sp, $r_sp, 6 * SZREG; \
/* Preserve our pointer */ \
move $r_s0, v0; \
/* Set return value */ \
move $r_ret, zero; \
bpf_slow_path_word_neg:
bpf_is_end_of_data
NESTED(sk_load_word_negative, (6 * SZREG), $r_sp)
bpf_negative_common(4)
jr $r_ra
lw $r_A, 0($r_s0)
END(sk_load_word_negative)
bpf_slow_path_half_neg:
bpf_is_end_of_data
NESTED(sk_load_half_negative, (6 * SZREG), $r_sp)
bpf_negative_common(2)
jr $r_ra
lhu $r_A, 0($r_s0)
END(sk_load_half_negative)
bpf_slow_path_byte_neg:
bpf_is_end_of_data
NESTED(sk_load_byte_negative, (6 * SZREG), $r_sp)
bpf_negative_common(1)
jr $r_ra
lbu $r_A, 0($r_s0)
END(sk_load_byte_negative)
fault:
jr $r_ra
addiu $r_ret, zero, 1
This diff is collapsed.
...@@ -46,9 +46,7 @@ endif ...@@ -46,9 +46,7 @@ endif
VDSO_LDFLAGS := \ VDSO_LDFLAGS := \
-Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 \ -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 \
$(addprefix -Wl$(comma),$(filter -E%,$(KBUILD_CFLAGS))) \ $(addprefix -Wl$(comma),$(filter -E%,$(KBUILD_CFLAGS))) \
-nostdlib -shared \ -nostdlib -shared -Wl,--hash-style=sysv -Wl,--build-id
$(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
$(call cc-ldoption, -Wl$(comma)--build-id)
GCOV_PROFILE := n GCOV_PROFILE := n
UBSAN_SANITIZE := n UBSAN_SANITIZE := n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment