Resend - Enabling IA32_TSC_ADJUST for Qemu KVM guest VMs
PATCH v2 1/1 Resend - Enabling IA32_TSC_ADJUST for Qemu KVM guest VMs
CPUID.7.0.EBX[1]=1 indicates IA32_TSC_ADJUST MSR 0x3b is supported
Basic design is to emulate the MSR by allowing reads and writes to the hypervisor vcpu specific locations to store the value of the emulated MSRs. In this way the IA32_TSC_ADJUST value will be included in all reads to the TSC MSR whether through rdmsr or rdtsc.
As this is a new MSR that the guest may access and modify its value needs to be migrated along with the other MRSs. The changes here are specifically for recognizing when IA32_TSC_ADJUST is enabled in CPUID and code added for migrating its value.
--- target-i386/cpu.h | 2 ++ target-i386/kvm.c | 15 +++++++++++++++ target-i386/machine.c | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+)
target-i386/cpu.h +2 -0
@@ -284,6 +284,7 @@#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_TSC_ADJUST 0x0000003b#define MSR_IA32_TSCDEADLINE 0x6e0#define MSR_MTRRcap 0xfe
@@ -701,6 +702,7 @@ typedef struct CPUX86State {uint64_t async_pf_en_msr;uint64_t tsc; +uint64_t tsc_adjust;uint64_t tsc_deadline;uint64_t mcg_status;
target-i386/kvm.c +15 -0
@@ -61,6 +61,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {static bool has_msr_star;static bool has_msr_hsave_pa; +static bool has_msr_tsc_adjust;static bool has_msr_tsc_deadline;static bool has_msr_async_pf_en;static bool has_msr_misc_enable;
@@ -641,6 +642,10 @@ static int kvm_get_supported_msrs(KVMState *s) has_msr_hsave_pa = true;continue ; } +if (kvm_msr_list->indices[i] ==MSR_TSC_ADJUST ) { + has_msr_tsc_adjust = true; +continue ; + }if (kvm_msr_list->indices[i] ==MSR_IA32_TSCDEADLINE ) { has_msr_tsc_deadline = true;continue ;
@@ -978,6 +983,10 @@ static int kvm_put_msrs(CPUX86State *env, int level)if (has_msr_hsave_pa) {kvm_msr_entry_set (&msrs[n++],MSR_VM_HSAVE_PA , env->vm_hsave); } +if (has_msr_tsc_adjust) { +kvm_msr_entry_set (&msrs[n++], +MSR_TSC_ADJUST , env->tsc_adjust); + }if (has_msr_tsc_deadline) {kvm_msr_entry_set (&msrs[n++],MSR_IA32_TSCDEADLINE , env->tsc_deadline); }
@@ -1234,6 +1243,9 @@ static int kvm_get_msrs(CPUX86State *env)if (has_msr_hsave_pa) { msrs[n++].index =MSR_VM_HSAVE_PA ; } +if (has_msr_tsc_adjust) { + msrs[n++].index =MSR_TSC_ADJUST ; + }if (has_msr_tsc_deadline) { msrs[n++].index =MSR_IA32_TSCDEADLINE ; }
@@ -1308,6 +1320,9 @@ static int kvm_get_msrs(CPUX86State *env)case MSR_IA32_TSC : env->tsc = msrs[i].data;break ; +case MSR_TSC_ADJUST : + env->tsc_adjust = msrs[i].data; +break ;case MSR_IA32_TSCDEADLINE : env->tsc_deadline = msrs[i].data;break ;
target-i386/machine.c +21 -0
@@ -310,6 +310,24 @@ static const VMStateDescription vmstate_fpop_ip_dp = { } }; +static bool tsc_adjust_needed (void *opaque) +{ +CPUX86State *cpu = opaque; + +return cpu->tsc_adjust !=0 ; +} + +static const VMStateDescription vmstate_msr_tsc_adjust = { + .name ="cpu/msr_tsc_adjust" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (tsc_adjust, CPUX86State), +VMSTATE_END_OF_LIST () + } +}; +static bool tscdeadline_needed (void *opaque) {CPUX86State *env = opaque;
@@ -457,6 +475,9 @@ static const VMStateDescription vmstate_cpu = { .vmsd = &vmstate_fpop_ip_dp, .needed = fpop_ip_dp_needed, }, { + .vmsd = &vmstate_msr_tsc_adjust, + .needed = tsc_adjust_needed, + }, { .vmsd = &vmstate_msr_tscdeadline, .needed = tscdeadline_needed, }, {
Signature · 1 line
1.8.0.rc0
Hello,
Am 26.11.2012 19:42, schrieb Will Auld:
Quoted 7 lines
CPUID.7.0.EBX[1]=1 indicates
IA32_TSC_ADJUSTMSR0x3bis supportedBasic design is to emulate the MSR by allowing reads and writes to the hypervisor vcpu specific locations to store the value of the emulated MSRs. In this way the
IA32_TSC_ADJUSTvalue will be included in all reads to the TSC MSR whether through rdmsr or rdtsc.
Quoted 6 lines
As this is a new MSR that the guest may access and modify its value needs to be migrated along with the other MRSs. The changes here are specifically for recognizing when
IA32_TSC_ADJUSTis enabled in CPUID and code added for migrating its value.Signed-off-by Will Auld <[email protected]>
$subject should get a prefix of "target-i386: " and "resend" is better used inside a tag so that it doesn't end up in the commit. And it's "QEMU". ;)
Some more stylistic issues inline:
Quoted 11 lines
--- target-i386/cpu.h | 2 ++ target-i386/kvm.c | 15 +++++++++++++++ target-i386/machine.c | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+)target-i386/cpu.h +0
-0
target-i386/cpu.h line 287
Quoted 4 lines
target-i386/cpu.h +1
-0@@ -284,6 +284,7 @@#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_TSC_ADJUST 0x0000003b
Tabs. You can use scripts/checkpatch.pl to verify.
Quoted 35 lines
target-i386/cpu.h +1
-0#define MSR_IA32_TSCDEADLINE 0x6e0#define MSR_MTRRcap 0xfe@@ -701,6 +702,7 @@ typedef struct CPUX86State {uint64_t async_pf_en_msr;uint64_t tsc; +uint64_t tsc_adjust;uint64_t tsc_deadline;uint64_t mcg_status;target-i386/kvm.c +5
-0@@ -61,6 +61,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {static bool has_msr_star;static bool has_msr_hsave_pa; +static bool has_msr_tsc_adjust;static bool has_msr_tsc_deadline;static bool has_msr_async_pf_en;static bool has_msr_misc_enable;@@ -641,6 +642,10 @@ static int kvm_get_supported_msrs(KVMState *s) has_msr_hsave_pa = true;continue ; } +if (kvm_msr_list->indices[i] ==MSR_TSC_ADJUST ) { + has_msr_tsc_adjust = true; +continue ; + }if (kvm_msr_list->indices[i] ==MSR_IA32_TSCDEADLINE ) { has_msr_tsc_deadline = true;continue ;
target-i386/kvm.c static int kvm_put_msrs(CPUX86State *env, int level) · line 988
Quoted 6 lines
target-i386/kvm.c +3
-0@@ -978,6 +983,10 @@ static int kvm_put_msrs(CPUX86State *env, int level)if (has_msr_hsave_pa) {kvm_msr_entry_set (&msrs[n++],MSR_VM_HSAVE_PA , env->vm_hsave); } +if (has_msr_tsc_adjust) { +kvm_msr_entry_set (&msrs[n++], +MSR_TSC_ADJUST , env->tsc_adjust);
Tabs.
Quoted 29 lines
target-i386/kvm.c +7
-0+ }if (has_msr_tsc_deadline) {kvm_msr_entry_set (&msrs[n++],MSR_IA32_TSCDEADLINE , env->tsc_deadline); }@@ -1234,6 +1243,9 @@ static int kvm_get_msrs(CPUX86State *env)if (has_msr_hsave_pa) { msrs[n++].index =MSR_VM_HSAVE_PA ; } +if (has_msr_tsc_adjust) { + msrs[n++].index =MSR_TSC_ADJUST ; + }if (has_msr_tsc_deadline) { msrs[n++].index =MSR_IA32_TSCDEADLINE ; }@@ -1308,6 +1320,9 @@ static int kvm_get_msrs(CPUX86State *env)case MSR_IA32_TSC : env->tsc = msrs[i].data;break ; +case MSR_TSC_ADJUST : + env->tsc_adjust = msrs[i].data; +break ;case MSR_IA32_TSCDEADLINE : env->tsc_deadline = msrs[i].data;break ;target-i386/machine.c +0
-0
target-i386/machine.c static const VMStateDescription vmstate_fpop_ip_dp = { · line 315
Quoted 6 lines
target-i386/machine.c +3
-0@@ -310,6 +310,24 @@ static const VMStateDescription vmstate_fpop_ip_dp = { } }; +static bool tsc_adjust_needed (void *opaque) +{ +CPUX86State *cpu = opaque;
Please name this "env" to differentiate from CPUState / X86CPU. Since there are other tsc_* fields already I won't request that you move your new field to the containing X86CPU struct but at some point we will need to convert the VMSDs to X86CPU.
Quoted 19 lines
target-i386/machine.c +15
-0+ +return cpu->tsc_adjust !=0 ; +} + +static const VMStateDescription vmstate_msr_tsc_adjust = { + .name ="cpu/msr_tsc_adjust" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (tsc_adjust, CPUX86State), +VMSTATE_END_OF_LIST () + } +}; +static bool tscdeadline_needed (void *opaque) {CPUX86State *env = opaque;
target-i386/machine.c static const VMStateDescription vmstate_cpu = { · line 483
Quoted 9 lines
target-i386/machine.c +3
-0@@ -457,6 +475,9 @@ static const VMStateDescription vmstate_cpu = { .vmsd = &vmstate_fpop_ip_dp, .needed = fpop_ip_dp_needed, }, { + .vmsd = &vmstate_msr_tsc_adjust, + .needed = tsc_adjust_needed, + }, { .vmsd = &vmstate_msr_tscdeadline, .needed = tscdeadline_needed, }, {
Otherwise looks okay to me. I'm expecting this to go through Marcello's queue unless I'm told otherwise.
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
RE: [Qemu-devel] [PATCH V2] Resend - Enabling IA32_TSC_ADJUST for QEMU KVM guest VMs
Andreas,
Thanks. I just sent the update patch (V3) to address your comments.
Will
Quoted 185 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Andreas Färber
Sent: Monday, November 26, 2012 11:05 AM
To: Auld, Will
Cc: Will Auld; qemu-devel; Gleb; Marcelo Tosatti; [email protected]; Dugger, Donald D; Liu, Jinsong; Zhang, Xiantao; [email protected]
Subject: Re: [Qemu-devel] [PATCH V2] Resend - EnablingIA32_TSC_ADJUSTfor Qemu KVM guest VMsHello,
Am 26.11.2012 19:42, schrieb Will Auld:
Quoted 3 lines
CPUID.7.0.EBX[1]=1 indicates
IA32_TSC_ADJUSTMSR0x3bis supportedBasic design is to emulate the MSR by allowing reads and writes to
the
Quoted 1 line
hypervisor vcpu specific locations to store the value of the emulated
MSRs.
Quoted 1 line
In this way the
IA32_TSC_ADJUSTvalue will be included in all readsto
Quoted 8 lines
the TSC MSR whether through rdmsr or rdtsc.
As this is a new MSR that the guest may access and modify its value needs to be migrated along with the other MRSs. The changes here are specifically for recognizing when
IA32_TSC_ADJUSTis enabled in CPUID and code added for migrating its value.Signed-off-by Will Auld <[email protected]>$subject should get a prefix of "target-i386: " and "resend" is better used inside a tag so that it doesn't end up in the commit. And it's "QEMU". ;)
Some more stylistic issues inline:
Quoted 11 lines
--- target-i386/cpu.h | 2 ++ target-i386/kvm.c | 15 +++++++++++++++ target-i386/machine.c | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+)target-i386/cpu.h index renamed from target-i386/cpu.h +0
-0aabf993..13d4152 100644
target-i386/cpu.h line 287
Quoted 4 lines
target-i386/cpu.h +1
-0@@ -284,6 +284,7 @@#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_TSC_ADJUST 0x0000003bTabs. You can use
scripts/checkpatch.plto verify.Quoted 25 lines
target-i386/cpu.h +1
-0#define MSR_IA32_TSCDEADLINE 0x6e0#define MSR_MTRRcap 0xfe@@ -701,6 +702,7 @@ typedef struct CPUX86State {uint64_t async_pf_en_msr;uint64_t tsc; +uint64_t tsc_adjust;uint64_t tsc_deadline;uint64_t mcg_status;target-i386/kvm.c index renamed from target-i386/kvm.c +0
-0696b14a..e974c42 100644
target-i386/kvm.c +1
-0@@ -61,6 +61,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {static bool has_msr_star;static bool has_msr_hsave_pa; +static bool has_msr_tsc_adjust;static bool has_msr_tsc_deadline;static bool has_msr_async_pf_en;static bool
has_msr_misc_enable;target-i386/kvm.c static int kvm_get_supported_msrs(KVMState *s) · line 649
Quoted 8 lines
target-i386/kvm.c +4
-0@@ -641,6 +642,10 @@ static int kvm_get_supported_msrs(KVMState *s) has_msr_hsave_pa = true;continue ; } +if (kvm_msr_list->indices[i] ==MSR_TSC_ADJUST ) { + has_msr_tsc_adjust = true; +continue ; + } if (kvm_msr_list->indices[i] ==
MSR_IA32_TSCDEADLINE) {target-i386/kvm.c static int kvm_put_msrs(CPUX86State *env, int
Quoted 3 lines
target-i386/kvm.c +0
-0has_msr_tsc_deadline = true;continue ;@@ -978,6 +983,10 @@ static int kvm_put_msrs(CPUX86State *env, intlevel)
target-i386/kvm.c static int kvm_put_msrs(CPUX86State *env, int level) · line 988
Quoted 7 lines
target-i386/kvm.c +3
-0if (has_msr_hsave_pa) {kvm_msr_entry_set (&msrs[n++],MSR_VM_HSAVE_PA , env- vm_hsave); } +if (has_msr_tsc_adjust) { +kvm_msr_entry_set (&msrs[n++], +MSR_TSC_ADJUST , env->tsc_adjust);Tabs.
target-i386/machine.c static const VMStateDescription
Quoted 30 lines
target-i386/kvm.c +1
-0+ }if (has_msr_tsc_deadline) { kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSCDEADLINE, env-tsc_deadline); }target-i386/kvm.c +6
-0@@ -1234,6 +1243,9 @@ static int kvm_get_msrs(CPUX86State *env)if (has_msr_hsave_pa) { msrs[n++].index =MSR_VM_HSAVE_PA ; } +if (has_msr_tsc_adjust) { + msrs[n++].index =MSR_TSC_ADJUST ; + }if (has_msr_tsc_deadline) { msrs[n++].index =MSR_IA32_TSCDEADLINE ; }@@ -1308,6 +1320,9 @@ static int kvm_get_msrs(CPUX86State *env)case MSR_IA32_TSC : env->tsc = msrs[i].data;break ; +case MSR_TSC_ADJUST : + env->tsc_adjust = msrs[i].data; +break ;case MSR_IA32_TSCDEADLINE : env->tsc_deadline = msrs[i].data;break ;target-i386/machine.c index renamed from target-i386/machine.c +0
-0a8be058..95bda9b 100644
target-i386/machine.c +0
-0@@ -310,6 +310,24 @@ static const VMStateDescription
vmstate_fpop_ip_dp= {target-i386/machine.c static const VMStateDescription vmstate_fpop_ip_dp = { · line 315
Quoted 5 lines
target-i386/machine.c +2
-0} }; +static bool tsc_adjust_needed (void *opaque) { +CPUX86State *cpu = opaque;Please name this "env" to differentiate from CPUState / X86CPU. Since there are other tsc_* fields already I won't request that you move your new field to the containing X86CPU struct but at some point we will need to convert the VMSDs to X86CPU.
Quoted 18 lines
target-i386/machine.c +15
-0+ +return cpu->tsc_adjust !=0 ; +} + +static const VMStateDescription vmstate_msr_tsc_adjust = { + .name ="cpu/msr_tsc_adjust" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (tsc_adjust, CPUX86State), +VMSTATE_END_OF_LIST () + } +}; +static bool tscdeadline_needed (void *opaque) {CPUX86State *env = opaque;target-i386/machine.c static const VMStateDescription vmstate_cpu = { · line 483
Quoted 9 lines
target-i386/machine.c +3
-0@@ -457,6 +475,9 @@ static const VMStateDescription vmstate_cpu = { .vmsd = &vmstate_fpop_ip_dp, .needed = fpop_ip_dp_needed, }, { + .vmsd = &vmstate_msr_tsc_adjust, + .needed = tsc_adjust_needed, + }, { .vmsd = &vmstate_msr_tscdeadline, .needed = tscdeadline_needed, }, {Otherwise looks okay to me. I'm expecting this to go through Marcello's queue unless I'm told otherwise.
Regards,
Andreas--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg --
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html