Skip to content

Commit 656be92

Browse files
atsushi-nemotoralfbaechle
authored andcommitted
[MIPS] Load modules to CKSEG0 if CONFIG_BUILD_ELF64=n
This is a patch to load 64-bit modules to CKSEG0 so that can be compiled with -msym32 option. This makes each module ~10% smaller. * introduce MODULE_START and MODULE_END * custom module_alloc() * PGD for modules * change XTLB refill handler synthesizer * enable -msym32 for modules again (revert ca78b1a5c6a6e70e052d3ea253828e49b5d07c8a) New XTLB refill handler looks like this: 80000080 dmfc0 k0,C0_BADVADDR 80000084 bltz k0,800000e4 # goto l_module_alloc 80000088 lui k1,0x8046 # %high(pgd_current) 8000008c ld k1,24600(k1) # %low(pgd_current) 80000090 dsrl k0,k0,0x1b # l_vmalloc_done: 80000094 andi k0,k0,0x1ff8 80000098 daddu k1,k1,k0 8000009c dmfc0 k0,C0_BADVADDR 800000a0 ld k1,0(k1) 800000a4 dsrl k0,k0,0x12 800000a8 andi k0,k0,0xff8 800000ac daddu k1,k1,k0 800000b0 dmfc0 k0,C0_XCONTEXT 800000b4 ld k1,0(k1) 800000b8 andi k0,k0,0xff0 800000bc daddu k1,k1,k0 800000c0 ld k0,0(k1) 800000c4 ld k1,8(k1) 800000c8 dsrl k0,k0,0x6 800000cc mtc0 k0,C0_ENTRYLO0 800000d0 dsrl k1,k1,0x6 800000d4 mtc0 k1,C0_ENTRYL01 800000d8 nop 800000dc tlbwr 800000e0 eret 800000e4 dsll k1,k0,0x2 # l_module_alloc: 800000e8 bgez k1,80000008 # goto l_vmalloc 800000ec lui k1,0xc000 800000f0 dsubu k0,k0,k1 800000f4 lui k1,0x8046 # %high(module_pg_dir) 800000f8 beq zero,zero,80000000 800000fc nop 80000000 beq zero,zero,80000090 # goto l_vmalloc_done 80000004 daddiu k1,k1,0x4000 80000008 dsll32 k1,k1,0x0 # l_vmalloc: 8000000c dsubu k0,k0,k1 80000010 beq zero,zero,80000090 # goto l_vmalloc_done 80000014 lui k1,0x8046 # %high(swapper_pg_dir) Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 56ae583 commit 656be92

7 files changed

Lines changed: 94 additions & 3 deletions

File tree

‎arch/mips/Makefile‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ cflags-y += -mabi=64
6363
ifdef CONFIG_BUILD_ELF64
6464
cflags-y += $(call cc-option,-mno-explicit-relocs)
6565
else
66-
# -msym32 can not be used for modules since they are loaded into XKSEG
67-
CFLAGS_MODULE += $(call cc-option,-mno-explicit-relocs)
68-
CFLAGS_KERNEL += $(call cc-option,-msym32)
66+
cflags-y += $(call cc-option,-msym32)
6967
endif
7068
endif
7169

‎arch/mips/kernel/head.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ NESTED(smp_bootstrap, 16, sp)
250250
*/
251251
page swapper_pg_dir, _PGD_ORDER
252252
#ifdef CONFIG_64BIT
253+
#if defined(CONFIG_MODULES) && !defined(CONFIG_BUILD_ELF64)
254+
page module_pg_dir, _PGD_ORDER
255+
#endif
253256
page invalid_pmd_table, _PMD_ORDER
254257
#endif
255258
page invalid_pte_table, _PTE_ORDER

‎arch/mips/kernel/module.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/kernel.h>
3030
#include <linux/module.h>
3131
#include <linux/spinlock.h>
32+
#include <asm/pgtable.h> /* MODULE_START */
3233

3334
struct mips_hi16 {
3435
struct mips_hi16 *next;
@@ -43,9 +44,23 @@ static DEFINE_SPINLOCK(dbe_lock);
4344

4445
void *module_alloc(unsigned long size)
4546
{
47+
#ifdef MODULE_START
48+
struct vm_struct *area;
49+
50+
size = PAGE_ALIGN(size);
51+
if (!size)
52+
return NULL;
53+
54+
area = __get_vm_area(size, VM_ALLOC, MODULE_START, MODULE_END);
55+
if (!area)
56+
return NULL;
57+
58+
return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL);
59+
#else
4660
if (size == 0)
4761
return NULL;
4862
return vmalloc(size);
63+
#endif
4964
}
5065

5166
/* Free memory returned from module_alloc */

‎arch/mips/mm/fault.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
6060
*/
6161
if (unlikely(address >= VMALLOC_START && address <= VMALLOC_END))
6262
goto vmalloc_fault;
63+
#ifdef MODULE_START
64+
if (unlikely(address >= MODULE_START && address < MODULE_END))
65+
goto vmalloc_fault;
66+
#endif
6367

6468
/*
6569
* If we're in an interrupt or have no user

‎arch/mips/mm/pgtable-64.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void __init pagetable_init(void)
5858

5959
/* Initialize the entire pgd. */
6060
pgd_init((unsigned long)swapper_pg_dir);
61+
#ifdef MODULE_START
62+
pgd_init((unsigned long)module_pg_dir);
63+
#endif
6164
pmd_init((unsigned long)invalid_pmd_table, (unsigned long)invalid_pte_table);
6265

6366
pgd_base = swapper_pg_dir;

