From patchwork Tue Mar 7 14:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2450585wrd; Tue, 7 Mar 2023 06:10:23 -0800 (PST) X-Google-Smtp-Source: AK7set+gqyfTcsIZckmBVwQj25mVMiju+gyQdt+rP2bQDEkTAdWcGM4CR53YjBc83y4TfTUgQFhh X-Received: by 2002:a17:906:1411:b0:8b1:779c:a8ac with SMTP id p17-20020a170906141100b008b1779ca8acmr14953599ejc.13.1678198223196; Tue, 07 Mar 2023 06:10:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678198223; cv=none; d=google.com; s=arc-20160816; b=tbJWyuF+Ma0bxMQK4cADWpzAIwdIy90+wkh17XhWEQadJ7EVRLEb785WT5kpDWcR4i ahYxDdv/UeGVswjQp3bpvOvh/gAbG5A5le19pLWBqzJdNFKJDNwJAijbZP4MWNgUsvs3 +5r/u+ZynzJ3Q/jIazxxVZBYd00s+8cp2sq2+kMnKjkew+fClnZmib2unmfLp/PADGaX NrLYYQT2EJgQ58uY2v0xxVpMGH1CRXxUA6stm6ZVKvOvapkIEIRVLStjfBJAiOaYF8Jq EwWR3tCPl/UOOzY5foo3im7ULWlt6768EIycBuazQWco+FGHtorHHmhPOVVdzp/LgI7e C5PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tG/8Up7uDhGaX1REo+kH96G78ruHi3AJ9Ail60wmBio=; b=YEkJR/jEhRmgo78X4PuDdyzv3FRc55otkAGVYXH08MzPjb4a0fqnxKVmevjidRoXjf ZMvCuAUBsVRWGRxnKS03ZXf0xmQEK0pcfw2hCezeKw8JnJnDvg7kb46rCud6S2lPZgWU bjmE72UHweq2E42gf0Vp8Vg6M2nh6UE21UHaaj6bM8alAgQaX0R0FlhXTTpkBdFsAEIZ Si70takuc9cHMUF011kIv3tc5moMo14OwGZso3lUxAzjv9pghsYS+fSweVGB6DZolzrX r3xnTfB12qSIsUP4wW/MYT8SSOXbVwjHG5gpizgoVpHEmxEraxbShZbbYnQQ7fQJVXmR RzNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="dmh/0+WL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a056402065000b004c4f980447bsi13963119edx.554.2023.03.07.06.09.53; Tue, 07 Mar 2023 06:10:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="dmh/0+WL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbjCGOH6 (ORCPT + 99 others); Tue, 7 Mar 2023 09:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjCGOH2 (ORCPT ); Tue, 7 Mar 2023 09:07:28 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B4D785B32 for ; Tue, 7 Mar 2023 06:07:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id C1D97CE1BDB for ; Tue, 7 Mar 2023 14:07:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F367EC433A4; Tue, 7 Mar 2023 14:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198020; bh=Z0j9wObyTVXTZrQkvIz4QQhYFAAbwmqHXOPjNCPpS40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dmh/0+WLWyZKE1AZ3RFWsVNPhgKp5N7kvnG6UXYFoRSwV742n6zU5hHla6sYel8b8 gelii+DvPq3+paT6Q8VQpr+1MSznAYJVO+H7ewASUZC36Uj3UvEP7totQL9gEYlkUd nkXfyque6u9vmwh4N65YehGqBPLgrLSlovO5XKvglPPlGyjzUFVy6/x/37Mc40jx+3 v846mKqopwhcSJm6xWrdnZMQmYZFQ9kdYn+kvst5kBLKb9C+ncfkHBEjHEZDbqEE6u /NDV7UJF0Dvris3SEjHM3WMXfNv6tAxPZPZ2ZkA4x3XVCQaqfW2AqHZpASMt+E+isr FTwy4IHFKhl+g== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: [PATCH v3 09/60] arm64: mm: Reclaim unused vmemmap region for vmalloc use Date: Tue, 7 Mar 2023 15:04:31 +0100 Message-Id: <20230307140522.2311461-10-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1777; i=ardb@kernel.org; h=from:subject; bh=Z0j9wObyTVXTZrQkvIz4QQhYFAAbwmqHXOPjNCPpS40=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdRcCqS6Dq49uTy+6v12D4px0bKZe08mLAWU8/5j8OC cuv8jh0lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIksFmBkeHaolWfTxmUGO+cd 7IjIXa8+J3uSbt/t8G/LL7Z2sP77NJuR4fedH2YyrWsUV6+7uqPwdlK95S7N0p3zL53T3LZ9Ybj JBXYA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759718379840940144?= X-GMAIL-MSGID: =?utf-8?q?1759718379840940144?= The vmemmap array is statically sized based on the maximum supported size of the virtual address space, but it is located inside the upper VA region, which is statically sized based on the *minimum* supported size of the VA space. This doesn't matter much when using 64k pages, which is the only configuration that currently supports 52-bit virtual addressing. However, upcoming LPA2 support will change this picture somewhat, as in that case, the vmemmap array will take up more than 25% of the upper VA region when using 4k pages. Given that most of this space is never used when running on a system that does not support 52-bit virtual addressing, let's reclaim the unused vmemmap area in that case. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/pgtable.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 3eff06c5d0eb73c7..2259898e8c3d990a 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -18,11 +18,15 @@ * VMALLOC range. * * VMALLOC_START: beginning of the kernel vmalloc space - * VMALLOC_END: extends to the available space below vmemmap, PCI I/O space - * and fixed mappings + * VMALLOC_END: extends to the available space below vmemmap */ #define VMALLOC_START (MODULES_END) +#if VA_BITS == VA_BITS_MIN #define VMALLOC_END (VMEMMAP_START - SZ_8M) +#else +#define VMEMMAP_UNUSED_NPAGES ((_PAGE_OFFSET(vabits_actual) - PAGE_OFFSET) >> PAGE_SHIFT) +#define VMALLOC_END (VMEMMAP_START + VMEMMAP_UNUSED_NPAGES * sizeof(struct page) - SZ_8M) +#endif #define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT))