Commit 6e4e3b4d authored by Cun Li's avatar Cun Li Committed by Paolo Bonzini

KVM: Stop using deprecated jump label APIs

The use of 'struct static_key' and 'static_key_false' is
deprecated. Use the new API.
Signed-off-by: default avatarCun Li <cun.jia.li@gmail.com>
Message-Id: <20210111152435.50275-1-cun.jia.li@gmail.com>
[Make it compile.  While at it, rename kvm_no_apic_vcpu to
 kvm_has_noapic_vcpu; the former reads too much like "true if
 no vCPU has an APIC". - Paolo]
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 14c2bf81
...@@ -91,8 +91,8 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap) ...@@ -91,8 +91,8 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap)
return __test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec)); return __test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
} }
struct static_key_deferred apic_hw_disabled __read_mostly; __read_mostly DEFINE_STATIC_KEY_DEFERRED_FALSE(apic_hw_disabled, HZ);
struct static_key_deferred apic_sw_disabled __read_mostly; __read_mostly DEFINE_STATIC_KEY_DEFERRED_FALSE(apic_sw_disabled, HZ);
static inline int apic_enabled(struct kvm_lapic *apic) static inline int apic_enabled(struct kvm_lapic *apic)
{ {
...@@ -290,9 +290,9 @@ static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val) ...@@ -290,9 +290,9 @@ static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
if (enabled != apic->sw_enabled) { if (enabled != apic->sw_enabled) {
apic->sw_enabled = enabled; apic->sw_enabled = enabled;
if (enabled) if (enabled)
static_key_slow_dec_deferred(&apic_sw_disabled); static_branch_slow_dec_deferred(&apic_sw_disabled);
else else
static_key_slow_inc(&apic_sw_disabled.key); static_branch_inc(&apic_sw_disabled.key);
atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY); atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
} }
...@@ -2175,10 +2175,10 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu) ...@@ -2175,10 +2175,10 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu)
hrtimer_cancel(&apic->lapic_timer.timer); hrtimer_cancel(&apic->lapic_timer.timer);
if (!(vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE)) if (!(vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE))
static_key_slow_dec_deferred(&apic_hw_disabled); static_branch_slow_dec_deferred(&apic_hw_disabled);
if (!apic->sw_enabled) if (!apic->sw_enabled)
static_key_slow_dec_deferred(&apic_sw_disabled); static_branch_slow_dec_deferred(&apic_sw_disabled);
if (apic->regs) if (apic->regs)
free_page((unsigned long)apic->regs); free_page((unsigned long)apic->regs);
...@@ -2250,9 +2250,9 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) ...@@ -2250,9 +2250,9 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE) { if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE) {
if (value & MSR_IA32_APICBASE_ENABLE) { if (value & MSR_IA32_APICBASE_ENABLE) {
kvm_apic_set_xapic_id(apic, vcpu->vcpu_id); kvm_apic_set_xapic_id(apic, vcpu->vcpu_id);
static_key_slow_dec_deferred(&apic_hw_disabled); static_branch_slow_dec_deferred(&apic_hw_disabled);
} else { } else {
static_key_slow_inc(&apic_hw_disabled.key); static_branch_inc(&apic_hw_disabled.key);
atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY); atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
} }
} }
...@@ -2449,7 +2449,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu, int timer_advance_ns) ...@@ -2449,7 +2449,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu, int timer_advance_ns)
* thinking that APIC state has changed. * thinking that APIC state has changed.
*/ */
vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE; vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE;
static_key_slow_inc(&apic_sw_disabled.key); /* sw disabled at reset */ static_branch_inc(&apic_sw_disabled.key); /* sw disabled at reset */
kvm_iodevice_init(&apic->dev, &apic_mmio_ops); kvm_iodevice_init(&apic->dev, &apic_mmio_ops);
return 0; return 0;
...@@ -2904,13 +2904,6 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu) ...@@ -2904,13 +2904,6 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
} }
} }
void kvm_lapic_init(void)
{
/* do not patch jump label more than once per second */
jump_label_rate_limit(&apic_hw_disabled, HZ);
jump_label_rate_limit(&apic_sw_disabled, HZ);
}
void kvm_lapic_exit(void) void kvm_lapic_exit(void)
{ {
static_key_deferred_flush(&apic_hw_disabled); static_key_deferred_flush(&apic_hw_disabled);
......
...@@ -131,7 +131,6 @@ static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu) ...@@ -131,7 +131,6 @@ static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu)
} }
int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len); int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len);
void kvm_lapic_init(void);
void kvm_lapic_exit(void); void kvm_lapic_exit(void);
#define VEC_POS(v) ((v) & (32 - 1)) #define VEC_POS(v) ((v) & (32 - 1))
...@@ -172,29 +171,29 @@ static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 va ...@@ -172,29 +171,29 @@ static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 va
__kvm_lapic_set_reg(apic->regs, reg_off, val); __kvm_lapic_set_reg(apic->regs, reg_off, val);
} }
extern struct static_key kvm_no_apic_vcpu; DECLARE_STATIC_KEY_FALSE(kvm_has_noapic_vcpu);
static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu) static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu)
{ {
if (static_key_false(&kvm_no_apic_vcpu)) if (static_branch_unlikely(&kvm_has_noapic_vcpu))
return vcpu->arch.apic; return vcpu->arch.apic;
return true; return true;
} }
extern struct static_key_deferred apic_hw_disabled; extern struct static_key_false_deferred apic_hw_disabled;
static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic) static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
{ {
if (static_key_false(&apic_hw_disabled.key)) if (static_branch_unlikely(&apic_hw_disabled.key))
return apic->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE; return apic->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE;
return MSR_IA32_APICBASE_ENABLE; return MSR_IA32_APICBASE_ENABLE;
} }
extern struct static_key_deferred apic_sw_disabled; extern struct static_key_false_deferred apic_sw_disabled;
static inline bool kvm_apic_sw_enabled(struct kvm_lapic *apic) static inline bool kvm_apic_sw_enabled(struct kvm_lapic *apic)
{ {
if (static_key_false(&apic_sw_disabled.key)) if (static_branch_unlikely(&apic_sw_disabled.key))
return apic->sw_enabled; return apic->sw_enabled;
return true; return true;
} }
......
...@@ -234,7 +234,7 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu) ...@@ -234,7 +234,7 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu)
} }
static bool mmu_audit; static bool mmu_audit;
static struct static_key mmu_audit_key; static DEFINE_STATIC_KEY_FALSE(mmu_audit_key);
static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
{ {
...@@ -250,7 +250,7 @@ static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) ...@@ -250,7 +250,7 @@ static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
{ {
if (static_key_false((&mmu_audit_key))) if (static_branch_unlikely((&mmu_audit_key)))
__kvm_mmu_audit(vcpu, point); __kvm_mmu_audit(vcpu, point);
} }
...@@ -259,7 +259,7 @@ static void mmu_audit_enable(void) ...@@ -259,7 +259,7 @@ static void mmu_audit_enable(void)
if (mmu_audit) if (mmu_audit)
return; return;
static_key_slow_inc(&mmu_audit_key); static_branch_inc(&mmu_audit_key);
mmu_audit = true; mmu_audit = true;
} }
...@@ -268,7 +268,7 @@ static void mmu_audit_disable(void) ...@@ -268,7 +268,7 @@ static void mmu_audit_disable(void)
if (!mmu_audit) if (!mmu_audit)
return; return;
static_key_slow_dec(&mmu_audit_key); static_branch_dec(&mmu_audit_key);
mmu_audit = false; mmu_audit = false;
} }
......
...@@ -7967,7 +7967,6 @@ int kvm_arch_init(void *opaque) ...@@ -7967,7 +7967,6 @@ int kvm_arch_init(void *opaque)
supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0;
} }
kvm_lapic_init();
if (pi_inject_timer == -1) if (pi_inject_timer == -1)
pi_inject_timer = housekeeping_enabled(HK_FLAG_TIMER); pi_inject_timer = housekeeping_enabled(HK_FLAG_TIMER);
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
...@@ -9991,7 +9990,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) ...@@ -9991,7 +9990,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
if (kvm_apicv_activated(vcpu->kvm)) if (kvm_apicv_activated(vcpu->kvm))
vcpu->arch.apicv_active = true; vcpu->arch.apicv_active = true;
} else } else
static_key_slow_inc(&kvm_no_apic_vcpu); static_branch_inc(&kvm_has_noapic_vcpu);
r = -ENOMEM; r = -ENOMEM;
...@@ -10120,7 +10119,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) ...@@ -10120,7 +10119,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
free_page((unsigned long)vcpu->arch.pio_data); free_page((unsigned long)vcpu->arch.pio_data);
kvfree(vcpu->arch.cpuid_entries); kvfree(vcpu->arch.cpuid_entries);
if (!lapic_in_kernel(vcpu)) if (!lapic_in_kernel(vcpu))
static_key_slow_dec(&kvm_no_apic_vcpu); static_branch_dec(&kvm_has_noapic_vcpu);
} }
void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
...@@ -10375,8 +10374,8 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu) ...@@ -10375,8 +10374,8 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0; return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
} }
struct static_key kvm_no_apic_vcpu __read_mostly; __read_mostly DEFINE_STATIC_KEY_FALSE(kvm_has_noapic_vcpu);
EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu); EXPORT_SYMBOL_GPL(kvm_has_noapic_vcpu);
void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int 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