Skip to contentSkip to conversation

Fix 'sleeping function called from invalid context' warning in sysrq generated crash.

PATCH In review Ani Sinha 2 participants 4 messages Dec 18, 2015 – Dec 20, 2015 TTY layer and serial drivers

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 Fix 'sleeping function called from invalid context' warning in sysrq generated crash.

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187

in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
---
 drivers/tty/sysrq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/tty/sysrq.c +6 -0
index 5381a72..08987ad 100644
@@ -133,6 +133,12 @@ static void sysrq_handle_crash(int key)
 {
 	char *killer = NULL;
 
+	/* we need to release the RCU read lock here,
+	   otherwise we get an annoying 
+	   'BUG: sleeping function called from invalid context'
+	   complaint from the kernel before the panic.
+	*/
+	rcu_read_unlock();
 	panic_on_oops = 1;	/* force panic */
 	wmb();
 	*killer = 1;
Signature · 1 line
1.8.1.4
Reviewed-by Rik van Riel on v1 1/1
#1 lore raw
Quoted 12 lines · Ani Sinha

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187

in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

Quoted 7 lines

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")

I queued this with Rik's Signed-off-by, and fixed some checkpatch.pl errors. Please run scripts/checkpatch.pl on your patches in the future.

Please see below for the result.

Rik, did you test this as well? If so, may I also have your Tested-by?

Thanx, Paul

------------------------------------------------------------------------

commit c95a158356397844a5a6deb0bd58758084f891df

Author: Ani Sinha <[email protected]>
Date:   Thu Dec 17 17:15:10 2015 -0800

sysrq: Fix warning in sysrq generated crash.

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187 in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
drivers/tty/sysrq.c +6 -0
index 5381a728d23e..e5139402e7f8 100644
@@ -133,6 +133,12 @@ static void sysrq_handle_crash(int key)
 {
 	char *killer = NULL;
 
+	/* we need to release the RCU read lock here,
+	 * otherwise we get an annoying
+	 * 'BUG: sleeping function called from invalid context'
+	 * complaint from the kernel before the panic.
+	 */
+	rcu_read_unlock();
 	panic_on_oops = 1;	/* force panic */
 	wmb();
 	*killer = 1;
author
#2 lore raw
Quoted 17 lines · Paul E. McKenney
Quoted 16 lines · Ani Sinha

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187

in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Quoted 8 lines
Quoted 3 lines
Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")

I queued this with Rik's Signed-off-by, and fixed some checkpatch.pl errors. Please run scripts/checkpatch.pl on your patches in the future.

Please see below for the result.

Yes, sorry. I forgot to run the script before sending Thanks for fixing my comment and the trailing whitespace.

Quoted 51 lines

Rik, did you test this as well? If so, may I also have your Tested-by?

Thanx, Paul

------------------------------------------------------------------------

commit c95a158356397844a5a6deb0bd58758084f891df

Author: Ani Sinha <[email protected]>
Date:   Thu Dec 17 17:15:10 2015 -0800

sysrq: Fix warning in sysrq generated crash.

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187 in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
drivers/tty/sysrq.c +6 -0
index 5381a728d23e..e5139402e7f8 100644
@@ -133,6 +133,12 @@ static void sysrq_handle_crash(int key)
 {
        char *killer = NULL;
 
+       /* we need to release the RCU read lock here,
+        * otherwise we get an annoying
+        * 'BUG: sleeping function called from invalid context'
+        * complaint from the kernel before the panic.
+        */
+       rcu_read_unlock();
        panic_on_oops = 1;      /* force panic */
        wmb();
        *killer = 1;
#3 lore raw
In reply to Paul E. McKenney
Quoted 19 lines · Paul E. McKenney
Quoted 18 lines · Ani Sinha

Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq") replaced spin_lock_irqsave() calls with rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not disable preemption, faulthandler_disabled() in __do_page_fault() in x86/fault.c returns false. When the code later calls might_sleep() in the pagefault handler, we get the following warning:

BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187

in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a

To fix this, we release the RCU read lock before we crash.

Tested this patch on linux 3.18 by booting off one of our boards.

Fixes 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
Quoted 9 lines
Quoted 1 line

I queued this with Rik's Signed-off-by, and fixed some checkpatch.pl errors. Please run scripts/checkpatch.pl on your patches in the future.

Please see below for the result.

Rik, did you test this as well? If so, may I also have your Tested-by?

I applied this patch on linux 4.4-rc5 and booted off a fedora core 22 vmware VM with it (sorry I don't have a real box around). Seems to be working fine. Also booted off a fc14 vm box with it and it also seems fine. Here's the kernel crash dump from fc22 box :

Fedora release 22 (Twenty Two)
Kernel 4.4.0-rc5-2847908.AroraKernelbleeding.5.fc18.x86_64 on an x86_64 (ttyS1)

localhost login: [ 50.070804] [drm:vmw_cmdbuf_work_func [vmwgfx]] *ERROR* Command buffer error.

[   81.823507] sysrq: SysRq : Trigger a crash
[   81.825099] BUG: unable to handle kernel NULL pointer dereference at           (null)
[   81.827357] IP: [<ffffffff8131c217>] sysrq_handle_crash+0x11/0x1b
[   81.828986] PGD 0 
[   81.829542] Oops: 0002 [#1] SMP 
[   81.830426] Modules linked in: rfcomm xt_CHECKSUM ipt_MASQUERADE nf_nat_masquerade_ipv4 tun nf_conntrack_netbios_ns nf_conntrack_broadcast xt_tcpudp ip6t_REJECT fuse ipt_REJECT xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw iptable_filter snd_seq_midi snd_seq_midi_event bnep coretemp hwmon crc32c_intel ppdev aesni_intel aes_x86_64 glue_helper lrw gf128mul ablk_helper cryptd snd_ens1371 snd_ac97_codec ac97_bus snd_seq pcspkr snd_pcm serio_raw snd_timer snd_rawmidi snd_seq_device snd soundcore gameport i2c_piix4 shpchp battery parport_pc parport btusb btrtl btbcm btintel ac bluetooth acpi_cpufreq tpm_tis tpm nfsd auth_rpcgss oid_registry nfs_acl lockd grace sunrpc ip_tables x_tables uhci_hcd vmwgfx e1000 ehci_pci ehci_hcd mptspi scsi_transport_spi mptscsih mptbase drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops ttm drm i2c_core sr_mod cdrom dm_mirror dm_region_hash dm_log dm_mod autofs4
[   81.854446] CPU: 0 PID: 2296 Comm: bash Not tainted 4.4.0-rc5-2847908.AroraKernelbleeding.5.fc18.x86_64 #1
[   81.856338] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 05/20/2014
[   81.858431] task: ffff88001c7d9a00 ti: ffff880004d70000 task.ti: ffff880004d70000
[   81.859903] RIP: 0010:[<ffffffff8131c217>]  [<ffffffff8131c217>] sysrq_handle_crash+0x11/0x1b
[   81.861609] RSP: 0018:ffff880004d73d98  EFLAGS: 00010296
[   81.862672] RAX: 000000000000000f RBX: ffffffff81a774a0 RCX: 0000000000000000
[   81.864078] RDX: ffff88003f60f101 RSI: ffff88003f60cae8 RDI: 0000000000000063
[   81.865482] RBP: ffff880004d73d98 R08: 000000000000000f R09: 0000000000000000
[   81.866889] R10: 0000000000000000 R11: 000000000000000f R12: 0000000000000004
[   81.868294] R13: 0000000000000063 R14: ffff880004d73f00 R15: 0000000000000000
[   81.869702] FS:  00007fd8e0c69700(0000) GS:ffff88003f600000(0000) knlGS:0000000000000000
[   81.871293] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   81.872437] CR2: 0000000000000000 CR3: 000000001199f000 CR4: 00000000001406f0
[   81.873877] Stack:
[   81.874297]  ffff880004d73dc8 ffffffff8131c835 0000000000000002 ffff880004cb5200
[   81.875876]  00007fd8e0c77000 ffff880004d73f20 ffff880004d73de8 ffffffff8131c8e7
[   81.877455]  fffffffffffffff2 ffff88003abff500 ffff880004d73e28 ffffffff81181949
[   81.879032] Call Trace:
[   81.879537]  [<ffffffff8131c835>] __handle_sysrq+0x8f/0x11c
[   81.880645]  [<ffffffff8131c8e7>] write_sysrq_trigger+0x25/0x36
[   81.881829]  [<ffffffff81181949>] proc_reg_write+0x54/0x76
[   81.883007]  [<ffffffff81131ce4>] __vfs_write+0x23/0xa2
[   81.884050]  [<ffffffff81200200>] ? security_file_permission+0x37/0x40
[   81.885344]  [<ffffffff81132338>] ? rw_verify_area+0x6b/0xcb
[   81.886469]  [<ffffffff81133ccf>] ? __sb_start_write+0x22/0x42
[   81.887628]  [<ffffffff81132abe>] vfs_write+0x86/0xdc
[   81.888634]  [<ffffffff81132ca7>] SyS_write+0x4d/0x7f
[   81.889643]  [<ffffffff8150406e>] entry_SYSCALL_64_fastpath+0x12/0x71
[   81.890919] Code: 7a 00 00 55 b8 01 00 00 00 48 89 e5 75 07 0f b6 05 73 53 7a 00 83 e0 01 5d c3 55 c7 05 e7 23 92 00 01 00 00 00 48 89 e5 0f ae f8 <c6> 04 25 00 00 00 00 01 5d c3 55 48 89 e5 53 48 89 f3 48 8d 55 
[   81.896661] RIP  [<ffffffff8131c217>] sysrq_handle_crash+0x11/0x1b
[   81.897915]  RSP <ffff880004d73d98>
[   81.898618] CR2: 0000000000000000
[   81.899346] ---[ end trace 7f48df1773107036 ]---
[   81.900306] Kernel panic - not syncing: Fatal exception
[   81.901378] Kernel Offset: disabled
[   81.902109] ---[ end Kernel panic - not syncing: Fatal exception