From patchwork Thu Oct 24 09:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 13848663 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 6006FCDDE69 for ; Thu, 24 Oct 2024 09:55:42 +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:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: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=NdpS8KYb5vkQR/DhNm39yYmYhHQB5WvzfR+2/DyAb/c=; b=t6/htYM8pE3YPncPLJcp+BWqwj 4ssQKrJSVxM76C1HFK6OQxHzkDnos/xU4bCVYxEelM7ExwWEtBPMOm5s/rKcRsejhD7NfclWV6QwV Wja3CfSvh5lC+Tfr+Pe41GOnF9/NO63sf9TLFdIV1broyVuAG/kV4TebksT/WJ4EnObyHUnKnup7K EVQCe3fNNBxVVs7NVu4BMomSA5XI5OEYCwj3/K+K8pEDNDHaYWM2AQ4pdJaIzVtuOe8fwXgqBmdIz s4jTjUVTFqCxezuZcRNyxLHIsmHChqD2ciayuL2UEs/B3qdBmPeMhJJsgy1l2z3l0EZKJsKfuwECW ROlKfjsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3uZ2-0000000HZFI-0Sxb; Thu, 24 Oct 2024 09:55:32 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3uKh-0000000HVrc-17uR for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2024 09:40:46 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XZ17b5vC3z6K5yF; Thu, 24 Oct 2024 17:38:35 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E3AB9140D1A; Thu, 24 Oct 2024 17:40:41 +0800 (CST) Received: from A2303104131.china.huawei.com (10.203.177.241) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 24 Oct 2024 11:40:35 +0200 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [RFC PATCH v2 1/3] KVM: arm64: Add hypercall support for retrieving migration targets Date: Thu, 24 Oct 2024 10:40:10 +0100 Message-ID: <20241024094012.29452-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> References: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.203.177.241] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241024_024043_876137_85C7668A X-CRM114-Status: GOOD ( 13.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the VM requires migration to multiple targets, these hypercalls will provide a way to inform the Guest kernel about those targets. These hypercalls must be handled by userspace VMM to provide the required details. In subsequent patches Guest kernel will use these hypercalls to retrieve the target CPU information. Signed-off-by: Shameer Kolothum --- Documentation/virt/kvm/arm/hypercalls.rst | 77 +++++++++++++++++++++++ include/linux/arm-smccc.h | 13 ++++ 2 files changed, 90 insertions(+) diff --git a/Documentation/virt/kvm/arm/hypercalls.rst b/Documentation/virt/kvm/arm/hypercalls.rst index af7bc2c2e0cb..ebd59fb72567 100644 --- a/Documentation/virt/kvm/arm/hypercalls.rst +++ b/Documentation/virt/kvm/arm/hypercalls.rst @@ -142,3 +142,80 @@ region is equal to the memory protection granule advertised by | | | +---------------------------------------------+ | | | | ``INVALID_PARAMETER (-3)`` | +---------------------+----------+----+---------------------------------------------+ + +``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID`` +------------------------------------------------------ + +Query total number of migration target CPUs the Guest VM will be running during its +lifetime and version information applicable to the data format used for +``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_CPUS_FUNC_ID``. The maximum number of targets +supported is 64. Also the version number supported currently is 1.0. This hypercall +must be handled by the userspace VMM. + ++---------------------+-------------------------------------------------------------+ +| Presence: | Optional; KVM/ARM64 Guests only | ++---------------------+-------------------------------------------------------------+ +| Calling convention: | HVC64 | ++---------------------+----------+--------------------------------------------------+ +| Function ID: | (uint32) | 0xC600007D | ++---------------------+----------+--------------------------------------------------+ +| Arguments: | None | ++---------------------+----------+----+---------------------------------------------+ +| Return Values: | (int64) | R0 | ``NOT_SUPPORTED (-1)`` on error, else | +| | | | [0-31] total migration targets | +| | | | [32-63] version number | ++---------------------+----------+----+---------------------------------------------+ +| | (uint64) | R1 | Reserved / Must be zero | +| +----------+----+---------------------------------------------+ +| | (uint64) | R2 | Reserved / Must be zero | ++---------------------+----------+----+---------------------------------------------+ +| | (uint64) | R3 | Reserved / Must be zero | ++---------------------+----------+----+---------------------------------------------+ + + +``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_CPUS_FUNC_ID`` +------------------------------------------------------- + +Request migration target CPU information for the Guest VM. The information must be +provided as per the format described by the version info in +``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID``. At present, we only support +the below format which corresponds to version 1.0. This hypercall will always be +preceded by ``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID`` and may be +invoked multiple times to retrieve the total number of target CPUs information +advertised. This hypercall must be handled by the userspace VMM. + +A typical userspace usage scenario will be like below: + +1. Receives ``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID`` + + * Returns total number of migration targets and version number + * Reset current target index to zero +2. Receives ``ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_CPUS_FUNC_ID`` + + * Returns MIDR/REVIDR info in return register fields. Can return up to 4 + * Update current target index based on returned target info + * If there are remaining register fields, return zero to indicate the end + * Repeat step 2 until current target index == total number of migration targets + ++---------------------+-------------------------------------------------------------+ +| Presence: | Optional; KVM/ARM64 Guests only | ++---------------------+-------------------------------------------------------------+ +| Calling convention: | HVC64 | ++---------------------+----------+--------------------------------------------------+ +| Function ID: | (uint32) | 0xC600007E | ++---------------------+----------+----+---------------------------------------------+ +| Arguments: | None | ++---------------------+----------+----+---------------------------------------------+ +| Return Values: | (int64) | R0 | ``NOT_SUPPORTED (-1)`` on error, else | +| | | | [0-31] MIDR, [31-63] REVIDR, else | +| | | | [0-63] Zero to mark end. | ++---------------------+----------+----+---------------------------------------------+ +| | (uint64) | R1 | [0-31] MIDR, [32-63] REVIDR, else | +| | | | [0-63] Zero to mark end. | ++---------------------+----------+----+---------------------------------------------+ +| | (uint64) | R2 | [0-31] MIDR, [32-63] REVIDR, else | +| | | | [0-63] Zero to mark end. | ++---------------------+----------+----+---------------------------------------------+ +| | (uint64) | R3 | [0-31] MIDR, [32-63] REVIDR, else | +| | | | [0-63] Zero to mark end. | ++---------------------+----------+----+---------------------------------------------+ diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index f59099a213d0..df87ce48ae9e 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -179,6 +179,8 @@ #define ARM_SMCCC_KVM_FUNC_PKVM_RESV_62 62 #define ARM_SMCCC_KVM_FUNC_PKVM_RESV_63 63 /* End of pKVM hypercall range */ +#define ARM_SMCCC_KVM_FUNC_MIGRN_TARGET_NUM 125 +#define ARM_SMCCC_KVM_FUNC_MIGRN_TARGET_CPUS 126 #define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 #define ARM_SMCCC_KVM_NUM_FUNCS 128 @@ -225,6 +227,17 @@ ARM_SMCCC_OWNER_VENDOR_HYP, \ ARM_SMCCC_KVM_FUNC_MMIO_GUARD) +#define ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_MIGRN_TARGET_NUM) + +#define ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_CPUS_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_MIGRN_TARGET_CPUS) /* ptp_kvm counter type ID */ #define KVM_PTP_VIRT_COUNTER 0 #define KVM_PTP_PHYS_COUNTER 1 From patchwork Thu Oct 24 09:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 13848685 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 7A221CDDE69 for ; Thu, 24 Oct 2024 09:58:55 +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:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: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=zYCk7E6ta+Ey8nwWP/38BvbPODIKMRBP7CdiGiNRmuI=; b=xADocr+pVN80giphilfJnA6bAE hhC4mRCdrJyGkO8cPTzgzuOFEzu65DYGNTG0VzNhWZYzuymffQhJw5TjVfVNPLPp8bCgPwsHmkZSD EpCOlQerpyQsfvVca9dfshYu8RhVtYtJnMdv8PyG+VfaF5VkDs+K3V4yN7f3HZUw7KmcpG77tySS5 u00UvQPbadLSdNDvvZzTdOYMG+WP81p0KiNpPIQjwGtus8izjXyGd/vW606L6vKOHNqoqShZKRsx0 nhP/aUl2oCiEYNZp7fsghytI91S4WEHxR1dgiDtuOBVUFa1Un/8wbYTHEHqR6K1SYf7aTfBGL/xcv SDdlZf6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3uc7-0000000Ha7h-1gil; Thu, 24 Oct 2024 09:58:43 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3uKq-0000000HVv1-115N for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2024 09:40:54 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XZ17m3dHfz6K61T; Thu, 24 Oct 2024 17:38:44 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 5851F1406AD; Thu, 24 Oct 2024 17:40:50 +0800 (CST) Received: from A2303104131.china.huawei.com (10.203.177.241) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 24 Oct 2024 11:40:43 +0200 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [RFC PATCH v2 2/3] KVM: arm64: Use hypercall to retrieve any migration targets Date: Thu, 24 Oct 2024 10:40:11 +0100 Message-ID: <20241024094012.29452-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> References: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.203.177.241] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241024_024052_600694_8AD70B57 X-CRM114-Status: GOOD ( 16.45 ) 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 Provides a paravirt helper function to retrieve any migration target CPUs if available and store it. This will be used in subsequent patch to enable any errata associated with those targets Signed-off-by: Shameer Kolothum --- ToDo: Not sure it make sense to use kvm_arm_hyp_service_available() here as these hypercalls will be handled by userspace VMM. --- arch/arm64/include/asm/cpufeature.h | 7 +++++ arch/arm64/include/asm/paravirt.h | 3 ++ arch/arm64/kernel/cpu_errata.c | 3 ++ arch/arm64/kernel/paravirt.c | 48 +++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 985d966787b1..6623f47814bc 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -386,6 +386,13 @@ struct arm64_cpu_capabilities { const struct cpumask *cpus; }; +#define MIGRN_TARGET_CPUS_HYP_CALL_VER_1 1 +#define MAX_MIGRN_TARGET_CPUS 64 +struct migrn_target { + u32 midr; + u32 revidr; +}; + static inline int cpucap_default_scope(const struct arm64_cpu_capabilities *cap) { return cap->type & ARM64_CPUCAP_SCOPE_MASK; diff --git a/arch/arm64/include/asm/paravirt.h b/arch/arm64/include/asm/paravirt.h index 9aa193e0e8f2..19cd97dafbbc 100644 --- a/arch/arm64/include/asm/paravirt.h +++ b/arch/arm64/include/asm/paravirt.h @@ -19,11 +19,14 @@ static inline u64 paravirt_steal_clock(int cpu) } int __init pv_time_init(void); +void __init pv_errata_migrn_target_init(void); #else #define pv_time_init() do {} while (0) +#define pv_errata_migrn_target_init() do {} while (0) + #endif // CONFIG_PARAVIRT #endif diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index dfefbdf4073a..feaaf2b11f46 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -14,6 +14,9 @@ #include #include +u32 __ro_after_init errata_migrn_target_num; +struct migrn_target __ro_after_init errata_migrn_target_cpus[MAX_MIGRN_TARGET_CPUS]; + static bool __maybe_unused is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) { diff --git a/arch/arm64/kernel/paravirt.c b/arch/arm64/kernel/paravirt.c index aa718d6a9274..675424258419 100644 --- a/arch/arm64/kernel/paravirt.c +++ b/arch/arm64/kernel/paravirt.c @@ -153,6 +153,54 @@ static bool __init has_pv_steal_clock(void) return (res.a0 == SMCCC_RET_SUCCESS); } +extern struct migrn_target __ro_after_init errata_migrn_target_cpus[]; +extern u32 __ro_after_init errata_migrn_target_num; +void __init pv_errata_migrn_target_init(void) +{ + u32 target_num; + struct arm_smccc_res res; + u32 curr = 0; + + /* Check we have already set errata targets */ + if (errata_migrn_target_num) + return; + + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_NUM_FUNC_ID, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + return; + + target_num = lower_32_bits(res.a0); + if (!target_num || target_num > MAX_MIGRN_TARGET_CPUS || + upper_32_bits(res.a0) != MIGRN_TARGET_CPUS_HYP_CALL_VER_1) + return; + + while (curr < target_num) { + unsigned long *ptr; + int j; + + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_TARGET_CPUS_FUNC_ID, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + break; + + ptr = (unsigned long *)&res; + for (j = 0; j < 4; j++, ptr++) { + if (!(*ptr)) + goto out; + errata_migrn_target_cpus[curr].midr = lower_32_bits(*ptr); + errata_migrn_target_cpus[curr].revidr = upper_32_bits(*ptr); + curr++; + } + } +out: + if (curr != target_num) { + pr_warn("Failed to retrieve all migration target CPUs\n"); + return; + } + + errata_migrn_target_num = target_num; + pr_info("Migration target CPUs set to %d\n", target_num); +} + int __init pv_time_init(void) { int ret; From patchwork Thu Oct 24 09:40:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 13848656 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 3D18CCDDE69 for ; Thu, 24 Oct 2024 09:49: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:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: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=In6DanEuIEW3Jj7lZXuhgOozrasX4WvOcfEag/TkPKQ=; b=ftbsQu76lu3H9+MS7SZz+6XQ2Y mJ3L2qt/h6PmhupEPhQLqvhGvtAl+G6ZQnN5C7FsPEfHKEibw6tPoqxgvfyHpBXc83QSMYBFPMbxF XzT786quwHOwZzmm0mPbPzcaXCNSOIQDVaRozcXS99ME/6Nh6KPC1bsLmEDZ56FRja2Ni6HrmMY4p HaIVmrV7tX0j5UCYEaosYw11VZmmFegeGKJfB/1OqHe3YnkRmYSmAJUCr38PEDy1WrgoaPswAZ/uz iBcXdOeHffxGNb75UEDEJIt42WQiUbbyEZyZlvXxDY12hhpngkleE3R3uuSZ1F+hjs3VSEyfJIx0+ KBe/mkuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3uSx-0000000HY1F-167p; Thu, 24 Oct 2024 09:49:15 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3uKz-0000000HVzB-11Ps for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2024 09:41:04 +0000 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XZ19C1RJFz6K5rC; Thu, 24 Oct 2024 17:39:59 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id A97C9140158; Thu, 24 Oct 2024 17:40:59 +0800 (CST) Received: from A2303104131.china.huawei.com (10.203.177.241) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 24 Oct 2024 11:40:52 +0200 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [RFC PATCH v2 3/3] KVM: arm64: Enable errata based on migration target CPUs Date: Thu, 24 Oct 2024 10:40:12 +0100 Message-ID: <20241024094012.29452-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> References: <20241024094012.29452-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.203.177.241] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241024_024101_666305_6D892502 X-CRM114-Status: GOOD ( 15.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 If the Guest has migration target CPUs set, enable all errata that are based on target MIDR/REVIDR. Also make sure we call the paravirt helper to retrieve migration targets if any. Signed-off-by: Shameer Kolothum --- arch/arm64/kernel/cpu_errata.c | 46 ++++++++++++++++++++++++++-------- arch/arm64/kernel/cpufeature.c | 3 +++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index feaaf2b11f46..df6d32dfd5c0 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -18,17 +18,14 @@ u32 __ro_after_init errata_migrn_target_num; struct migrn_target __ro_after_init errata_migrn_target_cpus[MAX_MIGRN_TARGET_CPUS]; static bool __maybe_unused -is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) +__is_affected_midr_range(const struct arm64_cpu_capabilities *entry, u32 midr, u32 revidr) { const struct arm64_midr_revidr *fix; - u32 midr = read_cpuid_id(), revidr; - WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); if (!is_midr_in_range(midr, &entry->midr_range)) return false; midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK; - revidr = read_cpuid(REVIDR_EL1); for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++) if (midr == fix->midr_rv && (revidr & fix->revidr_mask)) return false; @@ -37,27 +34,56 @@ is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) } static bool __maybe_unused -is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry, - int scope) +is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) { + int i; + + for (i = 0; i < errata_migrn_target_num; i++) { + if (__is_affected_midr_range(entry, errata_migrn_target_cpus[i].midr, + errata_migrn_target_cpus[i].revidr)) + return true; + } WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); - return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list); + return __is_affected_midr_range(entry, read_cpuid_id(), read_cpuid(REVIDR_EL1)); } static bool __maybe_unused -is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope) +is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry, + int scope) { - u32 model; + int i; + for (i = 0; i < errata_migrn_target_num; i++) { + if (is_midr_in_range_list(errata_migrn_target_cpus[i].midr, + entry->midr_range_list)) + return true; + } WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list); +} - model = read_cpuid_id(); +static bool __maybe_unused +__is_kryo_midr(const struct arm64_cpu_capabilities *entry, u32 model) +{ model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) | MIDR_ARCHITECTURE_MASK; return model == entry->midr_range.model; } +static bool __maybe_unused +is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope) +{ + int i; + + for (i = 0; i < errata_migrn_target_num; i++) { + if (__is_kryo_midr(entry, errata_migrn_target_cpus[i].midr)) + return true; + } + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + return __is_kryo_midr(entry, read_cpuid_id()); +} + static bool has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry, int scope) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index f7fd7e3259e4..390f4ffa773c 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include @@ -3597,6 +3598,8 @@ unsigned long cpu_get_elf_hwcap2(void) static void __init setup_boot_cpu_capabilities(void) { + pv_errata_migrn_target_init(); + /* * The boot CPU's feature register values have been recorded. Detect * boot cpucaps and local cpucaps for the boot CPU, then enable and