Commit a262bca3 authored by Wanpeng Li's avatar Wanpeng Li Committed by Paolo Bonzini

KVM: Introduce pv check helpers

Introduce some pv check helpers for consistency.
Suggested-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: default avatarWanpeng Li <wanpengli@tencent.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fcd07f9a
...@@ -425,7 +425,27 @@ static void __init sev_map_percpu_data(void) ...@@ -425,7 +425,27 @@ static void __init sev_map_percpu_data(void)
} }
} }
static bool pv_tlb_flush_supported(void)
{
return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
}
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static bool pv_ipi_supported(void)
{
return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
}
static bool pv_sched_yield_supported(void)
{
return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
}
#define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
static void __send_ipi_mask(const struct cpumask *mask, int vector) static void __send_ipi_mask(const struct cpumask *mask, int vector)
...@@ -619,9 +639,7 @@ static void __init kvm_guest_init(void) ...@@ -619,9 +639,7 @@ static void __init kvm_guest_init(void)
pv_ops.time.steal_clock = kvm_steal_clock; pv_ops.time.steal_clock = kvm_steal_clock;
} }
if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && if (pv_tlb_flush_supported()) {
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
pv_ops.mmu.tlb_remove_table = tlb_remove_table; pv_ops.mmu.tlb_remove_table = tlb_remove_table;
} }
...@@ -632,9 +650,7 @@ static void __init kvm_guest_init(void) ...@@ -632,9 +650,7 @@ static void __init kvm_guest_init(void)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus; smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus;
smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
if (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && if (pv_sched_yield_supported()) {
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
smp_ops.send_call_func_ipi = kvm_smp_send_call_func_ipi; smp_ops.send_call_func_ipi = kvm_smp_send_call_func_ipi;
pr_info("KVM setup pv sched yield\n"); pr_info("KVM setup pv sched yield\n");
} }
...@@ -700,7 +716,7 @@ static uint32_t __init kvm_detect(void) ...@@ -700,7 +716,7 @@ static uint32_t __init kvm_detect(void)
static void __init kvm_apic_init(void) static void __init kvm_apic_init(void)
{ {
#if defined(CONFIG_SMP) #if defined(CONFIG_SMP)
if (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI)) if (pv_ipi_supported())
kvm_setup_pv_ipi(); kvm_setup_pv_ipi();
#endif #endif
} }
...@@ -739,9 +755,7 @@ static __init int kvm_setup_pv_tlb_flush(void) ...@@ -739,9 +755,7 @@ static __init int kvm_setup_pv_tlb_flush(void)
if (!kvm_para_available() || nopv) if (!kvm_para_available() || nopv)
return 0; return 0;
if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && if (pv_tlb_flush_supported()) {
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu), zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
GFP_KERNEL, cpu_to_node(cpu)); GFP_KERNEL, cpu_to_node(cpu));
......
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