Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1106461lqo; Fri, 17 May 2024 10:48:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXz3/SHzijrltXEuz4YsT5OF8MUPS7zZwDS28ryPnG/Zjh4hsmCpfMf4BefOE+pLph7du3KI1yTxE1nddFazLGsfhaf9Qw+qUAenyH0SQ== X-Google-Smtp-Source: AGHT+IEmG8pgydl0X5k10di8zXXk86NwsLTF2tSyeqRmXAgGFEhExJj6gntpnouqbmmCBSituxwk X-Received: by 2002:a17:907:7787:b0:a5a:891b:416b with SMTP id a640c23a62f3a-a5a891b96d7mr701091866b.20.1715968103440; Fri, 17 May 2024 10:48:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715968103; cv=pass; d=google.com; s=arc-20160816; b=qCpfcZILDVqNojBr4/X1hrwPdHEln8NBuaIWCBf/xl4pcuU7In0ej1Pya0AS2ztkaB nkqdNdi/NASEO+cjoD3N6iML57eGwWFGUjtlZkym5zOhbVl14pftXpaOxGHyj8i+rT1o vue36mc9YVp8KmptoGEzHbwdhkUmpnyJiiCtfD4+gS5v8TzsZwABBqc4Ovx611Brzjh7 gXPN92xI/zELZoWzMtSqYvo5LYmYjtkGYy6hE206q1uQ4zpaSxKXmZB4KS9iPwrvO9K0 h2U1JE2maEo3uIJInevohNuKoPIxyx8752GWJL4cRsskMaARDe50kBMea2YICTEO01CH KTng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=IIpzTjnpYWvr4z4L+FkXXo9hR1khs/BwnW5TGVqv/IQ=; fh=QEU6YlSN09WR8eaqPOr9SWb3lb9iUeHe3+NKqEpIkCc=; b=ar/43u5x89sCO/rGhwx0yxXGka2US25nDqSdQhEioJvUO1C6CWoqFHCBbMAuoWDKPr 2QKsVeH2MswFOR4OeHq9BisiBUxNbzh3M1kYxKOWxRV7Fvouf9wSzUD2jdE48IMzTnv4 AqA4VsDLnqszny9pNaFnXcLdPmfXS9MEcgVbOnJIyYukUzBjZZrEwuDgkOkb+bMrcL/i n4nysfJ21AO2Pn74MJMQVO/GsGOzyCbUhOqCZOR/RiFfW5HOadcOtuOolpVy/NJqp08/ fAD7JTMJ4j3CARj85tglh4b75wBIucL6rabnk/TX0+WWe7JIe7MI5eMDW6CBrCVTcTP/ qI2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rHqiOYdp; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-182459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182459-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5cdc24ae2bsi265230966b.286.2024.05.17.10.48.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 10:48:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rHqiOYdp; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-182459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182459-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 032851F2320B for ; Fri, 17 May 2024 17:48:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C9E913E88B; Fri, 17 May 2024 17:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rHqiOYdp" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FF1D152188 for ; Fri, 17 May 2024 17:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967636; cv=none; b=HI3j4NfPF8NFfWFE6jnR5/IQ/khLFDIB3IzFcCMkUzT3xjNb0mvDafG0QYAjCT+SPHe7qdRlHubXe+zir/6Ili6MnbrGP4F1lYdqOje3CXqmDmL+rcVmMIZXxSXc75fgoMdAeGZsBAwlzOr4WPFnMepoo6Th3TAna2xhv73i574= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967636; c=relaxed/simple; bh=oxejklLlbBEENy3IfZNQJ8hlgrGXAQmHeztU44XlEA4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Vo20iZJjmFfglOdfnrumAVpbzEDsnqGtMDAxi6w3rnYrhmaK5BYalq7tTIvl650SyOALLrRaMidrU5h9/msFOooXATK8irX0Ecn0Jh/xtpu6D7WheRJIFGWXIzN+MnIn+af793i9ZUnPf4w9Hru+7sbZFHv0yMqernJVLvb1/tE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rHqiOYdp; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so12739299276.0 for ; Fri, 17 May 2024 10:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715967633; x=1716572433; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=IIpzTjnpYWvr4z4L+FkXXo9hR1khs/BwnW5TGVqv/IQ=; b=rHqiOYdpjW6Lwf3LFpflpCO//4QrXb0oRLwNT1VG9kmvFlr+BzVQdGNJyARlNoWgS3 lmfSqI5jQrasik/h3zrJyvI0/awwKhl0KlzY6JDD1pJLkhS5+SoYG7G9L9qxilotphac J3zWUMHP9rqvNytL8R3EN5E4kYmYL29EtJqawyyV2xtNNkvLScVloEJHqrf+KPCpd6fH gLnru4I4/YlekCs3co+ETL3kZ1chp4+zkUTqYVReCKA/toZJsTwERVs0AfZ1+Nn9wBXX m7KYGUrDL2o7XplkQSpGrJwKQ4o80yZSNaM9KXR2PS0Ozhh3OeqGoDhljYW76DBLooVV DN4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715967633; x=1716572433; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IIpzTjnpYWvr4z4L+FkXXo9hR1khs/BwnW5TGVqv/IQ=; b=W74YY9NWQQuufzZt5REgw/CunlUWaNekF+m3B4y+Ap5iZgqF+RuhQy8SNpup7tUJJm BdNYyqTaV0ECiI2dSutoRciOt/au9bzt02xBS6tIMR1BYk7x0GhOABvEWBLTZ/t6iqQp nFyoFtEFBFonIr+JE9dmZCO317qsDs+gUWKovTkVERIGbViAX4RvczphVg/IRbBKmBDW Cc/mDUrjhxMigbfKnFYiHMiOXiywv5X69yhOLgAFRg49hs4bvkvTWYwKhsYKeEjtDsUg o/LVV9tA2+kwiIHaF5vpRZLo+gZihUe87K1HLP1bG2nO1e4i5vdyRLrbMa/Y6jgVu3Mg Zxjw== X-Forwarded-Encrypted: i=1; AJvYcCU5eym1WGm9yXIzX2rHSgNI1K9uLvPvzrMdvdOqHHMSN/Oe5PNMxBZweH0iQtLuObkLK/USqdYjTTxkGWK5rs0XFzHi0jOpfd0Rua21 X-Gm-Message-State: AOJu0YwkP5kZB0ref2J13tnl2PYHmkuZeaufoC/mxhZy3yjIo5itOoXn KduZl+GUzmZBpBkj+CAEZbxDC965vql32mdVxkIStkBCBljHeXu5aHym2EDP+UAxK/8a+q+cY9b pKQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:70a:b0:dee:615c:ac3a with SMTP id 3f1490d57ef6-dee615cb53fmr1728101276.5.1715967633201; Fri, 17 May 2024 10:40:33 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 17 May 2024 10:39:03 -0700 In-Reply-To: <20240517173926.965351-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240517173926.965351-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240517173926.965351-27-seanjc@google.com> Subject: [PATCH v2 26/49] KVM: x86: Add a macro to init CPUID features that KVM emulates in software From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hou Wenlong , Kechen Lu , Oliver Upton , Maxim Levitsky , Binbin Wu , Yang Weijiang , Robert Hoo Content-Type: text/plain; charset="UTF-8" Now that kvm_cpu_cap_init() is a macro with its own scope, add EMUL_F() to OR-in features that KVM emulates in software, i.e. that don't depend on the feature being available in hardware. The contained scope of kvm_cpu_cap_init() allows using a local variable to track the set of emulated leaves, which in addition to avoiding confusing and/or unnecessary variables, helps prevent misuse of EMUL_F(). Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 1064e4d68718..33e3e77de1b7 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -94,6 +94,16 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted) F(name); \ }) +/* + * Emulated Feature - For features that KVM emulates in software irrespective + * of host CPU/kernel support. + */ +#define EMUL_F(name) \ +({ \ + kvm_cpu_cap_emulated |= F(name); \ + F(name); \ +}) + /* * Aliased Features - For features in 0x8000_0001.EDX that are duplicates of * identical 0x1.EDX features, and thus are aliased from 0x1 to 0x8000_0001. @@ -649,6 +659,7 @@ do { \ do { \ const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32); \ const u32 __maybe_unused kvm_cpu_cap_init_in_progress = leaf; \ + u32 kvm_cpu_cap_emulated = 0; \ \ if (leaf < NCAPINTS) \ kvm_cpu_caps[leaf] &= (mask); \ @@ -656,6 +667,7 @@ do { \ kvm_cpu_caps[leaf] = (mask); \ \ kvm_cpu_caps[leaf] &= raw_cpuid_get(cpuid); \ + kvm_cpu_caps[leaf] |= kvm_cpu_cap_emulated; \ } while (0) /* @@ -684,12 +696,10 @@ void kvm_set_cpu_caps(void) 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | F(FMA) | F(CX16) | 0 /* xTPR Update */ | F(PDCM) | F(PCID) | 0 /* Reserved, DCA */ | F(XMM4_1) | - F(XMM4_2) | F(X2APIC) | F(MOVBE) | F(POPCNT) | + F(XMM4_2) | EMUL_F(X2APIC) | F(MOVBE) | F(POPCNT) | 0 /* Reserved*/ | F(AES) | F(XSAVE) | 0 /* OSXSAVE */ | F(AVX) | F(F16C) | F(RDRAND) ); - /* KVM emulates x2apic in software irrespective of host support. */ - kvm_cpu_cap_set(X86_FEATURE_X2APIC); kvm_cpu_cap_init(CPUID_1_EDX, F(FPU) | F(VME) | F(DE) | F(PSE) | @@ -703,13 +713,13 @@ void kvm_set_cpu_caps(void) ); kvm_cpu_cap_init(CPUID_7_0_EBX, - F(FSGSBASE) | F(SGX) | F(BMI1) | F(HLE) | F(AVX2) | - F(FDP_EXCPTN_ONLY) | F(SMEP) | F(BMI2) | F(ERMS) | F(INVPCID) | - F(RTM) | F(ZERO_FCS_FDS) | 0 /*MPX*/ | F(AVX512F) | - F(AVX512DQ) | F(RDSEED) | F(ADX) | F(SMAP) | F(AVX512IFMA) | - F(CLFLUSHOPT) | F(CLWB) | 0 /*INTEL_PT*/ | F(AVX512PF) | - F(AVX512ER) | F(AVX512CD) | F(SHA_NI) | F(AVX512BW) | - F(AVX512VL)); + F(FSGSBASE) | EMUL_F(TSC_ADJUST) | F(SGX) | F(BMI1) | F(HLE) | + F(AVX2) | F(FDP_EXCPTN_ONLY) | F(SMEP) | F(BMI2) | F(ERMS) | + F(INVPCID) | F(RTM) | F(ZERO_FCS_FDS) | 0 /*MPX*/ | + F(AVX512F) | F(AVX512DQ) | F(RDSEED) | F(ADX) | F(SMAP) | + F(AVX512IFMA) | F(CLFLUSHOPT) | F(CLWB) | 0 /*INTEL_PT*/ | + F(AVX512PF) | F(AVX512ER) | F(AVX512CD) | F(SHA_NI) | + F(AVX512BW) | F(AVX512VL)); kvm_cpu_cap_init(CPUID_7_ECX, F(AVX512VBMI) | RAW_F(LA57) | F(PKU) | 0 /*OSPKE*/ | F(RDPID) | @@ -728,16 +738,12 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_init(CPUID_7_EDX, F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | - F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES) | F(INTEL_STIBP) | + F(SPEC_CTRL_SSBD) | EMUL_F(ARCH_CAPABILITIES) | F(INTEL_STIBP) | F(MD_CLEAR) | F(AVX512_VP2INTERSECT) | F(FSRM) | F(SERIALIZE) | F(TSXLDTRK) | F(AVX512_FP16) | F(AMX_TILE) | F(AMX_INT8) | F(AMX_BF16) | F(FLUSH_L1D) ); - /* TSC_ADJUST and ARCH_CAPABILITIES are emulated in software. */ - kvm_cpu_cap_set(X86_FEATURE_TSC_ADJUST); - kvm_cpu_cap_set(X86_FEATURE_ARCH_CAPABILITIES); - if (boot_cpu_has(X86_FEATURE_IBPB) && boot_cpu_has(X86_FEATURE_IBRS)) kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL); if (boot_cpu_has(X86_FEATURE_STIBP)) -- 2.45.0.215.g3402c0e53f-goog