From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Yang Shi <yang@os.amperecomputing.com>
Cc: cl@gentwo.org, dennis@kernel.org, tj@kernel.org,
urezki@gmail.com, catalin.marinas@arm.com, will@kernel.org,
ryan.roberts@arm.com, david@kernel.org,
akpm@linux-foundation.org, hca@linux.ibm.com, gor@linux.ibm.com,
agordeev@linux.ibm.com, linux-mm@kvack.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 04/16] vmalloc: pass in pgd pointer for vmap{__vunmap}_range_noflush()
Date: Tue, 4 Aug 2026 14:47:15 +0100 [thread overview]
Message-ID: <anHqZbo87H1hpC7V@lucifer> (raw)
In-Reply-To: <64d83bb0-b19c-47cd-94db-34ac99686ed0@os.amperecomputing.com>
On Mon, Aug 03, 2026 at 12:12:03PM -0700, Yang Shi wrote:
>
>
> On 7/29/26 2:32 AM, Lorenzo Stoakes (ARM) wrote:
> > On Wed, Jul 15, 2026 at 11:04:06AM -0700, Yang Shi wrote:
> > > vmap{__vunmap}_range_noflush() assume manipulate init_mm pgd. The
> > It's not an assumption, it's a requirement.
> >
> > There is now (and really should have always been) strictly a locking requirement
> > that the mm being manipulated is init_mm.
> >
> > > following patch will map percpu local mapping into percpu page table by
> > > calling them, so the assumption will no longer stand. Make them take
> > > pgd pointer as an parameter.
> > No, this isn't OK.
> >
> > vmalloc is expressly for manipulating kernel mappings in init_mm.
>
> This commit message may be a little bit misleading. vmalloc still
It is - it's worse than that implies :) as you're actually allowing arbitrary
mm's to be manipulated.
> manipulates init_mm all the time. The percpu allocator uses some vmalloc
> APIs to map memory. So the APIs used by percpu allocator needs to manipulate
> percpu page table when mapping memory for the new percpu area added by the
> following patches. So percpu pgd is just used when mapping the specific
> percpu area by percpu allocator.
Yup I understand all that, but my objection remains the same. You're essentially
hacking something in to the vmalloc code which adds complexity and confusion.
(The correct version of this, assuming the per-CPU page table stuff was
acceptable, would be to separate out common code and have vmalloc and the
per-CPU page table stuff use the common code :)
>
> >
> > > Also make vmap_range_noflush() non static, it will be called outside
> > > vmalloc in the following patch.
> > Hmm not loving the exposure of an internal function ehre.
>
> The RFC reused and extended the vmalloc APIs. We don't have to do so if it
> is not preferred. I think I can create some percpu allocator specific APIs
> to manipulate percpu area mapping with percpu pgd.
>
> >
> > > There is no functional change.
> > >
> > > Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
> > You're fundamentally changing something here, conceptually. I'm not sure why you
> > specifically need vmalloc to do it but it doesn't strike me as worthwhile for
> > what you're doing.
>
> The percpu allocator uses vmalloc APIs to map percpu variables currently. So
> the patch extended it to take pgd pointer as an extra parameter. This helped
> to reduce duplicate code. I can add percpu specific APIs if extending the
> APIs doesn't make too much sense.
I mean again, the correct version of this would be to separate out common code
and refactor etc. etc.
But yes, I'd rather the vmalloc code is left as-is. Doing what you're proposing
in this patch adds complexity and confusion as to whether remote mm's can be
updated.
(Overall my impression is that the per-CPU page table approach isn't something
Linus wants and there's push back from the commnity, so maybe worth discussing
the approach in general first rather than respinning?)
>
> Thanks,
> Yang
>
> >
> > > ---
> > > mm/internal.h | 5 ++++-
> > > mm/kmsan/hooks.c | 14 +++++++-------
> > > mm/vmalloc.c | 25 +++++++++++++------------
> > > 3 files changed, 24 insertions(+), 20 deletions(-)
> > >
> > > diff --git a/mm/internal.h b/mm/internal.h
> > > index 181e79f1d6a2..9d9f08cb26a1 100644
> > > --- a/mm/internal.h
> > > +++ b/mm/internal.h
> > > @@ -1552,10 +1552,13 @@ void clear_vm_uninitialized_flag(struct vm_struct *vm);
> > > int __must_check __vmap_pages_range_noflush(unsigned long addr,
> > > unsigned long end, pgprot_t prot,
> > > struct page **pages, unsigned int page_shift);
> > > +int __must_check vmap_range_noflush(pgd_t *pgdir, unsigned long addr,
> > > + unsigned long end, phys_addr_t phys_addr,
> > > + pgprot_t prot, unsigned int max_page_shift);
> > >
> > > void vunmap_range_noflush(unsigned long start, unsigned long end);
> > >
> > > -void __vunmap_range_noflush(unsigned long start, unsigned long end);
> > > +void __vunmap_range_noflush(pgd_t *pgdir, unsigned long start, unsigned long end);
> > >
> > > static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)
> > > {
> > > diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c
> > > index 8f22d1f22981..e2a0faf344b9 100644
> > > --- a/mm/kmsan/hooks.c
> > > +++ b/mm/kmsan/hooks.c
> > > @@ -135,8 +135,8 @@ static unsigned long vmalloc_origin(unsigned long addr)
> > >
> > > void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end)
> > > {
> > > - __vunmap_range_noflush(vmalloc_shadow(start), vmalloc_shadow(end));
> > > - __vunmap_range_noflush(vmalloc_origin(start), vmalloc_origin(end));
> > > + __vunmap_range_noflush(init_mm.pgd, vmalloc_shadow(start), vmalloc_shadow(end));
> > > + __vunmap_range_noflush(init_mm.pgd, vmalloc_origin(start), vmalloc_origin(end));
> > > flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
> > > flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
> > > }
> > > @@ -181,7 +181,7 @@ int kmsan_ioremap_page_range(unsigned long start, unsigned long end,
> > > vmalloc_origin(start + off + PAGE_SIZE), prot, &origin,
> > > PAGE_SHIFT);
> > > if (mapped) {
> > > - __vunmap_range_noflush(
> > > + __vunmap_range_noflush(init_mm.pgd,
> > > vmalloc_shadow(start + off),
> > > vmalloc_shadow(start + off + PAGE_SIZE));
> > > err = mapped;
> > > @@ -203,10 +203,10 @@ int kmsan_ioremap_page_range(unsigned long start, unsigned long end,
> > > __free_pages(shadow, 1);
> > > if (origin)
> > > __free_pages(origin, 1);
> > > - __vunmap_range_noflush(
> > > + __vunmap_range_noflush(init_mm.pgd,
> > > vmalloc_shadow(start),
> > > vmalloc_shadow(start + clean * PAGE_SIZE));
> > > - __vunmap_range_noflush(
> > > + __vunmap_range_noflush(init_mm.pgd,
> > > vmalloc_origin(start),
> > > vmalloc_origin(start + clean * PAGE_SIZE));
> > > }
> > > @@ -233,8 +233,8 @@ void kmsan_iounmap_page_range(unsigned long start, unsigned long end)
> > > i++, v_shadow += PAGE_SIZE, v_origin += PAGE_SIZE) {
> > > shadow = kmsan_vmalloc_to_page_or_null((void *)v_shadow);
> > > origin = kmsan_vmalloc_to_page_or_null((void *)v_origin);
> > > - __vunmap_range_noflush(v_shadow, vmalloc_shadow(end));
> > > - __vunmap_range_noflush(v_origin, vmalloc_origin(end));
> > > + __vunmap_range_noflush(init_mm.pgd, v_shadow, vmalloc_shadow(end));
> > > + __vunmap_range_noflush(init_mm.pgd, v_origin, vmalloc_origin(end));
> > > if (shadow)
> > > __free_pages(shadow, 1);
> > > if (origin)
> > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > > index 1afca3568b9b..17c26e9796b2 100644
> > > --- a/mm/vmalloc.c
> > > +++ b/mm/vmalloc.c
> > > @@ -295,9 +295,9 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
> > > return err;
> > > }
> > >
> > > -static int vmap_range_noflush(unsigned long addr, unsigned long end,
> > > - phys_addr_t phys_addr, pgprot_t prot,
> > > - unsigned int max_page_shift)
> > > +int vmap_range_noflush(pgd_t *pgdir, unsigned long addr, unsigned long end,
> > > + phys_addr_t phys_addr, pgprot_t prot,
> > > + unsigned int max_page_shift)
> > > {
> > > pgd_t *pgd;
> > > unsigned long start;
> > > @@ -314,7 +314,7 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
> > > BUG_ON(addr >= end);
> > >
> > > start = addr;
> > > - pgd = pgd_offset_k(addr);
> > > + pgd = pgd_offset_pgd(pgdir, addr);
> > > do {
> > > next = pgd_addr_end(addr, end);
> > > err = vmap_p4d_range(pgd, addr, next, phys_addr, prot,
> > > @@ -334,8 +334,8 @@ int vmap_page_range(unsigned long addr, unsigned long end,
> > > {
> > > int err;
> > >
> > > - err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
> > > - ioremap_max_page_shift);
> > > + err = vmap_range_noflush(init_mm.pgd, addr, end, phys_addr,
> > > + pgprot_nx(prot), ioremap_max_page_shift);
> > > flush_cache_vmap(addr, end);
> > > if (!err)
> > > err = kmsan_ioremap_page_range(addr, end, phys_addr, prot,
> > > @@ -478,7 +478,7 @@ static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
> > > *
> > > * This is an internal function only. Do not use outside mm/.
> > > */
> > > -void __vunmap_range_noflush(unsigned long start, unsigned long end)
> > > +void __vunmap_range_noflush(pgd_t *pgdir, unsigned long start, unsigned long end)
> > > {
> > > unsigned long next;
> > > pgd_t *pgd;
> > > @@ -486,7 +486,7 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end)
> > > pgtbl_mod_mask mask = 0;
> > >
> > > BUG_ON(addr >= end);
> > > - pgd = pgd_offset_k(addr);
> > > + pgd = pgd_offset_pgd(pgdir, addr);
> > > do {
> > > next = pgd_addr_end(addr, end);
> > > if (pgd_bad(*pgd))
> > > @@ -503,7 +503,7 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end)
> > > void vunmap_range_noflush(unsigned long start, unsigned long end)
> > > {
> > > kmsan_vunmap_range_noflush(start, end);
> > > - __vunmap_range_noflush(start, end);
> > > + __vunmap_range_noflush(init_mm.pgd, start, end);
> > > }
> > >
> > > /**
> > > @@ -670,9 +670,10 @@ int __vmap_pages_range_noflush(unsigned long addr, unsigned long end,
> > > for (i = 0; i < nr; i += 1U << (page_shift - PAGE_SHIFT)) {
> > > int err;
> > >
> > > - err = vmap_range_noflush(addr, addr + (1UL << page_shift),
> > > - page_to_phys(pages[i]), prot,
> > > - page_shift);
> > > + err = vmap_range_noflush(init_mm.pgd, addr,
> > > + addr + (1UL << page_shift),
> > > + page_to_phys(pages[i]), prot,
> > > + page_shift);
> > > if (err)
> > > return err;
> > >
> > > --
> > > 2.47.0
> > >
> > >
> > >
> > Cheers, Lorenzo
>
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-08-04 13:47 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 18:04 [RFC v2 PATCH 0/16] Optimize this_cpu_*() ops for non-x86 (ARM64 for this series) Yang Shi
2026-07-15 18:04 ` [PATCH 01/16] drivers: arch_numa: move percpu set up code to arch Yang Shi
2026-07-15 18:04 ` [PATCH 02/16] arm64: kconfig: make percpu related configs not depend on NUMA Yang Shi
2026-07-15 18:04 ` [PATCH 03/16] mm: pgalloc: introduce {pud|pmd}_populate_sync() Yang Shi
2026-07-15 18:04 ` [PATCH 04/16] vmalloc: pass in pgd pointer for vmap{__vunmap}_range_noflush() Yang Shi
2026-07-29 9:32 ` Lorenzo Stoakes (ARM)
2026-08-03 19:12 ` Yang Shi
2026-08-04 13:47 ` Lorenzo Stoakes (ARM) [this message]
2026-07-15 18:04 ` [PATCH 05/16] arm64: mm: enable percpu kernel page table Yang Shi
2026-07-15 18:04 ` [PATCH 06/16] arm64: mm: defined {pud|pmd}_populate_sync() Yang Shi
2026-07-15 18:04 ` [PATCH 07/16] arm64: mm: sync percpu page table for memory hotplug/unplug Yang Shi
2026-07-15 18:04 ` [PATCH 08/16] arm64: kasan: sync up kasan shadow area page table Yang Shi
2026-07-15 18:04 ` [PATCH 09/16] arm64: mm: define percpu virtual space area Yang Shi
2026-07-15 18:04 ` [PATCH 10/16] mm: percpu: prepare to use dedicated percpu area Yang Shi
2026-07-15 18:04 ` [PATCH 11/16] arm64: mm: map local percpu first chunk Yang Shi
2026-07-15 18:04 ` [PATCH 12/16] mm: percpu: set up first chunk and reserve chunk Yang Shi
2026-07-15 18:04 ` [PATCH 13/16] arm64: mm: introduce __per_cpu_local_off Yang Shi
2026-07-15 18:04 ` [PATCH 14/16] mm: percpu: allocate and free local percpu vm area Yang Shi
2026-07-15 18:04 ` [PATCH 15/16] arm64: kconfig: select HAVE_LOCAL_PER_CPU_MAP Yang Shi
2026-07-15 18:04 ` [PATCH 16/16] arm64: percpu: use local percpu for this_cpu_*() APIs Yang Shi
2026-07-16 13:23 ` [RFC v2 PATCH 0/16] Optimize this_cpu_*() ops for non-x86 (ARM64 for this series) Ryan Roberts
2026-07-21 19:08 ` Mark Rutland
2026-07-21 23:20 ` Yang Shi
2026-07-22 9:36 ` Mark Rutland
2026-07-27 21:10 ` Yang Shi
2026-07-27 22:06 ` Christoph Lameter (Ampere)
2026-07-29 9:28 ` David Hildenbrand (Arm)
2026-08-04 14:15 ` Lorenzo Stoakes (ARM)
2026-08-04 14:21 ` Lorenzo Stoakes (ARM)
2026-08-04 14:40 ` Jason Gunthorpe
2026-08-04 18:06 ` Matthew Wilcox
2026-08-04 18:16 ` Jason Gunthorpe
2026-08-04 15:21 ` Linus Torvalds
2026-08-04 16:15 ` Christoph Lameter (Ampere)
2026-08-04 16:30 ` Linus Torvalds
2026-08-04 16:54 ` David Hildenbrand (Arm)
2026-08-04 17:01 ` Linus Torvalds
2026-08-04 17:32 ` Lorenzo Stoakes (ARM)
2026-08-04 21:40 ` Christoph Lameter (Ampere)
2026-08-04 21:48 ` David Hildenbrand (Arm)
2026-08-04 21:56 ` Christoph Lameter (Ampere)
2026-08-04 22:01 ` David Hildenbrand (Arm)
2026-08-05 8:16 ` Lorenzo Stoakes (ARM)
2026-08-04 17:23 ` Lorenzo Stoakes (ARM)
2026-08-04 17:28 ` Linus Torvalds
2026-08-04 21:51 ` Yang Shi
2026-08-04 22:05 ` David Hildenbrand (Arm)
2026-08-04 22:35 ` Christoph Lameter (Ampere)
2026-08-05 6:11 ` David Hildenbrand (Arm)
2026-08-05 14:48 ` Mark Rutland
2026-08-05 7:52 ` Lorenzo Stoakes (ARM)
2026-08-06 17:15 ` Will Deacon
2026-08-06 17:31 ` Lorenzo Stoakes (ARM)
2026-08-04 16:19 ` Christoph Lameter (Ampere)
2026-08-04 16:47 ` David Hildenbrand (Arm)
2026-08-04 21:25 ` Christoph Lameter (Ampere)
2026-08-04 21:47 ` David Hildenbrand (Arm)
2026-08-04 22:01 ` Christoph Lameter (Ampere)
2026-08-05 6:12 ` David Hildenbrand (Arm)
2026-08-05 8:45 ` Heiko Carstens
2026-08-05 11:10 ` David Laight
2026-08-05 14:53 ` Mark Rutland
2026-07-30 6:06 ` [RFC v2 PATCH 0/16] Optimize this_cpu_*() ops for non-x86 (ARM64 for this series)~ Mete Durlu
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=anHqZbo87H1hpC7V@lucifer \
--to=ljs@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=david@kernel.org \
--cc=dennis@kernel.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=tj@kernel.org \
--cc=urezki@gmail.com \
--cc=will@kernel.org \
--cc=yang@os.amperecomputing.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