2014-10-28 04:24:54

by Stephen Rothwell

[permalink] [raw]
Subject: linux-next: manual merge of the akpm-current tree with the dma-mapping tree

Hi Andrew,

Today's linux-next merge of the akpm-current tree got a conflict in
mm/cma.c between commit 16195ddd4ebc ("mm: cma: Ensure that
reservations never cross the low/high mem boundary") from the
dma-mapping tree and commit 2a70e5a78672 ("mm/cma: ake kmemleak ignore
CMA regions") from the akpm-current tree.

I fixed it up (I think - see below) and can carry the fix as necessary
(no action is required).

--
Cheers,
Stephen Rothwell [email protected]

diff --cc mm/cma.c
index fde706e1284f,471fcfef043b..000000000000
--- a/mm/cma.c
+++ b/mm/cma.c
@@@ -278,30 -274,20 +278,35 @@@ int __init cma_declare_contiguous(phys_
goto err;
}
} else {
- phys_addr_t addr = memblock_alloc_range(size, alignment, base,
- limit);
+ phys_addr_t addr = 0;
+
+ /*
+ * All pages in the reserved area must come from the same zone.
+ * If the requested region crosses the low/high memory boundary,
+ * try allocating from high memory first and fall back to low
+ * memory in case of failure.
+ */
+ if (base < highmem_start && limit > highmem_start) {
+ addr = memblock_alloc_range(size, alignment,
+ highmem_start, limit);
+ limit = highmem_start;
+ }
+
if (!addr) {
- ret = -ENOMEM;
- goto err;
- } else {
- /*
- * kmemleak scans/reads tracked objects for pointers to
- * other objects but this address isn't mapped and
- * accessible
- */
- kmemleak_ignore(phys_to_virt(addr));
- base = addr;
+ addr = memblock_alloc_range(size, alignment, base,
+ limit);
+ if (!addr) {
+ ret = -ENOMEM;
+ goto err;
+ }
}
-
++ /*
++ * kmemleak scans/reads tracked objects for pointers to
++ * other objects but this address isn't mapped and
++ * accessible
++ */
++ kmemleak_ignore(phys_to_virt(addr));
+ base = addr;
}

ret = cma_init_reserved_mem(base, size, order_per_bit, res_cma);


Attachments:
(No filename) (819.00 B)
OpenPGP digital signature

2014-10-28 06:28:56

by Andrew Morton

[permalink] [raw]
Subject: Re: linux-next: manual merge of the akpm-current tree with the dma-mapping tree

On Tue, 28 Oct 2014 15:24:44 +1100 Stephen Rothwell <[email protected]> wrote:

> Today's linux-next merge of the akpm-current tree got a conflict in
> mm/cma.c between commit 16195ddd4ebc ("mm: cma: Ensure that
> reservations never cross the low/high mem boundary") from the
> dma-mapping tree and commit 2a70e5a78672 ("mm/cma: ake kmemleak ignore
> CMA regions") from the akpm-current tree.

hm, we have multiple trees altering mm/cma.c?

I'm a bit surprised that this series was merged, given that Laurent
said he would be sending out a v2...

2014-10-28 06:54:18

by Marek Szyprowski

[permalink] [raw]
Subject: Re: linux-next: manual merge of the akpm-current tree with the dma-mapping tree

Hello,

On 2014-10-28 07:29, Andrew Morton wrote:
> On Tue, 28 Oct 2014 15:24:44 +1100 Stephen Rothwell <[email protected]> wrote:
>
>> Today's linux-next merge of the akpm-current tree got a conflict in
>> mm/cma.c between commit 16195ddd4ebc ("mm: cma: Ensure that
>> reservations never cross the low/high mem boundary") from the
>> dma-mapping tree and commit 2a70e5a78672 ("mm/cma: ake kmemleak ignore
>> CMA regions") from the akpm-current tree.
> hm, we have multiple trees altering mm/cma.c?
>
> I'm a bit surprised that this series was merged, given that Laurent
> said he would be sending out a v2...

v2 of Laurent's patches has been posted on 24th October
(https://lkml.org/lkml/2014/10/24/207 ), but since I didn't notice them
to be taken
I thought that it would make sense to get them via my tree and send them
to Linus
during the 3.18-rc cycle. If this was not appropriate, I will drop my tree.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2014-10-28 20:26:19

by Andrew Morton

[permalink] [raw]
Subject: Re: linux-next: manual merge of the akpm-current tree with the dma-mapping tree

On Tue, 28 Oct 2014 07:54:09 +0100 Marek Szyprowski <[email protected]> wrote:

> Hello,
>
> On 2014-10-28 07:29, Andrew Morton wrote:
> > On Tue, 28 Oct 2014 15:24:44 +1100 Stephen Rothwell <[email protected]> wrote:
> >
> >> Today's linux-next merge of the akpm-current tree got a conflict in
> >> mm/cma.c between commit 16195ddd4ebc ("mm: cma: Ensure that
> >> reservations never cross the low/high mem boundary") from the
> >> dma-mapping tree and commit 2a70e5a78672 ("mm/cma: ake kmemleak ignore
> >> CMA regions") from the akpm-current tree.
> > hm, we have multiple trees altering mm/cma.c?
> >
> > I'm a bit surprised that this series was merged, given that Laurent
> > said he would be sending out a v2...
>
> v2 of Laurent's patches has been posted on 24th October
> (https://lkml.org/lkml/2014/10/24/207 ), but since I didn't notice them
> to be taken
> I thought that it would make sense to get them via my tree and send them
> to Linus
> during the 3.18-rc cycle. If this was not appropriate, I will drop my tree.

I think I got it all sorted out. Thierry's "mm/cma: make kmemleak
ignore CMA regions" needed a bit of rework - please check.


From: Thierry Reding <[email protected]>
Subject: mm/cma: make kmemleak ignore CMA regions

kmemleak will add allocations as objects to a pool. The memory allocated
for each object in this pool is periodically searched for pointers to
other allocated objects. This only works for memory that is mapped into
the kernel's virtual address space, which happens not to be the case for
most CMA regions.

Furthermore, CMA regions are typically used to store data transferred to
or from a device and therefore don't contain pointers to other objects.

Without this, the kernel crashes on the first execution of the
scan_gray_list() because it tries to access highmem. Perhaps a more
appropriate fix would be to reject any object that can't map to a kernel
virtual address?

[[email protected]: add comment]
[[email protected]: fix comment, per Catalin]
[[email protected]: include linux/io.h for phys_to_virt()]
Signed-off-by: Thierry Reding <[email protected]>
Cc: Michal Nazarewicz <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Catalin Marinas <[email protected]>
Signed-off-by: Stephen Rothwell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

mm/cma.c | 6 ++++++
1 file changed, 6 insertions(+)

diff -puN mm/cma.c~mm-cma-make-kmemleak-ignore-cma-regions mm/cma.c
--- a/mm/cma.c~mm-cma-make-kmemleak-ignore-cma-regions
+++ a/mm/cma.c
@@ -33,6 +33,7 @@
#include <linux/log2.h>
#include <linux/cma.h>
#include <linux/highmem.h>
+#include <linux/io.h>

struct cma {
unsigned long base_pfn;
@@ -301,6 +302,11 @@ int __init cma_declare_contiguous(phys_a
}
}

+ /*
+ * kmemleak scans/reads tracked objects for pointers to other
+ * objects but this address isn't mapped and accessible
+ */
+ kmemleak_ignore(phys_to_virt(addr));
base = addr;
}

_