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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html