i386: Hyper-V partition time restore feature
Subsystems (3)
PATCH 1/1 i386: Hyper-V partition time restore feature
A nested Hyper-V that sees the frequency MSRs lets L0 own the partition reference time. After a resume from hibernation it issues HvCallRestorePartitionTime with the TSC and the reference counter it saved. Hyper-V offers hibernation to its root partition only when L0 advertises CPUID 0x40000004 EAX bit 20 (RestoreTimeOnResume).
Add 'hv-restore-time-on-resume' for the bit. It requires 'hv-frequencies'. KVM reports the bit in KVM_GET_SUPPORTED_HV_CPUID when it handles the hypercall.
KVM side: https://lore.kernel.org/kvm/[email protected]/
The TLFS marks the bit as reserved. The name comes from Microsoft's hvdef crate.
--- docs/system/i386/hyperv.rst | 9 +++++++++ target/i386/cpu.c | 2 ++ target/i386/cpu.h | 1 + target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 8 ++++++++ 5 files changed, 21 insertions(+)
docs/system/i386/hyperv.rst +9 -0
@@ -259,6 +259,15 @@ Existing enlightenments Recommended: ``hv-evmcs`` (Intel) +``hv-restore-time-on-resume`` + The enlightenment is nested specific, it targets Hyper-V on KVM guests. When + enabled, Hyper-V lets L0 (KVM) own the partition reference time and issues + HvCallRestorePartitionTime after a resume from hibernation so that the TSC + and the reference counter continue from the values it saved. Hyper-V offers + hibernation to its root partition only when this enlightenment is present. + + Requires: ``hv-frequencies`` + Supplementary features ----------------------
target/i386/cpu.c +2 -0
@@ -10769,6 +10769,8 @@ static const Property x86_cpu_properties[] = { HYPERV_FEAT_TLBFLUSH_EXT, 0),DEFINE_PROP_BIT64 ("hv-tlbflush-direct" ,X86CPU , hyperv_features,HYPERV_FEAT_TLBFLUSH_DIRECT ,0 ), +DEFINE_PROP_BIT64 ("hv-restore-time-on-resume" ,X86CPU , hyperv_features, +HYPERV_FEAT_RESTORE_TIME_ON_RESUME ,0 ),DEFINE_PROP_ON_OFF_AUTO ("hv-no-nonarch-coresharing" ,X86CPU , hyperv_no_nonarch_cs,ON_OFF_AUTO_OFF ), #ifdef CONFIG_SYNDBG
target/i386/cpu.h +1 -0
@@ -1487,6 +1487,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define HYPERV_FEAT_XMM_INPUT 18#define HYPERV_FEAT_TLBFLUSH_EXT 19#define HYPERV_FEAT_TLBFLUSH_DIRECT 20 +#define HYPERV_FEAT_RESTORE_TIME_ON_RESUME 21#ifndef HYPERV_SPINLOCK_NEVER_NOTIFY #define HYPERV_SPINLOCK_NEVER_NOTIFY 0xFFFFFFFF
target/i386/kvm/hyperv-proto.h +1 -0
@@ -81,6 +81,7 @@#define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11)#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14)#define HV_NO_NONARCH_CORESHARING (1u << 18) +#define HV_RESTORE_TIME_ON_RESUME (1u << 20)/* * HV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits
target/i386/kvm/kvm.c +8 -0
@@ -1137,6 +1137,14 @@ static struct { }, .dependencies = BIT(HYPERV_FEAT_VAPIC) }, + [HYPERV_FEAT_RESTORE_TIME_ON_RESUME] = { + .desc = "partition time restore (hv-restore-time-on-resume)", + .flags = { + {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX, + .bits = HV_RESTORE_TIME_ON_RESUME} + }, + .dependencies = BIT(HYPERV_FEAT_FREQUENCIES) + }, }; static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max,
Signature · 1 line
2.47.3
Quoted 6 lines · Mushahid Hussain
A nested Hyper-V that sees the frequency MSRs lets L0 own the partition reference time. After a resume from hibernation it issues HvCallRestorePartitionTime with the TSC and the reference counter it saved. Hyper-V offers hibernation to its root partition only when L0 advertises CPUID
0x40000004EAX bit 20 (RestoreTimeOnResume).
Quoted 8 lines
Add 'hv-restore-time-on-resume' for the bit. It requires 'hv-frequencies'. KVM reports the bit in
KVM_GET_SUPPORTED_HV_CPUIDwhen it handles the hypercall.KVM side: https://lore.kernel.org/kvm/[email protected]/
The TLFS marks the bit as reserved. The name comes from Microsoft's hvdef crate.
This won't be the first time we use side channels to implement Hyper-V features in KVM/QEMU but it's certainly better when feature bits are documented and thus backwards compatible.
Quoted 86 lines
Signed-off-by Mushahid Hussain <[email protected]>--- docs/system/i386/hyperv.rst | 9 +++++++++ target/i386/cpu.c | 2 ++ target/i386/cpu.h | 1 + target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 8 ++++++++ 5 files changed, 21 insertions(+)docs/system/i386/hyperv.rst +9
-0@@ -259,6 +259,15 @@ Existing enlightenments Recommended: ``hv-evmcs`` (Intel) +``hv-restore-time-on-resume`` + The enlightenment is nested specific, it targets Hyper-V on KVM guests. When + enabled, Hyper-V lets L0 (KVM) own the partition reference time and issues + HvCallRestorePartitionTime after a resume from hibernation so that the TSC + and the reference counter continue from the values it saved. Hyper-V offers + hibernation to its root partition only when this enlightenment is present. + + Requires: ``hv-frequencies`` + Supplementary features ----------------------target/i386/cpu.c +2
-0@@ -10769,6 +10769,8 @@ static const Property x86_cpu_properties[] = { HYPERV_FEAT_TLBFLUSH_EXT, 0),DEFINE_PROP_BIT64 ("hv-tlbflush-direct" ,X86CPU , hyperv_features,HYPERV_FEAT_TLBFLUSH_DIRECT ,0 ), +DEFINE_PROP_BIT64 ("hv-restore-time-on-resume" ,X86CPU , hyperv_features, +HYPERV_FEAT_RESTORE_TIME_ON_RESUME ,0 ),DEFINE_PROP_ON_OFF_AUTO ("hv-no-nonarch-coresharing" ,X86CPU , hyperv_no_nonarch_cs,ON_OFF_AUTO_OFF ), #ifdef CONFIG_SYNDBGtarget/i386/cpu.h +1
-0@@ -1487,6 +1487,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define HYPERV_FEAT_XMM_INPUT 18#define HYPERV_FEAT_TLBFLUSH_EXT 19#define HYPERV_FEAT_TLBFLUSH_DIRECT 20 +#define HYPERV_FEAT_RESTORE_TIME_ON_RESUME 21#ifndef HYPERV_SPINLOCK_NEVER_NOTIFY #define HYPERV_SPINLOCK_NEVER_NOTIFY 0xFFFFFFFFtarget/i386/kvm/hyperv-proto.h +1
-0@@ -81,6 +81,7 @@#define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11)#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14)#define HV_NO_NONARCH_CORESHARING (1u << 18) +#define HV_RESTORE_TIME_ON_RESUME (1u << 20)/* * HV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits target/i386/kvm/kvm.c +8
-0@@ -1137,6 +1137,14 @@ static struct { }, .dependencies = BIT(HYPERV_FEAT_VAPIC) }, + [HYPERV_FEAT_RESTORE_TIME_ON_RESUME] = { + .desc = "partition time restore (hv-restore-time-on-resume)", + .flags = { + {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX, + .bits = HV_RESTORE_TIME_ON_RESUME} + }, + .dependencies = BIT(HYPERV_FEAT_FREQUENCIES) + }, }; static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max,
Signature · 1 line
Vitaly