From patchwork Thu Jul 13 15:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 119973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1902033vqm; Thu, 13 Jul 2023 08:28:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGv7Tau7PreNLDdH7/j+1vaepkjaC5X9j5CaVSez/MpFSzmcrOsPvIggJbeGtZMUEAQsdia X-Received: by 2002:a2e:9691:0:b0:2b6:3651:f12f with SMTP id q17-20020a2e9691000000b002b63651f12fmr1735724lji.3.1689262081312; Thu, 13 Jul 2023 08:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689262081; cv=none; d=google.com; s=arc-20160816; b=u4seKcrUW91G62G2/2gEBsIMuvPI6HO8YxSSylzRfkg3xE3ZMPmFyH3RseWYtBzefo eFZu8P6u50DTbUKyB1Db+XCVBmjrSryohJ24SWYrakt07WWwxU0QWr3UDyLeEhN+nI+L yV67/8BXu/r7DoDTpKr2Zl7AzFnT47VGwsdRI2eW45q+vbuBVy9+yDdQuWDMHyaIHNvp Jtz8NVcdXclMFvEaYM0Idx8qN1lgFZJaSSiuZNBP/2swVYrnPt1eEW8pA+eSpmxJN3qm blLxPU1/eWshtAcZXNyuOwzL//yEIDU5M1l2AG74dsZTDEyo4NQtQk+9xscAikAebbqq a/ag== 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=t3I+tulskuvhiOpe+fm1cN+b9fNH0wjIl3P0nbflmpM=; b=PQtttXO39kfFgQUtzHUZ7RrbnCacRznzlSDJU4vXa/ViRoT+izT0uHoCRqcyfpTwdi 9W7XiKiTlqWTDnhCvZr0V/V0ljn002TesnLEH9MrO1vPTC/4PTLErMUQpHTqBH8Q36rF 6V9+mA9PSGoPa7is8CKDZ1x93oZVfEJ2KoZvERfwr+pywiRDrZlKkjXN4Lm9blS6NfRU F01kYhnXvuMOnzEB8L/wCWud3pWRpv4inlFyQloSDwumx8nI/XBJi2Xs0FQosVQhAhxo aav6RUAmg7tr0wZkKKfnLsb78p0Y3Xo0pCnxqGM3D+POCyiEXpQ7Q0DZchs304TrqywA ZosQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=12G3+2Y0; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci7-20020a170906c34700b00992af7932d9si6889883ejb.690.2023.07.13.08.27.37; Thu, 13 Jul 2023 08:28:01 -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=12G3+2Y0; 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 S232503AbjGMPKO (ORCPT + 99 others); Thu, 13 Jul 2023 11:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232457AbjGMPKI (ORCPT ); Thu, 13 Jul 2023 11:10:08 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7AF2726 for ; Thu, 13 Jul 2023 08:10:06 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-314313f127fso969776f8f.1 for ; Thu, 13 Jul 2023 08:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1689261005; x=1691853005; 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=12G3+2Y00Sqmy3C4bHK2R4sUiuSMiHP21QdzHVQmMjgUKvRryyZ8lP4R3HAMAoanJO md8q9aAd47Acuc0fmNXsDZzKEQAEfWUZ+5ZTvY2oiRa4EOUJUDhMHV8RxcGqwc5aoZzi 1BJWHAtsnqguVT2wn/jpEX/M9Zz8yzQNyD6n4oU4M7/UBXDKc5IPkFgdfS/pxy6DR69o aiJ2wG4wTVjVDvJ3AJ/QPf4oFV9fg4zfOb+6GnaftHgah9MEmL65yonE/OU0DSLUj9nW n7MgYSa0mC8KWKrfozAz11cuYBW4qjohOukU8U5wIN/4Ph02tmk/xDT+hk82OSEXhwf4 iNmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689261005; x=1691853005; 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=gkWHp+DzpshqR9mdlTb47Faml36ZXUXxj/GsqUEPxJ/ffUYy1kEJlC711wK72pM367 O3QPEhufOsa1dxc2YokqD+ABdkomLXNGXb8yYNdFPefs3wKfqPp1d88LnQ5LLhgng2uf 0XbvSGIeke4+MtCOIud7cdHi8sClva/SEa6N7GebpHecRbdAoC90fytF/14RFicIMAie 7eoUGcEIAsEY0cQk0mINNVsA5nsz6/a/JPHSbVuTe2d6GMi8i3/4UTbYP1Yob1xMHvKZ Mk9nAP9eLmBKj9X2SvkPXmAPGkVQ2x89AgsGtRUCROea1Dd+mur57fnSFZwRwYgFWf5a jvfQ== X-Gm-Message-State: ABy/qLaXimzdKAuzpIEq96oftBAkXbZAdbeyOBjL/0/4u5f+UVVvRy+m FFfjULSMm0GwmsMiO8lUlOS2FA== X-Received: by 2002:a05:6000:1009:b0:313:f990:c631 with SMTP id a9-20020a056000100900b00313f990c631mr1408913wrx.44.1689261004976; Thu, 13 Jul 2023 08:10:04 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id q14-20020adfea0e000000b003063a92bbf5sm8173091wrm.70.2023.07.13.08.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 08:10:04 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ard Biesheuvel , 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 RESEND v4 2/5] riscv: Dump out kernel offset information on panic Date: Thu, 13 Jul 2023 17:07:57 +0200 Message-Id: <20230713150800.120821-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713150800.120821-1-alexghiti@rivosinc.com> References: <20230713150800.120821-1-alexghiti@rivosinc.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771319676138760522 X-GMAIL-MSGID: 1771319676138760522 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);