mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-17 23:52:26 +01:00
Patch series "mm: consolidate definitions of page table accessors", v2.
The low level page table accessors (pXY_index(), pXY_offset()) are
duplicated across all architectures and sometimes more than once. For
instance, we have 31 definition of pgd_offset() for 25 supported
architectures.
Most of these definitions are actually identical and typically it boils
down to, e.g.
static inline unsigned long pmd_index(unsigned long address)
{
return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
}
static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
{
return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
}
These definitions can be shared among 90% of the arches provided
XYZ_SHIFT, PTRS_PER_XYZ and xyz_page_vaddr() are defined.
For architectures that really need a custom version there is always
possibility to override the generic version with the usual ifdefs magic.
These patches introduce include/linux/pgtable.h that replaces
include/asm-generic/pgtable.h and add the definitions of the page table
accessors to the new header.
This patch (of 12):
The linux/mm.h header includes <asm/pgtable.h> to allow inlining of the
functions involving page table manipulations, e.g. pte_alloc() and
pmd_alloc(). So, there is no point to explicitly include <asm/pgtable.h>
in the files that include <linux/mm.h>.
The include statements in such cases are remove with a simple loop:
for f in $(git grep -l "include <linux/mm.h>") ; do
sed -i -e '/include <asm\/pgtable.h>/ d' $f
done
Signed-off-by: Mike Rapoport <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Cain <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Greentime Hu <[email protected]>
Cc: Greg Ungerer <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Guo Ren <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Ley Foon Tan <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Nick Hu <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: Russell King <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Thomas Bogendoerfer <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Vincent Chen <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
106 lines
2.5 KiB
C
106 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/arch/unicore32/kernel/module.c
|
|
*
|
|
* Code specific to PKUnity SoC and UniCore ISA
|
|
*
|
|
* Copyright (C) 2001-2010 GUAN Xue-tao
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/moduleloader.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/elf.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/string.h>
|
|
#include <linux/gfp.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
void *module_alloc(unsigned long size)
|
|
{
|
|
return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
|
|
GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
|
|
__builtin_return_address(0));
|
|
}
|
|
|
|
int
|
|
apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
|
|
unsigned int relindex, struct module *module)
|
|
{
|
|
Elf32_Shdr *symsec = sechdrs + symindex;
|
|
Elf32_Shdr *relsec = sechdrs + relindex;
|
|
Elf32_Shdr *dstsec = sechdrs + relsec->sh_info;
|
|
Elf32_Rel *rel = (void *)relsec->sh_addr;
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++, rel++) {
|
|
unsigned long loc;
|
|
Elf32_Sym *sym;
|
|
s32 offset;
|
|
|
|
offset = ELF32_R_SYM(rel->r_info);
|
|
if (offset < 0 || offset >
|
|
(symsec->sh_size / sizeof(Elf32_Sym))) {
|
|
printk(KERN_ERR "%s: bad relocation, "
|
|
"section %d reloc %d\n",
|
|
module->name, relindex, i);
|
|
return -ENOEXEC;
|
|
}
|
|
|
|
sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
|
|
|
|
if (rel->r_offset < 0 || rel->r_offset >
|
|
dstsec->sh_size - sizeof(u32)) {
|
|
printk(KERN_ERR "%s: out of bounds relocation, "
|
|
"section %d reloc %d offset %d size %d\n",
|
|
module->name, relindex, i, rel->r_offset,
|
|
dstsec->sh_size);
|
|
return -ENOEXEC;
|
|
}
|
|
|
|
loc = dstsec->sh_addr + rel->r_offset;
|
|
|
|
switch (ELF32_R_TYPE(rel->r_info)) {
|
|
case R_UNICORE_NONE:
|
|
/* ignore */
|
|
break;
|
|
|
|
case R_UNICORE_ABS32:
|
|
*(u32 *)loc += sym->st_value;
|
|
break;
|
|
|
|
case R_UNICORE_PC24:
|
|
case R_UNICORE_CALL:
|
|
case R_UNICORE_JUMP24:
|
|
offset = (*(u32 *)loc & 0x00ffffff) << 2;
|
|
if (offset & 0x02000000)
|
|
offset -= 0x04000000;
|
|
|
|
offset += sym->st_value - loc;
|
|
if (offset & 3 ||
|
|
offset <= (s32)0xfe000000 ||
|
|
offset >= (s32)0x02000000) {
|
|
printk(KERN_ERR
|
|
"%s: relocation out of range, section "
|
|
"%d reloc %d sym '%s'\n", module->name,
|
|
relindex, i, strtab + sym->st_name);
|
|
return -ENOEXEC;
|
|
}
|
|
|
|
offset >>= 2;
|
|
|
|
*(u32 *)loc &= 0xff000000;
|
|
*(u32 *)loc |= offset & 0x00ffffff;
|
|
break;
|
|
|
|
default:
|
|
printk(KERN_ERR "%s: unknown relocation: %u\n",
|
|
module->name, ELF32_R_TYPE(rel->r_info));
|
|
return -ENOEXEC;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|