From: Andrew Morton <akpm@linux-foundation.org>
To: Zqiang <qiang1.zhang@intel.com>
Cc: paulmck@kernel.org, thunder.leizhen@huawei.com,
frederic@kernel.org, joel@joelfernandes.org, rcu@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm: Make vmalloc_dump_obj() call in a preemptible context
Date: Thu, 17 Nov 2022 12:33:24 -0800 [thread overview]
Message-ID: <20221117123324.c3cdad45b3204d57b5f7bc3d@linux-foundation.org> (raw)
In-Reply-To: <20221117112520.3942618-1-qiang1.zhang@intel.com>
On Thu, 17 Nov 2022 19:25:20 +0800 Zqiang <qiang1.zhang@intel.com> wrote:
> 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) <--deadlock
>
> and for PREEMPT-RT kernel, the spinlock will convert to sleepable
> lock, so the vmap_area_lock spinlock not allowed to get in non-preemptive
> code segment. therefore, this commit make the vmalloc_dump_obj() call in
> a preemptible context.
>
> ...
>
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -1128,7 +1128,9 @@ void mem_dump_obj(void *object)
> return;
>
> if (virt_addr_valid(object))
> - type = "non-slab/vmalloc memory";
> + type = "non-slab memory";
> + else if (is_vmalloc_addr(object))
> + type = "vmalloc memory";
> else if (object == NULL)
> type = "NULL pointer";
> else if (object == ZERO_SIZE_PTR)
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index ccaa461998f3..018e417b12d6 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -4034,6 +4034,10 @@ bool vmalloc_dump_obj(void *object)
> struct vm_struct *vm;
> void *objp = (void *)PAGE_ALIGN((unsigned long)object);
>
> + if (!is_vmalloc_addr(objp) || ((IS_ENABLED(CONFIG_PREEMPT_RT) &&
> + !preemptible()) || in_interrupt()))
> + return false;
> +
> vm = find_vm_area(objp);
> if (!vm)
> return false;
I suggest this be restructured so we can comment each test:
/* comment goes here */
if (!is_vmalloc_addr(objp))
return false;
/* comment goes here */
if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
return false;
/* comment goes here */
if (in_interrupt()))
return false;
Where each comment carefully explains why we're performing the test.
It will generate the same code.
prev parent reply other threads:[~2022-11-17 20:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 11:25 Zqiang
2022-11-17 20:33 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221117123324.c3cdad45b3204d57b5f7bc3d@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=frederic@kernel.org \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang1.zhang@intel.com \
--cc=rcu@vger.kernel.org \
--cc=thunder.leizhen@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®