From patchwork Mon Jul 4 04:53:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Chen X-Patchwork-Id: 9211621 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 3D26360572 for ; Mon, 4 Jul 2016 04:56:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A2FB276AE for ; Mon, 4 Jul 2016 04:56:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1984B28465; Mon, 4 Jul 2016 04:56:20 +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 54C00276AE for ; Mon, 4 Jul 2016 04:56:18 +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 1bJvta-00064l-DE; Mon, 04 Jul 2016 04:54:10 +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 1bJvtW-000632-EG for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2016 04:54:08 +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=c6U8Xz4WRoo/R+PyzKwG8bpagyXXF4FfXTAkJnyxUks=; b=QDMFsi5fsjCCZFsQJ8ZQPUvIhC7OcX8B9oNmNdyqN9fXJnRtvhzSmuMwAk1CRX7Jqlg4t31qKum5bYFiExpguS406t8NX0L//qXbJMg0hwUiwPY561h50LfjI9qJxri6db8TMH7MLCEaPiJ7MRuReK9t7Pu4AK8+RTwrAZdzb5Q= Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp0179.outbound.protection.outlook.com [213.199.154.179]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-62-wUYAzdjhMNulc8cn1bu8nA-1; Mon, 04 Jul 2016 05:53:38 +0100 Received: from HE1PR0801CA0001.eurprd08.prod.outlook.com (10.167.184.11) by HE1PR08MB0572.eurprd08.prod.outlook.com (10.161.121.12) with Microsoft SMTP Server (TLS) id 15.1.528.16; Mon, 4 Jul 2016 04:53:36 +0000 Received: from AM1FFO11FD027.protection.gbl (2a01:111:f400:7e00::195) by HE1PR0801CA0001.outlook.office365.com (2603:10a6:3:6::11) with Microsoft SMTP Server (TLS) id 15.1.534.14 via Frontend Transport; Mon, 4 Jul 2016 04:53:35 +0000 Received: from nebula.arm.com (217.140.96.140) by AM1FFO11FD027.mail.protection.outlook.com (10.174.64.216) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Mon, 4 Jul 2016 04:53:35 +0000 Received: from dennis-ws.asiapac.arm.com (10.1.2.79) by mail.arm.com (10.1.105.66) with Microsoft SMTP Server id 14.3.294.0; Mon, 4 Jul 2016 05:53:22 +0100 From: Dennis Chen To: Subject: [PATCH] arm64:mm Remove the redundant initrd memblock codes Date: Mon, 4 Jul 2016 12:53:14 +0800 Message-ID: <1467607994-14368-1-git-send-email-dennis.chen@arm.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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)(199003)(189002)(50226002)(5003940100001)(36756003)(189998001)(33646002)(305945005)(86362001)(356003)(7846002)(77096005)(8936002)(110136002)(26826002)(11100500001)(19580395003)(246002)(8676002)(19580405001)(47776003)(5003600100003)(7696003)(106466001)(586003)(50466002)(2351001)(92566002)(87936001)(4326007)(6806005)(104016004)(50986999)(48376002)(229853001)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR08MB0572; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD027; 1:nJ67FYGjSugGQkzSUZAKr4kZkPx5KGiMGxMzXTbq/RQJ2Hc+B0uEtxVzJFndtQ7wr+kYeZAOBDsTJW/cn8x9eZl54m47nSpFaBJyb0S5ERNGwAO7gMJQFbAPsuIwVbwBxDG2aYbgnaUGSZMxCOnMhenLulyP5MARdqrAad7HrElffONwWNC3J8FH48tQ2WHACKRj7NSzoz+iz5MditYWTQPycA5fvuO0Rp/khek/GU89fDDg5eYAQIMSB/VuysD2UF5RP5J4XKQuAasqE8neH1QhvCN7ZH4Berh9MIsN9gTOhxtWnxqZf8mif9+YwpVBQzL6y2u0NVuX6QNa0c9o+hKtlVHP3WMrzN9TStccixCX0UFHGkXq2XuoCvhiwLzcXjXaGYNGygFOeDwXAdCVn3l7YOGBi/reB7jql/zl3qUK373f4jejssJLVkJQMI1tUDmOV11hzKJjGyPFuiykWld2SXdE/zUU0+zQgDdbmY008OA2OpZ4ntkHh9C27FZTTYCk5Ok34OLRDRJB1D84l2kYpFicuq6blblpsKTvt+OsTHfhHtkVRb1hymiJZfXe/2MkPed6IKAUYQbhA9ce9m6+Nod09SVnsF3LSj9B5Y4= X-MS-Office365-Filtering-Correlation-Id: c538102a-a3ec-42fb-44ec-08d3a3c7280d X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0572; 2:oOWY8xlqhzY7hi8zsFUVgoVmCe0WpeCJqNRu9BFBrgbNtiXlO63UOmdHtB1WZpb1HMCE/lUBhn4l0j2Fb6sIgcrXwz0cxowafnIOAWsN2+n+9sypuzj4AurW5kJXnHCQwA36YXFl3e3FqWDMmXNqJVHb7AujWZXCdhWMY3DUNIRUF1vwihRmSzdK3cXljhMr; 3:liplPVsEUOox943KKc094UrCTZcTZWW5GkUhCLQ1lOgDbOjO1fg189G5vbZS3MFRbOo9azsLGiRWN4Np7oYsrPhUk9LQXmKFLBOwjQqe8Rkn7ohiv9IMj2jf1zkfLFbqFNkamrfpidraEZ17EsgVYkv9fY+Ac8OGas2LjIehAB9PyKUdzKQ45KuSKXSSvhsOk31yrpv3n8C8NI8RE6PhXNwWGyDaskX4ulV6NOlBWtURN6bNO+l69a8aBqfm0xJsjmCLIbAY5yfXCEoia+FJ6w==; 25:2o/7t148YtxJG/rULqr40bNSsi785O/xSh2+x0hlA6ulTYp7C4LIdh8nqfoaKeGmU9DcFC2sVywDtctwQHNpEMy6C+6mdlOzy81LL2ZKj0LZdZLgiUA06VDnTzaRNUjUJ3M/GSD1JFlp6/ue1EZoPoVMbfvwQeu024sm/orDsX0iFlRcslmjkU/Eco+Uso3UeXBbw/B7IOikzPqhjaoi5nMGXZO8Uxa8T3GzSF33LG1LYs+QXjmfO0ErEp6Gc8X6xRK+AHrNrypx9Wj+cLJT/FQxQxIW7RqalMuMU36f/z77DVTTVQ/53QL1ganJeReOB8SQA1tvUxpfl9OMq50K5caigcRhFc5kwN2ZvdjHDef7fB+DR9gEVokgyyYi6/YAN3MqwoEZtOnaivmt8kmoJ7OJTj9+vNPuqqpO2evbWyc= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:HE1PR08MB0572; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0572; 31:pgBAHhBrF/mSsjaJWP9U8xM7iR1ZmcyV7fyaUy6nCF+M2VcZEjnwb6a3roIip3Y2l1vpe1ipobYfWuaUCWwYsLCOi1ZXzCRbLycaMIguY6s7f8YMR0LWt05LTEoF6S1XagSsWh4A/Tg+TCvowZCYOOfax+BwjYUmd0bvFXk5rZrV37XBGdVthNDNDbsiFmCon2ZJXCdEc7lUDzq5b7Z3kg==; 20:s5oxh3mYEkWqlX7GlKbRWSesFoD/2M2ArVwAPK+4+RgrT17lgqGyu/y9eTJA4/eToghy4k6MkQ/YxSW3Yev/ZuZeWqJ6JxPAjDamPfV5ZgJS5CElJNvkGqFGheLaSsVFWkjOUEgWUJ8crwJBiBWH4wFnMK0wmLWPKH5aC/sF0knGFEtf0yLgYrocR5u+PvZxH4AW5gR3L/Rk9n48ehc6bcsVu1G1HQqWOrGBN6ALdxkYo5OKvF7QOUe5SMXTym4W NoDisclaimer: 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)(13020025)(13013025)(5005006)(8121501046)(13023025)(13024025)(3002001)(10201501046)(6055026); SRVR:HE1PR08MB0572; BCL:0; PCL:0; RULEID:; SRVR:HE1PR08MB0572; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0572; 4:FyFrVoyvahe94uaQuhit1rKGRSV19/jR8+wKaey6Fc84YcwrVWNWfniUL1ezhL/WjFxYwaj5+/KyorGTp+5CruGSpxNThnhZvkh27L/DIXfhktwFFS3y1TQut2LY50qBgndIMceVwj95pjVYCTEisXwUyC6Ui51vSwzrwfzY9TVFaP9Er+fbZcCN9YYyeSFQVzy/S1KAytkmWmxVaQztmeWzlGcWSN4gvuEDpk35razOeiuRdAoDEOFY9549rPGV+rhZNwPstIy3rQVLIQc8HGxmhJmA7/c9EK5LxHFTBaaJNETYkPSKnPyjKIFHyETYvQ2MRqY92UdW5REuAUzbl7k5S78IUhYoIt38Ik3qy6QHtST+RUibGq/Yw4GA23hsD+2SBhMxTI/zsDppBt3kUIm4OO454/BYYvA6j6kmI1N+p+JF1wVI8/jxtChvGYrX0e4ejFz+VeihgL3ADqZIArG4ywx+Nh3sG4MXty93E/nRNLxU/kKwJtFaJctSqoMq X-Forefront-PRVS: 0993689CD1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR08MB0572; 23:NymMB4mCuvgWsaDpCJ3CwEcW9Uu/gP5fEM6+tlBbm?= =?us-ascii?Q?XpHkn4vkqy6t1QRbGPexO+1OPsurI66kIN2g2RdW67Sn41xNDB9NSxCSzVUx?= =?us-ascii?Q?lPU5Db0OpxDwEu1/vlZDzDyApLWQrPENMSEDdeZlHh4XgWOv+BLV12fFqpr6?= =?us-ascii?Q?i6m6o19een9ATdhyDau6gLXyDR9QMgWPTofFi1T6a0CcWRr+eZODzc8FojX4?= =?us-ascii?Q?I1aL5epFA7h5TvTqYyn2MasgVR+Dsduh4sjtqvNX9/4IIivWnQd8z7NKcVn4?= =?us-ascii?Q?RdZ3aYk590pBTC5XwWkEpYpr7Izfv+ULesmQ+gDnWpMdDutFIOeEsqP5m7qD?= =?us-ascii?Q?DLRcfIFFkJjRBroSI+vhik5DE7Uhu8zBaMaiDJzqWsXEWiZNvjumLCxp8JHU?= =?us-ascii?Q?Vbj2D8EOfvepFYpUy7PpjZAW2peJKoDvyMLsTUiIhzfdVZxS4BM46e5sm+KN?= =?us-ascii?Q?1xFbYGBIu87vXS+I92rZkZGqaAW2BoNd6w8vx0Ipjl4ikV4Ifb8M+9Ms9rqk?= =?us-ascii?Q?n8fh0IwRgoW2YoTfMgnHE30DEsGKRb9IgPxpT1nrOvJKLe7k+gUs7TZCNOdB?= =?us-ascii?Q?SGDs/3QTEW5Rb+ZI/i6XSPyhjvgDkysN4na/1aoBn4+QV3rbtnCH16bdacd4?= =?us-ascii?Q?8vbPfLmyTT+CQ0jrlQdsA97PzbejzjMquP55MMRYURcyB8eC0M240R/UzI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zpBgF20vCy018vvC2gnXplzRxMBFUGoTONXgDiiq/b6qyvOk5RNtJuiK24Bgq8P1khwhCRAtGpYl4c4E1CShdgsm/gE7Rjs7OwxhAV0xlk9E67pBcnSvhfixaCpU9xtvlFQQBiXkvkIcWS0UD5bVbgkkVsVqkIPPFBy//RyII/L0qYu9xgRClFrEiRHcqh2jNV6YHmoWHUkO/jz5jwgblSwRrPjM4/P7QjOL7fs11Sl4VWENaxR SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0572; 20:oCyQbl7sJ2f7jey0DTlls1y1mmg5LS2IhvSCzojYcgspaRu4Oybzusvgw2+Rsh2a6IZZH3tddhFfW4jppW/fQio4e3jCB/zSRq0uPPtDXalVJX2vi5ToheE/eeJsknsQEG1HaIC0jmXkVEU7xtYEqpn9d02N9/iPm5N0rvmFDPI= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2016 04:53:35.2809 (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: HE1PR08MB0572 X-MC-Unique: wUYAzdjhMNulc8cn1bu8nA-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160703_215406_964904_6038B0CC X-CRM114-Status: GOOD ( 10.42 ) 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 , Ard Biesheuvel , Catalin Marinas , Steve Capper , Will Deacon , Dennis Chen , nd@arm.com 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 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. 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 */