KVM: x86: replace kvm_apic_id with kvm_{x,x2}apic_id
There were three calls sites: - recalculate_apic_map and kvm_apic_match_physical_addr, where it would only complicate implementation of x2APIC hotplug; - in apic_debug, where it was still somewhat preserved, but keeping the old function just for apic_debug was not worth it Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Родитель
f98a3efb28
Коммит
6e50043912
|
@ -115,6 +115,16 @@ static inline int apic_enabled(struct kvm_lapic *apic)
|
||||||
(LVT_MASK | APIC_MODE_MASK | APIC_INPUT_POLARITY | \
|
(LVT_MASK | APIC_MODE_MASK | APIC_INPUT_POLARITY | \
|
||||||
APIC_LVT_REMOTE_IRR | APIC_LVT_LEVEL_TRIGGER)
|
APIC_LVT_REMOTE_IRR | APIC_LVT_LEVEL_TRIGGER)
|
||||||
|
|
||||||
|
static inline u8 kvm_xapic_id(struct kvm_lapic *apic)
|
||||||
|
{
|
||||||
|
return kvm_lapic_get_reg(apic, APIC_ID) >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 kvm_x2apic_id(struct kvm_lapic *apic)
|
||||||
|
{
|
||||||
|
return apic->vcpu->vcpu_id;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool kvm_apic_map_get_logical_dest(struct kvm_apic_map *map,
|
static inline bool kvm_apic_map_get_logical_dest(struct kvm_apic_map *map,
|
||||||
u32 dest_id, struct kvm_lapic ***cluster, u16 *mask) {
|
u32 dest_id, struct kvm_lapic ***cluster, u16 *mask) {
|
||||||
switch (map->mode) {
|
switch (map->mode) {
|
||||||
|
@ -159,13 +169,13 @@ static void recalculate_apic_map(struct kvm *kvm)
|
||||||
struct kvm_apic_map *new, *old = NULL;
|
struct kvm_apic_map *new, *old = NULL;
|
||||||
struct kvm_vcpu *vcpu;
|
struct kvm_vcpu *vcpu;
|
||||||
int i;
|
int i;
|
||||||
u32 max_id = 255;
|
u32 max_id = 255; /* enough space for any xAPIC ID */
|
||||||
|
|
||||||
mutex_lock(&kvm->arch.apic_map_lock);
|
mutex_lock(&kvm->arch.apic_map_lock);
|
||||||
|
|
||||||
kvm_for_each_vcpu(i, vcpu, kvm)
|
kvm_for_each_vcpu(i, vcpu, kvm)
|
||||||
if (kvm_apic_present(vcpu))
|
if (kvm_apic_present(vcpu))
|
||||||
max_id = max(max_id, kvm_apic_id(vcpu->arch.apic));
|
max_id = max(max_id, kvm_x2apic_id(vcpu->arch.apic));
|
||||||
|
|
||||||
new = kvm_kvzalloc(sizeof(struct kvm_apic_map) +
|
new = kvm_kvzalloc(sizeof(struct kvm_apic_map) +
|
||||||
sizeof(struct kvm_lapic *) * ((u64)max_id + 1));
|
sizeof(struct kvm_lapic *) * ((u64)max_id + 1));
|
||||||
|
@ -184,12 +194,13 @@ static void recalculate_apic_map(struct kvm *kvm)
|
||||||
if (!kvm_apic_present(vcpu))
|
if (!kvm_apic_present(vcpu))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
aid = kvm_apic_id(apic);
|
aid = apic_x2apic_mode(apic) ? kvm_x2apic_id(apic)
|
||||||
ldr = kvm_lapic_get_reg(apic, APIC_LDR);
|
: kvm_xapic_id(apic);
|
||||||
|
|
||||||
if (aid <= new->max_apic_id)
|
if (aid <= new->max_apic_id)
|
||||||
new->phys_map[aid] = apic;
|
new->phys_map[aid] = apic;
|
||||||
|
|
||||||
|
ldr = kvm_lapic_get_reg(apic, APIC_LDR);
|
||||||
|
|
||||||
if (apic_x2apic_mode(apic)) {
|
if (apic_x2apic_mode(apic)) {
|
||||||
new->mode |= KVM_APIC_MODE_X2APIC;
|
new->mode |= KVM_APIC_MODE_X2APIC;
|
||||||
} else if (ldr) {
|
} else if (ldr) {
|
||||||
|
@ -250,6 +261,8 @@ static inline void kvm_apic_set_x2apic_id(struct kvm_lapic *apic, u32 id)
|
||||||
{
|
{
|
||||||
u32 ldr = ((id >> 4) << 16) | (1 << (id & 0xf));
|
u32 ldr = ((id >> 4) << 16) | (1 << (id & 0xf));
|
||||||
|
|
||||||
|
WARN_ON_ONCE(id != apic->vcpu->vcpu_id);
|
||||||
|
|
||||||
kvm_lapic_set_reg(apic, APIC_ID, id);
|
kvm_lapic_set_reg(apic, APIC_ID, id);
|
||||||
kvm_lapic_set_reg(apic, APIC_LDR, ldr);
|
kvm_lapic_set_reg(apic, APIC_LDR, ldr);
|
||||||
recalculate_apic_map(apic->vcpu->kvm);
|
recalculate_apic_map(apic->vcpu->kvm);
|
||||||
|
@ -591,9 +604,9 @@ static bool kvm_apic_match_physical_addr(struct kvm_lapic *apic, u32 mda)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (apic_x2apic_mode(apic))
|
if (apic_x2apic_mode(apic))
|
||||||
return mda == kvm_apic_id(apic);
|
return mda == kvm_x2apic_id(apic);
|
||||||
|
|
||||||
return mda == SET_APIC_DEST_FIELD(kvm_apic_id(apic));
|
return mda == SET_APIC_DEST_FIELD(kvm_xapic_id(apic));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool kvm_apic_match_logical_addr(struct kvm_lapic *apic, u32 mda)
|
static bool kvm_apic_match_logical_addr(struct kvm_lapic *apic, u32 mda)
|
||||||
|
@ -1907,9 +1920,9 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
|
||||||
vcpu->arch.apic_arb_prio = 0;
|
vcpu->arch.apic_arb_prio = 0;
|
||||||
vcpu->arch.apic_attention = 0;
|
vcpu->arch.apic_attention = 0;
|
||||||
|
|
||||||
apic_debug("%s: vcpu=%p, id=%d, base_msr="
|
apic_debug("%s: vcpu=%p, id=0x%x, base_msr="
|
||||||
"0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__,
|
"0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__,
|
||||||
vcpu, kvm_apic_id(apic),
|
vcpu, kvm_lapic_get_reg(apic, APIC_ID),
|
||||||
vcpu->arch.apic_base, apic->base_address);
|
vcpu->arch.apic_base, apic->base_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,17 +202,6 @@ static inline int kvm_lapic_latched_init(struct kvm_vcpu *vcpu)
|
||||||
return lapic_in_kernel(vcpu) && test_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
|
return lapic_in_kernel(vcpu) && test_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u32 kvm_apic_id(struct kvm_lapic *apic)
|
|
||||||
{
|
|
||||||
/* To avoid a race between apic_base and following APIC_ID update when
|
|
||||||
* switching to x2apic_mode, the x2apic mode returns initial x2apic id.
|
|
||||||
*/
|
|
||||||
if (apic_x2apic_mode(apic))
|
|
||||||
return apic->vcpu->vcpu_id;
|
|
||||||
|
|
||||||
return kvm_lapic_get_reg(apic, APIC_ID) >> 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector);
|
bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector);
|
||||||
|
|
||||||
void wait_lapic_expire(struct kvm_vcpu *vcpu);
|
void wait_lapic_expire(struct kvm_vcpu *vcpu);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче