Skip to content

Commit e120d1b

Browse files
rpptakpm00
authored andcommitted
arch, mm: set high_memory in free_area_init()
high_memory defines upper bound on the directly mapped memory. This bound is defined by the beginning of ZONE_HIGHMEM when a system has high memory and by the end of memory otherwise. All this is known to generic memory management initialization code that can set high_memory while initializing core mm structures. Add a generic calculation of high_memory to free_area_init() and remove per-architecture calculation except for the architectures that set and use high_memory earlier than that. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Acked-by: Dave Hansen <[email protected]> [x86] Tested-by: Mark Brown <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Betkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: David S. Miller <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Gerald Schaefer <[email protected]> Cc: Guo Ren (csky) <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Helge Deller <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiaxun Yang <[email protected]> Cc: Johannes Berg <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russel King <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleinxer <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8268af3 commit e120d1b

File tree

25 files changed

+30
-62
lines changed

25 files changed

+30
-62
lines changed

arch/alpha/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ srm_paging_stop (void)
276276
void __init
277277
mem_init(void)
278278
{
279-
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
280279
memblock_free_all();
281280
}
282281

arch/arc/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ void __init setup_arch_memory(void)
150150
*/
151151
max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn;
152152

153-
high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
154-
155153
arch_pfn_offset = min(min_low_pfn, min_high_pfn);
156154
kmap_init();
157155
#endif /* CONFIG_HIGHMEM */

arch/arm64/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ void __init arm64_memblock_init(void)
309309
}
310310

311311
early_init_fdt_scan_reserved_mem();
312-
313-
high_memory = __va(memblock_end_of_DRAM() - 1) + 1;
314312
}
315313

316314
void __init bootmem_init(void)

arch/csky/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ void __init mem_init(void)
4747
#ifdef CONFIG_HIGHMEM
4848
unsigned long tmp;
4949
#endif
50-
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
5150

5251
memblock_free_all();
5352

arch/hexagon/mm/init.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ static void __init paging_init(void)
100100
* initial kernel segment table's physical address.
101101
*/
102102
init_mm.context.ptbase = __pa(init_mm.pgd);
103-
104-
/*
105-
* Start of high memory area. Will probably need something more
106-
* fancy if we... get more fancy.
107-
*/
108-
high_memory = (void *)((bootmem_lastpg + 1) << PAGE_SHIFT);
109103
}
110104

111105
#ifndef DMA_RESERVE

arch/loongarch/kernel/numa.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ void __init paging_init(void)
389389

390390
void __init mem_init(void)
391391
{
392-
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
393392
memblock_free_all();
394393
}
395394

arch/loongarch/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ void __init paging_init(void)
7878

7979
void __init mem_init(void)
8080
{
81-
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
82-
8381
memblock_free_all();
8482
}
8583
#endif /* !CONFIG_NUMA */

arch/microblaze/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ void __init setup_memory(void)
120120

121121
void __init mem_init(void)
122122
{
123-
high_memory = (void *)__va(memory_start + lowmem_size - 1);
124-
125123
/* this will put all memory onto the freelists */
126124
memblock_free_all();
127125
#ifdef CONFIG_HIGHMEM

arch/mips/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ void __init paging_init(void)
417417
max_zone_pfns[ZONE_HIGHMEM] = max_low_pfn;
418418
}
419419
#endif
420-
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
421420

422421
free_area_init(max_zone_pfns);
423422
}
@@ -469,7 +468,6 @@ void __init mem_init(void)
469468
#else /* CONFIG_NUMA */
470469
void __init mem_init(void)
471470
{
472-
high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT);
473471
setup_zero_pages(); /* This comes from node 0 */
474472
memblock_free_all();
475473
}

arch/nios2/mm/init.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ void __init paging_init(void)
6262

6363
void __init mem_init(void)
6464
{
65-
unsigned long end_mem = memory_end; /* this must not include
66-
kernel stack at top */
67-
68-
end_mem &= PAGE_MASK;
69-
high_memory = __va(end_mem);
70-
7165
/* this will put all memory onto the freelists */
7266
memblock_free_all();
7367
}

arch/openrisc/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ void __init mem_init(void)
193193
{
194194
BUG_ON(!mem_map);
195195

196-
high_memory = (void *)__va(max_low_pfn * PAGE_SIZE);
197-
198196
/* clear the zero-page */
199197
memset((void *)empty_zero_page, 0, PAGE_SIZE);
200198

arch/parisc/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ void __init mem_init(void)
562562
BUILD_BUG_ON(TMPALIAS_MAP_START >= 0x80000000);
563563
#endif
564564

565-
high_memory = __va((max_pfn << PAGE_SHIFT));
566565
memblock_free_all();
567566

568567
#ifdef CONFIG_PA11

arch/riscv/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ static void __init setup_bootmem(void)
295295
phys_ram_end = memblock_end_of_DRAM();
296296
min_low_pfn = PFN_UP(phys_ram_base);
297297
max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end);
298-
high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
299298

300299
dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn));
301300

arch/s390/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ void __init mem_init(void)
159159
cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
160160
cpumask_set_cpu(0, mm_cpumask(&init_mm));
161161

162-
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
163-
164162
pv_init();
165163
kfence_split_mapping();
166164

arch/sh/mm/init.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,6 @@ unsigned int mem_init_done = 0;
330330