‎arch/mips/mm/tlbex.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ enum label_id {
423423
label_invalid,
424424
label_second_part,
425425
label_leave,
426+
#ifdef MODULE_START
427+
label_module_alloc,
428+
#endif
426429
label_vmalloc,
427430
label_vmalloc_done,
428431
label_tlbw_hazard,
@@ -455,6 +458,9 @@ static __init void build_label(struct label **lab, u32 *addr,
455458

456459
L_LA(_second_part)
457460
L_LA(_leave)
461+
#ifdef MODULE_START
462+
L_LA(_module_alloc)
463+
#endif
458464
L_LA(_vmalloc)
459465
L_LA(_vmalloc_done)
460466
L_LA(_tlbw_hazard)
@@ -686,6 +692,13 @@ static void __init il_bgezl(u32 **p, struct reloc **r, unsigned int reg,
686692
i_bgezl(p, reg, 0);
687693
}
688694

695+
static void __init __attribute__((unused))
696+
il_bgez(u32 **p, struct reloc **r, unsigned int reg, enum label_id l)
697+
{
698+
r_mips_pc16(r, *p, l);
699+
i_bgez(p, reg, 0);
700+
}
701+
689702
/* The only general purpose registers allowed in TLB handlers. */
690703
#define K0 26
691704
#define K1 27
@@ -970,7 +983,11 @@ build_get_pmde64(u32 **p, struct label **l, struct reloc **r,
970983
* The vmalloc handling is not in the hotpath.
971984
*/
972985
i_dmfc0(p, tmp, C0_BADVADDR);
986+
#ifdef MODULE_START
987+
il_bltz(p, r, tmp, label_module_alloc);
988+
#else
973989
il_bltz(p, r, tmp, label_vmalloc);
990+
#endif
974991
/* No i_nop needed here, since the next insn doesn't touch TMP. */
975992

976993
#ifdef CONFIG_SMP
@@ -1023,8 +1040,46 @@ build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r,
10231040
{
10241041
long swpd = (long)swapper_pg_dir;
10251042

1043+
#ifdef MODULE_START
1044+
long modd = (long)module_pg_dir;
1045+
1046+
l_module_alloc(l, *p);
1047+
/*
1048+
* Assumption:
1049+
* VMALLOC_START >= 0xc000000000000000UL
1050+
* MODULE_START >= 0xe000000000000000UL
1051+
*/
1052+
i_SLL(p, ptr, bvaddr, 2);
1053+
il_bgez(p, r, ptr, label_vmalloc);
1054+
1055+
if (in_compat_space_p(MODULE_START) && !rel_lo(MODULE_START)) {
1056+
i_lui(p, ptr, rel_hi(MODULE_START)); /* delay slot */
1057+
} else {
1058+
/* unlikely configuration */
1059+
i_nop(p); /* delay slot */
1060+
i_LA(p, ptr, MODULE_START);
1061+
}
1062+
i_dsubu(p, bvaddr, bvaddr, ptr);
1063+
1064+
if (in_compat_space_p(modd) && !rel_lo(modd)) {
1065+
il_b(p, r, label_vmalloc_done);
1066+
i_lui(p, ptr, rel_hi(modd));
1067+
} else {
1068+
i_LA_mostly(p, ptr, modd);
1069+
il_b(p, r, label_vmalloc_done);
1070+
i_daddiu(p, ptr, ptr, rel_lo(modd));
1071+
}
1072+
1073+
l_vmalloc(l, *p);
1074+
if (in_compat_space_p(MODULE_START) && !rel_lo(MODULE_START) &&
1075+
MODULE_START << 32 == VMALLOC_START)
1076+
i_dsll32(p, ptr, ptr, 0); /* typical case */
1077+
else
1078+
i_LA(p, ptr, VMALLOC_START);
1079+
#else
10261080
l_vmalloc(l, *p);
10271081
i_LA(p, ptr, VMALLOC_START);
1082+
#endif
10281083
i_dsubu(p, bvaddr, bvaddr, ptr);
10291084

10301085
if (in_compat_space_p(swpd) && !rel_lo(swpd)) {

‎include/asm-mips/pgtable-64.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/addrspace.h>
1515
#include <asm/page.h>
1616
#include <asm/cachectl.h>
17+
#include <asm/fixmap.h>
1718

1819
#include <asm-generic/pgtable-nopud.h>
1920

@@ -103,6 +104,13 @@
103104
#define VMALLOC_START MAP_BASE
104105
#define VMALLOC_END \
105106
(VMALLOC_START + PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE)
107+
#if defined(CONFIG_MODULES) && !defined(CONFIG_BUILD_ELF64) && \
108+
VMALLOC_START != CKSSEG
109+
/* Load modules into 32bit-compatible segment. */
110+
#define MODULE_START CKSSEG
111+
#define MODULE_END (FIXADDR_START-2*PAGE_SIZE)
112+
extern pgd_t module_pg_dir[PTRS_PER_PGD];
113+
#endif
106114

107115
#define pte_ERROR(e) \
108116
printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
@@ -174,7 +182,12 @@ static inline void pud_clear(pud_t *pudp)
174182
#define __pmd_offset(address) pmd_index(address)
175183

176184
/* to find an entry in a kernel page-table-directory */
185+
#ifdef MODULE_START
186+
#define pgd_offset_k(address) \
187+
((address) >= MODULE_START ? module_pg_dir : pgd_offset(&init_mm, 0UL))
188+
#else
177189
#define pgd_offset_k(address) pgd_offset(&init_mm, 0UL)
190+
#endif
178191

179192
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
180193
#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))

0 commit comments

Comments
 (0)