mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 02:36:21 +00:00
902861e34c
from hotplugged memory rather than only from main memory. Series "implement "memmap on memory" feature on s390". - More folio conversions from Matthew Wilcox in the series "Convert memcontrol charge moving to use folios" "mm: convert mm counter to take a folio" - Chengming Zhou has optimized zswap's rbtree locking, providing significant reductions in system time and modest but measurable reductions in overall runtimes. The series is "mm/zswap: optimize the scalability of zswap rb-tree". - Chengming Zhou has also provided the series "mm/zswap: optimize zswap lru list" which provides measurable runtime benefits in some swap-intensive situations. - And Chengming Zhou further optimizes zswap in the series "mm/zswap: optimize for dynamic zswap_pools". Measured improvements are modest. - zswap cleanups and simplifications from Yosry Ahmed in the series "mm: zswap: simplify zswap_swapoff()". - In the series "Add DAX ABI for memmap_on_memory", Vishal Verma has contributed several DAX cleanups as well as adding a sysfs tunable to control the memmap_on_memory setting when the dax device is hotplugged as system memory. - Johannes Weiner has added the large series "mm: zswap: cleanups", which does that. - More DAMON work from SeongJae Park in the series "mm/damon: make DAMON debugfs interface deprecation unignorable" "selftests/damon: add more tests for core functionalities and corner cases" "Docs/mm/damon: misc readability improvements" "mm/damon: let DAMOS feeds and tame/auto-tune itself" - In the series "mm/mempolicy: weighted interleave mempolicy and sysfs extension" Rakie Kim has developed a new mempolicy interleaving policy wherein we allocate memory across nodes in a weighted fashion rather than uniformly. This is beneficial in heterogeneous memory environments appearing with CXL. - Christophe Leroy has contributed some cleanup and consolidation work against the ARM pagetable dumping code in the series "mm: ptdump: Refactor CONFIG_DEBUG_WX and check_wx_pages debugfs attribute". - Luis Chamberlain has added some additional xarray selftesting in the series "test_xarray: advanced API multi-index tests". - Muhammad Usama Anjum has reworked the selftest code to make its human-readable output conform to the TAP ("Test Anything Protocol") format. Amongst other things, this opens up the use of third-party tools to parse and process out selftesting results. - Ryan Roberts has added fork()-time PTE batching of THP ptes in the series "mm/memory: optimize fork() with PTE-mapped THP". Mainly targeted at arm64, this significantly speeds up fork() when the process has a large number of pte-mapped folios. - David Hildenbrand also gets in on the THP pte batching game in his series "mm/memory: optimize unmap/zap with PTE-mapped THP". It implements batching during munmap() and other pte teardown situations. The microbenchmark improvements are nice. - And in the series "Transparent Contiguous PTEs for User Mappings" Ryan Roberts further utilizes arm's pte's contiguous bit ("contpte mappings"). Kernel build times on arm64 improved nicely. Ryan's series "Address some contpte nits" provides some followup work. - In the series "mm/hugetlb: Restore the reservation" Breno Leitao has fixed an obscure hugetlb race which was causing unnecessary page faults. He has also added a reproducer under the selftest code. - In the series "selftests/mm: Output cleanups for the compaction test", Mark Brown did what the title claims. - Kinsey Ho has added the series "mm/mglru: code cleanup and refactoring". - Even more zswap material from Nhat Pham. The series "fix and extend zswap kselftests" does as claimed. - In the series "Introduce cpu_dcache_is_aliasing() to fix DAX regression" Mathieu Desnoyers has cleaned up and fixed rather a mess in our handling of DAX on archiecctures which have virtually aliasing data caches. The arm architecture is the main beneficiary. - Lokesh Gidra's series "per-vma locks in userfaultfd" provides dramatic improvements in worst-case mmap_lock hold times during certain userfaultfd operations. - Some page_owner enhancements and maintenance work from Oscar Salvador in his series "page_owner: print stacks and their outstanding allocations" "page_owner: Fixup and cleanup" - Uladzislau Rezki has contributed some vmalloc scalability improvements in his series "Mitigate a vmap lock contention". It realizes a 12x improvement for a certain microbenchmark. - Some kexec/crash cleanup work from Baoquan He in the series "Split crash out from kexec and clean up related config items". - Some zsmalloc maintenance work from Chengming Zhou in the series "mm/zsmalloc: fix and optimize objects/page migration" "mm/zsmalloc: some cleanup for get/set_zspage_mapping()" - Zi Yan has taught the MM to perform compaction on folios larger than order=0. This a step along the path to implementaton of the merging of large anonymous folios. The series is named "Enable >0 order folio memory compaction". - Christoph Hellwig has done quite a lot of cleanup work in the pagecache writeback code in his series "convert write_cache_pages() to an iterator". - Some modest hugetlb cleanups and speedups in Vishal Moola's series "Handle hugetlb faults under the VMA lock". - Zi Yan has changed the page splitting code so we can split huge pages into sizes other than order-0 to better utilize large folios. The series is named "Split a folio to any lower order folios". - David Hildenbrand has contributed the series "mm: remove total_mapcount()", a cleanup. - Matthew Wilcox has sought to improve the performance of bulk memory freeing in his series "Rearrange batched folio freeing". - Gang Li's series "hugetlb: parallelize hugetlb page init on boot" provides large improvements in bootup times on large machines which are configured to use large numbers of hugetlb pages. - Matthew Wilcox's series "PageFlags cleanups" does that. - Qi Zheng's series "minor fixes and supplement for ptdesc" does that also. S390 is affected. - Cleanups to our pagemap utility functions from Peter Xu in his series "mm/treewide: Replace pXd_large() with pXd_leaf()". - Nico Pache has fixed a few things with our hugepage selftests in his series "selftests/mm: Improve Hugepage Test Handling in MM Selftests". - Also, of course, many singleton patches to many things. Please see the individual changelogs for details. -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQTTMBEPP41GrTpTJgfdBJ7gKXxAjgUCZfJpPQAKCRDdBJ7gKXxA joxeAP9TrcMEuHnLmBlhIXkWbIR4+ki+pA3v+gNTlJiBhnfVSgD9G55t1aBaRplx TMNhHfyiHYDTx/GAV9NXW84tasJSDgA= =TG55 -----END PGP SIGNATURE----- Merge tag 'mm-stable-2024-03-13-20-04' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull MM updates from Andrew Morton: - Sumanth Korikkar has taught s390 to allocate hotplug-time page frames from hotplugged memory rather than only from main memory. Series "implement "memmap on memory" feature on s390". - More folio conversions from Matthew Wilcox in the series "Convert memcontrol charge moving to use folios" "mm: convert mm counter to take a folio" - Chengming Zhou has optimized zswap's rbtree locking, providing significant reductions in system time and modest but measurable reductions in overall runtimes. The series is "mm/zswap: optimize the scalability of zswap rb-tree". - Chengming Zhou has also provided the series "mm/zswap: optimize zswap lru list" which provides measurable runtime benefits in some swap-intensive situations. - And Chengming Zhou further optimizes zswap in the series "mm/zswap: optimize for dynamic zswap_pools". Measured improvements are modest. - zswap cleanups and simplifications from Yosry Ahmed in the series "mm: zswap: simplify zswap_swapoff()". - In the series "Add DAX ABI for memmap_on_memory", Vishal Verma has contributed several DAX cleanups as well as adding a sysfs tunable to control the memmap_on_memory setting when the dax device is hotplugged as system memory. - Johannes Weiner has added the large series "mm: zswap: cleanups", which does that. - More DAMON work from SeongJae Park in the series "mm/damon: make DAMON debugfs interface deprecation unignorable" "selftests/damon: add more tests for core functionalities and corner cases" "Docs/mm/damon: misc readability improvements" "mm/damon: let DAMOS feeds and tame/auto-tune itself" - In the series "mm/mempolicy: weighted interleave mempolicy and sysfs extension" Rakie Kim has developed a new mempolicy interleaving policy wherein we allocate memory across nodes in a weighted fashion rather than uniformly. This is beneficial in heterogeneous memory environments appearing with CXL. - Christophe Leroy has contributed some cleanup and consolidation work against the ARM pagetable dumping code in the series "mm: ptdump: Refactor CONFIG_DEBUG_WX and check_wx_pages debugfs attribute". - Luis Chamberlain has added some additional xarray selftesting in the series "test_xarray: advanced API multi-index tests". - Muhammad Usama Anjum has reworked the selftest code to make its human-readable output conform to the TAP ("Test Anything Protocol") format. Amongst other things, this opens up the use of third-party tools to parse and process out selftesting results. - Ryan Roberts has added fork()-time PTE batching of THP ptes in the series "mm/memory: optimize fork() with PTE-mapped THP". Mainly targeted at arm64, this significantly speeds up fork() when the process has a large number of pte-mapped folios. - David Hildenbrand also gets in on the THP pte batching game in his series "mm/memory: optimize unmap/zap with PTE-mapped THP". It implements batching during munmap() and other pte teardown situations. The microbenchmark improvements are nice. - And in the series "Transparent Contiguous PTEs for User Mappings" Ryan Roberts further utilizes arm's pte's contiguous bit ("contpte mappings"). Kernel build times on arm64 improved nicely. Ryan's series "Address some contpte nits" provides some followup work. - In the series "mm/hugetlb: Restore the reservation" Breno Leitao has fixed an obscure hugetlb race which was causing unnecessary page faults. He has also added a reproducer under the selftest code. - In the series "selftests/mm: Output cleanups for the compaction test", Mark Brown did what the title claims. - Kinsey Ho has added the series "mm/mglru: code cleanup and refactoring". - Even more zswap material from Nhat Pham. The series "fix and extend zswap kselftests" does as claimed. - In the series "Introduce cpu_dcache_is_aliasing() to fix DAX regression" Mathieu Desnoyers has cleaned up and fixed rather a mess in our handling of DAX on archiecctures which have virtually aliasing data caches. The arm architecture is the main beneficiary. - Lokesh Gidra's series "per-vma locks in userfaultfd" provides dramatic improvements in worst-case mmap_lock hold times during certain userfaultfd operations. - Some page_owner enhancements and maintenance work from Oscar Salvador in his series "page_owner: print stacks and their outstanding allocations" "page_owner: Fixup and cleanup" - Uladzislau Rezki has contributed some vmalloc scalability improvements in his series "Mitigate a vmap lock contention". It realizes a 12x improvement for a certain microbenchmark. - Some kexec/crash cleanup work from Baoquan He in the series "Split crash out from kexec and clean up related config items". - Some zsmalloc maintenance work from Chengming Zhou in the series "mm/zsmalloc: fix and optimize objects/page migration" "mm/zsmalloc: some cleanup for get/set_zspage_mapping()" - Zi Yan has taught the MM to perform compaction on folios larger than order=0. This a step along the path to implementaton of the merging of large anonymous folios. The series is named "Enable >0 order folio memory compaction". - Christoph Hellwig has done quite a lot of cleanup work in the pagecache writeback code in his series "convert write_cache_pages() to an iterator". - Some modest hugetlb cleanups and speedups in Vishal Moola's series "Handle hugetlb faults under the VMA lock". - Zi Yan has changed the page splitting code so we can split huge pages into sizes other than order-0 to better utilize large folios. The series is named "Split a folio to any lower order folios". - David Hildenbrand has contributed the series "mm: remove total_mapcount()", a cleanup. - Matthew Wilcox has sought to improve the performance of bulk memory freeing in his series "Rearrange batched folio freeing". - Gang Li's series "hugetlb: parallelize hugetlb page init on boot" provides large improvements in bootup times on large machines which are configured to use large numbers of hugetlb pages. - Matthew Wilcox's series "PageFlags cleanups" does that. - Qi Zheng's series "minor fixes and supplement for ptdesc" does that also. S390 is affected. - Cleanups to our pagemap utility functions from Peter Xu in his series "mm/treewide: Replace pXd_large() with pXd_leaf()". - Nico Pache has fixed a few things with our hugepage selftests in his series "selftests/mm: Improve Hugepage Test Handling in MM Selftests". - Also, of course, many singleton patches to many things. Please see the individual changelogs for details. * tag 'mm-stable-2024-03-13-20-04' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (435 commits) mm/zswap: remove the memcpy if acomp is not sleepable crypto: introduce: acomp_is_async to expose if comp drivers might sleep memtest: use {READ,WRITE}_ONCE in memory scanning mm: prohibit the last subpage from reusing the entire large folio mm: recover pud_leaf() definitions in nopmd case selftests/mm: skip the hugetlb-madvise tests on unmet hugepage requirements selftests/mm: skip uffd hugetlb tests with insufficient hugepages selftests/mm: dont fail testsuite due to a lack of hugepages mm/huge_memory: skip invalid debugfs new_order input for folio split mm/huge_memory: check new folio order when split a folio mm, vmscan: retry kswapd's priority loop with cache_trim_mode off on failure mm: add an explicit smp_wmb() to UFFDIO_CONTINUE mm: fix list corruption in put_pages_list mm: remove folio from deferred split list before uncharging it filemap: avoid unnecessary major faults in filemap_fault() mm,page_owner: drop unnecessary check mm,page_owner: check for null stack_record before bumping its refcount mm: swap: fix race between free_swap_and_cache() and swapoff() mm/treewide: align up pXd_leaf() retval across archs mm/treewide: drop pXd_large() ...
435 lines
13 KiB
C
435 lines
13 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Based on arch/arm/mm/init.c
|
|
*
|
|
* Copyright (C) 1995-2005 Russell King
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/export.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/init.h>
|
|
#include <linux/cache.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/nodemask.h>
|
|
#include <linux/initrd.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/math.h>
|
|
#include <linux/memblock.h>
|
|
#include <linux/sort.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_fdt.h>
|
|
#include <linux/dma-direct.h>
|
|
#include <linux/dma-map-ops.h>
|
|
#include <linux/efi.h>
|
|
#include <linux/swiotlb.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/kexec.h>
|
|
#include <linux/crash_dump.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <linux/acpi_iort.h>
|
|
#include <linux/kmemleak.h>
|
|
|
|
#include <asm/boot.h>
|
|
#include <asm/fixmap.h>
|
|
#include <asm/kasan.h>
|
|
#include <asm/kernel-pgtable.h>
|
|
#include <asm/kvm_host.h>
|
|
#include <asm/memory.h>
|
|
#include <asm/numa.h>
|
|
#include <asm/sections.h>
|
|
#include <asm/setup.h>
|
|
#include <linux/sizes.h>
|
|
#include <asm/tlb.h>
|
|
#include <asm/alternative.h>
|
|
#include <asm/xen/swiotlb-xen.h>
|
|
|
|
/*
|
|
* We need to be able to catch inadvertent references to memstart_addr
|
|
* that occur (potentially in generic code) before arm64_memblock_init()
|
|
* executes, which assigns it its actual value. So use a default value
|
|
* that cannot be mistaken for a real physical address.
|
|
*/
|
|
s64 memstart_addr __ro_after_init = -1;
|
|
EXPORT_SYMBOL(memstart_addr);
|
|
|
|
/*
|
|
* If the corresponding config options are enabled, we create both ZONE_DMA
|
|
* and ZONE_DMA32. By default ZONE_DMA covers the 32-bit addressable memory
|
|
* unless restricted on specific platforms (e.g. 30-bit on Raspberry Pi 4).
|
|
* In such case, ZONE_DMA32 covers the rest of the 32-bit addressable memory,
|
|
* otherwise it is empty.
|
|
*/
|
|
phys_addr_t __ro_after_init arm64_dma_phys_limit;
|
|
|
|
/*
|
|
* To make optimal use of block mappings when laying out the linear
|
|
* mapping, round down the base of physical memory to a size that can
|
|
* be mapped efficiently, i.e., either PUD_SIZE (4k granule) or PMD_SIZE
|
|
* (64k granule), or a multiple that can be mapped using contiguous bits
|
|
* in the page tables: 32 * PMD_SIZE (16k granule)
|
|
*/
|
|
#if defined(CONFIG_ARM64_4K_PAGES)
|
|
#define ARM64_MEMSTART_SHIFT PUD_SHIFT
|
|
#elif defined(CONFIG_ARM64_16K_PAGES)
|
|
#define ARM64_MEMSTART_SHIFT CONT_PMD_SHIFT
|
|
#else
|
|
#define ARM64_MEMSTART_SHIFT PMD_SHIFT
|
|
#endif
|
|
|
|
/*
|
|
* sparsemem vmemmap imposes an additional requirement on the alignment of
|
|
* memstart_addr, due to the fact that the base of the vmemmap region
|
|
* has a direct correspondence, and needs to appear sufficiently aligned
|
|
* in the virtual address space.
|
|
*/
|
|
#if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
|
|
#define ARM64_MEMSTART_ALIGN (1UL << SECTION_SIZE_BITS)
|
|
#else
|
|
#define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT)
|
|
#endif
|
|
|
|
static void __init arch_reserve_crashkernel(void)
|
|
{
|
|
unsigned long long low_size = 0;
|
|
unsigned long long crash_base, crash_size;
|
|
char *cmdline = boot_command_line;
|
|
bool high = false;
|
|
int ret;
|
|
|
|
if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
|
|
return;
|
|
|
|
ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
|
|
&crash_size, &crash_base,
|
|
&low_size, &high);
|
|
if (ret)
|
|
return;
|
|
|
|
reserve_crashkernel_generic(cmdline, crash_size, crash_base,
|
|
low_size, high);
|
|
}
|
|
|
|
/*
|
|
* Return the maximum physical address for a zone accessible by the given bits
|
|
* limit. If DRAM starts above 32-bit, expand the zone to the maximum
|
|
* available memory, otherwise cap it at 32-bit.
|
|
*/
|
|
static phys_addr_t __init max_zone_phys(unsigned int zone_bits)
|
|
{
|
|
phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits);
|
|
phys_addr_t phys_start = memblock_start_of_DRAM();
|
|
|
|
if (phys_start > U32_MAX)
|
|
zone_mask = PHYS_ADDR_MAX;
|
|
else if (phys_start > zone_mask)
|
|
zone_mask = U32_MAX;
|
|
|
|
return min(zone_mask, memblock_end_of_DRAM() - 1) + 1;
|
|
}
|
|
|
|
static void __init zone_sizes_init(void)
|
|
{
|
|
unsigned long max_zone_pfns[MAX_NR_ZONES] = {0};
|
|
unsigned int __maybe_unused acpi_zone_dma_bits;
|
|
unsigned int __maybe_unused dt_zone_dma_bits;
|
|
phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32);
|
|
|
|
#ifdef CONFIG_ZONE_DMA
|
|
acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address());
|
|
dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL));
|
|
zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits);
|
|
arm64_dma_phys_limit = max_zone_phys(zone_dma_bits);
|
|
max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit);
|
|
#endif
|
|
#ifdef CONFIG_ZONE_DMA32
|
|
max_zone_pfns[ZONE_DMA32] = PFN_DOWN(dma32_phys_limit);
|
|
if (!arm64_dma_phys_limit)
|
|
arm64_dma_phys_limit = dma32_phys_limit;
|
|
#endif
|
|
if (!arm64_dma_phys_limit)
|
|
arm64_dma_phys_limit = PHYS_MASK + 1;
|
|
max_zone_pfns[ZONE_NORMAL] = max_pfn;
|
|
|
|
free_area_init(max_zone_pfns);
|
|
}
|
|
|
|
int pfn_is_map_memory(unsigned long pfn)
|
|
{
|
|
phys_addr_t addr = PFN_PHYS(pfn);
|
|
|
|
/* avoid false positives for bogus PFNs, see comment in pfn_valid() */
|
|
if (PHYS_PFN(addr) != pfn)
|
|
return 0;
|
|
|
|
return memblock_is_map_memory(addr);
|
|
}
|
|
EXPORT_SYMBOL(pfn_is_map_memory);
|
|
|
|
static phys_addr_t memory_limit __ro_after_init = PHYS_ADDR_MAX;
|
|
|
|
/*
|
|
* Limit the memory size that was specified via FDT.
|
|
*/
|
|
static int __init early_mem(char *p)
|
|
{
|
|
if (!p)
|
|
return 1;
|
|
|
|
memory_limit = memparse(p, &p) & PAGE_MASK;
|
|
pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
|
|
|
|
return 0;
|
|
}
|
|
early_param("mem", early_mem);
|
|
|
|
void __init arm64_memblock_init(void)
|
|
{
|
|
s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual);
|
|
|
|
/*
|
|
* Corner case: 52-bit VA capable systems running KVM in nVHE mode may
|
|
* be limited in their ability to support a linear map that exceeds 51
|
|
* bits of VA space, depending on the placement of the ID map. Given
|
|
* that the placement of the ID map may be randomized, let's simply
|
|
* limit the kernel's linear map to 51 bits as well if we detect this
|
|
* configuration.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_KVM) && vabits_actual == 52 &&
|
|
is_hyp_mode_available() && !is_kernel_in_hyp_mode()) {
|
|
pr_info("Capping linear region to 51 bits for KVM in nVHE mode on LVA capable hardware.\n");
|
|
linear_region_size = min_t(u64, linear_region_size, BIT(51));
|
|
}
|
|
|
|
/* Remove memory above our supported physical address size */
|
|
memblock_remove(1ULL << PHYS_MASK_SHIFT, ULLONG_MAX);
|
|
|
|
/*
|
|
* Select a suitable value for the base of physical memory.
|
|
*/
|
|
memstart_addr = round_down(memblock_start_of_DRAM(),
|
|
ARM64_MEMSTART_ALIGN);
|
|
|
|
if ((memblock_end_of_DRAM() - memstart_addr) > linear_region_size)
|
|
pr_warn("Memory doesn't fit in the linear mapping, VA_BITS too small\n");
|
|
|
|
/*
|
|
* Remove the memory that we will not be able to cover with the
|
|
* linear mapping. Take care not to clip the kernel which may be
|
|
* high in memory.
|
|
*/
|
|
memblock_remove(max_t(u64, memstart_addr + linear_region_size,
|
|
__pa_symbol(_end)), ULLONG_MAX);
|
|
if (memstart_addr + linear_region_size < memblock_end_of_DRAM()) {
|
|
/* ensure that memstart_addr remains sufficiently aligned */
|
|
memstart_addr = round_up(memblock_end_of_DRAM() - linear_region_size,
|
|
ARM64_MEMSTART_ALIGN);
|
|
memblock_remove(0, memstart_addr);
|
|
}
|
|
|
|
/*
|
|
* If we are running with a 52-bit kernel VA config on a system that
|
|
* does not support it, we have to place the available physical
|
|
* memory in the 48-bit addressable part of the linear region, i.e.,
|
|
* we have to move it upward. Since memstart_addr represents the
|
|
* physical address of PAGE_OFFSET, we have to *subtract* from it.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_ARM64_VA_BITS_52) && (vabits_actual != 52))
|
|
memstart_addr -= _PAGE_OFFSET(vabits_actual) - _PAGE_OFFSET(52);
|
|
|
|
/*
|
|
* Apply the memory limit if it was set. Since the kernel may be loaded
|
|
* high up in memory, add back the kernel region that must be accessible
|
|
* via the linear mapping.
|
|
*/
|
|
if (memory_limit != PHYS_ADDR_MAX) {
|
|
memblock_mem_limit_remove_map(memory_limit);
|
|
memblock_add(__pa_symbol(_text), (u64)(_end - _text));
|
|
}
|
|
|
|
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
|
|
/*
|
|
* Add back the memory we just removed if it results in the
|
|
* initrd to become inaccessible via the linear mapping.
|
|
* Otherwise, this is a no-op
|
|
*/
|
|
u64 base = phys_initrd_start & PAGE_MASK;
|
|
u64 size = PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base;
|
|
|
|
/*
|
|
* We can only add back the initrd memory if we don't end up
|
|
* with more memory than we can address via the linear mapping.
|
|
* It is up to the bootloader to position the kernel and the
|
|
* initrd reasonably close to each other (i.e., within 32 GB of
|
|
* each other) so that all granule/#levels combinations can
|
|
* always access both.
|
|
*/
|
|
if (WARN(base < memblock_start_of_DRAM() ||
|
|
base + size > memblock_start_of_DRAM() +
|
|
linear_region_size,
|
|
"initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) {
|
|
phys_initrd_size = 0;
|
|
} else {
|
|
memblock_add(base, size);
|
|
memblock_clear_nomap(base, size);
|
|
memblock_reserve(base, size);
|
|
}
|
|
}
|
|
|
|
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
|
|
extern u16 memstart_offset_seed;
|
|
u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
|
|
int parange = cpuid_feature_extract_unsigned_field(
|
|
mmfr0, ID_AA64MMFR0_EL1_PARANGE_SHIFT);
|
|
s64 range = linear_region_size -
|
|
BIT(id_aa64mmfr0_parange_to_phys_shift(parange));
|
|
|
|
/*
|
|
* If the size of the linear region exceeds, by a sufficient
|
|
* margin, the size of the region that the physical memory can
|
|
* span, randomize the linear region as well.
|
|
*/
|
|
if (memstart_offset_seed > 0 && range >= (s64)ARM64_MEMSTART_ALIGN) {
|
|
range /= ARM64_MEMSTART_ALIGN;
|
|
memstart_addr -= ARM64_MEMSTART_ALIGN *
|
|
((range * memstart_offset_seed) >> 16);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Register the kernel text, kernel data, initrd, and initial
|
|
* pagetables with memblock.
|
|
*/
|
|
memblock_reserve(__pa_symbol(_stext), _end - _stext);
|
|
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
|
|
/* the generic initrd code expects virtual addresses */
|
|
initrd_start = __phys_to_virt(phys_initrd_start);
|
|
initrd_end = initrd_start + phys_initrd_size;
|
|
}
|
|
|
|
early_init_fdt_scan_reserved_mem();
|
|
|
|
high_memory = __va(memblock_end_of_DRAM() - 1) + 1;
|
|
}
|
|
|
|
void __init bootmem_init(void)
|
|
{
|
|
unsigned long min, max;
|
|
|
|
min = PFN_UP(memblock_start_of_DRAM());
|
|
max = PFN_DOWN(memblock_end_of_DRAM());
|
|
|
|
early_memtest(min << PAGE_SHIFT, max << PAGE_SHIFT);
|
|
|
|
max_pfn = max_low_pfn = max;
|
|
min_low_pfn = min;
|
|
|
|
arch_numa_init();
|
|
|
|
/*
|
|
* must be done after arch_numa_init() which calls numa_init() to
|
|
* initialize node_online_map that gets used in hugetlb_cma_reserve()
|
|
* while allocating required CMA size across online nodes.
|
|
*/
|
|
#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
|
|
arm64_hugetlb_cma_reserve();
|
|
#endif
|
|
|
|
kvm_hyp_reserve();
|
|
|
|
/*
|
|
* sparse_init() tries to allocate memory from memblock, so must be
|
|
* done after the fixed reservations
|
|
*/
|
|
sparse_init();
|
|
zone_sizes_init();
|
|
|
|
/*
|
|
* Reserve the CMA area after arm64_dma_phys_limit was initialised.
|
|
*/
|
|
dma_contiguous_reserve(arm64_dma_phys_limit);
|
|
|
|
/*
|
|
* request_standard_resources() depends on crashkernel's memory being
|
|
* reserved, so do it here.
|
|
*/
|
|
arch_reserve_crashkernel();
|
|
|
|
memblock_dump_all();
|
|
}
|
|
|
|
/*
|
|
* mem_init() marks the free areas in the mem_map and tells us how much memory
|
|
* is free. This is done after various parts of the system have claimed their
|
|
* memory after the kernel image.
|
|
*/
|
|
void __init mem_init(void)
|
|
{
|
|
bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit);
|
|
|
|
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) {
|
|
/*
|
|
* If no bouncing needed for ZONE_DMA, reduce the swiotlb
|
|
* buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
|
|
*/
|
|
unsigned long size =
|
|
DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
|
|
swiotlb_adjust_size(min(swiotlb_size_or_default(), size));
|
|
swiotlb = true;
|
|
}
|
|
|
|
swiotlb_init(swiotlb, SWIOTLB_VERBOSE);
|
|
|
|
/* this will put all unused low memory onto the freelists */
|
|
memblock_free_all();
|
|
|
|
/*
|
|
* Check boundaries twice: Some fundamental inconsistencies can be
|
|
* detected at build time already.
|
|
*/
|
|
#ifdef CONFIG_COMPAT
|
|
BUILD_BUG_ON(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64);
|
|
#endif
|
|
|
|
/*
|
|
* Selected page table levels should match when derived from
|
|
* scratch using the virtual address range and page size.
|
|
*/
|
|
BUILD_BUG_ON(ARM64_HW_PGTABLE_LEVELS(CONFIG_ARM64_VA_BITS) !=
|
|
CONFIG_PGTABLE_LEVELS);
|
|
|
|
if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
|
|
extern int sysctl_overcommit_memory;
|
|
/*
|
|
* On a machine this small we won't get anywhere without
|
|
* overcommit, so turn it on by default.
|
|
*/
|
|
sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
|
|
}
|
|
}
|
|
|
|
void free_initmem(void)
|
|
{
|
|
free_reserved_area(lm_alias(__init_begin),
|
|
lm_alias(__init_end),
|
|
POISON_FREE_INITMEM, "unused kernel");
|
|
/*
|
|
* Unmap the __init region but leave the VM area in place. This
|
|
* prevents the region from being reused for kernel modules, which
|
|
* is not supported by kallsyms.
|
|
*/
|
|
vunmap_range((u64)__init_begin, (u64)__init_end);
|
|
}
|
|
|
|
void dump_mem_limit(void)
|
|
{
|
|
if (memory_limit != PHYS_ADDR_MAX) {
|
|
pr_emerg("Memory Limit: %llu MB\n", memory_limit >> 20);
|
|
} else {
|
|
pr_emerg("Memory Limit: none\n");
|
|
}
|
|
}
|