From nobody Thu May 2 19:40:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1487801459870382.0534742576275; Wed, 22 Feb 2017 14:10:59 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1MM7NtQ001418; Wed, 22 Feb 2017 17:07:23 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1MM7MIt030728 for ; Wed, 22 Feb 2017 17:07:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4E8DA1587B; Wed, 22 Feb 2017 22:07:22 +0000 (UTC) Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id D37C02D654; Wed, 22 Feb 2017 22:07:21 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 19:07:07 -0300 Message-Id: <20170222220709.3707-2-ehabkost@redhat.com> In-Reply-To: <20170222220709.3707-1-ehabkost@redhat.com> References: <20170222220709.3707-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/3] i386: host_vendor_fms() helper function X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Helper function for code that needs to check the host CPU vendor/family/model/stepping values. Signed-off-by: Eduardo Habkost --- Changes v1 -> v2: * Coding style fix (split long lines) --- target/i386/cpu.h | 1 + target/i386/cpu.c | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 5f75ab1b15..647435a1d9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1431,6 +1431,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, void cpu_clear_apic_feature(CPUX86State *env); void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx= ); +void host_vendor_fms(char *vendor, int *family, int *model, int *stepping); =20 /* helper.c */ int x86_cpu_handle_mmu_fault(CPUState *cpu, vaddr addr, diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7a04e6ff34..a8e4f37e27 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -682,6 +682,25 @@ void host_cpuid(uint32_t function, uint32_t count, *edx =3D vec[3]; } =20 +void host_vendor_fms(char *vendor, int *family, int *model, int *stepping) +{ + uint32_t eax, ebx, ecx, edx; + + host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); + x86_cpu_vendor_words2str(vendor, ebx, edx, ecx); + + host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); + if (family) { + *family =3D ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); + } + if (model) { + *model =3D ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); + } + if (stepping) { + *stepping =3D eax & 0x0F; + } +} + /* CPU class name definitions: */ =20 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU @@ -1547,18 +1566,12 @@ static void host_x86_cpu_class_init(ObjectClass *oc= , void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); X86CPUClass *xcc =3D X86_CPU_CLASS(oc); - uint32_t eax =3D 0, ebx =3D 0, ecx =3D 0, edx =3D 0; =20 xcc->kvm_required =3D true; xcc->ordering =3D 9; =20 - host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); - x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx); - - host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); - host_cpudef.family =3D ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); - host_cpudef.model =3D ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); - host_cpudef.stepping =3D eax & 0x0F; + host_vendor_fms(host_cpudef.vendor, &host_cpudef.family, + &host_cpudef.model, &host_cpudef.stepping); =20 cpu_x86_fill_model_id(host_cpudef.model_id); =20 --=20 2.11.0.259.g40922b1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 19:40:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487801352200112.18326326029216; Wed, 22 Feb 2017 14:09:12 -0800 (PST) Received: from localhost ([::1]:55461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgf5w-0007nh-Ul for importer@patchew.org; Wed, 22 Feb 2017 17:09:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgf4H-0006rO-GO for qemu-devel@nongnu.org; Wed, 22 Feb 2017 17:07:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgf4G-0002bh-BG for qemu-devel@nongnu.org; Wed, 22 Feb 2017 17:07:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgf4G-0002bT-5u for qemu-devel@nongnu.org; Wed, 22 Feb 2017 17:07:24 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6AC1D3D95F for ; Wed, 22 Feb 2017 22:07:24 +0000 (UTC) Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MM7NNk024716; Wed, 22 Feb 2017 17:07:23 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 19:07:08 -0300 Message-Id: <20170222220709.3707-3-ehabkost@redhat.com> In-Reply-To: <20170222220709.3707-1-ehabkost@redhat.com> References: <20170222220709.3707-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 22 Feb 2017 22:07:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] i386/kvm: Blacklist TSX on known broken hosts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libvir-list@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Some Intel CPUs are known to have a broken TSX implementation. A microcode update from Intel disabled TSX on those CPUs, but GET_SUPPORTED_CPUID might be reporting it as supported if the hosts were not updated yet. Manually fixup the GET_SUPPORTED_CPUID data to ensure we will never enable TSX when running on those hosts. Reference: * glibc commit 2702856bf45c82cf8e69f2064f5aa15c0ceb6359: https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommit;h=3D2702856bf45c82cf= 8e69f2064f5aa15c0ceb6359 Signed-off-by: Eduardo Habkost --- target/i386/kvm.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 27fd0505df..2694f35e74 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -273,6 +273,19 @@ static int get_para_features(KVMState *s) return features; } =20 +static bool host_tsx_blacklisted(void) +{ + int family, model, stepping;\ + char vendor[CPUID_VENDOR_SZ + 1]; + + host_vendor_fms(vendor, &family, &model, &stepping); + + /* Check if we are running on a Haswell host known to have broken TSX = */ + return !strcmp(vendor, CPUID_VENDOR_INTEL) && + (family =3D=3D 6) && + ((model =3D=3D 63 && stepping < 4) || + model =3D=3D 60 || model =3D=3D 69 || model =3D=3D 70); +} =20 /* Returns the value for a specific register on the cpuid entry */ @@ -356,6 +369,10 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uin= t32_t function, } } else if (function =3D=3D 6 && reg =3D=3D R_EAX) { ret |=3D CPUID_6_EAX_ARAT; /* safe to allow because of emulated AP= IC */ + } else if (function =3D=3D 7 && index =3D=3D 0 && reg =3D=3D R_EBX) { + if (host_tsx_blacklisted()) { + ret &=3D ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE); + } } else if (function =3D=3D 0x80000001 && reg =3D=3D R_EDX) { /* On Intel, kvm returns cpuid according to the Intel spec, * so add missing bits according to the AMD spec: --=20 2.11.0.259.g40922b1 From nobody Thu May 2 19:40:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1487801462150882.5718640396615; Wed, 22 Feb 2017 14:11:02 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1MM7X6j027729; Wed, 22 Feb 2017 17:07:33 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1MM7QtE030751 for ; Wed, 22 Feb 2017 17:07:26 -0500 Received: from localhost (ovpn-116-33.gru2.redhat.com [10.97.116.33]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MM7PwD031318; Wed, 22 Feb 2017 17:07:25 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 19:07:09 -0300 Message-Id: <20170222220709.3707-4-ehabkost@redhat.com> In-Reply-To: <20170222220709.3707-1-ehabkost@redhat.com> References: <20170222220709.3707-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/3] i386: Change stepping of Haswell to non-blacklisted value X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" glibc blacklists TSX on Haswell CPUs with model=3D=3D60 and stepping < 4. To make the Haswell CPU model more useful, make those guests actually use TSX by changing CPU stepping to 4. References: * glibc commit 2702856bf45c82cf8e69f2064f5aa15c0ceb6359 https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommit;h=3D2702856bf45c82cf= 8e69f2064f5aa15c0ceb6359 Signed-off-by: Eduardo Habkost --- include/hw/i386/pc.h | 5 +++++ target/i386/cpu.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 079e8d9393..2ada479138 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -390,6 +390,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_= t *); .driver =3D TYPE_X86_CPU,\ .property =3D "vmware-cpuid-freq",\ .value =3D "off",\ + },\ + {\ + .driver =3D "Haswell-" TYPE_X86_CPU,\ + .property =3D "stepping",\ + .value =3D "1",\ }, =20 #define PC_COMPAT_2_7 \ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a8e4f37e27..eab1ad7935 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1190,7 +1190,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .vendor =3D CPUID_VENDOR_INTEL, .family =3D 6, .model =3D 60, - .stepping =3D 1, + .stepping =3D 4, .features[FEAT_1_EDX] =3D CPUID_VME | CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_M= CA | --=20 2.11.0.259.g40922b1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list