pageattr.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  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>
  8. #include <asm/pgtable.h>
  9. static void change_page_attr(unsigned long addr, int numpages,
  10. pte_t (*set) (pte_t))
  11. {
  12. pte_t *ptep, pte;
  13. pmd_t *pmdp;
  14. pud_t *pudp;
  15. pgd_t *pgdp;
  16. int i;
  17. for (i = 0; i < numpages; i++) {
  18. pgdp = pgd_offset(&init_mm, addr);
  19. pudp = pud_offset(pgdp, addr);
  20. pmdp = pmd_offset(pudp, addr);
  21. if (pmd_huge(*pmdp)) {
  22. WARN_ON_ONCE(1);
  23. continue;
  24. }
  25. ptep = pte_offset_kernel(pmdp, addr);
  26. pte = *ptep;
  27. pte = set(pte);
  28. __ptep_ipte(addr, ptep);
  29. *ptep = pte;
  30. addr += PAGE_SIZE;
  31. }
  32. }
  33. int set_memory_ro(unsigned long addr, int numpages)
  34. {
  35. change_page_attr(addr, numpages, pte_wrprotect);
  36. return 0;
  37. }
  38. EXPORT_SYMBOL_GPL(set_memory_ro);
  39. int set_memory_rw(unsigned long addr, int numpages)
  40. {
  41. change_page_attr(addr, numpages, pte_mkwrite);
  42. return 0;
  43. }
  44. EXPORT_SYMBOL_GPL(set_memory_rw);
  45. /* not possible */
  46. int set_memory_nx(unsigned long addr, int numpages)
  47. {
  48. return 0;
  49. }
  50. EXPORT_SYMBOL_GPL(set_memory_nx);
  51. int set_memory_x(unsigned long addr, int numpages)
  52. {
  53. return 0;
  54. }