Commit 72932c7a authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

x86: cpa move the flush into set and clear functions

To avoid the modification of the flush code for the clflush
implementation, move the flush into the set and clear functions and
provide helper functions for the debugging code.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent edeed305
...@@ -162,7 +162,7 @@ static __init int exercise_pageattr(void) ...@@ -162,7 +162,7 @@ static __init int exercise_pageattr(void)
continue; continue;
} }
err = change_page_attr_clear(addr[i], len[i], err = __change_page_attr_clear(addr[i], len[i],
__pgprot(_PAGE_GLOBAL)); __pgprot(_PAGE_GLOBAL));
if (err < 0) { if (err < 0) {
printk(KERN_ERR "CPA %d failed %d\n", i, err); printk(KERN_ERR "CPA %d failed %d\n", i, err);
...@@ -197,7 +197,7 @@ static __init int exercise_pageattr(void) ...@@ -197,7 +197,7 @@ static __init int exercise_pageattr(void)
failed++; failed++;
continue; continue;
} }
err = change_page_attr_set(addr[i], len[i], err = __change_page_attr_set(addr[i], len[i],
__pgprot(_PAGE_GLOBAL)); __pgprot(_PAGE_GLOBAL));
if (err < 0) { if (err < 0) {
printk(KERN_ERR "CPA reverting failed: %d\n", err); printk(KERN_ERR "CPA reverting failed: %d\n", err);
......
...@@ -301,7 +301,7 @@ static int change_page_attr_addr(unsigned long address, pgprot_t prot) ...@@ -301,7 +301,7 @@ static int change_page_attr_addr(unsigned long address, pgprot_t prot)
* This function is different from change_page_attr() in that only selected bits * This function is different from change_page_attr() in that only selected bits
* are impacted, all other bits remain as is. * are impacted, all other bits remain as is.
*/ */
static int change_page_attr_set(unsigned long addr, int numpages, static int __change_page_attr_set(unsigned long addr, int numpages,
pgprot_t prot) pgprot_t prot)
{ {
pgprot_t current_prot, new_prot; pgprot_t current_prot, new_prot;
...@@ -325,9 +325,19 @@ static int change_page_attr_set(unsigned long addr, int numpages, ...@@ -325,9 +325,19 @@ static int change_page_attr_set(unsigned long addr, int numpages,
return ret; return ret;
addr += PAGE_SIZE; addr += PAGE_SIZE;
} }
return 0; return 0;
} }
static int change_page_attr_set(unsigned long addr, int numpages, pgprot_t prot)
{
int ret = __change_page_attr_set(addr, numpages, prot);
global_flush_tlb();
return ret;
}
/** /**
* change_page_attr_clear - Change page table attributes in the linear mapping. * change_page_attr_clear - Change page table attributes in the linear mapping.
* @addr: Virtual address in linear mapping. * @addr: Virtual address in linear mapping.
...@@ -347,7 +357,7 @@ static int change_page_attr_set(unsigned long addr, int numpages, ...@@ -347,7 +357,7 @@ static int change_page_attr_set(unsigned long addr, int numpages,
* This function is different from change_page_attr() in that only selected bits * This function is different from change_page_attr() in that only selected bits
* are impacted, all other bits remain as is. * are impacted, all other bits remain as is.
*/ */
static int change_page_attr_clear(unsigned long addr, int numpages, static int __change_page_attr_clear(unsigned long addr, int numpages,
pgprot_t prot) pgprot_t prot)
{ {
pgprot_t current_prot, new_prot; pgprot_t current_prot, new_prot;
...@@ -371,81 +381,59 @@ static int change_page_attr_clear(unsigned long addr, int numpages, ...@@ -371,81 +381,59 @@ static int change_page_attr_clear(unsigned long addr, int numpages,
return ret; return ret;
addr += PAGE_SIZE; addr += PAGE_SIZE;
} }
return 0; return 0;
} }
int set_memory_uc(unsigned long addr, int numpages) static int change_page_attr_clear(unsigned long addr, int numpages,
pgprot_t prot)
{ {
int err; int ret = __change_page_attr_clear(addr, numpages, prot);
err = change_page_attr_set(addr, numpages,
__pgprot(_PAGE_PCD | _PAGE_PWT));
global_flush_tlb(); global_flush_tlb();
return err; return ret;
}
int set_memory_uc(unsigned long addr, int numpages)
{
return change_page_attr_set(addr, numpages,
__pgprot(_PAGE_PCD | _PAGE_PWT));
} }
EXPORT_SYMBOL(set_memory_uc); EXPORT_SYMBOL(set_memory_uc);
int set_memory_wb(unsigned long addr, int numpages) int set_memory_wb(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_clear(addr, numpages,
err = change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_PCD | _PAGE_PWT)); __pgprot(_PAGE_PCD | _PAGE_PWT));
global_flush_tlb();
return err;
} }
EXPORT_SYMBOL(set_memory_wb); EXPORT_SYMBOL(set_memory_wb);
int set_memory_x(unsigned long addr, int numpages) int set_memory_x(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_NX));
err = change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_NX));
global_flush_tlb();
return err;
} }
EXPORT_SYMBOL(set_memory_x); EXPORT_SYMBOL(set_memory_x);
int set_memory_nx(unsigned long addr, int numpages) int set_memory_nx(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_set(addr, numpages, __pgprot(_PAGE_NX));
err = change_page_attr_set(addr, numpages,
__pgprot(_PAGE_NX));
global_flush_tlb();
return err;
} }
EXPORT_SYMBOL(set_memory_nx); EXPORT_SYMBOL(set_memory_nx);
int set_memory_ro(unsigned long addr, int numpages) int set_memory_ro(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_RW));
err = change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_RW));
global_flush_tlb();
return err;
} }
int set_memory_rw(unsigned long addr, int numpages) int set_memory_rw(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_set(addr, numpages, __pgprot(_PAGE_RW));
err = change_page_attr_set(addr, numpages,
__pgprot(_PAGE_RW));
global_flush_tlb();
return err;
} }
int set_memory_np(unsigned long addr, int numpages) int set_memory_np(unsigned long addr, int numpages)
{ {
int err; return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_PRESENT));
err = change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_PRESENT));
global_flush_tlb();
return err;
} }
int set_pages_uc(struct page *page, int numpages) int set_pages_uc(struct page *page, int numpages)
...@@ -500,14 +488,17 @@ int set_pages_rw(struct page *page, int numpages) ...@@ -500,14 +488,17 @@ int set_pages_rw(struct page *page, int numpages)
static int __set_pages_p(struct page *page, int numpages) static int __set_pages_p(struct page *page, int numpages)
{ {
unsigned long addr = (unsigned long)page_address(page); unsigned long addr = (unsigned long)page_address(page);
return change_page_attr_set(addr, numpages,
return __change_page_attr_set(addr, numpages,
__pgprot(_PAGE_PRESENT | _PAGE_RW)); __pgprot(_PAGE_PRESENT | _PAGE_RW));
} }
static int __set_pages_np(struct page *page, int numpages) static int __set_pages_np(struct page *page, int numpages)
{ {
unsigned long addr = (unsigned long)page_address(page); unsigned long addr = (unsigned long)page_address(page);
return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_PRESENT));
return __change_page_attr_clear(addr, numpages,
__pgprot(_PAGE_PRESENT));
} }
void kernel_map_pages(struct page *page, int numpages, int enable) void kernel_map_pages(struct page *page, int numpages, int enable)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment