diff mbox series

[v9,26/27] gdbstub: Add support to read a MSR for KVM target

Message ID 20190502081554.5521-27-arilou@gmail.com
State New
Headers show
Series gdbstub: Refactor command packets handler | expand

Commit Message

Jon Doron May 2, 2019, 8:15 a.m. UTC
gdb> maint packet qqemu.kvm.Rdmsr:MsrIndex

Signed-off-by: Jon Doron <arilou@gmail.com>
---
 gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

Comments

Alex Bennée May 15, 2019, 5:48 p.m. UTC | #1
Jon Doron <arilou@gmail.com> writes:

> gdb> maint packet qqemu.kvm.Rdmsr:MsrIndex

gdbserver already has a mechanism for exposing system registers see:

  commit 200bf5b7ffea635079cc05fdfb363372b9544ce7
  Author: Abdallah Bouassida <abdallah.bouassida@lauterbach.com>
  Date:   Fri May 18 17:48:07 2018 +0100

for an example. As MSR's are very specific to x86 all this should be
handled via target/i386/gdbstub and kept out of the generic code.

>
> Signed-off-by: Jon Doron <arilou@gmail.com>
> ---
>  gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 34da10260d..f48c3a2b5f 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -2141,7 +2141,14 @@ static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
>
>  static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx)
>  {
> -    put_packet(gdb_ctx->s, "sstepbits;sstep;PhyMemMode");
> +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
> +             "sstepbits;sstep;PhyMemMode");
> +
> +    if (kvm_enabled()) {
> +        pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";kvm.Rdmsr");
> +    }
> +
> +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
>  }
>
>  static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx,
> @@ -2166,6 +2173,29 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx)
>      put_packet(gdb_ctx->s, "OK");
>  }
>
> +static void handle_query_kvm_read_msr(GdbCmdContext *gdb_ctx, void *user_ctx)
> +{
> +    uint64_t msr_val;
> +
> +    if (!kvm_enabled()) {
> +        return;
> +    }
> +
> +    if (!gdb_ctx->num_params) {
> +        put_packet(gdb_ctx->s, "E22");
> +        return;
> +    }
> +
> +    if (kvm_arch_read_msr(gdbserver_state->c_cpu, gdb_ctx->params[0].val_ul,
> +                          &msr_val)) {
> +        put_packet(gdb_ctx->s, "E00");
> +        return;
> +    }
> +
> +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%" PRIx64, msr_val);
> +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
> +}
> +
>  static GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
>      /* Order is important if has same prefix */
>      {
> @@ -2250,6 +2280,12 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
>          .handler = handle_query_qemu_phy_mem_mode,
>          .cmd = "qemu.PhyMemMode",
>      },
> +    {
> +        .handler = handle_query_kvm_read_msr,
> +        .cmd = "qemu.kvm.Rdmsr:",
> +        .cmd_startswith = 1,
> +        .schema = "l0"
> +    },
>  };
>
>  static GdbCmdParseEntry gdb_gen_set_table[] = {


--
Alex Bennée
Jon Doron May 20, 2019, 5:24 a.m. UTC | #2
Ah cool did not know about that I will look into it and perhaps can do
a different patchset just for this no need to add it on top of this
patchset

On Wed, May 15, 2019 at 8:48 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Jon Doron <arilou@gmail.com> writes:
>
> > gdb> maint packet qqemu.kvm.Rdmsr:MsrIndex
>
> gdbserver already has a mechanism for exposing system registers see:
>
>   commit 200bf5b7ffea635079cc05fdfb363372b9544ce7
>   Author: Abdallah Bouassida <abdallah.bouassida@lauterbach.com>
>   Date:   Fri May 18 17:48:07 2018 +0100
>
> for an example. As MSR's are very specific to x86 all this should be
> handled via target/i386/gdbstub and kept out of the generic code.
>
> >
> > Signed-off-by: Jon Doron <arilou@gmail.com>
> > ---
> >  gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 37 insertions(+), 1 deletion(-)
> >
> > diff --git a/gdbstub.c b/gdbstub.c
> > index 34da10260d..f48c3a2b5f 100644
> > --- a/gdbstub.c
> > +++ b/gdbstub.c
> > @@ -2141,7 +2141,14 @@ static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
> >
> >  static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx)
> >  {
> > -    put_packet(gdb_ctx->s, "sstepbits;sstep;PhyMemMode");
> > +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
> > +             "sstepbits;sstep;PhyMemMode");
> > +
> > +    if (kvm_enabled()) {
> > +        pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";kvm.Rdmsr");
> > +    }
> > +
> > +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
> >  }
> >
> >  static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx,
> > @@ -2166,6 +2173,29 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx)
> >      put_packet(gdb_ctx->s, "OK");
> >  }
> >
> > +static void handle_query_kvm_read_msr(GdbCmdContext *gdb_ctx, void *user_ctx)
> > +{
> > +    uint64_t msr_val;
> > +
> > +    if (!kvm_enabled()) {
> > +        return;
> > +    }
> > +
> > +    if (!gdb_ctx->num_params) {
> > +        put_packet(gdb_ctx->s, "E22");
> > +        return;
> > +    }
> > +
> > +    if (kvm_arch_read_msr(gdbserver_state->c_cpu, gdb_ctx->params[0].val_ul,
> > +                          &msr_val)) {
> > +        put_packet(gdb_ctx->s, "E00");
> > +        return;
> > +    }
> > +
> > +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%" PRIx64, msr_val);
> > +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
> > +}
> > +
> >  static GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
> >      /* Order is important if has same prefix */
> >      {
> > @@ -2250,6 +2280,12 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
> >          .handler = handle_query_qemu_phy_mem_mode,
> >          .cmd = "qemu.PhyMemMode",
> >      },
> > +    {
> > +        .handler = handle_query_kvm_read_msr,
> > +        .cmd = "qemu.kvm.Rdmsr:",
> > +        .cmd_startswith = 1,
> > +        .schema = "l0"
> > +    },
> >  };
> >
> >  static GdbCmdParseEntry gdb_gen_set_table[] = {
>
>
> --
> Alex Bennée
Alex Bennée May 20, 2019, 12:42 p.m. UTC | #3
Jon Doron <arilou@gmail.com> writes:

> Ah cool did not know about that I will look into it and perhaps can do
> a different patchset just for this no need to add it on top of this
> patchset

Yes just drop these arch specific patches for your next iteration while
you rework them for the target/ approach. Hopefully we'll have the
re-factor merged before you've finished.

>
> On Wed, May 15, 2019 at 8:48 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>>
>> Jon Doron <arilou@gmail.com> writes:
>>
>> > gdb> maint packet qqemu.kvm.Rdmsr:MsrIndex
>>
>> gdbserver already has a mechanism for exposing system registers see:
>>
>>   commit 200bf5b7ffea635079cc05fdfb363372b9544ce7
>>   Author: Abdallah Bouassida <abdallah.bouassida@lauterbach.com>
>>   Date:   Fri May 18 17:48:07 2018 +0100
>>
>> for an example. As MSR's are very specific to x86 all this should be
>> handled via target/i386/gdbstub and kept out of the generic code.
>>
>> >
>> > Signed-off-by: Jon Doron <arilou@gmail.com>
>> > ---
>> >  gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++-
>> >  1 file changed, 37 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/gdbstub.c b/gdbstub.c
>> > index 34da10260d..f48c3a2b5f 100644
>> > --- a/gdbstub.c
>> > +++ b/gdbstub.c
>> > @@ -2141,7 +2141,14 @@ static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
>> >
>> >  static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx)
>> >  {
>> > -    put_packet(gdb_ctx->s, "sstepbits;sstep;PhyMemMode");
>> > +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
>> > +             "sstepbits;sstep;PhyMemMode");
>> > +
>> > +    if (kvm_enabled()) {
>> > +        pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";kvm.Rdmsr");
>> > +    }
>> > +
>> > +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
>> >  }
>> >
>> >  static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx,
>> > @@ -2166,6 +2173,29 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx)
>> >      put_packet(gdb_ctx->s, "OK");
>> >  }
>> >
>> > +static void handle_query_kvm_read_msr(GdbCmdContext *gdb_ctx, void *user_ctx)
>> > +{
>> > +    uint64_t msr_val;
>> > +
>> > +    if (!kvm_enabled()) {
>> > +        return;
>> > +    }
>> > +
>> > +    if (!gdb_ctx->num_params) {
>> > +        put_packet(gdb_ctx->s, "E22");
>> > +        return;
>> > +    }
>> > +
>> > +    if (kvm_arch_read_msr(gdbserver_state->c_cpu, gdb_ctx->params[0].val_ul,
>> > +                          &msr_val)) {
>> > +        put_packet(gdb_ctx->s, "E00");
>> > +        return;
>> > +    }
>> > +
>> > +    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%" PRIx64, msr_val);
>> > +    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
>> > +}
>> > +
>> >  static GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
>> >      /* Order is important if has same prefix */
>> >      {
>> > @@ -2250,6 +2280,12 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
>> >          .handler = handle_query_qemu_phy_mem_mode,
>> >          .cmd = "qemu.PhyMemMode",
>> >      },
>> > +    {
>> > +        .handler = handle_query_kvm_read_msr,
>> > +        .cmd = "qemu.kvm.Rdmsr:",
>> > +        .cmd_startswith = 1,
>> > +        .schema = "l0"
>> > +    },
>> >  };
>> >
>> >  static GdbCmdParseEntry gdb_gen_set_table[] = {
>>
>>
>> --
>> Alex Bennée


--
Alex Bennée
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index 34da10260d..f48c3a2b5f 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2141,7 +2141,14 @@  static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
 
 static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx)
 {
-    put_packet(gdb_ctx->s, "sstepbits;sstep;PhyMemMode");
+    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
+             "sstepbits;sstep;PhyMemMode");
+
+    if (kvm_enabled()) {
+        pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";kvm.Rdmsr");
+    }
+
+    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
 }
 
 static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx,
