From 76d71ebddf23e8195dd5f7889cb2844530689907 Mon Sep 17 00:00:00 2001 From: Petr Tesarik Date: Tue, 29 Nov 2011 15:01:51 +0100 Subject: [PATCH 1/4] [IA64] Merge overlapping reserved regions at boot While working on the upcoming SLES11 SP2, I ran into an issue with booting the panic kernel on a kernel crash. In the first iteration I found out that the initial register backing store gets overwritten with zeroes, causing a kernel crash shortly afterwards. Further investigation revealed that rsvd_region[] contains overlapping entries: find_memmap_space() returns a pointer which lies between KERNEL_START and _end. This is correct with the EFI memmap as patched by the kexec purgatory code. That code removes vmlinux LOAD segments from the usable map, but there is a pretty large hole between the gate section and the per-cpu section. This happens because reserve_memory() blindly marks [KERNEL_START, __end] as reserved, even though there is a free block in the middle in the kexec case because it noticed a large gap between sections and modified the efi_memory_map to account for this. Signed-off-by: Petr Tesarik Signed-off-by: Tony Luck --- arch/ia64/kernel/setup.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 5e2c72498c51..cd57d7312de0 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -220,6 +220,23 @@ sort_regions (struct rsvd_region *rsvd_region, int max) } } +/* merge overlaps */ +static int __init +merge_regions (struct rsvd_region *rsvd_region, int max) +{ + int i; + for (i = 1; i < max; ++i) { + if (rsvd_region[i].start >= rsvd_region[i-1].end) + continue; + if (rsvd_region[i].end > rsvd_region[i-1].end) + rsvd_region[i-1].end = rsvd_region[i].end; + --max; + memmove(&rsvd_region[i], &rsvd_region[i+1], + (max - i) * sizeof(struct rsvd_region)); + } + return max; +} + /* * Request address space for all standard resources */ @@ -270,6 +287,7 @@ static void __init setup_crashkernel(unsigned long total, int *n) if (ret == 0 && size > 0) { if (!base) { sort_regions(rsvd_region, *n); + *n = merge_regions(rsvd_region, *n); base = kdump_find_rsvd_region(size, rsvd_region, *n); } @@ -373,6 +391,7 @@ reserve_memory (void) BUG_ON(IA64_MAX_RSVD_REGIONS + 1 < n); sort_regions(rsvd_region, num_rsvd_regions); + num_rsvd_regions = merge_regions(rsvd_region, num_rsvd_regions); } From ac0d1a48d8b18c4808ab73d990b83bb032f21c25 Mon Sep 17 00:00:00 2001 From: Thomas Meyer Date: Sat, 19 Nov 2011 12:27:39 +0100 Subject: [PATCH 2/4] ia64: tioca: Use kmemdup rather than duplicating its implementation The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer Signed-off-by: Tony Luck --- arch/ia64/sn/pci/tioca_provider.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/ia64/sn/pci/tioca_provider.c b/arch/ia64/sn/pci/tioca_provider.c index 642451e770ea..e77c477245fd 100644 --- a/arch/ia64/sn/pci/tioca_provider.c +++ b/arch/ia64/sn/pci/tioca_provider.c @@ -600,11 +600,11 @@ tioca_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont * Allocate kernel bus soft and copy from prom. */ - tioca_common = kzalloc(sizeof(struct tioca_common), GFP_KERNEL); + tioca_common = kmemdup(prom_bussoft, sizeof(struct tioca_common), + GFP_KERNEL); if (!tioca_common) return NULL; - memcpy(tioca_common, prom_bussoft, sizeof(struct tioca_common)); tioca_common->ca_common.bs_base = (unsigned long) ioremap(REGION_OFFSET(tioca_common->ca_common.bs_base), sizeof(struct tioca_common)); From b82a3ecdc54465c792326522d804d2eebaae9a23 Mon Sep 17 00:00:00 2001 From: Thomas Meyer Date: Thu, 17 Nov 2011 23:43:40 +0100 Subject: [PATCH 3/4] ia64: sn: Use kmemdup rather than duplicating its implementation The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer Signed-off-by: Tony Luck --- arch/ia64/sn/kernel/irq.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/ia64/sn/kernel/irq.c b/arch/ia64/sn/kernel/irq.c index 485c42d97e83..dfac09ab027a 100644 --- a/arch/ia64/sn/kernel/irq.c +++ b/arch/ia64/sn/kernel/irq.c @@ -150,12 +150,11 @@ struct sn_irq_info *sn_retarget_vector(struct sn_irq_info *sn_irq_info, * PROM does not support SAL_INTR_REDIRECT, or it failed. * Revert to old method. */ - new_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_ATOMIC); + new_irq_info = kmemdup(sn_irq_info, sizeof(struct sn_irq_info), + GFP_ATOMIC); if (new_irq_info == NULL) return NULL; - memcpy(new_irq_info, sn_irq_info, sizeof(struct sn_irq_info)); - /* Free the old PROM new_irq_info structure */ sn_intr_free(local_nasid, local_widget, new_irq_info); unregister_intr_pda(new_irq_info); From a4b1d1b3619ee2fac40cdf5ca86a4758e45b9358 Mon Sep 17 00:00:00 2001 From: Thomas Meyer Date: Sat, 19 Nov 2011 12:26:05 +0100 Subject: [PATCH 4/4] ia64: pcibr: Use kmemdup rather than duplicating its implementation The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer Signed-off-by: Tony Luck --- arch/ia64/sn/pci/pcibr/pcibr_provider.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/ia64/sn/pci/pcibr/pcibr_provider.c b/arch/ia64/sn/pci/pcibr/pcibr_provider.c index 5698f29d5add..8886a0bc4a11 100644 --- a/arch/ia64/sn/pci/pcibr/pcibr_provider.c +++ b/arch/ia64/sn/pci/pcibr/pcibr_provider.c @@ -127,12 +127,11 @@ pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont * Allocate kernel bus soft and copy from prom. */ - soft = kmalloc(sizeof(struct pcibus_info), GFP_KERNEL); + soft = kmemdup(prom_bussoft, sizeof(struct pcibus_info), GFP_KERNEL); if (!soft) { return NULL; } - memcpy(soft, prom_bussoft, sizeof(struct pcibus_info)); soft->pbi_buscommon.bs_base = (unsigned long) ioremap(REGION_OFFSET(soft->pbi_buscommon.bs_base), sizeof(struct pic));