rcu: avoid alloc_pages() when recording stack
PATCH 1/1 rcu: avoid alloc_pages() when recording stack
The default kasan_record_aux_stack() calls stack_depot_save() with GFP_NOWAIT, which in turn can then call alloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use either GFP_ATOMIC nor GFP_NOWAIT in certain non-preemptive contexts/RT kernel including raw_spin_locks (see gfp.h and ab00db216c9c7).
Fix it by instructing stackdepot to not expand stack storage via alloc_pages() in case it runs out by using kasan_record_aux_stack_noalloc().
Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9
--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +2 -2
@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */
@@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; } -kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);
Signature · 1 line
2.33.0
Add KASAN maintainers
Quoted 88 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +2
-2@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; } -kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);
Uladzislau Rezki
maintainerQuoted 87 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }
Quoted 6 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);
Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Signature · 1 line
Uladzislau Rezki
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 2 lines
--
Uladzislau Rezki
Thanks your approval. Could you like to give me a review?
And This fix patch is my last patch in WindRiver by using email of [email protected]. Because i will go to intel next week.
What about your advice @Paul E
---
Jun Miao
Quoted 99 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 5 lines
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Signature · 1 line
Uladzislau Rezki
Paul E. McKenney
maintainerQuoted 100 lines · Uladzislau Rezki
Quoted 99 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>
I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
Thanx, Paul
Paul E. McKenney
maintainerQuoted 108 lines · Paul E. McKenney
Quoted 100 lines · Uladzislau Rezki
Quoted 99 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>
Quoted 7 lines
I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
Well, the compiler does have an opinion:
kernel/rcu/tree.c: In function ‘__call_rcu’:kernel/rcu/tree.c:3029:2: error: implicit declaration of function ‘kasan_record_aux_stack_noalloc’; did you mean ‘kasan_record_aux_stack’? [-Werror=implicit-function-declaration]
3029 | kasan_record_aux_stack_noalloc(head);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| kasan_record_aux_stackI get the same message after merging in current mainline.
I have therefore dropped this patch for the time being.
Thanx, Paul
Quoted 123 lines · Paul E. McKenney
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 104 lines · Paul E. McKenney
Quoted 103 lines · Uladzislau Rezki
Quoted 102 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Quoted 8 lines
Quoted 1 line
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
Well, the compiler does have an opinion:
kernel/rcu/tree.c: In function ‘__call_rcu’:kernel/rcu/tree.c:3029:2: error: implicit declaration of function ‘kasan_record_aux_stack_noalloc’; did you mean ‘kasan_record_aux_stack’? [-Werror=implicit-function-declaration]3029 | kasan_record_aux_stack_noalloc(head); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | kasan_record_aux_stack
Quoted 5 lines
I get the same message after merging in current mainline.
I have therefore dropped this patch for the time being.
Thanx, Paul
Hi Paul E,
The kasan_record_aux_stack_noalloc() is just introduce to linux-next now, and marking "Notice: this object is not reachable from any branch." in commit.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/kasan.h?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926
--- ---
Jun Miao
Paul E. McKenney
maintainerQuoted 127 lines · Jun Miao
Quoted 125 lines · Paul E. McKenney
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 104 lines · Paul E. McKenney
Quoted 103 lines · Uladzislau Rezki
Quoted 102 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Quoted 8 lines
Quoted 1 line
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
Well, the compiler does have an opinion:
kernel/rcu/tree.c: In function ‘__call_rcu’:kernel/rcu/tree.c:3029:2: error: implicit declaration of function ‘kasan_record_aux_stack_noalloc’; did you mean ‘kasan_record_aux_stack’? [-Werror=implicit-function-declaration]3029 | kasan_record_aux_stack_noalloc(head); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | kasan_record_aux_stackI get the same message after merging in current mainline.
Quoted 8 lines
Quoted 3 lines
I have therefore dropped this patch for the time being.
Thanx, Paul
Hi Paul E,
Thekasan_record_aux_stack_noalloc()is just introduce to linux-next now, and marking "Notice: this object is not reachable from any branch." in commit.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/kasan.h?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926
That would explain it! Feel free to resend once the functionality is more generally available.
Thanx, Paul
Quoted 132 lines · Paul E. McKenney
Quoted 130 lines · Jun Miao
Quoted 128 lines · Paul E. McKenney
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 104 lines · Paul E. McKenney
Quoted 103 lines · Uladzislau Rezki
Quoted 102 lines · Jun Miao
Quoted 96 lines · Uladzislau Rezki
[Please note: This e-mail is from an EXTERNAL e-mail address]
Quoted 86 lines
Add KASAN maintainers
Quoted 83 lines · Jun Miao
The default
kasan_record_aux_stack()callsstack_depot_save()withGFP_NOWAIT, which in turn can then callalloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use eitherGFP_ATOMICnorGFP_NOWAITin certain non-preemptive contexts/RT kernel includingraw_spin_locks(seegfp.handab00db216c9c7).Fix it by instructing stackdepot to not expand stack storage via
alloc_pages()in case it runs out by usingkasan_record_aux_stack_noalloc().Jianwei Hu reported:
BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:969 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 15319, name: python3 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [<ffffffff856c8b13>] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 6 PID: 15319 Comm: python3 Tainted: G W O 5.15-rc7-preempt-rt #1 Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN4F, BIOS 1.1b 12/17/2018 Call Trace: show_stack+0x52/0x58 dump_stack+0xa1/0xd6 ___might_sleep.cold+0x11c/0x12d rt_spin_lock+0x3f/0xc0 rmqueue+0x100/0x1460 rmqueue+0x100/0x1460 mark_usage+0x1a0/0x1a0 ftrace_graph_ret_addr+0x2a/0xb0 rmqueue_pcplist.constprop.0+0x6a0/0x6a0 __kasan_check_read+0x11/0x20 __zone_watermark_ok+0x114/0x270 get_page_from_freelist+0x148/0x630 is_module_text_address+0x32/0xa0 __alloc_pages_nodemask+0x2f6/0x790 __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 create_prof_cpu_mask+0x30/0x30 alloc_pages_current+0xb1/0x150 stack_depot_save+0x39f/0x490 kasan_save_stack+0x42/0x50 kasan_save_stack+0x23/0x50 kasan_record_aux_stack+0xa9/0xc0 __call_rcu+0xff/0x9c0 call_rcu+0xe/0x10 put_object+0x53/0x70 __delete_object+0x7b/0x90 kmemleak_free+0x46/0x70 slab_free_freelist_hook+0xb4/0x160 kfree+0xe5/0x420 kfree_const+0x17/0x30 kobject_cleanup+0xaa/0x230 kobject_put+0x76/0x90 netdev_queue_update_kobjects+0x17d/0x1f0 ... ... ksys_write+0xd9/0x180 __x64_sys_write+0x42/0x50 do_syscall_64+0x38/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9Fixes 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN")Fixes 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack")Reported-by Jianwei Hu <[email protected]>Signed-off-by Jun Miao <[email protected]>--- kernel/rcu/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree.c +1
-1@@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next =NULL ;local_irq_save (flags); -kasan_record_aux_stack (head); +kasan_record_aux_stack_noalloc (head); rdp =this_cpu_ptr (&rcu_data);/* Add the callback to our list. */ @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)return ; }Quoted 5 lines
kernel/rcu/tree.c void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · line 3597
Quoted 5 lines
kernel/rcu/tree.c +1
-1-kasan_record_aux_stack (ptr); +kasan_record_aux_stack_noalloc (ptr); success =add_ptr_to_bulk_krc_lock (&krcp, &flags, ptr, !head);if (!success) {run_page_cache_worker (krcp);Yep an allocation is tricky here. This change looks correct to me at least from the point that it does not allocate.
Quoted 2 lines
--
Uladzislau RezkiThanks your approval. Could you like to give me a review?
Quoted 8 lines
Quoted 1 line
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
Well, the compiler does have an opinion:
kernel/rcu/tree.c: In function ‘__call_rcu’:kernel/rcu/tree.c:3029:2: error: implicit declaration of function ‘kasan_record_aux_stack_noalloc’; did you mean ‘kasan_record_aux_stack’? [-Werror=implicit-function-declaration]3029 | kasan_record_aux_stack_noalloc(head); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | kasan_record_aux_stackI get the same message after merging in current mainline.
I have therefore dropped this patch for the time being.
Thanx, Paul
Quoted 8 lines
Quoted 5 lines
Hi Paul E,
Thekasan_record_aux_stack_noalloc()is just introduce to linux-next now, and marking "Notice: this object is not reachable from any branch." in commit.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/kasan.h?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926That would explain it! Feel free to resend once the functionality is more generally available.
[email protected] mailing list
I found the full commit with kasan_record_aux_stack_noalloc() implementation:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926
but it calls kasan_save_stack() with second bool argument, and kasan_save_stack() accepts only 1 argument:
https://elixir.bootlin.com/linux/latest/source/mm/kasan/common.c#L33
so I am lost and can't comment on any of the Paul's questions re interrupts/spinlocks.
When re-sending this, please add kasan-dev@ mailing list and add links to the dependencies.
Thanks
On Mon, 8 Nov 2021 at 12:42, 'Dmitry Vyukov' via kasan-dev <[email protected]> wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>I have queued it for review and testing, thank you both! I do have some remaining concerns about this code being starved for memory. I am wondering if the code needs to check the interrupt state. And perhaps also whether locks are held. I of course will refrain from sending this to mainline until these concerns are resolved.
Marco, Dmitry, thoughts?
It's a general limitation of kasan_record_aux_stack_noalloc(), and if stackdepot's pool is exhausted, we just don't record the stacktrace. But given we just can't allocate any memory at all, I think it's the best we can do.
However, given there are enough normal (with allocation allowed) uses of stackdepot with KASAN enabled, the chances of stackdepot having exhausted its pool when calling this are small. The condition when recording the stack with the _noalloc() variant would fail is:
stackdepot runs out of space AND the same stack trace has not been recorded before. And the only time we'd notice this is if we actually hit a kernel bug that KASAN wants to report. The aggregate probability of all this happening is very very low.
The original series has some more explanation:
https://lkml.kernel.org/r/[email protected]
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Well, the compiler does have an opinion:
kernel/rcu/tree.c: In function ‘__call_rcu’:kernel/rcu/tree.c:3029:2: error: implicit declaration of function ‘kasan_record_aux_stack_noalloc’; did you mean ‘kasan_record_aux_stack’? [-Werror=implicit-function-declaration]3029 | kasan_record_aux_stack_noalloc(head); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | kasan_record_aux_stackI get the same message after merging in current mainline.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
I have therefore dropped this patch for the time being.
Thanx, Paul
Hi Paul E,
Thekasan_record_aux_stack_noalloc()is just introduce to linux-next now, and marking "Notice: this object is not reachable from any branch." in commit.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/kasan.h?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926
"Notice: this object is not reachable from any branch." because it kept changing the hash since it's in the -mm tree.
Quoted 5 lines
Quoted 2 lines
That would explain it! Feel free to resend once the functionality is more generally available.
[email protected] mailing list
Quoted 8 lines
I found the full commit with
kasan_record_aux_stack_noalloc()implementation:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20211029&id=2f64acf6b653d01fbdc92a693f12bbf71a205926but it calls
kasan_save_stack()with second bool argument, andkasan_save_stack()accepts only 1 argument:
https://elixir.bootlin.com/linux/latest/source/mm/kasan/common.c#L33
so I am lost and can't comment on any of the Paul's questions re interrupts/spinlocks.
None of the kasan_record_aux_stack_noalloc() code and its dependencies were in mainline yet. I think it landed a few days ago, but too late for the patches here.