cregit-Linux how code gets into the kernel

Release 4.14 arch/um/kernel/mem.c

Directory: arch/um/kernel
/*
 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 * Licensed under the GPL
 */

#include <linux/stddef.h>
#include <linux/module.h>
#include <linux/bootmem.h>
#include <linux/highmem.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/slab.h>
#include <asm/fixmap.h>
#include <asm/page.h>
#include <as-layout.h>
#include <init.h>
#include <kern.h>
#include <kern_util.h>
#include <mem_user.h>
#include <os.h>

/* allocated in paging_init, zeroed in mem_init, and unchanged thereafter */

unsigned long *empty_zero_page = NULL;

EXPORT_SYMBOL(empty_zero_page);
/* allocated in paging_init and unchanged thereafter */

static unsigned long *empty_bad_page = NULL;

/*
 * Initialized during boot, and readonly for initializing page tables
 * afterwards
 */

pgd_t swapper_pg_dir[PTRS_PER_PGD];

/* Initialized at boot time, and readonly after that */

unsigned long long highmem;

int kmalloc_ok = 0;

/* Used during early boot */

static unsigned long brk_end;


void __init mem_init(void) { /* clear the zero-page */ memset(empty_zero_page, 0, PAGE_SIZE); /* Map in the area just after the brk now that kmalloc is about * to be turned on. */ brk_end = (unsigned long) UML_ROUND_UP(sbrk(0)); map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0); free_bootmem(__pa(brk_end), uml_reserved - brk_end); uml_reserved = brk_end; /* this will put all low memory onto the freelists */ free_all_bootmem(); max_low_pfn = totalram_pages; max_pfn = totalram_pages; mem_init_print_info(NULL); kmalloc_ok = 1; }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike7785.56%562.50%
Paolo 'Blaisorblade' Giarrusso77.78%112.50%
Jason Lunz44.44%112.50%
Jiang Liu22.22%112.50%
Total90100.00%8100.00%

/* * Create a page table and place a pointer to it in a middle page * directory entry. */
static void __init one_page_table_init(pmd_t *pmd) { if (pmd_none(*pmd)) { pte_t *pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); set_pmd(pmd, __pmd(_KERNPG_TABLE + (unsigned long) __pa(pte))); if (pte != pte_offset_kernel(pmd, 0)) BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike67100.00%1100.00%
Total67100.00%1100.00%


static void __init one_md_table_init(pud_t *pud) { #ifdef CONFIG_3_LEVEL_PGTABLES pmd_t *pmd_table = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE); set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table))); if (pmd_table != pmd_offset(pud, 0)) BUG(); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike62100.00%1100.00%
Total62100.00%1100.00%


static void __init fixrange_init(unsigned long start, unsigned long end, pgd_t *pgd_base) { pgd_t *pgd; pud_t *pud; pmd_t *pmd; int i, j; unsigned long vaddr; vaddr = start; i = pgd_index(vaddr); j = pmd_index(vaddr); pgd = pgd_base + i; for ( ; (i < PTRS_PER_PGD) && (vaddr < end); pgd++, i++) { pud = pud_offset(pgd, vaddr); if (pud_none(*pud)) one_md_table_init(pud); pmd = pmd_offset(pud, vaddr); for (; (j < PTRS_PER_PMD) && (vaddr < end); pmd++, j++) { one_page_table_init(pmd); vaddr += PMD_SIZE; } j = 0; } }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike15298.70%360.00%
Andrew Morton21.30%240.00%
Total154100.00%5100.00%


static void __init fixaddr_user_init( void) { #ifdef CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA long size = FIXADDR_USER_END - FIXADDR_USER_START; pgd_t *pgd; pud_t *pud; pmd_t *pmd; pte_t *pte; phys_t p; unsigned long v, vaddr = FIXADDR_USER_START; if (!size) return; fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir); v = (unsigned long) alloc_bootmem_low_pages(size); memcpy((void *) v , (void *) FIXADDR_USER_START, size); p = __pa(v); for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE, p += PAGE_SIZE) { pgd = swapper_pg_dir + pgd_index(vaddr); pud = pud_offset(pgd, vaddr); pmd = pmd_offset(pud, vaddr); pte = pte_offset_kernel(pmd, vaddr); pte_set_val(*pte, p, PAGE_READONLY); } #endif }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike16398.79%480.00%
Al Viro21.21%120.00%
Total165100.00%5100.00%


void __init paging_init(void) { unsigned long zones_size[MAX_NR_ZONES], vaddr; int i; empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); for (i = 0; i < ARRAY_SIZE(zones_size); i++) zones_size[i] = 0; zones_size[ZONE_NORMAL] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT); free_area_init(zones_size); /* * Fixed mappings, only the page table structure has to be * created - mappings will be set by set_fixmap(): */ vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK; fixrange_init(vaddr, FIXADDR_TOP, swapper_pg_dir); fixaddr_user_init(); }

Contributors

PersonTokensPropCommitsCommitProp
Paolo 'Blaisorblade' Giarrusso7869.03%114.29%
Jeff Dike3530.97%685.71%
Total113100.00%7100.00%

/* * This can't do anything because nothing in the kernel image can be freed * since it's not in kernel physical memory. */
void free_initmem(void) { }

Contributors

PersonTokensPropCommitsCommitProp
Paolo 'Blaisorblade' Giarrusso6100.00%1100.00%
Total6100.00%1100.00%

#ifdef CONFIG_BLK_DEV_INITRD
void free_initrd_mem(unsigned long start, unsigned long end) { free_reserved_area((void *)start, (void *)end, -1, "initrd"); }

Contributors

PersonTokensPropCommitsCommitProp
Jiang Liu1545.45%360.00%
Paolo 'Blaisorblade' Giarrusso1133.33%120.00%
Jeff Dike721.21%120.00%
Total33100.00%5100.00%

#endif /* Allocate and free page tables. */
pgd_t *pgd_alloc(struct mm_struct *mm) { pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL); if (pgd) { memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); memcpy(pgd + USER_PTRS_PER_PGD, swapper_pg_dir + USER_PTRS_PER_PGD, (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); } return pgd; }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike69100.00%1100.00%
Total69100.00%1100.00%


