* [PATCH 1/2] kvm tools: Clean up 'kvm debug'
@ 2011-12-12 9:19 Sasha Levin
2011-12-12 9:19 ` [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using " Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2011-12-12 9:19 UTC (permalink / raw)
To: penberg; +Cc: mingo, gorcunov, asias.hejun, kvm, Sasha Levin
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-debug.c | 13 +++++++------
tools/kvm/builtin-run.c | 7 ++++---
tools/kvm/include/kvm/builtin-debug.h | 13 +++++++++----
3 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c
index eee26c3..292172a 100644
--- a/tools/kvm/builtin-debug.c
+++ b/tools/kvm/builtin-debug.c
@@ -19,16 +19,17 @@ static bool dump;
static const char *instance_name;
static const char * const debug_usage[] = {
- "kvm debug [--all] [-n name]",
+ "kvm debug [--all] [-n name] [-d] [-m vcpu]",
NULL
};
static const struct option debug_options[] = {
OPT_GROUP("General options:"),
- OPT_BOOLEAN('a', "all", &all, "Debug all instances"),
- OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
OPT_BOOLEAN('d', "dump", &dump, "Generate a debug dump from guest"),
OPT_INTEGER('m', "nmi", &nmi, "Generate NMI on VCPU"),
+ OPT_GROUP("Instance options:"),
+ OPT_BOOLEAN('a', "all", &all, "Debug all instances"),
+ OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
OPT_END()
};
@@ -54,11 +55,11 @@ static int do_debug(const char *name, int sock)
int r;
if (dump)
- cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_DUMP;
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_DUMP;
if (nmi != -1) {
- cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_NMI;
- cmd.cpu = nmi;
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_NMI;
+ cmd.params.cpu = nmi;
}
r = xwrite(sock, &cmd, sizeof(cmd));
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 4411c9e..5045278 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -510,11 +510,12 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
{
int i;
- u32 dbg_type = *(u32 *)msg;
- int vcpu = *(((u32 *)msg) + 1);
+ struct debug_cmd_params *params = (void *)msg;
+ u32 dbg_type = params->dbg_type;
+ u32 vcpu = params->cpu;
if (dbg_type & KVM_DEBUG_CMD_TYPE_NMI) {
- if (vcpu >= kvm->nrcpus)
+ if ((int)vcpu >= kvm->nrcpus)
return;
kvm_cpus[vcpu]->needs_nmi = 1;
diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h
index b24b501..0aafef9 100644
--- a/tools/kvm/include/kvm/builtin-debug.h
+++ b/tools/kvm/include/kvm/builtin-debug.h
@@ -3,15 +3,20 @@
#include <linux/types.h>
-struct debug_cmd {
- u32 type;
- u32 len;
- u32 dbg_type;
#define KVM_DEBUG_CMD_TYPE_DUMP (1 << 0)
#define KVM_DEBUG_CMD_TYPE_NMI (1 << 1)
+
+struct debug_cmd_params {
+ u32 dbg_type;
u32 cpu;
};
+struct debug_cmd {
+ u32 type;
+ u32 len;
+ struct debug_cmd_params params;
+};
+
int kvm_cmd_debug(int argc, const char **argv, const char *prefix);
void kvm_debug_help(void);
--
1.7.8
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
2011-12-12 9:19 [PATCH 1/2] kvm tools: Clean up 'kvm debug' Sasha Levin
@ 2011-12-12 9:19 ` Sasha Levin
2011-12-12 21:33 ` Pekka Enberg
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2011-12-12 9:19 UTC (permalink / raw)
To: penberg; +Cc: mingo, gorcunov, asias.hejun, kvm, Sasha Levin
Add options to assert and deassert IRQs using 'kvm debug'. For example, to
assert IRQ4 in guest 'my_instance':
vm debug -n my_instance --assert_irq 4
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-debug.c | 19 +++++++++++++++++++
tools/kvm/builtin-run.c | 12 ++++++++++++
tools/kvm/include/kvm/builtin-debug.h | 5 +++++
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c
index 292172a..37aed61 100644
--- a/tools/kvm/builtin-debug.c
+++ b/tools/kvm/builtin-debug.c
@@ -15,6 +15,7 @@
static bool all;
static int instance;
static int nmi = -1;
+static int assert_irq = -1, deassert_irq = -1, trigger_irq = -1, rtrigger_irq = -1;
static bool dump;
static const char *instance_name;
@@ -27,6 +28,10 @@ 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_INTEGER('\0', "assert_irq", &assert_irq, "Assert an IRQ"),
+ OPT_INTEGER('\0', "deassert_irq", &deassert_irq, "Deassert an IRQ"),
+ OPT_INTEGER('\0', "trigger_irq", &trigger_irq, "Trigger an IRQ"),
+ OPT_INTEGER('\0', "rtrigger_irq", &rtrigger_irq, "Reverse trigger an IRQ"),
OPT_GROUP("Instance options:"),
OPT_BOOLEAN('a', "all", &all, "Debug all instances"),
OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
@@ -62,6 +67,20 @@ static int do_debug(const char *name, int sock)
cmd.params.cpu = nmi;
}
+ if (assert_irq != -1) {
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_ASRT;
+ cmd.params.irq = assert_irq;
+ } else if (deassert_irq != -1) {
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_DSRT;
+ cmd.params.irq = deassert_irq;
+ } else if (trigger_irq != -1) {
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_TRG;
+ cmd.params.irq = trigger_irq;
+ } else if (rtrigger_irq != -1) {
+ cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_RTRG;
+ cmd.params.irq = rtrigger_irq;
+ }
+
r = xwrite(sock, &cmd, sizeof(cmd));
if (r < 0)
return r;
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 5045278..21af78a 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -513,6 +513,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
struct debug_cmd_params *params = (void *)msg;
u32 dbg_type = params->dbg_type;
u32 vcpu = params->cpu;
+ u32 irq = params->irq;
if (dbg_type & KVM_DEBUG_CMD_TYPE_NMI) {
if ((int)vcpu >= kvm->nrcpus)
@@ -522,6 +523,17 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
pthread_kill(kvm_cpus[vcpu]->thread, SIGUSR1);
}
+ if (dbg_type & KVM_DEBUG_CMD_TYPE_ASRT)
+ kvm__irq_line(kvm, irq, 1);
+ else if (dbg_type & KVM_DEBUG_CMD_TYPE_DSRT)
+ kvm__irq_line(kvm, irq, 0);
+ else if (dbg_type & KVM_DEBUG_CMD_TYPE_TRG)
+ kvm__irq_trigger(kvm, irq);
+ else {
+ kvm__irq_line(kvm, irq, 1);
+ kvm__irq_line(kvm, irq, 0);
+ }
+
if (!(dbg_type & KVM_DEBUG_CMD_TYPE_DUMP))
return;
diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h
index 0aafef9..86dc5df 100644
--- a/tools/kvm/include/kvm/builtin-debug.h
+++ b/tools/kvm/include/kvm/builtin-debug.h
@@ -5,10 +5,15 @@
#define KVM_DEBUG_CMD_TYPE_DUMP (1 << 0)
#define KVM_DEBUG_CMD_TYPE_NMI (1 << 1)
+#define KVM_DEBUG_CMD_TYPE_ASRT (1 << 2)
+#define KVM_DEBUG_CMD_TYPE_DSRT (1 << 3)
+#define KVM_DEBUG_CMD_TYPE_TRG (1 << 4)
+#define KVM_DEBUG_CMD_TYPE_RTRG (1 << 5)
struct debug_cmd_params {
u32 dbg_type;
u32 cpu;
+ u32 irq;
};
struct debug_cmd {
--
1.7.8
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
2011-12-12 9:19 ` [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using " Sasha Levin
@ 2011-12-12 21:33 ` Pekka Enberg
2011-12-13 5:37 ` Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: Pekka Enberg @ 2011-12-12 21:33 UTC (permalink / raw)
To: Sasha Levin; +Cc: mingo, gorcunov, asias.hejun, kvm
On Mon, 2011-12-12 at 11:19 +0200, Sasha Levin wrote:
> Add options to assert and deassert IRQs using 'kvm debug'. For example, to
> assert IRQ4 in guest 'my_instance':
>
> vm debug -n my_instance --assert_irq 4
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Why is this useful? How does it protect against random users asserting
IRQs in the guest?
Pekka
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
2011-12-12 21:33 ` Pekka Enberg
@ 2011-12-13 5:37 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2011-12-13 5:37 UTC (permalink / raw)
To: Pekka Enberg; +Cc: mingo, gorcunov, asias.hejun, kvm
On Mon, 2011-12-12 at 23:33 +0200, Pekka Enberg wrote:
> On Mon, 2011-12-12 at 11:19 +0200, Sasha Levin wrote:
> > Add options to assert and deassert IRQs using 'kvm debug'. For example, to
> > assert IRQ4 in guest 'my_instance':
> >
> > vm debug -n my_instance --assert_irq 4
> >
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>
> Why is this useful? How does it protect against random users asserting
> IRQs in the guest?
Mostly useful to debug hangs as it lets the user trigger an irq which
wasn't triggered the way it was supposed to be triggered.
We discussed doing this feature in when we were working on the virtio
code and had random hangs which we believed were caused by our code not
asserting IRQs the way it should be doing. This way we can do it
manually to debug such issues.
It doesn't prevent a user to shoot himself in the leg.
--
Sasha.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-12-13 5:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12 9:19 [PATCH 1/2] kvm tools: Clean up 'kvm debug' Sasha Levin
2011-12-12 9:19 ` [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using " Sasha Levin
2011-12-12 21:33 ` Pekka Enberg
2011-12-13 5:37 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).