[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 09/16] apic: drop APICCommonState.idx and use
From: |
Radim Krčmář |
Subject: |
Re: [Qemu-devel] [PATCH v4 09/16] apic: drop APICCommonState.idx and use APIC ID as index in local_apics[] |
Date: |
Mon, 18 Jul 2016 18:58:11 +0200 |
2016-07-14 18:54+0200, Igor Mammedov:
> local_apics[] is sized to contain all APIC ID supported in xAPIC mode,
> so use APIC ID as index in it instead of constantly increasing counter idx.
>
> Fixes error "apic initialization failed" when a CPU hotplugged and
> unplugged more times than there are free slots in local_apics[].
>
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
The new method handles dynamic APIC ID changes made by the guest and id
is set to the initial apic_id when realize is called, so it's even
better than the previous one as we have higher chance of hitting the
correct apic in local_apics[].
Reviewed-by: Radim Krčmář <address@hidden>
> CC: Radim Krčmář <address@hidden>
> CC: address@hidden
> ---
> include/hw/i386/apic_internal.h | 1 -
> hw/intc/apic.c | 16 +++++++---------
> 2 files changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
> index 67348e9..8330592 100644
> --- a/include/hw/i386/apic_internal.h
> +++ b/include/hw/i386/apic_internal.h
> @@ -174,7 +174,6 @@ struct APICCommonState {
> uint32_t initial_count;
> int64_t initial_count_load_time;
> int64_t next_time;
> - int idx; /* not actually common, used only by 'apic' derived class */
> QEMUTimer *timer;
> int64_t timer_expiry;
> int sipi_vector;
> diff --git a/hw/intc/apic.c b/hw/intc/apic.c
> index b0d237b..f473572 100644
> --- a/hw/intc/apic.c
> +++ b/hw/intc/apic.c
> @@ -421,7 +421,7 @@ static int apic_find_dest(uint8_t dest)
> int i;
>
> if (apic && apic->id == dest)
> - return dest; /* shortcut in case apic->id == apic->idx */
> + return dest; /* shortcut in case apic->id == local_apics[dest]->id
> */
>
> for (i = 0; i < MAX_APICS; i++) {
> apic = local_apics[i];
(We could also update local_apics[] when APIC ID changes and drop the
loop, but it's safer this way.)
> @@ -504,14 +504,14 @@ static void apic_deliver(DeviceState *dev, uint8_t
> dest, uint8_t dest_mode,
> break;
> case 1:
> memset(deliver_bitmask, 0x00, sizeof(deliver_bitmask));
> - apic_set_bit(deliver_bitmask, s->idx);
> + apic_set_bit(deliver_bitmask, s->id);
> break;
> case 2:
> memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask));
> break;
> case 3:
> memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask));
> - apic_reset_bit(deliver_bitmask, s->idx);
> + apic_reset_bit(deliver_bitmask, s->id);
> break;
> }
>
> @@ -871,20 +871,18 @@ static const MemoryRegionOps apic_io_ops = {
> static void apic_realize(DeviceState *dev, Error **errp)
> {
> APICCommonState *s = APIC_COMMON(dev);
> - static int apic_no;
>
> - if (apic_no >= MAX_APICS) {
> - error_setg(errp, "%s initialization failed.",
> - object_get_typename(OBJECT(dev)));
> + if (s->id >= MAX_APICS) {
> + error_setg(errp, "%s initialization failed. APIC ID %d is invalid",
> + object_get_typename(OBJECT(dev)), s->id);
> return;
> }
> - s->idx = apic_no++;
>
> memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s,
> "apic-msi",
> APIC_SPACE_SIZE);
>
> s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s);
> - local_apics[s->idx] = s;
> + local_apics[s->id] = s;
>
> msi_nonbroken = true;
> }
> --
> 2.7.4
>
- Re: [Qemu-devel] [PATCH v4 05/16] pc: enforce adding CPUs contiguously and removing them in opposit order, (continued)
[Qemu-devel] [PATCH v5 05/16] pc: enforce adding CPUs contiguously and removing them in opposit order, Igor Mammedov, 2016/07/18
Re: [Qemu-devel] [PATCH v4 05/16] pc: enforce adding CPUs contiguously and removing them in opposit order, Eric Blake, 2016/07/18
[Qemu-devel] [PATCH v4 06/16] pc: cpu: allow device_add to be used with x86 cpu, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 07/16] pc: implement query-hotpluggable-cpus callback, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 09/16] apic: drop APICCommonState.idx and use APIC ID as index in local_apics[], Igor Mammedov, 2016/07/14
- Re: [Qemu-devel] [PATCH v4 09/16] apic: drop APICCommonState.idx and use APIC ID as index in local_apics[],
Radim Krčmář <=
[Qemu-devel] [PATCH v4 08/16] apic: move MAX_APICS check to 'apic' class, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 11/16] (kvm)apic: add unrealize callbacks, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 10/16] apic: kvm-apic: fix crash due to access to freed memory region, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 13/16] target-i386: cpu: do not ignore error and fix apic parent, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 12/16] apic: use apic_id as apic's migration instance_id, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 14/16] target-i386: fix apic object leak when CPU is deleted, Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 15/16] target-i386: add x86_cpu_unrealizefn(), Igor Mammedov, 2016/07/14
[Qemu-devel] [PATCH v4 16/16] pc: make device_del CPU work for x86 CPUs, Igor Mammedov, 2016/07/14