Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240719235107.3023592-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+23 -23
+23 -23
arch/x86/kvm/lapic.c
··· 2453 2453 } 2454 2454 EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi); 2455 2455 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 + 2456 2479 /* emulate APIC access in a trap manner */ 2457 2480 void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset) 2458 2481 { ··· 3214 3191 } 3215 3192 3216 3193 vcpu->arch.apic->vapic_addr = vapic_addr; 3217 - return 0; 3218 - } 3219 - 3220 - #define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13)) 3221 - 3222 - int kvm_x2apic_icr_write(struct kvm_lapic *apic, u64 data) 3223 - { 3224 - if (data & X2APIC_ICR_RESERVED_BITS) 3225 - return 1; 3226 - 3227 - /* 3228 - * The BUSY bit is reserved on both Intel and AMD in x2APIC mode, but 3229 - * only AMD requires it to be zero, Intel essentially just ignores the 3230 - * bit. And if IPI virtualization (Intel) or x2AVIC (AMD) is enabled, 3231 - * the CPU performs the reserved bits checks, i.e. the underlying CPU 3232 - * behavior will "win". Arbitrarily clear the BUSY bit, as there is no 3233 - * sane way to provide consistent behavior with respect to hardware. 3234 - */ 3235 - data &= ~APIC_ICR_BUSY; 3236 - 3237 - kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32)); 3238 - kvm_lapic_set_reg64(apic, APIC_ICR, data); 3239 - trace_kvm_apic_write(APIC_ICR, data); 3240 3194 return 0; 3241 3195 } 3242 3196