From patchwork Mon Nov 9 09:39:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hui Liu X-Patchwork-Id: 7581941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1FB64C05C6 for ; Mon, 9 Nov 2015 09:41:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AE29206D2 for ; Mon, 9 Nov 2015 09:41:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 46E7C20611 for ; Mon, 9 Nov 2015 09:41:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zvivw-0003EH-25; Mon, 09 Nov 2015 09:40:16 +0000 Received: from mail-bl2on0140.outbound.protection.outlook.com ([65.55.169.140] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zvivn-0002QP-EG for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2015 09:40:08 +0000 Received: from DM2PR0301MB1213.namprd03.prod.outlook.com (10.160.219.154) by DM2PR0301MB1216.namprd03.prod.outlook.com (10.160.219.17) with Microsoft SMTP Server (TLS) id 15.1.312.18; Mon, 9 Nov 2015 09:39:44 +0000 Received: from DM2PR0301MB1213.namprd03.prod.outlook.com ([10.160.219.154]) by DM2PR0301MB1213.namprd03.prod.outlook.com ([10.160.219.154]) with mapi id 15.01.0312.014; Mon, 9 Nov 2015 09:39:44 +0000 From: Liu Jason To: "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: The alignment mismatch issues between the of_reserved_mem and the CMA setup requirement Thread-Topic: The alignment mismatch issues between the of_reserved_mem and the CMA setup requirement Thread-Index: AdEa0o7D4kn4ni8yTUC3iNCvu5aBsw== Date: Mon, 9 Nov 2015 09:39:43 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hui.Liu@freescale.com; x-originating-ip: [123.151.195.53] x-microsoft-exchange-diagnostics: 1; DM2PR0301MB1216; 5:yDXK7v/o3NyuTRDM6J5Oz77RbEWwizXLPSgBkfUuyYMhS2Ksfi6jeC9Yc9D+2uWu6LIaEnMdLFO+lC5OmNAFt1XMCQSTK+/IH3IF4I2JGx9aCnyNXirY6+XLW7I7ik14IhHw2z/FlAh8mnLvYX3tOw==; 24:EtBnrbTAGg2J+qhIrslKP4lrHxJu3sSwJ1jG3uw7Lz1rKl06MwvrYyZhjR2+1hgaAP/+quY00+kGiKW1WG4aqPugp3/JEC4VrkwSBPtr0UI=; 20:ASTwYF3NPK+51SKw6ROr5t8JWXWHgayE7ssaApS1sqVd+qjOMuhpgCcFOiKStvx+T6QXS6N9Rffxu1fpOwszbQ== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1216; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046); SRVR:DM2PR0301MB1216; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1216; x-forefront-prvs: 0755F54DD9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(106356001)(87936001)(229853001)(99286002)(76576001)(5008740100001)(5002640100001)(2900100001)(2501003)(77096005)(189998001)(102836002)(5001960100002)(86362001)(2201001)(66066001)(5004730100002)(92566002)(5007970100001)(10400500002)(19580395003)(74316001)(40100003)(122556002)(11100500001)(5001770100001)(81156007)(101416001)(33656002)(5003600100002)(5001920100001)(97736004)(105586002)(50986999)(54356999); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1216; H:DM2PR0301MB1213.namprd03.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: freescale.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Nov 2015 09:39:43.6769 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1216 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151109_014007_755090_82E22832 X-CRM114-Status: GOOD ( 12.49 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "grant.likely@linaro.org" , "robh+dt@kernel.org" , "m.szyprowski@samsung.com" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is an alignment mismatch issue between the of_reserved_mem and the CMA setup requirement. The alignment in Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt alignment (optional) - length based on parent's #size-cells                         - Address boundary for alignment of allocation. But this is not exactly match the CMA setup requirement if the alignment not set or set it not correctly. The of_reserved_mem will get the alignment from the DTS and pass it to __memblock_alloc_base to do the memory block allocation. If no alignment property in the DTS, the align will be SMP_CACHE_BYTES BUT, The CMA setup require the alignment as the following in the code: align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order) 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;         unsigned long node = rmem->fdt_node;         struct cma *cma;         int err;         if (!of_get_flat_dt_prop(node, "reusable", NULL) ||             of_get_flat_dt_prop(node, "no-map", NULL))                 return -EINVAL;         if ((rmem->base & mask) || (rmem->size & mask)) {                 pr_err("Reserved memory: incorrect alignment of CMA region\n");                 return -EINVAL;         }         } So, there is very likely that the alignment mismatch between the of_reserved_mem and the CMA setup requirement. The sanity check in the rmem_cma_setup will fail and CMA not get set up in the end, this is not expected for CMA. In the test, there will be following err log when this mismatch happen. Reserved memory: incorrect alignment of CMA region. The following patch to fix this issue, any comments? ======================================================================================= diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 62f467b..a20d4d3 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -124,6 +124,15 @@ static int __init __reserved_mem_alloc_size(unsigned long node, align = dt_mem_next_cell(dt_root_addr_cells, &prop); } + if (of_flat_dt_is_compatible(node,"shared-dma-pool")) { + phys_addr_t align_required = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); + if (!align || align != ALIGN(align, align_required)) { + pr_warn("Reserved memory: the alignment not set up correctly in '%s' node." + "change from %pa to %pa \n", uname, &align, &align_required); + align = align_required; + } + } + Best Regards, Jason Liu