Skip to contentSkip to conversation

loadvm and APIC

Qemu-devel malc 3 participants 6 messages Jun 17, 2008 – Jun 18, 2008

lore
Share & tools
lore

malc

author
#0 lore raw

Here's the scenario:

1. Start QEMU and boot Linux capable of using APIC
2. Save the VM state
3. Exit QEMU
4. Start QEMU and loadvm

Kernel instantly panics. Here's why:

Upon starting eventually following happens:
... -> pc_init -> ... -> pit_irq_timer_update
-> qemu_set_irq -> ...

    -> apic_local_deliver -> cpu_interrupt(CPU_INTERRUPT_HARD)

Then qemu_loadvm_state begins executing load handlers eventually coming to apic_load which loads the state from the storage overriding all the effects of apic_local_deliver, in the meantime env->interrupt_request stays the same.

Then cpu_exec is entered and it arrives at line 399 where cpu_get_pic_interrupt calls apic_get_interrupt which returns -1, this bogus interrupt number is then passed to do_interrupt and here it is finally caught by a IDT limit check at line 649, general protection fault is generated and kernel inside the VM panics.

Hence:

vl.c +1 -0
index d759fde..11827ba 100644
@@ -6296,6 +6296,7 @@ void do_loadvm(const char *name)
         goto the_end;
     }
     ret = qemu_loadvm_state(f);
+    first_cpu->interrupt_request = 0;
     qemu_fclose(f);
     if (ret < 0) {
         term_printf("Error %d while loading VM state\n", ret);

Okay to commit?

Signature · 1 line
mailto:[email protected]
#1 lore raw
Quoted 40 lines · malc

Here's the scenario:

1. Start QEMU and boot Linux capable of using APIC
2. Save the VM state
3. Exit QEMU
4. Start QEMU and loadvm

Kernel instantly panics. Here's why:

Upon starting eventually following happens:
... -> pc_init -> ... -> pit_irq_timer_update
-> qemu_set_irq -> ...

    -> apic_local_deliver -> cpu_interrupt(CPU_INTERRUPT_HARD)

Then qemu_loadvm_state begins executing load handlers eventually coming to apic_load which loads the state from the storage overriding all the effects of apic_local_deliver, in the meantime env->interrupt_request stays the same.

Then cpu_exec is entered and it arrives at line 399 where cpu_get_pic_interrupt calls apic_get_interrupt which returns -1, this bogus interrupt number is then passed to do_interrupt and here it is finally caught by a IDT limit check at line 649, general protection fault is generated and kernel inside the VM panics.

Hence:

vl.c +1 -0
index d759fde..11827ba 100644
@@ -6296,6 +6296,7 @@ void do_loadvm(const char *name)
         goto the_end;
     }
     ret = qemu_loadvm_state(f);
+    first_cpu->interrupt_request = 0;
     qemu_fclose(f);
     if (ret < 0) {
         term_printf("Error %d while loading VM state\n", ret);
Quoted 1 line

Okay to commit?

That is basically
http://permalink.gmane.org/gmane.comp.emulators.qemu/26215, which I would prefer.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 9 lines · malc
Quoted 3 lines · Jan Kiszka
Quoted 2 lines · malc

Here's the scenario:

[..snip..]

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

That is basically
http://permalink.gmane.org/gmane.comp.emulators.qemu/26215, which I would prefer.

Yes, i never paid enough attention to that patch, and it does indeed look better.

No. This is a hack which does not fix the real problem. At least saving and restoring "interrupt_pending" would bring us closer to a better solution.

Fabrice.

#4 lore raw
Quoted 11 lines · Fabrice Bellard
Quoted 10 lines · malc
Quoted 3 lines · Jan Kiszka
Quoted 2 lines · malc

Here's the scenario:

[..snip..]

Quoted 3 lines

That is basically
http://permalink.gmane.org/gmane.comp.emulators.qemu/26215, which I would prefer.

Quoted 6 lines
Quoted 2 lines

Yes, i never paid enough attention to that patch, and it does indeed look better.

No. This is a hack which does not fix the real problem. At least saving and restoring "interrupt_pending" would bring us closer to a better solution.

No problem, patch for archs that care about cpu state saving is on the way. I would just have appreciated receiving some indication how you'd like to see that bug being addressed earlier.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
author
#5 lore raw
In reply to Fabrice Bellard
Quoted 14 lines · Fabrice Bellard
Quoted 13 lines · malc
Quoted 3 lines · Jan Kiszka
Quoted 2 lines · malc

Here's the scenario:

[..snip..]

Quoted 4 lines

That is basically
http://permalink.gmane.org/gmane.comp.emulators.qemu/26215, which I would prefer.

Quoted 6 lines
Quoted 2 lines

Yes, i never paid enough attention to that patch, and it does indeed look better.

No. This is a hack which does not fix the real problem. At least saving and restoring "interrupt_pending" would bring us closer to a better solution.

Have you read my mail? It's pit/serlial vs [a]pic init/loadvm interaction which is broken, real fix would involve fixing this and i don't see clean way of doing that. When using plain i8259 guest doesn't panic only because i8259 emits a spurious IRQ (and APIC does not).

Signature · 1 line
mailto:[email protected]