@@ -2166,6 +2173,29 @@  static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx)
     put_packet(gdb_ctx->s, "OK");
 }
 
+static void handle_query_kvm_read_msr(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+    uint64_t msr_val;
+
+    if (!kvm_enabled()) {
+        return;
+    }
+
+    if (!gdb_ctx->num_params) {
+        put_packet(gdb_ctx->s, "E22");
+        return;
+    }
+
+    if (kvm_arch_read_msr(gdbserver_state->c_cpu, gdb_ctx->params[0].val_ul,
+                          &msr_val)) {
+        put_packet(gdb_ctx->s, "E00");
+        return;
+    }
+
+    snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%" PRIx64, msr_val);
+    put_packet(gdb_ctx->s, gdb_ctx->str_buf);
+}
+
 static GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
     /* Order is important if has same prefix */
     {
@@ -2250,6 +2280,12 @@  static GdbCmdParseEntry gdb_gen_query_table[] = {
         .handler = handle_query_qemu_phy_mem_mode,
         .cmd = "qemu.PhyMemMode",
     },
+    {
+        .handler = handle_query_kvm_read_msr,
+        .cmd = "qemu.kvm.Rdmsr:",
+        .cmd_startswith = 1,
+        .schema = "l0"
+    },
 };
 
 static GdbCmdParseEntry gdb_gen_set_table[] = {