Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6536805ybh; Thu, 8 Aug 2019 01:41:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkr/l2nj6vBMJmvAH7Md01vtnbUU+T+kBbOU1wR5uqfUSJUC6bqVeF8z6g/dRjeG7EVQzB X-Received: by 2002:a63:31c1:: with SMTP id x184mr12096759pgx.128.1565253689458; Thu, 08 Aug 2019 01:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565253689; cv=none; d=google.com; s=arc-20160816; b=tXarU4JEK8TNEx8Ygibg0LAOei7PAIWlDG1/qS+xlgYzkta4XWJ70IvB+eg8zfIHZk HXV+cbkStLf7vape7xmtWLK4R+ssNbCzOpRntTR94w/eWPH0qlac/rVEGy6jGDGVNifC B7Kvl+BdLU4D5NwcA6vW0xyCQmwuSf46iGbbwVYmo/biYUDJKFy+HbV7p2+awdqRDaMf ayB+Z2IKZHhf/fFZpLTUfIlti3r9WLGAzWcKK7wEUCq9n2Im+HkDyjW9sjyFIXSeGKe8 1IQayIOWM9d0B4cUKEuEyd+uLXijaw6FRLzgreAEUdjVIhufdh1BP1J5L+YOCnDEc37e qaeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=FYGO+HGzH5+oArXVY4BzxrGtkJ3Ab2wWt8ViU6OnYoY=; b=brNFq/r1FLkM5jWq3q+F6ReENn2IDNabRAFRNkEqNG+y3OIJHCricSO+Ih7aaLBPQk 3UWMQ8U7h8i2Q6ziN26oTlZGkuJrY4HknJdI+63GII1ZQ9gW5+wfFB4Xg5mkwlnnE2zB YLb0rVWWHoAcG9eRfnxU+Xl/m0DBMsQlbUPlVc5D0ocDntspheT2uthaqGn6D33SVkG0 kgR0L+Pvzy2W8B1VGVhDnyk1ql72ICo/sWesc9Cqt9LpLxesFWQPF100+zAvojBAnx1R FE3iDE5c+piWNVGJ9EZCt6Y2ZS+0sBS+GNOUiGeaydtXtiyVxQteMus2CsnZzQDd6wD2 lK2g== 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 t13si52525288pfh.245.2019.08.08.01.41.14; Thu, 08 Aug 2019 01:41:29 -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 S1731048AbfHHIjk (ORCPT + 99 others); Thu, 8 Aug 2019 04:39:40 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4220 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726187AbfHHIjk (ORCPT ); Thu, 8 Aug 2019 04:39:40 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E49C46160CF7EB186C3B; Thu, 8 Aug 2019 16:39:37 +0800 (CST) Received: from [127.0.0.1] (10.177.96.203) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Thu, 8 Aug 2019 16:39:27 +0800 Subject: Re: [PATCH v5 10/10] powerpc/fsl_booke/kaslr: dump out kernel offset information on panic To: Michael Ellerman , , , , , , , , CC: , , , , , , References: <20190807065706.11411-1-yanaijie@huawei.com> <20190807065706.11411-11-yanaijie@huawei.com> <87zhklt9eg.fsf@concordia.ellerman.id.au> From: Jason Yan Message-ID: <9113cc5b-0e89-f423-712a-79220af82b92@huawei.com> Date: Thu, 8 Aug 2019 16:39:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <87zhklt9eg.fsf@concordia.ellerman.id.au> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.96.203] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/8/7 21:03, Michael Ellerman wrote: > Jason Yan writes: >> 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. > > Some of this is taken from the arm64 version right? Please say so when > you copy other people's code. > No problem. Architectures like x86 or arm64 or s390 both have this similar code. I guess x86 is the first one. >> diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c >> index c4ed328a7b96..078fe3d76feb 100644 >> --- a/arch/powerpc/kernel/machine_kexec.c >> +++ b/arch/powerpc/kernel/machine_kexec.c >> @@ -86,6 +86,7 @@ void arch_crash_save_vmcoreinfo(void) >> VMCOREINFO_STRUCT_SIZE(mmu_psize_def); >> VMCOREINFO_OFFSET(mmu_psize_def, shift); >> #endif >> + vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset()); >> } > > There's no mention of that in the commit log. > > Please split it into a separate patch and describe what you're doing and > why. OK > >> diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c >> index 1f8db666468d..064075f02837 100644 >> --- a/arch/powerpc/kernel/setup-common.c >> +++ b/arch/powerpc/kernel/setup-common.c >> @@ -715,12 +715,31 @@ 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) >> { >> /* PPC64 always does a hard irq disable in its panic handler */ >> if (!IS_ENABLED(CONFIG_PPC64) && !ppc_md.panic) >> return; >> atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block); > >> + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_offset() > 0) >> + atomic_notifier_chain_register(&panic_notifier_list, >> + &kernel_offset_notifier); > > Don't you want to do that before the return above? > Eagle eye. This should not affected by the conditions above. >> } > > cheers > > . >