331331
void __init mem_init(void)
332332
{
333-
pg_data_t *pgdat;
334-
335-
high_memory = NULL;
336-
for_each_online_pgdat(pgdat)
337-
high_memory = max_t(void *, high_memory,
338-
__va(pgdat_end_pfn(pgdat) << PAGE_SHIFT));
339-
340333
memblock_free_all();
341334

342335
/* Set this up early, so we can take care of the zero page */

arch/sparc/mm/init_32.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ void __init mem_init(void)
275275

276276
taint_real_pages();
277277

278-
high_memory = __va(max_low_pfn << PAGE_SHIFT);
279278
memblock_free_all();
280279

281280
for (i = 0; sp_banks[i].num_bytes != 0; i++) {

arch/sparc/mm/init_64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,8 +2505,6 @@ static void __init register_page_bootmem_info(void)
25052505
}
25062506
void __init mem_init(void)
25072507
{
2508-
high_memory = __va(last_valid_pfn << PAGE_SHIFT);
2509-
25102508
memblock_free_all();
25112509

25122510
/*

arch/um/kernel/um_arch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ int __init linux_main(int argc, char **argv, char **envp)
385385

386386
high_physmem = uml_physmem + physmem_size;
387387
end_iomem = high_physmem + iomem_size;
388-
high_memory = (void *) end_iomem;
389388

390389
start_vm = VMALLOC_START;
391390

arch/x86/kernel/setup.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,6 @@ void __init setup_arch(char **cmdline_p)
972972
max_low_pfn = e820__end_of_low_ram_pfn();
973973
else
974974
max_low_pfn = max_pfn;
975-
976-
high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
977975
#endif
978976

979977
/* Find and reserve MPTABLE area */

arch/x86/mm/init_32.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,6 @@ void __init initmem_init(void)
643643
highstart_pfn = max_low_pfn;
644644
printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
645645
pages_to_mb(highend_pfn - highstart_pfn));
646-
high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
647-
#else
648-
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
649646
#endif
650647

651648
memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);

arch/x86/mm/numa_32.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ void __init initmem_init(void)
4141
highstart_pfn = max_low_pfn;
4242
printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
4343
pages_to_mb(highend_pfn - highstart_pfn));
44-
high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
45-
#else
46-
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
4744
#endif
4845
printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
4946
pages_to_mb(max_low_pfn));

arch/xtensa/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ void __init mem_init(void)
164164
{
165165
free_highpages();
166166

167-
high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
168-
169167
memblock_free_all();
170168
}
171169

mm/memory.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ static __always_inline bool vmf_orig_pte_uffd_wp(struct vm_fault *vmf)
113113
return pte_marker_uffd_wp(vmf->orig_pte);
114114
}
115115

116-
/*
117-
* A number of key systems in x86 including ioremap() rely on the assumption
118-
* that high_memory defines the upper bound on direct map memory, then end
119-
* of ZONE_NORMAL.
120-
*/
121-
void *high_memory;
122-
EXPORT_SYMBOL(high_memory);
123-
124116
/*
125117
* Randomize the address space (stacks, mmaps, brk, etc.).
126118
*

mm/mm_init.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ struct page *mem_map;
4545
EXPORT_SYMBOL(mem_map);
4646
#endif
4747

48+
/*
49+
* high_memory defines the upper bound on direct map memory, then end
50+
* of ZONE_NORMAL.
51+
*/
52+
void *high_memory;
53+
EXPORT_SYMBOL(high_memory);
54+
4855
#ifdef CONFIG_DEBUG_MEMORY_INIT
4956
int __meminitdata mminit_loglevel;
5057

@@ -1778,6 +1785,27 @@ static bool arch_has_descending_max_zone_pfns(void)
17781785
return IS_ENABLED(CONFIG_ARC) && !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
17791786
}
17801787

1788+
static void set_high_memory(void)
1789+
{
1790+
phys_addr_t highmem = memblock_end_of_DRAM();
1791+
1792+
/*
1793+
* Some architectures (e.g. ARM) set high_memory very early and
1794+
* use it in arch setup code.
1795+
* If an architecture already set high_memory don't overwrite it
1796+
*/
1797+
if (high_memory)
1798+
return;
1799+
1800+
#ifdef CONFIG_HIGHMEM
1801+
if (arch_has_descending_max_zone_pfns() ||
1802+
highmem > PFN_PHYS(arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]))
1803+
highmem = PFN_PHYS(arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]);
1804+
#endif
1805+
1806+
high_memory = phys_to_virt(highmem - 1) + 1;
1807+
}
1808+
17811809
/**
17821810
* free_area_init - Initialise all pg_data_t and zone data
17831811
* @max_zone_pfn: an array of max PFNs for each zone
@@ -1900,6 +1928,8 @@ void __init free_area_init(unsigned long *max_zone_pfn)
19001928

19011929
/* disable hash distribution for systems with a single node */
19021930
fixup_hashdist();
1931+
1932+
set_high_memory();
19031933
}
19041934

19051935
/**

mm/nommu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include <asm/mmu_context.h>
4343
#include "internal.h"
4444

45-
void *high_memory;
46-
EXPORT_SYMBOL(high_memory);
4745
unsigned long highest_memmap_pfn;
4846
int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
4947
int heap_stack_gap = 0;

0 commit comments

Comments
 (0)