Commit e8a6aec9b5e062ca8d14ae0e14efda17ae9685d8
Committed by
Anthony Liguori
1 parent
02b049df
kvm: Trim cpu features not supported by kvm
Remove cpu features that are not supported by kvm from the cpuid features reported to the guest. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
30 additions
and
0 deletions
target-i386/helper.c
| ... | ... | @@ -93,6 +93,21 @@ static void add_flagname_to_bitmaps(char *flagname, uint32_t *features, |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | +static void kvm_trim_features(uint32_t *features, uint32_t supported, | |
| 97 | + const char *names[]) | |
| 98 | +{ | |
| 99 | + int i; | |
| 100 | + uint32_t mask; | |
| 101 | + | |
| 102 | + for (i = 0; i < 32; ++i) { | |
| 103 | + mask = 1U << i; | |
| 104 | + if ((*features & mask) && !(supported & mask)) { | |
| 105 | + printf("Processor feature %s not supported by kvm\n", names[i]); | |
| 106 | + *features &= ~mask; | |
| 107 | + } | |
| 108 | + } | |
| 109 | +} | |
| 110 | + | |
| 96 | 111 | typedef struct x86_def_t { |
| 97 | 112 | const char *name; |
| 98 | 113 | uint32_t level; |
| ... | ... | @@ -1699,5 +1714,20 @@ CPUX86State *cpu_x86_init(const char *cpu_model) |
| 1699 | 1714 | |
| 1700 | 1715 | qemu_init_vcpu(env); |
| 1701 | 1716 | |
| 1717 | + if (kvm_enabled()) { | |
| 1718 | + kvm_trim_features(&env->cpuid_features, | |
| 1719 | + kvm_arch_get_supported_cpuid(env, 1, R_EDX), | |
| 1720 | + feature_name); | |
| 1721 | + kvm_trim_features(&env->cpuid_ext_features, | |
| 1722 | + kvm_arch_get_supported_cpuid(env, 1, R_ECX), | |
| 1723 | + ext_feature_name); | |
| 1724 | + kvm_trim_features(&env->cpuid_ext2_features, | |
| 1725 | + kvm_arch_get_supported_cpuid(env, 0x80000001, R_EDX), | |
| 1726 | + ext2_feature_name); | |
| 1727 | + kvm_trim_features(&env->cpuid_ext3_features, | |
| 1728 | + kvm_arch_get_supported_cpuid(env, 0x80000001, R_ECX), | |
| 1729 | + ext3_feature_name); | |
| 1730 | + } | |
| 1731 | + | |
| 1702 | 1732 | return env; |
| 1703 | 1733 | } | ... | ... |