Skip to content

Commit 5a9e3e1

Browse files
Jisheng Zhangwildea01
authored andcommitted
arm64: apply __ro_after_init to some objects
These objects are set during initialization, thereafter are read only. Previously I only want to mark vdso_pages, vdso_spec, vectors_page and cpu_ops as __read_mostly from performance point of view. Then inspired by Kees's patch[1] to apply more __ro_after_init for arm, I think it's better to mark them as __ro_after_init. What's more, I find some more objects are also read only after init. So apply __ro_after_init to all of them. This patch also removes global vdso_pagelist and tries to clean up vdso_spec[] assignment code. [1] http://www.spinics.net/lists/arm-kernel/msg523188.html Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Jisheng Zhang <jszhang@marvell.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent b6d081b commit 5a9e3e1

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

arch/arm64/kernel/cpu_ops.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <linux/acpi.h>
20+
#include <linux/cache.h>
2021
#include <linux/errno.h>
2122
#include <linux/of.h>
2223
#include <linux/string.h>
@@ -28,7 +29,7 @@ extern const struct cpu_operations smp_spin_table_ops;
2829
extern const struct cpu_operations acpi_parking_protocol_ops;
2930
extern const struct cpu_operations cpu_psci_ops;
3031

31-
const struct cpu_operations *cpu_ops[NR_CPUS];
32+
const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
3233

3334
static const struct cpu_operations *dt_supported_cpu_ops[] __initconst = {
3435
&smp_spin_table_ops,

arch/arm64/kernel/kaslr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* published by the Free Software Foundation.
77
*/
88

9+
#include <linux/cache.h>
910
#include <linux/crc32.h>
1011
#include <linux/init.h>
1112
#include <linux/libfdt.h>
@@ -20,7 +21,7 @@
2021
#include <asm/pgtable.h>
2122
#include <asm/sections.h>
2223

23-
u64 __read_mostly module_alloc_base;
24+
u64 __ro_after_init module_alloc_base;
2425
u16 __initdata memstart_offset_seed;
2526

2627
static __init u64 get_kaslr_seed(void *fdt)

arch/arm64/kernel/vdso.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
* Author: Will Deacon <will.deacon@arm.com>
1919
*/
2020

21-
#include <linux/kernel.h>
21+
#include <linux/cache.h>
2222
#include <linux/clocksource.h>
2323
#include <linux/elf.h>
2424
#include <linux/err.h>
2525
#include <linux/errno.h>
2626
#include <linux/gfp.h>
27+
#include <linux/kernel.h>
2728
#include <linux/mm.h>
2829
#include <linux/sched.h>
2930
#include <linux/signal.h>
@@ -37,8 +38,7 @@
3738
#include <asm/vdso_datapage.h>
3839

3940
extern char vdso_start, vdso_end;
40-
static unsigned long vdso_pages;
41-
static struct page **vdso_pagelist;
41+
static unsigned long vdso_pages __ro_after_init;
4242

4343
/*
4444
* The vDSO data page.
@@ -53,7 +53,7 @@ struct vdso_data *vdso_data = &vdso_data_store.data;
5353
/*
5454
* Create and map the vectors page for AArch32 tasks.
5555
*/
56-
static struct page *vectors_page[1];
56+
static struct page *vectors_page[1] __ro_after_init;
5757

5858
static int __init alloc_vectors_page(void)
5959
{
@@ -110,11 +110,19 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
110110
}
111111
#endif /* CONFIG_COMPAT */
112112

113-
static struct vm_special_mapping vdso_spec[2];
113+
static struct vm_special_mapping vdso_spec[2] __ro_after_init = {
114+
{
115+
.name = "[vvar]",
116+
},
117+
{
118+
.name = "[vdso]",
119+
},
120+
};
114121

115122
static int __init vdso_init(void)
116123
{
117124
int i;
125+
struct page **vdso_pagelist;
118126

119127
if (memcmp(&vdso_start, "\177ELF", 4)) {
120128
pr_err("vDSO is not a valid ELF object!\n");
@@ -138,16 +146,8 @@ static int __init vdso_init(void)
138146
for (i = 0; i < vdso_pages; i++)
139147
vdso_pagelist[i + 1] = pfn_to_page(PHYS_PFN(__pa(&vdso_start)) + i);
140148

141-
/* Populate the special mapping structures */
142-
vdso_spec[0] = (struct vm_special_mapping) {
143-
.name = "[vvar]",
144-
.pages = vdso_pagelist,
145-
};
146-
147-
vdso_spec[1] = (struct vm_special_mapping) {
148-
.name = "[vdso]",
149-
.pages = &vdso_pagelist[1],
150-
};
149+
vdso_spec[0].pages = &vdso_pagelist[0];
150+
vdso_spec[1].pages = &vdso_pagelist[1];
151151

152152
return 0;
153153
}

arch/arm64/mm/dma-mapping.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/gfp.h>
2121
#include <linux/acpi.h>
2222
#include <linux/bootmem.h>
23+
#include <linux/cache.h>
2324
#include <linux/export.h>
2425
#include <linux/slab.h>
2526
#include <linux/genalloc.h>
@@ -30,7 +31,7 @@
3031

3132
#include <asm/cacheflush.h>
3233

33-
static int swiotlb __read_mostly;
34+
static int swiotlb __ro_after_init;
3435

3536
static pgprot_t __get_dma_pgprot(unsigned long attrs, pgprot_t prot,
3637
bool coherent)

arch/arm64/mm/init.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/swap.h>
2424
#include <linux/init.h>
2525
#include <linux/bootmem.h>
26+
#include <linux/cache.h>
2627
#include <linux/mman.h>
2728
#include <linux/nodemask.h>
2829
#include <linux/initrd.h>
@@ -55,8 +56,8 @@
5556
* executes, which assigns it its actual value. So use a default value
5657
* that cannot be mistaken for a real physical address.
5758
*/
58-
s64 memstart_addr __read_mostly = -1;
59-
phys_addr_t arm64_dma_phys_limit __read_mostly;
59+
s64 memstart_addr __ro_after_init = -1;
60+
phys_addr_t arm64_dma_phys_limit __ro_after_init;
6061

6162
#ifdef CONFIG_BLK_DEV_INITRD
6263
static int __init early_initrd(char *p)

arch/arm64/mm/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
#include <linux/cache.h>
2021
#include <linux/export.h>
2122
#include <linux/kernel.h>
2223
#include <linux/errno.h>
@@ -46,7 +47,7 @@
4647

4748
u64 idmap_t0sz = TCR_T0SZ(VA_BITS);
4849

49-
u64 kimage_voffset __read_mostly;
50+
u64 kimage_voffset __ro_after_init;
5051
EXPORT_SYMBOL(kimage_voffset);
5152

5253
/*

0 commit comments

Comments
 (0)