From nobody Tue May 7 05:03:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685691631671404.0015418963069; Fri, 2 Jun 2023 00:40:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4zNs-0003gJ-Dt; Fri, 02 Jun 2023 03:39:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4zNn-0003fV-Uw for qemu-devel@nongnu.org; Fri, 02 Jun 2023 03:39:36 -0400 Received: from mx20.baidu.com ([111.202.115.85] helo=baidu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4zNj-0005Bz-Nh for qemu-devel@nongnu.org; Fri, 02 Jun 2023 03:39:34 -0400 From: Shiyuan Gao To: , , , CC: , Shiyuan Gao Subject: [PATCH] kvm: limit the maximum CPUID.0xA.edx[0..4] to 3 Date: Fri, 2 Jun 2023 15:38:57 +0800 Message-ID: <20230602073857.96790-1-gaoshiyuan@baidu.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BJHW-Mail-Ex14.internal.baidu.com (10.127.64.37) To bjkjy-mail-ex26.internal.baidu.com (172.31.50.42) X-FEAS-Client-IP: 172.31.51.58 X-FE-Policy-ID: 15:10:21:SYSTEM Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=111.202.115.85; envelope-from=gaoshiyuan@baidu.com; helo=baidu.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1685691632852100003 Content-Type: text/plain; charset="utf-8" Now, the CPUID.0xA depends on the KVM report. The value of CPUID.0xA.edx[0.= .4] and num_architectural_pmu_fixed_counters are inconsistent when the host ker= nel before this commit 2e8cd7a3b828 ("kvm: x86: limit the maximum number of vPMU fixed counters to 3") on icelake microarchitecture. This also break the live-migration between source host kernel before commit 2e8cd7a3b828 and dest host kernel after the commit on icelake microarchitec= ture. Signed-off-by: Shiyuan Gao --- target/i386/kvm/kvm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index de531842f6..e77129b737 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1761,7 +1761,7 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; - uint32_t limit, i, j, cpuid_i; + uint32_t limit, i, j, cpuid_i, cpuid_0xa; uint32_t unused; struct kvm_cpuid_entry2 *c; uint32_t signature[3]; @@ -1773,6 +1773,7 @@ int kvm_arch_init_vcpu(CPUState *cs) memset(&cpuid_data, 0, sizeof(cpuid_data)); =20 cpuid_i =3D 0; + cpuid_0xa =3D 0; =20 has_xsave2 =3D kvm_check_extension(cs->kvm_state, KVM_CAP_XSAVE2); =20 @@ -2045,6 +2046,9 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =3D i; c->flags =3D 0; cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + if (0x0a =3D=3D i) { + cpuid_0xa =3D cpuid_i - 1; + } if (!c->eax && !c->ebx && !c->ecx && !c->edx) { /* * KVM already returns all zeroes if a CPUID entry is miss= ing, @@ -2059,7 +2063,11 @@ int kvm_arch_init_vcpu(CPUState *cs) if (limit >=3D 0x0a) { uint32_t eax, edx; =20 - cpu_x86_cpuid(env, 0x0a, 0, &eax, &unused, &unused, &edx); + assert(cpuid_0xa >=3D 0x0a); + + c =3D &cpuid_data.entries[cpuid_0xa]; + eax =3D c->eax; + edx =3D c->edx; =20 has_architectural_pmu_version =3D eax & 0xff; if (has_architectural_pmu_version > 0) { @@ -2078,6 +2086,7 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 if (num_architectural_pmu_fixed_counters > MAX_FIXED_COUNT= ERS) { num_architectural_pmu_fixed_counters =3D MAX_FIXED_COU= NTERS; + c->edx =3D (edx & ~0x1f) | num_architectural_pmu_fixed= _counters; } } } --=20 2.36.1