Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751522AbcKQWt0 (ORCPT ); Thu, 17 Nov 2016 17:49:26 -0500 Received: from mail-db5eur01on0079.outbound.protection.outlook.com ([104.47.2.79]:5577 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750794AbcKQWtX (ORCPT ); Thu, 17 Nov 2016 17:49:23 -0500 From: Jason Liu To: Laura Abbott , "linux-arm-kernel@lists.infradead.org" CC: "gregkh@linuxfoundation.org" , "iamjoonsoo.kim@lge.com" , "linux-kernel@vger.kernel.org" , "m.szyprowski@samsung.com" Subject: RE: [PATCH 1/1] drivers: dma-contiguous: Ensure cma reserve region never cross the low/high mem boundary Thread-Topic: [PATCH 1/1] drivers: dma-contiguous: Ensure cma reserve region never cross the low/high mem boundary Thread-Index: AQHSP9OP4gd5IApOJ0ygFrKr6zB/xKDcCGSAgACXnzA= Date: Thu, 17 Nov 2016 05:21:37 +0000 Message-ID: References: <1479305975-21670-1-git-send-email-jason.hui.liu@nxp.com> <6bd1a1a9-2bc0-f5f4-0957-1826af15f4dd@redhat.com> In-Reply-To: <6bd1a1a9-2bc0-f5f4-0957-1826af15f4dd@redhat.com> 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=jason.hui.liu@nxp.com; x-originating-ip: [199.59.225.131] x-microsoft-exchange-diagnostics: 1;VI1PR04MB1136;7:U8jitgmNadZUja8cM8Wtn8EjesiiTvx6HQs1jFAfeiPhhw/aNO1fa2NceR4NswelFDtHMuNJRGElvPaTPIf4S9r9SuLhqDmwKrG7lDutQwQXcKg7Zn6YUwiA7AC9wq/BU8Sn5Z2Z09ZziKio7AVgWTnTZJmDL+HLCmaW7zCGtE6k9rr3Orr7DLjwGpvB4NXMw7DluKQpiRLVbPH8/fvIFR7oqPLCsLqlc22t6/cehJmM0UUljrXgvvE5ogDsA3bMqwOa4luQCeql6NRtmJgkKRmzNKe98GwQrXaKKFXV4elmkktQ5vw+AhCQCJEXx+AhJdUWygUJ9OhR2KilzOCZfLYutmrcK6EurNYYuIHyJYY=;23:55ArbUx85ap5MKRb5u3Mr54trtNQjVfw5h/CcMtableplwDQI4gE+hvYskqpS5Cd+MbfiIa93FmW8ZJzcE/oG958/aHhLazRC5CdQJtSxTjmYGNlsL84qtl8HEkqJxJmnprTMDnU2euFEwYkdbpRd9FAxKyYy+xBH17lUmn1LFydtO0z56B0swVgdjO9vldA x-ms-office365-filtering-correlation-id: 244f922d-ca3b-463f-be60-08d40ea99aaf x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR04MB1136; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197)(258649278758335)(7411616537696); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6060326)(6040281)(6045074)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6061324)(6041223)(6046074);SRVR:VI1PR04MB1136;BCL:0;PCL:0;RULEID:;SRVR:VI1PR04MB1136; x-forefront-prvs: 01294F875B x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(13464003)(377454003)(189002)(24454002)(199003)(2906002)(8936002)(68736007)(101416001)(92566002)(4326007)(122556002)(9686002)(3280700002)(3660700001)(5001770100001)(189998001)(6506003)(2501003)(54356999)(76176999)(50986999)(97736004)(87936001)(5660300001)(7736002)(7846002)(2950100002)(7696004)(8676002)(86362001)(229853002)(33656002)(305945005)(74316002)(66066001)(106356001)(77096005)(102836003)(81156014)(3846002)(81166006)(6116002)(76576001)(106116001)(105586002)(2900100001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB1136;H:VI1PR04MB1136.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Nov 2016 05:21:37.1922 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1136 X-OriginatorOrg: nxp.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAHMnW1b014316 Content-Length: 4100 Lines: 109 > -----Original Message----- > From: Laura Abbott [mailto:labbott@redhat.com] > Sent: Thursday, November 17, 2016 4:00 AM > To: Jason Liu ; linux-arm-kernel@lists.infradead.org > Cc: gregkh@linuxfoundation.org; iamjoonsoo.kim@lge.com; linux- > kernel@vger.kernel.org; m.szyprowski@samsung.com > Subject: Re: [PATCH 1/1] drivers: dma-contiguous: Ensure cma reserve region > never cross the low/high mem boundary > > On 11/16/2016 06:19 AM, Jason Liu wrote: > > 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 > > The inline #ifdef is not great style, we shouldn't be spreading it around. This is the similar fix in the 16195dd ("mm: cma: Ensure that reservations never cross the low/high mem boundary". Do you have a better idea for this? > > > + > > + /* > > + * 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; > > + } > > Given the alloc happened in the of code, it seems bad form to be bringing the > free and re-alloc here. Perhaps we should be doing the limiting and checking in > the reserved mem code? I original though to fix it into the drivers/of/of_reserved_mem.c, but hesitate to do it due to this of_reserved_mem is common code to do the reservation, which is something not related with CMA requirement. Appreciated that anyone can provide comments to improve this solution. Without this, the Linux kernel will not boot up when do the CMA reservation from the DTS method, since the dma_alloc_coherent will fail when do the dma memory allocation. > > If there is no other solution, at the least this deserves a pr_warn so users know > why a reason specified may not be getting requested. Yes, it deserves a pr_warn here. I will add it. Thanks Laura for the review. Jason Liu > > > > > err = cma_init_reserved_mem(rmem->base, rmem->size, 0, &cma); > > if (err) { > > > > > Thanks, > Laura