kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0 of 3] update gdbstub support
@ 2008-12-11 10:09 Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper Christian Ehrhardt
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Christian Ehrhardt @ 2008-12-11 10:09 UTC (permalink / raw)
  To: avi-H+wXaHxf7aLQT0dZR+AlfA
  Cc: ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA, kvm-u79uwXL29TY76Z2rM5mHXA,
	hollisb-r/Jw6+rmf7HQT0dZR+AlfA

This patch series updates the gdbstub support for kvm.
Patch 1&2 introduce basic powerpc support while patch 3 fixes gdbstub generic
code that was broken in a qemu merge.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper
  2008-12-11 10:09 [PATCH 0 of 3] update gdbstub support Christian Ehrhardt
@ 2008-12-11 10:09 ` Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 2 of 3] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub Christian Ehrhardt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Christian Ehrhardt @ 2008-12-11 10:09 UTC (permalink / raw)
  To: avi-H+wXaHxf7aLQT0dZR+AlfA
  Cc: ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA, kvm-u79uwXL29TY76Z2rM5mHXA,
	hollisb-r/Jw6+rmf7HQT0dZR+AlfA

# HG changeset patch
# User Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
# Date 1228924564 -3600
# Node ID 38846cef16e56c681da1ddc179e248972c8b2ff9
# Parent  705d874ff7a24484eaa15ed75a748c4e1a70c2ef
[PATCH] kvm-userspace: ppc: Add kvm_translate wrapper

From: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Add kvm_translate() wrapper used to get mmu translations from userspace.

Signed-off-by: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---

[diffstat]
 libkvm.c |    5 +++++
 libkvm.h |    2 ++
 2 files changed, 7 insertions(+)

[diff]

diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -987,6 +987,11 @@ int kvm_guest_debug(kvm_context_t kvm, i
 	return ioctl(kvm->vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg);
 }
 
+int kvm_translate(kvm_context_t kvm, int vcpu, struct kvm_translation *tr)
+{
+	return ioctl(kvm->vcpu_fd[vcpu], KVM_TRANSLATE, tr);
+}
+
 int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset)
 {
 	struct kvm_signal_mask *sigmask;
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -639,6 +639,8 @@ int kvm_set_pit(kvm_context_t kvm, struc
 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
 #endif
 
+int kvm_translate(kvm_context_t kvm, int vcpu, struct kvm_translation *tr);
+
 #endif
 
 #ifdef KVM_CAP_VAPIC
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2 of 3] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub
  2008-12-11 10:09 [PATCH 0 of 3] update gdbstub support Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper Christian Ehrhardt
@ 2008-12-11 10:09 ` Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration Christian Ehrhardt
  2008-12-17 13:12 ` [PATCH 0 of 3] update gdbstub support Avi Kivity
  3 siblings, 0 replies; 6+ messages in thread
From: Christian Ehrhardt @ 2008-12-11 10:09 UTC (permalink / raw)
  To: avi-H+wXaHxf7aLQT0dZR+AlfA
  Cc: ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA, kvm-u79uwXL29TY76Z2rM5mHXA,
	hollisb-r/Jw6+rmf7HQT0dZR+AlfA

# HG changeset patch
# User Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
# Date 1228989956 -3600
# Node ID 6f228c807ad0b239b7342d2974debfc66418d784
# Parent  38846cef16e56c681da1ddc179e248972c8b2ff9
[PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub

From: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Add basic KVM PowerPC support to qemu's gdbstub introducing a kvm ppc style
mmu implementation that uses the kvm_translate ioctl.
This also requires to save the kvm registers prior to the 'm' gdb operations.

Signed-off-by: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---

[diffstat]
 gdbstub.c                   |    2 ++
 hw/ppc440_bamboo.c          |    1 +
 qemu-kvm-powerpc.c          |   28 ++++++++++++++++++++++++++++
 target-ppc/cpu.h            |    2 ++
 target-ppc/helper.c         |    4 ++++
 target-ppc/translate_init.c |    5 +++++
 6 files changed, 42 insertions(+)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1374,6 +1374,7 @@ static int gdb_handle_packet(GDBState *s
         if (*p == ',')
             p++;
         len = strtoull(p, NULL, 16);
+        kvm_save_registers(s->g_cpu);
         if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {
             put_packet (s, "E14");
         } else {
@@ -1389,6 +1390,7 @@ static int gdb_handle_packet(GDBState *s
         if (*p == ':')
             p++;
         hextomem(mem_buf, p, len);
+        kvm_save_registers(s->gcpu);
         if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0)
             put_packet(s, "E14");
         else
diff --git a/qemu/hw/ppc440_bamboo.c b/qemu/hw/ppc440_bamboo.c
--- a/qemu/hw/ppc440_bamboo.c
+++ b/qemu/hw/ppc440_bamboo.c
@@ -99,6 +99,7 @@ void bamboo_init(ram_addr_t ram_size, in
 		fprintf(stderr, "Unable to initialize CPU!\n");
 		exit(1);
 	}
+	env->mmu_model = POWERPC_MMU_KVM;
 
 	/* call init */
 	printf("Calling function ppc440_init\n");
diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c
--- a/qemu/qemu-kvm-powerpc.c
+++ b/qemu/qemu-kvm-powerpc.c
@@ -102,6 +102,7 @@ void kvm_arch_save_regs(CPUState *env)
 
     env->spr[SPR_SRR0] = regs.srr0;
     env->spr[SPR_SRR1] = regs.srr1;
+    env->spr[SPR_BOOKE_PID] = regs.pid;
 
     env->spr[SPR_SPRG0] = regs.sprg0;
     env->spr[SPR_SPRG1] = regs.sprg1;
@@ -219,6 +220,33 @@ int handle_powerpc_dcr_write(int vcpu, u
     return 0; /* XXX ignore failed DCR ops */
 }
 
+int mmukvm_get_physical_address(CPUState *env, mmu_ctx_t *ctx,
+                                target_ulong eaddr, int rw, int access_type)
+{
+    struct kvm_translation tr;
+    uint64_t pid;
+    uint64_t as;
+    int r;
+
+    pid = env->spr[SPR_BOOKE_PID];
+
+    if (access_type == ACCESS_CODE)
+        as = env->msr & msr_ir;
+    else
+        as = env->msr & msr_dr;
+
+    tr.linear_address = as << 40 | pid << 32 | eaddr;
+    r = kvm_translate(kvm_context, env->cpu_index, &tr);
+    if (r == -1)
+        return r;
+
+    if (!tr.valid)
+        return -EFAULT;
+
+    ctx->raddr = tr.physical_address;
+    return 0;
+}
+
 void kvm_arch_cpu_reset(CPUState *env)
 {
 }
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -98,6 +98,8 @@ enum powerpc_mmu_t {
     POWERPC_MMU_BOOKE_FSL  = 0x00000009,
     /* PowerPC 601 MMU model (specific BATs format)            */
     POWERPC_MMU_601        = 0x0000000A,
+    /* KVM managing the MMU state                              */
+    POWERPC_MMU_KVM        = 0x0000000B,
 #if defined(TARGET_PPC64)
 #define POWERPC_MMU_64       0x00010000
     /* 64 bits PowerPC MMU                                     */
diff --git a/qemu/target-ppc/helper.c b/qemu/target-ppc/helper.c
--- a/qemu/target-ppc/helper.c
+++ b/qemu/target-ppc/helper.c
@@ -1429,6 +1429,10 @@ int get_physical_address (CPUState *env,
         fprintf(logfile, "%s\n", __func__);
     }
 #endif
+
+    if (env->mmu_model == POWERPC_MMU_KVM)
+        return mmukvm_get_physical_address(env, ctx, eaddr, rw, access_type);
+
     if ((access_type == ACCESS_CODE && msr_ir == 0) ||
         (access_type != ACCESS_CODE && msr_dr == 0)) {
         /* No address translation */
diff --git a/qemu/target-ppc/translate_init.c b/qemu/target-ppc/translate_init.c
--- a/qemu/target-ppc/translate_init.c
+++ b/qemu/target-ppc/translate_init.c
@@ -9273,6 +9273,11 @@ int cpu_ppc_register_internal (CPUPPCSta
         case POWERPC_MMU_601:
             mmu_model = "PowerPC 601";
             break;
+#ifdef KVM
+        case POWERPC_MMU_KVM:
+            mmu_model = "PowerPC KVM";
+            break;
+#endif
 #if defined (TARGET_PPC64)
         case POWERPC_MMU_64B:
             mmu_model = "PowerPC 64";
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration
  2008-12-11 10:09 [PATCH 0 of 3] update gdbstub support Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper Christian Ehrhardt
  2008-12-11 10:09 ` [PATCH 2 of 3] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub Christian Ehrhardt
