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: 13163664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1AF7C678D4 for ; Tue, 7 Mar 2023 14:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3wh8KsHLOeaUOTBW37bfjgGjrOtGWSQI8xUNTsDiiX0=; b=2MMmLjCIkmL5LA Um3lbVOMgTUj3TGYQE0z7rrF8/SZ69kHhS6+Py8bO4ap27nLULhe0l1yfxsv5PnWQBDf9zEHIcQkz YPLnKJxLc4YjG8mSefchEBDgKG0LSswpozb7LZx4aHvPGXM+9LkQvaWgtjeESSR7n3vrljmp0bSwr FvSOtSk8n5aKdvPF78xpkQja3u8ONZWtDrY28nlZSOSco/lL0Qu70WRlzjp1AIQ4DJVac7q85VxYB 1Yd/cS/V0ELEwwM8r5rEKM0Itj+pVnVq0uTgRfRUR5W5yQEl+wfMd04UarMEGr9zrECd78GsY9Ah0 1HrtrRyIa471S5/HsD4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZYAl-000jcP-B2; Tue, 07 Mar 2023 14:20:11 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXy0-000dwC-ID for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 14:07:02 +0000 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 dfw.source.kernel.org (Postfix) with ESMTPS id 2573C61454; Tue, 7 Mar 2023 14:07:00 +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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_060700_667756_BF8CA356 X-CRM114-Status: GOOD ( 16.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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))