Skip to content

Commit

Permalink
i386/kvm: add support for Direct Mode for Hyper-V synthetic timers
Browse files Browse the repository at this point in the history
Hyper-V on KVM can only use Synthetic timers with Direct Mode (opting for
an interrupt instead of VMBus message). This new capability is only
announced in KVM_GET_SUPPORTED_HV_CPUID.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20190517141924.19024-10-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
vittyvk authored and bonzini committed Jun 21, 2019
1 parent 8caba36 commit 128531d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/hyperv.txt
Expand Up @@ -174,6 +174,16 @@ without the feature to find out if enabling it is beneficial.

Requires: hv-vapic

3.17. hv-stimer-direct
=======================
Hyper-V specification allows synthetic timer operation in two modes: "classic",
when expiration event is delivered as SynIC message and "direct", when the event
is delivered via normal interrupt. It is known that nested Hyper-V can only
use synthetic timers in direct mode and thus 'hv-stimer-direct' needs to be
enabled.

Requires: hv-vpindex, hv-synic, hv-time, hv-stimer


4. Development features
========================
Expand Down
2 changes: 2 additions & 0 deletions target/i386/cpu.c
Expand Up @@ -5883,6 +5883,8 @@ static Property x86_cpu_properties[] = {
HYPERV_FEAT_EVMCS, 0),
DEFINE_PROP_BIT64("hv-ipi", X86CPU, hyperv_features,
HYPERV_FEAT_IPI, 0),
DEFINE_PROP_BIT64("hv-stimer-direct", X86CPU, hyperv_features,
HYPERV_FEAT_STIMER_DIRECT, 0),
DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false),

DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
Expand Down
1 change: 1 addition & 0 deletions target/i386/cpu.h
Expand Up @@ -749,6 +749,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
#define HYPERV_FEAT_TLBFLUSH 11
#define HYPERV_FEAT_EVMCS 12
#define HYPERV_FEAT_IPI 13
#define HYPERV_FEAT_STIMER_DIRECT 14

#ifndef HYPERV_SPINLOCK_NEVER_RETRY
#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF
Expand Down
1 change: 1 addition & 0 deletions target/i386/hyperv-proto.h
Expand Up @@ -49,6 +49,7 @@
#define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5)
#define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8)
#define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10)
#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19)

/*
* HV_CPUID_ENLIGHTMENT_INFO.EAX bits
Expand Down
9 changes: 9 additions & 0 deletions target/i386/kvm.c
Expand Up @@ -802,6 +802,14 @@ static struct {
},
.dependencies = BIT(HYPERV_FEAT_VPINDEX)
},
[HYPERV_FEAT_STIMER_DIRECT] = {
.desc = "direct mode synthetic timers (hv-stimer-direct)",
.flags = {
{.fw = FEAT_HYPERV_EDX,
.bits = HV_STIMER_DIRECT_MODE_AVAILABLE}
},
.dependencies = BIT(HYPERV_FEAT_STIMER)
},
};

static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max)
Expand Down Expand Up @@ -1124,6 +1132,7 @@ static int hyperv_handle_properties(CPUState *cs,
r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TLBFLUSH);
r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS);
r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI);
r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER_DIRECT);

/* Additional dependencies not covered by kvm_hyperv_properties[] */
if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) &&
Expand Down

0 comments on commit 128531d

Please sign in to comment.