From patchwork Sat Mar 29 03:44:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 14032568 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 A5B1DC28B20 for ; Sat, 29 Mar 2025 03:46: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: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tAHH9KrMEobkIlXW9ZawD+0mGx69oP+FIw5ULlaz1RU=; b=e2pXigIUfYZsvSYQ3vlPEY3Foh 7NEGGkjlHrb+9ngvpJIIacrSnQWhcJFQjzcFd96YcUSKvEQf78P9lf7+yXzl+EiYs3O8K6Y1XgE2/ xSG4UOcOIFZHitSD4GDAB8ZKGKbDlj14Xtyu9uT0ALyS3udVXwh5djt2AeEPFGqf99rvSh/OWgtW2 2w4ZPST8mXmKDwQ1AjyvOwSMoQrA3oEwAZhpLhZ7SSPnF7v9ejd8XkGaY6jlmsjh2lcAoXyH5aILZ MHBeJ45Phh4X1u93m6XUt9cB/xS9WSrJC8rQo7THRpDbjJ4PXcSszKuCtUWxDAwXYOkMR2T5v2K9i +U3hHLBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyN8r-0000000Eez2-2JGU; Sat, 29 Mar 2025 03:45:53 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyN76-0000000Eeuv-3SqS for linux-arm-kernel@lists.infradead.org; Sat, 29 Mar 2025 03:44:06 +0000 Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZPjmw5W58z1jBWW; Sat, 29 Mar 2025 11:39:12 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 7528A14013B; Sat, 29 Mar 2025 11:43:55 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Sat, 29 Mar 2025 11:43:54 +0800 From: Yicong Yang To: , , , , , CC: , , , , , , , Subject: [PATCH 1/3] arm64/cpufeature: Add missing id_aa64mmfr4 feature reg update Date: Sat, 29 Mar 2025 11:44:07 +0800 Message-ID: <20250329034409.21354-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20250329034409.21354-1-yangyicong@huawei.com> References: <20250329034409.21354-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250328_204405_046617_6D1C77A0 X-CRM114-Status: UNSURE ( 8.15 ) X-CRM114-Notice: Please train this message. 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: Yicong Yang Add missing id_aa64mmfr4 feature register check and update in update_cpu_features(). Update the taint status as well. Signed-off-by: Yicong Yang --- arch/arm64/kernel/cpufeature.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 9c4d6d552b25..75ef319c1ef8 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1403,6 +1403,8 @@ void update_cpu_features(int cpu, info->reg_id_aa64mmfr2, boot->reg_id_aa64mmfr2); taint |= check_update_ftr_reg(SYS_ID_AA64MMFR3_EL1, cpu, info->reg_id_aa64mmfr3, boot->reg_id_aa64mmfr3); + taint |= check_update_ftr_reg(SYS_ID_AA64MMFR4_EL1, cpu, + info->reg_id_aa64mmfr4, boot->reg_id_aa64mmfr4); taint |= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1, cpu, info->reg_id_aa64pfr0, boot->reg_id_aa64pfr0); From patchwork Sat Mar 29 03:44:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 14032571 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 EAE19C36010 for ; Sat, 29 Mar 2025 03:51: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: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gubgaoNfqjw0eIO+mQbh9QtxLuc2yJNKDLZbI4YuNX4=; b=xt5Sc3jjjYZXi72PAAb8cNYzud OXayVFH5J91ByObzqXBeiSscRu+uFgtuSmo8ZT5MNBGJSODtRxKwb1dL7500PTQ0fetTc/aepD0AU whbqOflMQDd4R9KHXSYAC+Pv0EO1+NDdV16uKm7OKJuOrpI3HxKguqjMhI6jF+Q7YGatx60HfI63C IwPcQtmazobIGvsfqpzpAbmRQEUS0gbLqo6GO0t/UfiW5l3XwOg5MRA3DWovtZWRezWGfzofKpUgJ X2kaDjJ3yDdGY8ENmC/0kY483A9g2XRqHBVxXpJOmfIAyX/Ur4WuTQ790XsMfcCKZhUoSXOwylcoF Nb4UoqPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyNDy-0000000EfGa-2TVz; Sat, 29 Mar 2025 03:51:10 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyN79-0000000Eeus-0FZq for linux-arm-kernel@lists.infradead.org; Sat, 29 Mar 2025 03:44:09 +0000 Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4ZPjpY3x3WzHrJR; Sat, 29 Mar 2025 11:40:37 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id F3BB11403D2; Sat, 29 Mar 2025 11:43:55 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Sat, 29 Mar 2025 11:43:55 +0800 From: Yicong Yang To: , , , , , CC: , , , , , , , Subject: [PATCH 2/3] arm64/cpufeature: Add cpucap for HCR_EL2.E2H RES1 (!FEAT_E2H0) Date: Sat, 29 Mar 2025 11:44:08 +0800 Message-ID: <20250329034409.21354-3-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20250329034409.21354-1-yangyicong@huawei.com> References: <20250329034409.21354-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250328_204407_425169_28EE3ACA X-CRM114-Status: GOOD ( 13.06 ) 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: Yicong Yang Arm introduced a "new" feature FEAT_E2H0 indicates that HCR_EL2.E2H can be programmed to the value 0 for legacy hardwares supported VHE. The feature is indicated by ID_AA64MMFR4_EL1.E2H0 == 0. It is needed to detect this feature for KVM mode initialization. Instead of bothering the existed hardwares, introduce a new cpucap HAS_E2H_RES1 to indicate FEAT_E2H0 is not supported. Make this a ARM64_CPUCAP_SYSTEM_FEATURE just like VHE. Introduce cpu_has_e2h_res1() for checking the feature's support which can be used in the early boot stage where CPU capabilities are not initialized. Signed-off-by: Yicong Yang --- arch/arm64/include/asm/cpufeature.h | 23 +++++++++++++++++++++++ arch/arm64/kernel/cpufeature.c | 12 ++++++++++++ arch/arm64/tools/cpucaps | 1 + 3 files changed, 36 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index c4326f1cb917..b35d393da28d 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -889,6 +889,29 @@ static inline bool cpu_has_hw_af(void) ID_AA64MMFR1_EL1_HAFDBS_SHIFT); } +/* + * Check whether FEAT_E2H0 is not supported, in which case HCR_EL2.E2H + * is implemented as RES1. + */ +static __always_inline bool cpu_has_e2h_res1(void) +{ + u64 mmfr4; + u32 val; + + /* + * It's also used for checking the kvm mode cfg in early_param() + * where boot capabilities is not initialized. In such case read + * mmfr4 directly. This works same after boot stage since + * ARM64_HAS_E2H_RES1 is a system feature, the cached sanitised + * value keeps same with every single CPU. + */ + mmfr4 = read_sysreg_s(SYS_ID_AA64MMFR4_EL1); + val = cpuid_feature_extract_signed_field(mmfr4, + ID_AA64MMFR4_EL1_E2H0_SHIFT); + + return val != ID_AA64MMFR4_EL1_E2H0_IMP; +} + static inline bool cpu_has_pan(void) { u64 mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 75ef319c1ef8..64e99330b380 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2473,6 +2473,12 @@ test_has_mpam_hcr(const struct arm64_cpu_capabilities *entry, int scope) return idr & MPAMIDR_EL1_HAS_HCR; } +static bool +has_e2h_res1(const struct arm64_cpu_capabilities *entry, int __unused) +{ + return cpu_has_e2h_res1(); +} + static const struct arm64_cpu_capabilities arm64_features[] = { { .capability = ARM64_ALWAYS_BOOT, @@ -3043,6 +3049,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = has_pmuv3, }, #endif + { + .desc = "HCR_EL2.E2H RES1", + .capability = ARM64_HAS_E2H_RES1, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .matches = has_e2h_res1, + }, {}, }; diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index 772c1b008e43..dd6631886d67 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -22,6 +22,7 @@ HAS_DCPODP HAS_DCPOP HAS_DIT HAS_E0PD +HAS_E2H_RES1 HAS_ECV HAS_ECV_CNTPOFF HAS_EPAN From patchwork Sat Mar 29 03:44:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 14032570 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 0C5A7C36008 for ; Sat, 29 Mar 2025 03:49:34 +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: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6bksi0ClpeLu/YdtJuf0xLijhkWkH1CO8Ud4A2ADlXQ=; b=Ib+yBOBp046Hx0DsgRRsC/eB4E K22PDx7CStRNt+m4C6g95joYqETC438CxG4mh/fzzsHyhDapejWhGJDCnBYF6VOvucDo+IgXSw8Pj jhIBXbfd4nm+xCn3yf6GT3tJJeQmbszQ4836MqTN/K5QC8k8l+vNT5T3jpykYbm2T+ZHyaqpoulxx at0cH7RK8fkUQ3qQ0wbz3JEYVXqadUyrg+6lLzl9omXCzzftm28YiL/33qpxXuolezhrdiXvgYy6K 9Gr9MPh2/9UlFziK4PEabZj5nFpDvsKSYibknexm2jxcgXLr90RXHZCbJ04v2OW4KjmLH6q+I9yz2 4CZiwv+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyNCF-0000000EfAl-3XWk; Sat, 29 Mar 2025 03:49:23 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tyN79-0000000Eeuu-0Esx for linux-arm-kernel@lists.infradead.org; Sat, 29 Mar 2025 03:44:08 +0000 Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4ZPjst2Phbz1d0y5; Sat, 29 Mar 2025 11:43:30 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 773A41800B4; Sat, 29 Mar 2025 11:43:56 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Sat, 29 Mar 2025 11:43:55 +0800 From: Yicong Yang To: , , , , , CC: , , , , , , , Subject: [PATCH 3/3] KVM: arm64: Fix boot warning with kvm-arm.mode=nvhe on !FEAT_E2H0 platforms Date: Sat, 29 Mar 2025 11:44:09 +0800 Message-ID: <20250329034409.21354-4-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20250329034409.21354-1-yangyicong@huawei.com> References: <20250329034409.21354-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250328_204407_254245_66502682 X-CRM114-Status: GOOD ( 14.33 ) 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: Yicong Yang If platforms don't support FEAT_E2H0, HCR_EL2.E2H is RES1 and nVHE is not available. The warning in early_kvm_mode_cfg() will be triggered if boot with kvm-arm.mode=nvhe and no indication for this. Fix this by skipping the non-VHE checking on !FEAT_E2H0 platform. Since this should only affect the "nvhe" mode, move "nested" mode check ahead to avoid being affected. Signed-off-by: Yicong Yang --- arch/arm64/kvm/arm.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 68fec8c95fee..a0c0bd936a53 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2905,6 +2905,11 @@ static int __init early_kvm_mode_cfg(char *arg) return 0; } + if (strcmp(arg, "nested") == 0 && !WARN_ON(!is_kernel_in_hyp_mode())) { + kvm_mode = KVM_MODE_NV; + return 0; + } + if (strcmp(arg, "protected") == 0) { if (!is_kernel_in_hyp_mode()) kvm_mode = KVM_MODE_PROTECTED; @@ -2914,13 +2919,16 @@ static int __init early_kvm_mode_cfg(char *arg) return 0; } - if (strcmp(arg, "nvhe") == 0 && !WARN_ON(is_kernel_in_hyp_mode())) { + /* If system doesn't support FEAT_E2H0, nVHE host is not available */ + if (cpu_has_e2h_res1()) { + WARN_ON(!is_kernel_in_hyp_mode()); kvm_mode = KVM_MODE_DEFAULT; + pr_warn_once("FEAT_E2H0 not supported. Ignoring kvm-arm.mode\n"); return 0; } - if (strcmp(arg, "nested") == 0 && !WARN_ON(!is_kernel_in_hyp_mode())) { - kvm_mode = KVM_MODE_NV; + if (strcmp(arg, "nvhe") == 0 && !WARN_ON(is_kernel_in_hyp_mode())) { + kvm_mode = KVM_MODE_DEFAULT; return 0; }