From patchwork Wed Jul 6 10:07:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Chen X-Patchwork-Id: 9216031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 939B960752 for ; Wed, 6 Jul 2016 10:10:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82FEA287F1 for ; Wed, 6 Jul 2016 10:10:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7759A287F3; Wed, 6 Jul 2016 10:10:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id A5ADB287F1 for ; Wed, 6 Jul 2016 10:09:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bKjkT-0005dN-P5; Wed, 06 Jul 2016 10:08:05 +0000 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bKjkP-0005X5-8M for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2016 10:08:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ufiUH7aehfREhe5L8oIRKZJA8yJDvWy0h3GMRbeusbo=; b=PONRNnqeq/pQoBknSWB/g0V7ZZng4rcZg1ppfJhAokLBQIZqKFRxiAZRyKElQkdjqplz4YpCK8XaKyXz8tkjujfHKaU5apzYsbF4SK7fzMUqZiKSg828591ZrvVQ5RzvlcH/kKwLhUDAyHHdc8bvXk1ebIBaz3/heh6x+21ageM= Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp0246.outbound.protection.outlook.com [213.199.154.246]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-52-axiH9U2QPeu77bF5WZG9RQ-1; Wed, 06 Jul 2016 11:07:36 +0100 Received: from VI1PR08CA0005.eurprd08.prod.outlook.com (10.164.95.15) by AM4PR08MB1218.eurprd08.prod.outlook.com (10.167.92.26) with Microsoft SMTP Server (TLS) id 15.1.534.14; Wed, 6 Jul 2016 10:07:34 +0000 Received: from DB3FFO11FD006.protection.gbl (2a01:111:f400:7e04::130) by VI1PR08CA0005.outlook.office365.com (2a01:111:e400:597a::15) with Microsoft SMTP Server (TLS) id 15.1.534.14 via Frontend Transport; Wed, 6 Jul 2016 10:07:34 +0000 Received: from nebula.arm.com (217.140.96.140) by DB3FFO11FD006.mail.protection.outlook.com (10.47.216.95) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 6 Jul 2016 10:07:34 +0000 Received: from arm.com (10.1.2.79) by mail.arm.com (10.1.106.66) with Microsoft SMTP Server id 14.3.294.0; Wed, 6 Jul 2016 11:07:29 +0100 Date: Wed, 6 Jul 2016 18:07:27 +0800 From: Dennis Chen To: Ard Biesheuvel Subject: Re: [PATCH] arm64:mm Remove the redundant initrd memblock codes Message-ID: <20160706100725.GA14647@arm.com> References: <1467607994-14368-1-git-send-email-dennis.chen@arm.com> <4ABE8B9C-8027-40AA-A303-A82CF014A287@linaro.org> <20160705022217.GA27637@arm.com> <20160705041834.GA28823@arm.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:217.140.96.140; IPV:CAL; SCL:-1; CTRY:GB; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(189002)(199003)(24454002)(51914003)(76176999)(54356999)(83506001)(50986999)(97756001)(86362001)(87936001)(4001350100001)(4326007)(2906002)(189998001)(11100500001)(110136002)(106466001)(93886004)(104016004)(586003)(47776003)(77096005)(6806005)(26826002)(36756003)(1076002)(46406003)(50466002)(92566002)(33656002)(356003)(19580395003)(7846002)(305945005)(19580405001)(8676002)(23726003)(5003600100003)(2950100001)(8936002)(246002)(7696003)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB1218; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD006; 1:9tyNkhBUfrce7ZuKXPIM3xLaCGTIYiCkRJfydQsmK2KOA/n3iuIYHHq6qdHBbQ4EVnHJTixk7NZGTfZUy9+JNvlwZ21TL0HhxKYqDMNhZknIlNX725rj+tIhxEuq8gUNhdAZw88Z+hoVr5V447sD5I2FbyZH33E8Twu7+S0FO8ald11dass4tyOo9Grx4hXF2rn8eT670gmf5WeifXHqTgdf51lnspuIKf5uHbUIPqe1wOnt+V0p18NMK8yNgjPnb5hbcxNVM82i1DJzjQ7LxhauSJEohPE7NRL2ap/+ltC/wZ76uHydH061NvoUj2AStWhnLSyQo8OwfEbdHOTk4NvrCLzKuuLlz+aSrGBGbo6Yr1lKERbTkTSap4rqKo91xJJFgxSQZEUKT67mvYf9Dp6pifhB4zbhQ1eWhkGqFjl/rcqf31L0YkyxDuF1BhxcKCB0iqz6e5wLFeDbVIAZ9g8QzpLzU1eW42rV1edNCERJ4M6Av9NrAGSvLNKmO+GfJ6EM7Fg7c7Qvezf8iaIpuYRzVzWJ/jl8ZWS+E46aHM93wXWgBx+sM0mk/a/QU9bJr+I5g6+GwWuQ3UlpMvWoDHtBpJ8kjzaajirDJqggoEU= X-MS-Office365-Filtering-Correlation-Id: a9c026d9-e1d7-4cf6-2933-08d3a58559a6 X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB1218; 2:o4LVmCA+yTNLqXw7BBz1WIfbDNi+0lO8bqH85rr4I7DrlLUdFu4v3IH9fN11XPAkkZPNv8av08tZYo2LV/RUkn0dfl/0Q14c3rbgQMXIpm7F1rVR2oyqT5TSFCmNBx/9cHloOoO7o3NPfiqz4REV+NbbF8JreiaCtlBhSpKCmUihG5uJynH1epKrTTsR3eSl; 3:7OpM+IYJ8j1oAgYuI0VAVwjH3IYW8fGPxeUeqYUzmROC5UURH0Hj4O7zQ0q3fb15weOuUE45FY+z8zST7F3EerkNROnPvqZg2ZqmHjaccC44WOkcanuISrYZ6FeeVws2tGB+98nzvIHf9oCKCx5p78w+xVEPOs3YrpH74E87BDWAxvt/ruEF948OU5bSWYWTvjQaKtWt3COPYwUFMZhSXTwz+qQ+4+X2czF+jDsvj1hc6k7SYc3y3gzHpae0PMDlxY+3kiwht7NDpXWd6nLpKw== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:AM4PR08MB1218; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB1218; 25:FVMi+nimJd3G1ka/RcScJG7uItJLKmmmNq7C8ownEiwRktzELbxVySpmsj9mjlRt4u1PLlxd4Gi5M7VsE4FlPXpD1HOCRVk2Cu+Tq67neMrxtvPXkHE4kxCqx9BWv9Q5j1qat8N2BBEKkFEQOWfOp2MECc6SIAM3nx2PTvOKNlISaQ7SicCRNNxYKld+UzVJ4JMrELsxCli5cjD96yudFZXIM6fqeqWvzmoqrz8/3zXe79MJsDZ3b/1cjYXeH/FNoQ42WAcLBEvWYQ1fH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: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13024025)(13023025)(13020025)(13013025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:AM4PR08MB1218; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB1218; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB1218; 4:Yyg7XEhYIxao/wE4zx/8nOX5+FabzISKh8CouAp5FS27DpJ1kyPgoHqpxPmCu20ZOvKOFycJCXKXx/syzldMPvUyspUD1T93XLsoTtg2AliJhH7ghq8sJvtKSbkOQeFZjXUGO1j+0+7TLN6HfVQSb2ihXFVWqTkqTT9Usd/59fxApd8Z5b5jfziVr3H7EK6QHG0ypCc0X2Pk/5QuLgfGkhp9QPkeHd/yBIyNZ/kohcSDEdL9laK+aIYZEHSMKnK4I3Y0PaIKxeeaX8sHl3ms+GVV/g6sspmjiYYySR6tpuR0ztesfR9cq/mjCOkClu6XbhQkMwqRKWO6eTTm+OZfr+l6hJV5dA3+3wfrenVAd0NKvqQzZ7RNnJF48QhoUhaN5tkfonL1NO/sD5B8h7UA3kd6a10S3p3Bev/sryq9U9XZ59Vis+vzxa9Xlb64E8ul3D+mT76RFA9VGwEaO+i5FRcpfAwBFzRQ2NjUjN82OLv9qFQY248cdNdfi16iMLgV X-Forefront-PRVS: 0995196AA2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB1218; 23:27yTf7PYjeEPWbouyuKNWf87eYcxz2z1DHxiL/vtf?= =?us-ascii?Q?0bI7x3DdwCiYFsh3NzWUF3YcLFkdS4w500FQamfb8FHRMRNewVIvpxKZ31g2?= =?us-ascii?Q?XY3xZrie7pD8vGyylTe2aBmydI0UO6OqKC+Jb3k04A5bL7dzvcgDagglow7c?= =?us-ascii?Q?tWpLftQ2xObDyvjj3AnqoPi0GbWDc1OglHuQoVqh/BYAHnJ54ba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H7 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB1218; 20:ue/MZex/tJzJAaWNSkv8k3Wq3e08Tm41r6Fm1I1R/PMtXKiqnaUCXTB3a6ByLCk/osA0qQiLcHmEXwxLVXVrAkX3iX8TLAFw6OjVOlCoED6i9r6FG/G5YyDki/nLYaQHvYVWL4XCi/zmiiPx4DiQ2D0okAUMFvUZSMzCl6E1kpc= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2016 10:07:34.0171 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB1218 X-MC-Unique: axiH9U2QPeu77bF5WZG9RQ-1 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160706_030801_833430_2A98B685 X-CRM114-Status: GOOD ( 27.39 ) 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: Mark Rutland , Steve Capper , Catalin Marinas , Will Deacon , nd@arm.com, "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Jul 06, 2016 at 10:47:57AM +0200, Ard Biesheuvel wrote: > On 5 July 2016 at 06:18, Dennis Chen wrote: > > On Tue, Jul 05, 2016 at 11:41:02AM +0800, Ard Biesheuvel wrote: > >> > >> > On 5 jul. 2016, at 10:22, Dennis Chen wrote: > >> > > >> >> On Mon, Jul 04, 2016 at 12:33:05PM +0200, Ard Biesheuvel wrote: > >> >> > >> >>> On 4 jul. 2016, at 06:53, Dennis Chen wrote: > >> >>> > >> >>> The memory range between initrd_start and initrd_end was added to the memblock > >> >>> twice unnecessarily in the same function before initrd memory range can be freed. > >> >>> This patch merge those codes into one piece of block and add the initrd memory > >> >>> range only once, also it makes the code clean and simple. > >> >> > >> >> This is likely to break under KASLR (and I would recommend that you test with kaslr enabled when you propose changes to this code) > >> > Hello Ard, I've tested it under KASLR on Juno board before proposing the changes,where the firmware provides the RNG protocol, it works well. > >> > >> Ok, thanks for confirming that (and apologies for assuming you did not test it) > >> > >> >> > >> >> The randomization of memstart_addr needs to execute /after/ adding back the initrd, otherwise the chosen value of memstart_addr may push the initrd beyond the end of the linear area into the userland range. > >> > Yes, I know the 'range' is depends on memblock_end_of_DRAM() and memblock_start_of_DRAM(), but I can't see that the order of initrd added to the memblock will affect > >> > those two values returned from memblock_ fucntions, IMHO the initrd will be loaded to somewhere within the DRAM by firmware, is that correct? > >> > >> memblock_add/_remove may affect the return values of memblock_start/_end_of_DRAM, so the reordering will affect the range of the randomized memstart_addr, afaict > >> > > Hello Ard, since the efi stub will load the initrd block to the DRAM, and all the memory descriptions passed in by the firmware will be added to the memblock by efi > > stub, so in this case adding the initrd to the memblock will not change the return value of memblock_start/_end_of_DRAM, else it's a bug from efi stub, isn't it? > > > > First of all, every memblock_add/_remove call is likely to affect > either memblock_start_of_DRAM or memblock_end_of_DRAM. The EFI stub > does not manipulate the memblock table, it simply retrieves the UEFI > memory map from the firmware and hands the address to the kernel > proper. > > But more importantly, the initrd could be loaded not only by the EFI > stub, but also by GRUB, and so we should be able to gracefully handle > the case where the initrd ends up in a place where it is outside of > the linear mapping, either due to a mem= kernel command line argument, > or due to an insufficient VA size (e.g., the Freescale platform that > puts 2 GB at 0x8000_0000 and the remaining memory at 0x80_0000_0000 > cannot run an ordinary 39-bit VA kernel without losing access to a > substantial chunk of its memory) > Hello Ard, Freescale platform is a good example. In this case, with 39-bit VA, the linear map area is only 256GB, while the upper memory block on that platform is 0x80_0000_0000 exceeding the linear size, so current code will not put the [0x80_0000_0000, size] into the memblock, if kernel is loaded into the lower address memblock [0x8000_0000, size] while initrd block is loaded into the higher memblock, so the memblock_end_of_DRAM() will be changed after adding back the initrd. OK, so please modulo my prior comments/questions. Maybe we can have: -------->8-------- Thanks, Dennis > > So this means that we cannot randomize the linear mapping until we > have added [back] the pieces we expect to be covered by it, which are > the [_text, _end) kernel range, and the initrd. > > > > >> >>> Signed-off-by: Dennis Chen > >> >>> Cc: Mark Rutland > >> >>> Cc: Steve Capper > >> >>> Cc: Catalin Marinas > >> >>> Cc: Ard Biesheuvel > >> >>> Cc: Will Deacon > >> >>> --- > >> >>> arch/arm64/mm/init.c | 58 +++++++++++++++++++++++----------------------------- > >> >>> 1 file changed, 26 insertions(+), 32 deletions(-) > >> >>> > >> >>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > >> >>> index 2ade7a6..cf26cdb 100644 > >> >>> --- a/arch/arm64/mm/init.c > >> >>> +++ b/arch/arm64/mm/init.c > >> >>> @@ -228,6 +228,29 @@ void __init arm64_memblock_init(void) > >> >>> memblock_add(__pa(_text), (u64)(_end - _text)); > >> >>> } > >> >>> > >> >>> + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { > >> >>> + extern u16 memstart_offset_seed; > >> >>> + u64 range = linear_region_size - > >> >>> + (memblock_end_of_DRAM() - memblock_start_of_DRAM()); > >> >>> + > >> >>> + /* > >> >>> + * If the size of the linear region exceeds, by a sufficient > >> >>> + * margin, the size of the region that the available physical > >> >>> + * memory spans, randomize the linear region as well. > >> >>> + */ > >> >>> + if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) { > >> >>> + range = range / ARM64_MEMSTART_ALIGN + 1; > >> >>> + memstart_addr -= ARM64_MEMSTART_ALIGN * > >> >>> + ((range * memstart_offset_seed) >> 16); > >> >>> + } > >> >>> + } > >> >>> + > >> >>> + /* > >> >>> + * Register the kernel text, kernel data, initrd, and initial > >> >>> + * pagetables with memblock. > >> >>> + */ > >> >>> + memblock_reserve(__pa(_text), _end - _text); > >> >>> + > >> >>> if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_start) { > >> >>> /* > >> >>> * Add back the memory we just removed if it results in the > >> >>> @@ -254,41 +277,12 @@ void __init arm64_memblock_init(void) > >> >>> memblock_remove(base, size); /* clear MEMBLOCK_ flags */ > >> >>> memblock_add(base, size); > >> >>> memblock_reserve(base, size); > >> >>> + /* the generic initrd code expects virtual addresses */ > >> >>> + initrd_start = __phys_to_virt(initrd_start); > >> >>> + initrd_end = __phys_to_virt(initrd_end); > >> >>> } > >> >>> } > >> >>> > >> >>> - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { > >> >>> - extern u16 memstart_offset_seed; > >> >>> - u64 range = linear_region_size - > >> >>> - (memblock_end_of_DRAM() - memblock_start_of_DRAM()); > >> >>> - > >> >>> - /* > >> >>> - * If the size of the linear region exceeds, by a sufficient > >> >>> - * margin, the size of the region that the available physical > >> >>> - * memory spans, randomize the linear region as well. > >> >>> - */ > >> >>> - if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) { > >> >>> - range = range / ARM64_MEMSTART_ALIGN + 1; > >> >>> - memstart_addr -= ARM64_MEMSTART_ALIGN * > >> >>> - ((range * memstart_offset_seed) >> 16); > >> >>> - } > >> >>> - } > >> >>> - > >> >>> - /* > >> >>> - * Register the kernel text, kernel data, initrd, and initial > >> >>> - * pagetables with memblock. > >> >>> - */ > >> >>> - memblock_reserve(__pa(_text), _end - _text); > >> >>> -#ifdef CONFIG_BLK_DEV_INITRD > >> >>> - if (initrd_start) { > >> >>> - memblock_reserve(initrd_start, initrd_end - initrd_start); > >> >>> - > >> >>> - /* the generic initrd code expects virtual addresses */ > >> >>> - initrd_start = __phys_to_virt(initrd_start); > >> >>> - initrd_end = __phys_to_virt(initrd_end); > >> >>> - } > >> >>> -#endif > >> >>> - > >> >>> early_init_fdt_scan_reserved_mem(); > >> >>> > >> >>> /* 4GB maximum for 32-bit only capable devices */ > >> >>> -- > >> >>> 1.8.3.1 > >> > > >> > > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 2ade7a6..2dede3b 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -279,15 +279,11 @@ void __init arm64_memblock_init(void) * pagetables with memblock. */ memblock_reserve(__pa(_text), _end - _text); -#ifdef CONFIG_BLK_DEV_INITRD - if (initrd_start) { - memblock_reserve(initrd_start, initrd_end - initrd_start); - + if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_start) { /* the generic initrd code expects virtual addresses */ initrd_start = __phys_to_virt(initrd_start); initrd_end = __phys_to_virt(initrd_end); } -#endif -------->8-------- But I really have no keen on this kind of cleanup. So let's ignore this changes, and thanks for the clarification!