From patchwork Wed Jun 29 00:57:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Chen X-Patchwork-Id: 9204171 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 CDDC960757 for ; Wed, 29 Jun 2016 01:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF8BC2862E for ; Wed, 29 Jun 2016 01:00:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3ED828630; Wed, 29 Jun 2016 01:00:05 +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=unavailable 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 48FCF2862E for ; Wed, 29 Jun 2016 01:00:05 +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 1bI3po-0006rr-Mx; Wed, 29 Jun 2016 00:58:32 +0000 Received: from eu-smtp-delivery-143.mimecast.com ([146.101.78.143]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bI3pi-0006n8-Dm for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2016 00:58:28 +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=3lBk+gkUh921fHkhtBVJ+KZUXbcUvJ0Fr9fGpdiGtSc=; b=aaSopqCmT8cCyHDD/5eyHnKDnnBGWql/sVmxTyWvOn1x/6WkazQ+Oonsj1Ma4qGBixCjORfMwTXFIWbCcspLErLAtmfne7sdtP0OTThUpPyprZLgeJUwJp+uA1q9tCRTyP/BeiM6QRWxaczitSoaDxK/nV7d+yjcBxKyy9+rF/Q= Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01lp0216.outbound.protection.outlook.com [213.199.154.216]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-55-QFc-4xYBMtGHyZuqNpMcvg-1; Wed, 29 Jun 2016 01:58:02 +0100 Received: from DB5PR08CA0020.eurprd08.prod.outlook.com (10.163.102.158) by AM4PR08MB0753.eurprd08.prod.outlook.com (10.164.82.143) with Microsoft SMTP Server (TLS) id 15.1.528.16; Wed, 29 Jun 2016 00:57:59 +0000 Received: from AM1FFO11OLC002.protection.gbl (2a01:111:f400:7e00::176) by DB5PR08CA0020.outlook.office365.com (2a01:111:e400:52c3::30) with Microsoft SMTP Server (TLS) id 15.1.528.16 via Frontend Transport; Wed, 29 Jun 2016 00:58:00 +0000 Received: from nebula.arm.com (217.140.96.140) by AM1FFO11OLC002.mail.protection.outlook.com (10.174.65.77) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 29 Jun 2016 00:57:59 +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; Wed, 29 Jun 2016 01:57:56 +0100 From: Dennis Chen To: Subject: [PATCH v5 2/3] mm: memblock Add some new functions to address the mem limit issue Date: Wed, 29 Jun 2016 08:57:34 +0800 Message-ID: <1467161855-10010-2-git-send-email-dennis.chen@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467161855-10010-1-git-send-email-dennis.chen@arm.com> References: <1467161855-10010-1-git-send-email-dennis.chen@arm.com> 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)(5003940100001)(92566002)(561944003)(356003)(50986999)(575784001)(76176999)(7696003)(104016004)(7846002)(5003600100003)(246002)(26826002)(50226002)(19580395003)(86362001)(36756003)(586003)(4326007)(19580405001)(6806005)(229853001)(189998001)(106466001)(2351001)(50466002)(48376002)(33646002)(77096005)(47776003)(2950100001)(87936001)(305945005)(2906002)(110136002)(8676002)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB0753; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11OLC002; 1:qqtwHRVvBFZZlAkUiZSqLNQAbdSP+h735uVevpBUfzVhD4O7a+sKneNOICMb8F5iLpYuk3saAxlepREa9sRNiDc1my1jRWz9HBsX3P1bjLSzC6YOZH/XipaMSlEmRwASQXjM3fOzoWAkYWThzYRhZiE8MxRy0p/XFf4S7AQd+uSIetdH8mdZkvkP3mrJRW5EuWpclTug2L0JqbW9hLLmIKFHxD7jO7D89yxeNgYzdQXWDj2E2B/AxpginBmRjs5OwFv5jWmsO/uON4tIbP99fAUTW+VFK7Spx+/C0fF+NSh2/XTbUVCx68q03XBwyFPEBU6+ZddsL4VtJdVliChAzaF/swDDZ9EfNTVw7rCHfswC2JSPzgpc0TSdwRdadNje/n48lZ4Ak4DtkE2qjPIVa5RVBcie6d75uxj397zfyT2th8zcz/eFJpYy0qIcW2BY141krmsRkjfGVMlvGldJZRWDcGHDyWaKlP62+nGzyYhCSYPi29Txyb+zpzK2HmkDC3Uh/z4gNRO8q/zpPvS68cZ/eLIEDEwlJvFuMMZyp4raFHGAjFyD5+jO81K35XvVLn20QtH9MpbMEr7drQFBtUirZ0fDPYs2i3H6HMLkyREChlnrwdYsmP+QuNNNDGKai969K95FQJ/qs7fxz9M+pg== X-MS-Office365-Filtering-Correlation-Id: 072520e6-a2c8-4ed0-84cc-08d39fb86a59 X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0753; 2:RgdbKQH5ClO9z+d2nR1PwKJtDzgslr4ioQrj92DKdt8l3i0uqdqOyvz/piLM7Gzires2t1qresXjW5yyWrr2MOJlANbwKFKC4PXFuKsIVfWURfJLl1wzk3k+Dssg/i4EL0ompCp8AJYX13r1tMnc1+mBLb1m2a6WC3Tv2eANEhI+5SsurSnbZ+1OAY/yGyLH; 3:N6Bd6PEIS01aJ5JUBVJ6mu0UZVzZrtwMrkKKZN8ff++QV1Lu8Zn/havr/dveKeSPix+3fz+EwftuPadkEiADpS08zCAcv1g4YHbQJLW0IvdpJCcR+XiP1s/shM67zGRNZgiBp0cSJk2CoAQhVZDWSyX5vevTfB393WVUwH14aFBmQkxnRXYWi9qEkPwCEo6c6Cqk6QQh0Eiqlskp62M3BwnIjnvw+mqHI6HyGKNKFNxjNjWUS470a9n7tSFdWJ+VhcMeYrXtcugFSGouock2cA==; 25:HD+puNwAY6B4LSEyZKo5Xc+CCa+H7Lq05eYytBNCfJ2TlcnvSW1TKyndouhEPW5FEQ+SoXWDJD4kGh8qBW+wMIpKliWD9YNaCwmzl5qYKzBxsj9geYEaQf7xqU37N2jNPOvlNWQZ+V3gfRYbWnEnsMCNI/NybVDafa9ln/zupOqoIqzIH/VdVqbFASWsxgtdba2/Sbaos9hVeia89WyaubCrAXYhBul/HyUdRmFHdmnUsGppHfhJnhEYsWqrd0u/OVKNqN0HJD//gtLsbOMJfJ1crhWZa/QQ31KclZRqvcPhvQpkxIIF2ahkVNnL0at/1AGinCeL2ehKdHRoUyOkNv/SLlIM4yJSJUMzBq7M5+60FOoW/jwber7RHOR8GaEZwLl8vOGTPDOLwPL11QFSh2yxomf9gf1AkAUG4FVhPlE= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:AM4PR08MB0753; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0753; 31:6BLGgoZ4l0BFrnB22+wFi0yLzhW1MZig3orsn8taRGWf7nH83FdrtwK9zs4W4buohQsu1DytskyEZUshilUOGYkHLyFiBGP99wexcVTAnsRE+2ocOjldZFyEhOdOLeC5y+rsqWg4EWaBwz8u7qPRS+TPJarPeS193q0FYNPtwSS3I/LUjX0Pytz4KppNKVClWIMo4RLGjL7pxR6NShNhAQ==; 20:HtJcND3gLSCQu6+po4RkavBy2/1dKKpns8muhtSVwCSLjMR7ml5eOPKZIBpzoNruuWPuEGJ5NhqhtULGRGq10+xbWgHObZ8CeW/5jzgWuvBBukrmk26tclMroeZI5HbDkjT3MwHg+SPli3cP9wtFmt0ODgOeErJFDapOeeOR9JBofL9g/QCKTwxqucaUGOGf/QcI4dbMc0fEMoVH2d6ChAROb70V1COI53WDpB1MzZuMFcqE8BeXu6L0cgd1Klm2 NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(9452136761055)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13013025)(13020025)(13024025)(13023025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:AM4PR08MB0753; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB0753; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0753; 4:SvimZ2HXcbYBC/thaCeCJU/qaVkaamLXzQognRB6Zjftoh6EIwYaKptupufKX9ngnOh8+uWQLduIDo5x8auiVdG49jxWVX70uRMe9BXs4lH1ZlnFboIKUvKNlFa1FUHkFRB2or+n7XbbcXl/LKpQl51Kln/nOeyZDpiNbgG4s0rWHQuZwv0ieuTQIR2ge73iNba+CBPDQTzoBGmLWQJeTLsn68Zc1EvFjIhq9T8esm7ya+gum7Z7bmfNibr2RAUbf6ou+bYqmhMlfrKhrz7ZGyi7McDKXvG5RbQ4O+J054EDzOPJn0LWXpz4VBsdMbuAlrx8BJDDlMRaO57n/g4MP8qZSAFbs5c18vDl3CrQmyqoWhk3FspupcyR0wTU+nTbRIN7i1UqYV50asZX7F9kwJHYhnjYldZEKM6yowCixI2Oj0URoZdUpEJke0fWG6HZIP61IKuidveMV8iBuBGfOkHU+k89Kg26UlaM0KGCimwYTKiXQt6OqDhD7cE1WkZXtwffqzBZNkwUAGAVLSaF8YexgPD2ynXfy8brfqNi8b2WfLH/reeT5ku+0tYqUtFh X-Forefront-PRVS: 09888BC01D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB0753; 23:cTi1F6CW+gHflROkaMm2LVdu5zrRRJnJGTDvVCmNm?= =?us-ascii?Q?lnSiCRx+A0lEOP2j4AITFlKVKUl8rwENsU1KlWVDmKZsadn25i2pHPZiPo0W?= =?us-ascii?Q?TZi1Nx3hgrY4SPwlHUDq5vaGezerKY0MdxORLbGstSHJKlvkQ8s2O0/a8Opm?= =?us-ascii?Q?QZn7qYEorCM2P64JL9+RbUbGA/UbIENOtQx+RntVKDjNwpB3NAiEGxlITO2D?= =?us-ascii?Q?xnZo8ucHWzjHrF5x4SSr5c3AY6DtSlFPkf5liXggCvgs/7TigoyM8/x0+xrK?= =?us-ascii?Q?+KM9/smGbwrF269bKXqcBXr0ftrSSdTMYt0z4gS0e0qX1KBegKC3A0eoNHHs?= =?us-ascii?Q?gqR/u/E8NWW74B/LyOZjMv302bhS0NaLoB8nois9Y0s81Xrq8CSaLQhGMgWl?= =?us-ascii?Q?Fg7TpXQqYIKElcHRW3dlmQt3DulEhfAtbvP2Dc7kLyONbAy6O5Kq4RZjeOz+?= =?us-ascii?Q?dMF9PU1Ig6h/41GYsbaN1S3glQqU3UAleRSaDqBW2w075TJ6MHD1CbA+v5Ao?= =?us-ascii?Q?+wkvmQjfuDsHsxvHAVezfzaP88R2gjxbIjHU/5qNeaXsqxLg3P9oNqv9KCXT?= =?us-ascii?Q?JfN1aeaAhgNZTyd77qKwHb9HICrMwcbTuUGGhh1NzWv8T+ZvhIwKcrnSNfJV?= =?us-ascii?Q?/wxh3TcuAG3gxzHO+oFv/jZm62ZlOG/xdLmeIrmLvQTpDe9QaH4hAMpwwXMI?= =?us-ascii?Q?957FJUBUTyvgkCktcxYHLU/axnKCamjC9pX5ttaio3V5LtSRqxndQJ6eijat?= =?us-ascii?Q?/zROVoDrsC26LuAAN2xjJamD2K4xcpLAwZkybtQG5wERg0niNvgE1pfgAvmk?= =?us-ascii?Q?GR3r9V2a3QaxL9nyGLbt768p+dIS/G6ebCq+eW9IenP0wrKUNZR+itExEL84?= =?us-ascii?Q?S1mOHG/21Ws7rwMca7b4K8IQ4DSrx+iyIGmTC6yTusw1Bdvai7hW9X9jMDlb?= =?us-ascii?Q?v0V1fu/IVHfGnsHwLyGBWuhE76HZ6T6xvaMBVUdjJfdHx7m6txkUek9l3p2C?= =?us-ascii?Q?pNgY0uTY8+FrFkUKX61XvcIWp3nRCKBS3NcQ5Z3SDqNTKanUbYlOuYvkLsvu?= =?us-ascii?Q?ZU2OxJBsySz03Xjb5aZLSWbd79B?= X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0753; 6:vxNcvGuhubivOlc3MQ2Oa0RRtUPTQhAO6NmrEHELRHTUhGWsLWdknYFCLgk+CXYsFiTmGIaMvQe/5iLZ5kkqvRs45W6LxAqucLpXaptcRjmTO3KL7idlsuf+bt9Aaz8lLS2Gd9R/fDzEZ2AHcT5vskbnJiQp6En18B+kK27e7kHnpffIDAyJKVrLuy61tClunsMpr/3cZ4JTBlN1Ii00qRoikInLkCLqrE+Q92QBS73QkHMvuE3HoWU1fTU2GuRzIIKHWdogvgwlIhkMTMe9lFmNEA0a9hEpXoB1xHXks0UJrIkBQPHL+uJIBmUXQaHhoDYp2Sf3WrWKFw47uTX7tg==; 5:/1TykN3xLt+GlLx2uMRMndBzayOH1A3UFiNma1rHhWCkpIp5JjnHQ2jayge2YyNaT4cNlddb9Vj4MBeTqWLijdhq7Hxe1pVD2ZwXvHb9XNkQlrY4tw3v/cQ4lRwn7kVyLvxbze5+jzIxCDDzW7BhYw==; 24:PDaIj258UkYbtT6B+4lEHTDcpf/XNlYfuTM7WW7aAxGTiRrwW98ibn+t1EzlcUg00tVb+28B/nb2yl0gAlwdNhBGgLGMeStBarthx5umgjc=; 7:hufpcVPsavm35LxU9NeJmPiTeXlpJatGKBBFVHMlwTOCLElnFzoZUEb2CnQIaTDIaD7yJfsmqO3S9poAX2CU3sYhZEsEYjPBxPPjZAMahSN9heVNOvpBOIJYh1aj8CJErxgto55GJDW4adL01XNDabxp38zzN3H0Hn7z7oGzrCOMRCLNFp423+ZmtLlVgOLCrh4jVLzkrVFdfJ2EwvqYvdBtaHXjSACrQCYJfINjEwYEYtrjQvg0afBflKJWlVNX SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0753; 20:ue1GvfEkOpkMKOLUBEdYb27Je+kiddNFjmxJ6Jy/YObnkzTrCa+Y1z7uoRpohXyBDVRgB1z0GmKhxsZMLEMQLrP4oIn3ERfaskWeuIJvgvTsDQ6KtPkbknPar6/cwHsvqgcWZcE5a0PckpMopX6s5N0a6P/Lq4nXReVEayC4O0I= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2016 00:57:59.3926 (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: AM4PR08MB0753 X-MC-Unique: QFc-4xYBMtGHyZuqNpMcvg-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160628_175826_835383_8B83FDEE X-CRM114-Status: GOOD ( 12.82 ) 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 , "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, Ard Biesheuvel , Matt Fleming , Catalin Marinas , Steve Capper , Will Deacon , linux-mm@kvack.org, linux-efi@vger.kernel.org, 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 In some cases, memblock is queried to determine whether a physical address corresponds to memory present in a system even if unused by the OS for the linear mapping, highmem, etc. For example, the ACPI core needs this information to determine which attributes to use when mapping ACPI regions. Use of incorrect memory types can result in faults, data corruption, or other issues. Removing memory with memblock_enforce_memory_limit throws away this information, and so a kernel booted with 'mem=' may suffers from the issues described above. To avoid this, we need to kept those nomap regions instead of removing all above limit, which preserves the information we need while preventing other use of the regions. This patch adds new insfrastructure to keep all nomap memblock regions while removing others, to cater for this. Signed-off-by: Dennis Chen Cc: Catalin Marinas Cc: Steve Capper Cc: Ard Biesheuvel Cc: Will Deacon Cc: Mark Rutland Cc: Rafael J. Wysocki Cc: Matt Fleming Cc: linux-mm@kvack.org Cc: linux-acpi@vger.kernel.org Cc: linux-efi@vger.kernel.org --- Change history v4->v5: Fix a build warning v3->v4: Incorporate some review comments from Mark Rutland. v2->v3: Only keep the NOMAP regions above limit while removing all others according to the proposal from Ard's v1->v2: Flag all regions above the limit as NOMAP per Mark's suggestion include/linux/memblock.h | 1 + mm/memblock.c | 53 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 6c14b61..2925da2 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -332,6 +332,7 @@ phys_addr_t memblock_mem_size(unsigned long limit_pfn); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); +void memblock_mem_limit_remove_map(phys_addr_t limit); bool memblock_is_memory(phys_addr_t addr); int memblock_is_map_memory(phys_addr_t addr); int memblock_is_region_memory(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 0fc0fa1..050ad0c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1465,15 +1465,16 @@ phys_addr_t __init_memblock memblock_end_of_DRAM(void) return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size); } -void __init memblock_enforce_memory_limit(phys_addr_t limit) +static phys_addr_t __init_memblock __find_max_addr(phys_addr_t limit) { phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX; struct memblock_region *r; - if (!limit) - return; - - /* find out max address */ + /* + * translate the memory @limit size into the max address within one of + * the memory memblock regions, if the @limit exceeds the total size + * of those regions, max_addr will keep original value ULLONG_MAX + */ for_each_memblock(memory, r) { if (limit <= r->size) { max_addr = r->base + limit; @@ -1482,6 +1483,22 @@ void __init memblock_enforce_memory_limit(phys_addr_t limit) limit -= r->size; } + return max_addr; +} + +void __init memblock_enforce_memory_limit(phys_addr_t limit) +{ + phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX; + + if (!limit) + return; + + max_addr = __find_max_addr(limit); + + /* @limit exceeds the total size of the memory, do nothing */ + if (max_addr == (phys_addr_t)ULLONG_MAX) + return; + /* truncate both memory and reserved regions */ memblock_remove_range(&memblock.memory, max_addr, (phys_addr_t)ULLONG_MAX); @@ -1489,6 +1506,32 @@ void __init memblock_enforce_memory_limit(phys_addr_t limit) (phys_addr_t)ULLONG_MAX); } +void __init memblock_mem_limit_remove_map(phys_addr_t limit) +{ + struct memblock_type *type = &memblock.memory; + phys_addr_t max_addr; + int i, ret, start_rgn, end_rgn; + + if (!limit) + return; + + max_addr = __find_max_addr(limit); + + /* @limit exceeds the total size of the memory, do nothing */ + if (max_addr == (phys_addr_t)ULLONG_MAX) + return; + + ret = memblock_isolate_range(type, max_addr, (phys_addr_t)ULLONG_MAX, + &start_rgn, &end_rgn); + if (ret) + return; + + for (i = end_rgn - 1; i >= start_rgn; i--) { + if (!memblock_is_nomap(&type->regions[i])) + memblock_remove_region(type, i); + } +} + static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) { unsigned int left = 0, right = type->cnt;