From patchwork Fri Jun 17 20:41:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 892482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5HKhmnj014810 for ; Fri, 17 Jun 2011 20:43:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933118Ab1FQUnq (ORCPT ); Fri, 17 Jun 2011 16:43:46 -0400 Received: from mail-qy0-f174.google.com ([209.85.216.174]:43785 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932493Ab1FQUnp (ORCPT ); Fri, 17 Jun 2011 16:43:45 -0400 Received: by qyk29 with SMTP id 29so673662qyk.19 for ; Fri, 17 Jun 2011 13:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=yY3tR6qjiAv088YEmSVYUO/r1NrkzTiXQwY7pxC0RAQ=; b=hmwd7QwNUXPI6HgRwQvqILY5q4xmTyrb6avWJp/AD33s9UefeZmlxLd4xYFHlz5tCm XKBT2AgCYgWAFkysBTuCdMyhWbHdytmUorMq6qXUYTuRLbJ5+7b7tDdd9XpRUwEMoTRz Jjrz5rVXD6VTuWxmsyNwN85j322gA/LQEsfgU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=dmhxAM+iLs2Ktwapp7dVflK3MrGiF6gytIVMU3pAvB44kCIHsMoriOKbO7qS7FSyag qe6fv+y2sMZyFGlgskSkl7jp8Qnf4chFfYgrp3EDdqYzts/DBI4r+jjAqgMztOTG0cRI iPs0/gWhyEfcxU67ubvJO6uVHCDqu5xRettZw= Received: by 10.229.63.69 with SMTP id a5mr2220996qci.94.1308343424624; Fri, 17 Jun 2011 13:43:44 -0700 (PDT) Received: from localhost.localdomain (c-71-232-157-243.hsd1.ma.comcast.net [71.232.157.243]) by mx.google.com with ESMTPS id g1sm2180020qck.44.2011.06.17.13.43.43 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 13:43:44 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v2] kvm tools: Implement keyboard reset method Date: Fri, 17 Jun 2011 16:41:28 -0400 Message-Id: <1308343288-17239-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 17 Jun 2011 20:43:48 +0000 (UTC) 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 --- tools/kvm/hw/i8042.c | 9 +++++++-- tools/kvm/include/kvm/kvm-cpu.h | 1 + tools/kvm/kvm-cpu.c | 8 +++++++- tools/kvm/kvm-run.c | 6 +++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/kvm/hw/i8042.c b/tools/kvm/hw/i8042.c index 21a779e..262368e 100644 --- a/tools/kvm/hw/i8042.c +++ b/tools/kvm/hw/i8042.c @@ -5,6 +5,7 @@ #include "kvm/term.h" #include "kvm/kvm.h" #include "kvm/i8042.h" +#include "kvm/kvm-cpu.h" #include @@ -30,6 +31,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 +140,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 +161,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_cpu__reboot(); + break; default: break; } @@ -314,7 +319,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-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h index 1eb4a52..95f3f9d 100644 --- a/tools/kvm/include/kvm/kvm-cpu.h +++ b/tools/kvm/include/kvm/kvm-cpu.h @@ -34,6 +34,7 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu); void kvm_cpu__setup_cpuid(struct kvm_cpu *vcpu); void kvm_cpu__enable_singlestep(struct kvm_cpu *vcpu); void kvm_cpu__run(struct kvm_cpu *vcpu); +void kvm_cpu__reboot(void); int kvm_cpu__start(struct kvm_cpu *cpu); void kvm_cpu__show_code(struct kvm_cpu *vcpu); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index 1fb1c74..f57d42e 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -16,6 +16,7 @@ #define PAGE_SIZE (sysconf(_SC_PAGE_SIZE)) +extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS]; extern __thread struct kvm_cpu *current_kvm_cpu; static inline bool is_in_protected_mode(struct kvm_cpu *vcpu) @@ -393,7 +394,7 @@ void kvm_cpu__run(struct kvm_cpu *vcpu) static void kvm_cpu_signal_handler(int signum) { if (signum == SIGKVMEXIT) { - if (current_kvm_cpu->is_running) { + if (current_kvm_cpu && current_kvm_cpu->is_running) { current_kvm_cpu->is_running = false; pthread_kill(pthread_self(), SIGKVMEXIT); } @@ -418,6 +419,11 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu) } } +void kvm_cpu__reboot(void) +{ + pthread_kill(kvm_cpus[0]->thread, SIGKVMEXIT); +} + int kvm_cpu__start(struct kvm_cpu *cpu) { sigset_t sigset; diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 6ad55aa..c66730f 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -557,7 +557,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) vidmode = 0; memset(real_cmdline, 0, sizeof(real_cmdline)); - strcpy(real_cmdline, "notsc noapic noacpi pci=conf1"); + strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k"); if (vnc || sdl) { strcat(real_cmdline, " video=vesafb console=tty0"); } else @@ -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); }