Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp145657iob; Tue, 17 May 2022 21:47:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUBD+YzKQprTnyGRfipbedk/cW3cHtAe9qXrjv0oBR+MfFHKmsAjgbwSLZxZ7WxuVLnw9S X-Received: by 2002:a17:902:d54b:b0:161:8f46:8207 with SMTP id z11-20020a170902d54b00b001618f468207mr10535913plf.67.1652849263580; Tue, 17 May 2022 21:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652849263; cv=none; d=google.com; s=arc-20160816; b=aoKBQ9TiuHdcSsKVmIVdy/85hDqX0zmob+FLY1vrvwTwe0tRU5/iKYeUPa+zY9R/e+ ilfZaBti42l3ITJwUPF4kuloHO/cErFCmvhNKhHgy+KFzWI3DMQMWzwdLxbOgG33rU48 euyXfUK76SPRNiDl2JiX17NCZeZhXJ5WTmx693klAjbTUga61cFJ829yY5HtRDgWyoM0 xxKLdd8L+36NPk0e9iW+pNVzuq8eB4AG2PksCSq+QZ7NEf82+u+LTw2kH6Wf3hYJRcnM SMt6MVEfRMsATCyaynKwlK+PViE6juao3zOWZ70+gg4NBl46YzUT5e71Z78ju5gP4VBr JGRA== 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=6s5Kt+Fz8ODBsnaEn4hTWh6elxNZ/IIbeZw2XTvUCZg=; b=baPRRuyvkDyoQe60xkW6j4hPr7xDJLW4q1t3K26Cl5bAxwBpNAwpkkuAj6Uj/NgpOq POh9I934tLXfGtkWZqO+fAxt2wUkE66XZvCXVY/m/3dWc6dG8+lWpTtbzNzotTpjz3QE s6zub7WTbRRnDJXJAZZI48fV6Vjdr97zas14fadtog9Cdnp9qjl0p7uPIddi+HuJkGw+ mEwEmY5h+4NwPYLJiKqdXAMcrT+RMfBTlUQaAUSjXk/f42lrLN9aB+xKaL9KyZzv6Eno ErpTkFcqHsatMMcI1I/VJ7meHw1WZfpeIeW9QNZu0XiDDqXPrWcHxQul6jhvpdkE7SN6 w9MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l9BCm+sZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c3-20020a170902aa4300b00153b2d164b1si1292504plr.185.2022.05.17.21.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l9BCm+sZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1E9E119049; Tue, 17 May 2022 20:59:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237082AbiEQAz7 (ORCPT + 99 others); Mon, 16 May 2022 20:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238125AbiEQAzx (ORCPT ); Mon, 16 May 2022 20:55:53 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C81631D for ; Mon, 16 May 2022 17:55:43 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id m12so16009264plb.4 for ; Mon, 16 May 2022 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6s5Kt+Fz8ODBsnaEn4hTWh6elxNZ/IIbeZw2XTvUCZg=; b=l9BCm+sZ/jPB00HhEvjDgNEBEZubgYsHBxfKzYQWLsXeMk7sC7EtDNnhmZul6RoA0n SOQYpqJmzwwC6ayzYVCcwcX6YYAi/DxWNaxKiV0TTUUIZ3D82gME2gJjJmZGl6xyHl+X i/IZkzXiPpVoYOSIkoOXPPW8daAFzitvLKTrSPCuyZfPrvXRGNJTTTiUYmoV3dkTAFg3 0Bset5Z9Y6xm6ZENrofdTr3hbh/LZ/lsw020yAaYZ2h+2cLCqmWhUg/6x9kYD+P4VV/e GYkKWLJlYgXsLom70JZTc0HvzyOh8IqkKVqiEHBbrPNVcvxxoZRI7yDs4QUT1F+ZFbSV DALA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6s5Kt+Fz8ODBsnaEn4hTWh6elxNZ/IIbeZw2XTvUCZg=; b=dvfCg5xQ7ZQ19i29E1/q+uygEM28mIejQ2Zc/h6qqa1f8nngnSiniHxcH0tZYFWDFj 6LMGElAKSvE2vXKpk0sFPsMSgi+kOhlwTFo6SXwXgl1swK2vceBIq/zRg+QUDt9CwtFa 6nedq8tdFyPpNsfiu9NLVI79ihZp/RGlY0yUKI2+eERVkWdEwAIv1wAUIQJwnvrnCjMf Rq3J9z3xDiCnnKCnkwbsexV1yJV4wlmuW8pP9ut4APtfpzHJ1S3P8MFOOlZqjCXrGgTu 6QMvoGT6J6JJar3x7aWnsI812a3JqE/ZQ9eN5Yhxa7hnXCH/OruodhqXclNKstypxuDo NczQ== X-Gm-Message-State: AOAM530MogQnLJh9yNrxD0XBs49OwP3EfaDplozKaIym/dgOL6QjyD+R F9OVCsLxChcJQHUhSXIF48mxdr/VvoNK+w== X-Received: by 2002:a17:903:246:b0:153:84fe:a9b0 with SMTP id j6-20020a170903024600b0015384fea9b0mr19934908plh.163.1652748942250; Mon, 16 May 2022 17:55:42 -0700 (PDT) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id k189-20020a6384c6000000b003c574b4a95dsm7374535pgd.53.2022.05.16.17.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 17:55:41 -0700 (PDT) From: Stafford Horne To: LKML Cc: Openrisc , Stafford Horne , Jonas Bonn , Stefan Kristiansson , "Eric W. Biederman" , "Russell King (Oracle)" , Andrew Morton , Kefeng Wang Subject: [PATCH v2 05/13] openrisc: Pretty print show_registers memory dumps Date: Tue, 17 May 2022 09:55:02 +0900 Message-Id: <20220517005510.3500105-6-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220517005510.3500105-1-shorne@gmail.com> References: <20220517005510.3500105-1-shorne@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Currently show registers, print memory dumps character by character and there is no address information, so its a bit difficult to use. For example before a stack dump looks as follows. [ 13.650000] Stack: [ 13.650000] Call trace [ 13.690000] [<(ptrval)>] ? put_timespec64+0x44/0x60 [ 13.690000] [<(ptrval)>] ? _data_page_fault_handler+0x104/0x10c [ 13.700000] [ 13.700000] Code: [ 13.700000] 13 [ 13.700000] ff [ 13.700000] ff [ 13.700000] f9 [ 13.710000] 84 [ 13.710000] 82 [ 13.710000] ff [ 13.710000] bc [ 13.710000] 07 [ 13.710000] fd [ 13.720000] 4e [ 13.720000] 67 [ 13.720000] 84 [ 13.720000] 62 [ 13.720000] ff ... This change updates this to print the address and data a word at time. [ 0.830000] Stack: [ 0.830000] Call trace: [ 0.830000] [<(ptrval)>] load_elf_binary+0x744/0xf5c [ 0.830000] [<(ptrval)>] ? __kernel_read+0x144/0x184 [ 0.830000] [<(ptrval)>] bprm_execve+0x27c/0x3e4 [ 0.830000] [<(ptrval)>] kernel_execve+0x16c/0x1a0 [ 0.830000] [<(ptrval)>] run_init_process+0xa0/0xec [ 0.830000] [<(ptrval)>] ? kernel_init+0x0/0x14c [ 0.830000] [<(ptrval)>] kernel_init+0x7c/0x14c [ 0.830000] [<(ptrval)>] ? calculate_sigpending+0x30/0x40 [ 0.830000] [<(ptrval)>] ret_from_fork+0x1c/0x84 [ 0.830000] [ 0.830000] c1033dbc: c1033dec [ 0.830000] c1033dc0: c015258c [ 0.830000] c1033dc4: c129da00 [ 0.830000] c1033dc8: 00000002 [ 0.830000] c1033dcc: 00000000 [ 0.830000] c1033dd0: c129da00 [ 0.830000] c1033dd4: 00000000 [ 0.830000] c1033dd8: 00000000 [ 0.830000] (c1033ddc:) 00001e04 [ 0.830000] c1033de0: 001501fc [ 0.830000] c1033de4: c1033e68 [ 0.830000] c1033de8: c0152e60 [ 0.830000] c1033dec: c129da5c [ 0.830000] c1033df0: c0674a20 [ 0.830000] c1033df4: c1033e50 [ 0.830000] c1033df8: c00e3d6c [ 0.830000] c1033dfc: c129da5c [ 0.830000] c1033e00: 00000003 [ 0.830000] c1033e04: 00150000 [ 0.830000] c1033e08: 00002034 [ 0.830000] c1033e0c: 001501fc [ 0.830000] c1033e10: 00000000 [ 0.830000] c1033e14: 00150000 [ 0.830000] c1033e18: 0014ebbc [ 0.830000] c1033e1c: 00002000 [ 0.830000] c1033e20: 00000003 [ 0.830000] c1033e24: c12a07e0 [ 0.830000] c1033e28: 00000000 [ 0.830000] c1033e2c: 00000000 [ 0.830000] c1033e30: 00000000 [ 0.830000] c1033e34: 40040000 [ 0.830000] c1033e38: 00000000 [ 0.830000] [ 0.830000] Code: [ 0.830000] c00047a4: 9c21fff8 [ 0.830000] c00047a8: d4012000 [ 0.830000] c00047ac: d4011804 [ 0.830000] c00047b0: e4040000 [ 0.830000] c00047b4: 10000005 [ 0.830000] c00047b8: 9c84ffff [ 0.830000] (c00047bc:) d8030000 [ 0.830000] c00047c0: 03fffffc [ 0.830000] c00047c4: 9c630001 [ 0.830000] c00047c8: 9d640001 [ 0.830000] c00047cc: 84810000 [ 0.830000] c00047d0: 84610004 Now we are also printing a bit of the stack as well as the code. The stack is output to help with debugging. There may be concern about exposing sensitive information on the stack, but we are already dumping all register content which would have similar sensitive information. So I am going ahead as this proves useful in investigation. Signed-off-by: Stafford Horne --- arch/openrisc/kernel/traps.c | 46 ++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/arch/openrisc/kernel/traps.c b/arch/openrisc/kernel/traps.c index 0446a3c34372..f2478bba77b9 100644 --- a/arch/openrisc/kernel/traps.c +++ b/arch/openrisc/kernel/traps.c @@ -46,6 +46,14 @@ void print_trace(void *data, unsigned long addr, int reliable) (void *) addr); } +static void print_data(unsigned long base_addr, unsigned long word, int i) +{ + if (i == 0) + printk("(%08lx:)\t%08lx", base_addr + (i * 4), word); + else + printk(" %08lx:\t%08lx", base_addr + (i * 4), word); +} + /* displays a short stack trace */ void show_stack(struct task_struct *task, unsigned long *esp, const char *loglvl) { @@ -99,22 +107,36 @@ void show_registers(struct pt_regs *regs) printk("\nStack: "); show_stack(NULL, (unsigned long *)esp, KERN_EMERG); + if (esp < PAGE_OFFSET) + goto bad_stack; + + printk("\n"); + for (i = -8; i < 24; i += 1) { + unsigned long word; + + if (__get_user(word, &((unsigned long *)esp)[i])) { +bad_stack: + printk(" Bad Stack value."); + break; + } + + print_data(esp, word, i); + } + printk("\nCode: "); if (regs->pc < PAGE_OFFSET) goto bad; - for (i = -24; i < 24; i++) { - unsigned char c; - if (__get_user(c, &((unsigned char *)regs->pc)[i])) { + for (i = -6; i < 6; i += 1) { + unsigned long word; + + if (__get_user(word, &((unsigned long *)regs->pc)[i])) { bad: printk(" Bad PC value."); break; } - if (i == 0) - printk("(%02x) ", c); - else - printk("%02x ", c); + print_data(regs->pc, word, i); } } printk("\n"); @@ -185,13 +207,11 @@ void nommu_dump_state(struct pt_regs *regs, printk("\nCode: "); for (i = -24; i < 24; i++) { - unsigned char c; - c = ((unsigned char *)(__pa(regs->pc)))[i]; + unsigned long word; + + word = ((unsigned long *)(__pa(regs->pc)))[i]; - if (i == 0) - printk("(%02x) ", c); - else - printk("%02x ", c); + print_data(regs->pc, word, i); } printk("\n"); } -- 2.31.1