From patchwork Fri Apr 8 12:44:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 694511 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p38Cj1wp020857 for ; Fri, 8 Apr 2011 12:45:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756614Ab1DHMo4 (ORCPT ); Fri, 8 Apr 2011 08:44:56 -0400 Received: from filtteri6.pp.htv.fi ([213.243.153.189]:42659 "EHLO filtteri6.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756550Ab1DHMoy (ORCPT ); Fri, 8 Apr 2011 08:44:54 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri6.pp.htv.fi (Postfix) with ESMTP id 4905F62A002; Fri, 8 Apr 2011 15:44:53 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp4.welho.com ([213.243.153.38]) by localhost (filtteri6.pp.htv.fi [213.243.153.189]) (amavisd-new, port 10024) with ESMTP id 2kwYQm4OFL33; Fri, 8 Apr 2011 15:44:53 +0300 (EEST) Received: from localhost.localdomain (cs181148025.pp.htv.fi [82.181.148.25]) by smtp4.welho.com (Postfix) with ESMTP id E7D545BC015; Fri, 8 Apr 2011 15:44:52 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Asias He , Cyrill Gorcunov , Ingo Molnar Subject: [PATCH 2/2] kvm tools: Send SysRq-P to guest kernel on SIGQUIT Date: Fri, 8 Apr 2011 15:44:51 +0300 Message-Id: <1302266691-8066-2-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1302266691-8066-1-git-send-email-penberg@kernel.org> References: <1302266691-8066-1-git-send-email-penberg@kernel.org> 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 (demeter1.kernel.org [140.211.167.41]); Fri, 08 Apr 2011 12:45:01 +0000 (UTC) This patch makes SIGQUIT to the host hypervisor send 'SysRq-P' to the guest kernel via 8250 serial console to make debugging stuck guests easier. Cc: Asias He Cc: Cyrill Gorcunov Cc: Ingo Molnar Signed-off-by: Pekka Enberg --- tools/kvm/8250-serial.c | 33 +++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/8250-serial.h | 1 + tools/kvm/main.c | 1 + 3 files changed, 35 insertions(+), 0 deletions(-) diff --git a/tools/kvm/8250-serial.c b/tools/kvm/8250-serial.c index e92ff89..639afb2 100644 --- a/tools/kvm/8250-serial.c +++ b/tools/kvm/8250-serial.c @@ -53,6 +53,29 @@ static struct serial8250_device devices[] = { }, }; +#define SYSRQ_PENDING_NONE 0 +#define SYSRQ_PENDING_BREAK 1 +#define SYSRQ_PENDING_CMD 2 + +static int sysrq_pending; + +static void serial8250__sysrq(struct kvm *self, struct serial8250_device *dev) +{ + switch (sysrq_pending) { + case SYSRQ_PENDING_BREAK: + dev->lsr |= UART_LSR_DR | UART_LSR_BI; + + sysrq_pending = SYSRQ_PENDING_CMD; + break; + case SYSRQ_PENDING_CMD: + dev->rbr = 'p'; + dev->lsr |= UART_LSR_DR; + + sysrq_pending = SYSRQ_PENDING_NONE; + break; + } +} + static void serial8250__receive(struct kvm *self, struct serial8250_device *dev) { int c; @@ -60,6 +83,11 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev) if (dev->lsr & UART_LSR_DR) return; + if (sysrq_pending) { + serial8250__sysrq(self, dev); + return; + } + if (!term_readable(CONSOLE_8250)) return; @@ -94,6 +122,11 @@ void serial8250__inject_interrupt(struct kvm *self) } } +void serial8250__inject_sysrq(struct kvm *self) +{ + sysrq_pending = SYSRQ_PENDING_BREAK; +} + static struct serial8250_device *find_device(uint16_t port) { unsigned int i; diff --git a/tools/kvm/include/kvm/8250-serial.h b/tools/kvm/include/kvm/8250-serial.h index 73ed078..7a6d3f3 100644 --- a/tools/kvm/include/kvm/8250-serial.h +++ b/tools/kvm/include/kvm/8250-serial.h @@ -5,5 +5,6 @@ struct kvm; void serial8250__init(struct kvm *kvm); void serial8250__inject_interrupt(struct kvm *kvm); +void serial8250__inject_sysrq(struct kvm *kvm); #endif /* KVM__8250_SERIAL_H */ diff --git a/tools/kvm/main.c b/tools/kvm/main.c index 6aa2534..d8f0c09 100644 --- a/tools/kvm/main.c +++ b/tools/kvm/main.c @@ -38,6 +38,7 @@ static void handle_sigint(int sig) static void handle_sigquit(int sig) { + serial8250__inject_sysrq(kvm); kvm__show_registers(kvm); kvm__show_code(kvm); kvm__show_page_tables(kvm);