Skip to content

Commit fbe9c96

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
m68k: runtime patching infrastructure
Add the basic infrastructure to allow runtime patching of kernel and modules to optimize a few functions with parameters, which are only calculated once during bootup and are otherwise constant. Use this for the conversion between virtual and physical addresses. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1fc799e commit fbe9c96

9 files changed

Lines changed: 107 additions & 7 deletions

File tree

‎arch/m68k/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ COMPILE_ARCH = $(shell uname -m)
1919
# override top level makefile
2020
AS += -m68020
2121
LDFLAGS := -m m68kelf
22+
LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds
2223
ifneq ($(COMPILE_ARCH),$(ARCH))
2324
# prefix for cross-compiling binaries
2425
CROSS_COMPILE = m68k-linux-gnu-

‎arch/m68k/kernel/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ else
99
endif
1010
extra-y += vmlinux.lds
1111

12-
obj-y := entry.o process.o traps.o ints.o signal.o ptrace.o \
12+
obj-y := entry.o process.o traps.o ints.o signal.o ptrace.o module.o \
1313
sys_m68k.o time.o semaphore.o setup.o m68k_ksyms.o devres.o
1414

1515
devres-y = ../../../kernel/irq/devres.o
1616

1717
obj-$(CONFIG_PCI) += bios32.o
18-
obj-$(CONFIG_MODULES) += module.o
1918
obj-y$(CONFIG_MMU_SUN3) += dma.o # no, it's not a typo
2019

2120
EXTRA_AFLAGS := -traditional

‎arch/m68k/kernel/module.c‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* This file is subject to the terms and conditions of the GNU General Public
3+
* License. See the file COPYING in the main directory of this archive
4+
* for more details.
5+
*/
6+
17
#include <linux/moduleloader.h>
28
#include <linux/elf.h>
39
#include <linux/vmalloc.h>
@@ -11,6 +17,8 @@
1117
#define DEBUGP(fmt...)
1218
#endif
1319

20+
#ifdef CONFIG_MODULES
21+
1422
void *module_alloc(unsigned long size)
1523
{
1624
if (size == 0)
@@ -118,11 +126,29 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
118126

119127
int module_finalize(const Elf_Ehdr *hdr,
120128
const Elf_Shdr *sechdrs,
121-
struct module *me)
129+
struct module *mod)
122130
{
131+
module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
132+
123133
return 0;
124134
}
125135

126136
void module_arch_cleanup(struct module *mod)
127137
{
128138
}
139+
140+
#endif /* CONFIG_MODULES */
141+
142+
void module_fixup(struct module *mod, struct m68k_fixup_info *start,
143+
struct m68k_fixup_info *end)
144+
{
145+
struct m68k_fixup_info *fixup;
146+
147+
for (fixup = start; fixup < end; fixup++) {
148+
switch (fixup->type) {
149+
case m68k_fixup_memoffset:
150+
*(u32 *)fixup->addr = m68k_memoffset;
151+
break;
152+
}
153+
}
154+
}

‎arch/m68k/kernel/module.lds‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SECTIONS {
2+
.m68k_fixup : {
3+
__start_fixup = .;
4+
*(.m68k_fixup)
5+
__stop_fixup = .;
6+
}
7+
}

‎arch/m68k/kernel/vmlinux-std.lds‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ SECTIONS
6060
__con_initcall_start = .;
6161
.con_initcall.init : { *(.con_initcall.init) }
6262
__con_initcall_end = .;
63+
.m68k_fixup : {
64+
__start_fixup = .;
65+
*(.m68k_fixup)
66+
__stop_fixup = .;
67+
}
6368
SECURITY_INIT
6469
#ifdef CONFIG_BLK_DEV_INITRD
6570
. = ALIGN(8192);

