linux-parisc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap()
@ 2019-09-09 13:38 Helge Deller
  2019-09-30  6:20 ` Jeroen Roovers
  0 siblings, 1 reply; 6+ messages in thread
From: Helge Deller @ 2019-09-09 13:38 UTC (permalink / raw)
  To: linux-parisc, James Bottomley, John David Anglin; +Cc: Sven Schnelle

Sven noticed that calling ioremap() and iounmap() multiple times leads
to a vmap memory leak:
	vmap allocation for size 4198400 failed:
	use vmalloc=<size> to increase size

It seems we missed calling remove_vm_area() for ioummap().

Signed-off-by: Helge Deller <deller@gmx.de>
Noticed-by: Sven Schnelle <svens@stackframe.org>
Cc: <stable@vger.kernel.org>

diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 92a9b5f12f98..bcfa98aa134c 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -3,13 +3,14 @@
  * arch/parisc/mm/ioremap.c
  *
  * (C) Copyright 1995 1996 Linus Torvalds
- * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de>
+ * (C) Copyright 2001-2019 Helge Deller <deller@gmx.de>
  * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
  */

 #include <linux/vmalloc.h>
 #include <linux/errno.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/io.h>
 #include <asm/pgalloc.h>

@@ -84,7 +85,8 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
 	addr = (void __iomem *) area->addr;
 	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
 			       phys_addr, pgprot)) {
-		vfree(addr);
+		remove_vm_area((void __force *)addr);
+		kfree(area);
 		return NULL;
 	}

@@ -94,7 +96,24 @@ EXPORT_SYMBOL(__ioremap);

 void iounmap(const volatile void __iomem *addr)
 {
-	if (addr > high_memory)
-		return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));
+	struct vm_struct *p, *o;
+
+	if (addr <= high_memory)
+		return;
+
+	addr = (volatile void __iomem *)
+		(PAGE_MASK & (unsigned long __force)addr);
+
+	p = find_vm_area((void __force *)addr);
+	if (!p) {
+		printk(KERN_ERR "iounmap: bad address %p\n", addr);
+		dump_stack();
+		return;
+	}
+
+	/* Finally remove it */
+	o = remove_vm_area((void __force *)addr);
+	BUG_ON(p != o || o == NULL);
+	kfree(p);
 }
 EXPORT_SYMBOL(iounmap);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap()
  2019-09-09 13:38 [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap() Helge Deller
@ 2019-09-30  6:20 ` Jeroen Roovers
  2019-09-30  6:35   ` Carlo Pisani
  2019-10-02 15:38   ` Helge Deller
  0 siblings, 2 replies; 6+ messages in thread
From: Jeroen Roovers @ 2019-09-30  6:20 UTC (permalink / raw)
  To: Helge Deller
  Cc: linux-parisc, James Bottomley, John David Anglin, Sven Schnelle

On Mon, 9 Sep 2019 15:38:56 +0200
Helge Deller <deller@gmx.de> wrote:

> Sven noticed that calling ioremap() and iounmap() multiple times leads
> to a vmap memory leak:
> 	vmap allocation for size 4198400 failed:
> 	use vmalloc=<size> to increase size
> 
> It seems we missed calling remove_vm_area() for ioummap().

That patch seems to work (tested on a C8000 for a couple of weeks). I
was surprised it wasn't part of the "parisc architecture updates for
kernel v5.4" pull request.


Kind regards,
     jer

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap()
  2019-09-30  6:20 ` Jeroen Roovers
@ 2019-09-30  6:35   ` Carlo Pisani
  2019-10-02 15:38   ` Helge Deller
  1 sibling, 0 replies; 6+ messages in thread
From: Carlo Pisani @ 2019-09-30  6:35 UTC (permalink / raw)
  To: Jeroen Roovers
  Cc: Helge Deller, linux-parisc, James Bottomley, John David Anglin,
	Sven Schnelle

has it already been tested on C36xx and C37xx?

Il giorno lun 30 set 2019 alle ore 08:22 Jeroen Roovers
<jer@gentoo.org> ha scritto:
>
> On Mon, 9 Sep 2019 15:38:56 +0200
> Helge Deller <deller@gmx.de> wrote:
>
> > Sven noticed that calling ioremap() and iounmap() multiple times leads
> > to a vmap memory leak:
> >       vmap allocation for size 4198400 failed:
> >       use vmalloc=<size> to increase size
> >
> > It seems we missed calling remove_vm_area() for ioummap().
>
> That patch seems to work (tested on a C8000 for a couple of weeks). I
> was surprised it wasn't part of the "parisc architecture updates for
> kernel v5.4" pull request.
>
>
> Kind regards,
>      jer

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap()
  2019-09-30  6:20 ` Jeroen Roovers
  2019-09-30  6:35   ` Carlo Pisani
@ 2019-10-02 15:38   ` Helge Deller
  2019-10-04 17:23     ` [PATCH v2] " Helge Deller
  2019-10-11 19:17     ` pATA Promise Technologies PDC20265 (datasheet) Carlo Pisani
  1 sibling, 2 replies; 6+ messages in thread
