Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1529649ybj; Fri, 20 Sep 2019 12:00:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPPz9xh9MDYFeGHK4xMdSV8pB2MMR+YemdaRf71tI00LpWrL27FmQ3FWP7WC5T5a3aiEVH X-Received: by 2002:a17:906:244c:: with SMTP id a12mr20152732ejb.288.1569006018753; Fri, 20 Sep 2019 12:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569006018; cv=none; d=google.com; s=arc-20160816; b=iDz0xVXdfQEgOLoRleT/878qZGC1Abjs7+bow5RbyPsXjHVfaZ13fe/kq31WowIMMC 50eW0f9YlJsvTwKHgWR2odJxNOBt0GvXPvXKC1SP0sM6yQPW87NJGDROdFYogdC5tJMA yYSI2eZqlYUEhfkxvA4PftZi8gezdyUa1bZgMW5++mh4GO9zPww0jgFUaJnc2DXX/VZX cvAswSjzC4FkYhwz2zpAaSL6Bfo+fEDS3D0iPu5KIq2vAk1LdXepfzAp/qQ0+vsf+jIh bF51/4b+xoXoDoeFg27g3vTuHp53CQ0aw9Z+aO5bncvU2YGlx4xb+2HDVhfy//R87byv vw4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=3WET/T/cf1cDTtT/IPPjF72sp/U+IhCFWEcA8q7rDAg=; b=HtjmS8XWgouxr94K9ad3kwpl9ziWSaELTd23Xs3qJ61dVpVrUs9JgvUwSpqZUTH51B WZ6MSi+OBvGoiDgW9qP86NRhyo3m4hr6y+1INPuj326pWx70YJNn5K73yJa1930Y83Ph S0xtjsYC6ca/t0oooyMERLq6fQpOpWLifl6WcGMF+Z4WbZH4f1SPGWTZKonPY2vlSBOx 85VkpCEwkxu7RLYBj00hbuPs1i1FD5SxMB4g9gLO7kC3Rqlul1WOWob9tE5GpsdOuWR4 +vRq2X8gNJ6v1+PMjXQTiHNDHtFAhd/VjS+NYWCi0/A5naaf3+37eiF3kwybiqT2azfw JrPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m16si1676422ejn.371.2019.09.20.11.59.54; Fri, 20 Sep 2019 12:00:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437915AbfITJ0B (ORCPT + 99 others); Fri, 20 Sep 2019 05:26:01 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2693 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2408511AbfITJZh (ORCPT ); Fri, 20 Sep 2019 05:25:37 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 627ED2E94B45DE7D3E8F; Fri, 20 Sep 2019 17:25:34 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Fri, 20 Sep 2019 17:25:25 +0800 From: Jason Yan To: , , , , , , , , CC: , , , , , , , Jason Yan Subject: [PATCH v7 10/12] powerpc/fsl_booke/kaslr: dump out kernel offset information on panic Date: Fri, 20 Sep 2019 17:45:44 +0800 Message-ID: <20190920094546.44948-11-yanaijie@huawei.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190920094546.44948-1-yanaijie@huawei.com> References: <20190920094546.44948-1-yanaijie@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When kaslr is enabled, the kernel offset is different for every boot. This brings some difficult to debug the kernel. Dump out the kernel offset when panic so that we can easily debug the kernel. This code is derived from x86/arm64 which has similar functionality. Signed-off-by: Jason Yan Cc: Diana Craciun Cc: Michael Ellerman Cc: Christophe Leroy Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Nicholas Piggin Cc: Kees Cook Reviewed-by: Christophe Leroy Reviewed-by: Diana Craciun Tested-by: Diana Craciun --- arch/powerpc/include/asm/page.h | 5 +++++ arch/powerpc/kernel/setup-common.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 4d32d1b561d6..b34b9cdd91f1 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -317,6 +317,11 @@ struct vm_area_struct; extern unsigned long kernstart_virt_addr; +static inline unsigned long kaslr_offset(void) +{ + return kernstart_virt_addr - KERNELBASE; +} + #include #endif /* __ASSEMBLY__ */ #include diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 1f8db666468d..ba1a34ab218a 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -715,8 +715,28 @@ static struct notifier_block ppc_panic_block = { .priority = INT_MIN /* may not return; must be done last */ }; +/* + * Dump out kernel offset information on panic. + */ +static int dump_kernel_offset(struct notifier_block *self, unsigned long v, + void *p) +{ + pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n", + kaslr_offset(), KERNELBASE); + + return 0; +} + +static struct notifier_block kernel_offset_notifier = { + .notifier_call = dump_kernel_offset +}; + void __init setup_panic(void) { + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_offset() > 0) + atomic_notifier_chain_register(&panic_notifier_list, + &kernel_offset_notifier); + /* PPC64 always does a hard irq disable in its panic handler */ if (!IS_ENABLED(CONFIG_PPC64) && !ppc_md.panic) return; -- 2.17.2