treewide: Use array_size() in vzalloc()
[linux-block.git] / arch / x86 / kvm / cpuid.c
index 92bf2f2e7cdd241d1b4019c0ed72ce72fbb95d11..812cada68e0f44f07e27914d2f32e3288c6315b5 100644 (file)
@@ -203,8 +203,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
                goto out;
        r = -ENOMEM;
        if (cpuid->nent) {
-               cpuid_entries = vmalloc(sizeof(struct kvm_cpuid_entry) *
-                                       cpuid->nent);
+               cpuid_entries =
+                       vmalloc(array_size(sizeof(struct kvm_cpuid_entry),
+                                          cpuid->nent));
                if (!cpuid_entries)
                        goto out;
                r = -EFAULT;
@@ -379,7 +380,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 
        /* cpuid 0x80000008.ebx */
        const u32 kvm_cpuid_8000_0008_ebx_x86_features =
-               F(AMD_IBPB) | F(AMD_IBRS) | F(VIRT_SSBD);
+               F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
+               F(AMD_SSB_NO);
 
        /* cpuid 0xC0000001.edx */
        const u32 kvm_cpuid_C000_0001_edx_x86_features =
@@ -664,7 +666,12 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
                        entry->ebx |= F(VIRT_SSBD);
                entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;
                cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX);
-               if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))
+               /*
+                * The preference is to use SPEC CTRL MSR instead of the
+                * VIRT_SPEC MSR.
+                */
+               if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
+                   !boot_cpu_has(X86_FEATURE_AMD_SSBD))
                        entry->ebx |= F(VIRT_SSBD);
                break;
        }
@@ -778,7 +785,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
                return -EINVAL;
 
        r = -ENOMEM;
-       cpuid_entries = vzalloc(sizeof(struct kvm_cpuid_entry2) * cpuid->nent);
+       cpuid_entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
+                                          cpuid->nent));
        if (!cpuid_entries)
                goto out;