From patchwork Fri Oct 11 07:50:47 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: 13832206 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 93035CFC611 for ; Fri, 11 Oct 2024 07:53:48 +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-Transfer-Encoding: Content-Type:MIME-Version: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:In-Reply-To:References:List-Owner; bh=Tg1ZmIr59VzBFXmoNQhq0GwOX1T32HH+zBKXaJio57A=; b=trql7wk/SzO9KbNEkuTZZjTgzy 1oaog6zQiPbWW73346KFfyd0OaINHfUF3OmmWtXANosUNL0Mkvn7RshyuO3qDSg2quVJajvvhD+OG aGS633NnOYLWyH22oMPxsgn6/anMGOZ2XlB/lIRVtqxQpWwao9nXbwTR1aAFRmUKPbiIenUtjDhPG 1QPdNNvJ+8ayyLr9JoDQhSTWYHJMJn7V1etB0Di+cJMvLLdnGrTh/JFHq81eS9pXPP9o//zrHQa2R hPP9o6u+34+diQ5nIQyrImyKAUHXxIFmdzqq8GlJn3I+XOTaiqIpdVVZttvyl32XbSerUtirhlpCN C389mTUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szASu-0000000FcWx-404h; Fri, 11 Oct 2024 07:53:36 +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 1szARV-0000000FcJM-2QfE for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 07:52:11 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XPzN71WsMz6JB3Q; Fri, 11 Oct 2024 15:51:35 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 17143140AE5; Fri, 11 Oct 2024 15:51:58 +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:51:51 +0200 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [RFC PATCH 0/6] KVM: arm64: Errata management for VM Live migration Date: Fri, 11 Oct 2024 08:50:47 +0100 Message-ID: <20241011075053.80540-1-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 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_005209_949489_F356B988 X-CRM114-Status: GOOD ( 16.82 ) 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 Hi, On ARM64 platforms most of the errata workarounds are based on CPU MIDR/REVIDR values and a number of these workarounds need to be implemented by the Guest kernel as well. This creates a problem when Guest needs to be migrated to a platform that differs in these MIDR/REVIDR values even if the VMM can come up with a common minimum feature list for the Guest using the recently introduced "Writable ID registers" support. (This is roughly based on a discussion I had with Marc and Oliver at KVM forum. Marc outlined his idea for a solution and this is an attempt to implement it. Thanks to both and I take all the blame if this is nowhere near what is intended/required) This RFC proposes a solution to handle the above issue by introducing the following, 1. A new VM IOCTL, KVM_ARM_SET_MIGRN_TARGET_CPUS _IOW(KVMIO, 0xb7, struct kvm_arm_migrn_cpus) This can be used by the userspace(VMM) to set the target CPUs the Guest will run in its lifetime. See patch #2 2. Add hypercall support for Guest kernel to retrieve any migration errata bitmap(ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_ERRATA) The above will return the bitmaps in R0-R3 registers. See patch #4 3. The "capability" field in struct arm64_cpu_capabilities is a generated one at present and may get renumbered or reordered. Hence, we can't use this directly for migration errata bitmaps. Instead, introduced "migartion_safe_cap", which has to be set statically for any erratum that needs to be enabled and is safe for migration purposes. See patches 3 & 6. 4. Rest of the patches includes the plumbing required to populate the errata bitmap based on the target CPUs set by the VMM and update the system_cap based on it. ToDos:- -We still need a way to handle the error in setting the invariant registers(MIDR/REVIDR/AIDR) during Guest migration. Perhaps we can handle it in userspace? - Possibly we could do better to avoid the additional "migartion_safe_cap" use. Suggestions welcome. -There are errata that require more than MIDR/REVIDR, eg: CTR_EL0. How to handle those? -Check for locking requirements if any. This is lightly tested on a HiSilicon ARM64 platform. Please take a look and let me know your thoughts. Thanks, Shameer Shameer Kolothum (6): arm64: Modify callback matches() fn to take a target info KVM: arm64: Add support for VMM to set migration target KVM: arm64: Introduce a helper to retrieve errata KVM: arm64: Add hypercall support for retrieving migration errata bitmap arm64: Use hypercall to check for any migration related errata arm64: errata: Set migration_safe_cap for MIDR based errata arch/arm64/include/asm/cpu_migrn_errata.h | 42 +++++++ arch/arm64/include/asm/cpufeature.h | 15 ++- arch/arm64/include/asm/kvm_host.h | 3 + arch/arm64/include/asm/paravirt.h | 4 + arch/arm64/include/asm/spectre.h | 8 +- arch/arm64/include/uapi/asm/kvm.h | 13 ++ arch/arm64/kernel/cpu_errata.c | 113 ++++++++++++++---- arch/arm64/kernel/cpufeature.c | 138 +++++++++++++++------- arch/arm64/kernel/paravirt.c | 18 +++ arch/arm64/kernel/proton-pack.c | 13 +- arch/arm64/kvm/arm.c | 38 ++++++ arch/arm64/kvm/hypercalls.c | 20 ++++ include/linux/arm-smccc.h | 8 +- include/uapi/linux/kvm.h | 2 + 14 files changed, 361 insertions(+), 74 deletions(-) create mode 100644 arch/arm64/include/asm/cpu_migrn_errata.h