* [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 11:22 ` miles.chen-NuS5LvNUpcJWk0Htik3J/w
0 siblings, 0 replies; 6+ messages in thread
From: miles.chen @ 2018-02-22 11:22 UTC (permalink / raw)
To: Christoph Hellwig, Marek Szyprowski, Robin Murphy
Cc: linux-kernel, iommu, linux-mediatek, wsd_upstream, Miles Chen
From: Miles Chen <miles.chen@mediatek.com>
Marty reported a memory leakage introduced by commit 3aaabbf1c39e
("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it
by checking the virtual address before allocating the entry.
This patch also use virt_addr_valid() instead of virt_to_page()
to check if a virtual address is linear.
Reported-by: Marty Faltesek <mfaltesek@google.com>
Signed-off-by: Miles Chen <miles.chen@mediatek.com>
---
lib/dma-debug.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 1b34d210452c..7f5cdc1e6b29 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
if (unlikely(virt == NULL))
return;
- entry = dma_entry_alloc();
- if (!entry)
+ /* handle vmalloc and linear addresses */
+ if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
return;
- /* handle vmalloc and linear addresses */
- if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
+ entry = dma_entry_alloc();
+ if (!entry)
return;
entry->type = dma_debug_coherent;
@@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
};
/* handle vmalloc and linear addresses */
- if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
+ if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
return;
if (is_vmalloc_addr(virt))
--
2.12.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 11:22 ` miles.chen-NuS5LvNUpcJWk0Htik3J/w
0 siblings, 0 replies; 6+ messages in thread
From: miles.chen-NuS5LvNUpcJWk0Htik3J/w @ 2018-02-22 11:22 UTC (permalink / raw)
To: Christoph Hellwig, Marek Szyprowski, Robin Murphy
Cc: Miles Chen, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
wsd_upstream-NuS5LvNUpcJWk0Htik3J/w
From: Miles Chen <miles.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Marty reported a memory leakage introduced by commit 3aaabbf1c39e
("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it
by checking the virtual address before allocating the entry.
This patch also use virt_addr_valid() instead of virt_to_page()
to check if a virtual address is linear.
Reported-by: Marty Faltesek <mfaltesek-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Miles Chen <miles.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
lib/dma-debug.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 1b34d210452c..7f5cdc1e6b29 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
if (unlikely(virt == NULL))
return;
- entry = dma_entry_alloc();
- if (!entry)
+ /* handle vmalloc and linear addresses */
+ if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
return;
- /* handle vmalloc and linear addresses */
- if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
+ entry = dma_entry_alloc();
+ if (!entry)
return;
entry->type = dma_debug_coherent;
@@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
};
/* handle vmalloc and linear addresses */
- if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
+ if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
return;
if (is_vmalloc_addr(virt))
--
2.12.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 14:04 ` Robin Murphy
0 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2018-02-22 14:04 UTC (permalink / raw)
To: miles.chen, Christoph Hellwig, Marek Szyprowski
Cc: linux-kernel, iommu, linux-mediatek, wsd_upstream
On 22/02/18 11:22, miles.chen@mediatek.com wrote:
> From: Miles Chen <miles.chen@mediatek.com>
>
> Marty reported a memory leakage introduced by commit 3aaabbf1c39e
> ("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it
> by checking the virtual address before allocating the entry.
Oops, seems I failed to look closely enough at the surrounding diff
context when I reviewed the original patch... :(
> This patch also use virt_addr_valid() instead of virt_to_page()
> to check if a virtual address is linear.
That's an area I happen to have been looking at lately and now
understand a lot better, so fully agreed there as well.
Acked-by: Robin Murphy <robin.murphy@arm.com>
Maybe also worth having a proper Fixes: tag instead of just naming the
commit in prose?
Thanks,
Robin.
> Reported-by: Marty Faltesek <mfaltesek@google.com>
> Signed-off-by: Miles Chen <miles.chen@mediatek.com>
> ---
> lib/dma-debug.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> index 1b34d210452c..7f5cdc1e6b29 100644
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
> if (unlikely(virt == NULL))
> return;
>
> - entry = dma_entry_alloc();
> - if (!entry)
> + /* handle vmalloc and linear addresses */
> + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
> return;
>
> - /* handle vmalloc and linear addresses */
> - if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
> + entry = dma_entry_alloc();
> + if (!entry)
> return;
>
> entry->type = dma_debug_coherent;
> @@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
> };
>
> /* handle vmalloc and linear addresses */
> - if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
> + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
> return;
>
> if (is_vmalloc_addr(virt))
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 14:04 ` Robin Murphy
0 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2018-02-22 14:04 UTC (permalink / raw)
To: miles.chen-NuS5LvNUpcJWk0Htik3J/w, Christoph Hellwig, Marek Szyprowski
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
wsd_upstream-NuS5LvNUpcJWk0Htik3J/w
On 22/02/18 11:22, miles.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org wrote:
> From: Miles Chen <miles.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
>
> Marty reported a memory leakage introduced by commit 3aaabbf1c39e
> ("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it
> by checking the virtual address before allocating the entry.
Oops, seems I failed to look closely enough at the surrounding diff
context when I reviewed the original patch... :(
> This patch also use virt_addr_valid() instead of virt_to_page()
> to check if a virtual address is linear.
That's an area I happen to have been looking at lately and now
understand a lot better, so fully agreed there as well.
Acked-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
Maybe also worth having a proper Fixes: tag instead of just naming the
commit in prose?
Thanks,
Robin.
> Reported-by: Marty Faltesek <mfaltesek-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Miles Chen <miles.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> ---
> lib/dma-debug.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> index 1b34d210452c..7f5cdc1e6b29 100644
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
> if (unlikely(virt == NULL))
> return;
>
> - entry = dma_entry_alloc();
> - if (!entry)
> + /* handle vmalloc and linear addresses */
> + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
> return;
>
> - /* handle vmalloc and linear addresses */
> - if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
> + entry = dma_entry_alloc();
> + if (!entry)
> return;
>
> entry->type = dma_debug_coherent;
> @@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
> };
>
> /* handle vmalloc and linear addresses */
> - if (!is_vmalloc_addr(virt) && !virt_to_page(virt))
> + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
> return;
>
> if (is_vmalloc_addr(virt))
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 23:03 ` Christoph Hellwig
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2018-02-22 23:03 UTC (permalink / raw)
To: miles.chen, Robin Murphy
Cc: Christoph Hellwig, Marek Szyprowski, linux-kernel, iommu,
linux-mediatek, wsd_upstream
Thanks, applied to the dma mapping tree for 4.16, including the Fixes
tag.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/dma-debug.c: fix memory leakage
@ 2018-02-22 23:03 ` Christoph Hellwig
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2018-02-22 23:03 UTC (permalink / raw)
To: miles.chen-NuS5LvNUpcJWk0Htik3J/w, Robin Murphy
Cc: wsd_upstream-NuS5LvNUpcJWk0Htik3J/w,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
Christoph Hellwig
Thanks, applied to the dma mapping tree for 4.16, including the Fixes
tag.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-02-22 23:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 11:22 [PATCH] lib/dma-debug.c: fix memory leakage miles.chen
2018-02-22 11:22 ` miles.chen-NuS5LvNUpcJWk0Htik3J/w
2018-02-22 14:04 ` Robin Murphy
2018-02-22 14:04 ` Robin Murphy
2018-02-22 23:03 ` Christoph Hellwig
2018-02-22 23:03 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.