Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753038AbcKPIAn (ORCPT ); Wed, 16 Nov 2016 03:00:43 -0500 Received: from mail-db5eur01on0049.outbound.protection.outlook.com ([104.47.2.49]:43461 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751754AbcKPIAk (ORCPT ); Wed, 16 Nov 2016 03:00:40 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jason.hui.liu@nxp.com; From: Jason Liu To: CC: , , , Subject: [PATCH 1/1] drivers: dma-contiguous: Ensure cma reserve region never cross the low/high mem boundary Date: Wed, 16 Nov 2016 22:19:35 +0800 Message-ID: <1479305975-21670-1-git-send-email-jason.hui.liu@nxp.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [199.59.226.141] X-ClientProxiedBy: SG2PR03CA0052.apcprd03.prod.outlook.com (10.169.50.20) To DB5PR04MB1128.eurprd04.prod.outlook.com (10.161.200.11) X-Microsoft-Exchange-Diagnostics: 1;DB5PR04MB1128;2:3JNH50lEobFa3vWUVV2V5caKJFpMmJx4wvmezuFWC0xWi05nvX/aqP9wQyOQN+9TwbICpqj39U38OPzXbXZna8awaKDxt7HNLQGqgVe3ula3FaBBLj6l61Is0M7DVKoGeGkgrrfnDtXJXE6GHn9ZA4mAMIPGbSHdoRJGQAh2UzU=;3:8lMmdlu1QenQxmmNHoIpFI5FZiEZ3J2rKmmOcscX1mMxMejHrILahA3OeX/Vqqo1z8RnY4wuITujFJ/bqWlqQTvzF98ujDYUFB40N3ZQVF9sF2k2DvoKTnWSt0+ijlyuh61/OBG+vr+vHAWgbdxZBJbtd6KXgjZ35koAg4FdeDE= X-MS-Office365-Filtering-Correlation-Id: 7d9e1446-fb31-44dd-218d-08d40de94b4d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB5PR04MB1128; X-Micro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9L/5+jmltVvss0xHxuVIXMFOw7VTt21vEI6ngmHvhv3UhzHY80+PkIFvH2Tb2OVeNwQNqg==;20:gcvQon3T7uocAFn3xpER44T94u31nEuAcSywsXw/+eikC4C9pKdZRgTqWxPFEIqV3m9N3lsELtAbC2BJfdwX11LAFuFVeQwueAARwpNAox1tvaV4HTiB8tqeZLaiofPLtcG+zISxs1sfCQ/mY+WCSfk/wbISIBuHKAJWvl/Tac/w73/oda/p6XksXrSEbEb4FtC07aH2HhjIPhi1m7rjldaRgf91WGnC4Q+RUfx4n3ZKcj5mDSAQ+QfVS6Q96wmRfZupseJTtOR6my2qoA1zZOy5KuUNXeI1vYRH3OtEaWT2gl/YFlLcD1MHgmZ1FDHTb9fZzdswYAcfzXrmxJ1DMwEHOEFehtBNatsb7V1RyvC6tMv5djwXCLqASvMe5fATfuOR98PJGcZ4oxpYxFWzHkpEsCzwl4QhP74nmL4vire9aGNZnYgJBjFaFpTUmE2oPsLLXsKSZIh7ZF68J+ARHkCVYPTcx1tGV7xYeZkyOZUabg/LT4GXnNvf0aKT8sx/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(7411616537696); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6060326)(6045074)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6061324)(6046074);SRVR:DB5PR04MB1128;BCL:0;PCL:0;RULEID:;SRVR:DB5PR04MB1128; X-Microsoft-Exchange-Diagnostics: 1;DB5PR04MB1128;4:mHvJsB201K6P9h34epWZp3kNMF2uiY5+wCzpLHWi/DLx35Q77VCpzn8uFVioU08L82mlRRKu2iYvSlTIqzX62oRf0ctxVDRGGUmTNjmX2aAXmFZ7byRjcDkCc4RuBiU9CgdhwTUNGgpJ4p2zrO0d4Ig0tGatv2jbLS0ILd1s52hGaPv4U68rOY4goWdxPYFtaTumNkjIZVNjvOE9QgHwiesS4G4QRQUfqdjbn7rcI+qnMTANOhvF+iEsfqJFnYLxQVFzsN/1BO1qY/kXdjGoHo0Estsc5z9FWfrlC5kmS+/tqrdOQiGLHUy2/SJolvGS/i/TVmIszAYFopxmgrHYw64iCjGty40KRkonG6k58izVYfyrdJp47tvVuLU2diSwT7WeO1LiibspVo1KdcqX05bvQiYJ9yClf3OL34wMA84/xoLUbry7OD66ijLn1RYRTV6P+fmQO0ouYFCqpgweyqWQ6IBKhzpBt5uhq6pXxtpv6+m1Tyz84j2wq30xuDSUfLDWfLaxmtOuTcuzc0MY7E4LpYzW7CnOxzY/BqJSh5Q= X-Forefront-PRVS: 01283822F8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(106356001)(81166006)(42186005)(8676002)(6116002)(92566002)(7736002)(305945005)(3846002)(6666003)(7846002)(105586002)(77096005)(36756003)(2351001)(47776003)(33646002)(66066001)(97736004)(2906002)(4326007)(81156014)(6916009)(50466002)(110136003)(48376002)(86362001)(101416001)(68736007)(50986999)(5660300001)(189998001)(5003940100001)(50226002)(7099028);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR04MB1128;H:lava-4-64bit.ap.freescale.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB5PR04MB1128;23:WHu/SWsJmr8ytfdmciZqHQoSaN14sTF1a6ZJeC+NU?= =?us-ascii?Q?yObWDg6dlX74bREDADIL1mXD9vlCnZRlWKFDHbhu3OZHYd6rDOI1ZnlhprPJ?= =?us-ascii?Q?UpOjx1BEc4nayXWY2GYYDbAtWqlr5PufI/132DASJBhZ2H0iodlXZtupIPni?= =?us-ascii?Q?S1fciqGqIjlw6Mf9fhQwI53ySv50W1JBKiVpErkUEzAieS2C3XUMMZqdn3g1?= =?us-ascii?Q?vdSukj3li/zIo2vyFmEgqcwgLjYACO9y+GrjhTijtKxuRm0cqjYTXimyri4D?= =?us-ascii?Q?M+UOiZaOnAe3h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fj2bkjiB65Q4Zcgn9OjNdivjvPtgGXRKfaa6wz2M29SZ/wwfcfoGPDSqrtmzavIzkL5PgKrvwyYPo9kPsDF1x4WGgdyFybyTOsZrn5uweAvxGjvKJFDosQzTN0JxPNX+xpDKDrJgLILgjIRgu49+IZhMaFiQN5EXsVZGZXcpqHqKhf49nfvqaTARwt0wBj5OPakuELKek5TDsIjUkIaEq+jVKdiO0uX50Fk12n64DbpqQ3;5:GJeHIz0wIwyyL1fXCFtcpDvx1s3vaqOwaqbnrNDhAWyg01uNlWvPthqXRyLGPsSnh9TYnDcY/VDlSDVfkaCKz9UT3NpdwGqniueKGTUytXURf9HzskigUCREVF/jNYnI8Rxy2G6jz/nbZcrXX4vT+Q==;24:CgRk5cJDos11G8e8TtTJ9TrGcmaXObX5lsh07HujEFD+T7BBVPQJ5joCHI2PO2WiiO4BFvKx0n4S6011QA0aoA0OONZqX+zCIaFYKo7PItw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB5PR04MB1128;7:jYu414qZFHEBlOj+9pHlUSvgsU+sfnet1eqHNLahzZkxUZiiAH3bLOJEvlUXXqpUb+PtIo+tzj3Xxy9Y4M4QQ4a4UKOfYafgSUDbB3O/9I/WrKUA6SsNU8IjTqnvzl/Y6MoFaiycbYXmfUQmTQBli6u7LsXmTXFUWcuDhPjbcXuP9B4rHjy4kQ6SO3db/ihaopnOgckXYByYG3e+Nk+7XjL3+ZraDWtQ5a7x7Zl5HfBlV8BmNteXsaIxOt/bZ5LbHrtOgU9KItDR5/zWS38eMlu92NifzF/rTlQhRhOzAyNZnLxJMulbvzi5a8AQ6V9/OuoW2PsUmJdhJ9YgBfydRr2dFLTqRC+eCPnIvSzfeFE= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2016 06:24:55.4947 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR04MB1128 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2246 Lines: 60 If the cma reserve region goes through the device-tree method, also need ensure the cma reserved region not cross the low/high mem boundary. This patch did the similar fix as commit:16195dd ("mm: cma: Ensure that reservations never cross the low/high mem boundary") Signed-off-by: Jason Liu Cc: Marek Szyprowski Cc: Joonsoo Kim Cc: Greg Kroah-Hartman --- drivers/base/dma-contiguous.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index e167a1e1..2bc093c 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -244,6 +244,7 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) { phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); phys_addr_t mask = align - 1; + phys_addr_t highmem_start; unsigned long node = rmem->fdt_node; struct cma *cma; int err; @@ -256,6 +257,32 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) pr_err("Reserved memory: incorrect alignment of CMA region\n"); return -EINVAL; } +#ifdef CONFIG_X86 + /* + * high_memory isn't direct mapped memory so retrieving its physical + * address isn't appropriate. But it would be useful to check the + * physical address of the highmem boundary so it's justfiable to get + * the physical address from it. On x86 there is a validation check for + * this case, so the following workaround is needed to avoid it. + */ + highmem_start = __pa_nodebug(high_memory); +#else + highmem_start = __pa(high_memory); +#endif + + /* + * All pages in the reserved area must come from the same zone. + * If the reserved region crosses the low/high memory boundary, + * try to fix it up and then fall back to allocate from the low mem + */ + if (rmem->base < highmem_start && + (rmem->base + rmem->size) > highmem_start) { + memblock_free(rmem->base, rmem->size); + rmem->base = memblock_alloc_range(rmem->size, align, 0, + highmem_start, MEMBLOCK_NONE); + if (!rmem->base) + return -ENOMEM; + } err = cma_init_reserved_mem(rmem->base, rmem->size, 0, &cma); if (err) { -- 1.9.1