]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/arm/mm/pageattr.c
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
6 #include <linux/module.h>
8 #include <asm/tlbflush.h>
9 #include <asm/set_memory.h>
11 struct page_change_data
{
16 static int change_page_range(pte_t
*ptep
, unsigned long addr
, void *data
)
18 struct page_change_data
*cdata
= data
;
21 pte
= clear_pte_bit(pte
, cdata
->clear_mask
);
22 pte
= set_pte_bit(pte
, cdata
->set_mask
);
24 set_pte_ext(ptep
, pte
, 0);
28 static bool in_range(unsigned long start
, unsigned long size
,
29 unsigned long range_start
, unsigned long range_end
)
31 return start
>= range_start
&& start
< range_end
&&
32 size
<= range_end
- start
;
35 static int change_memory_common(unsigned long addr
, int numpages
,
36 pgprot_t set_mask
, pgprot_t clear_mask
)
38 unsigned long start
= addr
& PAGE_MASK
;
39 unsigned long end
= PAGE_ALIGN(addr
) + numpages
* PAGE_SIZE
;
40 unsigned long size
= end
- start
;
42 struct page_change_data data
;
44 WARN_ON_ONCE(start
!= addr
);
49 if (!in_range(start
, size
, MODULES_VADDR
, MODULES_END
) &&
50 !in_range(start
, size
, VMALLOC_START
, VMALLOC_END
))
53 data
.set_mask
= set_mask
;
54 data
.clear_mask
= clear_mask
;
56 ret
= apply_to_page_range(&init_mm
, start
, size
, change_page_range
,
59 flush_tlb_kernel_range(start
, end
);
63 int set_memory_ro(unsigned long addr
, int numpages
)
65 return change_memory_common(addr
, numpages
,
66 __pgprot(L_PTE_RDONLY
),
70 int set_memory_rw(unsigned long addr
, int numpages
)
72 return change_memory_common(addr
, numpages
,
74 __pgprot(L_PTE_RDONLY
));
77 int set_memory_nx(unsigned long addr
, int numpages
)
79 return change_memory_common(addr
, numpages
,
84 int set_memory_x(unsigned long addr
, int numpages
)
86 return change_memory_common(addr
, numpages
,