Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp1115655rwo; Sat, 22 Jul 2023 06:57:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlGmg+Mm92negpNuo/trEOs3VxIYAgu54IgkmjyYTw3iU4aN5vWIf24Wu0wVJm6F4oETFWBp X-Received: by 2002:a05:6a21:3806:b0:131:4808:d5a1 with SMTP id yi6-20020a056a21380600b001314808d5a1mr2900804pzb.28.1690034238520; Sat, 22 Jul 2023 06:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690034238; cv=none; d=google.com; s=arc-20160816; b=wdJtb3PfmzfZUaukp1I8MJWsSJ8urf7OHzHPXBKIiZ06OCttdG97w3/FWpcMJX8zlY Of5CMYMsbae7tkEMJFOSv5DcCBHlChEDEqNDU2kq8th4WoP9CMESWpl7uKyDYi3QrDjo m5KUG2MSD+M6nl7nlRaPQewifIQtC26atffeV+VQNU6TWc10hsZxoAtSOaD9gZADxkc/ 1IN9tzx6XljOFq/OKFIgMy8Zjc7GqmeSwGlLxgcv7c0Cuszu8QoFZbWRtNiSqv0M5Oi5 u28ra6KcP5LQttvXK+R3SVRjaKJREl8f29PdjBlrk06ZNszynJ0c3Zd8gu6K9PRzW7fN Aaiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cxS6XaVGyfGeiOx9hXopxfMKjoMTvLr9eO536Fwx3rg=; fh=vrcH9zYij+n8XlRcc4iGdnMCWhiaadeqBO/ZfP9tKqU=; b=qfVBu2PfRXtJmgx4BJFZBeNwQwUI6hdWrx4HE6Ovbwb+RGSQ7uXYrlFm05JTRwfgIN Hdjrjm7sPZ3kDl/EZzopKSskfUt2iq7SsFEbUJZqRecvTvMwXjl6p7Vf00Y4aPvTa9Bx dpoZKIw6Ln/P97ZM4xS+5OmBvn7tgy9NEyqxLMyBBaLMKq5aOOKNIcOqlXzPB13jB8UL 8vkXLksdC1AiGVNPEKRMctDFiNxa0nUfOWo1nWJ+DD1QCKwF+QcYdR1kWlUOD9vNPGvC +omp6hnYVwZtYi3fY8NK/kJ4kOo43vGz2vJBgNx5N05WyJ6XBaNRMg+nDhY6Aj3Jti3F eMzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ubHJsOak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a637518000000b00553851380besi5355463pgc.397.2023.07.22.06.57.06; Sat, 22 Jul 2023 06:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ubHJsOak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbjGVMlC (ORCPT + 99 others); Sat, 22 Jul 2023 08:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjGVMlB (ORCPT ); Sat, 22 Jul 2023 08:41:01 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8709510F5 for ; Sat, 22 Jul 2023 05:41:00 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso26187735e9.0 for ; Sat, 22 Jul 2023 05:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690029659; x=1690634459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cxS6XaVGyfGeiOx9hXopxfMKjoMTvLr9eO536Fwx3rg=; b=ubHJsOakNyi6ANYSEfY1jfibGRvwTsZC06/UPIVijfttHEqAybPhZWsu6n+csh9e0l KaIDc/ee0jK34IeIOvDhwfUvuorT/jUT+Lc3zNxBn+AFfH+l6yOjUQS6Rd2/e9MeozK8 jR6YwmPhQ5kiYHNZBD01SLTO+1i4GVi5HibdyOu1QDcm7enIRNuwvCmftfPhFB4ORToz C3U1P2sZ72Wp31FcMQjOrO914SUZBYVecMSN8Qop2CKKpKdGOgRcP2cjNUw+bUa13u7l pcgT1XbQw+oZgWUOaur9xb2fkMtbRtf+60eB0JYS02Rjcnqsw6yCAIkTP8eryqK7lSVB wLfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690029659; x=1690634459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cxS6XaVGyfGeiOx9hXopxfMKjoMTvLr9eO536Fwx3rg=; b=UrUTupo8rYF1kMDTLPXudvr2BjMtXjAns7SIOZBJ4+XWNk8aZbS94IIgpNFLgpiz4w HvwAQX1CO4TPqmDRvUmNCzC72Gnb4YhuBu46Hthwk+ZpSsuLllY2wCr9dMrgg29jRvB3 i5lfw+72yuPfXSVM9+CastH003omgWQrbam9uzxaQyPTfMna+RiLbUteYyW3m+IsX0sZ Y1Gk+DkbumlZ0S2e2fXjCEoEhlzPGpJYsCkFOFg9x5ZoYH4cu9qFD/flvPAm+4cLiMYa VV2ckfo5hacgJMXbwbE1CEXsoFcTkTX8Fg0IUyaoaFVTrBa1RLzfFRoCuUXNI1jAPRuc st/A== X-Gm-Message-State: ABy/qLYqfBkt0ZSLn3kD/kmbnCz1BIR7rJHeDH8XBQq1kghoVOmKslE7 Mo3s2EZARYY3s2ITRM6JwyT1Gg== X-Received: by 2002:a7b:ca52:0:b0:3f6:1474:905 with SMTP id m18-20020a7bca52000000b003f614740905mr3713142wml.29.1690029658973; Sat, 22 Jul 2023 05:40:58 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id p24-20020a1c7418000000b003fc07e17d4esm7988080wmc.2.2023.07.22.05.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 05:40:58 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ard Biesheuvel , Kees Cook , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Alexandre Ghiti , Zong Li Subject: [PATCH v6 2/5] riscv: Dump out kernel offset information on panic Date: Sat, 22 Jul 2023 14:38:47 +0200 Message-Id: <20230722123850.634544-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230722123850.634544-1-alexghiti@rivosinc.com> References: <20230722123850.634544-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dump out the KASLR virtual kernel offset when panic to help debug kernel. Signed-off-by: Zong Li Signed-off-by: Alexandre Ghiti --- arch/riscv/kernel/setup.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 971fe776e2f8..0fb5a26ca4cc 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -341,3 +342,27 @@ void free_initmem(void) free_initmem_default(POISON_FREE_INITMEM); } + +static int dump_kernel_offset(struct notifier_block *self, + unsigned long v, void *p) +{ + pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n", + kernel_map.virt_offset, + KERNEL_LINK_ADDR); + + return 0; +} + +static struct notifier_block kernel_offset_notifier = { + .notifier_call = dump_kernel_offset +}; + +static int __init register_kernel_offset_dumper(void) +{ + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) + atomic_notifier_chain_register(&panic_notifier_list, + &kernel_offset_notifier); + + return 0; +} +device_initcall(register_kernel_offset_dumper); -- 2.39.2