* [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context
@ 2022-11-12 12:15 Zhen Lei
2022-11-15 0:54 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Zhen Lei @ 2022-11-12 12:15 UTC (permalink / raw)
To: Andrew Morton, linux-mm, linux-kernel
Cc: Zhen Lei, Paul E . McKenney, Zhang Qiang1
The function mem_dump_obj() can sometimes provide valuable debugging
information, but it cannot be called in an interrupt context because
spinlock vmap_area_lock has not been protected against IRQs. If the
current task has held the lock before hard/soft interrupt handler calls
mem_dump_obj(), simply abandoning the dump operation can avoid deadlock.
That is, no deadlock occurs in extreme cases, and dump succeeds in most
cases.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
mm/vmalloc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ccaa461998f3c37..cdd36c5a1aa16f8 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4034,6 +4034,9 @@ bool vmalloc_dump_obj(void *object)
struct vm_struct *vm;
void *objp = (void *)PAGE_ALIGN((unsigned long)object);
+ if (unlikely(spin_is_locked(&vmap_area_lock)))
+ return false;
+
vm = find_vm_area(objp);
if (!vm)
return false;
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context
2022-11-12 12:15 [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context Zhen Lei
@ 2022-11-15 0:54 ` Andrew Morton
2022-11-15 2:01 ` Leizhen (ThunderTown)
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2022-11-15 0:54 UTC (permalink / raw)
To: Zhen Lei
Cc: linux-mm, linux-kernel, Paul E . McKenney, Zhang Qiang1,
Uladzislau Rezki (Sony)
On Sat, 12 Nov 2022 20:15:37 +0800 Zhen Lei <thunder.leizhen@huawei.com> wrote:
> The function mem_dump_obj() can sometimes provide valuable debugging
> information, but it cannot be called in an interrupt context because
> spinlock vmap_area_lock has not been protected against IRQs. If the
> current task has held the lock before hard/soft interrupt handler calls
> mem_dump_obj(), simply abandoning the dump operation can avoid deadlock.
> That is, no deadlock occurs in extreme cases, and dump succeeds in most
> cases.
>
> ...
>
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -4034,6 +4034,9 @@ bool vmalloc_dump_obj(void *object)
> struct vm_struct *vm;
> void *objp = (void *)PAGE_ALIGN((unsigned long)object);
>
> + if (unlikely(spin_is_locked(&vmap_area_lock)))
> + return false;
> +
> vm = find_vm_area(objp);
> if (!vm)
> return false;
Yes, but this will worsen the current uses of this function. Consider
the case where task A wants to call vmalloc_dump_obj() but task B holds
vmap_area_lock. No problem, task A will simply spin until task B is
done.
But after this patch, task A's call to vmalloc_dump_obj() will return
without having done anything.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context
2022-11-15 0:54 ` Andrew Morton
@ 2022-11-15 2:01 ` Leizhen (ThunderTown)
2022-11-16 14:05 ` Leizhen (ThunderTown)
0 siblings, 1 reply; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2022-11-15 2:01 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Paul E . McKenney, Zhang Qiang1,
Uladzislau Rezki (Sony)
On 2022/11/15 8:54, Andrew Morton wrote:
> On Sat, 12 Nov 2022 20:15:37 +0800 Zhen Lei <thunder.leizhen@huawei.com> wrote:
>
>> The function mem_dump_obj() can sometimes provide valuable debugging
>> information, but it cannot be called in an interrupt context because
>> spinlock vmap_area_lock has not been protected against IRQs. If the
>> current task has held the lock before hard/soft interrupt handler calls
>> mem_dump_obj(), simply abandoning the dump operation can avoid deadlock.
>> That is, no deadlock occurs in extreme cases, and dump succeeds in most
>> cases.
>>
>> ...
>>
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -4034,6 +4034,9 @@ bool vmalloc_dump_obj(void *object)
>> struct vm_struct *vm;
>> void *objp = (void *)PAGE_ALIGN((unsigned long)object);
>>
>> + if (unlikely(spin_is_locked(&vmap_area_lock)))
>> + return false;
>> +
>> vm = find_vm_area(objp);
>> if (!vm)
>> return false;
>
> Yes, but this will worsen the current uses of this function. Consider
> the case where task A wants to call vmalloc_dump_obj() but task B holds
> vmap_area_lock. No problem, task A will simply spin until task B is
> done.
>
> But after this patch, task A's call to vmalloc_dump_obj() will return
> without having done anything.
Oh, right, this problem occurs when task A and task B run on
two different cores.
>
> .
>
--
Regards,
Zhen Lei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context
2022-11-15 2:01 ` Leizhen (ThunderTown)
@ 2022-11-16 14:05 ` Leizhen (ThunderTown)
0 siblings, 0 replies; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2022-11-16 14:05 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Paul E . McKenney, Zhang Qiang1,
Uladzislau Rezki (Sony)
On 2022/11/15 10:01, Leizhen (ThunderTown) wrote:
>
>
> On 2022/11/15 8:54, Andrew Morton wrote:
>> On Sat, 12 Nov 2022 20:15:37 +0800 Zhen Lei <thunder.leizhen@huawei.com> wrote:
>>
>>> The function mem_dump_obj() can sometimes provide valuable debugging
>>> information, but it cannot be called in an interrupt context because
>>> spinlock vmap_area_lock has not been protected against IRQs. If the
>>> current task has held the lock before hard/soft interrupt handler calls
>>> mem_dump_obj(), simply abandoning the dump operation can avoid deadlock.
>>> That is, no deadlock occurs in extreme cases, and dump succeeds in most
>>> cases.
>>>
>>> ...
>>>
>>> --- a/mm/vmalloc.c
>>> +++ b/mm/vmalloc.c
>>> @@ -4034,6 +4034,9 @@ bool vmalloc_dump_obj(void *object)
>>> struct vm_struct *vm;
>>> void *objp = (void *)PAGE_ALIGN((unsigned long)object);
>>>
>>> + if (unlikely(spin_is_locked(&vmap_area_lock)))
>>> + return false;
>>> +
>>> vm = find_vm_area(objp);
>>> if (!vm)
>>> return false;
>>
>> Yes, but this will worsen the current uses of this function. Consider
>> the case where task A wants to call vmalloc_dump_obj() but task B holds
>> vmap_area_lock. No problem, task A will simply spin until task B is
>> done.
>>
>> But after this patch, task A's call to vmalloc_dump_obj() will return
>> without having done anything.
>
> Oh, right, this problem occurs when task A and task B run on
> two different cores.
I've rethought it, this can be solved by adding in_interrupt().
>
>
>>
>> .
>>
>
--
Regards,
Zhen Lei
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-16 14:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-12 12:15 [PATCH] mm/vmalloc: allow mem_dump_obj() to be called in interrupt context Zhen Lei
2022-11-15 0:54 ` Andrew Morton
2022-11-15 2:01 ` Leizhen (ThunderTown)
2022-11-16 14:05 ` Leizhen (ThunderTown)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox