Bug 10489 - Kprobe smoke test lockdep warning
Summary: Kprobe smoke test lockdep warning
Status: CLOSED OBSOLETE
Alias: None
Product: Other
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: other_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-20 11:35 UTC by jean-marc LACROIX
Modified: 2012-05-21 15:07 UTC (History)
2 users (show)

See Also:
Kernel Version: 2.6.25
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description jean-marc LACROIX 2008-04-20 11:35:12 UTC
Latest working kernel version: 2.6.25
Earliest failing kernel version: 2.6.25
Distribution: DEbian Etch
Hardware Environment: PIII
Software Environment: 
Problem Description: Warning at boot after running all 
embedded test

Steps to reproduce: boot !!!
 

   2.701005] Registering sys device '<NULL>'
[    2.702320] Registering sys device '<NULL>'
[    2.703711] Registering sys device '<NULL>'
[    2.704536] Initializing RT-Tester: OK
[    2.704824] device: 'snapshot': device_add
[    2.705140] PM: Adding info for No Bus:snapshot
[    2.706804] audit: initializing netlink socket (disabled)
[    2.707199] type=2000 audit(1208713807.707:1): initialized
[    2.707509] Kprobe smoke test started
[    2.709300] ------------[ cut here ]------------
[    2.709420] WARNING: at kernel/lockdep.c:2658 check_flags+0x4d/0x12c()
[    2.709541] Modules linked in:
[    2.709588] Pid: 1, comm: swapper Not tainted 2.6.25.jml.057 #1
[    2.709588]  [<c0126acc>] warn_on_slowpath+0x41/0x51
[    2.709588]  [<c010bafc>] ? save_stack_trace+0x1d/0x3b
[    2.709588]  [<c0140a83>] ? save_trace+0x37/0x89
[    2.709588]  [<c011987d>] ? kernel_map_pages+0x103/0x11c
[    2.709588]  [<c0109803>] ? native_sched_clock+0xca/0xea
[    2.709588]  [<c0142958>] ? mark_held_locks+0x41/0x5c
[    2.709588]  [<c0382580>] ? kprobe_exceptions_notify+0x322/0x3af
[    2.709588]  [<c0142aff>] ? trace_hardirqs_on+0xf1/0x119
[    2.709588]  [<c03825b3>] ? kprobe_exceptions_notify+0x355/0x3af
[    2.709588]  [<c0140823>] check_flags+0x4d/0x12c
[    2.709588]  [<c0143c9d>] lock_release+0x58/0x195
[    2.709588]  [<c038347c>] ? __atomic_notifier_call_chain+0x0/0x80
[    2.709588]  [<c03834d6>] __atomic_notifier_call_chain+0x5a/0x80
[    2.709588]  [<c0383508>] atomic_notifier_call_chain+0xc/0xe
[    2.709588]  [<c013b6d4>] notify_die+0x2d/0x2f
[    2.709588]  [<c038168a>] do_debug+0x67/0xfe
[    2.709588]  [<c0381287>] debug_stack_correct+0x27/0x30
[    2.709588]  [<c01564c0>] ? kprobe_target+0x1/0x34
[    2.709588]  [<c0156572>] ? init_test_probes+0x50/0x186
[    2.709588]  [<c04fae48>] init_kprobes+0x85/0x8c
[    2.709588]  [<c04e947b>] kernel_init+0x13d/0x298
[    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
[    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
[    2.709588]  [<c0105ef7>] kernel_thread_helper+0x7/0x10
[    2.709588]  =======================
[    2.709588] ---[ end trace 778e504de7e3b1e3 ]---
[    2.709588] possible reason: unannotated irqs-off.
[    2.709588] irq event stamp: 370065
[    2.709588] hardirqs last  enabled at (370065): [<c0382580>] kprobe_exceptions_notify+0x322/0x3af
[    2.709588] hardirqs last disabled at (370064): [<c0381bb7>] do_int3+0x1d/0x7d
[    2.709588] softirqs last  enabled at (370050): [<c012b464>] __do_softirq+0xfa/0x100
[    2.709588] softirqs last disabled at (370045): [<c0107438>] do_softirq+0x74/0xd9
[    2.714751] Kprobe smoke test passed successfully
[    2.716150] Total HugeTLB memory allocated, 0
[    2.717288] VFS: Disk quotas dquot_6.5.1
[    2.717689] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    2.719630] device class 'bsg': registering
[    2.720568] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
[    2.720619] io scheduler noop registered
[    2.720732] io scheduler anticipatory registered
[    2.720848] io scheduler deadline registered
[    2.721089] io scheduler cfq registered (default)
[    2.721354] pci 0000:00:01.0: Boot video device

uname -a
Linux solo 2.6.25.jml.057 #1 SMP PREEMPT Fri Apr 18 23:39:29 CEST 2008 i686 GNU/Linux
-> lspci
00:00.0 Host bridge: Intel Corporation 82810E DC-133 GMCH [Graphics Memory Controller Hub] (rev 03)
00:01.0 VGA compatible controller: Intel Corporation 82810E DC-133 CGC [Chipset Graphics Controller] (rev 03)
00:1e.0 PCI bridge: Intel Corporation 82801AA PCI Bridge (rev 02)
00:1f.0 ISA bridge: Intel Corporation 82801AA ISA Bridge (LPC) (rev 02)
00:1f.1 IDE interface: Intel Corporation 82801AA IDE (rev 02)
00:1f.2 USB Controller: Intel Corporation 82801AA USB (rev 02)
00:1f.3 SMBus: Intel Corporation 82801AA SMBus (rev 02)
01:08.0 Ethernet controller: 3Com Corporation 3c905B 100BaseTX [Cyclone] (rev 30)
01:0a.0 Multimedia audio controller: Creative Labs SB Live! EMU10k1 (rev 06)
01:0a.1 Input device controller: Creative Labs SB Live! Game Port (rev 06)
01:0c.0 Ethernet controller: 3Com Corporation 3c905C-TX/TX-M [Tornado] (rev 78)

following modules after booting...

Module                  Size  Used by
nfs                   241460  2 
bnep                   16768  2 
rfcomm                 39328  5 
l2cap                  25232  9 bnep,rfcomm
bluetooth              58564  5 bnep,rfcomm,l2cap
ipv6                  267588  23 
ppdev                   9604  0 
lp                     13956  0 
ac                      7300  0 
battery                14860  0 
af_packet              23184  2 
autofs4                22812  5 
nfsd                  205552  15 
lockd                  63560  3 nfs,nfsd
nfs_acl                 4480  2 nfs,nfsd
auth_rpcgss            43328  1 nfsd
sunrpc                182132  19 nfs,nfsd,lockd,nfs_acl,auth_rpcgss
exportfs                6016  1 nfsd
snd_emu10k1_synth       8704  0 
snd_emux_synth         35232  1 snd_emu10k1_synth
snd_seq_virmidi         8712  1 snd_emux_synth
snd_seq_midi_emul       7168  1 snd_emux_synth
snd_emu10k1           133760  2 snd_emu10k1_synth
snd_seq_dummy           4868  0 
snd_seq_oss            32272  0 
snd_seq_midi           10240  0 
snd_seq_midi_event      8200  3 snd_seq_virmidi,snd_seq_oss,snd_seq_midi
snd_seq                53336  9 snd_emux_synth,snd_seq_virmidi,snd_seq_midi_emul,snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq_midi_event
snd_rawmidi            26016  3 snd_seq_virmidi,snd_emu10k1,snd_seq_midi
firmware_class         10880  1 snd_emu10k1
snd_ac97_codec         96068  1 snd_emu10k1
ac97_bus                2944  1 snd_ac97_codec
snd_pcm_oss            45984  1 
snd_mixer_oss          17160  1 snd_pcm_oss
snd_pcm                77228  3 snd_emu10k1,snd_ac97_codec,snd_pcm_oss
snd_seq_device          9492  8 snd_emu10k1_synth,snd_emux_synth,snd_emu10k1,snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq,snd_rawmidi
snd_timer              24604  3 snd_emu10k1,snd_seq,snd_pcm
snd_page_alloc         11784  2 snd_emu10k1,snd_pcm
snd_util_mem            6152  2 snd_emux_synth,snd_emu10k1
snd_hwdep              11020  2 snd_emux_synth,snd_emu10k1
parport_pc             38468  1 
parport                36712  3 ppdev,lp,parport_pc
8250_pnp               10880  0 
snd                    58340  18 snd_emu10k1_synth,snd_emux_synth,snd_seq_virmidi,snd_seq_midi_emul,snd_emu10k1,snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq,snd_rawmidi,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_seq_device,snd_timer,snd_util_mem,snd_hwdep
emu10k1_gp              4864  0 
gameport               16536  2 emu10k1_gp
soundcore               9184  2 snd
rtc                    15264  0 
button                  9616  0 
pcspkr                  4224  0 
i2c_i801               12816  0 
i2c_core               26512  1 i2c_i801
iTCO_wdt               13268  0 
iTCO_vendor_support     4868  1 iTCO_wdt
shpchp                 32204  0 
intel_rng               6784  0 
rng_core                6276  1 intel_rng
pci_hotplug            29476  1 shpchp
intel_agp              26436  1 
agpgart                33800  2 intel_agp
evdev                  13600  2 
dcdbas                  9252  0 
dm_mirror              28592  0 
dm_snapshot            19596  0 
dm_mod                 60108  13 dm_mirror,dm_snapshot
raid1                  25360  3 
md_mod                 77876  4 raid1
usb_storage            65984  0 
libusual               20432  1 usb_storage
uhci_hcd               24216  0 
usbcore               137392  4 usb_storage,libusual,uhci_hcd
ide_cd_mod             34208  0 
cdrom                  33056  1 ide_cd_mod
3c59x                  44080  0 
mii                     6144  1 3c59x
thermal                22564  0 
processor              49612  1 thermal
fan                     6916  0 
unix                   29756  196 


I can give the total dmesg and kernel .config file
Comment 1 jean-marc LACROIX 2008-04-20 11:39:27 UTC
plateform is 
-> cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 8
model name	: Pentium III (Coppermine)
stepping	: 3
cpu MHz		: 664.519
cache size	: 256 KB
fdiv_bug	: no
hlt_bug		: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 2
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr sse up
bogomips	: 1334.17
clflush size	: 32
Comment 2 Adrian Bunk 2008-04-21 08:07:33 UTC
http://bugzilla.kernel.org/show_bug.cgi?id=10489

Please reply via email (more information from the submitter is in the 
Bugzilla entry).


ReportedBy: jeanmarc.lacroix@free.Fr

Earliest failing kernel version: 2.6.25
Distribution: DEbian Etch
Hardware Environment: PIII
Software Environment: 
Problem Description: Warning at boot after running all 
embedded test

Steps to reproduce: boot !!!


   2.701005] Registering sys device '<NULL>'