void pgd_free(struct mm_struct *mm, pgd_t *pgd) { free_page((unsigned long) pgd); }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike1878.26%150.00%
Benjamin Herrenschmidt521.74%150.00%
Total23100.00%2100.00%


pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address) { pte_t *pte; pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); return pte; }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike3394.29%133.33%
Christoph Lameter12.86%133.33%
Andrew Morton12.86%133.33%
Total35100.00%3100.00%


pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address) { struct page *pte; pte = alloc_page(GFP_KERNEL|__GFP_ZERO); if (!pte) return NULL; if (!pgtable_page_ctor(pte)) { __free_page(pte); return NULL; } return pte; }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike2849.12%233.33%
Kirill A. Shutemov1729.82%116.67%
Martin Schwidefsky1017.54%116.67%
Christoph Lameter11.75%116.67%
Andrew Morton11.75%116.67%
Total57100.00%6100.00%

#ifdef CONFIG_3_LEVEL_PGTABLES
pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) { pmd_t *pmd = (pmd_t *) __get_free_page(GFP_KERNEL); if (pmd) memset(pmd, 0, PAGE_SIZE); return pmd; }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike44100.00%1100.00%
Total44100.00%1100.00%

#endif
void *uml_kmalloc(int size, int flags) { return kmalloc(size, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike20100.00%1100.00%
Total20100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Jeff Dike85281.69%2457.14%
Paolo 'Blaisorblade' Giarrusso11110.64%12.38%
Jiang Liu171.63%49.52%
Kirill A. Shutemov171.63%12.38%
Al Viro161.53%37.14%
Martin Schwidefsky100.96%12.38%
Benjamin Herrenschmidt50.48%12.38%
Andrew Morton40.38%37.14%
Jason Lunz40.38%12.38%
Tejun Heo40.38%12.38%
Christoph Lameter20.19%12.38%
Américo Wang10.10%12.38%
Total1043100.00%42100.00%
Directory: arch/um/kernel
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.