Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5768f08b authored by Arun KS's avatar Arun KS Committed by Sudarshan Rajagopalan
Browse files

arm64: Honor limits set by bootloader



Introduce a variable to save bootloader enforced memory limits and
restricts adding beyond this boundary during a memory hotplug. Also,
export this symbol so that other kernel module have access to it.

Change-Id: I28c100644b7287ec4625c4c018b5fffc865e2e72
Signed-off-by: default avatarArun KS <arunks@codeaurora.org>
[sudaraja@codeaurora.org: check limit with physical address of page]
Signed-off-by: default avatarSudarshan Rajagopalan <sudaraja@codeaurora.org>
parent f486fb89
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -189,6 +189,9 @@ extern u64 kimage_vaddr;
/* the offset between the kernel virtual and physical mappings */
/* the offset between the kernel virtual and physical mappings */
extern u64			kimage_voffset;
extern u64			kimage_voffset;


/* physical memory limit imposed by the booloader */
extern phys_addr_t bootloader_memory_limit;

static inline unsigned long kaslr_offset(void)
static inline unsigned long kaslr_offset(void)
{
{
	return kimage_vaddr - KIMAGE_VADDR;
	return kimage_vaddr - KIMAGE_VADDR;
+27 −0
Original line number Original line Diff line number Diff line
@@ -313,6 +313,7 @@ static void __init arm64_memory_present(void)
#endif
#endif


static phys_addr_t memory_limit = (phys_addr_t)ULLONG_MAX;
static phys_addr_t memory_limit = (phys_addr_t)ULLONG_MAX;
phys_addr_t bootloader_memory_limit;


/*
/*
 * Limit the memory size that was specified via FDT.
 * Limit the memory size that was specified via FDT.
@@ -395,6 +396,12 @@ void __init arm64_memblock_init(void)
		memblock_remove(0, memstart_addr);
		memblock_remove(0, memstart_addr);
	}
	}


	/*
	 * Save bootloader imposed memory limit before we overwirte
	 * memblock.
	 */
	bootloader_memory_limit = memblock_end_of_DRAM();

	/*
	/*
	 * Apply the memory limit if it was set. Since the kernel may be loaded
	 * 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
	 * high up in memory, add back the kernel region that must be accessible
@@ -835,4 +842,24 @@ int arch_remove_memory(u64 start, u64 size)
}
}


#endif /* CONFIG_MEMORY_HOTREMOVE */
#endif /* CONFIG_MEMORY_HOTREMOVE */
static int arm64_online_page(struct page *page)
{
	unsigned long phy_addr = page_to_phys(page);

	if (phy_addr + PAGE_SIZE >= bootloader_memory_limit)
		return -EINVAL;

	__online_page_set_limits(page);
	__online_page_increment_counters(page);
	__online_page_free(page);

	return 0;
}

static int __init arm64_memory_hotplug_init(void)
{
	set_online_page_callback(&arm64_online_page);
	return 0;
}
core_initcall(arm64_memory_hotplug_init);
#endif /* CONFIG_MEMORY_HOTPLUG */
#endif /* CONFIG_MEMORY_HOTPLUG */
+1 −1
Original line number Original line Diff line number Diff line
@@ -104,7 +104,7 @@ extern int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
	unsigned long *valid_start, unsigned long *valid_end);
	unsigned long *valid_start, unsigned long *valid_end);
extern void __offline_isolated_pages(unsigned long, unsigned long);
extern void __offline_isolated_pages(unsigned long, unsigned long);


typedef void (*online_page_callback_t)(struct page *page);
typedef int (*online_page_callback_t)(struct page *page);


extern int set_online_page_callback(online_page_callback_t callback);
extern int set_online_page_callback(online_page_callback_t callback);
extern int restore_online_page_callback(online_page_callback_t callback);
extern int restore_online_page_callback(online_page_callback_t callback);
+7 −5
Original line number Original line Diff line number Diff line
@@ -47,7 +47,7 @@
 * and restore_online_page_callback() for generic callback restore.
 * and restore_online_page_callback() for generic callback restore.
 */
 */


static void generic_online_page(struct page *page);
static int generic_online_page(struct page *page);


static online_page_callback_t online_page_callback = generic_online_page;
static online_page_callback_t online_page_callback = generic_online_page;
static DEFINE_MUTEX(online_page_callback_lock);
static DEFINE_MUTEX(online_page_callback_lock);
@@ -679,11 +679,12 @@ void __online_page_free(struct page *page)
}
}
EXPORT_SYMBOL_GPL(__online_page_free);
EXPORT_SYMBOL_GPL(__online_page_free);


static void generic_online_page(struct page *page)
static int generic_online_page(struct page *page)
{
{
	__online_page_set_limits(page);
	__online_page_set_limits(page);
	__online_page_increment_counters(page);
	__online_page_increment_counters(page);
	__online_page_free(page);
	__online_page_free(page);
	return 0;
}
}


static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
@@ -692,11 +693,12 @@ static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
	unsigned long i;
	unsigned long i;
	unsigned long onlined_pages = *(unsigned long *)arg;
	unsigned long onlined_pages = *(unsigned long *)arg;
	struct page *page;
	struct page *page;

	int ret;
	if (PageReserved(pfn_to_page(start_pfn)))
	if (PageReserved(pfn_to_page(start_pfn)))
		for (i = 0; i < nr_pages; i++) {
		for (i = 0; i < nr_pages; i++) {
			page = pfn_to_page(start_pfn + i);
			page = pfn_to_page(start_pfn + i);
			(*online_page_callback)(page);
			ret = (*online_page_callback)(page);
			if (!ret)
				onlined_pages++;
				onlined_pages++;
		}
		}