From patchwork Tue Jan 23 14:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527538 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 B8100C47DDB for ; Tue, 23 Jan 2024 14:55:23 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WdI8k8hKDivzltfr1ccwLnVa+5zkxzIH+q4rfbp2tI8=; b=PD2+T7JyG2P2cP0g9PjWjabNOJ QSbSDoyIVSzyMg6Q5S0lXBPGcz3F5DmLmC9pf380hFppp2kLYNBFLEg1Oblq8g9YVU8sE+elCb9BC gtWlKUccrVtf3y3Wp9ZDKtcZG1noVeT8mOV73lW3mJL2zGQFvoV/4tsQOSP7exwell9f78RYYXhyT 8q9GwNegTVKurvFDQ2q7EFLXec3dAGrOo+93DVfwGvN2kbdjk5SvxLEnZGZC1Xdpndm+TclU05h3Q u8Qarzr97gTzMGhMZ/PmfzVdRbiJMMF4RWH+WbaX+sYkCcF1ntC1nPdbjWu+K8Ygwlj4arADTzN92 gKVAzP2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSIAt-00Gtl5-2D; Tue, 23 Jan 2024 14:54:51 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIAf-00Gtef-2R for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:54:39 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-40e412c1e65so38557125e9.2 for ; Tue, 23 Jan 2024 06:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021675; x=1706626475; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5NlMdZIB9itIIAJFmR4aXI2QYcCN1XpZu8tjp+LjBQw=; b=qI7g39O8FVNLXGaAxedSF4uoyC3w+JYT2bUaUn9v1uyM0BrpytSNoE/4xZ/W7aCLco Fa5ruvtDIqacFFQsWdk5XeIRvcH0fbooACLYVV3cWMAPFSHoHrW4GPT0D/bXugt0Q4a7 1eKIauJ0iYG+HMte7KNwaMgMxwAZp2RJK0R6J13+XpEhA1eJtX9Wn+tSJOHsryYY2HUN BxDqxaT3SYPOa24bzyz5853oc6AWYCjQr2zDgGt84lrgvmwcQfPSzgUzjZFYxVZOu8Ef aJOq4Qqk2jvwdCrmpiknnRGHECSP2yLAmtPXPsuMZ/7rVlepdR52QLKrKqOE80uV4lkW pxlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021675; x=1706626475; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5NlMdZIB9itIIAJFmR4aXI2QYcCN1XpZu8tjp+LjBQw=; b=ZHNTrSZEXIx7IInq3bYCTbGJZoZZpX/SxkgTcE0yVU1B3DA3k2pGAvNLkvq0Omy0Ho iOyup63bqJL1tqbcNI5EAL4K4EXsd6gOf6oqrMdgIOsqmY9GJb44ezk3JT+b52X5/8w2 G0L/roPisBqjCzY0aGE29Baflys5WaToo2DjHzSO0clf21vegLIJ4qqhLio799M8UDo0 79Pr/+clOdJWJyLUSvXNS8v9N+br2tF3qCyGToarDLnqfJN3nVU/Ew8OWvbUUwTIGskp MfQ/SPefPS5u+uioBnGE8beXNnYRAdIlWEV+ae4EpLLNqiVsI/ptgjSu5huOTgD1M63Q Lt0w== X-Gm-Message-State: AOJu0Yzl0UBYCB3Ono8cgKmFHI4vAbo5irregMGP+262lNJ4ZmI9snki LIZSmK0NLpbtch59jqdiix73CfccnD/4exqubJuzn98n0BNRRXdX6hihfkygDH6IxbxW4oXdWbI eSNCliqWj+YNSCEdJtotRRu79RfKO9wK1zG/7kNYnJ+KDPHZcmj0PIKrQGTpqCtxdONCtHOKAjA 4qACuZx8xGZv715p473T3XpWGUuBW1v68TtgVCWFeu X-Google-Smtp-Source: AGHT+IE0mz02C+Ivqu8wGhKB2y2ML4VtaCHrQb1w9vnhEFZpeYhuM5KdysIxEKgjg0bqqNIKz/CAJzIj X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:519b:b0:40d:5b86:5fee with SMTP id fa27-20020a05600c519b00b0040d5b865feemr11315wmb.3.1706021675261; Tue, 23 Jan 2024 06:54:35 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:05 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1837; i=ardb@kernel.org; h=from:subject; bh=/dnFr10N9WRRkLMCwbVhnPYzrkgM/mTgegkcttUfcHM=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pYv/7p+tbYr5zr3D8ZDlnZQOg4nrO/78TWD/efzy5 bOB0W0tHaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAivxoY/sro2705dl3y0UWT QOGKVXN87/U47yx78neVZnfYo3uK/7IZGXbYZ2UJZXHkivevZthd4nkg7f7S4E1p369v8e7/M/F zHg8A X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-58-ardb+git@google.com> Subject: [PATCH v7 06/50] arm64: mm: Reclaim unused vmemmap region for vmalloc use From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_065437_794023_9C110483 X-CRM114-Status: GOOD ( 14.92 ) 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 From: Ard Biesheuvel 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. Acked-by: Mark Rutland 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 2aa2e3c961d7..522c21348ae8 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))