util: Publish and mock virHostCPUGetMSRFromKVM

The function will later be called when probing QEMU capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Jiri Denemark
2026-06-02 13:45:26 +02:00
parent ed3ae648a9
commit 3184289356
4 changed files with 47 additions and 1 deletions
+1
View File
@@ -2621,6 +2621,7 @@ virHostCPUGetKVMMaxVCPUs;
virHostCPUGetMap;
virHostCPUGetMicrocodeVersion;
virHostCPUGetMSR;
virHostCPUGetMSRFromKVM;
virHostCPUGetOnline;
virHostCPUGetOnlineBitmap;
virHostCPUGetPhysAddrSize;
+21 -1
View File
@@ -1376,7 +1376,18 @@ virHostCPUGetMicrocodeVersion(virArch hostArch G_GNUC_UNUSED)
#if WITH_LINUX_KVM_H && defined(KVM_GET_MSRS) && \
(defined(__i386__) || defined(__x86_64__))
static int
/**
* virHostCPUGetMSRFromKVM:
* @index: MSR to read
* @result: where to store the content of the @index register
*
* Reads the 64b content of the specified register via KVM_GET_MSRS ioctl.
*
* Returns 0 on success,
* 1 when the MSR is not supported by the host CPU,
* -1 on error.
*/
int
virHostCPUGetMSRFromKVM(unsigned long index,
uint64_t *result)
{
@@ -1613,6 +1624,15 @@ virHostCPUGetCPUID(void)
return NULL;
}
int
virHostCPUGetMSRFromKVM(unsigned long index G_GNUC_UNUSED,
uint64_t *result G_GNUC_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Reading MSRs is not supported on this platform"));
return -1;
}
int
virHostCPUGetMSR(unsigned long index G_GNUC_UNUSED,
uint64_t *msr G_GNUC_UNUSED)
+3
View File
@@ -78,6 +78,9 @@ int virHostCPUGetOnline(unsigned int cpu, bool *online);
unsigned int
virHostCPUGetMicrocodeVersion(virArch hostArch) ATTRIBUTE_MOCKABLE;
int virHostCPUGetMSRFromKVM(unsigned long index,
uint64_t *result) ATTRIBUTE_MOCKABLE;
int virHostCPUGetMSR(unsigned long index,
uint64_t *msr);
+22
View File
@@ -23,6 +23,7 @@
#include "qemu/qemu_capspriv.h"
#include "testutilshostcpus.h"
#include "virarch.h"
#include "util/virhostcpu.h"
virCPUDef *
@@ -33,3 +34,24 @@ virQEMUCapsProbeHostCPU(virArch hostArch G_GNUC_UNUSED,
return testUtilsHostCpusGetDefForModel(model);
}
int
virHostCPUGetMSRFromKVM(unsigned long index,
uint64_t *result)
{
if (index == 0x10a) {
/* Return some arbitrary bits in arch-capabilities MSR */
*result =
0x00000001 | /* rdctl-no */
0x00000008 | /* skip-l1dfl-vmentry */
0x00000020 | /* mds-no */
0x00000040 | /* pschange-mc-no */
0x04000000 | /* gds-no */
0x08000000; /* rfds-no */
return 0;
}
errno = ENOTSUP;
return -1;
}