2011-03-16 00:08:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 2011
|
|
|
|
* Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/hugetlb.h>
|
2011-10-30 22:17:13 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2011-03-16 00:08:22 +08:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
|
2012-10-01 22:18:46 +08:00
|
|
|
static pte_t *walk_page_table(unsigned long addr)
|
|
|
|
{
|
|
|
|
pgd_t *pgdp;
|
|
|
|
pud_t *pudp;
|
|
|
|
pmd_t *pmdp;
|
|
|
|
pte_t *ptep;
|
|
|
|
|
|
|
|
pgdp = pgd_offset_k(addr);
|
|
|
|
if (pgd_none(*pgdp))
|
|
|
|
return NULL;
|
|
|
|
pudp = pud_offset(pgdp, addr);
|
|
|
|
if (pud_none(*pudp))
|
|
|
|
return NULL;
|
|
|
|
pmdp = pmd_offset(pudp, addr);
|
|
|
|
if (pmd_none(*pmdp) || pmd_large(*pmdp))
|
|
|
|
return NULL;
|
|
|
|
ptep = pte_offset_kernel(pmdp, addr);
|
|
|
|
if (pte_none(*ptep))
|
|
|
|
return NULL;
|
|
|
|
return ptep;
|
|
|
|
}
|
|
|
|
|
2011-03-16 00:08:22 +08:00
|
|
|
static void change_page_attr(unsigned long addr, int numpages,
|
|
|
|
pte_t (*set) (pte_t))
|
|
|
|
{
|
|
|
|
pte_t *ptep, pte;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numpages; i++) {
|
2012-10-01 22:18:46 +08:00
|
|
|
ptep = walk_page_table(addr);
|
|
|
|
if (WARN_ON_ONCE(!ptep))
|
|
|
|
break;
|
2011-03-16 00:08:22 +08:00
|
|
|
pte = *ptep;
|
|
|
|
pte = set(pte);
|
2011-05-23 16:24:40 +08:00
|
|
|
__ptep_ipte(addr, ptep);
|
2011-03-16 00:08:22 +08:00
|
|
|
*ptep = pte;
|
2011-04-20 16:15:32 +08:00
|
|
|
addr += PAGE_SIZE;
|
2011-03-16 00:08:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_memory_ro(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
change_page_attr(addr, numpages, pte_wrprotect);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_memory_rw(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
change_page_attr(addr, numpages, pte_mkwrite);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not possible */
|
|
|
|
int set_memory_nx(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-20 06:55:26 +08:00
|
|
|
|
|
|
|
int set_memory_x(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|