Skip to content

Commit d332343

Browse files
committed
KVM: x86: Move x2APIC ICR helper above kvm_apic_write_nodecode()
Hoist kvm_x2apic_icr_write() above kvm_apic_write_nodecode() so that a local helper to _read_ the x2APIC ICR can be added and used in the nodecode path without needing a forward declaration. No functional change intended. Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 71bf395 commit d332343

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

arch/x86/kvm/lapic.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,29 @@ void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu)
24532453
}
24542454
EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi);
24552455

2456+
#define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13))
2457+
2458+
int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data)
2459+
{
2460+
if (data & X2APIC_ICR_RESERVED_BITS)
2461+
return 1;
2462+
2463+
/*
2464+
* The BUSY bit is reserved on both Intel and AMD in x2APIC mode, but
2465+
* only AMD requires it to be zero, Intel essentially just ignores the
2466+
* bit. And if IPI virtualization (Intel) or x2AVIC (AMD) is enabled,
2467+
* the CPU performs the reserved bits checks, i.e. the underlying CPU
2468+
* behavior will "win". Arbitrarily clear the BUSY bit, as there is no
2469+
* sane way to provide consistent behavior with respect to hardware.
2470+
*/
2471+
data &= ~APIC_ICR_BUSY;
2472+
2473+
kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32));
2474+
kvm_lapic_set_reg64(apic, APIC_ICR, data);
2475+
trace_kvm_apic_write(APIC_ICR, data);
2476+
return 0;
2477+
}
2478+
24562479
/* emulate APIC access in a trap manner */
24572480
void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)
24582481
{
@@ -3194,29 +3217,6 @@ int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr)
31943217
return 0;
31953218
}
31963219

3197-
#define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13))
3198-
3199-
int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data)
3200-
{
3201-
if (data & X2APIC_ICR_RESERVED_BITS)
3202-
return 1;
3203-
3204-
/*
3205-
* The BUSY bit is reserved on both Intel and AMD in x2APIC mode, but
3206-
* only AMD requires it to be zero, Intel essentially just ignores the
3207-
* bit. And if IPI virtualization (Intel) or x2AVIC (AMD) is enabled,
3208-
* the CPU performs the reserved bits checks, i.e. the underlying CPU
3209-
* behavior will "win". Arbitrarily clear the BUSY bit, as there is no
3210-
* sane way to provide consistent behavior with respect to hardware.
3211-
*/
3212-
data &= ~APIC_ICR_BUSY;
3213-
3214-
kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32));
3215-
kvm_lapic_set_reg64(apic, APIC_ICR, data);
3216-
trace_kvm_apic_write(APIC_ICR, data);
3217-
return 0;
3218-
}
3219-
32203220
static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data)
32213221
{
32223222
u32 low;

0 commit comments

Comments
 (0)