From patchwork Sun Jul 22 16:29:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1224741 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 14CF73FC5A for ; Sun, 22 Jul 2012 16:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752118Ab2GVQa3 (ORCPT ); Sun, 22 Jul 2012 12:30:29 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:42019 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045Ab2GVQ3t (ORCPT ); Sun, 22 Jul 2012 12:29:49 -0400 Received: by wibhq12 with SMTP id hq12so1849948wib.1 for ; Sun, 22 Jul 2012 09:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=uRKgiCFDvNytx0UwLAv9KSU5WpxLs5t9imM2SEo54fc=; b=F7Gfi5YpyWcHdIc/+BwU53EHhoS5GKFtClKC+irjG7fuUg93teEOXH21Gp0rdAUPlw AMnJeTZSxw4hPO9z66L6cC8jXG+I8hrh9OqIgF+kAfeYY0MICaYKSnOOOxCkTsi/TthF vHgpKu0gDwJ/pwatRw4AYm4xHtq3KPXzigBRqkh8d17gMavo5WHZ3CCUpV3Xz+zcSD4n VNYXBi3X66CrPbpDlag1joQIU8B1UaKOfMQiwJq4M/wb8qAvMbDWqxQb7ydiAM27ZzhI im6rzuJ7c/glETCyJ/VFkcddtBxhdM5RNspl1eScn+5UjwurbbufJrkGF2IQyOyBeD/S btqw== Received: by 10.216.138.73 with SMTP id z51mr2682017wei.39.1342974588226; Sun, 22 Jul 2012 09:29:48 -0700 (PDT) Received: from localhost.localdomain ([217.203.160.170]) by mx.google.com with ESMTPS id ep14sm17495905wid.0.2012.07.22.09.29.44 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 Jul 2012 09:29:47 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org, mingo@elte.hu, gorcunov@gmail.com Cc: kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: support injecting arbitrary sysrqs Date: Sun, 22 Jul 2012 18:29:51 +0200 Message-Id: <1342974594-31317-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1342974594-31317-1-git-send-email-levinsasha928@gmail.com> References: <1342974594-31317-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add support to 'lkvm debug' to inject arbitrary sysrqs using a new '-s ' argument. Signed-off-by: Sasha Levin --- tools/kvm/builtin-debug.c | 7 +++++++ tools/kvm/builtin-run.c | 5 ++++- tools/kvm/hw/serial.c | 7 +++---- tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/builtin-debug.h | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c index 20e27ff..4ae51d2 100644 --- a/tools/kvm/builtin-debug.c +++ b/tools/kvm/builtin-debug.c @@ -16,6 +16,7 @@ static bool all; static int nmi = -1; static bool dump; static const char *instance_name; +static const char *sysrq; static const char * const debug_usage[] = { "lkvm debug [--all] [-n name] [-d] [-m vcpu]", @@ -26,6 +27,7 @@ static const struct option debug_options[] = { OPT_GROUP("General options:"), OPT_BOOLEAN('d', "dump", &dump, "Generate a debug dump from guest"), OPT_INTEGER('m', "nmi", &nmi, "Generate NMI on VCPU"), + OPT_STRING('s', "sysrq", &sysrq, "sysrq", "Inject a sysrq"), OPT_GROUP("Instance options:"), OPT_BOOLEAN('a', "all", &all, "Debug all instances"), OPT_STRING('n', "name", &instance_name, "name", "Instance name"), @@ -61,6 +63,11 @@ static int do_debug(const char *name, int sock) cmd.cpu = nmi; } + if (sysrq) { + cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_SYSRQ; + cmd.sysrq = sysrq[0]; + } + r = kvm_ipc__send_msg(sock, KVM_IPC_DEBUG, sizeof(cmd), (u8 *)&cmd); if (r < 0) return r; diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index a120fe2..750d30c 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -557,6 +557,9 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) dbg_type = params->dbg_type; vcpu = params->cpu; + if (dbg_type & KVM_DEBUG_CMD_TYPE_SYSRQ) + serial8250__inject_sysrq(kvm, params->sysrq); + if (dbg_type & KVM_DEBUG_CMD_TYPE_NMI) { if ((int)vcpu >= kvm->nrcpus) return; @@ -589,7 +592,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) close(fd); - serial8250__inject_sysrq(kvm); + serial8250__inject_sysrq(kvm, 'p'); } static void handle_sigalrm(int sig) diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c index 852aea4..956307c 100644 --- a/tools/kvm/hw/serial.c +++ b/tools/kvm/hw/serial.c @@ -153,14 +153,13 @@ static void serial8250_update_irq(struct kvm *kvm, struct serial8250_device *dev } #define SYSRQ_PENDING_NONE 0 -#define SYSRQ_PENDING_BREAK 1 static int sysrq_pending; static void serial8250__sysrq(struct kvm *kvm, struct serial8250_device *dev) { dev->lsr |= UART_LSR_DR | UART_LSR_BI; - dev->rxbuf[dev->rxcnt++] = 'p'; + dev->rxbuf[dev->rxcnt++] = sysrq_pending; sysrq_pending = SYSRQ_PENDING_NONE; } @@ -219,9 +218,9 @@ void serial8250__update_consoles(struct kvm *kvm) } } -void serial8250__inject_sysrq(struct kvm *kvm) +void serial8250__inject_sysrq(struct kvm *kvm, char sysrq) { - sysrq_pending = SYSRQ_PENDING_BREAK; + sysrq_pending = sysrq; } static struct serial8250_device *find_device(u16 port) diff --git a/tools/kvm/include/kvm/8250-serial.h b/tools/kvm/include/kvm/8250-serial.h index df8ef53..e954551 100644 --- a/tools/kvm/include/kvm/8250-serial.h +++ b/tools/kvm/include/kvm/8250-serial.h @@ -6,6 +6,6 @@ struct kvm; int serial8250__init(struct kvm *kvm); int serial8250__exit(struct kvm *kvm); void serial8250__update_consoles(struct kvm *kvm); -void serial8250__inject_sysrq(struct kvm *kvm); +void serial8250__inject_sysrq(struct kvm *kvm, char sysrq); #endif /* KVM__8250_SERIAL_H */ diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h index 6105a8c..efa0268 100644 --- a/tools/kvm/include/kvm/builtin-debug.h +++ b/tools/kvm/include/kvm/builtin-debug.h @@ -6,10 +6,12 @@ #define KVM_DEBUG_CMD_TYPE_DUMP (1 << 0) #define KVM_DEBUG_CMD_TYPE_NMI (1 << 1) +#define KVM_DEBUG_CMD_TYPE_SYSRQ (1 << 2) struct debug_cmd_params { u32 dbg_type; u32 cpu; + char sysrq; }; int kvm_cmd_debug(int argc, const char **argv, const char *prefix);