Skip to content

Commit b66370d

Browse files
mdrothsuryasaimadhu
authored andcommitted
KVM: x86: Move lookup of indexed CPUID leafs to helper
Determining which CPUID leafs have significant ECX/index values is also needed by guest kernel code when doing SEV-SNP-validated CPUID lookups. Move this to common code to keep future updates in sync. Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Venu Busireddy <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5ea98e0 commit b66370d

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

arch/x86/include/asm/cpuid.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* CPUID-related helpers/definitions
4+
*
5+
* Derived from arch/x86/kvm/cpuid.c
6+
*/
7+
8+
#ifndef _ASM_X86_CPUID_H
9+
#define _ASM_X86_CPUID_H
10+
11+
static __always_inline bool cpuid_function_is_indexed(u32 function)
12+
{
13+
switch (function) {
14+
case 4:
15+
case 7:
16+
case 0xb:
17+
case 0xd:
18+
case 0xf:
19+
case 0x10:
20+
case 0x12:
21+
case 0x14:
22+
case 0x17:
23+
case 0x18:
24+
case 0x1d:
25+
case 0x1e:
26+
case 0x1f:
27+
case 0x8000001d:
28+
return true;
29+
}
30+
31+
return false;
32+
}
33+
34+
#endif /* _ASM_X86_CPUID_H */

arch/x86/kvm/cpuid.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <asm/user.h>
2020
#include <asm/fpu/xstate.h>
2121
#include <asm/sgx.h>
22+
#include <asm/cpuid.h>
2223
#include "cpuid.h"
2324
#include "lapic.h"
2425
#include "mmu.h"
@@ -744,24 +745,8 @@ static struct kvm_cpuid_entry2 *do_host_cpuid(struct kvm_cpuid_array *array,
744745
cpuid_count(entry->function, entry->index,
745746
&entry->eax, &entry->ebx, &entry->ecx, &entry->edx);
746747

747-
switch (function) {
748-
case 4:
749-
case 7:
750-
case 0xb:
751-
case 0xd:
752-
case 0xf:
753-
case 0x10:
754-
case 0x12:
755-
case 0x14:
756-
case 0x17:
757-
case 0x18:
758-
case 0x1d:
759-
case 0x1e:
760-
case 0x1f:
761-
case 0x8000001d:
748+
if (cpuid_function_is_indexed(function))
762749
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
763-
break;
764-
}
765750

766751
return entry;
767752
}

0 commit comments

Comments
 (0)