Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753166AbcCAMkq (ORCPT ); Tue, 1 Mar 2016 07:40:46 -0500 Received: from mail-by2on0059.outbound.protection.outlook.com ([207.46.100.59]:28554 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751362AbcCAMkp (ORCPT ); Tue, 1 Mar 2016 07:40:45 -0500 Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=caviumnetworks.com; Date: Tue, 1 Mar 2016 13:40:29 +0100 From: Robert Richter To: Laura Abbott CC: Marc Zyngier , Will Deacon , Catalin Marinas , Greg Kroah-Hartman , Thomas Gleixner , Tirumalesh Chalamarla , , , Subject: Re: [PATCH 0/2] arm64, cma, gicv3-its: Use CMA for allocation of large device tables Message-ID: <20160301124029.GV24726@rric.localdomain> References: <1456398164-16864-1-git-send-email-rrichter@caviumnetworks.com> <56D42199.7040207@arm.com> <20160229122511.GS24726@rric.localdomain> <56D44812.6000309@arm.com> <56D4D1A1.9060305@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <56D4D1A1.9060305@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Originating-IP: [92.224.193.43] X-ClientProxiedBy: VI1PR07CA0073.eurprd07.prod.outlook.com (25.164.94.169) To CY1PR0701MB1616.namprd07.prod.outlook.com (25.163.20.153) X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1616;2:EbVqy8sLQvGpmcJFfEtcoCOo3fUw5egmRS8+VPiUF7Bt7oKRwGaxrkI3v0sUfBaEj23y1coWzhlxVazlL1GmPDKYJ2HmQY+8AWt6IMAkMnaUU/eq/43C0oplMmK9WQcUT7jtCr/v7VRX1iI+BlEXWA==;3:eDp7qYtgZSQ4jeNWIhgi6V+Bc8HXddatEW5UFeT3bbvg1q26c0ZObuYXlqbaoodUOJk+3Hd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+em3VOQAdnTdmU5ge4cGV296ZbnE7Top7K22vXBJqiUKC7DkmeCd7sohv8Yz78Gk9vzEm6uHEwAWtJtToxUszhzugiB99LutCWhvmqCdc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:CY1PR0701MB1616;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0701MB1616; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1616;4:lTPPnoohFIf3oBQqCH87c5vrVJ4PeyvgaMe7AZtFUZDOL4rEALXeOstC6VcfW/LMzyAKUoRTLJLs/8CDcNPrvuEUhwGVYg17mTBrMH5QxIo/BVHTAj1rAQmrkTxhgJ0wduD4Tan3ZzzOZnDCWh8ZudwcOYTNd9RU2tPiY0hQFcpCb8C0snc8jWK5hTE6RbHVVLB4OKNzSNdNZKkqT353kYazT35fceBDz5xi1LwqFPExcBS7vO4YI2rMvX4NzvGGNUOPJfIaVM14669EJ1s2zN5xJUEeIDBstnimNa3texYyhoAfLYYNd0Mb5F/ucJ851pI0f4Sxtjftd1ugqzPqM7LNzfJYN/+t4t5w/mwKfq0tUAPsRijta5uI9+aI3PSK X-Forefront-PRVS: 086831DFB4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(24454002)(479174004)(377454003)(19580405001)(4326007)(19580395003)(77096005)(3846002)(2950100001)(23726003)(2906002)(1096002)(586003)(6116002)(5008740100001)(1076002)(86362001)(83506001)(81156008)(97756001)(87976001)(4001350100001)(189998001)(76176999)(47776003)(110136002)(122386002)(5004730100002)(92566002)(46406003)(50466002)(54356999)(93886004)(40100003)(42186005)(33656002)(50986999)(5001960100003)(66066001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0701MB1616;H:rric.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnost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Kuak2IdZN7gYjzWCVDprwkMF?= =?us-ascii?Q?XOhwI+gjBRhZX9QCx7PG+tEAobPR+y3XNWUzEIqKMalwbwSp24qi9mgb8pD1?= =?us-ascii?Q?z/0BURPVeNc9Is3D/2TC3QN5On3DG4vZGybDJ/v9UH0ZyhSP9l6p+2dtnW/r?= =?us-ascii?Q?kKgjyzpzeOX+qGHdaASBYxDnEkq9FoRX4Bfxjggnd8OHe5Xq8r6wHwHXBzdw?= =?us-ascii?Q?ygcl4HMd0cQKeVZWOfkTRf6klL1Ze1NuLS9MmSnxf9yO11B/KoA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1616;5:dEb2BTNHfIVqpT91PbPc5S7BSgf24mngURPZahySZrYIUrfL3uBUEdYYJgVrelww76l9A3xhdPkcEK43V+TJvVkgao8JQ6u1gWoQr0A4mUg3fFxDtbiLRDBF0NsXFhgTJkF1+oF5Wl3BOKyaOchH3g==;24:rMwDkoV/G4GgCijE2rNohdIeg6TLD7ls1SLvOIm7NwVVcBFtsrQ30e/oLO/3vFucM2YXIyVqkWvtOrs3rhinaeHtFpH5LQrg6dEkdJgu/6I= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2016 12:40:40.0898 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1616 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5889 Lines: 141 On 29.02.16 15:17:53, Laura Abbott wrote: > On 02/29/2016 05:30 AM, Marc Zyngier wrote: > >On 29/02/16 12:25, Robert Richter wrote: > >>On 29.02.16 10:46:49, Marc Zyngier wrote: > >>>On 25/02/16 11:02, Robert Richter wrote: > >>>>From: Robert Richter > >>>> > >>>>This series implements the use of CMA for allocation of large device > >>>>tables for the arm64 gicv3 interrupt controller. > >>>> > >>>>There are 2 patches, the first is for early activation of cma, which > >>>>needs to be done before interrupt initialization to make it available > >>>>to the gicv3. The second implements the use of CMA to allocate > >>>>gicv3-its device tables. > >>>> > >>>>This solves the problem where mem allocation is limited to 4MB. A > >>>>previous patch sent to the list to address this that instead increases > >>>>FORCE_MAX_ZONEORDER becomes obsolete. > >>> > >>>I think you're looking at the problem the wrong way. Instead of going > >>>through CMA directly, I'd rather go through the normal DMA API > >>>(dma_alloc_coherent), which can itself try CMA (should it be enabled). > >>> > >>>That will give you all the benefit of the CMA allocation, and also make > >>>the driver more robust. I meant to do this for a while, and never found > >>>the time. Any chance you could have a look? > >> > >>I was considering this first, and in fact the backend used is the > >>same. The problem is that irq initialization is much more earlier than > >>standard device probing. The gic even does not have its own struct > >>device and is not initialized like devices are. This makes the whole > >>dma_alloc_coherent() approach not feasable, at least this would > >>require introducing and using a dev struct for the gic. But still this > >>migth not work as it could be too early during boot. I also think > >>there were reasons not implementing the gic as a device. > >> > >>I was following more the approach of iommu/mmu implementations which > >>use dma_alloc_from_contiguous() directly. I think this is more close > >>to the device tables for its. > >> > >>Code path of dma_alloc_coherent(): > >> > >> dma_alloc_coherent() > >> v > >> dma_alloc_attrs() <---- Requires get_dma_ops(dev) != NULL > >> v > >> dma_alloc_from_coherent() > >> v > >> ... > >> > >>The difference it that dma_alloc_coherent() tries cma first and then > >>proceeds with ops->alloc() (which is __dma_alloc() for arm64) if > >>dma_alloc_from_coherent() fails. In my implementation I am directly > >>using dma_alloc_from_coherent() and only for large mem sizes. > >> > >>So both approaches uses finally the same allocation, but for gicv3-its > >>the generic dma framework is not used since the gic is not implemented > >>as a device. > > > >And that's what I propose we change. > > > >The core GIC itself indeed isn't a device, and I'm not proposing we make > >it a device (yet). But the ITS is only used much later in the game, and > >we could move the table allocation to a different time (when the actual > >domains are allocated, for example...). Then, we'd have a set of devices > >available, and the DMA API is our friend again. > > > > M. > > > > I did the first drop of CMA in the DMA APIs for arm64. When adding that, > it was decided to disallow dma_alloc calls without a valid device pointer > (c666e8d5cae7 "arm64: Warn on NULL device structure for dma APIs") so > if the GIC code wants to use dma_alloc it _must_ have a proper device. > > If the device shift still isn't feasible, a better approach might be > what powerpc did for kvm (arch/powerpc/kvm/book3s_hv_builtin.c). This > calls the cma_alloc functions directly and skips trying to work around > the DMA layer. > > With either option, I don't think the early initialization approach > proposed is great. If we want CMA early, it's probably be just to > explicitly initialize it early rather than trying to do it from > two places. Something like: I wasn't sure whether this works for all archs if called directly in mm_init(). If so, ok your proposed change would be better, though a stub for !CONFIG_CMA needs to be added. Any comment on the change below as a replacement for patch #1? On the other side, if we use device enablement for its, then early cma enablement is not needed anymore. Will check how that could work. -Robert > > diff --git a/include/linux/cma.h b/include/linux/cma.h > index 29f9e77..a26712a 100644 > --- a/include/linux/cma.h > +++ b/include/linux/cma.h > @@ -28,4 +28,5 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, > struct cma **res_cma); > extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align); > extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count); > +extern int __init cma_init_reserved_areas(void); > #endif > diff --git a/init/main.c b/init/main.c > index 58c9e37..a92bdb8 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -81,6 +81,7 @@ > #include > #include > #include > +#include > #include > #include > @@ -492,6 +493,7 @@ static void __init mm_init(void) > pgtable_init(); > vmalloc_init(); > ioremap_huge_init(); > + cma_init_reserved_areas(); > } > asmlinkage __visible void __init start_kernel(void) > diff --git a/mm/cma.c b/mm/cma.c > index ea506eb..42278d4 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -142,7 +142,7 @@ err: > return -EINVAL; > } > -static int __init cma_init_reserved_areas(void) > +int __init cma_init_reserved_areas(void) > { > int i; > @@ -155,7 +155,6 @@ static int __init cma_init_reserved_areas(void) > return 0; > } > -core_initcall(cma_init_reserved_areas); > /** > * cma_init_reserved_mem() - create custom contiguous area from reserved memory