Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5774264pxv; Wed, 7 Jul 2021 11:25:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY9XOa2RxrJpbyb8tHWdBMzK0cTDeGNhLEPLZUxcCk2oqkH2k0oI5tOn3jw/p5YfKRHDj0 X-Received: by 2002:a05:6402:1591:: with SMTP id c17mr6470200edv.146.1625682317555; Wed, 07 Jul 2021 11:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625682317; cv=none; d=google.com; s=arc-20160816; b=hi2j/4xXbq3Xk0gzFuwjbAp97MNl5w0K3gQ7uoPTq3xdPq/lXe/VuhO9fCxrQqTn+Y gnD5/fhyNoiW9OoEHtex5RV1wgSVnLademhLy1ZudbVkD/Pc3snmHO2Sk3N1kq9V5Xe6 iS7fZXbT69IKRBG9FMTou+bNusZvWStXOAIuILsmXCnNOqo7+b9w4E7WP2CNByV9zRoq SyGjnt8cJic6qe1i3YmAY32CM8leVUPe389NL2UdQZ73GXrFz4K6wbCysbdXbiK4/ova gZUpboYqFLx2zKq5nRqQ2EfYn6OGtIGo5quAkg3TTdwN1dTmaaVTm09nHQaecP9o6OqD ygwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mF5DpeP80QzR+srksvVofJQ5IcNTAEAob1kzMD7f+i8=; b=pGExIhZhr5jJNhZrx/3sxR+Rpwnd+1c4/Ec96K39KiLd0kDFJIcQigt/p6mdgTQ4sN Qqlugg1tktsXpNhvHVMGoY6r364rNwFCT97tuSoC3c2aeZTUtjrdt5Xk6t7d+or3T8x2 /ZzRV5q9ERNhjQSWEpwpsPYrq48Wgp95n9yha4f/xamvrj4p8DnWXvDc6KB9xJUM6Wlq WoGzu0HfpXfR8zC7Y6HGtQ9W3pF9ktbDb+28Wqjp5Jea6hgsMxcl+gfnYBcuNW5G3z/C K5q+uyhEqhxL3bzHBOaUTbDwV/7pr6IvdeBsLRL0Z7tsEcPMQKbU6LpoSiCsnGmUIlDb zEdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MWv29evP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi15si18953566edb.459.2021.07.07.11.24.54; Wed, 07 Jul 2021 11:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MWv29evP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbhGGS0b (ORCPT + 99 others); Wed, 7 Jul 2021 14:26:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59423 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231364AbhGGS0a (ORCPT ); Wed, 7 Jul 2021 14:26:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625682228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mF5DpeP80QzR+srksvVofJQ5IcNTAEAob1kzMD7f+i8=; b=MWv29evPpLgWw0RWHBKs3TRyi8WXALF0PtVH5LD2Ofq0HkQBIFMmBoyyBGOaDNXFm471GU /VVOnStR23zl5eLFTdrlvsOvaoMAS1dF1vwObAqThi/NIdDqToqQQl/8xbFpeo1rvI/MCF usIzrKZBEqxzu5yjBm2HhRvBpTjqW+k= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-wePUXVuEOwGs6Fp2QD2prg-1; Wed, 07 Jul 2021 14:23:47 -0400 X-MC-Unique: wePUXVuEOwGs6Fp2QD2prg-1 Received: by mail-lf1-f70.google.com with SMTP id t14-20020ac24c0e0000b0290323b04a9bd4so1538643lfq.9 for ; Wed, 07 Jul 2021 11:23:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mF5DpeP80QzR+srksvVofJQ5IcNTAEAob1kzMD7f+i8=; b=j3+KA57f7HTpYFxmqRQS3cmzf8xfrhIRPAxesLMn8CSO6pbkKWQ1UaKK0lCQ1SQU9n xGMMidVplwKOyll+EGIPZh5Mr2fESp1ijybRl5ip9emNYBDeG/fAl1XvD9650jRxgkvu QihuVUCX3JPGtsNpj9d72xa+WgGfRpGsVuB/NLPFyqmBxBN279JxNeyh7TVH6uAHkcx0 x0Mxq6HNkDqFyyYF7I+p8e8dv0jQZk6W1OYAXNHr5e3Y4zJVKk9XK4IR0Vt4MSqN5MwN xuCCdxpVpuBXBUIEDz+WdYvV/ZBhermQHejh0pAvM2UN4sdFl1UXzEVavmbZDOUxsAEH S0RQ== X-Gm-Message-State: AOAM531meDP9JPrnD7JMGh0or4wSqjKiipj8h4Kpdf+JBCHshGuak1gY 89um7Lns64olyTTZ5sVIVxXyNtY7jnyEfXOVYGZXYY+Ov0/iggbCNkWHEEbVuBEsC+UwtnZ4MHn fxzqJoKpXgLYCcXZTzNM4PglCsI3C5bb39WuMkQ27 X-Received: by 2002:a05:6512:102e:: with SMTP id r14mr18889739lfr.34.1625682225878; Wed, 07 Jul 2021 11:23:45 -0700 (PDT) X-Received: by 2002:a05:6512:102e:: with SMTP id r14mr18889718lfr.34.1625682225596; Wed, 07 Jul 2021 11:23:45 -0700 (PDT) MIME-Version: 1.0 References: <20210706195233.h6w4cm73oktfqpgz@habkost.net> <4cc2c5fe-2153-05c5-dedd-8cb650753740@redhat.com> <671be35f-220a-f583-aa31-3a2da7dae93a@redhat.com> In-Reply-To: From: Eduardo Habkost Date: Wed, 7 Jul 2021 14:23:29 -0400 Message-ID: Subject: Re: [PATCH 4/4] x86/tsx: Add cmdline tsx=fake to not clear CPUID bits RTM and HLE To: Jim Mattson Cc: Paolo Bonzini , Pawan Gupta , Thomas Gleixner , Borislav Petkov , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , x86@kernel.org, "H. Peter Anvin" , "Paul E. McKenney" , Randy Dunlap , Andrew Morton , "Maciej W. Rozycki" , Viresh Kumar , Vlastimil Babka , Tony Luck , Sean Christopherson , Kyung Min Park , Fenghua Yu , Ricardo Neri , Tom Lendacky , Juergen Gross , Krish Sadhukhan , Kan Liang , Joerg Roedel , Victor Ding , Srinivas Pandruvada , Brijesh Singh , Dave Hansen , Mike Rapoport , Anthony Steinhauser , Anand K Mistry , Andi Kleen , Miguel Ojeda , Nick Desaulniers , Joe Perches , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, Jiri Denemark , "libvir-list@redhat.com" , Michal Privoznik Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 7, 2021 at 1:18 PM Jim Mattson wrote: > > On Wed, Jul 7, 2021 at 10:08 AM Eduardo Habkost wrote: > > > > On Wed, Jul 7, 2021 at 12:42 PM Jim Mattson wrote: > > > > > > On Wed, Jul 7, 2021 at 8:09 AM Eduardo Habkost wrote: > > > > > > > > CCing libvir-list, Jiri Denemark, Michal Privoznik, so they are aware > > > > that the definition of "supported CPU features" will probably become a > > > > bit more complex in the future. > > > > > > Has there ever been a clear definition? Family, model, and stepping, > > > for instance: are these the only values supported? That would make > > > cross-platform migration impossible. What about the vendor string? Is > > > that the only value supported? That would make cross-vendor migration > > > impossible. For the maximum input value for basic CPUID information > > > (CPUID.0H:EAX), is that the only value supported, or is it the maximum > > > value supported? On the various individual feature bits, does a '1' > > > imply that '0' is also supported, or is '1' the only value supported? > > > What about the feature bits with reversed polarity (e.g. > > > CPUID.(EAX=07H,ECX=0):EBX.FDP_EXCPTN_ONLY[bit 6])? > > > > > > This API has never made sense to me. I have no idea how to interpret > > > what it is telling me. > > > > Is this about GET_SUPPORTED_CPUID, QEMU's query-cpu-model-expansion & > > related commands, or the libvirt CPU APIs? > > This is my ongoing rant about KVM_GET_SUPPORTED_CPUID. > I agree the definition is not clear. I have tried to enumerate below what QEMU assumes about the return value of KVM_GET_SUPPORTED_CPUID. These are a collection of workarounds and feature-specific rules that are encoded in the kvm_arch_get_supported_cpuid() x86_cpu_filter_features(), and cpu_x86_cpuid() functions in QEMU. 1. Passing through the returned values (unchanged) from KVM_GET_SUPPORTED_CPUID to KVM_SET_CPUID is assumed to be always safe, as long as the ability to save/resume VCPU state is not required. (This is the behavior implemented by "-cpu host,migratable=off") 2. The safety of setting a bit to a different value requires specific knowledge about the CPUID bit. 2.1. For a specific set of registers (see below), QEMU assumes it's safe to set the bit to 0 when KVM_GET_SUPPORTED_CPUID returns 1. 2.2. For a few specific leaves (see below), there are more complex rules. 2.4. For all other leaves, QEMU doesn't use the return value of KVM_GET_SUPPORTED_CPUID at all (AFAICS). The CPUID leaves mentioned in 2.1 are: CPUID[1].EDX CPUID[1].ECX CPUID[6].EAX CPUID[EAX=7,ECX=0].EBX - This unfortunately includes de-feature bits like FDP_EXCPTN_ONLY and ZERO_FCS_FDS CPUID[EAX=7,ECX=0].ECX CPUID[EAX=7,ECX=0].EDX CPUID[EAX=7,ECX=1].EAX CPUID[EAX=0Dh,ECX=0].EAX CPUID[EAX=0Dh,ECX=0].EDX CPUID[EAX=0Dh,ECX=1].EAX - Note that CPUID[0Dh] has additional logic to ensure XSAVE component info on CPUID is consistent CPUID[40000001h].EAX CPUID[40000001h].EDX CPUID[80000001h].EDX CPUID[80000001h].ECX CPUID[80000007h].EDX CPUID[80000008h].EBX CPUID[8000000Ah].EDX CPUID[C0000001h].EDX Some of the CPUID leaves mentioned in 2.2 are: CPUID[1].ECX.HYPERVISOR[bit 31] - Can be enabled unconditionally CPUID[1].ECX.TSC_DEADLINE_TIMER[bit 24] - Can be set to 1 if using the in-kernel irqchip and KVM_CAP_TSC_DEADLINE_TIMER is enabled CPUID[1].ECX.X2APIC[bit 21] - Can be set to 1 if using the in-kernel irqchip CPUID[1].ECX.MONITOR[bit 3] - Can be set to 1 if KVM_X86_DISABLE_EXITS_MWAIT is enabled CPUID[6].EAX.ARAT[bit 2] - Can be enabled unconditionally CPUID[EAX=7,ECX=0].EDX.ARCH_CAPABILITIES - Workaround for KVM bug in Linux v4.17-v4.20 CPUID[EAX=14h,ECX=0], CPUID{EAX=14h,ECX=1] - Most bits must match the host, unless CPUID[EAX=7,ECX=0].EBX.INTEL_PT[bit 25] is 0 CPUID[80000001h].EDX - AMD-specific feature flag aliases can be set based on CPUID[1].EDX CPUID[40000001h].EAX - KVM_FEATURE_PV_UNHALT requires in-kernel irqchip - KVM_FEATURE_MSI_EXT_DEST_ID requires split irqchip CPUID[40000001].EDX.KVM_HINTS_REALTIME - Can be enabled unconditionally -- Eduardo