From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19362C433FF for ; Wed, 7 Aug 2019 13:03:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9D1D21BE3 for ; Wed, 7 Aug 2019 13:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388092AbfHGNDm (ORCPT ); Wed, 7 Aug 2019 09:03:42 -0400 Received: from ozlabs.org ([203.11.71.1]:39343 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387981AbfHGNDm (ORCPT ); Wed, 7 Aug 2019 09:03:42 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 463WsR3f5pz9sNx; Wed, 7 Aug 2019 23:03:39 +1000 (AEST) From: Michael Ellerman To: Jason Yan , linuxppc-dev@lists.ozlabs.org, diana.craciun@nxp.com, christophe.leroy@c-s.fr, benh@kernel.crashing.org, paulus@samba.org, npiggin@gmail.com, keescook@chromium.org, kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, wangkefeng.wang@huawei.com, yebin10@huawei.com, thunder.leizhen@huawei.com, jingxiangfeng@huawei.com, fanchengyang@huawei.com, zhaohongjiang@huawei.com, Jason Yan Subject: Re: [PATCH v5 10/10] powerpc/fsl_booke/kaslr: dump out kernel offset information on panic In-Reply-To: <20190807065706.11411-11-yanaijie@huawei.com> References: <20190807065706.11411-1-yanaijie@huawei.com> <20190807065706.11411-11-yanaijie@huawei.com> Date: Wed, 07 Aug 2019 23:03:35 +1000 Message-ID: <87zhklt9eg.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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. > 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? > } cheers