From patchwork Tue Oct 20 18:54:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 55337 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 7ED9123024 for ; Tue, 20 Oct 2015 19:02:02 +0000 (UTC) Received: by wikv3 with SMTP id v3sf12748226wik.1 for ; Tue, 20 Oct 2015 12:02:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:subject:from:to:date :in-reply-to:references:mime-version:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe:cc :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=XPVAxI5G5tUoNqi2+rfpliu+Xxl+0mSsS30j9yaayHU=; b=ZQFTHeDesICwqUwikEBEA+WYfj5OZ1dpMYGmrtFm9GFVhVXOP8zqjsGnCoKG365/Kc YogPxBIIui6w6LnUxwJLrAmrVCy/+5UrtK4bFMFho9hzafufpiZgetxz9Doy6GQBHFzD TuWmetQ19WSCy8q7OTIUFKIeuCd7WWGZ2FvkxXkUbH5XWs5DImwGEdBUJBF2XAZjo/fy +luP4uXucR4bQhZumP9m0M3fwHHRFuCHxkIHVE3jH66qXI3X8oSdg8FTwhvjuxqmqGAO g8tyCr0iB2LkYz/nViMne+nPvLHrVywm0ao1skcg9OEEz2ABkfiCJ0pIs30DjmwJOeOj t/1A== X-Gm-Message-State: ALoCoQk7ttTxgf4dWEToZlBgSAPgQj+pe6kQdU02WG1RljEqSfMXfz6mLUKKt/Pn1wcLezQXB04u X-Received: by 10.194.248.131 with SMTP id ym3mr1017097wjc.7.1445367719216; Tue, 20 Oct 2015 12:01:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.206.211 with SMTP id e202ls119073lfg.109.gmail; Tue, 20 Oct 2015 12:01:58 -0700 (PDT) X-Received: by 10.112.198.69 with SMTP id ja5mr1696701lbc.106.1445367718588; Tue, 20 Oct 2015 12:01:58 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id rm8si3455142lbb.16.2015.10.20.12.01.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Oct 2015 12:01:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbwb3 with SMTP id wb3so22508473lbb.1 for ; Tue, 20 Oct 2015 12:01:58 -0700 (PDT) X-Received: by 10.112.17.34 with SMTP id l2mr2885954lbd.117.1445367718313; Tue, 20 Oct 2015 12:01:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2254193lbq; Tue, 20 Oct 2015 12:01:57 -0700 (PDT) X-Received: by 10.66.147.104 with SMTP id tj8mr5577863pab.125.1445367717174; Tue, 20 Oct 2015 12:01:57 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id yf8si7138971pbc.129.2015.10.20.12.01.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Oct 2015 12:01:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zoc9U-00081u-G4; Tue, 20 Oct 2015 19:00:52 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zoc9M-0007tX-Nk; Tue, 20 Oct 2015 19:00:44 +0000 Received: from 107-1-141-74-ip-static.hfc.comcastbusiness.net ([107.1.141.74] helo=[192.168.252.189]) by casper.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zoc30-0004dp-WB; Tue, 20 Oct 2015 18:54:11 +0000 Message-ID: <1445367246.30908.78.camel@infradead.org> Subject: [PATCH v10.1 12/16] arm64: kdump: implement machine_crash_shutdown() From: Geoff Levand To: Catalin Marinas , Will Deacon Date: Tue, 20 Oct 2015 11:54:06 -0700 In-Reply-To: <10adbaf4a069aabc3d774963cf6613dfa46f923d.1445297709.git.geoff@infradead.org> References: <10adbaf4a069aabc3d774963cf6613dfa46f923d.1445297709.git.geoff@infradead.org> X-Mailer: Evolution 3.16.5-1ubuntu1 Mime-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: Mark Rutland , AKASHI@infradead.org, marc.zyngier@arm.com, kexec@lists.infradead.org, Takahiro , christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: geoff@infradead.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: AKASHI Takahiro kdump calls machine_crash_shutdown() to shut down non-boot cpus and save registers' status in per-cpu ELF notes before starting the crash dump kernel. See kernel_kexec(). ipi_cpu_stop() is a bit modified and used to support this behavior. Signed-off-by: AKASHI Takahiro --- v10.1: Fixed: crash dump kernel won't be able to boot if a kvm guest is running at crash. This is because we don't have any chance to reset EL2 mode at crash and so "switch to EL2" in cpu_reset fails. arch/arm64/include/asm/kexec.h | 34 +++++++++++++++++++++++++++++++++- arch/arm64/kernel/machine_kexec.c | 32 ++++++++++++++++++++++++++++++-- arch/arm64/kernel/smp.c | 16 ++++++++++++++-- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 46d63cd..555a955 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -30,6 +30,8 @@ #if !defined(__ASSEMBLY__) +extern bool in_crash_kexec; + /** * crash_setup_regs() - save registers for the panic kernel * @@ -40,7 +42,37 @@ static inline void crash_setup_regs(struct pt_regs *newregs, struct pt_regs *oldregs) { - /* Empty routine needed to avoid build errors. */ + if (oldregs) { + memcpy(newregs, oldregs, sizeof(*newregs)); + } else { + __asm__ __volatile__ ( + "stp x0, x1, [%3, #16 * 0]\n" + "stp x2, x3, [%3, #16 * 1]\n" + "stp x4, x5, [%3, #16 * 2]\n" + "stp x6, x7, [%3, #16 * 3]\n" + "stp x8, x9, [%3, #16 * 4]\n" + "stp x10, x11, [%3, #16 * 5]\n" + "stp x12, x13, [%3, #16 * 6]\n" + "stp x14, x15, [%3, #16 * 7]\n" + "stp x16, x17, [%3, #16 * 8]\n" + "stp x18, x19, [%3, #16 * 9]\n" + "stp x20, x21, [%3, #16 * 10]\n" + "stp x22, x23, [%3, #16 * 11]\n" + "stp x24, x25, [%3, #16 * 12]\n" + "stp x26, x27, [%3, #16 * 13]\n" + "stp x28, x29, [%3, #16 * 14]\n" + "str x30, [%3, #16 * 15]\n" + "mov %0, sp\n" + "adr %1, 1f\n" + "mrs %2, spsr_el1\n" + "1:" + : "=r" (newregs->sp), + "=r" (newregs->pc), + "=r" (newregs->pstate) + : "r" (&newregs->regs) + : "memory" + ); + } } #endif /* !defined(__ASSEMBLY__) */ diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 362f719..8595d43 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -9,6 +9,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -28,6 +29,8 @@ extern unsigned long arm64_kexec_kimage_start_offset; static unsigned long kimage_head; static unsigned long kimage_start; +bool in_crash_kexec; + /** * kexec_is_dtb - Helper routine to check the device tree header signature. */ @@ -121,7 +124,7 @@ static void soft_restart(unsigned long addr) { setup_mm_for_reboot(); cpu_soft_restart(virt_to_phys(cpu_reset), addr, - is_hyp_mode_available()); + (in_crash_kexec ? 0 : is_hyp_mode_available())); BUG(); /* Should never get here. */ } @@ -198,7 +201,32 @@ void machine_kexec(struct kimage *image) soft_restart(reboot_code_buffer_phys); } +/** + * machine_crash_shutdown - shutdown non-boot cpus and save registers + */ void machine_crash_shutdown(struct pt_regs *regs) { - /* Empty routine needed to avoid build errors. */ + struct pt_regs dummy_regs; + int cpu; + + local_irq_disable(); + + in_crash_kexec = true; + + /* + * clear and initialize the per-cpu info. This is necessary + * because, otherwise, slots for offline cpus would never be + * filled up. See smp_send_stop(). + */ + memset(&dummy_regs, 0, sizeof(dummy_regs)); + for_each_possible_cpu(cpu) + crash_save_cpu(&dummy_regs, cpu); + + /* shutdown non-boot cpus */ + smp_send_stop(); + + /* for boot cpu */ + crash_save_cpu(regs, smp_processor_id()); + + pr_info("Loading crashdump kernel...\n"); } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index dbdaacd..88aec66 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,8 @@ #include #include +#include "cpu-reset.h" + #define CREATE_TRACE_POINTS #include @@ -679,8 +682,12 @@ static DEFINE_RAW_SPINLOCK(stop_lock); /* * ipi_cpu_stop - handle IPI from smp_send_stop() */ -static void ipi_cpu_stop(unsigned int cpu) +static void ipi_cpu_stop(unsigned int cpu, struct pt_regs *regs) { +#ifdef CONFIG_KEXEC + /* printing messages may slow down the shutdown. */ + if (!in_crash_kexec) +#endif if (system_state == SYSTEM_BOOTING || system_state == SYSTEM_RUNNING) { raw_spin_lock(&stop_lock); @@ -693,6 +700,11 @@ static void ipi_cpu_stop(unsigned int cpu) local_irq_disable(); +#ifdef CONFIG_KEXEC + if (in_crash_kexec) + crash_save_cpu(regs, cpu); +#endif /* CONFIG_KEXEC */ + while (1) cpu_relax(); } @@ -723,7 +735,7 @@ void handle_IPI(int ipinr, struct pt_regs *regs) case IPI_CPU_STOP: irq_enter(); - ipi_cpu_stop(cpu); + ipi_cpu_stop(cpu, regs); irq_exit(); break;