From patchwork Wed Oct 30 10:18: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: 13856236 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 6B23FD5CC88 for ; Wed, 30 Oct 2024 10:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GCB5nfE7CGuNRBvDe++G1u/AhX4jCAZ21H5NNpZdneM=; b=3SBZysseEtyfM1aQ2OZcPDSA/k Un64OMeSPbKz9H0KppHsIuRAw2nYUPkwkesCwWsx8eP4FTjbeFBJJexrVe/esBr3HsCq3OgorhPuV fEVUiqDMNhB0tKsuBuYdqFiHDU4z1LBW/kOGgM/DrJ6KecKzut16NCzU40Z41n8a64q1PRI2BNz8z AguVpOnnLpX3GYnAga9A2vufBvpO38W0ZyGDfDTWc2k3kJ02X7fWCWqGdD3U4OjAs9wZ5056xardF 5IdOKbKtoZ6+qgCJIuayUPIYS2jXCUuElwLVX0SDemev8M/VNjIcsehdav6w2k8kggXjxZj3J3m2g kuc/f1tQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65pn-0000000HXFH-2rTC; Wed, 30 Oct 2024 10:21:51 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mY-0000000HWVv-35fp for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:32 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-37d45de8bbfso4454273f8f.3 for ; Wed, 30 Oct 2024 03:18:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283508; x=1730888308; 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=GCB5nfE7CGuNRBvDe++G1u/AhX4jCAZ21H5NNpZdneM=; b=RSqTO9aaT8Ie6CzSmOudHt6BniXqmXNyMbiU1J43DoQ9JAp7H+llDM0/qeWuvg12Ae OHQm20wdiHsEMSiATSkv4EGrzsGDNN8/yJQEE1U10j1DiFuhzQ6o+HQ8N6Np0JLzpU3o FJOIB9B7bJ24R6HwIZEWe3KDS6KDNr5i8wVTN2CoRRqu1afhnLXz8C0+WWBTp65ZnlFm ePpn/umPUXmMRdeBtTkuu4gAPhYiPKaFa80h3mdE2FqKAiEwnyn1pGht4xn1nungqYFB WlXAtgutfQdLK68pU+CixWYaUSgKtyY+a0FjWvjpcvqaKZ7IokeCOpUZcQ2In1ctuc3L BIEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283508; x=1730888308; 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=GCB5nfE7CGuNRBvDe++G1u/AhX4jCAZ21H5NNpZdneM=; b=tR1Ya1PfUT+6NCANOZyhZZS1P4Gb+SgMT2gmKYqzYyTtOv3sMn6z6rV6c9dHi846Y/ 8kXi9q35Ts4qAbr7LsjrEQm/5OanWEglVcc5rvLcE1XYbRw1knrVUkeGoqY+R1r984E8 yGbUXy1HNolg6KdBOGywZBXrQLzREOWWBYLH+gVsDlwsEPP2Au5TuWuQvGBJMIc0qWOI W1WrZefnTnAdROKCdQ6M4m1LNt2EhZHBwcJbTfi1dbOk3S1bOprRKgbwfSRCjFdpngA1 AgfKEu91Rl77is54LEnjdebdgT0UpM0svtldNZknSQ+FLDODnR127D2U35NTjmPNgAb8 zK+A== X-Gm-Message-State: AOJu0YxSPCi4JCF6nRzLp7D6xYZIqrz/NZ8Z8/XeaVK1ks3ra73QUJMO yYGHvqfCXJGH/M5DZTw+BvuA99KqQGcheuYA66GJIMnZr23sheARQixkqqmF+9o6QIkb1dq/9oP GKfk5cOFPAw3eesfcRSIxm83BrhR9SJv8z3s8JUyUbF2Crk5+E7oEdwuKepnkkwMOYtqJdlOFYX NZjJu+GXSqRiBY9kmLYEcSd1PHaRy+uUbyRstK8U/4 X-Google-Smtp-Source: AGHT+IH4tMMcP9ENuBVAD8pIlbbZTGfAbTgfXdsdcBy01t2vMHHwycPrtUm3l2DZ83XxryT9zDG5yMKk X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:adf:f551:0:b0:37c:d162:8289 with SMTP id ffacd0b85a97d-380612281c3mr9870f8f.10.1730283508476; Wed, 30 Oct 2024 03:18:28 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:05 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2688; i=ardb@kernel.org; h=from:subject; bh=VuHW66kh3SrzeofrGytIHYJsJQA3k3osacidUqjC91c=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/W7XOsuH/Kd2h5y8J60kczJ8TXYDx74Jz/etkPzYa Mjj5WvRUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYS94fhr+iqt7mP91+MuW97 Omn+Hc536Vmsa2W7Jv1IfWp0kMN6cgQjw67VgjcvcT2quZ2S0enprazpknZsq/5FwzgVId25cSk l/AA= X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-11-ardb+git@google.com> Subject: [RFC PATCH 1/8] arm64: Kconfig: force ARM64_PAN=y when enabling TTBR0 sw PAN From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031830_803976_906F615C X-CRM114-Status: GOOD ( 13.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 We have a couple of instances of Kconfig constraints where PAN must be enabled too if TTBR0 sw PAN is enabled, primarily to avoid dealing with the modified TTBR0_EL1 sysreg format that is used when 52-bit physical addressing and/or CnP are enabled (support for either implies support for hardware PAN as well, which will supersede PAN emulation if both are available) Let's simplify this, and always enable ARM64_PAN when enabling TTBR0 sw PAN. This decouples the PAN configuration from the VA size selection, permitting us to simplify the latter in subsequent patches. (Note that PAN and TTBR0 sw PAN can still be disabled after this patch, but not independently) To avoid a convoluted circular Kconfig dependency involving KCSAN, make ARM64_MTE select ARM64_PAN too, instead of depending on it. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 232dcade2783..ec218ef22f2b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1368,7 +1368,6 @@ config ARM64_VA_BITS_48 config ARM64_VA_BITS_52 bool "52-bit" - depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN help Enable 52-bit virtual addressing for userspace when explicitly requested via a hint to mmap(). The kernel will also use 52-bit @@ -1420,7 +1419,6 @@ config ARM64_PA_BITS_48 config ARM64_PA_BITS_52 bool "52-bit" depends on ARM64_64K_PAGES || ARM64_VA_BITS_52 - depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN help Enable support for a 52-bit physical address space, introduced as part of the ARMv8.2-LPA extension. @@ -1667,6 +1665,7 @@ config RODATA_FULL_DEFAULT_ENABLED config ARM64_SW_TTBR0_PAN bool "Emulate Privileged Access Never using TTBR0_EL1 switching" depends on !KCSAN + select ARM64_PAN help Enabling this option prevents the kernel from accessing user-space memory directly by pointing TTBR0_EL1 to a reserved @@ -1923,7 +1922,6 @@ config ARM64_RAS_EXTN config ARM64_CNP bool "Enable support for Common Not Private (CNP) translations" default y - depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN help Common Not Private (CNP) allows translation table entries to be shared between different PEs in the same inner shareable @@ -2118,7 +2116,7 @@ config ARM64_MTE depends on AS_HAS_ARMV8_5 depends on AS_HAS_LSE_ATOMICS # Required for tag checking in the uaccess routines - depends on ARM64_PAN + select ARM64_PAN select ARCH_HAS_SUBPAGE_FAULTS select ARCH_USES_HIGH_VMA_FLAGS select ARCH_USES_PG_ARCH_2 From patchwork Wed Oct 30 10:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856238 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 8DD5DD5CC87 for ; Wed, 30 Oct 2024 10:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Bt+GDj8bSCsrOuFvhauMB0QKz25eKh57Bb5+kpwY7Gc=; b=U4uBCXrUGjJYh1n4CVT/UQWQih kcDle94sznlOQFYv0IcwGlzMZQP7qy+3zAdnKvNQGIgBacU3I0oNmYTW3S6qFhr8a6xRt50XFVzZK DfIZcy9QOmp9Gy7rtYkW0B62rgHQNbIaQsMhoduIA4qu8bNFjZFdtFQkqmPw1Xe/j47p+nh2wj0Q+ psBcOXCyihVtG60KSGyfJmRlPspvW8yYYh4RR9kLZuSHpSSc/O005PT9J1aM78vV5yQRPcN6jlCJ5 fALb2hYVPDzy4rey52YJ1GVUqKTinOENmDrZvDqnF+uEMlZsVj0yZsdV9o5YOb6KeP+g0LCZ1CMf/ FUE5J7XA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65rP-0000000HXUi-0nCz; Wed, 30 Oct 2024 10:23:31 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65ma-0000000HWWH-46J3 for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:34 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e59dc7df64so10059937b3.1 for ; Wed, 30 Oct 2024 03:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283511; x=1730888311; 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=Bt+GDj8bSCsrOuFvhauMB0QKz25eKh57Bb5+kpwY7Gc=; b=EP31fTaTvOoc6QMKKKq+z6sr2BPWizgGuYhzdSb9tcMwlfaAgnI2dXK1UdRjEbByq/ nDYQKbpnD2TMM8t7rPIHTBXMJnpXiAfaM1SOeDnaqP/NH/m1//XB83vUXOFaSRWShh+k PZRZ6/zhyHWxUnGlgB6x9DSU9W0NXjkDjAJYONAYNiHnW8m8wz8QzHt5ge01XGeDlCQ3 2wYLHiNWGBWoJ3yJndJwIH/RKoVmHt7KuQdv9trUcTHYc1XYmxgjnrWOFQnLGVDfeZBf tPfDXhYA3it7zAICVNg/pHaI6Z8jQ8RlO8Tkg12Tcc4hXVnQod+LClwlM07uZPOVBdhQ j7BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283511; x=1730888311; 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=Bt+GDj8bSCsrOuFvhauMB0QKz25eKh57Bb5+kpwY7Gc=; b=cOsfEVtuTVLq1QW9MX8vzxVbW9gWbl8xWwK2AIz4de0n/qiTBirBp6Ug8zU19I0Mpy VuxpaLzuKsUssaiccCPVvr2p8HIVGKJoiLlw0wmBm/xsJo09bMYRgQSp3AmgASM7Lx0r JVUtlJ+/WKQBRYIcv8IFGjK8lbl73rbgXKBgGzKTks0tRDmRIgZay9Po4j517GuD3+PT vVS9zckxgF+WBFzeA+z0qBDOF6vCvW2Zn3L+2BU0j8UadFxBgvvu9hiV1UPFszYoMlll X/tKduPboaLxUOPwX32EP1o8QUDcrkodo4Kf3AvbZgRBMwPWfqRTbv+EvLYweezknDFG Gisg== X-Gm-Message-State: AOJu0YzAFfItbRz3EdYtdgkq2sUpU8FcdLrVaEL/tNk6yIOz3kaMwVJ6 cpUjxaF7cFb2Ite7/1e5xVp16WWDeyYZTh6BDSj9+zuFraJNym1M/Y00tsBn6Tg4UkxT1dHVxDb wzGhx8n6FfdY2EAXwokZaXcWi3xO7fq2MEtuU4M1xWG2C86rj32Ob2hhg6785sSTuDRb/Hf9nwU ZMnmqr+mKd9QXawg6oZDqR+52C30MTi+l9IyD31siQ X-Google-Smtp-Source: AGHT+IHkg/m0TjIto84EqA/r5FuO1zVU5A4uj4lUTPcQZpzUFb+a+5T9IxFqqsZLyYJRz7Dar4t9cHib X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:4d45:b0:6e2:ac0a:8982 with SMTP id 00721157ae682-6ea3e59140amr1606947b3.0.1730283510742; Wed, 30 Oct 2024 03:18:30 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:06 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1276; i=ardb@kernel.org; h=from:subject; bh=5xf0c9c6JVxVeaGrMTt8Z5pUMYFzvmJMGfwOWomg+o4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/f6zFT9nH5hVuODhimtszh7iS2sfqq4Kapj3UKp46 dHqRemNHaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiQRsZ/ofeD8s69o3zJWun a6LH1Um6UXe/Ti/cwyAr/ih6ZY29QBsjw6vpRqe+3yxvS1rY9kF3artwwL+mVLMe+7vMc/7Wbnb 25wUA X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-12-ardb+git@google.com> Subject: [RFC PATCH 2/8] arm64: Kconfig: fix ARCH_MMAP_RND_BITS_MAX for 52-bit virtual addressing From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031833_039568_7D2DD1A3 X-CRM114-Status: GOOD ( 11.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 default values for ARCH_MMAP_RND_BITS_MAX fail to take into account that we now have support for 52-bit virtual addressing. As these configs are compatible with hardware that is incapable of 52-bit virtual addressing, use the same value we use for 47/48-bit virtual addressing. (For the sake of simplicity, use the same value for 47 and 48 bit virtual addressing for 16k pages) Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index ec218ef22f2b..ac8e7550430b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -324,13 +324,9 @@ config ARCH_MMAP_RND_BITS_MAX default 19 if ARM64_VA_BITS=36 default 24 if ARM64_VA_BITS=39 default 27 if ARM64_VA_BITS=42 - default 30 if ARM64_VA_BITS=47 - default 29 if ARM64_VA_BITS=48 && ARM64_64K_PAGES - default 31 if ARM64_VA_BITS=48 && ARM64_16K_PAGES - default 33 if ARM64_VA_BITS=48 - default 14 if ARM64_64K_PAGES - default 16 if ARM64_16K_PAGES - default 18 + default 29 if ARM64_64K_PAGES + default 30 if ARM64_16K_PAGES + default 33 config ARCH_MMAP_RND_COMPAT_BITS_MIN default 7 if ARM64_64K_PAGES From patchwork Wed Oct 30 10:18:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856239 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 6B02ED5CC87 for ; Wed, 30 Oct 2024 10:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GiSNJuUVqUmThi4ywhxxBlIx/VAibAab/TSDDvzR4DQ=; b=ODgmhfNqCjXwkInjcGVyPJ3MGL V3PqqHntqigblg7v+CB95UUVcu/4BZa/9sQvWmGe0s4u+rhKoG7bBDOFh2WkYFxiG7nSvl+Y4hUAJ WVWAAj7L2/BC/+eJTEEyRNrXuBHz8Dpx1gjITuD3901RYR9j0CEu9cGe/wQh/ymtMnZ5jVIyPrz/1 webYtFxBPIbPMQIdnJxds0fIOxrtxmpbPhYcbeg/FkgWZHB1UyG09PgA0Zl5ZmiFAE/9E4TfoLEcY kx+cNZ1lUAmnjxcKDsdhZ985JHiXdNdn4SMlArFfHy2GQkOlxvXDN6CMsFnXejBtuwlvUQiWeVKqw kORiYwKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65sz-0000000HXhr-2lAe; Wed, 30 Oct 2024 10:25:09 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65md-0000000HWWl-368K for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:37 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e02fff66a83so10644946276.0 for ; Wed, 30 Oct 2024 03:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283514; x=1730888314; 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=GiSNJuUVqUmThi4ywhxxBlIx/VAibAab/TSDDvzR4DQ=; b=KUqp50YsDaJFY4/hyqNi+0BcWVv4sYmgsawb0DmiMbz6LGw89NybWA3Xgbflo9rh8J OYfQ3YJ1d3Lc2hOAfhyalIufWoL0fkSGLw8SIB0JEE0TjmKmP7fTmb4dSEhNZHw2BHCO 73VN1SLPMSLRcTjMapWHW6KhF2Dlhvys4owkWpZGoJA+Dx0nzqP8UE81mVeiYbtVhyBf xxe+iDydAm9C9bUmUy8YpEw0T4/71kzrV7wFe9xl3lu0N3P+ufTg0PkiKIzp08aaO/Ld +8JFiKuvJGDYh7EXSW0nxXe7HCDUtGiq2cW0l/0Dz/g7o3NrUEUM5ux5Ndfyiq5zpft/ tZlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283514; x=1730888314; 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=GiSNJuUVqUmThi4ywhxxBlIx/VAibAab/TSDDvzR4DQ=; b=H0v8+6FyCNLsGcldrKEkCCVhC5MRNJQYkY30uPmlhAM6daps4U53I8CT1OW3y7O12p eRHSK2Ua8ko7SA3ocVGL63kPhTwXajs+hfRWuLguJLecVvugcXtl4z5jtFZ7AZCW5F5A MFzNk/SpVkJ1qS+2Cwvn94eKt2d7Prxj0ucMBp4EA9rkhKcE765Csz4V0gFiCQr+62dF QHddnJmFO70qChdfKfytJXmQ0Re4DnlhvzyF1go2bmYhsgpwvYLNidKJBuWUFgMrPVTc O8Pt3gAIXVunOWh6PFe1DRHtqQa2zgI/JfEqlvQ1kPzDIkCSCDnnuReBKMkm+7VJBe9Z PDGA== X-Gm-Message-State: AOJu0YxTQoXe9ud57PwYGEEiVWf84uHA8K3dTnO8TqiVKAO7evcClvVB X3Aw7Bj1gQyBDZHs5+6JiA/fs6lQb4C92JSbOwNVRE6wQh/Bj7oqH5NgT0L2SlToXFq9zral742 bu+yA/4xOQ3m5FLp2dmMDoqQZ49SeFgbOdhicND7fCQ04jWAJftSxjGeToq4SE/YiAwit+Gtlac fLI0gRqrD+NvHhl8nw7eGxboYzQ5ECeVcp9+dU7dkL X-Google-Smtp-Source: AGHT+IGnzByXmSferZ3znjFU1DAilPqK1hmhAoXGiKFphTF4R0E903gJtI58oxzNWHclXhOgvzUE8ntq X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a25:9c82:0:b0:e30:d445:a7c with SMTP id 3f1490d57ef6-e30d4450d48mr1746276.1.1730283513173; Wed, 30 Oct 2024 03:18:33 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:07 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2846; i=ardb@kernel.org; h=from:subject; bh=nfmkIc8BC3bWhOA+Opu1lUMycwYGYNKNBpiB1H0YnYE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/UH+r80LJJV36/2bn/fVcbvkiewdvStu6spqL742U VLoXcOGjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjAR3SKGv6IZp6KznvSxqaob LI4S9fjedylpPveSTdkKDSy8/9+2fmRkmHzAzrl1hl3Vm5i4GR/3zr74UM1a9uafK/x/l5StPxy 3iREA X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-13-ardb+git@google.com> Subject: [RFC PATCH 3/8] arm64: Kconfig: eliminate 64k/48-bit VA combination From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031835_806423_F46C431C X-CRM114-Status: GOOD ( 16.62 ) 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 Now that the vmemmap region is sized dynamically based on the actual size of the kernel VA space, there are no longer any material differences between supporting 48-bit and 52-bit VA space sizes for 64k pages, which use the same number of translation levels. And if needed, 52-bit virtual addressing can be disabled at boot on systems that do support it but where 48-bit virtual addressing is preferred. The only remaining difference is the size of a root level user page table, which grows from 512 bytes to 8k when 52-bit virtual addressing is enabled, but given that both are less than the size of a page, this is easily fixed in the pgd_alloc init code. (In all other possible cases where vabits_actual < VABITS holds, the effective PGD_SIZE equals the page size, and so this change has no effect.) Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 5 +++-- arch/arm64/mm/pgd.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index ac8e7550430b..6a73fd61b4aa 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -379,11 +379,11 @@ config PGTABLE_LEVELS int default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36 default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42 - default 3 if ARM64_64K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) default 3 if ARM64_4K_PAGES && ARM64_VA_BITS_39 default 3 if ARM64_16K_PAGES && ARM64_VA_BITS_47 + default 3 if ARM64_64K_PAGES default 4 if ARM64_16K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) - default 4 if !ARM64_64K_PAGES && ARM64_VA_BITS_48 + default 4 if ARM64_VA_BITS_48 default 5 if ARM64_4K_PAGES && ARM64_VA_BITS_52 config ARCH_SUPPORTS_UPROBES @@ -1361,6 +1361,7 @@ config ARM64_VA_BITS_47 config ARM64_VA_BITS_48 bool "48-bit" + depends on !PAGE_SIZE_64KB config ARM64_VA_BITS_52 bool "52-bit" diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c index 0c501cabc238..ecc4b1ec235c 100644 --- a/arch/arm64/mm/pgd.c +++ b/arch/arm64/mm/pgd.c @@ -48,20 +48,21 @@ void pgd_free(struct mm_struct *mm, pgd_t *pgd) void __init pgtable_cache_init(void) { + unsigned int size = PGD_SIZE >> (VA_BITS - vabits_actual); + if (pgdir_is_page_size()) return; -#ifdef CONFIG_ARM64_PA_BITS_52 /* * With 52-bit physical addresses, the architecture requires the * top-level table to be aligned to at least 64 bytes. */ - BUILD_BUG_ON(PGD_SIZE < 64); -#endif + if (IS_ENABLED(CONFIG_ARM64_PA_BITS_52)) + size = max(size, 64); /* * Naturally aligned pgds required by the architecture. */ - pgd_cache = kmem_cache_create("pgd_cache", PGD_SIZE, PGD_SIZE, + pgd_cache = kmem_cache_create("pgd_cache", size, size, SLAB_PANIC, NULL); } From patchwork Wed Oct 30 10:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856240 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 8B3F1D5CC87 for ; Wed, 30 Oct 2024 10:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=94qiCXWUuDIydTk8X4LSwVPIw3rMHWBfIZEjN6jzQTM=; b=oEpR2hAlrex31LEDU3sOlMrZTj EYsc651xYpPPEgkGeAub5S880VSFer+r6k8R/48TcfCyvTbS3poJviQ1pIGe9hJLjtZVaNVckc/aB x56LE+9OU+8jbx4dc6bibqbmpEy8O1/+n74fEGMJHTuwvsSX5xg2Y7VoqDLQfWq1cAVDbHnJ02fwZ zK1Kv/8JEksu18YAQ7GEmCOjr+JFXx/RL67mWwRQxQAcTfFqGtf9UubWX0In28WIQ54gNnNIdjEWz pLwBayIN5QSyH9Wr+XJeYlk1SV0Zn+PEknx7QKCZBDv2RgD3C5ZhcgrqsdfNftal5Je/Mg0y92vSe QMdrJoPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65ub-0000000HXyu-3f8x; Wed, 30 Oct 2024 10:26:49 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mg-0000000HWXK-2Qz4 for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:39 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-37d458087c0so476544f8f.1 for ; Wed, 30 Oct 2024 03:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283516; x=1730888316; 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=94qiCXWUuDIydTk8X4LSwVPIw3rMHWBfIZEjN6jzQTM=; b=MXZViov+ztF9pdGhWp7wBDi1i40iexSr1uvM5TCj9gi4S32izsKx20KtjVD4vNUtrL off3xEAc0N2MGeLNlsne1Vo6PYnOI6nxihxeKepfb3+UOFmfWYTZMv5qdKnaGUYWBs8V Y++O10iBBMiHo8p0mtvOzBmZl6beAZnHvmpsc3MiyG/hDEngaM3+NO9LNoS/q3z2PbBr KffNe3IEbE/c2/orGap7psHTDIWPiFC88SDJQS0j44lt0Sqg7vrN+mAYh0VqssHbiy0F N4vaAebhR5U8CgBvPuyrSKNaSMO3r6F+aTH08+UZKJlEzW+RlKvDbtNgYTRgFgAS90Q2 AOyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283516; x=1730888316; 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=94qiCXWUuDIydTk8X4LSwVPIw3rMHWBfIZEjN6jzQTM=; b=iCOLGwNBbe/AX6UtMQOCqPASYyP3pS1zAs95IyonKnkstcbcamdbOIO95KWxBkkz48 qhCC3tTeLM9J8XNWmhsyh2SptbSGEZU1pjY5rIL+uOD1OFdVL0EqR3XkPs9VxvD/Figz BRZdb3/jWjOaMs34n60Ta0l0t6ZF8GhnNpxiW8qel6WSROqH7owFefOWePIYBYTqNEzM xkTMumsaeXqno4wv2fgxaKMoWoO1VgoxO5LlHs17TB7uY2rEJtAuCxCf1WQp36YcJrPL +CrdIqJAGkb2e6T2xsVEIA0nL0eYnT2kCzoWvZiebSLgdnRwN1bnWt+Ev2mlv9o030gC OKOQ== X-Gm-Message-State: AOJu0YzfGxrOjHR5rRNhcRViPXLSsg/QfY+9YsFcSR7DgInIqyMag53j KRF5vGub5A4a/UcYmF8Du41uTL3tDgBn2JPVYmFfWFKCLFw+Z0CKaCInzqOBZV0erC8cT17YhfS /MtgzbXzSaSPImueIaFPNlzohBMcSCrc7GmB4xHIejJFSH+juRL+4MlPk/WnsmrkQQDcQVqnCAf WcnaB1bKnyijQ3TxMn/4meX0ueqq88irL0cD8ViZWy X-Google-Smtp-Source: AGHT+IGgZ0OVXp37+8lR94Wvdy5onp5gAtpP8orinG9/1ZVyPMEa++a9r+U9/Ky9ZN9he1zyQEnHX9oP X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:adf:ee0e:0:b0:37d:3878:ff42 with SMTP id ffacd0b85a97d-381b97ee8ffmr2531f8f.5.1730283515784; Wed, 30 Oct 2024 03:18:35 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:08 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1441; i=ardb@kernel.org; h=from:subject; bh=+QSrRJ4X17z2RWinz87UiXL8BkQ2pVlA6A7QdKOdXQc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/dGURw+Pr1WzLuW0DhebMaGOi/GdYk5ZvZjG40duz L8EU5s6SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQKNjL8d+ZfneP6eJnzfTPJ BLYfizuv/fe2Onfz2p0yJsuvOo6x9xkZpize3nbJzPLyKhHxxisTPeu/aiYZTZp5IUhcOOVRm/8 vVgA= X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-14-ardb+git@google.com> Subject: [RFC PATCH 4/8] arm64: Kconfig: eliminate 4k/48-bit VA combination From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031838_644525_DC8DA843 X-CRM114-Status: GOOD ( 12.15 ) 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 Now that LPA2 is supported seamlessly, using alternatives patching where appropriate to fall back to 48-bit virtual addressing when running with 4k page size on hardware that lacks LPA support, there is no longer a need to keep the separate 48-bit VA size configurations. Note that LPA2 support can be overridden at boot time by passing arm64.nolva on the command line, and given that no LPA2 hardware exists yet in the field, now is a good time to make this change. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6a73fd61b4aa..099b1a825b9f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -382,9 +382,8 @@ config PGTABLE_LEVELS default 3 if ARM64_4K_PAGES && ARM64_VA_BITS_39 default 3 if ARM64_16K_PAGES && ARM64_VA_BITS_47 default 3 if ARM64_64K_PAGES - default 4 if ARM64_16K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) - default 4 if ARM64_VA_BITS_48 - default 5 if ARM64_4K_PAGES && ARM64_VA_BITS_52 + default 4 if ARM64_16K_PAGES + default 5 if ARM64_4K_PAGES config ARCH_SUPPORTS_UPROBES def_bool y @@ -1361,7 +1360,7 @@ config ARM64_VA_BITS_47 config ARM64_VA_BITS_48 bool "48-bit" - depends on !PAGE_SIZE_64KB + depends on PAGE_SIZE_16KB config ARM64_VA_BITS_52 bool "52-bit" From patchwork Wed Oct 30 10:18:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856242 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 52199D5CC8A for ; Wed, 30 Oct 2024 10:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0lkeE3D8+J4OcDtDEGiGIXOA7IIy99qfhKrBIJpYyvY=; b=EWtvfPGSxlZZnkM4qx9Wuj/a3D o5Ml7HYaQ5lqVuRA9dIpv0XJLQ8ol5KiuBgLJLWOJDlv/kZqwfMnqEr3APJAGFgE6CiM9nYRV+2Lb tHtORKxLMa0PNKWqMheciEzcSd5d2JeiY+1f6aE6zr+vpPjp8RrrZSvt1BS/PMLgH0XqEqigXkOhT KsCBrdXN3RUCQtfkCPNxJq4ViK2EzVbhmspeCiWqBzpMkJikvPMn2KJzgsxhI7efRX6fS32v3xSz3 5w1X/rj2Lk8ddycL6DWOu5KFyLvFvU81txLLoh5WCuOuFlE+XsrAjaURqTjITl1yt+hda64VTAmqk dl42qXFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65wD-0000000HYH4-3t2P; Wed, 30 Oct 2024 10:28:29 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mi-0000000HWYN-1Pl4 for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:41 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e370139342so120135207b3.3 for ; Wed, 30 Oct 2024 03:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283519; x=1730888319; 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=0lkeE3D8+J4OcDtDEGiGIXOA7IIy99qfhKrBIJpYyvY=; b=Ri0BmhcNlWN536E2ejooFd7V+uo5xtqs0TZuxHGJwg72oDbIg/IpSmjyFZSJvmghnr mw0JScF0clHvRT7m5UXZ9go/hbGk/IBUo8tneIKAjczcoOvI33aAPtnE1YAW5teWupsC kvcSRG1CDk0E7VaeWTbO/DPHHMOy+NP1QBC/RVaPJfN7TLdPwolD7Cf5sANuGMVi7lQk x8QXW3nQVSHT4LjO3XXAkc4DNOS6Gn8cpY3GWVmSq/aQzt3gen8uce4Dwg0LSbxZcNzQ MtkBLxAx/pi7c7+KUK4Caid5XfvbvWcoNP1h5+xROLVfVxbEf+6t0Pe52dlxezf64G2L 9QMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283519; x=1730888319; 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=0lkeE3D8+J4OcDtDEGiGIXOA7IIy99qfhKrBIJpYyvY=; b=nAkoz+QJ+ReDcuGiliitRQvimd2vG6JNheMWH9FDkzLxscXDyvvepbeIWvn3MkC6dx YJofTV769XgLrN3Eyj2Z3+gGCRzCIb4RyxR9zsVZMS2QgnOakCSOMQVqnZBYKhK8rGMa fUi0cKo5QvhTcy9FqVHmrGorXn9MBKBd4rJRAtC+xXjnzjREXZP4DPDiOlSA/WLHdCV7 2vo5w72HU5T4uxkaxoMOrxL6E6MmDcOnzCoW6ORnqu53u24KSbzOflha63kLv3wUDhq8 GxEAkQxBHc1CDVz/aunTKBPIQUIdtOotXgW/bCa5H33STh3r9PGMrfUrlbXTL4C0Csv6 yxgg== X-Gm-Message-State: AOJu0YwZ6jzIQlQ5KHfef8h+zLvtx+T1eMgA+JuQ0X+No+7XdK4TYW9N rKTlg3NdRxvKAUaU/aQXJ0HE69CytLwYVm3rYkeOSsJl2+Drpt5+4itkvma/kJzN8dBybjIIBnT bNZXRDPgu9RSvk4If9ynVb5bmCK8aod9DUVg8y5ATAqwn1XBf21qOoZSVPXWMvzmeGiOpbkouK2 7yFOqd//O8yNJere6fqmke916J2cAZbhIpd00ozWLR X-Google-Smtp-Source: AGHT+IGYWIKtsISSLmZozooMwTQpsr6uP8eXuzu1h8K7n8sXmZ2Z4/5RcAprTfRvs8MnaiExmLO2GGiB X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:6383:b0:6e2:ad08:4924 with SMTP id 00721157ae682-6e9d8aacb2dmr10859077b3.4.1730283518114; Wed, 30 Oct 2024 03:18:38 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:09 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2720; i=ardb@kernel.org; h=from:subject; bh=KrPhtIjOJOdsjzLuM0pYgTBMlukJZDWck1DRFJ4KhOY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/fEK9kaevBx3Dv2e4nzmCa9FlknPUUlkW5NUe/yEu OU974iOUhYGMQ4GWTFFFoHZf9/tPD1RqtZ5lizMHFYmkCEMXJwCMBGlXwz/PU99XLJ41767Ozwz bmYfFnoUeIDj3XOLCeJnjs6eP+302ccM/xTyTxXuvDnz4OW0kshvCzneJLwXODqh6kHH7x95bku TGpkB X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-15-ardb+git@google.com> Subject: [RFC PATCH 5/8] arm64/Kconfig: Drop support for 47-bit virtual addressing From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031840_408648_335CB98C X-CRM114-Status: GOOD ( 12.88 ) 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 Drop the separate 47-bit virtual address space configuration, which is identical in practice to 52-bit VA configuration on all 16k pages capable hardware currently in the field. For future hardware that does implement support for 52-bit virtual addressing, this mode can be chosen at boot by passing 'arm64.nolva' on the kernel command line. This reduces the number of configurations that need to be supported and validated. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 099b1a825b9f..7df7d24c767d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -380,7 +380,6 @@ config PGTABLE_LEVELS default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36 default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42 default 3 if ARM64_4K_PAGES && ARM64_VA_BITS_39 - default 3 if ARM64_16K_PAGES && ARM64_VA_BITS_47 default 3 if ARM64_64K_PAGES default 4 if ARM64_16K_PAGES default 5 if ARM64_4K_PAGES @@ -412,12 +411,12 @@ config KASAN_SHADOW_OFFSET hex depends on KASAN_GENERIC || KASAN_SW_TAGS default 0xdfff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && !KASAN_SW_TAGS - default 0xdfffc00000000000 if (ARM64_VA_BITS_47 || ARM64_VA_BITS_52) && ARM64_16K_PAGES && !KASAN_SW_TAGS + default 0xdfffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && !KASAN_SW_TAGS default 0xdffffe0000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS default 0xdfffffc000000000 if ARM64_VA_BITS_39 && !KASAN_SW_TAGS default 0xdffffff800000000 if ARM64_VA_BITS_36 && !KASAN_SW_TAGS default 0xefff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && KASAN_SW_TAGS - default 0xefffc00000000000 if (ARM64_VA_BITS_47 || ARM64_VA_BITS_52) && ARM64_16K_PAGES && KASAN_SW_TAGS + default 0xefffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && KASAN_SW_TAGS default 0xeffffe0000000000 if ARM64_VA_BITS_42 && KASAN_SW_TAGS default 0xefffffc000000000 if ARM64_VA_BITS_39 && KASAN_SW_TAGS default 0xeffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS @@ -1354,10 +1353,6 @@ config ARM64_VA_BITS_42 bool "42-bit" depends on PAGE_SIZE_64KB -config ARM64_VA_BITS_47 - bool "47-bit" - depends on PAGE_SIZE_16KB - config ARM64_VA_BITS_48 bool "48-bit" depends on PAGE_SIZE_16KB @@ -1397,7 +1392,6 @@ config ARM64_VA_BITS default 36 if ARM64_VA_BITS_36 default 39 if ARM64_VA_BITS_39 default 42 if ARM64_VA_BITS_42 - default 47 if ARM64_VA_BITS_47 default 48 if ARM64_VA_BITS_48 default 52 if ARM64_VA_BITS_52 From patchwork Wed Oct 30 10:18:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856243 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 67616D5CC87 for ; Wed, 30 Oct 2024 10:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=52XSQSJD/DBoSd/dVK+WzCA1fOPBNSpbtkHc/N5BpME=; b=sN9vWDXsFkcy5wP7QPr6kVbCeE 9YCxJQLw70MFgIY+RMyhKdJPXPGx/isxRssrl8bc6msghiuCrVpEHrAIA2zW3vGKMbiw7EPrHNlQh 1J2wAaoKvB6nZyRjPaV0d9Yg2P1wBXBp4g4mIVvcaMdo1nF9PUA6bygxk63rSHmto705BlS9qnV5M pcnMrSnHtTAmEcNsP4S1T2dblxsEQwCHQk8Tvvs3QBiCGxk7l/09RGrliNsTfyQNlYsd6QJ+afJZl UI6WrhG47geq+qv78MYfxMs66j0JVLY2ikJ6um5O/eNxnuQMiGjDs7xd0EKtCd/288npAhSPjvNEb ZCimrtVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65xp-0000000HYQS-02Pz; Wed, 30 Oct 2024 10:30:09 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mk-0000000HWYr-3ldf for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:44 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-4314c6ca114so46648435e9.1 for ; Wed, 30 Oct 2024 03:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283521; x=1730888321; 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=52XSQSJD/DBoSd/dVK+WzCA1fOPBNSpbtkHc/N5BpME=; b=EoDgBNW2kxTtpmcj+jNjlAlPWrtcmiZMeXi1guhM/o6GqR3Od5SsE4tUs6NIUgz6ZB ATR7uP0DucPlw21CzwuGHtO2AaAT7kKtYkwJRnz2aa3S1qA/91HYuVnhgvMu5BZJgIkS YOM1VhtQLvzidOCQzTBc9lq0IztVjxOoYMOIEyufeW1wAEwts90e2w9iX4f/TIdF2yqJ 0D0ejffi8TwC875ppvWfhP6nHNhRKQoK2J6qWjC4dWVSAd5udJiluxu/MnQ1faDV0Mz2 XSjlwY3QrVleTnZc/SMPdENcx8Y5POyuTI09QjvJUJwVSBKEeZT8XnzdShQd0qmgI6Je 4KBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283521; x=1730888321; 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=52XSQSJD/DBoSd/dVK+WzCA1fOPBNSpbtkHc/N5BpME=; b=bGu7TlwjJLs013PhdzOTvNnyfnjeszv19WNTghwFZI3ZNTdNoWW/wOUqsJVanE1IAH uvEi5r9VRoXh6ZS25PpYnf7K/P3EVr6xWJQ0h9kwYFpUsNvTsuELhXft11Y/1RZe/Vyx Kr/1H40LMHVtQqVJ3Vs120Xpea/BS8KIefXTT4INQ3zaHodRe8wm8k/nDG4myU1Sdzwo hHVK6fcU53zh6UnhgDrUkm4j2aHpgg94Ds1H1zMPOl+oZE4TMOc8OyoKux7QU+gEQ1Zl OqA41Uy8XhP8bFknGBZsncWO8WZFduX0gfB3TnRAUfkAc+ng1YhOerGZpz8T231wyUrV X5qg== X-Gm-Message-State: AOJu0Yxccirmmgbc6kkEv+Z+VDvhJ8z0Rn0ijmZFMgolOImMAhXfeA/A /9wRdf1kGqiWwsM+5D67+41q5mNf2mPpr+gAErKaACVS6p66l2HMyz8a/CPG3gvBSIqqA/KuoMh a1RaNPCae7FLZpCjFCSeTS+yb+bGLoqavHN3JKYFGOMnkJmuNqvHVcYS7toI/NrqkKWbSQ5QUZI Y+Pig0tLxSNpQdC5LUo7S7h4nfOD+Q+Pr/jShwHbYw X-Google-Smtp-Source: AGHT+IE+VEO/hNHzg7jdjYQZotl0+so22jmmCWNlXHxB6h6jNcpvLk11K2SoNznqTnbSklfAXsYs5vYW X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a7b:cb58:0:b0:430:52b1:ae39 with SMTP id 5b1f17b1804b1-4319ad3436cmr194225e9.6.1730283520639; Wed, 30 Oct 2024 03:18:40 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:10 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2475; i=ardb@kernel.org; h=from:subject; bh=Q+pr1M8F6H61P9kQUTYPtb4597ihTA9POIZzPdbOGKE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/cmzb6dbs+SaWnIUZB/uT8gUOpxzjIG1YddKuaiuk sfN6RYdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCJ2Ygz/q+wZnv75ufDFJvWD qfadKiGbXXv/HmTTSDMrcsyLDosUYfgfwS7VxLaaoezGeqaXZYZdormWnUv+OjDG3jZ7v3l6+Td uAA== X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-16-ardb+git@google.com> Subject: [RFC PATCH 6/8] arm64/Kconfig: Drop support for 48-bit virtual addressing From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031842_971978_EB2D59DC X-CRM114-Status: GOOD ( 12.09 ) 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 Drop support for 48-bit virtual addressing on 16k pages, which is the only remaining config that supports this explicitly. On 16k pages, 48-bit virtual addressing uses 4 levels of translation, where the top level has only 2 entries. This is very inefficient in terms of TLB utilization, and so 47-bit virtual addressing is usually a better choice. Note that x86 supports only 47-bit virtual addressing for user space with 4 translation levels, due to the way its page tables are constructed (a single combined root table for both kernel and user space), and so removing this configuration is unlikely to create portability concerns. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7df7d24c767d..39d0d2eb5b7c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -410,12 +410,12 @@ config BUILTIN_RETURN_ADDRESS_STRIPS_PAC config KASAN_SHADOW_OFFSET hex depends on KASAN_GENERIC || KASAN_SW_TAGS - default 0xdfff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && !KASAN_SW_TAGS + default 0xdfff800000000000 if ARM64_VA_BITS_52 && !ARM64_16K_PAGES && !KASAN_SW_TAGS default 0xdfffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && !KASAN_SW_TAGS default 0xdffffe0000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS default 0xdfffffc000000000 if ARM64_VA_BITS_39 && !KASAN_SW_TAGS default 0xdffffff800000000 if ARM64_VA_BITS_36 && !KASAN_SW_TAGS - default 0xefff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && KASAN_SW_TAGS + default 0xefff800000000000 if ARM64_VA_BITS_52 && !ARM64_16K_PAGES && KASAN_SW_TAGS default 0xefffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && KASAN_SW_TAGS default 0xeffffe0000000000 if ARM64_VA_BITS_42 && KASAN_SW_TAGS default 0xefffffc000000000 if ARM64_VA_BITS_39 && KASAN_SW_TAGS @@ -1353,10 +1353,6 @@ config ARM64_VA_BITS_42 bool "42-bit" depends on PAGE_SIZE_64KB -config ARM64_VA_BITS_48 - bool "48-bit" - depends on PAGE_SIZE_16KB - config ARM64_VA_BITS_52 bool "52-bit" help @@ -1392,7 +1388,6 @@ config ARM64_VA_BITS default 36 if ARM64_VA_BITS_36 default 39 if ARM64_VA_BITS_39 default 42 if ARM64_VA_BITS_42 - default 48 if ARM64_VA_BITS_48 default 52 if ARM64_VA_BITS_52 choice From patchwork Wed Oct 30 10:18:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856244 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 475CDD5CC8C for ; Wed, 30 Oct 2024 10:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Kg/kIHVTHiz8etJGdNS9GpgXHNuRCTwjnnrHRUXl/AA=; b=opxqX4xL2VEPZpc7cb8BCxNhIO U4ck/SXBEdrtOy9Khq1I0eyheUvL5aB4IlHEWKBjebDNH8t1ZbyfLsp3KpMgqXOKA1Jet0R3o2P9/ QpKgLXqATbXlhdzrWUGdarQLW46/hZBfs3o2y/Y2+fbUIAUqW9Ig5kDXev1gZBqD7IVjFraz981Rl YUHlBnP+WDfsNRvLB0yVkAM/1BBJ0X6G3nU2XW14dEoC3PbD5p/rhtM+o0G//IuFhgnEaK1Peetd9 srms2EPi/n7dGaWFZTQPGhYsEFSHpvQhiJJ9GXHlmOIPWXDRg82TUsvKfd4mqYLVj1M9U79ECqDP2 Iw2t0iVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t65zQ-0000000HYc1-0tVV; Wed, 30 Oct 2024 10:31:48 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mn-0000000HWaC-3y5a for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:47 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e30ba241e7eso3848743276.2 for ; Wed, 30 Oct 2024 03:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283524; x=1730888324; 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=Kg/kIHVTHiz8etJGdNS9GpgXHNuRCTwjnnrHRUXl/AA=; b=JFUakK/kMDyXLLowgxGr00/eqGeBiqHBZ0/oOAxQri0QVKzTTzTg3od13hgTZXibJQ vxmlB4bVTuhWGqKExRIkVje5ZapVaQFvS3XimMz/b6H7f4J82jcVSz8jfD84K8OIIaqK q4UGGW4BtK7kz8GzwmIZq/CmzywZS/SC4lAgOg3ldEVGvGoHmIH58oVDO0Q9WlrTg0S6 NZ4Ud+cSUxy32MZMCWtLBfusjUcGWYOMkAxp7nhFuwGi78piOUmhFecRGtsLBxQX+gqQ +oa/XsgPWVhlPV8W4wE8BrWa28zWNrEqmYZoEoOCIEuE9QYVQSdjnKGHCKOLKnRz7HfA h10A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283524; x=1730888324; 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=Kg/kIHVTHiz8etJGdNS9GpgXHNuRCTwjnnrHRUXl/AA=; b=XMRXAgCIP77z3kn16RO38oxmRpySwSRavFTUOJOHWQe8nkjZRlED8GbVH1Otr1I/7p G6UPacw78HE/Oi6tnNEgpRCFcLpqgtcBa2m/Q3O4oCJwhzxzbdW1sOTC7iATtU0/oQ8L +z5Ne9lC0S6CdNNA850u8mb+J+0rZUeCiF7e9xSgCwoEJwPgj+PqQ+fEIswIKvGYX7EN IgYX70utI3xyd4AjQL91lyUzauEMoiqHjTQATs/kHgj5xRoXk6Va4TIggAzje7s+cbex b47PZN+rMIqyh6y41du1Ev7YIWchq7dob49hke/4nGELg/7i+msqXld5yvtQAzoXYXQu 0ikw== X-Gm-Message-State: AOJu0YzdRk4tXr/abG3iYYSRkWFkyaG6pZy5kpKHZRnnbUaihiRLegde SjIwenB6GbOlNFNTk/wB/vwi3eUB8ylBX8keTbLFgbc/pLNvjkLtvrcJLBVX4uy7cVR6k72b/VV I5WLRY19GOSZczLV5J1r77ObuMlGC29m2zTOOd6HxB3JR1vqgbxUOh8qjzeCb+P1tsr+lnwUZZ7 iwzJaY0+7OpZDbtsfRAOEmNxSo1KBoea6UtiNRd5U5 X-Google-Smtp-Source: AGHT+IHs9QWvufbOWXr5ECBWgcAR6C8EuNXNWeeS3nrHZJLBKoPbhzIuqfsM8OKvQ+nmRRRRdEtMEeLD X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a5b:91:0:b0:e28:f2a5:f1d with SMTP id 3f1490d57ef6-e3087a4ed65mr49338276.4.1730283523057; Wed, 30 Oct 2024 03:18:43 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:11 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=11655; i=ardb@kernel.org; h=from:subject; bh=EsNyVRynRKFNOTFmisbkOFj6S81RcOlobIQYO8jCGKU=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/VlU76I5Jgue2PF8CVvna5Xc0Pj2ixzvq0el4Ut7H vhmbNnUUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbyXoCR4dmsoy+3PVKvEVdm ilj+zV80c5LqTI3m9DY/80xT/oI7QowMVw1z2S5N2z0/ofdY0qFzLmZr/SsU/3zx6suKSJwWt5W NCQA= X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-17-ardb+git@google.com> Subject: [RFC PATCH 7/8] arm64/mm: Use reduced VA sizes (36/39/42 bits) only for user space From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031846_033367_F886C2F9 X-CRM114-Status: GOOD ( 25.04 ) 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 advantage of a reduced virtual address space size is its impact on the number of translation levels, which affects TLB pressure. The working set of translations covering the kernel side is negligible compared to user space, where each process has its own set of page tables, and so most of the same benefit can be obtained by reducing the VA size only for user space. As a preparatory step towards implementing this, drop all the reduced VA space sizes in Kconfig, and replace it with a configurable userland VA space size that is reflected in TASK_SIZE. This will be taken advantage of in a subsequent patch to actually reduce the number of translations used by the MMU for translating user space virtual addresses. As a bonus, this will allow 36-bit virtual addressing for user space to be used on SoCs whose physical address space layout is based on the misguided 'Principles of ARM memory maps' document, which struggle with this currently, given that a 35-bit linear map can only fit 2 GiB of RAM (and on these designs, the rest of RAM comes after a 30 GiB hole in the physical address space) Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 56 +++++++++----------- arch/arm64/include/asm/assembler.h | 2 +- arch/arm64/include/asm/memory.h | 4 -- arch/arm64/include/asm/pgtable-hwdef.h | 2 - arch/arm64/include/asm/processor.h | 6 +-- arch/arm64/kernel/cpufeature.c | 2 - arch/arm64/kernel/head.S | 4 -- arch/arm64/mm/init.c | 4 +- arch/arm64/mm/proc.S | 2 - 9 files changed, 31 insertions(+), 51 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 39d0d2eb5b7c..78e82383f8e2 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -111,7 +111,7 @@ config ARM64 select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS - select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) + select ARCH_WANT_HUGE_PMD_SHARE if !ARM64_64K_PAGES select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_EXECMEM_LATE if EXECMEM select ARCH_WANTS_NO_INSTR @@ -321,9 +321,9 @@ config ARCH_MMAP_RND_BITS_MIN # max bits determined by the following formula: # VA_BITS - PAGE_SHIFT - 3 config ARCH_MMAP_RND_BITS_MAX - default 19 if ARM64_VA_BITS=36 - default 24 if ARM64_VA_BITS=39 - default 27 if ARM64_VA_BITS=42 + default 19 if ARM64_USER_VA_BITS_36 + default 24 if ARM64_USER_VA_BITS_39 + default 27 if ARM64_USER_VA_BITS_42 default 29 if ARM64_64K_PAGES default 30 if ARM64_16K_PAGES default 33 @@ -377,9 +377,6 @@ config FIX_EARLYCON_MEM config PGTABLE_LEVELS int - default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36 - default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42 - default 3 if ARM64_4K_PAGES && ARM64_VA_BITS_39 default 3 if ARM64_64K_PAGES default 4 if ARM64_16K_PAGES default 5 if ARM64_4K_PAGES @@ -410,16 +407,10 @@ config BUILTIN_RETURN_ADDRESS_STRIPS_PAC config KASAN_SHADOW_OFFSET hex depends on KASAN_GENERIC || KASAN_SW_TAGS - default 0xdfff800000000000 if ARM64_VA_BITS_52 && !ARM64_16K_PAGES && !KASAN_SW_TAGS - default 0xdfffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && !KASAN_SW_TAGS - default 0xdffffe0000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS - default 0xdfffffc000000000 if ARM64_VA_BITS_39 && !KASAN_SW_TAGS - default 0xdffffff800000000 if ARM64_VA_BITS_36 && !KASAN_SW_TAGS - default 0xefff800000000000 if ARM64_VA_BITS_52 && !ARM64_16K_PAGES && KASAN_SW_TAGS - default 0xefffc00000000000 if ARM64_VA_BITS_52 && ARM64_16K_PAGES && KASAN_SW_TAGS - default 0xeffffe0000000000 if ARM64_VA_BITS_42 && KASAN_SW_TAGS - default 0xefffffc000000000 if ARM64_VA_BITS_39 && KASAN_SW_TAGS - default 0xeffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS + default 0xdfff800000000000 if !ARM64_16K_PAGES && !KASAN_SW_TAGS + default 0xdfffc00000000000 if ARM64_16K_PAGES && !KASAN_SW_TAGS + default 0xefff800000000000 if !ARM64_16K_PAGES && KASAN_SW_TAGS + default 0xefffc00000000000 if ARM64_16K_PAGES && KASAN_SW_TAGS default 0xffffffffffffffff config UNWIND_TABLES @@ -1334,26 +1325,26 @@ config ARM64_64K_PAGES endchoice choice - prompt "Virtual address space size" - default ARM64_VA_BITS_52 + prompt "Virtual address space size for user space" + default ARM64_USER_VA_BITS_52 help Allows choosing one of multiple possible virtual address space sizes. The level of translation table is determined by a combination of page size and virtual address space size. -config ARM64_VA_BITS_36 - bool "36-bit" if EXPERT +config ARM64_USER_VA_BITS_36 + bool "36-bit" depends on PAGE_SIZE_16KB -config ARM64_VA_BITS_39 +config ARM64_USER_VA_BITS_39 bool "39-bit" depends on PAGE_SIZE_4KB -config ARM64_VA_BITS_42 +config ARM64_USER_VA_BITS_42 bool "42-bit" depends on PAGE_SIZE_64KB -config ARM64_VA_BITS_52 +config ARM64_USER_VA_BITS_52 bool "52-bit" help Enable 52-bit virtual addressing for userspace when explicitly @@ -1372,7 +1363,7 @@ endchoice config ARM64_FORCE_52BIT bool "Force 52-bit virtual addresses for userspace" - depends on ARM64_VA_BITS_52 && EXPERT + depends on ARM64_USER_VA_BITS_52 && EXPERT help For systems with 52-bit userspace VAs enabled, the kernel will attempt to maintain compatibility with older software by providing 48-bit VAs @@ -1385,10 +1376,14 @@ config ARM64_FORCE_52BIT config ARM64_VA_BITS int - default 36 if ARM64_VA_BITS_36 - default 39 if ARM64_VA_BITS_39 - default 42 if ARM64_VA_BITS_42 - default 52 if ARM64_VA_BITS_52 + default 52 + +config TASK_SIZE_BITS + int + default 36 if ARM64_USER_VA_BITS_36 + default 39 if ARM64_USER_VA_BITS_39 + default 42 if ARM64_USER_VA_BITS_42 + default 52 choice prompt "Physical address space size" @@ -1399,11 +1394,10 @@ choice config ARM64_PA_BITS_48 bool "48-bit" - depends on ARM64_64K_PAGES || !ARM64_VA_BITS_52 + depends on ARM64_64K_PAGES config ARM64_PA_BITS_52 bool "52-bit" - depends on ARM64_64K_PAGES || ARM64_VA_BITS_52 help Enable support for a 52-bit physical address space, introduced as part of the ARMv8.2-LPA extension. diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 3d8d534a7a77..337ba98d0272 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -577,7 +577,7 @@ alternative_endif * ttbr: Value of ttbr to set, modified. */ .macro offset_ttbr1, ttbr, tmp -#if defined(CONFIG_ARM64_VA_BITS_52) && !defined(CONFIG_ARM64_LPA2) +#ifndef CONFIG_ARM64_LPA2 mrs \tmp, tcr_el1 and \tmp, \tmp, #TCR_T1SZ_MASK cmp \tmp, #TCR_T1SZ(VA_BITS_MIN) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 0480c61dbb4f..e138deb78bee 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -53,15 +53,11 @@ #define PCI_IO_END (PCI_IO_START + PCI_IO_SIZE) #define FIXADDR_TOP (-UL(SZ_8M)) -#if VA_BITS > 48 #ifdef CONFIG_ARM64_16K_PAGES #define VA_BITS_MIN (47) #else #define VA_BITS_MIN (48) #endif -#else -#define VA_BITS_MIN (VA_BITS) -#endif #define _PAGE_END(va) (-(UL(1) << ((va) - 1))) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index fd330c1db289..a7e0c0f3c6c8 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -336,10 +336,8 @@ #define TTBR_BADDR_MASK_52 GENMASK_ULL(47, 2) #endif -#ifdef CONFIG_ARM64_VA_BITS_52 /* Must be at least 64-byte aligned to prevent corruption of the TTBR */ #define TTBR1_BADDR_4852_OFFSET (((UL(1) << (52 - PGDIR_SHIFT)) - \ (UL(1) << (48 - PGDIR_SHIFT))) * 8) -#endif #endif diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 1bf1a3b16e88..62f30d8f9738 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -50,9 +50,9 @@ * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. */ -#define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS_MIN) -#define TASK_SIZE_64 (UL(1) << vabits_actual) -#define TASK_SIZE_MAX (UL(1) << VA_BITS) +#define DEFAULT_MAP_WINDOW_64 (UL(1) << MIN(VA_BITS_MIN, CONFIG_TASK_SIZE_BITS)) +#define TASK_SIZE_64 (UL(1) << MIN(vabits_actual, CONFIG_TASK_SIZE_BITS)) +#define TASK_SIZE_MAX (UL(1) << CONFIG_TASK_SIZE_BITS) #ifdef CONFIG_COMPAT #if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 37e4c02e0272..c36c66562c0a 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2866,7 +2866,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .cpu_enable = cpu_enable_fpmr, ARM64_CPUID_FIELDS(ID_AA64PFR2_EL1, FPMR, IMP) }, -#ifdef CONFIG_ARM64_VA_BITS_52 { .capability = ARM64_HAS_VA52, .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, @@ -2883,7 +2882,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { #endif #endif }, -#endif { .desc = "NV1", .capability = ARM64_HAS_HCR_NV1, diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 5ab1970ee543..15e9c1c5547d 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -380,11 +380,9 @@ SYM_FUNC_START_LOCAL(secondary_startup) */ mov x20, x0 // preserve boot mode -#ifdef CONFIG_ARM64_VA_BITS_52 alternative_if ARM64_HAS_VA52 bl __cpu_secondary_check52bitva alternative_else_nop_endif -#endif bl __cpu_setup // initialise processor adrp x1, swapper_pg_dir @@ -488,7 +486,6 @@ SYM_FUNC_START(__enable_mmu) ret SYM_FUNC_END(__enable_mmu) -#ifdef CONFIG_ARM64_VA_BITS_52 SYM_FUNC_START(__cpu_secondary_check52bitva) #ifndef CONFIG_ARM64_LPA2 mrs_s x0, SYS_ID_AA64MMFR2_EL1 @@ -509,7 +506,6 @@ SYM_FUNC_START(__cpu_secondary_check52bitva) 2: ret SYM_FUNC_END(__cpu_secondary_check52bitva) -#endif SYM_FUNC_START_LOCAL(__no_granule_support) /* Indicate that this CPU can't boot and is stuck in the kernel */ diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d21f67d67cf5..c4349852846f 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -236,8 +236,8 @@ void __init arm64_memblock_init(void) * we have to move it upward. Since memstart_addr represents the * physical address of PAGE_OFFSET, we have to *subtract* from it. */ - if (IS_ENABLED(CONFIG_ARM64_VA_BITS_52) && (vabits_actual != 52)) - memstart_addr -= _PAGE_OFFSET(vabits_actual) - _PAGE_OFFSET(52); + if (vabits_actual != VA_BITS) + memstart_addr -= _PAGE_OFFSET(vabits_actual) - _PAGE_OFFSET(VA_BITS); /* * Apply the memory limit if it was set. Since the kernel may be loaded diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 8abdc7fed321..779f589f947c 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -472,7 +472,6 @@ SYM_FUNC_START(__cpu_setup) tcr_clear_errata_bits tcr, x9, x5 -#ifdef CONFIG_ARM64_VA_BITS_52 mov x9, #64 - VA_BITS alternative_if ARM64_HAS_VA52 tcr_set_t1sz tcr, x9 @@ -480,7 +479,6 @@ alternative_if ARM64_HAS_VA52 orr tcr, tcr, #TCR_DS #endif alternative_else_nop_endif -#endif /* * Set the IPS bits in TCR_EL1. From patchwork Wed Oct 30 10:18:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13856261 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 50F07D5CC8C for ; Wed, 30 Oct 2024 10:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PPRGspoCFMLa/ML1zQGAdf+RPV3kEKo7CdywG6YAezg=; b=HTD6x8d20fd1ZNbqnsHKgTxcrJ 4m3VQ4YbbjimteK6wfnlhEAkW8lT6x819MGBIU5SSnI0WCYejSVBYPsgVxRh7/vf/hfv7/l2nwn52 UhFdtZsAJRZngv5+S+yY9JYizTNMFSWFfvC+nmlnw2ClJUQZx8hI1aPgUsjF1AnXeh1X8Qzognfwh ZX31qosDVdgPwfsuZO5zWasytyIvIYwiPipjBr95Jka1xq1jR2pdkfrkUMZ3k3zy7N+Fi/NhZOZ0T /OZLcHoEWDFp4ajFi45uCRcB7e+f1DqDd3q/dtfeID/fweM6YX76tos2d2LhagSCmMQFve7NMMpf9 PBSZdtDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6615-0000000HZ2z-17li; Wed, 30 Oct 2024 10:33:31 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t65mp-0000000HWb7-2lnw for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 10:18:49 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e36cfed818so104404107b3.3 for ; Wed, 30 Oct 2024 03:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730283526; x=1730888326; 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=PPRGspoCFMLa/ML1zQGAdf+RPV3kEKo7CdywG6YAezg=; b=HGIkOT90QgNS/8LTzsDYAmndFy3w5f4bRzUdKmyaOoIoU142npmsJGWjo+g2RMGENf 9MG5iJEb6ML7FbDKEMFAfUagKP0jsCCepu3AqrxXQ/HHwAcFhznr1PZTWaP0F4iiUu5L MbAHeOyXkQaCHbxxnsjjJOqmsu5GmscXekVettLPkcBoWP9Sz+wtnyrO9db1d3Lpky+k wnsdZ3uU9z4EaL1Kp79G43vDK2CRCaUMJ4lMETFEVb16GTX5GBYnQQ4l5uHyWFM62E4q oW3VWeNBa5cPa1iokCoErR/IKFbNETSbP6c6dWXN1GjPvo+6UllI5j9iwHIBu8zWF2aq URDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730283526; x=1730888326; 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=PPRGspoCFMLa/ML1zQGAdf+RPV3kEKo7CdywG6YAezg=; b=jOj1ljZuG1VZxvpt4NWXNPqmR6zofn81lW4Bb8jRRH+bSuggRI9CKUDn6Wubbl3//g yYl+fvIvJOv6NdXIKQO9gSNn2EOB5PnCpsXqoxCLbGROWplFXLsW8WhXYhwLVvVavEif 5XEZYxDGQIMWdnE/Rbvxkde1vbAZxkz6sLtsEGg/OOJSa2Vvu5s/vd/daFOkjKmivwNn 5yEG578X0Lmyh/SGXMQY3NXqQ54bUnfi65TISX1Vq4YzdOp41tdKmpYDwzyHnpa5RHFY BMNUxYAvWV9zCCMiflxnehabrlNfXgcIcDci5zsxb87Ulfx3bih4EkvMSJ7q0Vaaju0s AdmQ== X-Gm-Message-State: AOJu0YwLQoNxyyDYKa0WitpBTnBuY2TAEzYj82OYuUlUH1v8o1GlVQPn hLAcXm4yXA/54JwODW2YJE5YagqkLTxVN5eGe1q8eLT0ZFPM+flqHd+kKRcpUJo6yAZnQgg+YEi enZW3NWk8X/xEI45T4k/oc+fjt7ONmykiVqa4jztJEq2Y9M58WPB4Ri57QkFlo9N06DY1qL/2SA 61PUXvpzenwZG5yIV5dl9vPWt+481qovyFj7cEt7Hn X-Google-Smtp-Source: AGHT+IGuD4l1ccYFqEeRi/42ggdhN+cT+EfjhCRmyQyLIYZ8jOto7EuAD2t5GeGk27eitJwFt3iyIp5y X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:9682:b0:69b:c01:82a5 with SMTP id 00721157ae682-6e9d8b89f8amr11429747b3.7.1730283525807; Wed, 30 Oct 2024 03:18:45 -0700 (PDT) Date: Wed, 30 Oct 2024 11:18:12 +0100 In-Reply-To: <20241030101803.2037606-10-ardb+git@google.com> Mime-Version: 1.0 References: <20241030101803.2037606-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1757; i=ardb@kernel.org; h=from:subject; bh=GbwFno5F+PIqgoDy9QYiqnwQa9iDjNg0VPN0fHtr9z0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV2J/bnIwZZp+slTLQy8f8f5P/x5vHqBnEsh84JFAesdK oVPFW7pKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNZ18zwh3uvrHbGsTnTw8Kd eL2fT+9I1a/sTPre9WrnoXWnT7ZMvMXI0B+71t/0riuPF8Mui5eb8/8n6fqZlytwe745kmOzbLk rEwA= X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030101803.2037606-18-ardb+git@google.com> Subject: [RFC PATCH 8/8] arm64/mm: Account for reduced VA sizes in T0SZ and skip the levels From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, 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-20241030_031847_728971_0B5E7238 X-CRM114-Status: GOOD ( 14.87 ) 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 Now that a smaller value for TASK_SIZE is used when running with a reduced virtual address space for userland, it is guaranteed that only the first entry of each root level page table is populated. This means that we can reduce the number of levels of translation performed by the MMU by programming this entry into TTBR0_EL1 directly, and updating T0SZ accordingly. This is a quick and dirty hack, but should reap all the benefits in terms of MMU performance and reduced TLB pressure, at the cost of one wasted page per process (or 2 on 52-bit VA capable hardware). Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu_context.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 48b3d9553b67..99777da39228 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -57,7 +57,13 @@ void cpu_do_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); static inline void cpu_switch_mm(pgd_t *pgd, struct mm_struct *mm) { + int advance = (vabits_actual - CONFIG_TASK_SIZE_BITS) / (PAGE_SHIFT - 3); + BUG_ON(pgd == swapper_pg_dir); + + while (advance-- > 0) + pgd = __va(__pgd_to_phys(*pgd)); + cpu_do_switch_mm(virt_to_phys(pgd),mm); } @@ -82,7 +88,8 @@ static inline void __cpu_set_tcr_t0sz(unsigned long t0sz) isb(); } -#define cpu_set_default_tcr_t0sz() __cpu_set_tcr_t0sz(TCR_T0SZ(vabits_actual)) +#define cpu_set_default_tcr_t0sz() __cpu_set_tcr_t0sz(TCR_T0SZ(MIN(vabits_actual, \ + CONFIG_TASK_SIZE_BITS))) #define cpu_set_idmap_tcr_t0sz() __cpu_set_tcr_t0sz(idmap_t0sz) /*