@ 2008-12-11 10:09 ` Christian Ehrhardt
  2008-12-16 17:49   ` Michal Suchanek
  2008-12-17 13:12 ` [PATCH 0 of 3] update gdbstub support Avi Kivity
  3 siblings, 1 reply; 6+ messages in thread
From: Christian Ehrhardt @ 2008-12-11 10:09 UTC (permalink / raw)
  To: avi-H+wXaHxf7aLQT0dZR+AlfA
  Cc: ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	kvm-ppc-u79uwXL29TY76Z2rM5mHXA, kvm-u79uwXL29TY76Z2rM5mHXA,
	hollisb-r/Jw6+rmf7HQT0dZR+AlfA

# HG changeset patch
# User Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
# Date 1228989958 -3600
# Node ID f80fb35de91fe69dae889c70948c9a53212ee444
# Parent  6f228c807ad0b239b7342d2974debfc66418d784
[PATCH] kvm-userspace: fix gdbstub kvm integration

From: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

Some recent qemu upstream merges brought in a new concept to not use "env" as
current cpu in gdb_handle_packet anymore. But the kvm calls still do, this
leads to SIGDEV's as env is not initialized when calling the functions like
kvm_save_registers.

Insted there is now a gdbstate structure holding current cpu for
step/continue and "other" ops splitted.

This patch changes the kvm_save_registers calls to use the right CPUState
variable for the kvm calls in gdb_handle_packet.

Signed-off-by: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---

[diffstat]
 gdbstub.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

[diff]

diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
--- a/qemu/gdbstub.c
+++ b/qemu/gdbstub.c
@@ -1348,7 +1348,7 @@ static int gdb_handle_packet(GDBState *s
         }
         break;
     case 'g':
-        kvm_save_registers(env);
+        kvm_save_registers(s->g_cpu);
         len = 0;
         for (addr = 0; addr < num_g_regs; addr++) {
             reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);
@@ -1366,7 +1366,7 @@ static int gdb_handle_packet(GDBState *s
             len -= reg_size;
             registers += reg_size;
         }
-        kvm_load_registers(env);
+        kvm_load_registers(s->g_cpu);
         put_packet(s, "OK");
         break;
     case 'm':
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration
  2008-12-11 10:09 ` [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration Christian Ehrhardt
@ 2008-12-16 17:49   ` Michal Suchanek
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Suchanek @ 2008-12-16 17:49 UTC (permalink / raw)
  To: Christian Ehrhardt
  Cc: avi-H+wXaHxf7aLQT0dZR+AlfA, kvm-ppc-u79uwXL29TY76Z2rM5mHXA,
	kvm-u79uwXL29TY76Z2rM5mHXA, hollisb-r/Jw6+rmf7HQT0dZR+AlfA

Hello

I was trying to debug my patch that is not working and noticed this
crash in current kvm git.

The patch below makes kvm not crash when gdb is attched to gdbserver
so it certainly improves things.

Thanks

Michal

PS if you want further input from me add me to CC

On 16/12/2008, Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org> wrote:
> # HG changeset patch
>  # User Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
>  # Date 1228989958 -3600
>  # Node ID f80fb35de91fe69dae889c70948c9a53212ee444
>  # Parent  6f228c807ad0b239b7342d2974debfc66418d784
>  [PATCH] kvm-userspace: fix gdbstub kvm integration
>
>  From: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
>
>  Some recent qemu upstream merges brought in a new concept to not use "env" as
>  current cpu in gdb_handle_packet anymore. But the kvm calls still do, this
>  leads to SIGDEV's as env is not initialized when calling the functions like
>  kvm_save_registers.
>
>  Insted there is now a gdbstate structure holding current cpu for
>  step/continue and "other" ops splitted.
>
>  This patch changes the kvm_save_registers calls to use the right CPUState
>  variable for the kvm calls in gdb_handle_packet.
>
>  Signed-off-by: Christian Ehrhardt <ehrhardt-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
>  ---
>
>  [diffstat]
>   gdbstub.c |    8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
>  [diff]
>
>  diff --git a/qemu/gdbstub.c b/qemu/gdbstub.c
>  --- a/qemu/gdbstub.c
>  +++ b/qemu/gdbstub.c
>  @@ -1348,7 +1348,7 @@ static int gdb_handle_packet(GDBState *s
>          }
>          break;
>      case 'g':
>  -        kvm_save_registers(env);
>  +        kvm_save_registers(s->g_cpu);
>          len = 0;
>          for (addr = 0; addr < num_g_regs; addr++) {
>              reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);
>  @@ -1366,7 +1366,7 @@ static int gdb_handle_packet(GDBState *s
>              len -= reg_size;
>              registers += reg_size;
>          }
>  -        kvm_load_registers(env);
>  +        kvm_load_registers(s->g_cpu);
>          put_packet(s, "OK");
>          break;
>      case 'm':
>
> --
>  To unsubscribe from this list: send the line "unsubscribe kvm" in
>  the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>  More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0 of 3] update gdbstub support
  2008-12-11 10:09 [PATCH 0 of 3] update gdbstub support Christian Ehrhardt
                   ` (2 preceding siblings ...)
  2008-12-11 10:09 ` [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration Christian Ehrhardt
@ 2008-12-17 13:12 ` Avi Kivity
  3 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2008-12-17 13:12 UTC (permalink / raw)
  To: Christian Ehrhardt; +Cc: kvm-ppc, kvm, hollisb

Christian Ehrhardt wrote:
> This patch series updates the gdbstub support for kvm.
> Patch 1&2 introduce basic powerpc support while patch 3 fixes gdbstub generic
> code that was broken in a qemu merge.
>   

Please rebase, as the recent debug changes probably affect this area.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-12-17 13:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-11 10:09 [PATCH 0 of 3] update gdbstub support Christian Ehrhardt
2008-12-11 10:09 ` [PATCH 1 of 3] [PATCH] kvm-userspace: ppc: Add kvm_translate wrapper Christian Ehrhardt
2008-12-11 10:09 ` [PATCH 2 of 3] [PATCH] qemu: ppc: kvm-userspace: KVM PowerPC support for qemu gdbstub Christian Ehrhardt
2008-12-11 10:09 ` [PATCH 3 of 3] [PATCH] kvm-userspace: fix gdbstub kvm integration Christian Ehrhardt
2008-12-16 17:49   ` Michal Suchanek
2008-12-17 13:12 ` [PATCH 0 of 3] update gdbstub support Avi Kivity

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).