rcu: Make vmalloc_dump_obj() call in a preemptible context
Subsystems (3)
PATCH 1/1 rcu: Make vmalloc_dump_obj() call in a preemptible context
Currently, the mem_dump_obj() is invoked in call_rcu(), the call_rcu() is maybe invoked in non-preemptive code segment, for object allocated from vmalloc(), the following scenarios may occur:
CPU 0
tasks context
spin_lock(&vmap_area_lock)
Interrupt context
call_rcu()
mem_dump_obj
vmalloc_dump_obj
spin_lock(&vmap_area_lock) <--deadlockand for PREEMPT-RT kernel, the spinlock will convert to sleepable lock, it also make vmap_area_lock spinlock can not acquire in non-preemptive code segment. therefore, this commit make the vmalloc_dump_obj() call in a preemptible context.
--- mm/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
mm/util.c +7 -3
@@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object)return ; } -if (vmalloc_dump_obj (object)) -return ; +if (is_vmalloc_addr (object)) { +if (preemptible () &&vmalloc_dump_obj (object)) +return ; + type ="vmalloc memory" ; + goto end; + }if (virt_addr_valid (object)) type ="non-slab/vmalloc memory" ;
@@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) type ="zero-size pointer" ; else type ="non-paged memory" ; - +end:pr_cont (" %s\n" , type); }EXPORT_SYMBOL_GPL (mem_dump_obj);
Signature · 1 line
2.25.1
Quoted 1 line · Zqiang
Currently, the
mem_dump_obj()is invoked incall_rcu(), the
Plan to call mem_dump_obj() in rcu_do_batch().
Quoted 28 lines
call_rcu()is maybe invoked in non-preemptive code segment, for object allocated fromvmalloc(), the following scenarios may occur:CPU 0
tasks context
spin_lock(&vmap_area_lock)Interrupt context call_rcu() mem_dump_obj vmalloc_dump_obj spin_lock(&vmap_area_lock) <--deadlockand for PREEMPT-RT kernel, the spinlock will convert to sleepable lock, it also make
vmap_area_lockspinlock can not acquire in non-preemptive code segment. therefore, this commit make thevmalloc_dump_obj()call in a preemptible context.Signed-off-by Zqiang <[email protected]>--- mm/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)mm/util.c +0
-0
mm/util.c void mem_dump_obj(void *object) · line 1128
Quoted 7 lines
mm/util.c +2
-2@@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object)return ; } -if (vmalloc_dump_obj (object)) -return ; +if (is_vmalloc_addr (object)) { +if (preemptible () &&vmalloc_dump_obj (object))
preemptible() --> !in_interrupt()?
mm/util.c void mem_dump_obj(void *object) · line 1132
Quoted 4 lines
mm/util.c +4
-0+return ; + type ="vmalloc memory" ; + goto end; + }
Move into vmalloc_dump_obj()?
Quoted 13 lines
mm/util.c +1
-1if (virt_addr_valid (object)) type ="non-slab/vmalloc memory" ;@@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) type ="zero-size pointer" ; else type ="non-paged memory" ; - +end:pr_cont (" %s\n" , type); }EXPORT_SYMBOL_GPL (mem_dump_obj);
Signature · 2 lines
Regards, Zhen Lei
Quoted 40 lines · Zqiang
Currently, the
mem_dump_obj()is invoked incall_rcu(), thePlan to call
mem_dump_obj()inrcu_do_batch().
call_rcu()is maybe invoked in non-preemptive code segment, for object allocated fromvmalloc(), the following scenarios may occur:CPU 0
tasks context
spin_lock(&vmap_area_lock)Interrupt context call_rcu() mem_dump_obj vmalloc_dump_obj spin_lock(&vmap_area_lock) <--deadlockand for PREEMPT-RT kernel, the spinlock will convert to sleepable lock, it also make
vmap_area_lockspinlock can not acquire in non-preemptive code segment. therefore, this commit make thevmalloc_dump_obj()call in a preemptible context.Signed-off-by Zqiang <[email protected]>--- mm/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)mm/util.c +2
-2@@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object)return ; } -if (vmalloc_dump_obj (object)) -return ; +if (is_vmalloc_addr (object)) { +if (preemptible () &&vmalloc_dump_obj (object))
Quoted 1 line
preemptible()--> !in_interrupt()?
Hi Leizhen
!in_interrupt() not include following scenario:
task context:
local_irq_save() or preempt_disable();call_rcu()
mem_dump_obj() vmalloc_dump_obj() spin_lock(&vmap_area_lock)
local_irq_restore() or preempt_denable();
for PREEMPT-RT kernel, spinlock will convert to sleepable lock.
Quoted 7 lines
mm/util.c +4
-0+return ; + type ="vmalloc memory" ; + goto end; + }Move into
vmalloc_dump_obj()?
you mean move preemptible() into vmalloc_dump_obj()?
Thanks
Zqiang
Quoted 14 lines
mm/util.c +1
-1if (virt_addr_valid (object)) type ="non-slab/vmalloc memory" ;@@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) type ="zero-size pointer" ; else type ="non-paged memory" ; - +end:pr_cont (" %s\n" , type); }EXPORT_SYMBOL_GPL (mem_dump_obj);
Signature · 2 lines
Regards, Zhen Lei
Quoted 51 lines · On 2022/11/17 13:20, Zhang, Qiang1 wrote:
Quoted 40 lines · Zqiang
Currently, the
mem_dump_obj()is invoked incall_rcu(), thePlan to call
mem_dump_obj()inrcu_do_batch().
call_rcu()is maybe invoked in non-preemptive code segment, for object allocated fromvmalloc(), the following scenarios may occur:CPU 0
tasks context
spin_lock(&vmap_area_lock)Interrupt context call_rcu() mem_dump_obj vmalloc_dump_obj spin_lock(&vmap_area_lock) <--deadlockand for PREEMPT-RT kernel, the spinlock will convert to sleepable lock, it also make
vmap_area_lockspinlock can not acquire in non-preemptive code segment. therefore, this commit make thevmalloc_dump_obj()call in a preemptible context.Signed-off-by Zqiang <[email protected]>--- mm/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)mm/util.c +2
-2@@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object)return ; } -if (vmalloc_dump_obj (object)) -return ; +if (is_vmalloc_addr (object)) { +if (preemptible () &&vmalloc_dump_obj (object))Quoted 1 line
preemptible()--> !in_interrupt()?Hi Leizhen
!in_interrupt() not include following scenario:
task context:
Quoted 8 lines
local_irq_save()orpreempt_disable();call_rcu()mem_dump_obj() vmalloc_dump_obj() spin_lock(&vmap_area_lock)
local_irq_restore()orpreempt_denable();for PREEMPT-RT kernel, spinlock will convert to sleepable lock.
OK.
Quoted 10 lines
Quoted 8 lines
mm/util.c +4
-0+return ; + type ="vmalloc memory" ; + goto end; + }Move into
vmalloc_dump_obj()?you mean move
preemptible()intovmalloc_dump_obj()?
Move all? Currently, vmalloc_dump_obj() is invoked only by mem_dump_obj(). The encapsulation is a little better in my opinion.
Quoted 19 lines
Thanks
ZqiangQuoted 14 lines
mm/util.c +1
-1if (virt_addr_valid (object)) type ="non-slab/vmalloc memory" ;@@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) type ="zero-size pointer" ; else type ="non-paged memory" ; - +end:pr_cont (" %s\n" , type); }EXPORT_SYMBOL_GPL (mem_dump_obj);
Signature · 2 lines
Regards, Zhen Lei