Petr Tesarik b91dd8
From: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Petr Tesarik b91dd8
Subject: s390/kdump: fix out-of-memory with PCI
Petr Tesarik b91dd8
Patch-mainline: never, fixed upstream with larger code rework
Petr Tesarik b91dd8
References: bsc#1182257 LTC#191375
Petr Tesarik b91dd8
Petr Tesarik b91dd8
Description:   s390/kdump: fix out-of-memory with PCI
Petr Tesarik b91dd8
Symptom:       The kdump kernel runs out of memory when allocating memory for
Petr Tesarik b91dd8
               PCI IOMMU bitmaps in zpci_dma_init_device().
Petr Tesarik b91dd8
Problem:       The kdump kernel does not properly restrict memory_end, which
Petr Tesarik b91dd8
               the PCI code uses to calculate the size of the IOMMU bitmap, and
Petr Tesarik b91dd8
               too much memory will be allocated.
Petr Tesarik b91dd8
Solution:      Properly restrict memory_end to the available memory of the
Petr Tesarik b91dd8
               kdump kernel (OLDMEM_SIZE), similar to how it would be done with
Petr Tesarik b91dd8
               a "mem=" kernel parameter.
Petr Tesarik b91dd8
               This was fixed inadvertently by an unrelated upstream commit
Petr Tesarik b91dd8
               73045a08cf55 ("s390: unify identity mapping limits handling").
Petr Tesarik b91dd8
               But that commit cannot easily be backported to distribution
Petr Tesarik b91dd8
               levels, so only the part that fixes this bug will be submitted.
Petr Tesarik b91dd8
Reproduction:  Try kdump on a system with large memory size and many PCI
Petr Tesarik b91dd8
               functions.
Petr Tesarik b91dd8
Petr Tesarik b91dd8
Petr Tesarik b91dd8
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Petr Tesarik b91dd8
Acked-by: Petr Tesarik <ptesarik@suse.com>
Petr Tesarik b91dd8
---
Petr Tesarik b91dd8
 arch/s390/boot/ipl_parm.c |    2 ++
Petr Tesarik b91dd8
 1 file changed, 2 insertions(+)
Petr Tesarik b91dd8
Petr Tesarik b91dd8
--- a/arch/s390/boot/ipl_parm.c
Petr Tesarik b91dd8
+++ b/arch/s390/boot/ipl_parm.c
Petr Tesarik b91dd8
@@ -243,6 +243,8 @@ void setup_memory_end(void)
Petr Tesarik b91dd8
 #ifdef CONFIG_CRASH_DUMP
Petr Tesarik b91dd8
 	if (OLDMEM_BASE) {
Petr Tesarik b91dd8
 		kaslr_enabled = 0;
Petr Tesarik b91dd8
+		memory_end = min(memory_end ?: OLDMEM_SIZE, OLDMEM_SIZE);
Petr Tesarik b91dd8
+		memory_end_set = 1;
Petr Tesarik b91dd8
 	} else if (ipl_block_valid &&
Petr Tesarik b91dd8
 		   ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
Petr Tesarik b91dd8
 		   ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP) {