mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: alexander.levin@verizon.com
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Jibin Xu <jibin.xu@windriver.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alexander.levin@verizon.com
Subject: [PATCH AUTOSEL for 4.9 19/24] sysrq : fix Show Regs call trace on ARM
Date: Wed, 22 Nov 2017 22:26:15 +0000	[thread overview]
Message-ID: <20171122222604.20122-19-alexander.levin@verizon.com> (raw)
In-Reply-To: <20171122222604.20122-1-alexander.levin@verizon.com>

From: Jibin Xu <jibin.xu@windriver.com>

[ Upstream commit b00bebbc301c8e1f74f230dc82282e56b7e7a6db ]

When kernel configuration SMP,PREEMPT and DEBUG_PREEMPT are enabled,
echo 1 >/proc/sys/kernel/sysrq
echo p >/proc/sysrq-trigger
kernel will print call trace as below:

sysrq: SysRq : Show Regs
BUG: using __this_cpu_read() in preemptible [00000000] code: sh/435
caller is __this_cpu_preempt_check+0x18/0x20
Call trace:
[<ffffff8008088e80>] dump_backtrace+0x0/0x1d0
[<ffffff8008089074>] show_stack+0x24/0x30
[<ffffff8008447970>] dump_stack+0x90/0xb0
[<ffffff8008463950>] check_preemption_disabled+0x100/0x108
[<ffffff8008463998>] __this_cpu_preempt_check+0x18/0x20
[<ffffff80084c9194>] sysrq_handle_showregs+0x1c/0x40
[<ffffff80084c9c7c>] __handle_sysrq+0x12c/0x1a0
[<ffffff80084ca140>] write_sysrq_trigger+0x60/0x70
[<ffffff8008251e00>] proc_reg_write+0x90/0xd0
[<ffffff80081f1788>] __vfs_write+0x48/0x90
[<ffffff80081f241c>] vfs_write+0xa4/0x190
[<ffffff80081f3354>] SyS_write+0x54/0xb0
[<ffffff80080833f0>] el0_svc_naked+0x24/0x28

This can be seen on a common board like an r-pi3.
This happens because when echo p >/proc/sysrq-trigger,
get_irq_regs() is called outside of IRQ context,
if preemption is enabled in this situation,kernel will
print the call trace. Since many prior discussions on
the mailing lists have made it clear that get_irq_regs
either just returns NULL or stale data when used outside
of IRQ context,we simply avoid calling it outside of
IRQ context.

Signed-off-by: Jibin Xu <jibin.xu@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 drivers/tty/sysrq.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 701c085bb19b..53cbf4ebef10 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -243,8 +243,10 @@ static void sysrq_handle_showallcpus(int key)
 	 * architecture has no support for it:
 	 */
 	if (!trigger_all_cpu_backtrace()) {
-		struct pt_regs *regs = get_irq_regs();
+		struct pt_regs *regs = NULL;
 
+		if (in_irq())
+			regs = get_irq_regs();
 		if (regs) {
 			pr_info("CPU%d:\n", smp_processor_id());
 			show_regs(regs);
@@ -263,7 +265,10 @@ static struct sysrq_key_op sysrq_showallcpus_op = {
 
 static void sysrq_handle_showregs(int key)
 {
-	struct pt_regs *regs = get_irq_regs();
+	struct pt_regs *regs = NULL;
+
+	if (in_irq())
+		regs = get_irq_regs();
 	if (regs)
 		show_regs(regs);
 	perf_event_print_debug();
-- 
2.11.0

  parent reply	other threads:[~2017-11-22 22:28 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 22:26 [PATCH AUTOSEL for 4.9 01/24] ima: fix hash algorithm initialization alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 02/24] s390/pci: do not require AIS facility alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 04/24] staging: greybus: loopback: Fix iteration count on async path alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 05/24] m68k: fix ColdFire node shift size calculation alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 06/24] serial: 8250_fintek: Fix rs485 disablement on invalid ioctl() alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 03/24] selftests/x86/ldt_get: Add a few additional tests for limits alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 10/24] mmc: sdhci-msm: fix issue with power irq alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 07/24] staging: rtl8188eu: avoid a null dereference on pmlmepriv alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 08/24] spi: sh-msiof: Fix DMA transfer size check alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 09/24] spi: spi-axi: fix potential use-after-free after deregistration alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 14/24] serial: 8250: Preserve DLD[7:4] for PORT_XR17V35X alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 13/24] usb: phy: tahvo: fix error handling in tahvo_usb_probe() alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 12/24] usb: dwc2: Error out of dwc2_hsotg_ep_disable() if we're in host mode alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 11/24] usb: dwc2: Fix UDC state tracking alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 17/24] irqchip/gic: Make quirks matching conditional on init return value alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 15/24] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 18/24] EDAC, sb_edac: Fix missing break in switch alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 16/24] x86/entry: Use SYSCALL_DEFINE() macros for sys_modify_ldt() alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 22/24] kprobes/x86: Disable preemption in ftrace-based jprobes alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 21/24] perf test attr: Fix ignored test case result alexander.levin
2017-11-22 22:26 ` alexander.levin [this message]
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 20/24] usbip: tools: Install all headers needed for libusbip development alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 24/24] iio: adc: ti-ads1015: add 10% to conversion wait time alexander.levin
2017-11-22 22:26 ` [PATCH AUTOSEL for 4.9 23/24] tools include: Do not use poison with C++ alexander.levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171122222604.20122-19-alexander.levin@verizon.com \
    --to=alexander.levin@verizon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jibin.xu@windriver.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®