From: Jim Mattson <jmattson@google.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
"'Paolo Bonzini '" <pbonzini@redhat.com>,
"'Sean Christopherson '" <seanjc@google.com>
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH 2/2] KVM: x86: Use a switch statement in __feature_translate()
Date: Mon, 23 Oct 2023 17:16:36 -0700 [thread overview]
Message-ID: <20231024001636.890236-2-jmattson@google.com> (raw)
In-Reply-To: <20231024001636.890236-1-jmattson@google.com>
The compiler will probably do better than linear search.
No functional change intended.
Signed-off-by: Jim Mattson <jmattson@google.com>
---
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
next prev parent reply other threads:[~2023-10-24 0:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 0:16 [PATCH 1/2] KVM: x86: Advertise CPUID.(EAX=7,ECX=2):EDX[5:0] to userspace Jim Mattson
2023-10-24 0:16 ` Jim Mattson [this message]
2023-10-24 0:25 ` [PATCH 2/2] KVM: x86: Use a switch statement in __feature_translate() Sean Christopherson
2023-11-30 20:28 ` Sean Christopherson
2023-12-01 1:39 ` Jim Mattson
2023-10-25 7:06 ` [PATCH 1/2] KVM: x86: Advertise CPUID.(EAX=7,ECX=2):EDX[5:0] to userspace Chao Gao
2023-12-01 1:52 ` Sean Christopherson
2023-12-01 4:18 ` Jim Mattson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231024001636.890236-2-jmattson@google.com \
--to=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox