From patchwork Mon Nov 11 08:35: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: 13870398 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 D12ABD2E9C0 for ; Mon, 11 Nov 2024 08:40: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=jdRnYA4Dp/HKDbLf8iEX384rtZ3sORsc5iDaybCR36k=; b=lYKa1A/pUxGXR6yWdOzx1uW55V Lf2y6QYxbh49/i+h5eFc6K/ja/Jtfq6XLZo7QScpLqJEOzBaPZmcmGLlK+3kBzFo9NK5CcqSYriAv ngHbabRZmFykCjLKQgZerXfIzU3mvZxIdIzZBr1oAQ4G7uAbRt4T8PX/KMyVe2Q1F4IIcrGPItxc/ WVkzOdn0Ep9V67KYuRS8tUCtElU/6WjpNkY1ZYYXHMzm7aK0ZXqquqijxI2ncNOLJC3s6FOmmW68m iV0fNa9Y1xM6DVdB23fwCTWkeNOFznjaC1ncphkyCqxlZ1fO20QONcUzeEAmHrW65X1kp8uzBG6SP BHdzvyaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAPxa-0000000GpzI-2svR; Mon, 11 Nov 2024 08:39:46 +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 1tAPtw-0000000GpNB-1xru for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:02 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e30cf121024so7090656276.1 for ; Mon, 11 Nov 2024 00:35:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314157; x=1731918957; 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=jdRnYA4Dp/HKDbLf8iEX384rtZ3sORsc5iDaybCR36k=; b=3EqZuKTZrTa/ckJVMI2VkFkqSNRnasVbdHWhHMn+P8YQcDqXME/Oa0pg+Gr4+XiEHg oCNtiWVcsrPPV/BJ0BqjNniTo2ZHh7wU8LVFnaeUTs5B9j9FJOgFn76GL4rGlJjDJspx Nxn1U+itR4dk3Ns3aykK/XG7vWQuCnYEEi7KpGLSCB4zJe9DHjnV7Exi9muXKSc3Ro6D ajWrqkHYqzFYdNoiQ2ERLSaHGNE1H7D3HJFiRxDOsvAPMU/mP4ss/dpPTenD46IpWVun 18jH+VKy9gwmt4SBvT9oCL1PEIu5c6ZN8gAKwR0vxEY4gXKhZbiBYytNpaQTBoPWOvlx 781w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314157; x=1731918957; 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=jdRnYA4Dp/HKDbLf8iEX384rtZ3sORsc5iDaybCR36k=; b=UxPTvAJkRfASbDiSRwCIDICDj0Xe2ucwatfSsASwAbVDxLWddtx7SxaJwuPvzoMg+4 8UE08gT/nqJaK5/5Vq+jTc0OcLSDkMn8tx0skxpp1TWIUIYMyrODCcTINm4LmoN+4kji uaUTHacIjp1aGyIxzwI6AJtDBhUSC4PDeTYkrw5i/uXESgQYmgONcuiiOQDSG/cQXMGS N5h/vHUflH0awsfnpg8+7jRe2gWGWPPkrqAkdLlyTwZ3Rcq2e1JtvvdFT2Oyy1EmRnaz Ao+FaH1f9KPxpErboVLCBAID90155VKWxLWSLFrWnqhojcZMNDn7b0LoBvkTqThRF49O zH8g== X-Gm-Message-State: AOJu0Yz3RnXD2ngWt1tWr7GKLa8tGXKzhZUgicSG+fUGfvlSf1AK3IQW cjYCBq++HlVVcYRFmJw4T4zyBH72jyVJI+5BgSj6psZNfksIAsEWL5CZIswvOb/lOH0ju8Cw+0+ FDQccRb+KbjgwAgo6qjeyDXi+INMlfLXj4MUpfVAWmnlwhs+lWyqzxaF/jmh4ECM+ixZn0gfzce UEbaNdeojYWwkgEmbF5zKc0CsnNdop1FL5swKpbl4+ X-Google-Smtp-Source: AGHT+IEhAd1ZYt2KUoU4K2QDCIjo6LctpoeG1kVqzvVn0qTYE0SJcqJsrkLHh8WG4AcoXgHHmsa2YvUF X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a25:c7cf:0:b0:e28:fb8b:9155 with SMTP id 3f1490d57ef6-e337f8e8d9fmr19018276.9.1731314156955; Mon, 11 Nov 2024 00:35:56 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:45 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=3161; i=ardb@kernel.org; h=from:subject; bh=TQ6skMuf6HwA53KOOzLH55jf3veEJQFpWOO2ik/HsBo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4MN7c/r4xb+212w9/UK9/v7xGy5zfjLLhXUusGL9v Ce78nhsRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjI7Q0M/zPSfD9stF61bcvv gOLaRwocrAs92kUdV719F//36YSD+ycyMrRekNqwdgurp5Z8d5mbiXmHVsPsopc2D7Jall/YM29 OCiMA X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-9-ardb+git@google.com> Subject: [PATCH 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: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003600_535986_021D78AF X-CRM114-Status: GOOD ( 14.56 ) 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 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 support is modeled as a CPU feature which can be overridden, and with LPA2 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 is supported but not enabled. Fixes: 352b0395b505 ("arm64: Enable 52-bit virtual addressing for 4k and 16k granule configs") Cc: Signed-off-by: Ard Biesheuvel Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable-hwdef.h | 6 ------ arch/arm64/include/asm/pgtable-prot.h | 7 +++++++ arch/arm64/include/asm/sparsemem.h | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index fd330c1db289..a970def932aa 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -218,12 +218,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..035e0ca74e88 100644 --- a/arch/arm64/include/asm/sparsemem.h +++ b/arch/arm64/include/asm/sparsemem.h @@ -5,7 +5,9 @@ #ifndef __ASM_SPARSEMEM_H #define __ASM_SPARSEMEM_H -#define MAX_PHYSMEM_BITS CONFIG_ARM64_PA_BITS +#include + +#define MAX_PHYSMEM_BITS PHYS_MASK_SHIFT /* * Section size must be at least 512MB for 64K base From patchwork Mon Nov 11 08:35: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: 13870399 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 6523CD2E9C2 for ; Mon, 11 Nov 2024 08:41:44 +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=+4O6vPXncAdT+5klHHB6JLQEFGlmp/qVLkbHu/JVbLo=; b=I0u16n0k7cv8125RBx73gtaJXV ek24wa4zZfZnTHK2wylqBu47iizFPFHVU0yjiNnZ16nWiC2IQzvO9BbEwYzYypY9qZs5bipdpVawz rRFvDsKBXxMgHEo6RzLl99TrSIBGoeA6NEthM251uV6qz4zsoWnaYP5mCHtPAnJIgVa6Oopx8kPE8 lBg5HafP7fNWAeBNPca1SBhhaeGwK4FmWTv3lJ3RHb6KAXmnmyDErTkS/DM7nSvIVwpklkqcHpQVj awuyIosu+C96GTGdCfV8Wjt4rZmYMt4x6CSTeofXdE07pgG47UcqL3DjeSnf5le1i7HQEUwhFoDIP tA3B7wsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAPzL-0000000GqJu-1PjT; Mon, 11 Nov 2024 08:41:35 +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 1tAPtx-0000000GpNL-3UVu for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:03 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e38fabff35so23652247b3.0 for ; Mon, 11 Nov 2024 00:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314159; x=1731918959; 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=+4O6vPXncAdT+5klHHB6JLQEFGlmp/qVLkbHu/JVbLo=; b=3zgyhNikS2IpDzSoRmKhov8TW7oLN2nyXvGNqO3sq9FHdQsiTMW2TaH6kPwmZ8bgXh CFYtbBicAsQOA6ht7y2/nRkQIY6pDM7hXYfvbkYytVe1nabQEjQzRasAv0WfsAeDUphi ZhuKGx8EuoPmhv67veY2cIPWtZ6YaQjHh9OuWrIm5nDRVm1L+24tmtMf6r1p4ZqgEf9i HzXyp0vBStm6OUZY7bT3rnV2Limbkn2wE99MGxOvIcXQeM4i9k26TG7ouGkw0oSbnTj0 OmWaYB4K1Pvh+ICzteqLaPcTueFQ6easwZd13O9MBZwS1diVC8kNOvcE9ihUZ/sy5hET 4WMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314159; x=1731918959; 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=+4O6vPXncAdT+5klHHB6JLQEFGlmp/qVLkbHu/JVbLo=; b=jltmh/VFSLOuOoyqUi8JQ7Om/2CSdzOdWLfoGbJt1tdVgnSrxbEa7SCDD4AwcSFvRV KHLcdp1l67Lw0t2NYxyCUoFT1RcpBQlE/+xibgyf8oP8HpGd+n2REsIw2SX28SscObMZ 0d/XT/gYrSdaFV6G3X70d/rh0cgmbZWrbEDIEDhsBZ6zfnzhIyd1QPFQzvN4jAJlov2Q nRJHfRl6Ow45jfdnRlxc5YItqbz/FP1+E/xF/zPJKXFFlfcfwo+wFclm4AnWFS4xFkYY qBuIz1CWZe+zQDdTgY3Cm8Jz0eNlwVaivLxL5uPkFANgHhfNaUelji7vcxBbgoEekSzB oQBQ== X-Gm-Message-State: AOJu0YwlxUTjYjps6Sirf9uqN3WfW4aTxCUGynskCPjC9FmpIDsYRSGT 8405VKscHIUT6kxjxTXwQ8Daz6I2jFqOrzE9HLmqi3YgiB9RvgcQ9pC1Dwo6S6E1w8YvHg7ZFTa LVKnCanJyxYvEICiwBbx60+NINNz/t5kofpQ0GvQAUbiEtoJKlvhiYt0DPHEGbOJEihD/2NgJQl VD7M606Vaysutm29pcBqbIqlQ+oQPHH95UybwmpZzM X-Google-Smtp-Source: AGHT+IFHExbV/UaCmb9SO/GvwiePUkfieauhVEdjQbeeo7rkNuDf0FnYJMGSUhAwD4yKRoCmYO6xtYGR X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a0d:fd01:0:b0:6e3:6414:80c5 with SMTP id 00721157ae682-6eadda22e76mr762687b3.0.1731314159320; Mon, 11 Nov 2024 00:35:59 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:46 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=4298; i=ardb@kernel.org; h=from:subject; bh=v82eHrgTptnYI3SkH3DFWlg65i0BvRLyLZmKr5z7P/o=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4CP/at7Cu+4F321Y7dhUrNetClomFBRmzcf5YvKOq fIXZq/uKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABMRCGNk+PMnf9quWKN9P7eX p4kJl9w36Dxn7+fDWl1QO1X+6IQbBxkZni2erlXhv50vlmOeGceUp3Zhxf1vdmnusX8sH+e0oaK QCwA= X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-10-ardb+git@google.com> Subject: [PATCH 2/6] arm64/mm: Override PARange for !LPA2 and use it consistently From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003601_903763_9CFB1FEA X-CRM114-Status: GOOD ( 16.29 ) 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 | 2 +- 5 files changed, 22 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 37e4c02e0272..6f5137040ff6 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -3399,7 +3399,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..4db9887b2aef 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -280,7 +280,7 @@ void __init arm64_memblock_init(void) if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { extern u16 memstart_offset_seed; - u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); + 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 Mon Nov 11 08:35: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: 13870404 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 EE25AD2E9C0 for ; Mon, 11 Nov 2024 08:43: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=0N4/8trK7fv9irXSAqJ3zFfA8vt6Qj0oJ/C7156uK8I=; b=36B5i3SR03f0zUYjDbLh0XzShs FtQ0LTkQhvm8iX54yErN3U4ZEfQ6KwTQMxuyYZibIyL43J5YK2YYGkyyQPCMNT5mJ2dZQrwDvWDzJ yh+7US4QUck+lafopeemJtT34K+i8ac3W4kce7tQ0TkkVTr6VzYqJVrnpoBa6VkUjMqMWT2im+qET rQsCDcYo849UB1Fevox3ASm5Z78CCjBicctpkiqPnUrn7vcoumEOQnN5legN4juqNFAJnD2xvu0Uw Xm7bXFrQS+L3T5Cv9Obh5XZ/gTCdbAqhFY7DVOb5M5TiAHevmWVyBm2n5PcbKCnU2hlb6Bo/7VTyj nZvFlmBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAQ15-0000000GqhB-4A9w; Mon, 11 Nov 2024 08:43:23 +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 1tAPu0-0000000GpO6-1yV1 for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:05 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6ea7cfb6e0fso81492617b3.0 for ; Mon, 11 Nov 2024 00:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314162; x=1731918962; 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=0N4/8trK7fv9irXSAqJ3zFfA8vt6Qj0oJ/C7156uK8I=; b=VCu6zN16luP+TryJfj82zwG3h6egyjyfe6TOu8VIftFrMaO+VquvywMJnt3nmzZXar /CWAxNzbwgQWfuEhzgyYOzTZMt3vohKqBldG9Px2S8AIFacFiCZhrQcpcBhSRWU9Cqhx y02NrtHzfw58DX1BPYSxC06xSO8lSpsPO05c2SkcG7IEkEXYCFxDX/nI+3GxaInQJB3k 7NQpUfmdIRi4oEOy6zEE5kdPm/PVw9DYY2xMYNxh79cpJK0/frekrOlH/tqQxKQ89EAy Yhrtj3bxGAzIIhVruoscXszzPuiuZoma7yfw318b4VA1W0o2IBxBVj12yNoSoKm1ZW9M IvVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314162; x=1731918962; 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=0N4/8trK7fv9irXSAqJ3zFfA8vt6Qj0oJ/C7156uK8I=; b=SOSgQOQ03e7GOh5EMOrlip98Q1cbX/VO51Agqyk84TZh9/rRwuUb0NfZlM2voR/SSB 2S8u/Svqc5ETkdngbWcp4MVuDIrb1u7OAUMVkbk5K+PYm3qbNcg10i8n6++qY5xLpCNB diSa38DeyMJBN6ibZZ10neEzlJuhPjKcP3fuGPk8kbd8Y80aVamRYoc0iZKHnA63BkTQ GIc5dHxQD/9HbM7tvfcLBdN+K40pw4PfqKbQ2meJOVL07a2MN01Q3Nnie3BWwq2y9n+B /dGsFdcwjTHnxpTspT0JpNCjtzlmcUvMH6y7enmD2+r/lcO/8Mv8jpB7uubug+mgEP36 tbjQ== X-Gm-Message-State: AOJu0YzruDlqy7BORBXASwYep9iT7ZVCqPeveagzLF+wOfmestpWpS+N 4ITQ2k02AqVahIsqNfxv10AJK5a7Xj8EGeKCLcKnQrhWoPES+WYkdVIMW/q7CSvsYt9W/J7IZAf Y9B130WWI1leunLvR7h8PrW1t7Kl5WdhFRox7KqhyouXMeUpuR40qQXCXr7MwLs/hBNx0jWKOe0 lcVIxcV2nUW0Tvh5SJlfB5AwR6qb3/Qq+Yy1NzjgK9 X-Google-Smtp-Source: AGHT+IEaVcyWaEFOsAGEmUmx521XJZzIe6O0nRTJpeaLf4pyHpMVyj2xe5eAr/hgU4liSlwSx1Soq/gO X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a81:be05:0:b0:6e2:6f2:efc with SMTP id 00721157ae682-6eb028d6c59mr467177b3.5.1731314161525; Mon, 11 Nov 2024 00:36:01 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:47 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=Rsge2hKhZ3IgLduep4Ol+NMdQ1OnlqaAQBu4vFWrM8I=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4OOI3t6JM3he6wj/fvl1/iRNb5+KfI0rxVsSN3fVB d7tbdrbUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbiE8jwTzsjSViaR1mnNmoX 60UTV7//fRcMNrQk7GviOF0zeSnDXob/DosF7weG9whVPg2PLs25au19KFFvwdm4D6GXDs7quXC dFQA= X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-11-ardb+git@google.com> Subject: [PATCH 3/6] arm64/kvm: Configure HYP TCR.PS/DS based on host stage1 From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003604_542671_37D16C99 X-CRM114-Status: GOOD ( 17.79 ) 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 a0d01c46e408..1d20d86bb9f5 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2005,8 +2005,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 @@ -2020,6 +2019,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 { @@ -2029,8 +2029,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 Mon Nov 11 08:35: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: 13870405 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 90470D2E9C0 for ; Mon, 11 Nov 2024 08:45:29 +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=mvYw5KMEsKEr1XuASRWN06RAKoI6bIJLeOEgHSiiZzM=; b=pXfMuoL5wZ1DLHXmbPSBD5zCPD UMDePBP7MZ+ntKlNYxLUruxNRzXWFg8tzGjq+CzeZhtNkvnC8O1V51JhLg1QachUQEo/Pjuk+DExr UlFzAX4ppzFAhXs8r0wBdzUGBksDqg2dqnlqqldmJ1Tx1tQ9pJKNiJbC4S+QfYwlnTdRR2NdQQ+mT aZGgO45Synu6w7gJDOp8SFA4CeF5XRJMKypoHQZ6k+QdiiTne68q0VXxWDbqfxRLWM+PYaG4iPBcn SbE6cEI/aygr4MBL3vQN2nCrvceDkIDl2RCSnh9Oii5Yt9JKgB+50tMAb5lNIJDPAIwCY713Ca0/d Jj4LYR7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAQ2v-0000000GrB7-3DBk; Mon, 11 Nov 2024 08:45:17 +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 1tAPu1-0000000GpOG-1Ejq for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:06 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e297a366304so6524341276.2 for ; Mon, 11 Nov 2024 00:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314164; x=1731918964; 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=mvYw5KMEsKEr1XuASRWN06RAKoI6bIJLeOEgHSiiZzM=; b=OwGjcY5oOoE3mmxBt3kJvkoxkBcIWY2NxAvz83O0AymtfgrU95i4kqZayIU/QycUss sWK4FyPRTysQuIZuCRROhQNUBlR/fWdoQwR7hrJgiJqSl1oEo0H2JN3uWT8pMEZkrcL/ Kr2lIuRhrh1O/WKsrzBTbbvGjEBj2NbOgDPptNvHf6W6Di+m6KhsXLhEaTJFKqMRPnLw byvE/N56nvV0ZGMUAgBvKzY/XjSbpUFhvCgbzjz2ezjrK6OHQxUgVmFiUFayG9khFOOa h3k6Msg7n08fJSf1QtNU5/WyODiSLKxBU41qc91fQCt2oujZHM77KYeeCbWZY/e6c0Z+ PGzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314164; x=1731918964; 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=mvYw5KMEsKEr1XuASRWN06RAKoI6bIJLeOEgHSiiZzM=; b=DhFkuzn1s2ME07EQ838x4JqwzB9tPOl00qol4PDx2k5Z0O78EbaTu2H3WEwK4up8QK LUb4S9xPeX+hQqRwSfg2WU9Og1A/XPB/plV9QljwoVcMF7mXFxcQzXKoRf0jeWV0SbyM Ad0CHB5T2hTYADH5VjP2XxHzBbF2n2VkrAQlHHZT5WSST+dmqgUG/zEmqF+ZgIELcRhT LBefklzU/6xnv8gTmbZ/OW63Wd8Uwwa6u8FmuBOZZUkrlzGgyh9RJCei0votw0MKiV28 vVyfNFaysJQ2aVvD4UU1hTH4Be/KXpZsbbLaTp6YGd90bUzzPxkbamiCzv+LpZuIlMlQ IsRg== X-Gm-Message-State: AOJu0Yz6FJrCYbMEcKjzTZORyF0wQgByO0EDLDW60VpQkSuP0yHK/hCn ohNaBxJNswQdcYprum6G/UrGeTQpfeLw+VkpG9ZAIH+jc19OHRRcZMLEjTLh6YKQm21pd7+8Pnu 6tJadJlOUGc348D0xTuEcD2FkrfRr6gdA7ox6eKLzGpAm1A/J/ZspuXbrCysRmtztl5jXAAegJ+ EI12BRbZcCSSsqQ5l3IQf2656tHDBaKLLkworz1Qy/ X-Google-Smtp-Source: AGHT+IGpvIMbkxeYdUfsPGg0p8TdUt7jkXcMTRirtn29GW64/R+2fJohGiuoVhYqzVfdaxv+KAZTWwUo X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:6902:4d1:b0:e0e:4841:3a7e with SMTP id 3f1490d57ef6-e337f8da4fdmr33424276.7.1731314163950; Mon, 11 Nov 2024 00:36:03 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:48 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=4086; i=ardb@kernel.org; h=from:subject; bh=ibxNk8At7yeC6neiP0xU3/81ts81JCLm+aYwdEzytG4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4JM7ggvj+DacKNi+aJHSyRtRzunim0WYP06ZPT9h1 +rVbqmVHaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiBWGMDHsTJm1cfW2x0srf 09K8nz/i5NPlkmS5G200dd6pGo6kZ/IM/6sMDmSw/L0Qf1f4kc0D+0e7Jp3SOuzBnhA/R2hpFMP xZ0wA X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-12-ardb+git@google.com> Subject: [PATCH 4/6] arm64/kvm: Avoid invalid physical addresses to signal owner updates From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003605_361569_50ADA4D4 X-CRM114-Status: GOOD ( 20.18 ) 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 owner_id fields of descriptors should be updated, which 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. Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/hyp/pgtable.c | 37 ++++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b11bcebac908..4bf618b2cba7 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 owner_update; }; 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,13 @@ 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; + /* + * Pass a value that is aligned to any block size when updating + * only the owner_id on invalid mappings. + */ + if (data->owner_update) + phys = 0; + return kvm_block_mapping_supported(ctx, phys); } @@ -923,7 +914,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->owner_update) new = kvm_init_valid_leaf_pte(phys, data->attr, ctx->level); else new = kvm_init_invalid_leaf_owner(data->owner_id); @@ -1085,11 +1076,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, + .owner_update = true, }; struct kvm_pgtable_walker walker = { .cb = stage2_map_walker, From patchwork Mon Nov 11 08:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13870406 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 9A59AD2E9C0 for ; Mon, 11 Nov 2024 08:47: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=oYXPp059bnBZquw3jsb03/CH5q5Ir/ZRO9Vlwe8AifA=; b=OaYY/zglPolg/IFPbN+Rr0XBfK p6OSwPqtJUYAg3RedhUEh8SIvJDnJifwlBRLTw2V7oZAMKVqKcbQ2OtTbPaMGYC4+eA1A4Q2D/n4d UukM+djbBSvvT44u/1l1YHfBGAGK+MBGwIEDzzgP9euNaJDizGE+OA4XJEFM6YlS6flBSdMNSdNvs qakpKQpdPBtYzG3w71uz5d+r4NzCDEe6U+r/MU2CuqEehO7nteqdAN3711+xT7j4LK4Sp0i8Jr3rr 4+EQ3xeajz+jvpzmXd+e2nKmKsV07DnRvZ0HJchOoIj406aB+rJv/ZhUkZHFgk+BgiAcaiQkaR22n /+n+1MGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAQ4g-0000000GrRb-0CL6; Mon, 11 Nov 2024 08:47:06 +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 1tAPu4-0000000GpP0-2H9w for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:09 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-43159603c92so30498465e9.2 for ; Mon, 11 Nov 2024 00:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314166; x=1731918966; 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=oYXPp059bnBZquw3jsb03/CH5q5Ir/ZRO9Vlwe8AifA=; b=2YfuXIZu4kzWOXBixO/wmQi/9ZgCUH/XGipPHDW0hX/VcADlq608eQNfXcGXPe2EPP 2ZSDB7HxstADYo0+30oR47biBt+tnE3KE8aA2AxXzu6d5ROrLHu67zkDV9uynp2PXbm8 sBIQSwbrmkkxZZKStUC+NrlqDf+E8KVavmRW35w7ulUH+p+2Lu2Q1zhN2ZSF/82F5BaM OkPbUrCLlJzD8F3P9hy8y6PJ3VUh5dxgPw/T3Ze3b2Qo2O+J4BDF420VDd/u37rK81Fs Ynsy4iEVCK0s9DT0xhEJ5YuQDHxdn9esoCjBrPpaZNWF1ts8/8Veih6pdOzx9BjJ0Sp2 JZiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314166; x=1731918966; 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=oYXPp059bnBZquw3jsb03/CH5q5Ir/ZRO9Vlwe8AifA=; b=wh9DQoVYV1yzNhZ2E1hRuIJJAhmf9SG7UbmNxvgk0bs6/eQhviExJvPaobG2bkrNim NwHbVougkWVF9BBQx0vbYEeRxtK7FudiQUBtNMAF/B6DteqR5e9qppJULy0/9v76MPeH c3oqs8N8oNUcV0Hhc3Nac4GUzEGf4g4Ne4CrCIGy/MJL8Y5IQ0xbSKTTF8WZBP4jlfq6 7+YLif3Wp1g3mkc5ldJWBhBaNA2H16XmkXaaAv/ATHGo+ttUJiwG1aJjedKI4TvMtkEJ a+Mj40IuB9Pqyp3Uq0Qb8niWt7Fh/UJJUyRu5gwwpzcEcUiarz2XawsMiWg6Gf2+BDEJ NJcw== X-Gm-Message-State: AOJu0Yxxla+5KarEiZm/HWhZ0F+QuLq05aI7fmo68WYtDH4eI5QbIgJ8 Xu3S44dIfwTf8t3oGD+Hk66VNsAWRqCHkBM/P++9wMtx3+IxMRPRmuycFBumef+OD+1ALt+Imzh vE4Qm0Ff6k+Y2DfJTVWZ10aQFie7LO+Hn0KnjllqqZLxcnPTMzeYFrdmclFfP1lIec/NjCA5puF ZD3cKQwXWNO7Y76b6/RTDcDBp5vAs0M7jSfp4ap3EK X-Google-Smtp-Source: AGHT+IE02UNmtXOHYFjrucm9+q7KBzR2E2ndSPtx+J0shefNcLQtRP1OFaNSXkaOsrH95Sb1gjDJZQcB X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:600c:4202:b0:42c:ae4e:a983 with SMTP id 5b1f17b1804b1-432b7515cbbmr106975e9.3.1731314166058; Mon, 11 Nov 2024 00:36:06 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:49 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=2688; i=ardb@kernel.org; h=from:subject; bh=9dZ738TTk77gIGMJKlX5UefvULUxz18unqArcxKdWUo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4DPfB/t41n9lMpqgcHm/xMxkYYYzvTdv7m8rY1EVS kquUP7eUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYyex8jw04pca3Hcsv3pRy7 Ornq5Yevqz5sf/3/2VPBNwJHAnKtWXMZGf4lZ/sK6Wvl6TROagyP4q01d117Nu7z7oiZ5+62qfY aMQEA X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-13-ardb+git@google.com> Subject: [PATCH 5/6] arm64: Kconfig: force ARM64_PAN=y when enabling TTBR0 sw PAN From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003608_607987_4B3A2593 X-CRM114-Status: GOOD ( 13.66 ) 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 Mon Nov 11 08:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13870418 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 0014BD2E9CA for ; Mon, 11 Nov 2024 08:49: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=m1xFEblsgxa4RclC164P/nqkAMzUCB5wc1os0ZZKcFg=; b=MIDluriHp9ezVSvUwDJhndWd54 z6wcFh2gUfIr10LproD/yrNH3WQc7CCL9oie+ketcPZ4LwwBlG2ejSwNYZfCF+/f1eoiwltUXLpUw ngsKLG9qmWypHBoDdzqgV3dxy4chNql1zWVerMTBGy/vqckBnCrgZ27hH/ZeFtD38eTYpoZr7ndX5 lxlOEtTugaSoCjueyLwqWyhCmlKd8o4ARTS+dVl+YKSvEiW+vSL4CpQ35LTht9Gqo5yd3NWMbjTix g5ISTiXK/NWFK5Eb6U2RFeMrUDCeS6u0cMmyvJvnvbMlyJmUHGt5dlIxkhtPAGBTT6jHQmTrS4K/E P7jp4XgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAQ6T-0000000Grky-3yha; Mon, 11 Nov 2024 08:48:58 +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 1tAPu5-0000000GpPL-28MZ for linux-arm-kernel@lists.infradead.org; Mon, 11 Nov 2024 08:36:11 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e35199eb2bso78973947b3.3 for ; Mon, 11 Nov 2024 00:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731314168; x=1731918968; 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=m1xFEblsgxa4RclC164P/nqkAMzUCB5wc1os0ZZKcFg=; b=I2EbzMxAUqGpu9ns3nSsOGQ7/0Dhh08o2rIGFixq+fazdw/F9TjLSJnO6/sOlS8Lmo vNkMO6el+PS67x3prN5pGuHgDQkE1DcnXO6HQLkZkG/NJ83OMFxEbphKY4Am3Y7aH4+V 4+sYfxG27zW1VmgiUUBUAoQuM+gTz59Awlhq5mZ3Tch8lWu6te4bCLXVN0P26OlCERSP 834kFwweCeP7cxzo0y5MtTAqYh9j6Uw0zf3oM/RvRXIrR/a5gOqO0I2Eo71rYWth44ff /euA5r0KykmbSld8c80MVWpy/OuMU8oHoSbS4hYMGmDHTtDcqVfOysi2l9hxO5CXUrJK WgPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731314168; x=1731918968; 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=m1xFEblsgxa4RclC164P/nqkAMzUCB5wc1os0ZZKcFg=; b=TgPBSJououTN+sH/7pMQOW+o41f3QCvR9GPVBHj/TM0LX5/IjDXSwAVZLkow2XWMQZ pifLqwdx7YS6q5wEQx85uFbrPglUIbj8CqPRBn2vk+TIGOIVuhqv8S525nZbkVLHg5md kRBTr0hem8wfK4ieMZj4b9JN3yI09vXAta9b61h/z0aLGmD083R+2ot6L5WHJ0gcWbts iwSFrlaFAfMPnCmfOwb2AzojEupwWeM49lMXyXD2mG/bdzoFkLd6rOrKUtFKtrQUhajC BPLO/3NAdwM34wvK2l3iswp1pjj6t8Bi3T7fSHANDaVn4zgjci3xmo/ds8Iig0ev7sKq WeQw== X-Gm-Message-State: AOJu0Yy3eMs4b/DomdhQH0sCeCGkQbjdBHk0x115EqmkCApb3Zt+5nbu wpLZ8k6yLmrItfeiz2E4JX8Agy8CM+84d0des+NHu45tk7PuR9K/CGgJNw3geQ7o5ZMZDBCj1WX fLHhYYVHPRhihyal4lbXWstZG7wdrNQuS7ih0cbZ+R7HVWqCSfOWnnbJ1o6E2yUdyglb5YAynyp A+4iEeDPKkDOab2/Z4EB/mKOnRYYoLf0BJZIR+D/SB X-Google-Smtp-Source: AGHT+IF+g4PJjJqLTTfJPqlybNIeyhrNsYZlpNKrEQrIK0fyY8IdIspqleNLzuhsLMsDA7X4fE7bBtsQ X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:3501:b0:62c:f976:a763 with SMTP id 00721157ae682-6eaddd8b094mr2527637b3.1.1731314168386; Mon, 11 Nov 2024 00:36:08 -0800 (PST) Date: Mon, 11 Nov 2024 09:35:50 +0100 In-Reply-To: <20241111083544.1845845-8-ardb+git@google.com> Mime-Version: 1.0 References: <20241111083544.1845845-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=slWQNmnUuKGuETXL+/E2wzb/ApCZRk8VG4TRdX1m+qI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId3w4PNjh1cwuM765bVp7d/0XQz7k/lOMrSsZvQ6NnXiQ fuvF7fs6ShlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATWRvEyHBlMk+u5iIus674 9oadqxOnCx2YfIRrVuTBe71f76XEX5BlZLgl0Jp2SMFKbg1DZYOh/J2PEy7+zuMrL61q3s3jLTN vFTcA X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111083544.1845845-14-ardb+git@google.com> Subject: [PATCH 6/6] arm64/mm: Drop configurable 48-bit physical address space limit From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_003609_584966_010E42AB X-CRM114-Status: GOOD ( 22.52 ) 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 ec218ef22f2b..769af2da4db5 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1405,38 +1405,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 e889e12b7648..3852ef120484 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -862,9 +862,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 03f4c3d7839c..c98643542597 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 a970def932aa..7ad52dc4c16e 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -172,7 +172,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 @@ -182,7 +181,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). @@ -323,12 +321,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 dd5dcf7ae056..dd4f1ad9ffca 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) \ @@ -1493,11 +1488,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 9c98ff448bd9..11af40e501ae 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -928,12 +928,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 8abdc7fed321..84657d04dc51 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