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: 13312363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20426C001B0 for ; Thu, 13 Jul 2023 15:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MISTjFvPcTpJuGSOohiGFkLo+i4UZkTbVfCUdypRVzs=; b=ycdCJU3P0SEX/c tfuPM19T/jogFSXhHhuBlEvDZqPvf8eTEo9Y3dYk5SMkFQcuniFAPqFJQdRhsY8LJoRKsq1Qsmyvv qkrWVClVqniP2G1bnXnle85Mcc8BT1l2jOn3xAZN2vhl1SzeeLzV1nvGK+guwPwlRODG0v+fdDg79 7QSzDvAetuSdEAH5xewycOjihcvP55bPgGx4LhaE3AEeeVVaWbyJGYczuUklNTVfOgviChFg2GbUR kSYkLtkJNvgfNyWM3A9/A9YikbJVehlv+f8nqQYBLkyy5UoyQIprerA7dievPr4KIWuVifo1y2pSj rENCensq6MyH1drWQyBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJxxK-003gta-2v; Thu, 13 Jul 2023 15:10:10 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJxxH-003grG-34 for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 15:10:09 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso981323f8f.0 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=WhhWJNqDtIMCoYl+cbJlIWjeKbMn1gNgol4uJdtfRxWiD9AYVW1gmjR18O6Sr+EeJc yYvtUm4+8BLT5xta7PTqjHNhIdltGT3q7FEb5QPFQeDNzo8uJcqDWKybDcVrNEbQgNfJ esw15wxbh8BpdUbUEJkNvM4gPc4QW9khrjS3uK7Bz5UbOcKDBFDMEl+6o3G0/lCJTsW0 ykMut1UCQXLWcqHq+wp1qfAXKPYm8RMsHiMNSqHbdpt/H+VttZ23dXDqrrAqYDs84adA yVOnEJSvIoT0K0tvdlza6Wz47DSwnyj/IadIfQjla/e1VLXnqfn8uv3pmTMlcQcXqoLI lWDQ== X-Gm-Message-State: ABy/qLaIeujIodGhHLu1jS6IDvQ6STiDsW2YG3/quc1FKveGriF6lMHT 0W2hOOcwUVYgfchjXPP2tQRpyQ== X-Google-Smtp-Source: APBJJlEFMrP0/qw3uxLKCVQPZAJw7F36JXx2A1kJbs6oGdJIWClw3b1SF7al95mzWxvu1hXdlj929Q== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_081007_987055_9BECCE5E X-CRM114-Status: GOOD ( 11.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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);