Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hao Ge" <hao.ge@linux.dev>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Alexander Potapenko" <glider@google.com>,
	"Marco Elver" <elver@google.com>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Dennis Zhou" <dennis@kernel.org>, "Tejun Heo" <tj@kernel.org>,
	"Christoph Lameter" <cl@gentwo.org>
Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org
Subject: Re: [PATCH v2 4/5] powerpc: drop redundant unmaps of failed vmap mappings
Date: Tue, 20 Oct 2026 05:45:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-178440@kernel.org> (raw)
In-Reply-To: <20261019054531.87652-5-hao.ge@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] powerpc/pci: leak of vm_struct in ioremap_phb() when ioremap_page_range() fails
--

commit 293efb97e53f2ab49d30288da6e26fcbf75e032f
Author: Hao Ge <hao.ge@linux.dev>

powerpc: drop redundant unmaps of failed vmap mappings

This commit removes vunmap_range() calls from the error paths of
remap_isa_base() and ioremap_phb(), since vmap_page_range() and
ioremap_page_range() already clean up their installed PTEs upon failure.

> diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
> index e27342ef128b8..f74269636d5ec 100644
> --- a/arch/powerpc/kernel/pci_64.c
> +++ b/arch/powerpc/kernel/pci_64.c
> @@ -139,10 +139,8 @@ void __iomem *ioremap_phb(phys_addr_t paddr, unsigned long size)
>  
>  	addr = (unsigned long)area->addr;
>  	if (ioremap_page_range(addr, addr + size, paddr,
> -			pgprot_noncached(PAGE_KERNEL))) {
> -		vunmap_range(addr, addr + size);
> +			pgprot_noncached(PAGE_KERNEL)))
>  		return NULL;
> -	}
>  
>  	return (void __iomem *)addr;
>  }

[Severity: Medium]
Does ioremap_phb() still leak area and its reserved virtual address range in
[PHB_IO_BASE, PHB_IO_END) when ioremap_page_range() fails?

Prior to calling ioremap_page_range(), ioremap_phb() allocates a virtual
memory area:

arch/powerpc/kernel/pci_64.c:ioremap_phb() {
    ...
	area = __get_vm_area_caller(size, VM_IOREMAP, PHB_IO_BASE, PHB_IO_END,
				    __builtin_return_address(0));
	if (!area)
		return NULL;
    ...
}

When ioremap_page_range() fails (for example, -ENOMEM when allocating page
tables in vmap_range_noflush()), vmap_page_range() rolls back the PTEs via
__vunmap_range_noflush(), but it does not free or unlink the struct vm_struct
and struct vmap_area allocated by __get_vm_area_caller().

Should this error path call free_vm_area(area) before returning NULL, matching
generic_ioremap_prot() in mm/ioremap.c?

mm/ioremap.c:generic_ioremap_prot() {
    ...
	if (ioremap_page_range(vaddr, vaddr + size, phys_addr, prot)) {
		free_vm_area(area);
		return NULL;
	}
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261019054531.87652-1-hao.ge@linux.dev?part=4


  reply	other threads:[~2026-10-20  5:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  5:45 [PATCH v2 0/5] mm/vmalloc: make the mapping functions undo their partial mappings Hao Ge
2026-10-19  5:45 ` [PATCH v2 1/5] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
2026-10-19 14:54   ` Dev Jain
2026-10-19  5:45 ` [PATCH v2 2/5] mm/kmsan: skip vunmap_range_noflush when KMSAN is disabled Hao Ge
2026-10-19 15:22   ` Dev Jain
2026-10-20  2:26     ` Hao Ge
2026-10-20  5:21   ` Dev Jain
2026-10-19  5:45 ` [PATCH v2 3/5] mm/vmalloc: undo partial mappings inside the mapping functions Hao Ge
2026-10-20  5:45   ` sashiko-bot
2026-10-20 10:03     ` Hao Ge
2026-10-20 13:27       ` Hao Ge
2026-10-20 15:08         ` Uladzislau Rezki
2026-10-20  5:46   ` Dev Jain
2026-10-20 13:12     ` Hao Ge
2026-10-19  5:45 ` [PATCH v2 4/5] powerpc: drop redundant unmaps of failed vmap mappings Hao Ge
2026-10-20  5:45   ` sashiko-bot [this message]
2026-10-19  5:45 ` [PATCH v2 5/5] mm/percpu: stop unmapping the CPU that failed to map Hao Ge

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=sashiko-outbox-178440@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chleroy@kernel.org \
    --cc=cl@gentwo.org \
    --cc=dennis@kernel.org \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=hao.ge@linux.dev \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-mm@kvack.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sshegde@linux.ibm.com \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=urezki@gmail.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