kvm tools: Implement keyboard reset method
PATCH 1/1 kvm tools: Implement keyboard reset method
Implement the keyboard reset method which allows guest kernel to reboot the guest using the keyboard controller.
This will allow guest kernel to reboot the guest when it needs to, for example - kernel panic (when passing "panic=1" as kernel parameter).
Based on Pekka Enberg's patch.
--- tools/kvm/hw/i8042.c | 8 ++++++-- tools/kvm/include/kvm/kvm.h | 2 ++ tools/kvm/kvm-cpu.c | 2 +- tools/kvm/kvm-run.c | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-)
tools/kvm/hw/i8042.c +6 -2
@@ -30,6 +30,7 @@#define I8042_CMD_AUX_TEST 0xA9#define I8042_CMD_AUX_DISABLE 0xA7#define I8042_CMD_AUX_ENABLE 0xA8 +#define I8042_CMD_SYSTEM_RESET 0xFE#define RESPONSE_ACK 0xFA
@@ -138,7 +139,7 @@ void kbd_queue(u8 c)kbd_update_irq (); } -static void kbd_write_command (u8 val) +static void kbd_write_command (struct kvm *kvm,u8 val) {switch (val) {case I8042_CMD_CTL_RCTR :
@@ -159,6 +160,9 @@ static void kbd_write_command(u8 val)case I8042_CMD_AUX_ENABLE : state.mode &= ~MODE_DISABLE_AUX ;break ; +case I8042_CMD_SYSTEM_RESET : + kvm->stopped = true; +break ;default :break ; }
@@ -314,7 +318,7 @@ static bool kbd_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *dataswitch (port) {case I8042_COMMAND_REG : {u8 value =ioport__read8 (data); -kbd_write_command (value); +kbd_write_command (kvm, value);break ; }case I8042_DATA_REG : {
tools/kvm/include/kvm/kvm.h +2 -0
@@ -41,6 +41,8 @@ struct kvm {const char *vmlinux;struct disk_image **disks;int nr_disks; + +bool stopped; };struct kvm *kvm__init (const char *kvm_dev,u64 ram_size);
tools/kvm/kvm-cpu.c +1 -1
@@ -433,7 +433,7 @@ int kvm_cpu__start(struct kvm_cpu *cpu)kvm_cpu__setup_cpuid (cpu);kvm_cpu__reset_vcpu (cpu); -for (;;) { +while (!cpu->kvm->stopped) {if (cpu->paused) {kvm__notify_paused (); cpu->paused =0 ;
tools/kvm/kvm-run.c +2 -2
@@ -648,17 +648,17 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)kvm__init_ram (kvm); +kbd__init (kvm); +if (vnc || sdl) fb =vesa__init (kvm);if (vnc) { -kbd__init (kvm);if (fb)vnc__init (fb); }if (sdl) { -kbd__init (kvm);if (fb)sdl__init (fb); }
Signature · 1 line
1.7.5.3
Quoted 9 lines · Sasha Levin
Implement the keyboard reset method which allows guest kernel to reboot the guest using the keyboard controller.
This will allow guest kernel to reboot the guest when it needs to, for example - kernel panic (when passing "panic=1" as kernel parameter).
Based on Pekka Enberg's patch.
Signed-off-by Sasha Levin <[email protected]>
Does this work for you? For me it get stuck with this:
[ 0.833234] Rebooting in 1 seconds.. # # vCPU #0's dump: #
Registers:
----------
rip: ffffffff8106130a rsp: ffff880013c03f88 flags: 0000000000000046 rax: ffffffff81c15300 rbx: ffffffff81c00010 rcx: 0000000031798af5 rdx: 0000000000000000 rsi: 00000000000000ff rdi: 00000000000000f0 rbp: ffff880013c03f88 r8: 0000000000000000 r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000001 r12: 0000000000000000 r13: 0000000000000000 r14: ffffffffffffffff r15: 0000000000013d70 cr0: 000000008005003b cr2: 0000000000000000 cr3: 0000000001c03000 cr4: 00000000000006f0 cr8: 0000000000000000
Segment registers:
------------------
register selector base limit type p dpl db s l g avl cs 0010 0000000000000000 ffffffff 0b 1 0 0 1 1 1 0 ss 0018 0000000000000000 ffffffff 03 1 0 1 1 0 1 0 ds 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 es 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 fs 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 gs 0000 ffff880013c00000 ffffffff 00 0 0 0 0 0 0 0 tr 0040 ffff880013c0ec00 00002087 0b 1 0 0 0 0 0 0 ldt 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 gdt ffff880013c04000 0000007f idt ffffffff81da7000 00000fff
APIC:
-----
efer: 0000000000000d01 apic base: 00000000fee00900 nmi: enabled
Interrupt bitmap:
-----------------
0000000000000000 0000000000000000 0000000000000000 0000000000000000
Code:
-----
rip: [<ffffffff8106130a>] <unknown>
Stack: ------
which seems to be in native_halt:
ffffffff81061300 t native_haltffffffff81061310 t native_clts
Quoted 57 lines · Pekka Enberg
Quoted 9 lines · Sasha Levin
Implement the keyboard reset method which allows guest kernel to reboot the guest using the keyboard controller.
This will allow guest kernel to reboot the guest when it needs to, for example - kernel panic (when passing "panic=1" as kernel parameter).
Based on Pekka Enberg's patch.
Signed-off-by Sasha Levin <[email protected]>Does this work for you? For me it get stuck with this:
[ 0.833234] Rebooting in 1 seconds.. # # vCPU #0's dump: #Registers:
----------rip: ffffffff8106130a rsp: ffff880013c03f88 flags: 0000000000000046 rax: ffffffff81c15300 rbx: ffffffff81c00010 rcx: 0000000031798af5 rdx: 0000000000000000 rsi: 00000000000000ff rdi: 00000000000000f0 rbp: ffff880013c03f88 r8: 0000000000000000 r9: 0000000000000000 r10: 0000000000000000 r11: 0000000000000001 r12: 0000000000000000 r13: 0000000000000000 r14: ffffffffffffffff r15: 0000000000013d70 cr0: 000000008005003b cr2: 0000000000000000 cr3: 0000000001c03000 cr4: 00000000000006f0 cr8: 0000000000000000Segment registers:
------------------register selector base limit type p dpl db s l g avl cs 0010 0000000000000000 ffffffff 0b 1 0 0 1 1 1 0 ss 0018 0000000000000000 ffffffff 03 1 0 1 1 0 1 0 ds 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 es 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 fs 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 gs 0000 ffff880013c00000 ffffffff 00 0 0 0 0 0 0 0 tr 0040 ffff880013c0ec00 00002087 0b 1 0 0 0 0 0 0 ldt 0000 0000000000000000 ffffffff 00 0 0 0 0 0 0 0 gdt ffff880013c04000 0000007f idt ffffffff81da7000 00000fffAPIC:
-----
efer:0000000000000d01apic base:00000000fee00900nmi: enabledInterrupt bitmap:
-----------------
0000000000000000 0000000000000000 0000000000000000 0000000000000000Code:
-----
rip: [<ffffffff8106130a>] <unknown>
Quoted 8 lines
Stack: ------which seems to be in
native_halt:
ffffffff81061300tnative_haltffffffff81061310tnative_clts
Yes:
[ 1.844359] Rebooting in 1 seconds.. # KVM session ended normally.
Can you try passing "reboot=k" as an additional kernel parameter and see if it works then? Maybe keyboard reset isn't set as default.
Signature · 1 line
Sasha.
Quoted 6 lines · Sasha Levin
Yes:
[ 1.844359] Rebooting in 1 seconds.. # KVM session ended normally.Can you try passing "reboot=k" as an additional kernel parameter and see if it works then? Maybe keyboard reset isn't set as default.
Yup, that works. I'll add it as default kernel parameter too.
Quoted 6 lines · Sasha Levin
Yes:
[ 1.844359] Rebooting in 1 seconds.. # KVM session ended normally.Can you try passing "reboot=k" as an additional kernel parameter and see if it works then? Maybe keyboard reset isn't set as default.
It still doesn't work reliably. The problem is that if CPU1, for example, receives the ioport write, we'll wait for CPU0 forever.
Pekka