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 <levinsasha928@xxxxxxxxx> --- 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(-) diff --git a/tools/kvm/hw/i8042.c b/tools/kvm/hw/i8042.c index 21a779e..0bcf7e6 100644 --- a/tools/kvm/hw/i8042.c +++ b/tools/kvm/hw/i8042.c @@ -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 *data switch (port) { case I8042_COMMAND_REG: { u8 value = ioport__read8(data); - kbd_write_command(value); + kbd_write_command(kvm, value); break; } case I8042_DATA_REG: { diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 7d90d35..d647ecf 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -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); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index 1fb1c74..35b3bd7 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -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; diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 6ad55aa..1310e39 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -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); } -- 1.7.5.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html