2005-04-17 06:20:36 +08:00
|
|
|
/* Kernel module help for sparc64.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Rusty Russell.
|
|
|
|
* Copyright (C) 2002 David S. Miller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/moduleloader.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/elf.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/fs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
2008-12-27 07:38:17 +08:00
|
|
|
#include <linux/ctype.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/spitfire.h>
|
2012-03-29 01:30:03 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-18 14:44:58 +08:00
|
|
|
#include "entry.h"
|
|
|
|
|
2008-12-27 07:37:24 +08:00
|
|
|
#ifdef CONFIG_SPARC64
|
2010-09-17 23:09:25 +08:00
|
|
|
|
|
|
|
#include <linux/jump_label.h>
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void *module_map(unsigned long size)
|
|
|
|
{
|
2011-01-14 07:46:02 +08:00
|
|
|
if (PAGE_ALIGN(size) > MODULES_LEN)
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
2011-01-14 07:46:02 +08:00
|
|
|
return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
|
2015-02-14 06:40:07 +08:00
|
|
|
GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
|
2011-01-14 07:46:02 +08:00
|
|
|
__builtin_return_address(0));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-12-27 07:38:17 +08:00
|
|
|
#else
|
|
|
|
static void *module_map(unsigned long size)
|
|
|
|
{
|
|
|
|
return vmalloc(size);
|
|
|
|
}
|
2008-12-27 07:37:24 +08:00
|
|
|
#endif /* CONFIG_SPARC64 */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void *module_alloc(unsigned long size)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
ret = module_map(size);
|
2012-09-21 02:57:51 +08:00
|
|
|
if (ret)
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(ret, 0, size);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make generic code ignore STT_REGISTER dummy undefined symbols. */
|
|
|
|
int module_frob_arch_sections(Elf_Ehdr *hdr,
|
|
|
|
Elf_Shdr *sechdrs,
|
|
|
|
char *secstrings,
|
|
|
|
struct module *mod)
|
|
|
|
{
|
|
|
|
unsigned int symidx;
|
2008-12-27 07:36:29 +08:00
|
|
|
Elf_Sym *sym;
|
2008-12-27 07:37:24 +08:00
|
|
|
char *strtab;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
|
|
|
|
if (symidx == hdr->e_shnum-1) {
|
|
|
|
printk("%s: no symtab found.\n", mod->name);
|
|
|
|
return -ENOEXEC;
|
|
|
|
}
|
|
|
|
}
|
2008-12-27 07:36:29 +08:00
|
|
|
sym = (Elf_Sym *)sechdrs[symidx].sh_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
|
|
|
|
|
|
|
|
for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
|
2008-12-27 07:37:24 +08:00
|
|
|
if (sym[i].st_shndx == SHN_UNDEF) {
|
2012-05-16 02:23:01 +08:00
|
|
|
if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER)
|
2008-12-27 07:37:24 +08:00
|
|
|
sym[i].st_shndx = SHN_ABS;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-27 07:36:29 +08:00
|
|
|
int apply_relocate_add(Elf_Shdr *sechdrs,
|
2005-04-17 06:20:36 +08:00
|
|
|
const char *strtab,
|
|
|
|
unsigned int symindex,
|
|
|
|
unsigned int relsec,
|
|
|
|
struct module *me)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2008-12-27 07:36:29 +08:00
|
|
|
Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
|
|
|
|
Elf_Sym *sym;
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 *location;
|
|
|
|
u32 *loc32;
|
|
|
|
|
|
|
|
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
|
2008-12-27 07:36:29 +08:00
|
|
|
Elf_Addr v;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This is where to make the change */
|
|
|
|
location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
|
|
|
|
+ rel[i].r_offset;
|
|
|
|
loc32 = (u32 *) location;
|
|
|
|
|
2008-12-27 07:37:24 +08:00
|
|
|
#ifdef CONFIG_SPARC64
|
2005-04-17 06:20:36 +08:00
|
|
|
BUG_ON(((u64)location >> (u64)32) != (u64)0);
|
2008-12-27 07:37:24 +08:00
|
|
|
#endif /* CONFIG_SPARC64 */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This is the symbol it is referring to. Note that all
|
|
|
|
undefined symbols have been resolved. */
|
2008-12-27 07:36:29 +08:00
|
|
|
sym = (Elf_Sym *)sechdrs[symindex].sh_addr
|
|
|
|
+ ELF_R_SYM(rel[i].r_info);
|
2005-04-17 06:20:36 +08:00
|
|
|
v = sym->st_value + rel[i].r_addend;
|
|
|
|
|
2008-12-27 07:36:29 +08:00
|
|
|
switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
|
2012-09-18 03:59:52 +08:00
|
|
|
case R_SPARC_DISP32:
|
|
|
|
v -= (Elf_Addr) location;
|
|
|
|
*loc32 = v;
|
|
|
|
break;
|
2008-12-27 07:37:24 +08:00
|
|
|
#ifdef CONFIG_SPARC64
|
2005-04-17 06:20:36 +08:00
|
|
|
case R_SPARC_64:
|
|
|
|
location[0] = v >> 56;
|
|
|
|
location[1] = v >> 48;
|
|
|
|
location[2] = v >> 40;
|
|
|
|
location[3] = v >> 32;
|
|
|
|
location[4] = v >> 24;
|
|
|
|
location[5] = v >> 16;
|
|
|
|
location[6] = v >> 8;
|
|
|
|
location[7] = v >> 0;
|
|
|
|
break;
|
|
|
|
|
2008-12-27 07:37:24 +08:00
|
|
|
case R_SPARC_WDISP19:
|
|
|
|
v -= (Elf_Addr) location;
|
|
|
|
*loc32 = (*loc32 & ~0x7ffff) |
|
|
|
|
((v >> 2) & 0x7ffff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_OLO10:
|
|
|
|
*loc32 = (*loc32 & ~0x1fff) |
|
|
|
|
(((v & 0x3ff) +
|
|
|
|
(ELF_R_TYPE(rel[i].r_info) >> 8))
|
|
|
|
& 0x1fff);
|
|
|
|
break;
|
|
|
|
#endif /* CONFIG_SPARC64 */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case R_SPARC_32:
|
2008-12-27 07:38:17 +08:00
|
|
|
case R_SPARC_UA32:
|
2005-04-17 06:20:36 +08:00
|
|
|
location[0] = v >> 24;
|
|
|
|
location[1] = v >> 16;
|
|
|
|
location[2] = v >> 8;
|
|
|
|
location[3] = v >> 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_WDISP30:
|
2008-12-27 07:36:29 +08:00
|
|
|
v -= (Elf_Addr) location;
|
2005-04-17 06:20:36 +08:00
|
|
|
*loc32 = (*loc32 & ~0x3fffffff) |
|
|
|
|
((v >> 2) & 0x3fffffff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_WDISP22:
|
2008-12-27 07:36:29 +08:00
|
|
|
v -= (Elf_Addr) location;
|
2005-04-17 06:20:36 +08:00
|
|
|
*loc32 = (*loc32 & ~0x3fffff) |
|
|
|
|
((v >> 2) & 0x3fffff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_LO10:
|
|
|
|
*loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_HI22:
|
|
|
|
*loc32 = (*loc32 & ~0x3fffff) |
|
|
|
|
((v >> 10) & 0x3fffff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "module %s: Unknown relocation: %x\n",
|
|
|
|
me->name,
|
2008-12-27 07:36:29 +08:00
|
|
|
(int) (ELF_R_TYPE(rel[i].r_info) & 0xff));
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOEXEC;
|
2011-06-03 22:45:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-27 07:37:24 +08:00
|
|
|
#ifdef CONFIG_SPARC64
|
2011-11-18 14:44:58 +08:00
|
|
|
static void do_patch_sections(const Elf_Ehdr *hdr,
|
|
|
|
const Elf_Shdr *sechdrs)
|
|
|
|
{
|
|
|
|
const Elf_Shdr *s, *sun4v_1insn = NULL, *sun4v_2insn = NULL;
|
|
|
|
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
|
|
|
|
|
|
|
|
for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
|
|
|
|
if (!strcmp(".sun4v_1insn_patch", secstrings + s->sh_name))
|
|
|
|
sun4v_1insn = s;
|
|
|
|
if (!strcmp(".sun4v_2insn_patch", secstrings + s->sh_name))
|
|
|
|
sun4v_2insn = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sun4v_1insn && tlb_type == hypervisor) {
|
|
|
|
void *p = (void *) sun4v_1insn->sh_addr;
|
|
|
|
sun4v_patch_1insn_range(p, p + sun4v_1insn->sh_size);
|
|
|
|
}
|
|
|
|
if (sun4v_2insn && tlb_type == hypervisor) {
|
|
|
|
void *p = (void *) sun4v_2insn->sh_addr;
|
|
|
|
sun4v_patch_2insn_range(p, p + sun4v_2insn->sh_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int module_finalize(const Elf_Ehdr *hdr,
|
|
|
|
const Elf_Shdr *sechdrs,
|
|
|
|
struct module *me)
|
|
|
|
{
|
2010-09-17 23:09:25 +08:00
|
|
|
/* make jump label nops */
|
|
|
|
jump_label_apply_nops(me);
|
|
|
|
|
2011-11-18 14:44:58 +08:00
|
|
|
do_patch_sections(hdr, sechdrs);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Cheetah's I-cache is fully coherent. */
|
|
|
|
if (tlb_type == spitfire) {
|
|
|
|
unsigned long va;
|
|
|
|
|
|
|
|
flushw_all();
|
|
|
|
for (va = 0; va < (PAGE_SIZE << 1); va += 32)
|
|
|
|
spitfire_put_icache_tag(va, 0x0);
|
|
|
|
__asm__ __volatile__("flush %g6");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-27 07:37:24 +08:00
|
|
|
#endif /* CONFIG_SPARC64 */
|