From patchwork Fri Oct 11 07:50:52 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: 13832219 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 B333FCFC60F for ; Fri, 11 Oct 2024 08:00:39 +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=yUKuSrMYI3kc/K570btjL7r5JtUXXr8KyamToKrrtJc=; b=y5Om6e+PWOiALA8JtYYtKw+i3R KwuBVt1EE8lKTDDNR9UnlzrIIHu+Zi3oPbrnYiP2wolvuV3ef0Rx+VfzjyeyiDUN2IPANDiaYPoB6 /CFjJoDd85Z9pi6SoL7RdZjg9fXu8BNZ/iQ8myzrUw93Pd51fnHoJO7rRwwhsnVPAwwtAFjuzLL9r 3C/MzF+4j7dQxRvaWA+/rqMeEYjm6WAG3jiKs3HyMdTUzPnsDMC7G9395ifxWabegRp3Ib/eEiZ5O RRqne5imFmvNvo8Kth5BKUJcHGKs5QKd48SNliutowHBCOleMO7/yed/pSb6DI4mIdfTckFPLeT/k b8SkksiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szAZV-0000000FdD5-3NtQ; Fri, 11 Oct 2024 08:00:25 +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 1szAS2-0000000FcQV-0sVX for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 07:52:43 +0000 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XPzMm6PJNz6FGb8; Fri, 11 Oct 2024 15:51:16 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 56C1014010C; Fri, 11 Oct 2024 15:52:40 +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; Fri, 11 Oct 2024 09:52:33 +0200 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [RFC PATCH 5/6] arm64: Use hypercall to check for any migration related errata Date: Fri, 11 Oct 2024 08:50:52 +0100 Message-ID: <20241011075053.80540-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20241011075053.80540-1-shameerali.kolothum.thodi@huawei.com> References: <20241011075053.80540-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.203.177.241] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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-20241011_005242_576608_6678686B X-CRM114-Status: GOOD ( 13.81 ) 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 We now have a hypercall to retrieve any migration related erratas for Guest kernels. Use that and update system_cpucaps based on any set errata. Signed-off-by: Shameer Kolothum --- arch/arm64/include/asm/paravirt.h | 4 ++++ arch/arm64/kernel/cpufeature.c | 27 +++++++++++++++++++++++++++ arch/arm64/kernel/paravirt.c | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/arch/arm64/include/asm/paravirt.h b/arch/arm64/include/asm/paravirt.h index 9aa193e0e8f2..f2cbf2c51acc 100644 --- a/arch/arm64/include/asm/paravirt.h +++ b/arch/arm64/include/asm/paravirt.h @@ -19,11 +19,15 @@ static inline u64 paravirt_steal_clock(int cpu) } int __init pv_time_init(void); +int __init pv_update_migrn_errata(unsigned long *errata_map); #else #define pv_time_init() do {} while (0) +static inline int pv_update_migrn_errata(unsigned long *errata_map) +{ return -EINVAL; } + #endif // CONFIG_PARAVIRT #endif diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 7b39b0a4aadd..829b9eccec09 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -85,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,8 @@ static struct arm64_cpu_capabilities const __ro_after_init *cpucap_ptrs[ARM64_NC DECLARE_BITMAP(boot_cpucaps, ARM64_NCAPS); +DECLARE_BITMAP(migrn_safe_errata_map, ARM64_NCAPS); + bool arm64_use_ng_mappings = false; EXPORT_SYMBOL(arm64_use_ng_mappings); @@ -3189,6 +3192,29 @@ void arm_get_migrn_errata_map(void *target, unsigned long *errata_map) } } +static void update_migrn_errata(void) +{ + int i, j; + const struct arm64_cpu_capabilities *caps; + u16 scope = ARM64_CPUCAP_LOCAL_CPU_ERRATUM; + + if (pv_update_migrn_errata(migrn_safe_errata_map)) + return; + + for_each_set_bit(i, migrn_safe_errata_map, ARM64_NCAPS) { + for (j = 0; j < ARM64_NCAPS; j++) { + caps = cpucap_ptrs[j]; + if (!caps || !(caps->type & scope) || + caps->migration_safe_cap != i || + cpus_have_cap(caps->capability)) + continue; + if (caps->desc && !caps->cpus) + pr_info("Updated with migration errata: %s\n", caps->desc); + __set_bit(caps->capability, system_cpucaps); + } + } +} + static void update_cpu_capabilities(u16 scope_mask) { int i; @@ -3566,6 +3592,7 @@ static void __init setup_system_capabilities(void) * cpucaps. */ update_cpu_capabilities(SCOPE_SYSTEM); + update_migrn_errata(); enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU); apply_alternatives_all(); diff --git a/arch/arm64/kernel/paravirt.c b/arch/arm64/kernel/paravirt.c index aa718d6a9274..04b1930d0e9a 100644 --- a/arch/arm64/kernel/paravirt.c +++ b/arch/arm64/kernel/paravirt.c @@ -23,6 +23,7 @@ #include #include #include +#include struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; @@ -153,6 +154,23 @@ static bool __init has_pv_steal_clock(void) return (res.a0 == SMCCC_RET_SUCCESS); } +int __init pv_update_migrn_errata(unsigned long *errata_map) +{ + int ret; + struct arm_smccc_res res; + + ret = kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MIGRN_ERRATA); + if (ret <= 0) + return -EOPNOTSUPP; + + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_ERRATA, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + return -EINVAL; + + bitmap_from_arr64(errata_map, &res, ARM64_NCAPS); + return 0; +} + int __init pv_time_init(void) { int ret;