Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1562599rda; Mon, 23 Oct 2023 17:17:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhoOgPURzzBpXce5DD+gY42V4kQGP4tvlULHsss4GyHT6cqRpOFBQjQSYIyDAcC+pE2Z5J X-Received: by 2002:a17:90a:1901:b0:27d:2cff:65a1 with SMTP id 1-20020a17090a190100b0027d2cff65a1mr8258257pjg.29.1698106634482; Mon, 23 Oct 2023 17:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698106634; cv=none; d=google.com; s=arc-20160816; b=ZyG04TbXpmkNmsTlA/UUMdzL5ZfDVhfAwxu6VAc654wxId8U/4diaDLRVfIFkab/YR J8lGpSXeWIkHlPcDwUJcfl/BZG53YEVjS29acH6322l2/O3mPwI8/cCCkbQm3OC1Xyqh Z1QBPOPygG5XIjq1FNo6YN4qjNzSRwg8XDLRekDxjFR3/x6oyG0lEbJuZZspxhYjX9CB oIENhFaWBSlcJQKSxm14d1ZStClMEUhOA+djR8JKrL+CK/rXD2+pK7HUoAg/mJp4s6e5 PItiP3DkF4AggLHoLYUL0aqu63aq8i9oUe2LPtXNPkVZ2RjlcTs+HMzv7M+0OdPFYmiv GWog== 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.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id nv3-20020a17090b1b4300b0027ced8e1837si7477861pjb.180.2023.10.23.17.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:17:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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.34 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 howler.vger.email (Postfix) with ESMTP id CCBF08075956; Mon, 23 Oct 2023 17:17:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231545AbjJXAQx (ORCPT + 99 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 Content-Type: text/plain; charset="UTF-8" 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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 23 Oct 2023 17:17:12 -0700 (PDT) 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) -- 2.42.0.758.gaed0368e0e-goog