Commit b9964ee3 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Make kvm_lapic_set_reg() a "private" xAPIC helper

Hide the lapic's "raw" write helper inside lapic.c to force non-APIC code
to go through proper helpers when modification the vAPIC state.  Keep the
read helper visible to outsiders for now, refactoring KVM to hide it too
is possible, it will just take more work to do so.

No functional change intended.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20220204214205.3306634-11-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent a57a3168
...@@ -68,6 +68,16 @@ static bool lapic_timer_advance_dynamic __read_mostly; ...@@ -68,6 +68,16 @@ static bool lapic_timer_advance_dynamic __read_mostly;
/* step-by-step approximation to mitigate fluctuation */ /* step-by-step approximation to mitigate fluctuation */
#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8 #define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
static inline void __kvm_lapic_set_reg(char *regs, int reg_off, u32 val)
{
*((u32 *) (regs + reg_off)) = val;
}
static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
{
__kvm_lapic_set_reg(apic->regs, reg_off, val);
}
static __always_inline u64 __kvm_lapic_get_reg64(char *regs, int reg) static __always_inline u64 __kvm_lapic_get_reg64(char *regs, int reg)
{ {
BUILD_BUG_ON(reg != APIC_ICR); BUILD_BUG_ON(reg != APIC_ICR);
......
...@@ -118,6 +118,7 @@ int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr); ...@@ -118,6 +118,7 @@ int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu); void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu);
void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu); void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data);
int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data); int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data); int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
...@@ -150,19 +151,14 @@ static inline void kvm_lapic_set_irr(int vec, struct kvm_lapic *apic) ...@@ -150,19 +151,14 @@ static inline void kvm_lapic_set_irr(int vec, struct kvm_lapic *apic)
apic->irr_pending = true; apic->irr_pending = true;
} }
static inline u32 kvm_lapic_get_reg(struct kvm_lapic *apic, int reg_off) static inline u32 __kvm_lapic_get_reg(char *regs, int reg_off)
{ {
return *((u32 *) (apic->regs + reg_off)); return *((u32 *) (regs + reg_off));
} }
static inline void __kvm_lapic_set_reg(char *regs, int reg_off, u32 val) static inline u32 kvm_lapic_get_reg(struct kvm_lapic *apic, int reg_off)
{
*((u32 *) (regs + reg_off)) = val;
}
static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
{ {
__kvm_lapic_set_reg(apic->regs, reg_off, val); return __kvm_lapic_get_reg(apic->regs, reg_off);
} }
DECLARE_STATIC_KEY_FALSE(kvm_has_noapic_vcpu); DECLARE_STATIC_KEY_FALSE(kvm_has_noapic_vcpu);
......
...@@ -253,13 +253,13 @@ TRACE_EVENT(kvm_cpuid, ...@@ -253,13 +253,13 @@ TRACE_EVENT(kvm_cpuid,
* Tracepoint for apic access. * Tracepoint for apic access.
*/ */
TRACE_EVENT(kvm_apic, TRACE_EVENT(kvm_apic,
TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val), TP_PROTO(unsigned int rw, unsigned int reg, u64 val),
TP_ARGS(rw, reg, val), TP_ARGS(rw, reg, val),
TP_STRUCT__entry( TP_STRUCT__entry(
__field( unsigned int, rw ) __field( unsigned int, rw )
__field( unsigned int, reg ) __field( unsigned int, reg )
__field( unsigned int, val ) __field( u64, val )
), ),
TP_fast_assign( TP_fast_assign(
...@@ -268,7 +268,7 @@ TRACE_EVENT(kvm_apic, ...@@ -268,7 +268,7 @@ TRACE_EVENT(kvm_apic,
__entry->val = val; __entry->val = val;
), ),
TP_printk("apic_%s %s = 0x%x", TP_printk("apic_%s %s = 0x%llx",
__entry->rw ? "write" : "read", __entry->rw ? "write" : "read",
__print_symbolic(__entry->reg, kvm_trace_symbol_apic), __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
__entry->val) __entry->val)
......
...@@ -2041,14 +2041,8 @@ static int handle_fastpath_set_x2apic_icr_irqoff(struct kvm_vcpu *vcpu, u64 data ...@@ -2041,14 +2041,8 @@ static int handle_fastpath_set_x2apic_icr_irqoff(struct kvm_vcpu *vcpu, u64 data
if (((data & APIC_SHORT_MASK) == APIC_DEST_NOSHORT) && if (((data & APIC_SHORT_MASK) == APIC_DEST_NOSHORT) &&
((data & APIC_DEST_MASK) == APIC_DEST_PHYSICAL) && ((data & APIC_DEST_MASK) == APIC_DEST_PHYSICAL) &&
((data & APIC_MODE_MASK) == APIC_DM_FIXED) && ((data & APIC_MODE_MASK) == APIC_DM_FIXED) &&
((u32)(data >> 32) != X2APIC_BROADCAST)) { ((u32)(data >> 32) != X2APIC_BROADCAST))
data &= ~APIC_ICR_BUSY; return kvm_x2apic_icr_write(vcpu->arch.apic, data);
kvm_apic_send_ipi(vcpu->arch.apic, (u32)data, (u32)(data >> 32));
kvm_lapic_set_reg(vcpu->arch.apic, APIC_ICR2, (u32)(data >> 32));
kvm_lapic_set_reg(vcpu->arch.apic, APIC_ICR, (u32)data);
trace_kvm_apic_write(APIC_ICR, (u32)data);
return 0;
}
return 1; return 1;
} }
......
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