blob: b36537a5f43e33e3a1a6cc9907efcf3920e8d583 [file] [log] [blame]
Jan Glauber305b1522011-03-15 17:08:22 +01001/*
2 * Copyright IBM Corp. 2011
3 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
4 */
5#include <linux/module.h>
6#include <linux/mm.h>
7#include <linux/hugetlb.h>
Martin Schwidefsky638ad342011-10-30 15:17:13 +01008#include <asm/cacheflush.h>
Jan Glauber305b1522011-03-15 17:08:22 +01009#include <asm/pgtable.h>
10
11static void change_page_attr(unsigned long addr, int numpages,
12 pte_t (*set) (pte_t))
13{
14 pte_t *ptep, pte;
15 pmd_t *pmdp;
16 pud_t *pudp;
17 pgd_t *pgdp;
18 int i;
19
20 for (i = 0; i < numpages; i++) {
21 pgdp = pgd_offset(&init_mm, addr);
22 pudp = pud_offset(pgdp, addr);
23 pmdp = pmd_offset(pudp, addr);
24 if (pmd_huge(*pmdp)) {
25 WARN_ON_ONCE(1);
26 continue;
27 }
Jan Glaubere4c031b2011-04-20 10:15:32 +020028 ptep = pte_offset_kernel(pmdp, addr);
Jan Glauber305b1522011-03-15 17:08:22 +010029
30 pte = *ptep;
31 pte = set(pte);
Martin Schwidefskyb2fa47e2011-05-23 10:24:40 +020032 __ptep_ipte(addr, ptep);
Jan Glauber305b1522011-03-15 17:08:22 +010033 *ptep = pte;
Jan Glaubere4c031b2011-04-20 10:15:32 +020034 addr += PAGE_SIZE;
Jan Glauber305b1522011-03-15 17:08:22 +010035 }
36}
37
38int set_memory_ro(unsigned long addr, int numpages)
39{
40 change_page_attr(addr, numpages, pte_wrprotect);
41 return 0;
42}
43EXPORT_SYMBOL_GPL(set_memory_ro);
44
45int set_memory_rw(unsigned long addr, int numpages)
46{
47 change_page_attr(addr, numpages, pte_mkwrite);
48 return 0;
49}
50EXPORT_SYMBOL_GPL(set_memory_rw);
51
52/* not possible */
53int set_memory_nx(unsigned long addr, int numpages)
54{
55 return 0;
56}
57EXPORT_SYMBOL_GPL(set_memory_nx);
Jan Glauber448694a2011-05-19 16:55:26 -060058
59int set_memory_x(unsigned long addr, int numpages)
60{
61 return 0;
62}