‎arch/m68k/kernel/vmlinux-sun3.lds‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ __init_begin = .;
5454
__con_initcall_start = .;
5555
.con_initcall.init : { *(.con_initcall.init) }
5656
__con_initcall_end = .;
57+
.m68k_fixup : {
58+
__start_fixup = .;
59+
*(.m68k_fixup)
60+
__stop_fixup = .;
61+
}
5762
SECURITY_INIT
5863
#ifdef CONFIG_BLK_DEV_INITRD
5964
. = ALIGN(8192);

‎arch/m68k/mm/motorola.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ void __init paging_init(void)
222222
pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
223223
}
224224

225+
module_fixup(NULL, __start_fixup, __stop_fixup);
226+
flush_icache();
227+
225228
/*
226229
* Map the physical memory available into the kernel virtual
227230
* address space. It may allocate some memory for page

‎include/asm-m68k/module.h‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
#ifndef _ASM_M68K_MODULE_H
22
#define _ASM_M68K_MODULE_H
3-
struct mod_arch_specific { };
3+
4+
struct mod_arch_specific {
5+
struct m68k_fixup_info *fixup_start, *fixup_end;
6+
};
7+
8+
#define MODULE_ARCH_INIT { \
9+
.fixup_start = __start_fixup, \
10+
.fixup_end = __stop_fixup, \
11+
}
12+
413
#define Elf_Shdr Elf32_Shdr
514
#define Elf_Sym Elf32_Sym
615
#define Elf_Ehdr Elf32_Ehdr
16+
17+
18+
enum m68k_fixup_type {
19+
m68k_fixup_memoffset,
20+
};
21+
22+
struct m68k_fixup_info {
23+
enum m68k_fixup_type type;
24+
void *addr;
25+
};
26+
27+
#define m68k_fixup(type, addr) \
28+
" .section \".m68k_fixup\",\"aw\"\n" \
29+
" .long " #type "," #addr "\n" \
30+
" .previous\n"
31+
32+
extern struct m68k_fixup_info __start_fixup[], __stop_fixup[];
33+
34+
struct module;
35+
extern void module_fixup(struct module *mod, struct m68k_fixup_info *start,
36+
struct m68k_fixup_info *end);
37+
738
#endif /* _ASM_M68K_MODULE_H */

‎include/asm-m68k/page.h‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#ifndef __ASSEMBLY__
2929

30+
#include <asm/module.h>
31+
3032
#define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
3133
#define free_user_page(page, addr) free_page(addr)
3234

@@ -114,14 +116,35 @@ typedef struct { unsigned long pgprot; } pgprot_t;
114116

115117
#ifndef __ASSEMBLY__
116118

119+
extern unsigned long m68k_memoffset;
120+
117121
#ifndef CONFIG_SUN3
118122

119123
#define WANT_PAGE_VIRTUAL
120124
#ifdef CONFIG_SINGLE_MEMORY_CHUNK
121-
extern unsigned long m68k_memoffset;
122125

123-
#define __pa(vaddr) ((unsigned long)(vaddr)+m68k_memoffset)
124-
#define __va(paddr) ((void *)((unsigned long)(paddr)-m68k_memoffset))
126+
static inline unsigned long ___pa(void *vaddr)
127+
{
128+
unsigned long paddr;
129+
asm (
130+
"1: addl #0,%0\n"
131+
m68k_fixup(%c2, 1b+2)
132+
: "=r" (paddr)
133+
: "0" (vaddr), "i" (m68k_fixup_memoffset));
134+
return paddr;
135+
}
136+
#define __pa(vaddr) ___pa((void *)(vaddr))
137+
static inline void *__va(unsigned long paddr)
138+
{
139+
void *vaddr;
140+
asm (
141+
"1: subl #0,%0\n"
142+
m68k_fixup(%c2, 1b+2)
143+
: "=r" (vaddr)
144+
: "0" (paddr), "i" (m68k_fixup_memoffset));
145+
return vaddr;
146+
}
147+
125148
#else
126149
#define __pa(vaddr) virt_to_phys((void *)(vaddr))
127150
#define __va(paddr) phys_to_virt((unsigned long)(paddr))

0 commit comments

Comments
 (0)