From patchwork Fri Jun 17 13:13:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 891322 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 p5HDLga7006057 for ; Fri, 17 Jun 2011 13:21:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758959Ab1FQNVk (ORCPT ); Fri, 17 Jun 2011 09:21:40 -0400 Received: from mail-qw0-f46.google.com ([209.85.216.46]:64144 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758935Ab1FQNVj (ORCPT ); Fri, 17 Jun 2011 09:21:39 -0400 Received: by qwk3 with SMTP id 3so1130927qwk.19 for ; Fri, 17 Jun 2011 06:21:38 -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=IcwkbhlHz9RL538FR/PRgHBJuDzyFCIkxKACpJKPSFk=; b=TVVn5f/oYupVl/SWdfoZIKQExEzls+DY9d9WmD1rHQ1XrivE48nlVo32/LEZqYjsM8 S7Dd37RMI6SImuVmdw5/GnMRNbj36dwrnSt66cmfXHgDbuQUjwdZQJs4+GwAlUy2t6ct mvGURCamHDrQgzL0J9/1BsInBV6IhrZOCVT5I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=bNfTlLn9n5OMXYkRr3M1QWFJJ6g6Z1DPdC6+poSagrMG2fkrIXv2m+8jJsz7CJMuFK TW4iJWlKOeDcVZ/KSDHKfliqdtciEZg6zYJlwefDzjFBS4WyzJBiAHG02vTwvTMwoSqP LZfmSnlvF9+YV+g3zdggp49SmI6Oz1lKK/grk= Received: by 10.229.26.130 with SMTP id e2mr1700379qcc.241.1308316898367; Fri, 17 Jun 2011 06:21:38 -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 p10sm1893519qcu.37.2011.06.17.06.21.36 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 06:21:37 -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] kvm tools: Implement keyboard reset method Date: Fri, 17 Jun 2011 09:13:29 -0400 Message-Id: <1308316409-9825-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 13:21:43 +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 | 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); }