Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964836AbcKWN0j (ORCPT ); Wed, 23 Nov 2016 08:26:39 -0500 Received: from mail-db5eur01on0067.outbound.protection.outlook.com ([104.47.2.67]:22160 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935010AbcKWN0S (ORCPT ); Wed, 23 Nov 2016 08:26:18 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jason.hui.liu@nxp.com; From: Jason Liu To: CC: , , , Subject: [PATCH 1/1] of: of_reserved_mem: Ensure cma reserved region not cross the low/high memory Date: Wed, 23 Nov 2016 19:37:01 +0800 Message-ID: <1479901021-25064-1-git-send-email-jason.hui.liu@nxp.com> X-Mailer: git-send-email 1.8.3.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.158.241.86] X-ClientProxiedBy: KL1PR03CA0012.apcprd03.prod.outlook.com (10.165.63.22) To AM2PR04MB1121.eurprd04.prod.outlook.com (10.162.36.18) X-Microsoft-Exchange-Diagnostics: 1;AM2PR04MB1121;2:5WxfxOHnLg5QAV/oJPaBo9m8HdcrCff0XBIgXMw71LqN7WPTbIOxQYwNRNkwxk57xLopx5d/eHw9zo6veFd815IZgffq4r4y/XrgLZWxchfvxdNr+XimdpL+k2VmoIEgiROiR9DHst72wBHoZmE7I9P+uCtaUKOd6Vd3R8njJ3s=;3:+/eX0HWDECgn8ZP4RQ6tAJkXpNLCxszylJNa3HUyNGyxjiiUB+psmJBGFcjjxH73feldat7TFqXE2alyeVDqrHjIVyjoyIvrJUX11FbxuqvGBSRrtAuMkBj4z4k9fh33vXhZkfw96WeFzDgexRvSYhAd4P01+fZQ+D2bnmM2vZY=;25:6ERjiiPjfzquJMInWLQU/GPX8JKUdCI6z4sSn9NubFhJXNqVjS1372rO7X/O8hoZgzuvQXsM+3MAjOScJ1Ie2r1/DGBLNQSGduP8DJsDh9qXjjUxkJ5OPr9UI7OCdW3IsTVzPsmtqUIR0ypxgcmCsiFovFsKm7787u92yUjsJo1VtzedRgvQXtdS4stHPgkWU3k5j4N6/WdQXsmznzv1mmyAEcvpEYyk1yQ9yM+Bfgt5ujFvrFTyhwq7goAgqFsvnvy663maKuegSWeTzEQwlmqBui02xJ6Yx3HaZV6qXfS4Yh5NsHXQ5Need64JIP1DYhNTYwilAC9SqZYvch0tTcn+3b9+mcBYYJe0Sww8dFPGkWIx2Ef9G54ic0IablUKgAIY4C15uUdt2NUEFwLi4DzGAHbAWalQdSc7oSe+OcvYcAfGmGTvzPbFza4FrD5hBeVNys5yorbpHlPKok+4ZQ== X-MS-Office365-Filtering-Correlation-Id: 269f1a53-19ad-423d-5ee9-08d413970084 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:AM2PR04MB1121; X-Microsoft-Exchange-Diagnostics: 1;AM2PR04MB1121;31:KLlnOD1BlfoQC6n21HIAnlD9kHLGlBkjcAJVZ7qpbaqscUZs+y7JHqZ56yF9DD2XSALKzKBaDEjlHmxuapwxNpOrKQ81YD+xhY7cMGQX809XXvAdkTmd48ni/B08DDHylfwnr2NZziVcR4wuY5axeokRPCQXcZmFYG4W7UF+ETS+U3/0AB3N7LD7JIJptxWwfQtrRzd1sI/MhZQrJhjPAZU8MOWc+PwUVYt14RAg4B6nNX0REIrboo/ZK/2M5iRZigiLWKnH2OtvFZPuXt0YBA==;20:nQMaGrnZBGAuWZFn6yjoV1uKaKN291NjMypK17tPSk6AaM2p9MGPDxFJDxIZL13/olAUUlrrjbVpJM2sdulNLgVD8DNB/kyaFNMkSZM5FccH3xsZncpMTY4D3OygFdMNEukgcXC9C7aBsHztPSGvTktWKRBY5kGT2I2dmXUiT8UxZA/w4cDFlF4fHjv42pLMATEXfI3m0G0oGINStGoPlHt0XHEZKRSYTo0LhPWUVEYmtVXB5pvh9hVyhZNQLVCsDvHZ/vmfMffT+sm5TpkvI79eyWuiGTKhRJtrH4YDAw5xDHTljOcuArgIi6KoSNoTdppl264Qcb/l/sI2tU8yNuBYQyltD5xFbTmmFe7AQ0jt/mi2s0qb3E4fWJsrN3UoEXWD4fJjg44VKRkWyNeIuzyU0x4mjWbP/KP3W9JBN+H/0s7U0wFzTmbcjVd/y8QQ+q5NsxFUbJIC0NmWvJuLV5gw/h0ac4tpiR2GisJrJY4UFgPbZAfGGFieH6Bs3fq6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6060326)(6040307)(6045199)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6046074)(6061324)(6041248);SRVR:AM2PR04MB1121;BCL:0;PCL:0;RULEID:;SRVR:AM2PR04MB1121; X-Microsoft-Exchange-Diagnostics: 1;AM2PR04MB1121;4:o7tOlck18NPBauJQH8EaQmmP03lgqX/sQH5NvNkdbiWm/6rbtsuh+aYBxm2ioRw3LKDVL6EhqBHuh+d7pBVYdFc1HYN/q5jQa7ZAkIvtguAjderb7a88mA/fbQi1Xk2Z4i6rUG+mVippIKsGTjchD9RXwnaja6uTjpEt0VO6T3z54VQcRz2pejwHlJLI92sY0K0SWGVB1oBr8AZFy7AkWALNy+wa81sRUqQB6Uf1jJXDnWl5qPAANICz6dVpUlweKpmG7ShXBqvLz9UPMTktgC3oKZgWQBk0rXT6VdxvDhVBQ6OEaGWpsrf6iUES6UqvHLo7j/+guBhiR3UfImuBM4cGstgBUSiVcl9DniQpN9r1mw7n+JdnVFK8XaNBT06BY1QL5lRk8iSniwsKFqGiOEd6NncNj3n1XlUhNryRW2vhGEGjtOJ5/ktAMjbY5Nk8mPfEDXLqxo8SS2UgHhkP83bBoITQ6U6VQzT7ixkpJbmAXYeKUsX0f8SkuuwUrimnKbMexCGd9ccZBqk7XrHcVeV+teBBlgR/lri2YWEEV0JFrn67FwKQ/8KS3ZzhPfOzUZE0EeSzMs2oZA0f32lI2A== X-Forefront-PRVS: 013568035E X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(68736007)(7736002)(92566002)(3846002)(77096005)(5003940100001)(6116002)(4720700003)(33646002)(47776003)(97736004)(189998001)(8676002)(106356001)(7846002)(66066001)(50226002)(305945005)(50466002)(48376002)(81166006)(81156014)(38730400001)(86362001)(5660300001)(6916009)(50986999)(2351001)(110136003)(36756003)(4326007)(2906002)(101416001)(42186005)(39060400001)(105586002)(7099028)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM2PR04MB1121;H:yocato.ap.freescale.net;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM2PR04MB1121;23:78JzCDImq9G/a5E/6NvIaeBElf4CRP9jnDRmwYemO?= =?us-ascii?Q?f4qb303JcAZ8GYAAwuqsJDWY4aFH7br94+URS+Y9rgqh3XC+mU4lYZOe7E8j?= =?us-ascii?Q?h/T/MezkpTnxFLlItVAykbKrU18wmpsYj2UBTlo+AXkflBkr/F51jwYBsbIz?= =?us-ascii?Q?J8jRLP4HjZmGLoQtbJRsVtmixDHmIUU0+DHAsqJcLmMUXJ63Ei4d+2ryEvqT?= =?us-ascii?Q?GBgD5ze3k7JNCkblnMGxqvV6CutLGn86pk96JDtDS+EiQ2lbWsfSgYOjAPY3?= =?us-ascii?Q?y/tTkXAb51ludjBwA3mgA37RGn+sEv40ZT1+OYUSpLrB48+cMlk6S6ZY+TK6?= =?us-ascii?Q?6s1bUzTE/ETavmLFAkWrKiafNC7y65Tnf6I8eMjLKkIpAW7KI2QKpsGEsWau?= =?us-ascii?Q?Fpti/zQdwEbyZLa/C7LUDTqXHyDOtSGpbPkQF+PWyBpU/XffRxuJnwx2cfNo?= =?us-ascii?Q?refUNS0UJIAt5ZQT5AQ+DEFohTbPK8yQzwWOP+lFowpNvIX5406vAdsy/vs+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XEgTiLRzIZP49OuOO7iaCL2akn39NOlpPBa9xAnA9cJOElL7QD0vAzrxBQ4lONg6IvYO88Viw/PpVMZCfEYr86efQ8kQMOPe7tTmRU4mbhCh1jvSxGGKW7tCMeggTRBPUxHUZkjlVgSYqwCEbhAwU;5:l2fB/QAyMs9yVjNDCKdhp7SGWVlXCbXHySipnIyAz3QHpJXiAcAGL2UopdDsXtUty1rPBZ/Pl7Z8vJNHARI3tPjyxsTKyP7xpr7c1BGnoULU1STnni1LqXZ4d9e17A+R00+UwIF6iWRkIUqQoKN9OA==;24:Q990vajn6ns1LAz7KAlYR8n01j56PrwB1+wECEB8b+LsCJMCUdGs1uECGLkypl7Ot+wSEY73tLAH3zVJg4hydLDzXYErJnxB6YuCmgCDCy4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM2PR04MB1121;7:wZQIPuZvpb7Fg4DK9DMx/xtWvbxMn8MW8xW2VwniVbkj9b+nQC2BVCcFXuBCp7NkZ3Ex5E8i7WX8zyDChXDIN5m3clebIKOZtSZnRMvrOrxoJ9ZaImrzNkDdBazYIGSO4vIHZJvNQcyNGNVoaNlCI9ZefxLJErOIyjk3T7ScXm0zN9F+Ol7LBX0LfWrSC+iNsBC+WRzPNARo75O8KETdb7tJO3kdHBDt7AB7WrZqlHX0UfSK20V6hLhwjZP6Z7ccCIc7cQVBsmZlaa7fgi7WKaxj/f6t/AOcNPIZ/Pwmz9QWRpbGOZzj3OYRchUfXeYtYalH/PcRoww/5G6MSNkj84/U8+3gmXvz29a7q6bdnuo= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2016 11:51:01.3299 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR04MB1121 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4258 Lines: 112 Need ensure the cma reserved region not cross the low/high memory boundary when using the dynamic allocation methond through device-tree, otherwise, kernel will fail to boot up when cma reserved region cross how/high mem. Signed-off-by: Jason Liu Cc: Laura Abbott Cc: Frank Rowand Cc: Rob Herring Cc: stable@vger.kernel.org --- drivers/of/of_reserved_mem.c | 42 +++++++++++++++++++++++++++++++---------- include/linux/of_reserved_mem.h | 3 ++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 366d8c3..852345a 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -31,11 +31,15 @@ #if defined(CONFIG_HAVE_MEMBLOCK) #include -int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, - phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, - phys_addr_t *res_base) +int __init __weak early_init_dt_alloc_reserved_memory_arch(unsigned long node, + phys_addr_t size, phys_addr_t align, phys_addr_t start, phys_addr_t end, + bool nomap, phys_addr_t *res_base) { phys_addr_t base; + phys_addr_t highmem_start; + + highmem_start = __pa(high_memory - 1) + 1; + /* * We use __memblock_alloc_base() because memblock_alloc_base() * panic()s on allocation failure. @@ -53,15 +57,33 @@ int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, return -ENOMEM; } + /* + * Sanity check for the cma reserved region:If the reserved region + * crosses the low/high memory boundary, try to fix it up and then + * fall back to allocate the cma region from the low mememory space. + */ + + if (IS_ENABLED(CONFIG_CMA) + && of_flat_dt_is_compatible(node, "shared-dma-pool") + && of_get_flat_dt_prop(node, "reusable", NULL) && !nomap) { + if (base < highmem_start && (base + size) > highmem_start) { + memblock_free(base, size); + base = memblock_alloc_range(size, align, start, + highmem_start, MEMBLOCK_NONE); + if (!base) + return -ENOMEM; + } + } + *res_base = base; if (nomap) return memblock_remove(base, size); return 0; } #else -int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, - phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, - phys_addr_t *res_base) +int __init __weak early_init_dt_alloc_reserved_memory_arch(unsigned long node, + phys_addr_t size, phys_addr_t align, phys_addr_t start, phys_addr_t end, + bool nomap, phys_addr_t *res_base) { pr_err("Reserved memory not supported, ignoring region 0x%llx%s\n", size, nomap ? " (nomap)" : ""); @@ -155,8 +177,8 @@ static int __init __reserved_mem_alloc_size(unsigned long node, end = start + dt_mem_next_cell(dt_root_size_cells, &prop); - ret = early_init_dt_alloc_reserved_memory_arch(size, - align, start, end, nomap, &base); + ret = early_init_dt_alloc_reserved_memory_arch(node, + size, align, start, end, nomap, &base); if (ret == 0) { pr_debug("allocated memory for '%s' node: base %pa, size %ld MiB\n", uname, &base, @@ -167,8 +189,8 @@ static int __init __reserved_mem_alloc_size(unsigned long node, } } else { - ret = early_init_dt_alloc_reserved_memory_arch(size, align, - 0, 0, nomap, &base); + ret = early_init_dt_alloc_reserved_memory_arch(node, + size, align, 0, 0, nomap, &base); if (ret == 0) pr_debug("allocated memory for '%s' node: base %pa, size %ld MiB\n", uname, &base, (unsigned long)size / SZ_1M); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index f8e1992..a6ee451 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -34,7 +34,8 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx); void of_reserved_mem_device_release(struct device *dev); -int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, +int early_init_dt_alloc_reserved_memory_arch(unsigned long node, + phys_addr_t size, phys_addr_t align, phys_addr_t start, phys_addr_t end, -- 1.8.3.2