[    2.702320] Registering sys device '<NULL>'
[    2.703711] Registering sys device '<NULL>'
[    2.704536] Initializing RT-Tester: OK
[    2.704824] device: 'snapshot': device_add
[    2.705140] PM: Adding info for No Bus:snapshot
[    2.706804] audit: initializing netlink socket (disabled)
[    2.707199] type=2000 audit(1208713807.707:1): initialized
[    2.707509] Kprobe smoke test started
[    2.709300] ------------[ cut here ]------------
[    2.709420] WARNING: at kernel/lockdep.c:2658 check_flags+0x4d/0x12c()
[    2.709541] Modules linked in:
[    2.709588] Pid: 1, comm: swapper Not tainted 2.6.25.jml.057 #1
[    2.709588]  [<c0126acc>] warn_on_slowpath+0x41/0x51
[    2.709588]  [<c010bafc>] ? save_stack_trace+0x1d/0x3b
[    2.709588]  [<c0140a83>] ? save_trace+0x37/0x89
[    2.709588]  [<c011987d>] ? kernel_map_pages+0x103/0x11c
[    2.709588]  [<c0109803>] ? native_sched_clock+0xca/0xea
[    2.709588]  [<c0142958>] ? mark_held_locks+0x41/0x5c
[    2.709588]  [<c0382580>] ? kprobe_exceptions_notify+0x322/0x3af
[    2.709588]  [<c0142aff>] ? trace_hardirqs_on+0xf1/0x119
[    2.709588]  [<c03825b3>] ? kprobe_exceptions_notify+0x355/0x3af
[    2.709588]  [<c0140823>] check_flags+0x4d/0x12c
[    2.709588]  [<c0143c9d>] lock_release+0x58/0x195
[    2.709588]  [<c038347c>] ? __atomic_notifier_call_chain+0x0/0x80
[    2.709588]  [<c03834d6>] __atomic_notifier_call_chain+0x5a/0x80
[    2.709588]  [<c0383508>] atomic_notifier_call_chain+0xc/0xe
[    2.709588]  [<c013b6d4>] notify_die+0x2d/0x2f
[    2.709588]  [<c038168a>] do_debug+0x67/0xfe
[    2.709588]  [<c0381287>] debug_stack_correct+0x27/0x30
[    2.709588]  [<c01564c0>] ? kprobe_target+0x1/0x34
[    2.709588]  [<c0156572>] ? init_test_probes+0x50/0x186
[    2.709588]  [<c04fae48>] init_kprobes+0x85/0x8c
[    2.709588]  [<c04e947b>] kernel_init+0x13d/0x298
[    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
[    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
[    2.709588]  [<c0105ef7>] kernel_thread_helper+0x7/0x10
[    2.709588]  =======================
[    2.709588] ---[ end trace 778e504de7e3b1e3 ]---
[    2.709588] possible reason: unannotated irqs-off.
[    2.709588] irq event stamp: 370065
[    2.709588] hardirqs last  enabled at (370065): [<c0382580>]
kprobe_exceptions_notify+0x322/0x3af
[    2.709588] hardirqs last disabled at (370064): [<c0381bb7>]
do_int3+0x1d/0x7d
[    2.709588] softirqs last  enabled at (370050): [<c012b464>]
__do_softirq+0xfa/0x100
[    2.709588] softirqs last disabled at (370045): [<c0107438>]
do_softirq+0x74/0xd9
[    2.714751] Kprobe smoke test passed successfully
[    2.716150] Total HugeTLB memory allocated, 0
[    2.717288] VFS: Disk quotas dquot_6.5.1
[    2.717689] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    2.719630] device class 'bsg': registering
[    2.720568] Block layer SCSI generic (bsg) driver version 0.4 loaded (major
253)
[    2.720619] io scheduler noop registered
[    2.720732] io scheduler anticipatory registered
[    2.720848] io scheduler deadline registered
[    2.721089] io scheduler cfq registered (default)
[    2.721354] pci 0000:00:01.0: Boot video device




cu
Adrian
Comment 3 Vegard Nossum 2008-04-21 08:13:34 UTC
On Mon, Apr 21, 2008 at 5:06 PM, Adrian Bunk <bunk@kernel.org> wrote:
> http://bugzilla.kernel.org/show_bug.cgi?id=10489
>
>  Please reply via email (more information from the submitter is in the
>  Bugzilla entry).
>
>
>  ReportedBy: jeanmarc.lacroix@free.Fr
>
>  Earliest failing kernel version: 2.6.25
>  Distribution: DEbian Etch
>  Hardware Environment: PIII
>  Software Environment:
>  Problem Description: Warning at boot after running all
>  embedded test
>
>  Steps to reproduce: boot !!!
>
>
>    2.701005] Registering sys device '<NULL>'
>  [    2.702320] Registering sys device '<NULL>'
>  [    2.703711] Registering sys device '<NULL>'
>  [    2.704536] Initializing RT-Tester: OK
>  [    2.704824] device: 'snapshot': device_add
>  [    2.705140] PM: Adding info for No Bus:snapshot
>  [    2.706804] audit: initializing netlink socket (disabled)
>  [    2.707199] type=2000 audit(1208713807.707:1): initialized
>  [    2.707509] Kprobe smoke test started
>  [    2.709300] ------------[ cut here ]------------
>  [    2.709420] WARNING: at kernel/lockdep.c:2658 check_flags+0x4d/0x12c()
>  [    2.709541] Modules linked in:
>  [    2.709588] Pid: 1, comm: swapper Not tainted 2.6.25.jml.057 #1
>  [    2.709588]  [<c0126acc>] warn_on_slowpath+0x41/0x51
>  [    2.709588]  [<c010bafc>] ? save_stack_trace+0x1d/0x3b
>  [    2.709588]  [<c0140a83>] ? save_trace+0x37/0x89
>  [    2.709588]  [<c011987d>] ? kernel_map_pages+0x103/0x11c
>  [    2.709588]  [<c0109803>] ? native_sched_clock+0xca/0xea
>  [    2.709588]  [<c0142958>] ? mark_held_locks+0x41/0x5c
>  [    2.709588]  [<c0382580>] ? kprobe_exceptions_notify+0x322/0x3af
>  [    2.709588]  [<c0142aff>] ? trace_hardirqs_on+0xf1/0x119
>  [    2.709588]  [<c03825b3>] ? kprobe_exceptions_notify+0x355/0x3af
>  [    2.709588]  [<c0140823>] check_flags+0x4d/0x12c
>  [    2.709588]  [<c0143c9d>] lock_release+0x58/0x195
>  [    2.709588]  [<c038347c>] ? __atomic_notifier_call_chain+0x0/0x80
>  [    2.709588]  [<c03834d6>] __atomic_notifier_call_chain+0x5a/0x80
>  [    2.709588]  [<c0383508>] atomic_notifier_call_chain+0xc/0xe
>  [    2.709588]  [<c013b6d4>] notify_die+0x2d/0x2f
>  [    2.709588]  [<c038168a>] do_debug+0x67/0xfe
>  [    2.709588]  [<c0381287>] debug_stack_correct+0x27/0x30
>  [    2.709588]  [<c01564c0>] ? kprobe_target+0x1/0x34
>  [    2.709588]  [<c0156572>] ? init_test_probes+0x50/0x186
>  [    2.709588]  [<c04fae48>] init_kprobes+0x85/0x8c
>  [    2.709588]  [<c04e947b>] kernel_init+0x13d/0x298
>  [    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
>  [    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
>  [    2.709588]  [<c0105ef7>] kernel_thread_helper+0x7/0x10
>  [    2.709588]  =======================
>  [    2.709588] ---[ end trace 778e504de7e3b1e3 ]---
>  [    2.709588] possible reason: unannotated irqs-off.
>  [    2.709588] irq event stamp: 370065
>  [    2.709588] hardirqs last  enabled at (370065): [<c0382580>]
>  kprobe_exceptions_notify+0x322/0x3af
>  [    2.709588] hardirqs last disabled at (370064): [<c0381bb7>]
>  do_int3+0x1d/0x7d
>  [    2.709588] softirqs last  enabled at (370050): [<c012b464>]
>  __do_softirq+0xfa/0x100
>  [    2.709588] softirqs last disabled at (370045): [<c0107438>]
>  do_softirq+0x74/0xd9
>  [    2.714751] Kprobe smoke test passed successfully
>  [    2.716150] Total HugeTLB memory allocated, 0
>  [    2.717288] VFS: Disk quotas dquot_6.5.1
>  [    2.717689] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
>  [    2.719630] device class 'bsg': registering
>  [    2.720568] Block layer SCSI generic (bsg) driver version 0.4 loaded
>  (major
>  253)
>  [    2.720619] io scheduler noop registered
>  [    2.720732] io scheduler anticipatory registered
>  [    2.720848] io scheduler deadline registered
>  [    2.721089] io scheduler cfq registered (default)
>  [    2.721354] pci 0000:00:01.0: Boot video device
>

This is because kprobes (just like kmemcheck and mmiotrace) needs to
disable interrupts while it single-steps the instruction. This is not
dangerous, and should be fixed by doing as the warning suggests, by
annotating the irqs-off. I don't remember the name of the function(s),
it is probably somewhere in lockdep.h.

Vegard
Comment 4 Vegard Nossum 2008-04-21 10:38:12 UTC
Hi,

I cannot reproduce it here, but this seems to be a likely fix.

Vegard


diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index 34a5912..6d58f6e 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -424,6 +424,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
 	clear_btf();
 	regs->flags |= X86_EFLAGS_TF;
 	regs->flags &= ~X86_EFLAGS_IF;
+	trace_hardirqs_off();
 	/* single step inline if the instruction is an int3 */
 	if (p->opcode == BREAKPOINT_INSTRUCTION)
 		regs->ip = (unsigned long)p->addr;
Comment 5 Anonymous Emailer 2008-04-21 15:54:27 UTC
Reply-To: mhiramat@redhat.com

Thank you for reporting.

Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
(which is called from kprobe_exceptions_notify) by
trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
is set in pt_regs->flags, true hardirq is still off until returning
from do_debug. Thus, lockdep assumes that hardirq is off without annotation.

IMHO, one possible solution is that fixing hardirq flags right after
notify_die in do_debug instead of in post_kprobe_handler.

Thanks,
Comment 6 Anonymous Emailer 2008-04-22 06:10:45 UTC
Reply-To: peterz@infradead.org

On Mon, 2008-04-21 at 18:54 -0400, Masami Hiramatsu wrote:
> Thank you for reporting.
> 
> Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
> (which is called from kprobe_exceptions_notify) by
> trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
> is set in pt_regs->flags, true hardirq is still off until returning
> from do_debug. Thus, lockdep assumes that hardirq is off without annotation.
> 
> IMHO, one possible solution is that fixing hardirq flags right after
> notify_die in do_debug instead of in post_kprobe_handler.

My reply to BZ 10489:


> [    2.707509] Kprobe smoke test started
> [    2.709300] ------------[ cut here ]------------
> [    2.709420] WARNING: at kernel/lockdep.c:2658 check_flags+0x4d/0x12c()
> [    2.709541] Modules linked in:
> [    2.709588] Pid: 1, comm: swapper Not tainted 2.6.25.jml.057 #1
> [    2.709588]  [<c0126acc>] warn_on_slowpath+0x41/0x51
> [    2.709588]  [<c010bafc>] ? save_stack_trace+0x1d/0x3b
> [    2.709588]  [<c0140a83>] ? save_trace+0x37/0x89
> [    2.709588]  [<c011987d>] ? kernel_map_pages+0x103/0x11c
> [    2.709588]  [<c0109803>] ? native_sched_clock+0xca/0xea
> [    2.709588]  [<c0142958>] ? mark_held_locks+0x41/0x5c
> [    2.709588]  [<c0382580>] ? kprobe_exceptions_notify+0x322/0x3af
> [    2.709588]  [<c0142aff>] ? trace_hardirqs_on+0xf1/0x119
> [    2.709588]  [<c03825b3>] ? kprobe_exceptions_notify+0x355/0x3af
> [    2.709588]  [<c0140823>] check_flags+0x4d/0x12c
> [    2.709588]  [<c0143c9d>] lock_release+0x58/0x195
> [    2.709588]  [<c038347c>] ? __atomic_notifier_call_chain+0x0/0x80
> [    2.709588]  [<c03834d6>] __atomic_notifier_call_chain+0x5a/0x80
> [    2.709588]  [<c0383508>] atomic_notifier_call_chain+0xc/0xe
> [    2.709588]  [<c013b6d4>] notify_die+0x2d/0x2f
> [    2.709588]  [<c038168a>] do_debug+0x67/0xfe
> [    2.709588]  [<c0381287>] debug_stack_correct+0x27/0x30
> [    2.709588]  [<c01564c0>] ? kprobe_target+0x1/0x34
> [    2.709588]  [<c0156572>] ? init_test_probes+0x50/0x186
> [    2.709588]  [<c04fae48>] init_kprobes+0x85/0x8c
> [    2.709588]  [<c04e947b>] kernel_init+0x13d/0x298
> [    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
> [    2.709588]  [<c04e933e>] ? kernel_init+0x0/0x298
> [    2.709588]  [<c0105ef7>] kernel_thread_helper+0x7/0x10
> [    2.709588]  =======================
> [    2.709588] ---[ end trace 778e504de7e3b1e3 ]---
> [    2.709588] possible reason: unannotated irqs-off.
> [    2.709588] irq event stamp: 370065
> [    2.709588] hardirqs last  enabled at (370065): [<c0382580>]
> kprobe_exceptions_notify+0x322/0x3af
> [    2.709588] hardirqs last disabled at (370064): [<c0381bb7>]
> do_int3+0x1d/0x7d
> [    2.709588] softirqs last  enabled at (370050): [<c012b464>]
> __do_softirq+0xfa/0x100
> [    2.709588] softirqs last disabled at (370045): [<c0107438>]
> do_softirq+0x74/0xd9
> [    2.714751] Kprobe smoke test passed successfully

how I love this stuff...


Ok, do_debug() is a trap, this can happen at any time regardless of the
machine's IRQ state. So the first thing we do is fix up the IRQ state.
Then we call this die notifier stuff; and return with messed up IRQ
state... YAY.

So, kprobes fudges it..

  notify_die(DIE_DEBUG)
    kprobe_exceptions_notify()
      post_kprobe_handler()
        modify regs->flags
        trace_hardirqs_fixup_flags(regs->flags);  <--- must be it

So what's the use of modifying flags if they're not meant to take effect
at some point.

/me tries to reproduce issue; enable kprobes test thingy && boot

OK, that reproduces..

So the below makes it work - but I'm not getting this code; at the time
I wrote that stuff I CC'ed each and every kprobe maintainer listed in
the usual places but got no reposonse - can some please explain this
stuff to me?

Are the saved flags only for the TF bit or are they made in full effect
later (and if so, where) ?

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index 34a5912..fe71e64 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -865,7 +865,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
 
        resume_execution(cur, regs, kcb);
        regs->flags |= kcb->kprobe_saved_flags;
-       trace_hardirqs_fixup_flags(regs->flags);
 
        /* Restore back the original saved kprobes variables and continue. */
        if (kcb->kprobe_status == KPROBE_REENTER) {
Comment 7 Anonymous Emailer 2008-04-22 06:26:54 UTC
Reply-To: peterz@infradead.org

On Tue, 2008-04-22 at 15:09 +0200, Peter Zijlstra wrote:
> On Mon, 2008-04-21 at 18:54 -0400, Masami Hiramatsu wrote:
> > Thank you for reporting.
> > 
> > Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
> > (which is called from kprobe_exceptions_notify) by
> > trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
> > is set in pt_regs->flags, true hardirq is still off until returning
> > from do_debug. Thus, lockdep assumes that hardirq is off without
> annotation.

Ah, can you clarrify? pt_regs->flags will only be set when returning to
the original trap site? in that case we should not need a lockdep
annotation I guess, unless its allowed and exptected for the int3 site
to change IRQ state.
Comment 8 Anonymous Emailer 2008-04-22 08:25:47 UTC
Reply-To: mhiramat@redhat.com

Peter Zijlstra wrote:
> On Tue, 2008-04-22 at 15:09 +0200, Peter Zijlstra wrote:
>> On Mon, 2008-04-21 at 18:54 -0400, Masami Hiramatsu wrote:
>>> Thank you for reporting.
>>>
>>> Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
>>> (which is called from kprobe_exceptions_notify) by
>>> trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
>>> is set in pt_regs->flags, true hardirq is still off until returning
>>> from do_debug. Thus, lockdep assumes that hardirq is off without
>>> annotation.
> 
> Ah, can you clarrify? pt_regs->flags will only be set when returning to
> the original trap site? in that case we should not need a lockdep
> annotation I guess, unless its allowed and exptected for the int3 site
> to change IRQ state.

As far as I took a look at the lockdep, your suggestion is correct.
post_kprobe_handler should not set a lockdep annotation, because
processor's IF is not changed yet in that time.

Thanks,
Comment 9 Anonymous Emailer 2008-04-22 09:06:22 UTC
Reply-To: peterz@infradead.org

On Tue, 2008-04-22 at 11:25 -0400, Masami Hiramatsu wrote:
> Peter Zijlstra wrote:
> > On Tue, 2008-04-22 at 15:09 +0200, Peter Zijlstra wrote:
> >> On Mon, 2008-04-21 at 18:54 -0400, Masami Hiramatsu wrote:
> >>> Thank you for reporting.
> >>>
> >>> Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
> >>> (which is called from kprobe_exceptions_notify) by
> >>> trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
> >>> is set in pt_regs->flags, true hardirq is still off until returning
> >>> from do_debug. Thus, lockdep assumes that hardirq is off without
> annotation.
> > 
> > Ah, can you clarrify? pt_regs->flags will only be set when returning to
> > the original trap site? in that case we should not need a lockdep
> > annotation I guess, unless its allowed and exptected for the int3 site
> > to change IRQ state.
> 
> As far as I took a look at the lockdep, your suggestion is correct.
> post_kprobe_handler should not set a lockdep annotation, because
> processor's IF is not changed yet in that time.

That much was clear; but when _will_ it be changed?
Comment 10 Anonymous Emailer 2008-04-22 09:18:39 UTC
Reply-To: mhiramat@redhat.com

Hi Peter,

Thank you for the patch,

Peter Zijlstra wrote:
> So the below makes it work - but I'm not getting this code; at the time
> I wrote that stuff I CC'ed each and every kprobe maintainer listed in
> the usual places but got no reposonse - can some please explain this
> stuff to me?

Sure, I came to the same decision. It is enough to remove unnecessary
trace_hardirqs_fixup_flags() from post_kprobe_handler. pt_regs->flags is
just a variable on stack -- not effective flags in that time. So we don't
need to change thread's hardirq flag.

> Are the saved flags only for the TF bit or are they made in full effect
> later (and if so, where) ?

The saved flags is for TF and IF bits.
Actually, kprobes does following:

---
do_int3()
 kprobe_exceptions_notify()
  kprobe_handler()
   prepare_singlestep() : save regs->flags, set TF and clear IF on regs->flags
"iret" : pop regs->flags image to EFLAGS reg.

<single step an instruction>

do_debug()
 kprobe_exceptions_notify()
  post_kprobe_handler() : restore regs->flags (clearing TF and restoring IF)
"iret" : pop regs->flags image to EFLAGS reg.
---

While executing a single step, EFLAGS is different from the original EFLAGS.
However, it will be recovered soon by post_kprobe_handler.
NOTE: if the single-stepping instruction is a pushf, kprobes writes saved
     EFLAGS to the top of stack.

> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

I tested it on x86-64/i386.

Acked-by: Masami Hiramatsu <mhiramat@redhat.com>

> ---
> diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
> index 34a5912..fe71e64 100644
> --- a/arch/x86/kernel/kprobes.c
> +++ b/arch/x86/kernel/kprobes.c
> @@ -865,7 +865,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs
> *regs)
>  
>         resume_execution(cur, regs, kcb);
>         regs->flags |= kcb->kprobe_saved_flags;
> -       trace_hardirqs_fixup_flags(regs->flags);
>  
>         /* Restore back the original saved kprobes variables and continue. */
>         if (kcb->kprobe_status == KPROBE_REENTER) {
> 
> 
> 
Comment 11 Anonymous Emailer 2008-04-22 09:23:57 UTC
Reply-To: mhiramat@redhat.com

Peter Zijlstra wrote:
> On Tue, 2008-04-22 at 11:25 -0400, Masami Hiramatsu wrote:
>> Peter Zijlstra wrote:
>>> On Tue, 2008-04-22 at 15:09 +0200, Peter Zijlstra wrote:
>>>> On Mon, 2008-04-21 at 18:54 -0400, Masami Hiramatsu wrote:
>>>>> Thank you for reporting.
>>>>>
>>>>> Actually, kprobes tries to fixup thread's flags in post_kprobe_handler
>>>>> (which is called from kprobe_exceptions_notify) by
>>>>> trace_hardirqs_fixup_flags(pt_regs->flags). However, even the irq flag
>>>>> is set in pt_regs->flags, true hardirq is still off until returning
>>>>> from do_debug. Thus, lockdep assumes that hardirq is off without
>>>>> annotation.
>>> Ah, can you clarrify? pt_regs->flags will only be set when returning to
>>> the original trap site? in that case we should not need a lockdep
>>> annotation I guess, unless its allowed and exptected for the int3 site
>>> to change IRQ state.
>> As far as I took a look at the lockdep, your suggestion is correct.
>> post_kprobe_handler should not set a lockdep annotation, because
>> processor's IF is not changed yet in that time.
> 
> That much was clear; but when _will_ it be changed?

processor's IF bit is changed when an iret(q) is issued.
In other words, when returning from a debug/int3 exception.
Comment 12 Anonymous Emailer 2008-04-22 12:52:02 UTC
Reply-To: mhiramat@redhat.com

Masami Hiramatsu wrote:
> processor's IF bit is changed when an iret(q) is issued.
> In other words, when returning from a debug/int3 exception.

By the way, when returning from an exception on x86-64, it seems
paranoidexit@entry_64.S doesn't use TRACE_IRQS_IRETQ except for
it executes swapgs, does it?

If not, I guess the lockdep on x86-64 may causes an warning
by below code:

spin_lock(...)
kprobe_target_function()
spin_unlock(...)

Thanks,

Note You need to log in before you can comment on or make changes to this bug.