From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S268184AbUHQMMN (ORCPT ); Tue, 17 Aug 2004 08:12:13 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S268202AbUHQMLb (ORCPT ); Tue, 17 Aug 2004 08:11:31 -0400 Received: from e31.co.us.ibm.com ([32.97.110.129]:42391 "EHLO e31.co.us.ibm.com") by vger.kernel.org with ESMTP id S268188AbUHQMHe (ORCPT ); Tue, 17 Aug 2004 08:07:34 -0400 Date: Tue, 17 Aug 2004 17:37:17 +0530 From: Hariprasad Nellitheertha To: linux-kernel@vger.kernel.org, fastboot@osdl.org Cc: akpm@osdl.org, Suparna Bhattacharya , mbligh@aracnet.com, litke@us.ibm.com, ebiederm@xmission.com Subject: Re: [PATCH][2/6]Memory preserving reboot using kexec Message-ID: <20040817120717.GC3916@in.ibm.com> Reply-To: hari@in.ibm.com References: <20040817120239.GA3916@in.ibm.com> <20040817120531.GB3916@in.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="1UWUbFP1cBYEclgG" Content-Disposition: inline In-Reply-To: <20040817120531.GB3916@in.ibm.com> User-Agent: Mutt/1.4.1i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org --1UWUbFP1cBYEclgG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Regards, Hari -- Hariprasad Nellitheertha Linux Technology Center India Software Labs IBM India, Bangalore --1UWUbFP1cBYEclgG Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="kd-reb-268.patch" This patch contains the code that does the memory preserving reboot. It copies over the first CRASH_BACKUP_SIZE amount of memory into a backup region before handing over to kexec. Signed off by Hariprasad Nellitheertha Signed off by Adam Litke --- linux-2.6.8.1-hari/arch/i386/Kconfig | 22 +++++++++++ linux-2.6.8.1-hari/arch/i386/kernel/machine_kexec.c | 31 +++++++++++++++ linux-2.6.8.1-hari/arch/i386/kernel/setup.c | 11 +++++ linux-2.6.8.1-hari/include/asm-i386/crash_dump.h | 39 ++++++++++++++++++++ linux-2.6.8.1-hari/include/linux/bootmem.h | 1 linux-2.6.8.1-hari/include/linux/crash_dump.h | 27 +++++++++++++ linux-2.6.8.1-hari/kernel/panic.c | 6 +++ linux-2.6.8.1-hari/mm/bootmem.c | 5 ++ 8 files changed, 142 insertions(+) diff -puN arch/i386/Kconfig~kd-reb-268 arch/i386/Kconfig --- linux-2.6.8.1/arch/i386/Kconfig~kd-reb-268 2004-08-17 17:04:35.000000000 +0530 +++ linux-2.6.8.1-hari/arch/i386/Kconfig 2004-08-17 17:05:03.000000000 +0530 @@ -865,6 +865,28 @@ config REGPARM generate incorrect output with certain kernel constructs when -mregparm=3 is used. +config CRASH_DUMP + bool "kernel crash dumps (EXPERIMENTAL)" + depends on KEXEC + help + Generate crash dump using kexec. + +config BACKUP_BASE + int "location of the crash dumps backup region" + depends on CRASH_DUMP + default 128 + help + Offset of backup region in terms of MB. Change this if you want + to modify the location of the crash dumps backup region. + +config BACKUP_SIZE + int "Size of the crash dumps backup region" + depends on CRASH_DUMP + range 16 64 + default 16 + help + The size of the backup region, in MB. This is also the size of the + memory that will be used to boot the second kernel after a crash. endmenu diff -puN arch/i386/kernel/machine_kexec.c~kd-reb-268 arch/i386/kernel/machine_kexec.c --- linux-2.6.8.1/arch/i386/kernel/machine_kexec.c~kd-reb-268 2004-08-17 17:04:35.000000000 +0530 +++ linux-2.6.8.1-hari/arch/i386/kernel/machine_kexec.c 2004-08-17 17:05:03.000000000 +0530 @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include static void set_idt(void *newidt, __u16 limit) @@ -76,6 +78,28 @@ const extern unsigned int relocate_new_k extern void use_mm(struct mm_struct *mm); /* + * We are going to do a memory preserving reboot. So, we copy over the + * first xxMB of memory into a backup location. + */ +void __relocate_base_mem(unsigned long backup_addr, unsigned long backup_size) +{ + unsigned long pfn, pfn_max; + void *src_addr, *dest_addr; + struct page *page; + + pfn_max = backup_size >> PAGE_SHIFT; + for (pfn = 0; pfn < pfn_max; pfn++) { + src_addr = phys_to_virt(pfn << PAGE_SHIFT); + dest_addr = backup_addr + src_addr; + if (!pfn_valid(pfn)) + continue; + page = pfn_to_page(pfn); + if (PageReserved(page)) + copy_page(dest_addr, src_addr); + } +} + +/* * Do not allocate memory (or fail in any way) in machine_kexec(). * We are past the point of no return, committed to rebooting now. */ @@ -94,6 +118,13 @@ void machine_kexec(struct kimage *image) reboot_code_buffer = page_to_pfn(image->reboot_code_pages) << PAGE_SHIFT; indirection_page = image->head & PAGE_MASK; + /* + * If we are here to do a crash dump, save the memory from + * 0-16MB before we copy over the kexec kernel image. Otherwise + * our dump will show the wrong kernel entirely. + */ + relocate_base_mem(); + /* copy it out */ memcpy((void *)reboot_code_buffer, relocate_new_kernel, relocate_new_kernel_size); diff -puN arch/i386/kernel/setup.c~kd-reb-268 arch/i386/kernel/setup.c --- linux-2.6.8.1/arch/i386/kernel/setup.c~kd-reb-268 2004-08-17 17:04:35.000000000 +0530 +++ linux-2.6.8.1-hari/arch/i386/kernel/setup.c 2004-08-17 17:05:03.000000000 +0530 @@ -39,6 +39,7 @@ #include #include #include +#include #include