|
|
c461a1 |
From 0bce0c69b76a246ee901c09a4d02bcd05619d9e0 Mon Sep 17 00:00:00 2001
|
|
|
c461a1 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
c461a1 |
Date: Mon, 23 Sep 2019 20:40:22 +0200
|
|
|
c461a1 |
Subject: [PATCH 06/12] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and
|
|
|
2ec96d |
KVM_GET_MSRS system ioctl
|
|
|
2ec96d |
|
|
|
c461a1 |
RH-Author: plai@redhat.com
|
|
|
c461a1 |
Message-id: <1569271227-28026-6-git-send-email-plai@redhat.com>
|
|
|
c461a1 |
Patchwork-id: 90856
|
|
|
c461a1 |
O-Subject: [RHEL7.8 qemu-kvm PATCH v6 05/10] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
|
|
|
c461a1 |
Bugzilla: 1709971
|
|
|
c461a1 |
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
2ec96d |
RH-Acked-by: Bandan Das <bsd@redhat.com>
|
|
|
c461a1 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
2ec96d |
|
|
|
2ec96d |
From: Robert Hoo <robert.hu@linux.intel.com>
|
|
|
2ec96d |
|
|
|
2ec96d |
Add kvm_get_supported_feature_msrs() to get supported MSR feature index list.
|
|
|
2ec96d |
Add kvm_arch_get_supported_msr_feature() to get each MSR features value.
|
|
|
2ec96d |
|
|
|
2ec96d |
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
|
|
|
2ec96d |
Message-Id: <1539578845-37944-2-git-send-email-robert.hu@linux.intel.com>
|
|
|
2ec96d |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
2ec96d |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
2ec96d |
(cherry picked from commit f57bceb6ab5163ddd6c41ff4344ab8cf28a9c63d)
|
|
|
2ec96d |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
2ec96d |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
2ec96d |
---
|
|
|
2ec96d |
include/sysemu/kvm.h | 1 +
|
|
|
2ec96d |
linux-headers/linux/kvm.h | 2 ++
|
|
|
c461a1 |
target-i386/kvm.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
c461a1 |
3 files changed, 82 insertions(+)
|
|
|
2ec96d |
|
|
|
2ec96d |
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
|
|
|
2ec96d |
index e4403be..281fe26 100644
|
|
|
2ec96d |
--- a/include/sysemu/kvm.h
|
|
|
2ec96d |
+++ b/include/sysemu/kvm.h
|
|
|
2ec96d |
@@ -253,6 +253,7 @@ int kvm_check_extension(KVMState *s, unsigned int extension);
|
|
|
2ec96d |
|
|
|
2ec96d |
uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
|
|
|
2ec96d |
uint32_t index, int reg);
|
|
|
2ec96d |
+uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
|
|
|
2ec96d |
void kvm_cpu_synchronize_state(CPUArchState *env);
|
|
|
2ec96d |
|
|
|
2ec96d |
/* generic hooks - to be moved/refactored once there are more users */
|
|
|
2ec96d |
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
|
|
|
2ec96d |
index 4b93099..bfeafff 100644
|
|
|
2ec96d |
--- a/linux-headers/linux/kvm.h
|
|
|
2ec96d |
+++ b/linux-headers/linux/kvm.h
|
|
|
2ec96d |
@@ -541,6 +541,7 @@ struct kvm_ppc_smmu_info {
|
|
|
2ec96d |
#define KVM_TRACE_ENABLE __KVM_DEPRECATED_MAIN_W_0x06
|
|
|
2ec96d |
#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07
|
|
|
2ec96d |
#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08
|
|
|
2ec96d |
+#define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list)
|
|
|
2ec96d |
|
|
|
2ec96d |
/*
|
|
|
2ec96d |
* Extension capability list.
|
|
|
2ec96d |
@@ -667,6 +668,7 @@ struct kvm_ppc_smmu_info {
|
|
|
2ec96d |
#define KVM_CAP_PPC_RTAS 91
|
|
|
2ec96d |
#define KVM_CAP_IRQ_XICS 92
|
|
|
2ec96d |
#define KVM_CAP_HYPERV_TIME 96
|
|
|
2ec96d |
+#define KVM_CAP_GET_MSR_FEATURES 153
|
|
|
2ec96d |
|
|
|
2ec96d |
#ifdef KVM_CAP_IRQ_ROUTING
|
|
|
2ec96d |
|
|
|
2ec96d |
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
|
|
|
c461a1 |
index b6c76f1..159ed4c 100644
|
|
|
2ec96d |
--- a/target-i386/kvm.c
|
|
|
2ec96d |
+++ b/target-i386/kvm.c
|
|
|
c461a1 |
@@ -84,6 +84,7 @@ static bool has_msr_virt_ssbd;
|
|
|
2ec96d |
|
|
|
2ec96d |
static bool has_msr_architectural_pmu;
|
|
|
2ec96d |
static uint32_t num_architectural_pmu_counters;
|
|
|
2ec96d |
+static struct kvm_msr_list *kvm_feature_msrs;
|
|
|
2ec96d |
|
|
|
2ec96d |
bool kvm_allows_irq0_override(void)
|
|
|
2ec96d |
{
|
|
|
c461a1 |
@@ -251,11 +252,87 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
|
|
2ec96d |
return ret;
|
|
|
2ec96d |
}
|
|
|
2ec96d |
|
|
|
2ec96d |
+uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index)
|
|
|
2ec96d |
+{
|
|
|
2ec96d |
+ struct {
|
|
|
2ec96d |
+ struct kvm_msrs info;
|
|
|
2ec96d |
+ struct kvm_msr_entry entries[1];
|
|
|
2ec96d |
+ } msr_data;
|
|
|
2ec96d |
+ uint32_t ret;
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ if (kvm_feature_msrs == NULL) { /* Host doesn't support feature MSRs */
|
|
|
2ec96d |
+ return 0;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ /* Check if requested MSR is supported feature MSR */
|
|
|
2ec96d |
+ int i;
|
|
|
2ec96d |
+ for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
|
|
|
2ec96d |
+ if (kvm_feature_msrs->indices[i] == index) {
|
|
|
2ec96d |
+ break;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+ if (i == kvm_feature_msrs->nmsrs) {
|
|
|
2ec96d |
+ return 0; /* if the feature MSR is not supported, simply return 0 */
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ msr_data.info.nmsrs = 1;
|
|
|
2ec96d |
+ msr_data.entries[0].index = index;
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ ret = kvm_ioctl(s, KVM_GET_MSRS, &msr_data);
|
|
|
2ec96d |
+ if (ret != 1) {
|
|
|
2ec96d |
+ error_report("KVM get MSR (index=0x%x) feature failed, %s",
|
|
|
2ec96d |
+ index, strerror(-ret));
|
|
|
2ec96d |
+ exit(1);
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ return msr_data.entries[0].data;
|
|
|
2ec96d |
+}
|
|
|
2ec96d |
+
|
|
|
2ec96d |
typedef struct HWPoisonPage {
|
|
|
2ec96d |
ram_addr_t ram_addr;
|
|
|
2ec96d |
QLIST_ENTRY(HWPoisonPage) list;
|
|
|
2ec96d |
} HWPoisonPage;
|
|
|
2ec96d |
|
|
|
2ec96d |
+static int kvm_get_supported_feature_msrs(KVMState *s)
|
|
|
2ec96d |
+{
|
|
|
2ec96d |
+ int ret = 0;
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ if (kvm_feature_msrs != NULL) {
|
|
|
2ec96d |
+ return 0;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ if (!kvm_check_extension(s, KVM_CAP_GET_MSR_FEATURES)) {
|
|
|
2ec96d |
+ return 0;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ struct kvm_msr_list msr_list;
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ msr_list.nmsrs = 0;
|
|
|
2ec96d |
+ ret = kvm_ioctl(s, KVM_GET_MSR_FEATURE_INDEX_LIST, &msr_list);
|
|
|
2ec96d |
+ if (ret < 0 && ret != -E2BIG) {
|
|
|
2ec96d |
+ error_report("Fetch KVM feature MSR list failed: %s",
|
|
|
2ec96d |
+ strerror(-ret));
|
|
|
2ec96d |
+ return ret;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ assert(msr_list.nmsrs > 0);
|
|
|
2ec96d |
+ kvm_feature_msrs = (struct kvm_msr_list *) \
|
|
|
2ec96d |
+ g_malloc0(sizeof(msr_list) +
|
|
|
2ec96d |
+ msr_list.nmsrs * sizeof(msr_list.indices[0]));
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ kvm_feature_msrs->nmsrs = msr_list.nmsrs;
|
|
|
2ec96d |
+ ret = kvm_ioctl(s, KVM_GET_MSR_FEATURE_INDEX_LIST, kvm_feature_msrs);
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ if (ret < 0) {
|
|
|
2ec96d |
+ error_report("Fetch KVM feature MSR list failed: %s",
|
|
|
2ec96d |
+ strerror(-ret));
|
|
|
2ec96d |
+ g_free(kvm_feature_msrs);
|
|
|
2ec96d |
+ kvm_feature_msrs = NULL;
|
|
|
2ec96d |
+ return ret;
|
|
|
2ec96d |
+ }
|
|
|
2ec96d |
+
|
|
|
2ec96d |
+ return 0;
|
|
|
2ec96d |
+}
|
|
|
2ec96d |
+
|
|
|
2ec96d |
static QLIST_HEAD(, HWPoisonPage) hwpoison_page_list =
|
|
|
2ec96d |
QLIST_HEAD_INITIALIZER(hwpoison_page_list);
|
|
|
2ec96d |
|
|
|
c461a1 |
@@ -846,6 +923,8 @@ int kvm_arch_init(KVMState *s)
|
|
|
2ec96d |
return ret;
|
|
|
2ec96d |
}
|
|
|
2ec96d |
|
|
|
2ec96d |
+ kvm_get_supported_feature_msrs(s);
|
|
|
2ec96d |
+
|
|
|
2ec96d |
uname(&utsname);
|
|
|
2ec96d |
lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
|
|
|
2ec96d |
|
|
|
2ec96d |
--
|
|
|
2ec96d |
1.8.3.1
|
|
|
2ec96d |
|