|
|
b38b0f |
From 90b8d9d17a9c252427df71fbe5bd76f897529e71 Mon Sep 17 00:00:00 2001
|
|
|
69f3e1 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
b38b0f |
Date: Wed, 3 Apr 2019 15:54:30 +0100
|
|
|
b38b0f |
Subject: [PATCH 06/10] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and
|
|
|
69f3e1 |
KVM_GET_MSRS system ioctl
|
|
|
69f3e1 |
|
|
|
69f3e1 |
RH-Author: plai@redhat.com
|
|
|
b38b0f |
Message-id: <1554306874-28796-7-git-send-email-plai@redhat.com>
|
|
|
b38b0f |
Patchwork-id: 85384
|
|
|
b38b0f |
O-Subject: [RHEL8.1 qemu-kvm PATCH resend 06/10] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
|
|
|
b38b0f |
Bugzilla: 1561761
|
|
|
69f3e1 |
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
69f3e1 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
b38b0f |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
69f3e1 |
|
|
|
69f3e1 |
From: Robert Hoo <robert.hu@linux.intel.com>
|
|
|
69f3e1 |
|
|
|
69f3e1 |
Add kvm_get_supported_feature_msrs() to get supported MSR feature index list.
|
|
|
69f3e1 |
Add kvm_arch_get_supported_msr_feature() to get each MSR features value.
|
|
|
69f3e1 |
|
|
|
69f3e1 |
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
|
|
|
69f3e1 |
Message-Id: <1539578845-37944-2-git-send-email-robert.hu@linux.intel.com>
|
|
|
69f3e1 |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
69f3e1 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
69f3e1 |
(cherry picked from commit f57bceb6ab5163ddd6c41ff4344ab8cf28a9c63d)
|
|
|
69f3e1 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
69f3e1 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
69f3e1 |
---
|
|
|
69f3e1 |
include/sysemu/kvm.h | 2 ++
|
|
|
69f3e1 |
target/i386/kvm.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
69f3e1 |
2 files changed, 82 insertions(+)
|
|
|
69f3e1 |
|
|
|
69f3e1 |
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
|
|
|
69f3e1 |
index 23669c4..3d8f294 100644
|
|
|
69f3e1 |
--- a/include/sysemu/kvm.h
|
|
|
69f3e1 |
+++ b/include/sysemu/kvm.h
|
|
|
69f3e1 |
@@ -464,6 +464,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
|
|
|
69f3e1 |
|
|
|
69f3e1 |
uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
|
|
|
69f3e1 |
uint32_t index, int reg);
|
|
|
69f3e1 |
+uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
|
|
|
69f3e1 |
void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
|
|
|
69f3e1 |
|
|
|
69f3e1 |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
|
b38b0f |
index 702e3bf..096ed24 100644
|
|
|
69f3e1 |
--- a/target/i386/kvm.c
|
|
|
69f3e1 |
+++ b/target/i386/kvm.c
|
|
|
69f3e1 |
@@ -106,6 +106,7 @@ static int has_pit_state2;
|
|
|
69f3e1 |
static bool has_msr_mcg_ext_ctl;
|
|
|
69f3e1 |
|
|
|
69f3e1 |
static struct kvm_cpuid2 *cpuid_cache;
|
|
|
69f3e1 |
+static struct kvm_msr_list *kvm_feature_msrs;
|
|
|
69f3e1 |
|
|
|
69f3e1 |
int kvm_has_pit_state2(void)
|
|
|
69f3e1 |
{
|
|
|
69f3e1 |
@@ -405,6 +406,42 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
|
|
69f3e1 |
return ret;
|
|
|
69f3e1 |
}
|
|
|
69f3e1 |
|
|
|
69f3e1 |
+uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index)
|
|
|
69f3e1 |
+{
|
|
|
69f3e1 |
+ struct {
|
|
|
69f3e1 |
+ struct kvm_msrs info;
|
|
|
69f3e1 |
+ struct kvm_msr_entry entries[1];
|
|
|
69f3e1 |
+ } msr_data;
|
|
|
69f3e1 |
+ uint32_t ret;
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ if (kvm_feature_msrs == NULL) { /* Host doesn't support feature MSRs */
|
|
|
69f3e1 |
+ return 0;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ /* Check if requested MSR is supported feature MSR */
|
|
|
69f3e1 |
+ int i;
|
|
|
69f3e1 |
+ for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
|
|
|
69f3e1 |
+ if (kvm_feature_msrs->indices[i] == index) {
|
|
|
69f3e1 |
+ break;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+ if (i == kvm_feature_msrs->nmsrs) {
|
|
|
69f3e1 |
+ return 0; /* if the feature MSR is not supported, simply return 0 */
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ msr_data.info.nmsrs = 1;
|
|
|
69f3e1 |
+ msr_data.entries[0].index = index;
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ ret = kvm_ioctl(s, KVM_GET_MSRS, &msr_data);
|
|
|
69f3e1 |
+ if (ret != 1) {
|
|
|
69f3e1 |
+ error_report("KVM get MSR (index=0x%x) feature failed, %s",
|
|
|
69f3e1 |
+ index, strerror(-ret));
|
|
|
69f3e1 |
+ exit(1);
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ return msr_data.entries[0].data;
|
|
|
69f3e1 |
+}
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
typedef struct HWPoisonPage {
|
|
|
69f3e1 |
ram_addr_t ram_addr;
|
|
|
69f3e1 |
QLIST_ENTRY(HWPoisonPage) list;
|
|
|
69f3e1 |
@@ -1164,6 +1201,47 @@ void kvm_arch_do_init_vcpu(X86CPU *cpu)
|
|
|
69f3e1 |
}
|
|
|
69f3e1 |
}
|
|
|
69f3e1 |
|
|
|
69f3e1 |
+static int kvm_get_supported_feature_msrs(KVMState *s)
|
|
|
69f3e1 |
+{
|
|
|
69f3e1 |
+ int ret = 0;
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ if (kvm_feature_msrs != NULL) {
|
|
|
69f3e1 |
+ return 0;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ if (!kvm_check_extension(s, KVM_CAP_GET_MSR_FEATURES)) {
|
|
|
69f3e1 |
+ return 0;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ struct kvm_msr_list msr_list;
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ msr_list.nmsrs = 0;
|
|
|
69f3e1 |
+ ret = kvm_ioctl(s, KVM_GET_MSR_FEATURE_INDEX_LIST, &msr_list);
|
|
|
69f3e1 |
+ if (ret < 0 && ret != -E2BIG) {
|
|
|
69f3e1 |
+ error_report("Fetch KVM feature MSR list failed: %s",
|
|
|
69f3e1 |
+ strerror(-ret));
|
|
|
69f3e1 |
+ return ret;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ assert(msr_list.nmsrs > 0);
|
|
|
69f3e1 |
+ kvm_feature_msrs = (struct kvm_msr_list *) \
|
|
|
69f3e1 |
+ g_malloc0(sizeof(msr_list) +
|
|
|
69f3e1 |
+ msr_list.nmsrs * sizeof(msr_list.indices[0]));
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ kvm_feature_msrs->nmsrs = msr_list.nmsrs;
|
|
|
69f3e1 |
+ ret = kvm_ioctl(s, KVM_GET_MSR_FEATURE_INDEX_LIST, kvm_feature_msrs);
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ if (ret < 0) {
|
|
|
69f3e1 |
+ error_report("Fetch KVM feature MSR list failed: %s",
|
|
|
69f3e1 |
+ strerror(-ret));
|
|
|
69f3e1 |
+ g_free(kvm_feature_msrs);
|
|
|
69f3e1 |
+ kvm_feature_msrs = NULL;
|
|
|
69f3e1 |
+ return ret;
|
|
|
69f3e1 |
+ }
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
+ return 0;
|
|
|
69f3e1 |
+}
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
static int kvm_get_supported_msrs(KVMState *s)
|
|
|
69f3e1 |
{
|
|
|
69f3e1 |
static int kvm_supported_msrs;
|
|
|
69f3e1 |
@@ -1320,6 +1398,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
|
|
|
69f3e1 |
return ret;
|
|
|
69f3e1 |
}
|
|
|
69f3e1 |
|
|
|
69f3e1 |
+ kvm_get_supported_feature_msrs(s);
|
|
|
69f3e1 |
+
|
|
|
69f3e1 |
uname(&utsname);
|
|
|
69f3e1 |
lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
|
|
|
69f3e1 |
|
|
|
69f3e1 |
--
|
|
|
69f3e1 |
1.8.3.1
|
|
|
69f3e1 |
|