From patchwork Thu Aug 21 08:45:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 35725 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C417320540 for ; Thu, 21 Aug 2014 08:45:45 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hq11sf27004104vcb.3 for ; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=tFnHulMEMjlU+REA2RvCemBZQYij13sEpFJPvm93Ifo=; b=OSUS1VLvRqW90NnkLAl/m5C0rMVXimEiRgQk/47Lw9WwWehFkDUPH8UjviUK+CRpwb 7bj+chgqrTzfzvUbKja2IpbUSGc1pIi6eczwxbs19usqLYLQJ2QoJky4D+Y4kJe2GVBa LOTkExBM7DqHJrZlDNnUO4YdEgt6D8jnb2LGy4ypGD/rMHkLzsKtzfkSNLzqnPj92o96 QnwSeLXFYqLJV/7DDFiuH6nLorFJB80kIwg3JY3FvfM0uGf0ouj/b3IuPY0ZvAnkaUF6 jnbXQCVvtCzzeMsYWq/o7tlWYLpW/YMca1XMC71+EMuboP/nKwd7+uF7xRb/8d3yNqME UijQ== X-Gm-Message-State: ALoCoQkgVH9WUqfuM6vnWmWDSG6Mm2kV6Qh+Nhg6iQED8LUdyuiureCEIVWlsQ5l57tE/pIdYYkY X-Received: by 10.236.112.234 with SMTP id y70mr25336411yhg.32.1408610745535; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.38 with SMTP id i35ls624227qgf.76.gmail; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) X-Received: by 10.220.251.200 with SMTP id mt8mr1347120vcb.24.1408610745437; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id qc6si12130746vcb.85.2014.08.21.01.45.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Aug 2014 01:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so10403780vcb.31 for ; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) X-Received: by 10.220.114.66 with SMTP id d2mr40996906vcq.27.1408610745303; Thu, 21 Aug 2014 01:45:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp117914vcb; Thu, 21 Aug 2014 01:45:44 -0700 (PDT) X-Received: by 10.229.67.69 with SMTP id q5mr85951804qci.25.1408610744777; Thu, 21 Aug 2014 01:45:44 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id j49si37847302qga.126.2014.08.21.01.45.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 21 Aug 2014 01:45:44 -0700 (PDT) Received-SPF: none (google.com: linaro-mm-sig-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKO07-00063N-1p; Thu, 21 Aug 2014 08:45:43 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKO00-000639-D8 for linaro-mm-sig@lists.linaro.org; Thu, 21 Aug 2014 08:45:36 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NAN009BHF4J7X70@mailout4.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 21 Aug 2014 09:48:19 +0100 (BST) X-AuditID: cbfec7f5-b7f776d000003e54-ea-53f5b1a9bab8 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id E3.66.15956.9A1B5F35; Thu, 21 Aug 2014 09:45:29 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NAN0078ZEZNEK20@eusync4.samsung.com>; Thu, 21 Aug 2014 09:45:29 +0100 (BST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linaro-mm-sig@lists.linaro.org Date: Thu, 21 Aug 2014 10:45:13 +0200 Message-id: <1408610714-16204-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1408610714-16204-1-git-send-email-m.szyprowski@samsung.com> References: <1408610714-16204-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4Nd2VG78GG3S9ZbWYs34Nm8XK7mY2 i7NNb9gtvlx5yGSx6fE1Vot7a/6zWty+zGux9shddosFx1tYHTg9Wpp72Dw2fZrE7tH19gqT x4kZv1k8Ni+p97j97zGzx7o/r5g8+rasYgzgiOKySUnNySxLLdK3S+DKOHN1MVPBNv6KR1tn sTYwrufpYuTkkBAwkeg+9Y4NwhaTuHBvPZDNxSEksJRRYtbzucwQTh+TxPYJcxhBqtgEDCW6 3naBdYgIxElcP9fIClLELPCAUeJn03N2kIQwUOL4ny4gm4ODRUBV4sd5XZAwr4CHxL8tU5kg tslJ/H+5AszmFPCUaDwEMocDaJmHxNrX0RMYeRcwMqxiFE0tTS4oTkrPNdIrTswtLs1L10vO z93ECAnCrzsYlx6zOsQowMGoxMN7c9GXYCHWxLLiytxDjBIczEoivDZ9X4OFeFMSK6tSi/Lj i0pzUosPMTJxcEo1MGacXh3FGhB8sInXc0HV/dWcCTeF7a+IhjlknHi11oCLZ/3D+jSLfdv+ /j7H3n/RXf1f7QT+X7mXCwR7twenxSwuMm+6r3A0+7Hm0+bMG7P3PCm9mfyt3UspoD/wXdiR zHPxxivO7fqglrnv/nq3g99fMLf8uLe3Xp5bJV1SSPTaOqGD03qL7iuxFGckGmoxFxUnAgD6 Hnz7IAIAAA== Cc: Joonsoo Kim , Russell King - ARM Linux , Andrew Morton , Michal Nazarewicz Subject: [Linaro-mm-sig] [PATCH 1/2] mm: cma: adjust address limit to avoid hitting low/high memory boundary X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 Acked-by: Michal Nazarewicz --- 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 #include #include +#include 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) ||