All of lore.kernel.org
 help / color / mirror / Atom feed
From: mina86@mina86.com (Michal Nazarewicz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] mm: cma: adjust address limit to avoid hitting low/high memory boundary
Date: Sun, 24 Aug 2014 15:34:21 +0200	[thread overview]
Message-ID: <xa1ty4ueui3m.fsf@mina86.com> (raw)
In-Reply-To: <1408610714-16204-2-git-send-email-m.szyprowski@samsung.com>

On Thu, Aug 21 2014, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> Automatically allocated regions should not cross low/high memory boundary,
> because such regions cannot be later correctly initialized due to spanning
> across two memory zones. This patch adds a check for this case and a simple
> code for moving region to low memory if automatically selected address might
> not fit completely into high memory.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  mm/cma.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index c17751c0dcaf..4acc6aa4a086 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -32,6 +32,7 @@
>  #include <linux/slab.h>
>  #include <linux/log2.h>
>  #include <linux/cma.h>
> +#include <linux/highmem.h>
>  
>  struct cma {
>  	unsigned long	base_pfn;
> @@ -163,6 +164,8 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  			bool fixed, struct cma **res_cma)
>  {
>  	struct cma *cma;
> +	phys_addr_t memblock_end = memblock_end_of_DRAM();
> +	phys_addr_t highmem_start = __pa(high_memory);
>  	int ret = 0;
>  
>  	pr_debug("%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n",
> @@ -196,6 +199,24 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (!IS_ALIGNED(size >> PAGE_SHIFT, 1 << order_per_bit))
>  		return -EINVAL;
>  
> +	/*
> +	 * adjust limit to avoid crossing low/high memory boundary for
> +	 * automatically allocated regions
> +	 */
> +	if (((limit == 0 || limit > memblock_end) &&
> +	     (memblock_end - size < highmem_start &&
> +	      memblock_end > highmem_start)) ||
> +	    (!fixed && limit > highmem_start && limit - size < highmem_start)) {
> +		limit = highmem_start;
> +	}
> +
> +	if (fixed && base < highmem_start && base+size > highmem_start) {
> +		ret = -EINVAL;
> +		pr_err("Region at %08lx defined on low/high memory boundary (%08lx)\n",
> +			(unsigned long)base, (unsigned long)highmem_start);
> +		goto err;
> +	}
> +
>  	/* Reserve memory */
>  	if (base && fixed) {
>  		if (memblock_is_region_reserved(base, size) ||
> -- 
> 1.9.2
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Micha? ?mina86? Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

WARNING: multiple messages have this Message-ID (diff)
From: Michal Nazarewicz <mina86@mina86.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
	linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org,
	linaro-mm-sig@lists.linaro.org
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/2] mm: cma: adjust address limit to avoid hitting low/high memory boundary
Date: Sun, 24 Aug 2014 15:34:21 +0200	[thread overview]
Message-ID: <xa1ty4ueui3m.fsf@mina86.com> (raw)
In-Reply-To: <1408610714-16204-2-git-send-email-m.szyprowski@samsung.com>

On Thu, Aug 21 2014, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> Automatically allocated regions should not cross low/high memory boundary,
> because such regions cannot be later correctly initialized due to spanning
> across two memory zones. This patch adds a check for this case and a simple
> code for moving region to low memory if automatically selected address might
> not fit completely into high memory.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  mm/cma.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index c17751c0dcaf..4acc6aa4a086 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -32,6 +32,7 @@
>  #include <linux/slab.h>
>  #include <linux/log2.h>
>  #include <linux/cma.h>
> +#include <linux/highmem.h>
>  
>  struct cma {
>  	unsigned long	base_pfn;
> @@ -163,6 +164,8 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  			bool fixed, struct cma **res_cma)
>  {
>  	struct cma *cma;
> +	phys_addr_t memblock_end = memblock_end_of_DRAM();
> +	phys_addr_t highmem_start = __pa(high_memory);
>  	int ret = 0;
>  
>  	pr_debug("%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n",
> @@ -196,6 +199,24 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (!IS_ALIGNED(size >> PAGE_SHIFT, 1 << order_per_bit))
>  		return -EINVAL;
>  
> +	/*
> +	 * adjust limit to avoid crossing low/high memory boundary for
> +	 * automatically allocated regions
> +	 */
> +	if (((limit == 0 || limit > memblock_end) &&
> +	     (memblock_end - size < highmem_start &&
> +	      memblock_end > highmem_start)) ||
> +	    (!fixed && limit > highmem_start && limit - size < highmem_start)) {
> +		limit = highmem_start;
> +	}
> +
> +	if (fixed && base < highmem_start && base+size > highmem_start) {
> +		ret = -EINVAL;
> +		pr_err("Region at %08lx defined on low/high memory boundary (%08lx)\n",
> +			(unsigned long)base, (unsigned long)highmem_start);
> +		goto err;
> +	}
> +
>  	/* Reserve memory */
>  	if (base && fixed) {
>  		if (memblock_is_region_reserved(base, size) ||
> -- 
> 1.9.2
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2014-08-24 13:34 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21  8:45 [PATCH 0/2] ARM: Remove lowmem limit for default CMA region Marek Szyprowski
2014-08-21  8:45 ` Marek Szyprowski
2014-08-21  8:45 ` [PATCH 1/2] mm: cma: adjust address limit to avoid hitting low/high memory boundary Marek Szyprowski
2014-08-21  8:45   ` Marek Szyprowski
2014-08-24 13:34   ` Michal Nazarewicz [this message]
2014-08-24 13:34     ` Michal Nazarewicz
2014-08-21  8:45 ` [PATCH 2/2] ARM: mm: don't limit default CMA region only to low memory Marek Szyprowski
2014-08-21  8:45   ` Marek Szyprowski
2014-08-21  9:26   ` Daniel Drake
2014-08-21  9:26     ` Daniel Drake
2014-08-24 13:34   ` Michal Nazarewicz
2014-08-24 13:34     ` Michal Nazarewicz
2014-08-25  1:26 ` [PATCH 0/2] ARM: Remove lowmem limit for default CMA region Minchan Kim
2014-08-25  1:26   ` Minchan Kim
2014-08-25  8:00   ` Marek Szyprowski
2014-08-25  8:00     ` Marek Szyprowski
2014-08-25  8:18     ` Minchan Kim
2014-08-25  8:18       ` Minchan Kim
2014-08-25  8:33       ` Marek Szyprowski
2014-08-25  8:33         ` Marek Szyprowski
2014-08-26  2:43         ` Minchan Kim
2014-08-26  2:43           ` Minchan Kim
2014-08-26 12:34           ` Marek Szyprowski
2014-08-26 12:34             ` Marek Szyprowski
2014-08-27  0:36             ` Minchan Kim
2014-08-27  0:36               ` Minchan Kim
2014-08-27  1:42               ` Joonsoo Kim
2014-08-27  1:42                 ` Joonsoo Kim
2014-08-27  2:57                 ` Minchan Kim
2014-08-27  2:57                   ` Minchan Kim
2014-08-26 23:10 ` Andrew Morton
2014-08-26 23:10   ` Andrew Morton

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=xa1ty4ueui3m.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 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.