From patchwork Thu Dec 12 08:18:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904797 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 410B4E7717F for ; Thu, 12 Dec 2024 08:22:07 +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=o1eR/nZYWDy7JnUFA+IXxK3QIAKZs/ki75z6WryhmEE=; b=45jbliquIyLjNJaPs1dE00sVvo fAs4c4mD9WpoEmFitF/qEqT0bkBc5sTbfr1A4eQUfr15lCLsziEUJpj8DNok9dQFGGYex3WH4NMoJ wXCfZiJdzZBzUilyMUetzuWojh9eIxu3GKky4DJKImBg7oKEiXbom3vqh3t5zNMJ48Xey3rxUX5yW X9Hcbyz6oLssx0wmMNoVANoh3BuhzhFy7xp/rONiYt6pZFNT4T5NMy1JYEELA5x+tBzc4+RBeqkqk mbC5oj0PQ2EmB6SjQyuJxRbO45Z4QmUME6Uw3cNxdlbgfL2wM2KQjkC7njIgv1kAk1cbYakNTuaI2 OxHpoOtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeSH-0000000HHae-02rh; Thu, 12 Dec 2024 08:21:53 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLePV-0000000HGiU-3wG7 for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:02 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so2860365e9.3 for ; Thu, 12 Dec 2024 00:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991539; x=1734596339; 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=o1eR/nZYWDy7JnUFA+IXxK3QIAKZs/ki75z6WryhmEE=; b=y1TzEsh6i/WPS8bZB/wO6sNRt1tDMidjxWCvG2c3kcO5S3FUYNa7ANX5/gICbmkQtH PKXoLeWQpRU00u69Ku79pv1vwTM31zdY97x00uYSwYwCP/pVb41pnB8jDnBY06VqMhIV alSxi6JwDrUXSQhGblASKXTpkBthjmDMxp/Pnggx8Dz6ELyeVWwyYSeepOuzc0t/zwrL 1XGjMXULVhOYdhVHZEXhOvABhO2UqtSIO5hoHPHwn+b+0RIxNwbEIdcXLOO2jNC4o/mJ aZvnkYCl5wK8GzgDVRx+LGgsSdC3+nA4WOteE5APT6+k9exRzJluwoh1m0HdDamYgeKs kGqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991539; x=1734596339; 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=o1eR/nZYWDy7JnUFA+IXxK3QIAKZs/ki75z6WryhmEE=; b=fI856UE8lc8FAmG/eR2cKXMH7fI4rwpTSccJmfnTPsT3zkTuYWE46vvqBbHlrfRq0x PjOFDOL99ds3Yjh7+M9pRpAIkjdx7vZEH27CRrV4xzvujkOOtkqyfEm8F2Ykml6UoKEU O1ogthjTLsboGKUUdOgE26Wi9uirveYiqiRPvdtU/J7JfoPdn2zsszktRXAuuKU/62NT /Uj1HXTNKL9NQJWSeT6yfFPTB1P6lghO4M9zjpbuRS2JlwDfkZsXCnTZK5d3XnSvZZd0 bxNVw+9rf2fLIyWKwJu7N/7dV5UgzL4xE9sPbTMrGjlOzRMTROMDhsD4L2Et9jXkjhPS 2q+Q== X-Gm-Message-State: AOJu0YxQXvyDgnZY9Vv0wsN7xfnGX5l1LUNEP8pegvWjt0RoUlThi8Ix 5S+o7QA7T9axfSTfRH0J+z4vyhRi8rdfmHi8fz1m5JpafnaklyAXKrPvvf2PBWHTBh6qFQd6rXI 8GbWakO46lrKgp1PWJBO4NdB2K+CBWxfiU1AXTkcP3Cr1rgm4aSRvdjnQKHIYB7rU//9q2dRvtC Trv/hBgcWU3eD1WhGMlJXkZirUtasqTh5AnKVRew+M X-Google-Smtp-Source: AGHT+IGFCr+ILtDVl2I89l402u827GSiQNpyuMXKvIlTJVWCnPRqtE/rGoww4lT3RPPpvSl62IgYuB0T X-Received: from wmbjl17.prod.google.com ([2002:a05:600c:6a91:b0:434:f1d0:7dc9]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3acf:b0:434:f8a0:9dd8 with SMTP id 5b1f17b1804b1-4361c345006mr43908945e9.1.1733991539243; Thu, 12 Dec 2024 00:18:59 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:43 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3310; i=ardb@kernel.org; h=from:subject; bh=6f63k+zdnDPwoV97pZOXKmLYrRvOc+ffRW8gf6CiYQc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTrKo0a3oN1wHTtdf0f30szBTp23N+v4dx//IP2pct 76saO2UjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjAR0Q+MDPfPvVh+Tmqatu21 lEWKL1c0BX40+O93iFvmyIV32WHP6nkZGeYtYw8WiPs7dbfhv+4oo5aJWVEfv7yODYy2tFBMnl5 RwgsA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-9-ardb+git@google.com> Subject: [PATCH v3 1/6] arm64/mm: Reduce PA space to 48 bits when LPA2 is not enabled 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 , Quentin Perret , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001901_976998_AFCD9CE4 X-CRM114-Status: GOOD ( 15.68 ) 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 Currently, LPA2 kernel support implies support for up to 52 bits of physical addressing, and this is reflected in global definitions such as PHYS_MASK_SHIFT and MAX_PHYSMEM_BITS. This is potentially problematic, given that LPA2 hardware support is modeled as a CPU feature which can be overridden, and with LPA2 hardware support turned off, attempting to map physical regions with address bits [51:48] set (which may exist on LPA2 capable systems booting with arm64.nolva) will result in corrupted mappings with a truncated output address and bogus shareability attributes. This means that the accepted physical address range in the mapping routines should be at most 48 bits wide when LPA2 support is configured but not enabled at runtime. Fixes: 352b0395b505 ("arm64: Enable 52-bit virtual addressing for 4k and 16k granule configs") Cc: Reviewed-by: Anshuman Khandual Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/pgtable-hwdef.h | 6 ------ arch/arm64/include/asm/pgtable-prot.h | 7 +++++++ arch/arm64/include/asm/sparsemem.h | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index c78a988cca93..a9136cc551cc 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -222,12 +222,6 @@ */ #define S1_TABLE_AP (_AT(pmdval_t, 3) << 61) -/* - * Highest possible physical address supported. - */ -#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) -#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) - #define TTBR_CNP_BIT (UL(1) << 0) /* diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 9f9cf13bbd95..a95f1f77bb39 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -81,6 +81,7 @@ extern unsigned long prot_ns_shared; #define lpa2_is_enabled() false #define PTE_MAYBE_SHARED PTE_SHARED #define PMD_MAYBE_SHARED PMD_SECT_S +#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) #else static inline bool __pure lpa2_is_enabled(void) { @@ -89,8 +90,14 @@ static inline bool __pure lpa2_is_enabled(void) #define PTE_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PTE_SHARED) #define PMD_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PMD_SECT_S) +#define PHYS_MASK_SHIFT (lpa2_is_enabled() ? CONFIG_ARM64_PA_BITS : 48) #endif +/* + * Highest possible physical address supported. + */ +#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) + /* * If we have userspace only BTI we don't want to mark kernel pages * guarded even if the system does support BTI. diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h index 8a8acc220371..84783efdc9d1 100644 --- a/arch/arm64/include/asm/sparsemem.h +++ b/arch/arm64/include/asm/sparsemem.h @@ -5,7 +5,10 @@ #ifndef __ASM_SPARSEMEM_H #define __ASM_SPARSEMEM_H -#define MAX_PHYSMEM_BITS CONFIG_ARM64_PA_BITS +#include + +#define MAX_PHYSMEM_BITS PHYS_MASK_SHIFT +#define MAX_POSSIBLE_PHYSMEM_BITS (52) /* * Section size must be at least 512MB for 64K base From patchwork Thu Dec 12 08:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904798 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 A7D4AE7717F for ; Thu, 12 Dec 2024 08:23:07 +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=2hytoeGuBGhQsTErvMf3yZxZWvdEkxkHmgM5PMFEUtg=; b=c855Qkz7GOC1BP33HrYRZiRtUt AefcJ3XSWIySyhLq4MXSDE35xXI0yfuDTnavCVCS3kaDubfitvG+QLN2SRBqhza9r2FnHj74QpU+X spnB8v8IdWkX8sOlNKIFgemKdoF0cBE1jyQGb0JQSNBJDnYgulnsXXC29Pn9RoqEsR1+4yMB/gGvr Ed5/NL++8kPZ9xAMX47kX5eUKIvku8XmGtr39VxveMzALLaC6iztB06fSOYeFizShQF/HO+PCa6Ux eQzUkPB+VbDLxsbU/fV2dByYXeVT+IFo+oQcOehXTsG1C3USFPkHCyeXFyZpO/fnRLG8+e9SUiwVz Z9wDfxnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeTI-0000000HHlo-2bff; Thu, 12 Dec 2024 08:22:56 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLePW-0000000HGjC-42JD for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:04 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so2524235e9.2 for ; Thu, 12 Dec 2024 00:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991541; x=1734596341; 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=2hytoeGuBGhQsTErvMf3yZxZWvdEkxkHmgM5PMFEUtg=; b=lfJNeMRlLd3k1ktDqVv+wFDofoBreG8mwjcMkpiBleLZhapDNfs86dpbMTse9y6AvX +fFVLhOiN/S0zi97GetZhdv/y0QqHDhvaa/3A41ncARqJO2hpV8QNq/rcNtTBnR66pSL iEE0GmtQ0e53ZE/t5hktjsDiSgUtJ7EhZYAsyxn3e9Ty0WAeYQg7fwWZfbuDvXru1z8O hOl1spQzGgNzosd78x16S1ipm6QCzHX3m49cFcCSctF7hSOrdMP3/d/sy+BpD4H+Uo9O jKn4DJxUhAQY/00FQZ/3W0fBhl0E5iEowd1qtmteCgvqZ7fj3aErv0bh83zbrDYdGSh6 4rNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991541; x=1734596341; 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=2hytoeGuBGhQsTErvMf3yZxZWvdEkxkHmgM5PMFEUtg=; b=iIsvRCU0owQg/62mE3FAHr3YLu6IPCH+978GtsKt+xvEYLlBNglZknUSNZaTJMncmo rijQEsVwMMBNb5zUdvxrL+pWetruguXQwIA4nZLLO1jYPUXt+Dr/J/akaWiRjJr5ftD7 3aoAZMpiHKebywYcrQFWRFR5kWzjAVZZA/nOTZt9p6v+dnu4hJORtxrJCxsVLQKVs+dW aPNE2W0EWOhez68ODFQrAzC1yixFNNCElCzN9h71NSfpbqOzHV8fOFcziUPpSaUTabkN 6l5SQq3PJC82imFyMuJJLAB+x0O7O2lcr2+JogkXDz/6/ia1yZHTCLPsrNq58sJv+dUN m24g== X-Gm-Message-State: AOJu0YxkbXPx6QEoerf22zonQ0tBMxFgVJuRNO5mKwUxED79BYUFLRtl /Axc8oPoguTqKtbfgt4lyQg9JpwqcGWbQVXp1MKz2T983UUbEl8dqwq2C3AzxsrSJLfQlK17kvU D5KqKT5rjYYiJluxWECWB06XtfR242/U4LfHN5Gf8QMDB3R7ERG1arvG4L68dakcNtQYhYCmSTN PqtSj9ErdRfW4pKkPksd6/7KvtFczMxjA2xaIXQHba X-Google-Smtp-Source: AGHT+IEGYsYtFhuo1M+mXxwr1oPLrb4FHzvmxqJpmKzmSM6VR7FR039Eo4mTnt9ojOSbZqHRyAKca3wz X-Received: from wmee4.prod.google.com ([2002:a05:600c:2184:b0:434:f2eb:aa72]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:190c:b0:434:fe62:28c1 with SMTP id 5b1f17b1804b1-43622842fe4mr19916235e9.18.1733991541383; Thu, 12 Dec 2024 00:19:01 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:44 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4458; i=ardb@kernel.org; h=from:subject; bh=sxVQfPUsQxyoLylOvN26XLQadF9/wxwUb33vSk2ahfI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTur1D0H+U+c0Oh3k/7fY2m9Tvtv6JrPF/g+Z/q4oz 2tbGnKoo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEykxIXhf/BxLV/To+f/h2of CzpiU5aroGt51O/cxPIvmscNVMwOP2Bk+F9k6SMTXssv+fCnKHMSz4GvK3OWVls23FAM+LvUb8o KBgA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-10-ardb+git@google.com> Subject: [PATCH v3 2/6] arm64/mm: Override PARange for !LPA2 and use it consistently 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 , Quentin Perret , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001903_010953_9D850F4A X-CRM114-Status: GOOD ( 16.80 ) 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 When FEAT_LPA{,2} are not implemented, the ID_AA64MMFR0_EL1.PARange and TCR.IPS values corresponding with 52-bit physical addressing are reserved. Setting the TCR.IPS field to 0b110 (52-bit physical addressing) has side effects, such as how the TTBRn_ELx.BADDR fields are interpreted, and so it is important that disabling FEAT_LPA2 (by overriding the ID_AA64MMFR0.TGran fields) also presents a PARange field consistent with that. So limit the field to 48 bits unless LPA2 is enabled, and update existing references to use the override consistently. Fixes: 352b0395b505 ("arm64: Enable 52-bit virtual addressing for 4k and 16k granule configs") Cc: Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/assembler.h | 5 +++++ arch/arm64/kernel/cpufeature.c | 2 +- arch/arm64/kernel/pi/idreg-override.c | 9 +++++++++ arch/arm64/kernel/pi/map_kernel.c | 6 ++++++ arch/arm64/mm/init.c | 7 ++++++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 3d8d534a7a77..ad63457a05c5 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -343,6 +343,11 @@ alternative_cb_end // Narrow PARange to fit the PS field in TCR_ELx ubfx \tmp0, \tmp0, #ID_AA64MMFR0_EL1_PARANGE_SHIFT, #3 mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_MAX +#ifdef CONFIG_ARM64_LPA2 +alternative_if_not ARM64_HAS_VA52 + mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_48 +alternative_else_nop_endif +#endif cmp \tmp0, \tmp1 csel \tmp0, \tmp1, \tmp0, hi bfi \tcr, \tmp0, \pos, #3 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 6ce71f444ed8..f8cb8a6ab98a 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -3478,7 +3478,7 @@ static void verify_hyp_capabilities(void) return; safe_mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); - mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); /* Verify VMID bits */ diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index 22159251eb3a..c6b185b885f7 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -83,6 +83,15 @@ static bool __init mmfr2_varange_filter(u64 val) id_aa64mmfr0_override.val |= (ID_AA64MMFR0_EL1_TGRAN_LPA2 - 1) << ID_AA64MMFR0_EL1_TGRAN_SHIFT; id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_TGRAN_SHIFT; + + /* + * Override PARange to 48 bits - the override will just be + * ignored if the actual PARange is smaller, but this is + * unlikely to be the case for LPA2 capable silicon. + */ + id_aa64mmfr0_override.val |= + ID_AA64MMFR0_EL1_PARANGE_48 << ID_AA64MMFR0_EL1_PARANGE_SHIFT; + id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_PARANGE_SHIFT; } #endif return true; diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_kernel.c index f374a3e5a5fe..e57b043f324b 100644 --- a/arch/arm64/kernel/pi/map_kernel.c +++ b/arch/arm64/kernel/pi/map_kernel.c @@ -136,6 +136,12 @@ static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(u64 ttbr) { u64 sctlr = read_sysreg(sctlr_el1); u64 tcr = read_sysreg(tcr_el1) | TCR_DS; + u64 mmfr0 = read_sysreg(id_aa64mmfr0_el1); + u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_EL1_PARANGE_SHIFT); + + tcr &= ~TCR_IPS_MASK; + tcr |= parange << TCR_IPS_SHIFT; asm(" msr sctlr_el1, %0 ;" " isb ;" diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d21f67d67cf5..2b2289d55eaa 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -280,7 +280,12 @@ void __init arm64_memblock_init(void) if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { extern u16 memstart_offset_seed; - u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); + + /* + * Use the sanitised version of id_aa64mmfr0_el1 so that linear + * map randomization can be enabled by shrinking the IPA space. + */ + u64 mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); int parange = cpuid_feature_extract_unsigned_field( mmfr0, ID_AA64MMFR0_EL1_PARANGE_SHIFT); s64 range = linear_region_size - From patchwork Thu Dec 12 08:18:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904802 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 E8728E7717F for ; Thu, 12 Dec 2024 08:24: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: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=JMOjAKt7SYh21CnU2/gurhD18i4qBMjjU7YQtDJALn4=; b=uDYX5NRZPXs7Tvw/ScaNIoMr0H S5+or7SllgJY7RoNF77TnBnUjNMBUqq3VqjgIeaDu6Rt0fO0KFQCe8WoM9bhVLT4AziIwHU0LpZio QqBod12egUvaZhQH/7hon34ywOl5z7e7lVTW0dyDgryWZiGfZ6PbaZW+ggDxKorp0Vae6cRDAyZHn b0G7J+3ippb1eH15MhBPSORWwIZxxhbRqNuMzVuLBS1Bm20cSilleyxK2559m1XnnBbqzzH7Q2m/J kBzURrZRYA2eC3LapQGKcZiRiLiH5+RJN9DsNYJLCIvIIXUnNLuW17WFlAvRA8V0YNMBuhN0Jh3ng vzY81iqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeUL-0000000HHwI-0p66; Thu, 12 Dec 2024 08:24:01 +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 1tLePZ-0000000HGkI-0jGQ for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:06 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso1817705e9.1 for ; Thu, 12 Dec 2024 00:19:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991543; x=1734596343; 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=JMOjAKt7SYh21CnU2/gurhD18i4qBMjjU7YQtDJALn4=; b=Dztpa1DmS/FqF6CroiaWhoH4m3qDdv4iZ/k7SWx4JdhtOAnjoywPBtRQfKE0vS19VA jHEEVxhp6IdJpYrADJOY2/c46Mw6K7UXjz8wpziOfMeHkHOSmamJxKQuY5sGegUCeAdN 1tSjL0WnguCymFjF1QB+AT0DgnPA/0V1bv3CLgMVl3h7e/PBLYX2ZiOlYR2Rn8eNxuc2 pqMym0fqa7LpxCgLUnfsf3Z2jdaO6i6mKSXsO6PDK8qSAhmvlh6Ooq+EHBprl0rx7uh4 XxPFextgi5v1jHy02za0usS6G9+/Mbg8w/ad8oWQNAVJfE5sRyM9ZMTfeL2KX/5NA9Bn sXIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991543; x=1734596343; 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=JMOjAKt7SYh21CnU2/gurhD18i4qBMjjU7YQtDJALn4=; b=XXk9F1iFlbqvtjr5y4YLT+gcva0KfoCEHRAGYd+GaaIpdUSS0ZpCchovLJPHMb2JEi HF045apwy1nzqfcufHxv/kw37fLuS20UgaqHt5SIB2CkKzdrZwgOmFGG8ppRt8NDy58d TrpGLMj/FsRgTUbmU7+y6xf43X9HaGURPcpNdv55Ksjo6vxkdctG+IZZ2AuP3Mr6/65S F9igjF4sgNibQ70Sk/nkTjzVDcRuVz0p/aSAzgouKYk00JIh5E82eagb6NKEIjzcX3O6 iQoRzq6hx0gwcq4aaPs27RMAjFsQjqFP/lmQkI8AxzzT+Rk7nSWuojnU2jCfW+JI8B0P DEKw== X-Gm-Message-State: AOJu0Ywpjq6itvDYLC/EIzd//2iWg9hIx0oPp44r4/+x0og6aLtMHxvd amVtmNtivD06m74YAqO4CYhzlKF9EeFqI6cnfIKMdm1Ul/ZnsbfGr+N+8PDRvn1dvnuVSOE0oVI 7yXfFLg4qZLXxGxZzNOStVXpmk8ZtLbui1pXApKkRge6G2HSaw5Cp7QnceFGzfYuWGnG7yjTBAq 5oAMDylTQwL6UuKgHWcwaIwwzG93Lwn9DEAzGmicYF X-Google-Smtp-Source: AGHT+IGEPZXeZNx8gT7l0K6n8hjylpD9slamcamh+DZ/t1Et8nSF8q/2TqsFY0uo9/d5Ix+2xT283bTa X-Received: from wmee4.prod.google.com ([2002:a05:600c:2184:b0:434:f2eb:aa72]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3109:b0:434:fafe:edb with SMTP id 5b1f17b1804b1-4361c3e22e7mr42421225e9.24.1733991543459; Thu, 12 Dec 2024 00:19:03 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:45 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2178; i=ardb@kernel.org; h=from:subject; bh=rw9Vhm4jDehzLkAS6zRdIPR2y59w9k4f1UOcpcAZYnI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTlrdArlJHb3+TBsqGsoKNB8W9Z027b7oFacqcWXDr YrT6/52lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIlUzmX4zX4/6nDo9FP3mzZI uV3zzz+6pfK36PIlc2r+ntb2zQqVPsDwv3pBaqX9/pkC57imvot+L9+VGLnZ8Mu2ZI60JsUWb20 5ZgA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-11-ardb+git@google.com> Subject: [PATCH v3 3/6] arm64/kvm: Configure HYP TCR.PS/DS based on host stage1 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 , Quentin Perret , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001905_213902_46396C7E X-CRM114-Status: GOOD ( 17.19 ) 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 When the host stage1 is configured for LPA2, the value currently being programmed into TCR_EL2.T0SZ may be invalid unless LPA2 is configured at HYP as well. This means kvm_lpa2_is_enabled() is not the right condition to test when setting TCR_EL2.DS, as it will return false if LPA2 is only available for stage 1 but not for stage 2. Similary, programming TCR_EL2.PS based on a limited IPA range due to lack of stage2 LPA2 support could potentially result in problems. So use lpa2_is_enabled() instead, and set the PS field according to the host's IPS, which is capped at 48 bits if LPA2 support is absent or disabled. Whether or not we can make meaningful use of such a configuration is a different question. Cc: Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/arm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a102c3aebdbc..7b2735ad32e9 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1990,8 +1990,7 @@ static int kvm_init_vector_slots(void) static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits) { struct kvm_nvhe_init_params *params = per_cpu_ptr_nvhe_sym(kvm_init_params, cpu); - u64 mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); - unsigned long tcr; + unsigned long tcr, ips; /* * Calculate the raw per-cpu offset without a translation from the @@ -2005,6 +2004,7 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits) params->mair_el2 = read_sysreg(mair_el1); tcr = read_sysreg(tcr_el1); + ips = FIELD_GET(TCR_IPS_MASK, tcr); if (cpus_have_final_cap(ARM64_KVM_HVHE)) { tcr |= TCR_EPD1_MASK; } else { @@ -2014,8 +2014,8 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits) tcr &= ~TCR_T0SZ_MASK; tcr |= TCR_T0SZ(hyp_va_bits); tcr &= ~TCR_EL2_PS_MASK; - tcr |= FIELD_PREP(TCR_EL2_PS_MASK, kvm_get_parange(mmfr0)); - if (kvm_lpa2_is_enabled()) + tcr |= FIELD_PREP(TCR_EL2_PS_MASK, ips); + if (lpa2_is_enabled()) tcr |= TCR_EL2_DS; params->tcr_el2 = tcr; From patchwork Thu Dec 12 08:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904803 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 DC989E7717F for ; Thu, 12 Dec 2024 08:25:20 +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=6isFNd8zHOf41Of/wjxlI+b9qTAIYvxlEpDr2EkvB3U=; b=AMAewcmc/BjC4idf01rQJfWOfw IOARQWwH7rh7YhM2xwCRdibYpoGH71U7UAFqhEa8J4R42E4zTL4KfylZJCztzNp+gV5Rup3tPjnNs ppwQnh+n03c/tVaHrxM4QlOaK1aAPVZaqGCGMrO256u+YTgQfg/cujNi6aLhk+pLHcPlAjtARCEqt m4WLFe3DuLxioyu4WrthWofFQ6TTGf3Ena0aAHwHxk3niAkPuB8RbD2k/tYmMjIHYeq9HHWeIufx+ 3CvqoAt8vlDRjvKUBM5jC7/IxgWuvj2X7YFZ7IaeBdX91wY3ywnLHMwU+WHhYmbqVOLVFva3Lbhj2 t+HAyN7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeVM-0000000HI2L-3kxV; Thu, 12 Dec 2024 08:25:04 +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 1tLePb-0000000HGl7-1CDG for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:08 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-434fe2b605eso1921665e9.2 for ; Thu, 12 Dec 2024 00:19:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991545; x=1734596345; 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=6isFNd8zHOf41Of/wjxlI+b9qTAIYvxlEpDr2EkvB3U=; b=itsq4h8XjleQB6LO7pehLy2SBuSoKtnBo8Yz43rxCoJYL8ORrDR/P3yF7jj8ivyv/Q hUSzLWLK32tr5/i2XhSsJrf4uAjaUHCBigE7pbYQ1jtQeGXhTaOcMaHfygBHqIOktZBJ RaFFUQ+A/0mgaY3i5QDMjk/n3EHMaVQRn+g8nWzeOEvl31JAXKxojMtWtWAHKih53psR Cvnh2K/ger2ORnN2EAmSlifycG368sO61YDJJ6N1ZAQhqrbbjP5CR8kCH0Y+SjQOPOv5 ky6CHTrCKZYV2XnA5HfBbdqlRy2siTeSXkvD+v3+lqEjZai5GM1vb5q3zs7/j/KJ/VVN /bAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991545; x=1734596345; 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=6isFNd8zHOf41Of/wjxlI+b9qTAIYvxlEpDr2EkvB3U=; b=EqyBEfHDB73I8jFvDK0VTwl2xEpK1TSjNa9OVPxclD66SprudG8mfvwBiYcbjSzpC1 FaLLdp7V8j7n+qrCorH97TZd6uyMb2ROmWMXWEtvTvkwT0/9dXajK0NAlhilmQhUvOB4 CieKIofSpUPu1Y+HHVC0yqOC9+qOoYHIc7iqOSTyskG/dvlj3eaOvRrPhelEc9qENpa3 8EUXW+9U/ytD+5wdjo+IIXRqCjQbi8/4XBE39mytAUrr7bYOhHHO0NqwGseuojSJXTea IsMWb0I4Av+PKK15S95yivB/8mnMPV14E+COeY4iU7arvdK/4ogJLUh+j3Zm0M+/CDi+ /x3w== X-Gm-Message-State: AOJu0YzYtyQQ9HKYWRTa16UQHJUjfowBgepHkMYptJelx93XIJry6AyZ NVvsvX+JU7ZGE/Qw1BYjOuR5KdQQdHc9qNA8b3Qzw34KvUEsLanMEyKGlx/4y2ZfSdPZalvOUEw tnOimsA8gImzHMXMETFFu+jEULgvzMLN4wmJsInV+n5/0d5PV3Qy/FdwJFM1uIz1UNJJd4pTXlz ijKA8HyBrAArhAOomiKsx3tuM0YiNkJd2WxqMHI2+Y X-Google-Smtp-Source: AGHT+IGiNwt46ersFJk8J3W4FvXc0YIFm/aDF3p261C7M4Bc1ps+NMc5UV9QpUddAEBdOk7TXMj8hL3G X-Received: from wmfv7.prod.google.com ([2002:a05:600c:15c7:b0:431:1903:8a3e]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:468a:b0:434:f0df:a14 with SMTP id 5b1f17b1804b1-4361c34623dmr48042095e9.2.1733991545427; Thu, 12 Dec 2024 00:19:05 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:46 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4036; i=ardb@kernel.org; h=from:subject; bh=wxQBa7Qia0zG9OkBtRYf+Ymgq0cT+W+pOrTZLi6s8yQ=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTnpY6bHtf7P6ePhaAiaXMSobvfSe5hBzWDJBMM308 rUKv7COUhYGMQ4GWTFFFoHZf9/tPD1RqtZ5lizMHFYmkCEMXJwCMBHLpQz/lAy4y1iv/gk7c5Pf 43HPlMeTvzDt/SSVFRO2fd8xC+01JQz/6w49Ovvy3pzpBR22RWy3irYtb9G3Wc7Xs3NS0IHlk67 eYgQA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-12-ardb+git@google.com> Subject: [PATCH v3 4/6] arm64/kvm: Avoid invalid physical addresses to signal owner updates 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 , Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001907_323341_3A9408CD X-CRM114-Status: GOOD ( 19.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 The pKVM stage2 mapping code relies on an invalid physical address to signal to the internal API that only the annotations of descriptors should be updated, and these are stored in the high bits of invalid descriptors covering memory that has been donated to protected guests, and is therefore unmapped from the host stage-2 page tables. Given that these invalid PAs are never stored into the descriptors, it is better to rely on an explicit flag, to clarify the API and to avoid confusion regarding whether or not the output address of a descriptor can ever be invalid to begin with (which is not the case with LPA2). That removes a dependency on the logic that reasons about the maximum PA range, which differs on LPA2 capable CPUs based on whether LPA2 is enabled or not, and will be further clarified in subsequent patches. Cc: Quentin Perret Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/hyp/pgtable.c | 33 ++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 40bd55966540..ed600126161a 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -35,14 +35,6 @@ static bool kvm_pgtable_walk_skip_cmo(const struct kvm_pgtable_visit_ctx *ctx) return unlikely(ctx->flags & KVM_PGTABLE_WALK_SKIP_CMO); } -static bool kvm_phys_is_valid(u64 phys) -{ - u64 parange_max = kvm_get_parange_max(); - u8 shift = id_aa64mmfr0_parange_to_phys_shift(parange_max); - - return phys < BIT(shift); -} - static bool kvm_block_mapping_supported(const struct kvm_pgtable_visit_ctx *ctx, u64 phys) { u64 granule = kvm_granule_size(ctx->level); @@ -53,7 +45,7 @@ static bool kvm_block_mapping_supported(const struct kvm_pgtable_visit_ctx *ctx, if (granule > (ctx->end - ctx->addr)) return false; - if (kvm_phys_is_valid(phys) && !IS_ALIGNED(phys, granule)) + if (!IS_ALIGNED(phys, granule)) return false; return IS_ALIGNED(ctx->addr, granule); @@ -587,6 +579,9 @@ struct stage2_map_data { /* Force mappings to page granularity */ bool force_pte; + + /* Walk should update owner_id only */ + bool annotation; }; u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift) @@ -885,18 +880,7 @@ static u64 stage2_map_walker_phys_addr(const struct kvm_pgtable_visit_ctx *ctx, { u64 phys = data->phys; - /* - * Stage-2 walks to update ownership data are communicated to the map - * walker using an invalid PA. Avoid offsetting an already invalid PA, - * which could overflow and make the address valid again. - */ - if (!kvm_phys_is_valid(phys)) - return phys; - - /* - * Otherwise, work out the correct PA based on how far the walk has - * gotten. - */ + /* Work out the correct PA based on how far the walk has gotten */ return phys + (ctx->addr - ctx->start); } @@ -908,6 +892,9 @@ static bool stage2_leaf_mapping_allowed(const struct kvm_pgtable_visit_ctx *ctx, if (data->force_pte && ctx->level < KVM_PGTABLE_LAST_LEVEL) return false; + if (data->annotation && ctx->level == KVM_PGTABLE_LAST_LEVEL) + return true; + return kvm_block_mapping_supported(ctx, phys); } @@ -923,7 +910,7 @@ static int stage2_map_walker_try_leaf(const struct kvm_pgtable_visit_ctx *ctx, if (!stage2_leaf_mapping_allowed(ctx, data)) return -E2BIG; - if (kvm_phys_is_valid(phys)) + if (!data->annotation) new = kvm_init_valid_leaf_pte(phys, data->attr, ctx->level); else new = kvm_init_invalid_leaf_owner(data->owner_id); @@ -1085,11 +1072,11 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, { int ret; struct stage2_map_data map_data = { - .phys = KVM_PHYS_INVALID, .mmu = pgt->mmu, .memcache = mc, .owner_id = owner_id, .force_pte = true, + .annotation = true, }; struct kvm_pgtable_walker walker = { .cb = stage2_map_walker, From patchwork Thu Dec 12 08:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904804 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 8805BE7717F for ; Thu, 12 Dec 2024 08:26: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=HdgtdUqEBd5LKxpewIKQlxiAPN7TmKSwfgktC1/nR3M=; b=ZZ+pzY9s5vXZwDmGVoPVqtT7kn /goFzmdyo1YvwgnsoPwRB1ZEL6qDuih6X+cabl+cqG3UkbDTkECmuHe/DyvSbXrZUjb6BPbVOKDnr xjkUUL+3WrvqDVlBAfIIMTjVpI/Z+p4eQHqA/eG2Kv5XZvq0ohLKZShLQl7G3JaI6luBHiSsZh68P ca+z4X7LljENDvpVrT7kztnp+NFmBNTYHqCywNtiN+Fd4F3PC4P6deikQaCKp7R3k2nfKoSlkpGsx tafavvF0PwGzEgkfsjh0x0YRUa3/ajQ4XbwOs1qBH0DWgHKr+0WNrrU4gfOGSiesB7G3y1qvJzQNe 2yPmnUvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeWP-0000000HIMT-23DT; Thu, 12 Dec 2024 08:26:09 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLePd-0000000HGls-0wEl for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:10 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4361efc9dc6so1858455e9.3 for ; Thu, 12 Dec 2024 00:19:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991547; x=1734596347; 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=HdgtdUqEBd5LKxpewIKQlxiAPN7TmKSwfgktC1/nR3M=; b=svjDpZ5XwctKdKDnXC5OPvCO1+EEWGBPsEnpmQAcjF/XsfmJu5WVvFfowucBaF+HQL bo7NuDx+MX0YlvwvrnOIziHi38X5dOA3CxzIPwepZKPAvGoUnraMJ4MFVwJHxB4A8ISZ Srz8aN3DORWXPSv2YCR+ZPlJ7r7Sh00bOINWrkI48uaCxgMx/596fESnCkim9Ap2NW6R Ntx0HTtt10xUNWTW661fQotvZgOYyPTR8dKFueSy52dZQjPGc3N7aINIkTCYGmm0JcPd BgEByDIotHKBUcWEZxKtgTkYafH14TXmlVtvXqehB4U94lzhrOAc2jawMvWEi0iyZ0NJ 24yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991547; x=1734596347; 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=HdgtdUqEBd5LKxpewIKQlxiAPN7TmKSwfgktC1/nR3M=; b=LiNrYiW3MI7uL+RXzsAcm07a6dz73TB62z7WI5wkiSWpNiqFEc1JPLmpHKC89Yz7AC M6xXrqSc/tbZGp6pSLJJKgasbI1jZmTaiPTcP6ses6LoZwJDb9TNfe5EDujCMlfJhFin fj42ciizfikgpqq7s5F8UeLOirWrsnhL255qtlY0YIJETqpyVwHlgVb702J/oQ4a1hit lcJ4JJ9Z3d3ij0+m5p4AbqnHKlSEG5K8gwvJTFfZgw+bcUUUpD/5uasOZ6gV3v5+JPrv wm+rau1sfVOS1FArFGEKMX/4UHg3gslafWHQxuy1+ooV3CeDGWvJ96USkklv3AbdFGoK /w9g== X-Gm-Message-State: AOJu0YwvAFdotdrrCMqtt43M8ASPbJ6GbmfSGtwryPV+xUHsk2SRPkcA CK0A3wpXFe/PUJulUP9iXr3T+Hmqy/b3Fw7D6wyhbQtP5r5s5Ie0pmzS0Pl5pdFqIIC9G2RlppF JHKsUfaWgg/7vDiCBHHkM3yxI++RqRcUya9nuMVcGcXgE6ip1TdG0kBQHz2dwShJTK5BHS2RgIs H4JsAEB+m3K2hKjz8GZOtNmh3AdJ4lDkEQmBwsKA1m X-Google-Smtp-Source: AGHT+IGWPJvO6+9CCQmmFw3OSCuh5I3iyCbxp28yrcBF8dbr114C30A5zZAFQgAChqfAkJPHTDhYBmac X-Received: from wmqy11.prod.google.com ([2002:a05:600c:364b:b0:434:fc6f:e8c3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:ac7:b0:436:aaf:7eb9 with SMTP id 5b1f17b1804b1-4362285f79fmr17388455e9.20.1733991547419; Thu, 12 Dec 2024 00:19:07 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:47 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2690; i=ardb@kernel.org; h=from:subject; bh=vw43pFoSabaJKFXhQUhpwCIEl+ZhAtorVG0O+2+nOWw=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTub9hSnTjk48PK1RpV2XYXXNlqrNtyyiLh7s1n/+4 PPZT7ZRHaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiFxUZGQ6vfyod9Ht3of+P SYo920KmBTy4duOD/dJ7dlxsCjaKSv8Y/im7pDU+c+SIbvS/7bu477PN5Snpd9uubteI6Nf3Tlj byQIA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-13-ardb+git@google.com> Subject: [PATCH v3 5/6] 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 , Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001909_261511_5ACBB9E5 X-CRM114-Status: GOOD ( 14.11 ) 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 There are 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 100570a048c5..c1ca21adddc1 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1379,7 +1379,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 @@ -1431,7 +1430,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. @@ -1681,6 +1679,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 @@ -1937,7 +1936,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 @@ -2132,7 +2130,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 Thu Dec 12 08:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13904805 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 E8EE1E7717F for ; Thu, 12 Dec 2024 08:27:27 +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=Ey45ut0cYqhlv0rHJjDTgjPj+B5/bG+PQfUrVzCrXlU=; b=KN/7sClsH8/WYk3Qz/XTiGgyuE 8YYTeEeV+1t+B5b2SgLX1z/pRQ9M6TberA//6C4K+hlA/LZDt8vV5fWLgWwosRaGWBXzYPXa2kA4T ISzLQPE+Du6Zo7Aks52bSSLSIqm1DFLvAdRmjguHecTUP1KyEYFjZP0GKdeVtg1U9Xf4PfVL6M8uI VIqFHQaIt6wYthN46O97zRE1S573KiLoTjUlkuBAFEg8eOTa8j+MgcZK1CuTApcDPFZgsy8Uv+SJg EUykBT6FEjULeWfev8VjhkI2HEsPJExttCfOBORM+EBCe8wPAKkzzgQh8lrHOBopBK9IlYKsCN3bP WUvMEZdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLeXS-0000000HIZ8-0Rqu; Thu, 12 Dec 2024 08:27:14 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLePf-0000000HGmz-0yX5 for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2024 08:19:12 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4361efc9d23so2905025e9.3 for ; Thu, 12 Dec 2024 00:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733991549; x=1734596349; 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=Ey45ut0cYqhlv0rHJjDTgjPj+B5/bG+PQfUrVzCrXlU=; b=E4H0BenbnAq5ruMwuouDHT2fAiKsHk4+GlD0Pj9GDqd3FZ8rbTlAvU2xIHqADw7vyM rh7LdSpSWs4o5iJRUWvWiWBH9hdekfCiX7QPMGE4vrO2oAEFtAKXUruiAlypxE5Zk8lk fQNXPPMKX0COka40IgTXeMfIPGRH7VKKKe1sXQ0FNav+9T7Wex0pKejT9dZuxaRZihT8 85AZminT1Ki7E1l4I0IXDEJ71bViGtE7FoMgIm9ycLg1Jg92ZX19snBzx25v2kApNEg1 +/t/aK1teCAr0w9xVa4Lg7rQFydM5kXmz+5hjSl3ugU9nt0xkD5YurVLRo50G94QHQFc EOkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733991549; x=1734596349; 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=Ey45ut0cYqhlv0rHJjDTgjPj+B5/bG+PQfUrVzCrXlU=; b=dSfO4L47el+AIq67ySwa84/X0EmLB1ceD8qvO5h5oDcTDQ+CR8DXxhkvVasRI19ra7 PQmPqq2wddY++DXyqBa5+0feNQk07nSxbXgUF87/JSSDzB6gQ4WPfGk30p3BweQ2leOz s6krwN7h0lONZxIlcBaAFepPvW80i5xe+aCB2A2Gc3jEV/ldPExEgwtO/zxjmrAm/DKV fUYLRhk4TeUiadTSYkpNlsqHL7HI+AG87b8P9bMVk2Z8M54OdIrEx1AyPWU7EkqW1D7Y wq0ctDt2WAWnmkf3YuikkvDJSzd/Zwv37Z4JuIm2JrjUNMtpIiIlfRfI4iL4yJ7QtwPq rl1A== X-Gm-Message-State: AOJu0YzS3qbFAp+8Y3+A4f1JXCZ8KklTq49GFx/v3xbHbJo1tFSk2e1t BdLhOwHxQVt+AC+opy6Lx+Eq9xkRAkzPuH0eor7b1yXl03Tv9nVHPzy7E4DdOdX2qLihxk3KgMd JaG0PyQYPoxVKAoPUkF6Va0Q8C8lKBoruQvEnZDh6IPp9pQtM1OMEf/wzH3XGtIxZ5Vmw5/Bg/n zzPDyaulJcjGO0YLM27w2sM4ehEIxjedYJegbQQXl2 X-Google-Smtp-Source: AGHT+IFcDPi/tJJwAsl19d48itWuAeTtp0GYsuRI58iTvVH0YxvBQoA7Eq57mdP63vpaZu5145ucgqLD X-Received: from wmik9.prod.google.com ([2002:a7b:c409:0:b0:435:21e:7bec]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:35c9:b0:434:a734:d279 with SMTP id 5b1f17b1804b1-4361c3c6fbfmr55375515e9.16.1733991549429; Thu, 12 Dec 2024 00:19:09 -0800 (PST) Date: Thu, 12 Dec 2024 09:18:48 +0100 In-Reply-To: <20241212081841.2168124-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241212081841.2168124-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=11772; i=ardb@kernel.org; h=from:subject; bh=5i2/jnuksoamN8To8RDijcFECekYd7sFcR9Y5NN+knE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT1qTpaiim1ZUHnYtpPcJ1cbnzrNnHa2Q5ixr5TlhGWD8 uYVl106SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQq0hj+FzotbA6ceUY+nrGD 00ziSm6ve9Th6l3fN9Yy7J+aad3wkOGvoKfJC5XUS049d+8fqROcdqun5HrjogyHl8sLZTTaVVJ 5AQ== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241212081841.2168124-14-ardb+git@google.com> Subject: [PATCH v3 6/6] arm64/mm: Drop configurable 48-bit physical address space limit 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 , Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241212_001911_275750_4B561BA1 X-CRM114-Status: GOOD ( 23.10 ) 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 Currently, the maximum supported physical address space can be configured as either 48 bits or 52 bits. The only remaining difference between these in practice is that the former omits the masking and shifting required to construct TTBR and PTE values, which carry bits #48 and higher disjoint from the rest of the physical address. The overhead of performing these additional calculations is negligible, and so there is little reason to retain support for two different configurations, and we can simply support whatever the hardware supports. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 31 +------------------- arch/arm64/include/asm/assembler.h | 13 ++------ arch/arm64/include/asm/cpufeature.h | 3 +- arch/arm64/include/asm/kvm_pgtable.h | 3 +- arch/arm64/include/asm/pgtable-hwdef.h | 6 +--- arch/arm64/include/asm/pgtable-prot.h | 4 +-- arch/arm64/include/asm/pgtable.h | 11 +------ arch/arm64/include/asm/sysreg.h | 6 ---- arch/arm64/mm/pgd.c | 9 +++--- arch/arm64/mm/proc.S | 2 -- scripts/gdb/linux/constants.py.in | 1 - tools/arch/arm64/include/asm/sysreg.h | 6 ---- 12 files changed, 14 insertions(+), 81 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c1ca21adddc1..7ebd0ba32a32 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1416,38 +1416,9 @@ config ARM64_VA_BITS default 48 if ARM64_VA_BITS_48 default 52 if ARM64_VA_BITS_52 -choice - prompt "Physical address space size" - default ARM64_PA_BITS_48 - help - Choose the maximum physical address range that the kernel will - support. - -config ARM64_PA_BITS_48 - bool "48-bit" - depends on ARM64_64K_PAGES || !ARM64_VA_BITS_52 - -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. - - With this enabled, the kernel will also continue to work on CPUs that - do not support ARMv8.2-LPA, but with some added memory overhead (and - minor performance overhead). - -endchoice - -config ARM64_PA_BITS - int - default 48 if ARM64_PA_BITS_48 - default 52 if ARM64_PA_BITS_52 - config ARM64_LPA2 def_bool y - depends on ARM64_PA_BITS_52 && !ARM64_64K_PAGES + depends on !ARM64_64K_PAGES choice prompt "Endianness" diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index ad63457a05c5..01a1e3c16283 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -342,14 +342,13 @@ alternative_cb_end mrs \tmp0, ID_AA64MMFR0_EL1 // Narrow PARange to fit the PS field in TCR_ELx ubfx \tmp0, \tmp0, #ID_AA64MMFR0_EL1_PARANGE_SHIFT, #3 - mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_MAX #ifdef CONFIG_ARM64_LPA2 alternative_if_not ARM64_HAS_VA52 mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_48 -alternative_else_nop_endif -#endif cmp \tmp0, \tmp1 csel \tmp0, \tmp1, \tmp0, hi +alternative_else_nop_endif +#endif bfi \tcr, \tmp0, \pos, #3 .endm @@ -599,21 +598,13 @@ alternative_endif * ttbr: returns the TTBR value */ .macro phys_to_ttbr, ttbr, phys -#ifdef CONFIG_ARM64_PA_BITS_52 orr \ttbr, \phys, \phys, lsr #46 and \ttbr, \ttbr, #TTBR_BADDR_MASK_52 -#else - mov \ttbr, \phys -#endif .endm .macro phys_to_pte, pte, phys -#ifdef CONFIG_ARM64_PA_BITS_52 orr \pte, \phys, \phys, lsr #PTE_ADDR_HIGH_SHIFT and \pte, \pte, #PHYS_TO_PTE_ADDR_MASK -#else - mov \pte, \phys -#endif .endm /* diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index b64e49bd9d10..ed327358e734 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -885,9 +885,8 @@ static inline u32 id_aa64mmfr0_parange_to_phys_shift(int parange) * However, by the "D10.1.4 Principles of the ID scheme * for fields in ID registers", ARM DDI 0487C.a, any new * value is guaranteed to be higher than what we know already. - * As a safe limit, we return the limit supported by the kernel. */ - default: return CONFIG_ARM64_PA_BITS; + default: return 52; } } diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index aab04097b505..525aef178cb4 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -30,8 +30,7 @@ static inline u64 kvm_get_parange_max(void) { - if (kvm_lpa2_is_enabled() || - (IS_ENABLED(CONFIG_ARM64_PA_BITS_52) && PAGE_SHIFT == 16)) + if (kvm_lpa2_is_enabled() || PAGE_SHIFT == 16) return ID_AA64MMFR0_EL1_PARANGE_52; else return ID_AA64MMFR0_EL1_PARANGE_48; diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index a9136cc551cc..9b34180042b2 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -176,7 +176,6 @@ #define PTE_SWBITS_MASK _AT(pteval_t, (BIT(63) | GENMASK(58, 55))) #define PTE_ADDR_LOW (((_AT(pteval_t, 1) << (50 - PAGE_SHIFT)) - 1) << PAGE_SHIFT) -#ifdef CONFIG_ARM64_PA_BITS_52 #ifdef CONFIG_ARM64_64K_PAGES #define PTE_ADDR_HIGH (_AT(pteval_t, 0xf) << 12) #define PTE_ADDR_HIGH_SHIFT 36 @@ -186,7 +185,6 @@ #define PTE_ADDR_HIGH_SHIFT 42 #define PHYS_TO_PTE_ADDR_MASK GENMASK_ULL(49, 8) #endif -#endif /* * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers). @@ -327,12 +325,10 @@ /* * TTBR. */ -#ifdef CONFIG_ARM64_PA_BITS_52 /* - * TTBR_ELx[1] is RES0 in this configuration. + * TTBR_ELx[1] is RES0 when using 52-bit physical addressing */ #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 */ diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index a95f1f77bb39..b73acf25341f 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -81,7 +81,7 @@ extern unsigned long prot_ns_shared; #define lpa2_is_enabled() false #define PTE_MAYBE_SHARED PTE_SHARED #define PMD_MAYBE_SHARED PMD_SECT_S -#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) +#define PHYS_MASK_SHIFT (52) #else static inline bool __pure lpa2_is_enabled(void) { @@ -90,7 +90,7 @@ static inline bool __pure lpa2_is_enabled(void) #define PTE_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PTE_SHARED) #define PMD_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PMD_SECT_S) -#define PHYS_MASK_SHIFT (lpa2_is_enabled() ? CONFIG_ARM64_PA_BITS : 48) +#define PHYS_MASK_SHIFT (lpa2_is_enabled() ? 52 : 48) #endif /* diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 6986345b537a..ec8124d66b9c 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -69,10 +69,9 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; pr_err("%s:%d: bad pte %016llx.\n", __FILE__, __LINE__, pte_val(e)) /* - * Macros to convert between a physical address and its placement in a + * Helpers to convert between a physical address and its placement in a * page table entry, taking care of 52-bit addresses. */ -#ifdef CONFIG_ARM64_PA_BITS_52 static inline phys_addr_t __pte_to_phys(pte_t pte) { pte_val(pte) &= ~PTE_MAYBE_SHARED; @@ -83,10 +82,6 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) { return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK; } -#else -#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_LOW) -#define __phys_to_pte_val(phys) (phys) -#endif #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT) #define pfn_pte(pfn,prot) \ @@ -1495,11 +1490,7 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf, update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0) -#ifdef CONFIG_ARM64_PA_BITS_52 #define phys_to_ttbr(addr) (((addr) | ((addr) >> 46)) & TTBR_BADDR_MASK_52) -#else -#define phys_to_ttbr(addr) (addr) -#endif /* * On arm64 without hardware Access Flag, copying from user will fail because diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index b8303a83c0bf..f902893ec903 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -916,12 +916,6 @@ #define ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_LPA2 0x3 #define ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_MAX 0x7 -#ifdef CONFIG_ARM64_PA_BITS_52 -#define ID_AA64MMFR0_EL1_PARANGE_MAX ID_AA64MMFR0_EL1_PARANGE_52 -#else -#define ID_AA64MMFR0_EL1_PARANGE_MAX ID_AA64MMFR0_EL1_PARANGE_48 -#endif - #if defined(CONFIG_ARM64_4K_PAGES) #define ID_AA64MMFR0_EL1_TGRAN_SHIFT ID_AA64MMFR0_EL1_TGRAN4_SHIFT #define ID_AA64MMFR0_EL1_TGRAN_LPA2 ID_AA64MMFR0_EL1_TGRAN4_52_BIT diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c index 0c501cabc238..8722ab6d4b1c 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 pgd_size = PGD_SIZE; + 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 (PHYS_MASK_SHIFT >= 52) + pgd_size = max(pgd_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", pgd_size, pgd_size, SLAB_PANIC, NULL); } diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index b8edc5765441..51ed0e9d0a0d 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -197,10 +197,8 @@ SYM_FUNC_ALIAS(__pi_idmap_cpu_replace_ttbr1, idmap_cpu_replace_ttbr1) .macro pte_to_phys, phys, pte and \phys, \pte, #PTE_ADDR_LOW -#ifdef CONFIG_ARM64_PA_BITS_52 and \pte, \pte, #PTE_ADDR_HIGH orr \phys, \phys, \pte, lsl #PTE_ADDR_HIGH_SHIFT -#endif .endm .macro kpti_mk_tbl_ng, type, num_entries diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in index fd6bd69c5096..05034c0b8fd7 100644 --- a/scripts/gdb/linux/constants.py.in +++ b/scripts/gdb/linux/constants.py.in @@ -141,7 +141,6 @@ LX_CONFIG(CONFIG_ARM64_4K_PAGES) LX_CONFIG(CONFIG_ARM64_16K_PAGES) LX_CONFIG(CONFIG_ARM64_64K_PAGES) if IS_BUILTIN(CONFIG_ARM64): - LX_VALUE(CONFIG_ARM64_PA_BITS) LX_VALUE(CONFIG_ARM64_VA_BITS) LX_VALUE(CONFIG_PAGE_SHIFT) LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER) diff --git a/tools/arch/arm64/include/asm/sysreg.h b/tools/arch/arm64/include/asm/sysreg.h index cd8420e8c3ad..daeecb1a5366 100644 --- a/tools/arch/arm64/include/asm/sysreg.h +++ b/tools/arch/arm64/include/asm/sysreg.h @@ -574,12 +574,6 @@ #define ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_MIN 0x2 #define ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_MAX 0x7 -#ifdef CONFIG_ARM64_PA_BITS_52 -#define ID_AA64MMFR0_EL1_PARANGE_MAX ID_AA64MMFR0_EL1_PARANGE_52 -#else -#define ID_AA64MMFR0_EL1_PARANGE_MAX ID_AA64MMFR0_EL1_PARANGE_48 -#endif - #if defined(CONFIG_ARM64_4K_PAGES) #define ID_AA64MMFR0_EL1_TGRAN_SHIFT ID_AA64MMFR0_EL1_TGRAN4_SHIFT #define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN