Skip to content

Commit ff402f5

Browse files
committed
KVM: x86: Extract code for generating per-entry emulated CPUID information
Extract the meat of __do_cpuid_func_emulated() into a separate helper, cpuid_func_emulated(), so that cpuid_func_emulated() can be used with a single CPUID entry. This will allow marking emulated features as fully supported in the guest cpu_caps without needing to hardcode the set of emulated features in multiple locations. No functional change intended. Reviewed-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent a7a308f commit ff402f5

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,38 +1213,38 @@ static struct kvm_cpuid_entry2 *do_host_cpuid(struct kvm_cpuid_array *array,
12131213
return entry;
12141214
}
12151215

1216-
static int __do_cpuid_func_emulated(struct kvm_cpuid_array *array, u32 func)
1216+
static int cpuid_func_emulated(struct kvm_cpuid_entry2 *entry, u32 func)
12171217
{
1218-
struct kvm_cpuid_entry2 *entry;
1219-
1220-
if (array->nent >= array->maxnent)
1221-
return -E2BIG;
1218+
memset(entry, 0, sizeof(*entry));
12221219

1223-
entry = &array->entries[array->nent];
12241220
entry->function = func;
12251221
entry->index = 0;
12261222
entry->flags = 0;
12271223

12281224
switch (func) {
12291225
case 0:
12301226
entry->eax = 7;
1231-
++array->nent;
1232-
break;
1227+
return 1;
12331228
case 1:
12341229
entry->ecx = feature_bit(MOVBE);
1235-
++array->nent;
1236-
break;
1230+
return 1;
12371231
case 7:
12381232
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
12391233
entry->eax = 0;
12401234
if (kvm_cpu_cap_has(X86_FEATURE_RDTSCP))
12411235
entry->ecx = feature_bit(RDPID);
1242-
++array->nent;
1243-
break;
1236+
return 1;
12441237
default:
1245-
break;
1238+
return 0;
12461239
}
1240+
}
1241+
1242+
static int __do_cpuid_func_emulated(struct kvm_cpuid_array *array, u32 func)
1243+
{
1244+
if (array->nent >= array->maxnent)
1245+
return -E2BIG;
12471246

1247+
array->nent += cpuid_func_emulated(&array->entries[array->nent], func);
12481248
return 0;
12491249
}
12501250

0 commit comments

Comments
 (0)