From: Helge Deller @ 2019-10-02 15:38 UTC (permalink / raw)
  To: Jeroen Roovers
  Cc: linux-parisc, James Bottomley, John David Anglin, Sven Schnelle

On 30.09.19 08:20, Jeroen Roovers wrote:
> On Mon, 9 Sep 2019 15:38:56 +0200
> Helge Deller <deller@gmx.de> wrote:
>
>> Sven noticed that calling ioremap() and iounmap() multiple times leads
>> to a vmap memory leak:
>> 	vmap allocation for size 4198400 failed:
>> 	use vmalloc=<size> to increase size
>>
>> It seems we missed calling remove_vm_area() for ioummap().
>
> That patch seems to work (tested on a C8000 for a couple of weeks).
Did you actually stress-tested it?
modprobe/rmmod is not used that often if you have the patch simply
compiled in...

> I was surprised it wasn't part of the "parisc architecture updates for
> kernel v5.4" pull request.

My hope was that some mm-knowledgeable person would doublecheck.
It seems we could e.g. use vunmap() instead of remove_vm_area() & kfree()...

The patch is not forgotten, it just needs some more thoughts/discussions.

Helge

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] parisc: Fix vmap memory leak in ioremap()/iounmap()
  2019-10-02 15:38   ` Helge Deller
@ 2019-10-04 17:23     ` Helge Deller
  2019-10-11 19:17     ` pATA Promise Technologies PDC20265 (datasheet) Carlo Pisani
  1 sibling, 0 replies; 6+ messages in thread
From: Helge Deller @ 2019-10-04 17:23 UTC (permalink / raw)
  To: Helge Deller, linux-parisc, James Bottomley, John David Anglin
  Cc: Jeroen Roovers, Sven Schnelle

Sven noticed that calling ioremap() and iounmap() multiple times leads
to a vmap memory leak:
	vmap allocation for size 4198400 failed:
	use vmalloc=<size> to increase size

It seems we missed calling vunmap() in ioummap().

Signed-off-by: Helge Deller <deller@gmx.de>
Noticed-by: Sven Schnelle <svens@stackframe.org>
Cc: <stable@vger.kernel.org>

diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 92a9b5f12f98..f29f682352f0 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -3,7 +3,7 @@
  * arch/parisc/mm/ioremap.c
  *
  * (C) Copyright 1995 1996 Linus Torvalds
- * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de>
+ * (C) Copyright 2001-2019 Helge Deller <deller@gmx.de>
  * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
  */

@@ -84,7 +84,7 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
 	addr = (void __iomem *) area->addr;
 	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
 			       phys_addr, pgprot)) {
-		vfree(addr);
+		vunmap(addr);
 		return NULL;
 	}

@@ -92,9 +92,11 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
 }
 EXPORT_SYMBOL(__ioremap);

-void iounmap(const volatile void __iomem *addr)
+void iounmap(const volatile void __iomem *io_addr)
 {
-	if (addr > high_memory)
-		return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));
+	unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
+
+	if (is_vmalloc_addr((void *)addr))
+		vunmap((void *)addr);
 }
 EXPORT_SYMBOL(iounmap);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* pATA Promise Technologies PDC20265 (datasheet)
  2019-10-02 15:38   ` Helge Deller
  2019-10-04 17:23     ` [PATCH v2] " Helge Deller
@ 2019-10-11 19:17     ` Carlo Pisani
  1 sibling, 0 replies; 6+ messages in thread
From: Carlo Pisani @ 2019-10-11 19:17 UTC (permalink / raw)
  To: linux-parisc

hi
perhaps a bit OT, but I really don't know where to ask.
I googled a lot these days, but couldn't find a datasheet about the
Promise Technologies PDC20265 chip.

does anyone happen to have a copy of it?

thanks
=)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-11 19:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 13:38 [PATCH] parisc: Fix vmap memory leak in ioremap()/iounmap() Helge Deller
2019-09-30  6:20 ` Jeroen Roovers
2019-09-30  6:35   ` Carlo Pisani
2019-10-02 15:38   ` Helge Deller
2019-10-04 17:23     ` [PATCH v2] " Helge Deller
2019-10-11 19:17     ` pATA Promise Technologies PDC20265 (datasheet) Carlo Pisani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).