Commit 2d5ba19b authored by Marcelo Tosatti's avatar Marcelo Tosatti Committed by Paolo Bonzini

kvm: x86: add host poll control msrs

Add an MSRs which allows the guest to disable
host polling (specifically the cpuidle-haltpoll,
when performing polling in the guest, disables
host side polling).
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fdb28619
...@@ -273,3 +273,12 @@ MSR_KVM_EOI_EN: 0x4b564d04 ...@@ -273,3 +273,12 @@ MSR_KVM_EOI_EN: 0x4b564d04
guest must both read the least significant bit in the memory area and guest must both read the least significant bit in the memory area and
clear it using a single CPU instruction, such as test and clear, or clear it using a single CPU instruction, such as test and clear, or
compare and exchange. compare and exchange.
MSR_KVM_POLL_CONTROL: 0x4b564d05
Control host-side polling.
data: Bit 0 enables (1) or disables (0) host-side HLT polling logic.
KVM guests can request the host not to poll on HLT, for example if
they are performing polling themselves.
...@@ -755,6 +755,8 @@ struct kvm_vcpu_arch { ...@@ -755,6 +755,8 @@ struct kvm_vcpu_arch {
struct gfn_to_hva_cache data; struct gfn_to_hva_cache data;
} pv_eoi; } pv_eoi;
u64 msr_kvm_poll_control;
/* /*
* Indicate whether the access faults on its page table in guest * Indicate whether the access faults on its page table in guest
* which is set when fix page fault and used to detect unhandeable * which is set when fix page fault and used to detect unhandeable
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#define KVM_FEATURE_PV_TLB_FLUSH 9 #define KVM_FEATURE_PV_TLB_FLUSH 9
#define KVM_FEATURE_ASYNC_PF_VMEXIT 10 #define KVM_FEATURE_ASYNC_PF_VMEXIT 10
#define KVM_FEATURE_PV_SEND_IPI 11 #define KVM_FEATURE_PV_SEND_IPI 11
#define KVM_FEATURE_POLL_CONTROL 12
#define KVM_HINTS_REALTIME 0 #define KVM_HINTS_REALTIME 0
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
#define MSR_KVM_ASYNC_PF_EN 0x4b564d02 #define MSR_KVM_ASYNC_PF_EN 0x4b564d02
#define MSR_KVM_STEAL_TIME 0x4b564d03 #define MSR_KVM_STEAL_TIME 0x4b564d03
#define MSR_KVM_PV_EOI_EN 0x4b564d04 #define MSR_KVM_PV_EOI_EN 0x4b564d04
#define MSR_KVM_POLL_CONTROL 0x4b564d05
struct kvm_steal_time { struct kvm_steal_time {
__u64 steal; __u64 steal;
......
...@@ -41,6 +41,7 @@ config KVM ...@@ -41,6 +41,7 @@ config KVM
select PERF_EVENTS select PERF_EVENTS
select HAVE_KVM_MSI select HAVE_KVM_MSI
select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_CPU_RELAX_INTERCEPT
select HAVE_KVM_NO_POLL
select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_VFIO select KVM_VFIO
select SRCU select SRCU
......
...@@ -658,7 +658,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -658,7 +658,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
(1 << KVM_FEATURE_PV_UNHALT) | (1 << KVM_FEATURE_PV_UNHALT) |
(1 << KVM_FEATURE_PV_TLB_FLUSH) | (1 << KVM_FEATURE_PV_TLB_FLUSH) |
(1 << KVM_FEATURE_ASYNC_PF_VMEXIT) | (1 << KVM_FEATURE_ASYNC_PF_VMEXIT) |
(1 << KVM_FEATURE_PV_SEND_IPI); (1 << KVM_FEATURE_PV_SEND_IPI) |
(1 << KVM_FEATURE_POLL_CONTROL);
if (sched_info_on()) if (sched_info_on())
entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); entry->eax |= (1 << KVM_FEATURE_STEAL_TIME);
......
...@@ -1177,6 +1177,7 @@ static u32 emulated_msrs[] = { ...@@ -1177,6 +1177,7 @@ static u32 emulated_msrs[] = {
MSR_IA32_POWER_CTL, MSR_IA32_POWER_CTL,
MSR_K7_HWCR, MSR_K7_HWCR,
MSR_KVM_POLL_CONTROL,
}; };
static unsigned num_emulated_msrs; static unsigned num_emulated_msrs;
...@@ -2636,6 +2637,14 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2636,6 +2637,14 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
return 1; return 1;
break; break;
case MSR_KVM_POLL_CONTROL:
/* only enable bit supported */
if (data & (-1ULL << 1))
return 1;
vcpu->arch.msr_kvm_poll_control = data;
break;
case MSR_IA32_MCG_CTL: case MSR_IA32_MCG_CTL:
case MSR_IA32_MCG_STATUS: case MSR_IA32_MCG_STATUS:
case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1: case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1:
...@@ -2885,6 +2894,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2885,6 +2894,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_KVM_PV_EOI_EN: case MSR_KVM_PV_EOI_EN:
msr_info->data = vcpu->arch.pv_eoi.msr_val; msr_info->data = vcpu->arch.pv_eoi.msr_val;
break; break;
case MSR_KVM_POLL_CONTROL:
msr_info->data = vcpu->arch.msr_kvm_poll_control;
break;
case MSR_IA32_P5_MC_ADDR: case MSR_IA32_P5_MC_ADDR:
case MSR_IA32_P5_MC_TYPE: case MSR_IA32_P5_MC_TYPE:
case MSR_IA32_MCG_CAP: case MSR_IA32_MCG_CAP:
...@@ -8861,6 +8873,10 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) ...@@ -8861,6 +8873,10 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
msr.host_initiated = true; msr.host_initiated = true;
kvm_write_tsc(vcpu, &msr); kvm_write_tsc(vcpu, &msr);
vcpu_put(vcpu); vcpu_put(vcpu);
/* poll control enabled by default */
vcpu->arch.msr_kvm_poll_control = 1;
mutex_unlock(&vcpu->mutex); mutex_unlock(&vcpu->mutex);
if (!kvmclock_periodic_sync) if (!kvmclock_periodic_sync)
...@@ -9972,6 +9988,13 @@ bool kvm_vector_hashing_enabled(void) ...@@ -9972,6 +9988,13 @@ bool kvm_vector_hashing_enabled(void)
} }
EXPORT_SYMBOL_GPL(kvm_vector_hashing_enabled); EXPORT_SYMBOL_GPL(kvm_vector_hashing_enabled);
bool kvm_arch_no_poll(struct kvm_vcpu *vcpu)
{
return (vcpu->arch.msr_kvm_poll_control & 1) == 0;
}
EXPORT_SYMBOL_GPL(kvm_arch_no_poll);
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit);
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio);
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment