kvm/apic: fix 2.2->2.1 migration
PATCH 1/1 kvm/apic: fix 2.2->2.1 migration
The wait_for_sipi field is set back to 1 after an INIT, so it was not effective to reset it in kvm_apic_realize. Introduce a reset callback and reset wait_for_sipi there.
--- hw/i386/kvm/apic.c | 10 +++++++--- hw/intc/apic_common.c | 5 +++++ include/hw/i386/apic_internal.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-)
hw/i386/kvm/apic.c +7 -3
@@ -171,12 +171,15 @@ static const MemoryRegionOps kvm_apic_io_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void kvm_apic_realize (DeviceState *dev,Error **errp) +static void kvm_apic_reset (APICCommonState *s) { -APICCommonState *s =APIC_COMMON (dev); -/* Not used by KVM, which uses the CPU mp_state instead. */ s->wait_for_sipi =0 ; +} + +static void kvm_apic_realize (DeviceState *dev,Error **errp) +{ +APICCommonState *s =APIC_COMMON (dev);memory_region_init_io (&s->io_memory,NULL , &kvm_apic_io_ops, s,"kvm-apic-msi" ,APIC_SPACE_SIZE );
@@ -191,6 +194,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void *data)APICCommonClass *k =APIC_COMMON_CLASS (klass); k->realize = kvm_apic_realize; + k->reset = kvm_apic_reset; k->set_base = kvm_apic_set_base; k->set_tpr = kvm_apic_set_tpr; k->get_tpr = kvm_apic_get_tpr;
hw/intc/apic_common.c +5 -0
@@ -178,6 +178,7 @@ bool apic_next_timer(APICCommonState *s, int64_t current_time)void apic_init_reset (DeviceState *dev) {APICCommonState *s =APIC_COMMON (dev); +APICCommonClass *info =APIC_COMMON_GET_CLASS (s);int i;if (!s) {
@@ -206,6 +207,10 @@ void apic_init_reset(DeviceState *dev)timer_del (s->timer); } s->timer_expiry =-1 ; + +if (info->reset) { + info->reset (s); + } }void apic_designate_bsp (DeviceState *dev)
include/hw/i386/apic_internal.h +1 -0
@@ -89,6 +89,7 @@ typedef struct APICCommonClassvoid (*external_nmi)(APICCommonState *s);void (*pre_save)(APICCommonState *s);void (*post_load)(APICCommonState *s); +void (*reset)(APICCommonState *s); } APICCommonClass;struct APICCommonState {
Signature · 1 line
2.1.0
Quoted 7 lines · * Paolo Bonzini ([email protected]) wrote:
The
wait_for_sipifield is set back to 1 after an INIT, so it was not effective to reset it inkvm_apic_realize. Introduce a reset callback and resetwait_for_sipithere.Reported-by Igor Mammedov <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>
OK, let me just check that I get this....
It gets reset to 0 already in kvm_apic_realize
then we do the common init that sets it to !bsp - so 1 for most CPUs then you're adding this so that a specific APIC implementation (kvm) can nobble it back to 0 again?
and on the load side it's forced to zero by apic_pre_load.
Dave
Quoted 76 lines
--- hw/i386/kvm/apic.c | 10 +++++++--- hw/intc/apic_common.c | 5 +++++ include/hw/i386/apic_internal.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-)hw/i386/kvm/apic.c +7
-3@@ -171,12 +171,15 @@ static const MemoryRegionOps kvm_apic_io_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void kvm_apic_realize (DeviceState *dev,Error **errp) +static void kvm_apic_reset (APICCommonState *s) { -APICCommonState *s =APIC_COMMON (dev); -/* Not used by KVM, which uses the CPU mp_state instead. */ s->wait_for_sipi =0 ; +} + +static void kvm_apic_realize (DeviceState *dev,Error **errp) +{ +APICCommonState *s =APIC_COMMON (dev);memory_region_init_io (&s->io_memory,NULL , &kvm_apic_io_ops, s,"kvm-apic-msi" ,APIC_SPACE_SIZE );@@ -191,6 +194,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void *data)APICCommonClass *k =APIC_COMMON_CLASS (klass); k->realize = kvm_apic_realize; + k->reset = kvm_apic_reset; k->set_base = kvm_apic_set_base; k->set_tpr = kvm_apic_set_tpr; k->get_tpr = kvm_apic_get_tpr;hw/intc/apic_common.c +5
-0@@ -178,6 +178,7 @@ bool apic_next_timer(APICCommonState *s, int64_t current_time)void apic_init_reset (DeviceState *dev) {APICCommonState *s =APIC_COMMON (dev); +APICCommonClass *info =APIC_COMMON_GET_CLASS (s);int i;if (!s) {@@ -206,6 +207,10 @@ void apic_init_reset(DeviceState *dev)timer_del (s->timer); } s->timer_expiry =-1 ; + +if (info->reset) { + info->reset (s); + } }void apic_designate_bsp (DeviceState *dev)include/hw/i386/apic_internal.h +1
-0@@ -89,6 +89,7 @@ typedef struct APICCommonClassvoid (*external_nmi)(APICCommonState *s);void (*pre_save)(APICCommonState *s);void (*post_load)(APICCommonState *s); +void (*reset)(APICCommonState *s); } APICCommonClass;struct APICCommonState {Signature · 1 line
2.1.0
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 3 lines · Dr. David Alan Gilbert
OK, let me just check that I get this....
It gets reset to 0 already in
kvm_apic_realize
(before this patch -- after this patch it's only done in reset)
Quoted 1 line
then we do the common init
Then as part of starting up auxiliary processors we send an INIT interrupt, that resets the APIC and...
Quoted 3 lines
that sets it to !bsp - so 1 for most CPUs
then you're adding this so that a specific APIC implementation (kvm) can nobble it back to 0 again?
Yes. That's needed because this APIC implementation does not use the field at all.
Quoted 1 line
and on the load side it's forced to zero by
apic_pre_load.
Yes. That's the common case for the !APIC implementation because it gets to zero as soon as te OS starts.
Paolo
Dr. David Alan Gilbert
Reviewed-byQuoted 18 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 3 lines · Dr. David Alan Gilbert
OK, let me just check that I get this....
It gets reset to 0 already in
kvm_apic_realize(before this patch -- after this patch it's only done in reset)
Quoted 1 line
then we do the common init
Then as part of starting up auxiliary processors we send an INIT interrupt, that resets the APIC and...
Quoted 3 lines
that sets it to !bsp - so 1 for most CPUs
then you're adding this so that a specific APIC implementation (kvm) can nobble it back to 0 again?
Quoted 7 lines
Yes. That's needed because this APIC implementation does not use the field at all.
Quoted 1 line
and on the load side it's forced to zero by
apic_pre_load.Yes. That's the common case for the !APIC implementation because it gets to zero as soon as te OS starts.
OK; yep, that's OK.
Quoted 2 lines
Paolo
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 48 lines · Paolo Bonzini
The
wait_for_sipifield is set back to 1 after an INIT, so it was not effective to reset it inkvm_apic_realize. Introduce a reset callback and resetwait_for_sipithere.Reported-by Igor Mammedov <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/i386/kvm/apic.c | 10 +++++++--- hw/intc/apic_common.c | 5 +++++ include/hw/i386/apic_internal.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-)hw/i386/kvm/apic.c +7
-3@@ -171,12 +171,15 @@ static const MemoryRegionOps kvm_apic_io_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void kvm_apic_realize (DeviceState *dev,Error **errp) +static void kvm_apic_reset (APICCommonState *s) { -APICCommonState *s =APIC_COMMON (dev); -/* Not used by KVM, which uses the CPU mp_state instead. */ s->wait_for_sipi =0 ; +} + +static void kvm_apic_realize (DeviceState *dev,Error **errp) +{ +APICCommonState *s =APIC_COMMON (dev);memory_region_init_io (&s->io_memory,NULL , &kvm_apic_io_ops, s,"kvm-apic-msi" ,APIC_SPACE_SIZE );@@ -191,6 +194,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void *data)APICCommonClass *k =APIC_COMMON_CLASS (klass); k->realize = kvm_apic_realize; + k->reset = kvm_apic_reset; k->set_base = kvm_apic_set_base; k->set_tpr = kvm_apic_set_tpr; k->get_tpr = kvm_apic_get_tpr;hw/intc/apic_common.c +0
-0
hw/intc/apic_common.c bool apic_next_timer(APICCommonState *s, int64_t current_time) · line 184
Quoted 7 lines
hw/intc/apic_common.c +1
-0@@ -178,6 +178,7 @@ bool apic_next_timer(APICCommonState *s, int64_t current_time)void apic_init_reset (DeviceState *dev) {APICCommonState *s =APIC_COMMON (dev); +APICCommonClass *info =APIC_COMMON_GET_CLASS (s);int i;if (!s) {
*** CID 1264327: Dereference before null check (REVERSE_INULL) /hw/intc/apic_common.c: 184 in apic_init_reset()
178 void apic_init_reset(DeviceState *dev)
179 {
180 APICCommonState *s = APIC_COMMON(dev); 181 APICCommonClass *info = APIC_COMMON_GET_CLASS(s); 182 int i;
183
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
CID 1264327: Dereference before null check (
REVERSE_INULL) Null-checking "s" suggests that it may be null, but it has
already been dereferenced on all paths leading to the check.
184 if (!s) {
185 return;
186 } 187 s->tpr = 0; 188 s->spurious_vec = 0xff; 189 s->log_dest = 0;
[...]