Skip to content

Commit

Permalink
KVM: x86: Implement MSR_CORE_THREAD_COUNT MSR
Browse files Browse the repository at this point in the history
The MSR_CORE_THREAD_COUNT MSR describes CPU package topology, such as number
of threads and cores for a given package. This is information that QEMU has
readily available and can provide through the new user space MSR deflection
interface.

This patch propagates the existing hvf logic from patch 027ac0c
("target/i386/hvf: add rdmsr 35H MSR_CORE_THREAD_COUNT") to KVM.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Message-Id: <20221004225643.65036-4-agraf@csgraf.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
agraf authored and bonzini committed Oct 11, 2022
1 parent 860054d commit 3765647
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions target/i386/kvm/kvm.c
Expand Up @@ -2401,6 +2401,17 @@ static int kvm_get_supported_msrs(KVMState *s)
return ret;
}

static bool kvm_rdmsr_core_thread_count(X86CPU *cpu, uint32_t msr,
uint64_t *val)
{
CPUState *cs = CPU(cpu);

*val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
*val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */

return true;
}

static Notifier smram_machine_done;
static KVMMemoryListener smram_listener;
static AddressSpace smram_address_space;
Expand Down Expand Up @@ -2613,13 +2624,23 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
}
}
if (kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) {
bool r;

ret = kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0,
KVM_MSR_EXIT_REASON_FILTER);
if (ret) {
error_report("Could not enable user space MSRs: %s",
strerror(-ret));
exit(1);
}

r = kvm_filter_msr(s, MSR_CORE_THREAD_COUNT,
kvm_rdmsr_core_thread_count, NULL);
if (!r) {
error_report("Could not install MSR_CORE_THREAD_COUNT handler: %s",
strerror(-ret));
exit(1);
}
}

return 0;
Expand Down

0 comments on commit 3765647

Please sign in to comment.