Re: [RFC PATCH 3/3] alloc_tag: remove /proc/allocinfo outside of mod_lock
Suren Baghdasaryan <[email protected]>
| Newsgroups | org.kernel.vger.linux-modules,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <CAJuCfpGfQrYJ=Rgrar-8btsiUCg=OQotWPou0J-mpMFNzrJC6A@mail.gmail.com> |
On Thu, Aug 13, 2026 at 2:34 AM Hao Ge <[email protected]> wrote: > > shutdown_mem_profiling() calls remove_proc_entry() from > reserve_module_tags(), which runs under mod_lock held for write. > remove_proc_entry() waits for readers, and a reader takes mod_lock for > read in allocinfo_start(): > > CPU0 (insmod) CPU1 (read /proc/allocinfo) > ---------------- ---------------------------- > reserve_module_tags() > down_write(&mod_lock) [held] > use_pde() [in_use++] > allocinfo_start() > down_read(&mod_lock) <- blocks > shutdown_mem_profiling() > remove_proc_entry() > wait for in_use == 0 <- blocks Yes, this is indeed a possible race. > > Move remove_proc_entry() to a workqueue. > > Fixes: 4835f747d3ed ("alloc_tag: support for page allocation tag compression") I think all these issues were reported by Sashiko, so you should add a Reported-by tag. > Signed-off-by: Hao Ge <[email protected]> LGTM > --- > mm/alloc_tag.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c > index 7481180dadd2..b80f5a151f28 100644 > --- a/mm/alloc_tag.c > +++ b/mm/alloc_tag.c > @@ -591,6 +591,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old) > put_page_tag_ref(handle_new); > } > > +static void remove_allocinfo_file(struct work_struct *work) > +{ > + remove_proc_entry(ALLOCINFO_FILE_NAME, NULL); > +} > + > +static DECLARE_WORK(remove_allocinfo_work, remove_allocinfo_file); > + > static void shutdown_mem_profiling(bool remove_file) > { > if (mem_alloc_profiling_enabled()) > @@ -600,7 +607,7 @@ static void shutdown_mem_profiling(bool remove_file) > return; > > if (remove_file) > - remove_proc_entry(ALLOCINFO_FILE_NAME, NULL); > + schedule_work(&remove_allocinfo_work); > mem_profiling_support = false; > } > > -- > 2.25.1 >