From patchwork Tue Jun 28 09:45:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Chen X-Patchwork-Id: 9202425 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 7C8EE60757 for ; Tue, 28 Jun 2016 09:48:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BC82285E6 for ; Tue, 28 Jun 2016 09:48:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6086C28600; Tue, 28 Jun 2016 09:48:30 +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 E5997285E6 for ; Tue, 28 Jun 2016 09:48:29 +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 1bHpbb-0001JQ-NB; Tue, 28 Jun 2016 09:46:55 +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 1bHpbY-00016N-3x for linux-arm-kernel@lists.infradead.org; Tue, 28 Jun 2016 09:46:53 +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=UDHFGFzuBFJ5tkUvR7fxR7QKjmYaR/Jv1UleUJlKZvY=; b=J5i4xzNA+rXYauGZ0qu5EUwYcpZSjGqxZn3MB0R10ynsL+v7nH/R5jlGt8qmDZYXF3CJy0V+5ad1tIxktUIDjKKhzC6vlVyfeG0pc0ppj2FeW8PhDdHph7krblGOiwhxckrQPxorRq7UIbIfsQbtKdsFjLcJi7FKrSyXZR0/6yU= Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1lrp0020.outbound.protection.outlook.com [213.199.154.20]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-51-03Io_vyGOiOek1goGeWW4w-1; Tue, 28 Jun 2016 10:46:26 +0100 Received: from HE1PR08CA0039.eurprd08.prod.outlook.com (10.161.112.49) by VI1PR08MB0768.eurprd08.prod.outlook.com (10.164.93.18) with Microsoft SMTP Server (TLS) id 15.1.523.12; Tue, 28 Jun 2016 09:46:25 +0000 Received: from DB3FFO11FD036.protection.gbl (2a01:111:f400:7e04::180) by HE1PR08CA0039.outlook.office365.com (2a01:111:e400:5097::49) with Microsoft SMTP Server (TLS) id 15.1.528.16 via Frontend Transport; Tue, 28 Jun 2016 09:46:25 +0000 Received: from nebula.arm.com (217.140.96.140) by DB3FFO11FD036.mail.protection.outlook.com (10.47.217.67) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Tue, 28 Jun 2016 09:46:24 +0000 Received: from dennis-ws.asiapac.arm.com (10.1.2.79) by mail.arm.com (10.1.106.66) with Microsoft SMTP Server id 14.3.294.0; Tue, 28 Jun 2016 10:46:10 +0100 From: Dennis Chen To: Subject: [PATCH v4 2/3] mm: memblock Add some new functions to address the mem limit issue Date: Tue, 28 Jun 2016 17:45:36 +0800 Message-ID: <1467107137-29631-2-git-send-email-dennis.chen@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467107137-29631-1-git-send-email-dennis.chen@arm.com> References: <1467107137-29631-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)(189002)(199003)(189998001)(8936002)(50226002)(26826002)(561944003)(77096005)(36756003)(92566002)(7846002)(5003600100003)(76176999)(2950100001)(4326007)(305945005)(586003)(50986999)(19580405001)(7696003)(356003)(110136002)(48376002)(87936001)(246002)(2351001)(229853001)(104016004)(575784001)(86362001)(47776003)(6806005)(11100500001)(5003940100001)(19580395003)(8676002)(2906002)(106466001)(50466002)(33646002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB0768; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD036; 1:19DwrfPDgoPhYSKAMvq0bmIBMG4KbCVa/0JLZxp3sv5qKnGGoH7UEKGjyWnamvodC8swro4G7dCgH8hrZtkg6e2Z2jVRtc2iUqsWfCuxQgO46pn8RPTD2vWuDsGpsIHaHNyQcbCHTUuL4PxHxUTQ5dtt1sJcLOdH8RxrfjpKfJkDwiMU3rzeC0dGb8GgoNOrP7dFhSPA5af7L9zWBQ7YiUljiEubiNwy8hm91FH2mKHkMDBQ52RBVE1RHuZznzCNQRT6NKHDirLwRiIRSg8sX2+yqaT4mKMoa4GKPjSmEEHatjtCbX9c7+QUkPH9wPB+hPJibd5/54xzxGGGYEn+796baKUu4YW9Ys0VMbfroseDf63QkQMx57sUTl6/0cEiaaOKQYJi8QehyDIX66IweAJc3VI7+GT8uInny0hBHfYEyRPZpYgi0vI2W2+NEiDonDewrBO38YMxhSffi61j6+ufCEQsXQxesgtaAZe7MdO4n4ImomQUDMhEy6EfLvdPZnWc7jhuAXRVwVph3BSUiXHk+2tjmMhE+xWMOiLUTXTFQYXVqPvKOvjZNrb03Dlmc++426sPPyZrBLbayG6864IbrWAShm2MChKjK5Rxx+QWG+dIknqsGy+KymiFL0rIRPS0tg2jpfoRotLpgu7Hug== X-MS-Office365-Filtering-Correlation-Id: d6119a8e-2193-4b75-8623-08d39f39119d X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0768; 2:XkskeEUYUQ9N45+633rDNA0LBikW8ac1HyJJBqUD/FmvljY0AymZPAC6Ki60s++nXk53hELw8dZcGfX+xmC8xt9GosUhU4gq23HN5wvGEcdJl2DiE747gi38jqnsOjS6VmRpMCa/yUpkI3qqEMlclswxsoiIHGZXldB/3npmd0N85x8vUneJa+FCnVTxUVPl; 3:ioJ9cZ6MGmZHG5RyFX7ClWZ9qo+HUwGE/vaW4wgMx3sY5hkG+WMsFl8T5NnTyYGDUvOJ/1C0vK5pj3zcR6jlofNnrhRFScAxxQ7iCoEZOGPuQq35zQLIlVTZPQdwjRskNno65vDMdEBgSd3QbbAQcDCL+B3XQ5iwkWX22Czwn8OP7K6E7lZzADT/RnXGMy5CCstFdUqSZRiiXvbpKC0DitfRgAzLf5Y7Aqs+R7XdpAPmE4STNSZywPQZy0PgN/CKII4bqS+Rah74upYU2kQE8w== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:VI1PR08MB0768; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0768; 25:O9cAEfbzhjROECr7jG9DayjGWrJnVhT3pJVbQ3nSSB5mYjQxjgLVORFGl/QX+O+ZANUwgH8mmvMgaKVGRRCKxKFlEB1tavZkNLXYrm+dLrn2w56RBDtdTFPApH+dYAVyBbGHXdKGT8c2qdYDzzvTYe2RTYRFGRNwYWtJ0hHMIjZCpRTacz+ogGInJfOakkk0EE8uXkE70yYvoiSYqhfuA/Q9l0o8f0I3r/7R1RwO1R9WV/TvE8Yi6AJwDOMlKDaHofM25F6pr3/dzkjhtwsdj66495HzABVMVfOV8EfzM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ifEMNN0jbsA4inN0ZA1O0BCJyTSS8QrYNQ8fE1ejh5uOz4WBBNQN2edNjarFbUJ9HKY9v7dSuI8pAn4cJ4hUKnLKm8NqaKiBcff6LmZLkQ6bWkb6y+ZsNGwXrdFNu6M/q4MR4PyzLWFPyIM3J3u5jMfV0/0Qr6vo6Qj/aDMrNheFLv1pP7rCVov8DNwuHzIgDVLOBgsfbnYOb2PQnlgRKbjXQFftsZyvxTLjh4XV6sH370kQ1gEBZCgYEnRkawdIJYUYpKEQ5qHC+JVPYavTf+mUvaPFpEWuc3GK+cd5Rlrhcfce6q3M0aQCj6DwwYvF 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)(5005006)(8121501046)(13020025)(13013025)(13024025)(13023025)(3002001)(10201501046)(6055026); SRVR:VI1PR08MB0768; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB0768; X-Forefront-PRVS: 0987ACA2E2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0768; 23:VHQoxvJq7JSwL+PT0OkSnQRA98w54Py3zT7MKxLBw?= =?us-ascii?Q?VACW9IN4Hmvps9EgoGazpFQIqlKF48bzdtuvzWvXOWbdXz5tAsoINw2F+zHC?= =?us-ascii?Q?hRO+mVzSRwdRi9xc87/eoHo8g+meA3Q1ohjXr0/vbB8h82wL7O47QwIOm1iP?= =?us-ascii?Q?Hk+55SwBGkeno7lgGPyFqaeOcaeRdumEiuwxPhNr7VfLM4JzFz5fsyijPdTo?= =?us-ascii?Q?XVh1bb5zGahlNAK+GTTBvsGiUild7Ht3geVMZTbh3yd0CKn7GEZ2eCEZfb9h?= =?us-ascii?Q?qO7krNedrRZkhs0lTNgVCR3cTrTod2oF3GlzpsJBf/loKvIHoTrKtKmN3TH4?= =?us-ascii?Q?ZoeeqAUjKxwgwxZG+NtzZk/tOaY6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-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2016 09:46:24.4364 (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: VI1PR08MB0768 X-MC-Unique: 03Io_vyGOiOek1goGeWW4w-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160628_024652_562390_30DA6160 X-CRM114-Status: GOOD ( 12.80 ) 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 kept 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 v1->v2: Mark all regions above the limit as NOMAP per Mark's suggestion v2->v3: Only keep the NOMAP regions above limit while removing all ohters according to the proposal from Ard's v3->v4: Incorporate some review comments from Mark Rutland. include/linux/memblock.h | 1 + mm/memblock.c | 54 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 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..993f597 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,23 @@ 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; + struct memblock_region *r; + + 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 +1507,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;