Skip to content

Commit beef335

Browse files
sean-jcgregkh
authored andcommitted
KVM: x86: Move x2APIC ICR helper above kvm_apic_write_nodecode()
commit d332343 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7eae461 commit beef335

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
@@ -2443,6 +2443,29 @@ void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu)
24432443
}
24442444
EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi);
24452445

2446+
#define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13))
2447+
2448+
int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data)
2449+
{
2450+
if (data & X2APIC_ICR_RESERVED_BITS)
2451+
return 1;
2452+
2453+
/*
2454+
* The BUSY bit is reserved on both Intel and AMD in x2APIC mode, but
2455+
* only AMD requires it to be zero, Intel essentially just ignores the
2456+
* bit. And if IPI virtualization (Intel) or x2AVIC (AMD) is enabled,
2457+
* the CPU performs the reserved bits checks, i.e. the underlying CPU
2458+
* behavior will "win". Arbitrarily clear the BUSY bit, as there is no
2459+
* sane way to provide consistent behavior with respect to hardware.
2460+
*/
2461+
data &= ~APIC_ICR_BUSY;
2462+
2463+
kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32));
2464+
kvm_lapic_set_reg64(apic, APIC_ICR, data);
2465+
trace_kvm_apic_write(APIC_ICR, data);
2466+
return 0;
2467+
}
2468+
24462469
/* emulate APIC access in a trap manner */
24472470
void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)
24482471
{
@@ -3153,29 +3176,6 @@ int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr)
31533176
return 0;
31543177
}
31553178

3156-
#define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13))
3157-
3158-
int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data)
3159-
{
3160-
if (data & X2APIC_ICR_RESERVED_BITS)
3161-
return 1;
3162-
3163-
/*
3164-
* The BUSY bit is reserved on both Intel and AMD in x2APIC mode, but
3165-
* only AMD requires it to be zero, Intel essentially just ignores the
3166-
* bit. And if IPI virtualization (Intel) or x2AVIC (AMD) is enabled,
3167-
* the CPU performs the reserved bits checks, i.e. the underlying CPU
3168-
* behavior will "win". Arbitrarily clear the BUSY bit, as there is no
3169-
* sane way to provide consistent behavior with respect to hardware.
3170-
*/
3171-
data &= ~APIC_ICR_BUSY;
3172-
3173-
kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32));
3174-
kvm_lapic_set_reg64(apic, APIC_ICR, data);
3175-
trace_kvm_apic_write(APIC_ICR, data);
3176-
return 0;
3177-
}
3178-
31793179
static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data)
31803180
{
31813181
u32 low;

0 commit comments

Comments
 (0)