kvm tools: Clean up 'kvm debug'
PATCH 1/2 kvm tools: Clean up 'kvm debug'
--- 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(-)
tools/kvm/builtin-debug.c +7 -6
@@ -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));
tools/kvm/builtin-run.c +4 -3
@@ -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 ;
tools/kvm/include/kvm/builtin-debug.h +9 -4
@@ -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 );
Signature · 1 line
1.7.8
PATCH 2/2 kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
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
--- 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(-)
tools/kvm/builtin-debug.c +19 -0
@@ -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;
tools/kvm/builtin-run.c +12 -0
@@ -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 ;
tools/kvm/include/kvm/builtin-debug.h +5 -0
@@ -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 {
Signature · 1 line
1.7.8
Re: [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
Quoted 6 lines · 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 4Signed-off-by Sasha Levin <[email protected]>
Why is this useful? How does it protect against random users asserting IRQs in the guest?
Pekka
Re: [PATCH 2/2] kvm tools: Add ability to assert/deassert IRQs using 'kvm debug'
Quoted 10 lines · Pekka Enberg
Quoted 6 lines · 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 4Signed-off-by Sasha Levin <[email protected]>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.
Signature · 1 line
Sasha.