summaryrefslogtreecommitdiff
path: root/arch/s390/boot
diff options
context:
space:
mode:
authorVasily Gorbik <gor@linux.ibm.com>2023-01-27 19:08:29 +0300
committerHeiko Carstens <hca@linux.ibm.com>2023-02-06 13:13:55 +0300
commit8382c963249dafcbe809dea307c2de16d5645579 (patch)
tree688302288abea53f10fdf777f7510a31b4d70ea2 /arch/s390/boot
parent3615d01114047ffce3a0942c21e6402c7b49bb3f (diff)
downloadlinux-8382c963249dafcbe809dea307c2de16d5645579.tar.xz
s390/boot: avoid page tables memory in kaslr
If kernel is build without KASAN support there is a chance that kernel image is going to be positioned by KASLR code to overlap with identity mapping page tables. When kernel is build with KASAN support enabled memory which is potentially going to be used for page tables and KASAN shadow mapping is accounted for in KASLR with the use of kasan_estimate_memory_needs(). Split this function and introduce vmem_estimate_memory_needs() to cover decompressor's vmem identity mapping page tables. Fixes: bb1520d581a3 ("s390/mm: start kernel with DAT enabled") Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Diffstat (limited to 'arch/s390/boot')
-rw-r--r--arch/s390/boot/boot.h1
-rw-r--r--arch/s390/boot/kaslr.c6
-rw-r--r--arch/s390/boot/vmem.c7
3 files changed, 12 insertions, 2 deletions
diff --git a/arch/s390/boot/boot.h b/arch/s390/boot/boot.h
index e91bbb004efb..ed85b144119a 100644
--- a/arch/s390/boot/boot.h
+++ b/arch/s390/boot/boot.h
@@ -46,6 +46,7 @@ void sclp_early_setup_buffer(void);
void print_pgm_check_info(void);
unsigned long get_random_base(unsigned long safe_addr);
void setup_vmem(unsigned long asce_limit);
+unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total);
void __printf(1, 2) decompressor_printk(const char *fmt, ...);
void error(char *m);
diff --git a/arch/s390/boot/kaslr.c b/arch/s390/boot/kaslr.c
index bbf6860ebc45..9cab7bbbfd18 100644
--- a/arch/s390/boot/kaslr.c
+++ b/arch/s390/boot/kaslr.c
@@ -172,16 +172,18 @@ static unsigned long position_to_address(unsigned long pos, unsigned long kernel
unsigned long get_random_base(unsigned long safe_addr)
{
+ unsigned long online_mem_total = get_mem_detect_online_total();
unsigned long memory_limit = get_mem_detect_end();
unsigned long base_pos, max_pos, kernel_size;
int i;
/*
* Avoid putting kernel in the end of physical memory
- * which kasan will use for shadow memory and early pgtable
- * mapping allocations.
+ * which vmem and kasan code will use for shadow memory and
+ * pgtable mapping allocations.
*/
memory_limit -= kasan_estimate_memory_needs(memory_limit);
+ memory_limit -= vmem_estimate_memory_needs(online_mem_total);
safe_addr = ALIGN(safe_addr, THREAD_SIZE);
kernel_size = vmlinux.image_size + vmlinux.bss_size;
diff --git a/arch/s390/boot/vmem.c b/arch/s390/boot/vmem.c
index 82ef57827042..4e54357ccd00 100644
--- a/arch/s390/boot/vmem.c
+++ b/arch/s390/boot/vmem.c
@@ -269,3 +269,10 @@ void setup_vmem(unsigned long asce_limit)
init_mm.context.asce = S390_lowcore.kernel_asce;
}
+
+unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total)
+{
+ unsigned long pages = DIV_ROUND_UP(online_mem_total, PAGE_SIZE);
+
+ return DIV_ROUND_UP(pages, _PAGE_ENTRIES) * _PAGE_TABLE_SIZE * 2;
+}