From e9e26236af6a858961280cd4997c437eab27c1e9 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Thu, 22 Sep 2016 19:07:57 +0200 Subject: [PATCH 2/3] target-i386: introduce kvm_put_one_msr RH-Author: Dr. David Alan Gilbert Message-id: <1474571278-16316-2-git-send-email-dgilbert@redhat.com> Patchwork-id: 72406 O-Subject: [RHEL-7.3 qemu-kvm-rhev PATCH 1/2] target-i386: introduce kvm_put_one_msr Bugzilla: 1377920 RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Paolo Bonzini RH-Acked-by: Radim Krcmar From: Paolo Bonzini Avoid further code duplication in the next patch. Signed-off-by: Paolo Bonzini (cherry picked from commit 73e1b8f2f9b8a90361f9c1af306ee17bfcfd592d) Merge conflict: We don't yet have Eduardo's patch where kvm_msr_entry_add was added, so rework to the older kvm_msr_entry_set. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Miroslav Rezanina --- target-i386/kvm.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index b80347c..85ef5dc 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1451,27 +1451,32 @@ static void kvm_msr_entry_set(struct kvm_msr_entry *entry, entry->data = value; } -static int kvm_put_tscdeadline_msr(X86CPU *cpu) +static int kvm_put_one_msr(X86CPU *cpu, int index, uint64_t value) { - CPUX86State *env = &cpu->env; struct { struct kvm_msrs info; struct kvm_msr_entry entries[1]; } msr_data; - struct kvm_msr_entry *msrs = msr_data.entries; - int ret; - - if (!has_msr_tsc_deadline) { - return 0; - } - kvm_msr_entry_set(&msrs[0], MSR_IA32_TSCDEADLINE, env->tsc_deadline); + kvm_msr_entry_set(&msr_data.entries[0], index, value); msr_data.info = (struct kvm_msrs) { .nmsrs = 1, }; - ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, &msr_data); + return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, &msr_data); +} + +static int kvm_put_tscdeadline_msr(X86CPU *cpu) +{ + CPUX86State *env = &cpu->env; + int ret; + + if (!has_msr_tsc_deadline) { + return 0; + } + + ret = kvm_put_one_msr(cpu, MSR_IA32_TSCDEADLINE, env->tsc_deadline); if (ret < 0) { return ret; } @@ -1488,24 +1493,14 @@ static int kvm_put_tscdeadline_msr(X86CPU *cpu) */ static int kvm_put_msr_feature_control(X86CPU *cpu) { - struct { - struct kvm_msrs info; - struct kvm_msr_entry entry; - } msr_data; int ret; if (!has_msr_feature_control) { return 0; } - kvm_msr_entry_set(&msr_data.entry, MSR_IA32_FEATURE_CONTROL, - cpu->env.msr_ia32_feature_control); - - msr_data.info = (struct kvm_msrs) { - .nmsrs = 1, - }; - - ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, &msr_data); + ret = kvm_put_one_msr(cpu, MSR_IA32_FEATURE_CONTROL, + cpu->env.msr_ia32_feature_control); if (ret < 0) { return ret; } -- 1.8.3.1