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)