From patchwork Tue Oct 24 00:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 157152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1629597vqx; Mon, 23 Oct 2023 17:17:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhIYDxw1MGQKBMivmhQ0NZEV1Ye3KbyxYYx8vAF8dUHlvzeGvBC/U/LhzSJNCJRd7CmHK2 X-Received: by 2002:a05:6871:5296:b0:1e9:64f1:9c30 with SMTP id hu22-20020a056871529600b001e964f19c30mr14577076oac.18.1698106626002; Mon, 23 Oct 2023 17:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698106625; cv=none; d=google.com; s=arc-20160816; b=qWPVtvJaeChpJGgRotYsEh3iYRreU5/qcGZIZ46pMnOhy/sFj+Tx579T6fXSwAuszD cG6RgzzFxkLV/loBLRFnTwQiY+Fdpmc6hGpLW6LT09Vgk9H99mI+LCQ0iC928B9kAOXT 2gLOlmMvxosNa9K15RXs5YTPYTuZuQvq9LCq5VhtVa7iRXRehHaqvbneujqObtrZZ2mP BGN41t+XQJVEjSYclnYkQS6EffHITqBfdx45NI0K0E3SC1FyK58ZqQ7zzDRjSQy0XlzM MEFRi9M6DBeySK8/X3a8Lx90fEG3iaTB7RuHd6QaPzsxYmWFO7DAFtD6dDt1viPXw/Uu D8sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=T6ALsOVdAlXxureR7/QG1Tl27zbxYFHpyn+YFicZdFw=; fh=v4tBNjFz0MhCe7RmlB14AySRf8hmC1xADAhhevdW76k=; b=Dr4A623Rrt++7YwLomTxDYbJpA5DefdeZ5CiK89ll4KNfTeox/rCx2UxWFFlw3TSzS 73N8mHz7ZGnOZCL+LHRB9dMWuJcpzrvPxD5+iM98pEhn9jP8kEBbHhlPhGm+W0SROT+m 48HjUsIzz9n9a27yyVBLndEo6mrp+3Ed1an5bcQ1JF5b0S+USGJdOwR3n7j4ET6Veh6E apQSzTvBAUo8eYLZranXl0fdQ7fpSDcQPAsmO6HTjSWTc4+ckzEwsvQ1MmWIkKG6P5bJ cZmJTHraPWhVXzvRTO2WBPJqZtirz5+klfie6cK/tF1bNKWlBl1r5CBGEweR4dNvLhuT 3CYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=i9HwRcdQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 18-20020a630f52000000b00578d0d070f4si7203247pgp.844.2023.10.23.17.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:17:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=i9HwRcdQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CF68380465E9; Mon, 23 Oct 2023 17:17:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbjJXAQv (ORCPT + 27 others); Mon, 23 Oct 2023 20:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjJXAQt (ORCPT ); Mon, 23 Oct 2023 20:16:49 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B453510E for ; Mon, 23 Oct 2023 17:16:47 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c9c83b656fso32840315ad.1 for ; Mon, 23 Oct 2023 17:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698106607; x=1698711407; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=T6ALsOVdAlXxureR7/QG1Tl27zbxYFHpyn+YFicZdFw=; b=i9HwRcdQ9Snto35wwaub/NWGrf4zhl8z+CwyN/hcPoeChICO78mEZyINA1Gg5i198B qxxJF1mcm9UmfSGhTrI9E4UZqF1PUnooB7bxayu11gUCI9ChoqrrSRTNoJ+/xc/EGVvo zv6jxeZP1oHGSgL7uSqcxf1aSdc19JqNpRvfuED76VZr6Z7cPIHC9vrj3/PF2GiKDCEO lkPaNohK2gr0eivBcxP48FqktbbnXh1pu7F7labgzNDjuKo5M7REutWAlynSYpL8hpHC 0UP3oYdEDNWYhvVSpKjVv6PLfGgHtgKl0LIHRzKaarUPofqhTY5/ze38tQ3Vk25Hiw8Y He8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698106607; x=1698711407; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T6ALsOVdAlXxureR7/QG1Tl27zbxYFHpyn+YFicZdFw=; b=IcPUeWNN5hRib6H3/kxUjh5JuId558KFtBLKdd4Lo2FrmUb36rkI5J2vR/E14p6qNe 3rbufx0A9tdFCICL+WQjJSbznddYkL6Y8R7AhZfRYoCYSdqPxHnzhTXXXZuKU1qhzd/b r2jKahtGcoTo1iUcNmJPA7zdTib9OBSUy13Ge/5WErSkNeMz1tvvDiuVSJvPKcpH2/ST 8i07vpeqjSnXztP/t7OC5C6kXWL3v2Wfs0RKlNm+Yhd/is/6XqUrN5X0rZf87HB5Ph/X A5zt3+bGkhYXm6oduY8fZL5K+L7B0Fwn/pWfPWPHz714yOO2r04upOIxBJxk7NumujAL RGfA== X-Gm-Message-State: AOJu0Yw+CsTynLPLX9cF3mUOoymVj60TJkTtYmYW44XRmimSZ3DmUMrs foUJww2OqBnBOJb5CIiLaA54hhjrdy87eg== X-Received: from loggerhead.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:29a]) (user=jmattson job=sendgmr) by 2002:a17:902:7fc6:b0:1c9:e830:15fa with SMTP id t6-20020a1709027fc600b001c9e83015famr187346plb.0.1698106606998; Mon, 23 Oct 2023 17:16:46 -0700 (PDT) Date: Mon, 23 Oct 2023 17:16:35 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024001636.890236-1-jmattson@google.com> Subject: [PATCH 1/2] KVM: x86: Advertise CPUID.(EAX=7,ECX=2):EDX[5:0] to userspace From: Jim Mattson To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "'Paolo Bonzini '" , "'Sean Christopherson '" Cc: Jim Mattson X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 17:17:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780593853314954209 X-GMAIL-MSGID: 1780593853314954209 The low five bits {INTEL_PSFD, IPRED_CTRL, RRSBA_CTRL, DDPD_U, BHI_CTRL} advertise the availability of specific bits in IA32_SPEC_CTRL. Since KVM dynamically determines the legal IA32_SPEC_CTRL bits for the underlying hardware, the hard work has already been done. Just let userspace know that a guest can use these IA32_SPEC_CTRL bits. The sixth bit (MCDT_NO) states that the processor does not exhibit MXCSR Configuration Dependent Timing (MCDT) behavior. This is an inherent property of the physical processor that is inherited by the virtual CPU. Pass that information on to userspace. Signed-off-by: Jim Mattson Reviewed-by: Chao Gao --- arch/x86/kvm/cpuid.c | 21 ++++++++++++++++++--- arch/x86/kvm/reverse_cpuid.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index c134c181ba80..e5fc888b2715 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -677,6 +677,11 @@ void kvm_set_cpu_caps(void) F(AMX_COMPLEX) ); + kvm_cpu_cap_init_kvm_defined(CPUID_7_2_EDX, + F(INTEL_PSFD) | F(IPRED_CTRL) | F(RRSBA_CTRL) | F(DDPD_U) | + F(BHI_CTRL) | F(MCDT_NO) + ); + kvm_cpu_cap_mask(CPUID_D_1_EAX, F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | F(XSAVES) | f_xfd ); @@ -957,13 +962,13 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) break; /* function 7 has additional index. */ case 7: - entry->eax = min(entry->eax, 1u); + max_idx = entry->eax = min(entry->eax, 2u); cpuid_entry_override(entry, CPUID_7_0_EBX); cpuid_entry_override(entry, CPUID_7_ECX); cpuid_entry_override(entry, CPUID_7_EDX); - /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */ - if (entry->eax == 1) { + /* KVM only supports up to 0x7.2, capped above via min(). */ + if (max_idx >= 1) { entry = do_host_cpuid(array, function, 1); if (!entry) goto out; @@ -973,6 +978,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->ebx = 0; entry->ecx = 0; } + if (max_idx >= 2) { + entry = do_host_cpuid(array, function, 2); + if (!entry) + goto out; + + cpuid_entry_override(entry, CPUID_7_2_EDX); + entry->ecx = 0; + entry->ebx = 0; + entry->eax = 0; + } break; case 0xa: { /* Architectural Performance Monitoring */ union cpuid10_eax eax; diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index b81650678375..17007016d8b5 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -16,6 +16,7 @@ enum kvm_only_cpuid_leafs { CPUID_7_1_EDX, CPUID_8000_0007_EDX, CPUID_8000_0022_EAX, + CPUID_7_2_EDX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -46,6 +47,14 @@ enum kvm_only_cpuid_leafs { #define X86_FEATURE_AMX_COMPLEX KVM_X86_FEATURE(CPUID_7_1_EDX, 8) #define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) +/* Intel-defined sub-features, CPUID level 0x00000007:2 (EDX) */ +#define X86_FEATURE_INTEL_PSFD KVM_X86_FEATURE(CPUID_7_2_EDX, 0) +#define X86_FEATURE_IPRED_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 1) +#define KVM_X86_FEATURE_RRSBA_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 2) +#define X86_FEATURE_DDPD_U KVM_X86_FEATURE(CPUID_7_2_EDX, 3) +#define X86_FEATURE_BHI_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 4) +#define X86_FEATURE_MCDT_NO KVM_X86_FEATURE(CPUID_7_2_EDX, 5) + /* CPUID level 0x80000007 (EDX). */ #define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8) @@ -80,6 +89,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_8000_0007_EDX] = {0x80000007, 0, CPUID_EDX}, [CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX}, [CPUID_8000_0022_EAX] = {0x80000022, 0, CPUID_EAX}, + [CPUID_7_2_EDX] = { 7, 2, CPUID_EDX}, }; /* @@ -116,6 +126,8 @@ static __always_inline u32 __feature_translate(int x86_feature) return KVM_X86_FEATURE_CONSTANT_TSC; else if (x86_feature == X86_FEATURE_PERFMON_V2) return KVM_X86_FEATURE_PERFMON_V2; + else if (x86_feature == X86_FEATURE_RRSBA_CTRL) + return KVM_X86_FEATURE_RRSBA_CTRL; return x86_feature; } From patchwork Tue Oct 24 00:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 157153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1629626vqx; Mon, 23 Oct 2023 17:17:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGp1GPHPIU+lWj8RdVFhe1wDs2lQ9qDYeYbacnFkiOQ8CYNcoFQk1IpN4CWApJXya8/TT3 X-Received: by 2002:a17:902:fb8f:b0:1bf:c59:c944 with SMTP id lg15-20020a170902fb8f00b001bf0c59c944mr7095542plb.22.1698106629828; Mon, 23 Oct 2023 17:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698106629; cv=none; d=google.com; s=arc-20160816; b=g8hpr3LSZkay3wMal2ArfYG80vAX5HR4Y4iRT0vDJB37U1E0yXNa3Upfe+nmNzwiLE LLAPWuStBo25V2eRgP/8AftxGyzhcyaZlQ5Ufw0XwOROmm/iDzkguASI31cU1xWhDlYl qwsfcrSwo+VyhhDi19zBtiuv5bFUuxWYKLgg/AY5G66/ylS5Hy4sG81J6jmRAhJq/DMC Vy684zyYc6vV9MPRrKiXXDVZKdYWlWVP3rdrKdVSZV3fuVZtIG4XWeKP9kP5uQf0TTRU /l7VILbukXroGo5hP3Xb5Rn8iB4SOw/ph5jWc+7Fe/MLzR6VOsR3s7kARgLeG9RP6tTW Cs8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=jq7rtvs1J7SUa9QYH0420MH6Fu/kuIgYkCbKvTY6XYY=; fh=v4tBNjFz0MhCe7RmlB14AySRf8hmC1xADAhhevdW76k=; b=wBiwM/hYNAo9Zby1oICaInP/BWRsmmaymy65OeAYhp5GN7OlMD+YN9KddJCYNxnwwV aAxWoY2y8bzSEOp5jkbhDrp/pp9IwUEp5ttxPh+6dvuB1co1SOBp6mp68lnH3StTdRFJ 7oZjlIdYgIwXtSIWOCKlrzd1brBqbtfyKTV63YVad/YYponCUYiRAT4SLmWUpwB2elHv HkQymlfvGKQuka0qYGMCT79kAQFO56i9MVCT3FZGAE7Qd/WK/uS6C5H8PmpJKBxCh5mY R98FQv/hl5bgLzwEJV29bGBlywyJpyTAp+sAcqFDaCowxGiQTwXS4yqs0mUG8SbKwIyx KS4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SjvGOKPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s2-20020a170902ea0200b001b829a32f2dsi7634182plg.457.2023.10.23.17.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SjvGOKPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E221C803EF04; Mon, 23 Oct 2023 17:17:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjJXAQx (ORCPT + 27 others); Mon, 23 Oct 2023 20:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbjJXAQv (ORCPT ); Mon, 23 Oct 2023 20:16:51 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9902F10C for ; Mon, 23 Oct 2023 17:16:49 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7af53bde4so53769537b3.0 for ; Mon, 23 Oct 2023 17:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698106609; x=1698711409; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jq7rtvs1J7SUa9QYH0420MH6Fu/kuIgYkCbKvTY6XYY=; b=SjvGOKPcCTxWApoChHPHp/hxH4zxspSqapH2ECYLSyOZllFII4jQ93D3yk8bLRq6wt pec5GR9sq+shHUclsbw/cIHLvcJYCgAkViHQprjbbJdekNXvPSqVAaioTuo0OYsmJhWL u/JA8zeE5RmuEcWVloySqUa2CxOeYjegZJfQm8eQiCdD2MIOXbUGL3m+y/+09/iQPVEN uxdaB7w35KFBiIzLBcboVzVaBi7+e8C0pQQ/CKIkMrN0Xa97ZNZjF6ja6bGf465oO88n KqYaWUYi2XFkf9IG7IwWBBIXxP6A8f4Vvd3vng2yZwH5bekMVHJE3g3LBpGFVHSYCWrg zIqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698106609; x=1698711409; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jq7rtvs1J7SUa9QYH0420MH6Fu/kuIgYkCbKvTY6XYY=; b=tQrEF/MCScfabPTCiTflvlnYsd09bouAmoh7ZRt6ywjs2bZG8LQcssBmApJZviFeGj 3wE98JTlGMdpgzRLR6GYZiRuN0KX80y2OnDOaw7xn6AxuT2lkSN2iykh4ooXHsO5ZAdM ImCmvEI/3C3JFQGbT9gCZxE/mUpdsDWRYZuPrIhN6juDf62qlh5RtX7OHl6rrTSZ6A59 +2qtFuD3BtDkju8EHLIFhNSgK3p1d5jbUb+a484CrvI8iUffVZifSdXIRqNfo+3tFGNS G1i6RtYj9sc40R1/1pFYkPwAz0Sf7aJpCVTpq6GyQoklnPCtReqTTSOrSQjz4xaDtWsu cwRg== X-Gm-Message-State: AOJu0YwlxBPAjnsxtcXdXDqAq6eQCDVk1qZKEiBWAo9s8RxODM+3OOl1 JFkjWl1zCFrX5nB4X72gqoVoKy8nONZxRA== X-Received: from loggerhead.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:29a]) (user=jmattson job=sendgmr) by 2002:a0d:cc91:0:b0:5a8:15c4:5314 with SMTP id o139-20020a0dcc91000000b005a815c45314mr234855ywd.4.1698106608846; Mon, 23 Oct 2023 17:16:48 -0700 (PDT) Date: Mon, 23 Oct 2023 17:16:36 -0700 In-Reply-To: <20231024001636.890236-1-jmattson@google.com> Mime-Version: 1.0 References: <20231024001636.890236-1-jmattson@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024001636.890236-2-jmattson@google.com> Subject: [PATCH 2/2] KVM: x86: Use a switch statement in __feature_translate() From: Jim Mattson To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "'Paolo Bonzini '" , "'Sean Christopherson '" Cc: Jim Mattson X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 23 Oct 2023 17:17:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780593857298621909 X-GMAIL-MSGID: 1780593857298621909 The compiler will probably do better than linear search. No functional change intended. Signed-off-by: Jim Mattson --- arch/x86/kvm/reverse_cpuid.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 17007016d8b5..da52f5ea0351 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -116,20 +116,22 @@ static __always_inline void reverse_cpuid_check(unsigned int x86_leaf) */ static __always_inline u32 __feature_translate(int x86_feature) { - if (x86_feature == X86_FEATURE_SGX1) + switch (x86_feature) { + case X86_FEATURE_SGX1: return KVM_X86_FEATURE_SGX1; - else if (x86_feature == X86_FEATURE_SGX2) + case X86_FEATURE_SGX2: return KVM_X86_FEATURE_SGX2; - else if (x86_feature == X86_FEATURE_SGX_EDECCSSA) + case X86_FEATURE_SGX_EDECCSSA: return KVM_X86_FEATURE_SGX_EDECCSSA; - else if (x86_feature == X86_FEATURE_CONSTANT_TSC) + case X86_FEATURE_CONSTANT_TSC: return KVM_X86_FEATURE_CONSTANT_TSC; - else if (x86_feature == X86_FEATURE_PERFMON_V2) + case X86_FEATURE_PERFMON_V2: return KVM_X86_FEATURE_PERFMON_V2; - else if (x86_feature == X86_FEATURE_RRSBA_CTRL) + case X86_FEATURE_RRSBA_CTRL: return KVM_X86_FEATURE_RRSBA_CTRL; - - return x86_feature; + default: + return x86_feature; + } } static __always_inline u32 __feature_leaf(int x86_feature)