x86: clean up arch/x86/mm/pageattr_32.c
clean up arch/x86/mm/pageattr_32.c. no code changed: text data bss dec hex filename 1255 40 0 1295 50f pageattr_32.o.before 1255 40 0 1295 50f pageattr_32.o.after Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
@@ -3,26 +3,27 @@
|
|||||||
* Thanks to Ben LaHaise for precious feedback.
|
* Thanks to Ben LaHaise for precious feedback.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/mm.h>
|
|
||||||
#include <linux/sched.h>
|
|
||||||
#include <linux/highmem.h>
|
#include <linux/highmem.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/sched.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <asm/uaccess.h>
|
#include <linux/mm.h>
|
||||||
|
|
||||||
#include <asm/processor.h>
|
#include <asm/processor.h>
|
||||||
#include <asm/tlbflush.h>
|
#include <asm/tlbflush.h>
|
||||||
#include <asm/pgalloc.h>
|
|
||||||
#include <asm/sections.h>
|
#include <asm/sections.h>
|
||||||
|
#include <asm/uaccess.h>
|
||||||
|
#include <asm/pgalloc.h>
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(cpa_lock);
|
static DEFINE_SPINLOCK(cpa_lock);
|
||||||
static struct list_head df_list = LIST_HEAD_INIT(df_list);
|
static struct list_head df_list = LIST_HEAD_INIT(df_list);
|
||||||
|
|
||||||
|
|
||||||
pte_t *lookup_address(unsigned long address)
|
pte_t *lookup_address(unsigned long address)
|
||||||
{
|
{
|
||||||
pgd_t *pgd = pgd_offset_k(address);
|
pgd_t *pgd = pgd_offset_k(address);
|
||||||
pud_t *pud;
|
pud_t *pud;
|
||||||
pmd_t *pmd;
|
pmd_t *pmd;
|
||||||
|
|
||||||
if (pgd_none(*pgd))
|
if (pgd_none(*pgd))
|
||||||
return NULL;
|
return NULL;
|
||||||
pud = pud_offset(pgd, address);
|
pud = pud_offset(pgd, address);
|
||||||
@@ -33,16 +34,17 @@ pte_t *lookup_address(unsigned long address)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (pmd_large(*pmd))
|
if (pmd_large(*pmd))
|
||||||
return (pte_t *)pmd;
|
return (pte_t *)pmd;
|
||||||
|
|
||||||
return pte_offset_kernel(pmd, address);
|
return pte_offset_kernel(pmd, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct page *split_large_page(unsigned long address, pgprot_t prot,
|
static struct page *
|
||||||
pgprot_t ref_prot)
|
split_large_page(unsigned long address, pgprot_t prot, pgprot_t ref_prot)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
struct page *base;
|
struct page *base;
|
||||||
pte_t *pbase;
|
pte_t *pbase;
|
||||||
|
int i;
|
||||||
|
|
||||||
spin_unlock_irq(&cpa_lock);
|
spin_unlock_irq(&cpa_lock);
|
||||||
base = alloc_pages(GFP_KERNEL, 0);
|
base = alloc_pages(GFP_KERNEL, 0);
|
||||||
@@ -61,6 +63,7 @@ static struct page *split_large_page(unsigned long address, pgprot_t prot,
|
|||||||
addr = address & LARGE_PAGE_MASK;
|
addr = address & LARGE_PAGE_MASK;
|
||||||
pbase = (pte_t *)page_address(base);
|
pbase = (pte_t *)page_address(base);
|
||||||
paravirt_alloc_pt(&init_mm, page_to_pfn(base));
|
paravirt_alloc_pt(&init_mm, page_to_pfn(base));
|
||||||
|
|
||||||
for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) {
|
for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) {
|
||||||
set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT,
|
set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT,
|
||||||
addr == address ? prot : ref_prot));
|
addr == address ? prot : ref_prot));
|
||||||
@@ -70,10 +73,11 @@ static struct page *split_large_page(unsigned long address, pgprot_t prot,
|
|||||||
|
|
||||||
static void cache_flush_page(struct page *p)
|
static void cache_flush_page(struct page *p)
|
||||||
{
|
{
|
||||||
void *adr = page_address(p);
|
void *addr = page_address(p);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
|
for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
|
||||||
clflush(adr+i);
|
clflush(addr + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_kernel_map(void *arg)
|
static void flush_kernel_map(void *arg)
|
||||||
@@ -85,10 +89,13 @@ static void flush_kernel_map(void *arg)
|
|||||||
if (0 && cpu_has_clflush) {
|
if (0 && cpu_has_clflush) {
|
||||||
list_for_each_entry(p, lh, lru)
|
list_for_each_entry(p, lh, lru)
|
||||||
cache_flush_page(p);
|
cache_flush_page(p);
|
||||||
} else if (boot_cpu_data.x86_model >= 4)
|
} else {
|
||||||
|
if (boot_cpu_data.x86_model >= 4)
|
||||||
wbinvd();
|
wbinvd();
|
||||||
|
}
|
||||||
|
|
||||||
/* Flush all to work around Errata in early athlons regarding
|
/*
|
||||||
|
* Flush all to work around Errata in early athlons regarding
|
||||||
* large page flushing.
|
* large page flushing.
|
||||||
*/
|
*/
|
||||||
__flush_tlb_all();
|
__flush_tlb_all();
|
||||||
@@ -96,10 +103,11 @@ static void flush_kernel_map(void *arg)
|
|||||||
|
|
||||||
static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
|
static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
|
||||||
{
|
{
|
||||||
struct page *page;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
struct page *page;
|
||||||
|
|
||||||
set_pte_atomic(kpte, pte); /* change init_mm */
|
/* change init_mm */
|
||||||
|
set_pte_atomic(kpte, pte);
|
||||||
if (SHARED_KERNEL_PMD)
|
if (SHARED_KERNEL_PMD)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -108,6 +116,7 @@ static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
|
|||||||
pgd_t *pgd;
|
pgd_t *pgd;
|
||||||
pud_t *pud;
|
pud_t *pud;
|
||||||
pmd_t *pmd;
|
pmd_t *pmd;
|
||||||
|
|
||||||
pgd = (pgd_t *)page_address(page) + pgd_index(address);
|
pgd = (pgd_t *)page_address(page) + pgd_index(address);
|
||||||
pud = pud_offset(pgd, address);
|
pud = pud_offset(pgd, address);
|
||||||
pmd = pmd_offset(pud, address);
|
pmd = pmd_offset(pud, address);
|
||||||
@@ -117,8 +126,8 @@ static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No more special protections in this 2/4MB area - revert to a
|
* No more special protections in this 2/4MB area - revert to a large
|
||||||
* large page again.
|
* page again.
|
||||||
*/
|
*/
|
||||||
static inline void revert_page(struct page *kpte_page, unsigned long address)
|
static inline void revert_page(struct page *kpte_page, unsigned long address)
|
||||||
{
|
{
|
||||||
@@ -142,12 +151,11 @@ static inline void save_page(struct page *kpte_page)
|
|||||||
list_add(&kpte_page->lru, &df_list);
|
list_add(&kpte_page->lru, &df_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int __change_page_attr(struct page *page, pgprot_t prot)
|
||||||
__change_page_attr(struct page *page, pgprot_t prot)
|
|
||||||
{
|
{
|
||||||
pte_t *kpte;
|
|
||||||
unsigned long address;
|
|
||||||
struct page *kpte_page;
|
struct page *kpte_page;
|
||||||
|
unsigned long address;
|
||||||
|
pte_t *kpte;
|
||||||
|
|
||||||
BUG_ON(PageHighMem(page));
|
BUG_ON(PageHighMem(page));
|
||||||
address = (unsigned long)page_address(page);
|
address = (unsigned long)page_address(page);
|
||||||
@@ -155,6 +163,7 @@ __change_page_attr(struct page *page, pgprot_t prot)
|
|||||||
kpte = lookup_address(address);
|
kpte = lookup_address(address);
|
||||||
if (!kpte)
|
if (!kpte)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
kpte_page = virt_to_page(kpte);
|
kpte_page = virt_to_page(kpte);
|
||||||
BUG_ON(PageLRU(kpte_page));
|
BUG_ON(PageLRU(kpte_page));
|
||||||
BUG_ON(PageCompound(kpte_page));
|
BUG_ON(PageCompound(kpte_page));
|
||||||
@@ -163,8 +172,8 @@ __change_page_attr(struct page *page, pgprot_t prot)
|
|||||||
if (!pte_huge(*kpte)) {
|
if (!pte_huge(*kpte)) {
|
||||||
set_pte_atomic(kpte, mk_pte(page, prot));
|
set_pte_atomic(kpte, mk_pte(page, prot));
|
||||||
} else {
|
} else {
|
||||||
pgprot_t ref_prot;
|
|
||||||
struct page *split;
|
struct page *split;
|
||||||
|
pgprot_t ref_prot;
|
||||||
|
|
||||||
ref_prot =
|
ref_prot =
|
||||||
((address & LARGE_PAGE_MASK) < (unsigned long)&_etext)
|
((address & LARGE_PAGE_MASK) < (unsigned long)&_etext)
|
||||||
@@ -172,16 +181,19 @@ __change_page_attr(struct page *page, pgprot_t prot)
|
|||||||
split = split_large_page(address, prot, ref_prot);
|
split = split_large_page(address, prot, ref_prot);
|
||||||
if (!split)
|
if (!split)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
set_pmd_pte(kpte, address, mk_pte(split, ref_prot));
|
set_pmd_pte(kpte, address, mk_pte(split, ref_prot));
|
||||||
kpte_page = split;
|
kpte_page = split;
|
||||||
}
|
}
|
||||||
page_private(kpte_page)++;
|
page_private(kpte_page)++;
|
||||||
} else if (!pte_huge(*kpte)) {
|
} else {
|
||||||
|
if (!pte_huge(*kpte)) {
|
||||||
set_pte_atomic(kpte, mk_pte(page, PAGE_KERNEL));
|
set_pte_atomic(kpte, mk_pte(page, PAGE_KERNEL));
|
||||||
BUG_ON(page_private(kpte_page) == 0);
|
BUG_ON(page_private(kpte_page) == 0);
|
||||||
page_private(kpte_page)--;
|
page_private(kpte_page)--;
|
||||||
} else
|
} else
|
||||||
BUG();
|
BUG();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the pte was reserved, it means it was created at boot
|
* If the pte was reserved, it means it was created at boot
|
||||||
@@ -219,9 +231,8 @@ static inline void flush_map(struct list_head *l)
|
|||||||
*/
|
*/
|
||||||
int change_page_attr(struct page *page, int numpages, pgprot_t prot)
|
int change_page_attr(struct page *page, int numpages, pgprot_t prot)
|
||||||
{
|
{
|
||||||
int err = 0;
|
|
||||||
int i;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
int err = 0, i;
|
||||||
|
|
||||||
spin_lock_irqsave(&cpa_lock, flags);
|
spin_lock_irqsave(&cpa_lock, flags);
|
||||||
for (i = 0; i < numpages; i++, page++) {
|
for (i = 0; i < numpages; i++, page++) {
|
||||||
@@ -230,13 +241,15 @@ int change_page_attr(struct page *page, int numpages, pgprot_t prot)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&cpa_lock, flags);
|
spin_unlock_irqrestore(&cpa_lock, flags);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(change_page_attr);
|
||||||
|
|
||||||
void global_flush_tlb(void)
|
void global_flush_tlb(void)
|
||||||
{
|
{
|
||||||
struct list_head l;
|
|
||||||
struct page *pg, *next;
|
struct page *pg, *next;
|
||||||
|
struct list_head l;
|
||||||
|
|
||||||
BUG_ON(irqs_disabled());
|
BUG_ON(irqs_disabled());
|
||||||
|
|
||||||
@@ -253,26 +266,28 @@ void global_flush_tlb(void)
|
|||||||
__free_page(pg);
|
__free_page(pg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(global_flush_tlb);
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_PAGEALLOC
|
#ifdef CONFIG_DEBUG_PAGEALLOC
|
||||||
void kernel_map_pages(struct page *page, int numpages, int enable)
|
void kernel_map_pages(struct page *page, int numpages, int enable)
|
||||||
{
|
{
|
||||||
if (PageHighMem(page))
|
if (PageHighMem(page))
|
||||||
return;
|
return;
|
||||||
if (!enable)
|
if (!enable) {
|
||||||
debug_check_no_locks_freed(page_address(page),
|
debug_check_no_locks_freed(page_address(page),
|
||||||
numpages * PAGE_SIZE);
|
numpages * PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/* the return value is ignored - the calls cannot fail,
|
/*
|
||||||
|
* the return value is ignored - the calls cannot fail,
|
||||||
* large pages are disabled at boot time.
|
* large pages are disabled at boot time.
|
||||||
*/
|
*/
|
||||||
change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0));
|
change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0));
|
||||||
/* we should perform an IPI and flush all tlbs,
|
|
||||||
|
/*
|
||||||
|
* we should perform an IPI and flush all tlbs,
|
||||||
* but that can deadlock->flush only current cpu.
|
* but that can deadlock->flush only current cpu.
|
||||||
*/
|
*/
|
||||||
__flush_tlb_all();
|
__flush_tlb_all();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EXPORT_SYMBOL(change_page_attr);
|
|
||||||
EXPORT_SYMBOL(global_flush_tlb);
|
|
||||||
|
Reference in New Issue
Block a user