diff mbox

[RFC,v2,04/16] monitor: use debug version of memory access apis

Message ID 147455594859.8519.8825725423514687933.stgit@brijesh-build-machine (mailing list archive)
State New, archived
Headers show

Commit Message

Brijesh Singh Sept. 22, 2016, 2:52 p.m. UTC
updates hmp monitor to use debug version of memory access apis when
accessing the guest memory.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 cpus.c                |    2 +-
 disas.c               |    2 +-
 monitor.c             |    2 +-
 target-i386/helper.c  |   14 +++++++-------
 target-i386/monitor.c |   18 ++++++++++--------
 5 files changed, 20 insertions(+), 18 deletions(-)

Comments

Paolo Bonzini Sept. 22, 2016, 3:18 p.m. UTC | #1
On 22/09/2016 16:52, Brijesh Singh wrote:
> diff --git a/target-i386/monitor.c b/target-i386/monitor.c
> index fccfe40..47d3c2d 100644
> --- a/target-i386/monitor.c
> +++ b/target-i386/monitor.c
> @@ -130,12 +130,12 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env)
>  
>      pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
>      for (l1 = 0; l1 < 512; l1++) {
> -        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
> +        cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8);
>          pml4e = le64_to_cpu(pml4e);
>          if (pml4e & PG_PRESENT_MASK) {
>              pdp_addr = pml4e & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
> +                cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8);
>                  pdpe = le64_to_cpu(pdpe);
>                  if (pdpe & PG_PRESENT_MASK) {
>                      if (pdpe & PG_PSE_MASK) {

Please use ldq_phys_debug instead here and in mem_info_64.

Paolo
Michael S. Tsirkin Sept. 22, 2016, 7:24 p.m. UTC | #2
On Thu, Sep 22, 2016 at 10:52:28AM -0400, Brijesh Singh wrote:
> updates hmp monitor to use debug version of memory access apis when
> accessing the guest memory.
> 
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>

Does this cover the gdb stub as well?

> ---
>  cpus.c                |    2 +-
>  disas.c               |    2 +-
>  monitor.c             |    2 +-
>  target-i386/helper.c  |   14 +++++++-------
>  target-i386/monitor.c |   18 ++++++++++--------
>  5 files changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 84c3520..48dc4d1 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1725,7 +1725,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
>          l = sizeof(buf);
>          if (l > size)
>              l = size;
> -        cpu_physical_memory_read(addr, buf, l);
> +        cpu_physical_memory_read_debug(addr, buf, l);
>          if (fwrite(buf, 1, l, f) != l) {
>              error_setg(errp, QERR_IO_ERROR);
>              goto exit;
> diff --git a/disas.c b/disas.c
> index 05a7a12..382cc2c 100644
> --- a/disas.c
> +++ b/disas.c
> @@ -356,7 +356,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
>      CPUDebug *s = container_of(info, CPUDebug, info);
>  
>      if (monitor_disas_is_physical) {
> -        cpu_physical_memory_read(memaddr, myaddr, length);
> +        cpu_physical_memory_read_debug(memaddr, myaddr, length);
>      } else {
>          cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0);
>      }
> diff --git a/monitor.c b/monitor.c
> index 5c00373..4773ee1 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1299,7 +1299,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
>          if (l > line_size)
>              l = line_size;
>          if (is_physical) {
> -            cpu_physical_memory_read(addr, buf, l);
> +            cpu_physical_memory_read_debug(addr, buf, l);
>          } else {
>              if (cpu_memory_rw_debug(mon_get_cpu(), addr, buf, l, 0) < 0) {
>                  monitor_printf(mon, " Cannot access memory\n");
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 1c250b8..88fa4fa 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1034,13 +1034,13 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>              }
>              pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
>                  env->a20_mask;
> -            pml4e = x86_ldq_phys(cs, pml4e_addr);
> +            pml4e = ldq_phys_debug(cs, pml4e_addr);
>              if (!(pml4e & PG_PRESENT_MASK)) {
>                  return -1;
>              }
>              pdpe_addr = ((pml4e & PG_ADDRESS_MASK) +
>                           (((addr >> 30) & 0x1ff) << 3)) & env->a20_mask;
> -            pdpe = x86_ldq_phys(cs, pdpe_addr);
> +            pdpe = ldq_phys_debug(cs, pdpe_addr);
>              if (!(pdpe & PG_PRESENT_MASK)) {
>                  return -1;
>              }
> @@ -1055,14 +1055,14 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>          {
>              pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
>                  env->a20_mask;
> -            pdpe = x86_ldq_phys(cs, pdpe_addr);
> +            pdpe = ldq_phys_debug(cs, pdpe_addr);
>              if (!(pdpe & PG_PRESENT_MASK))
>                  return -1;
>          }
>  
>          pde_addr = ((pdpe & PG_ADDRESS_MASK) +
>                      (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask;
> -        pde = x86_ldq_phys(cs, pde_addr);
> +        pde = ldq_phys_debug(cs, pde_addr);
>          if (!(pde & PG_PRESENT_MASK)) {
>              return -1;
>          }
> @@ -1075,7 +1075,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>              pte_addr = ((pde & PG_ADDRESS_MASK) +
>                          (((addr >> 12) & 0x1ff) << 3)) & env->a20_mask;
>              page_size = 4096;
> -            pte = x86_ldq_phys(cs, pte_addr);
> +            pte = ldq_phys_debug(cs, pte_addr);
>          }
>          if (!(pte & PG_PRESENT_MASK)) {
>              return -1;
> @@ -1085,7 +1085,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>  
>          /* page directory entry */
>          pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
> -        pde = x86_ldl_phys(cs, pde_addr);
> +        pde = ldl_phys_debug(cs, pde_addr);
>          if (!(pde & PG_PRESENT_MASK))
>              return -1;
>          if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
> @@ -1094,7 +1094,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>          } else {
>              /* page directory entry */
>              pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
> -            pte = x86_ldl_phys(cs, pte_addr);
> +            pte = ldl_phys_debug(cs, pte_addr);
>              if (!(pte & PG_PRESENT_MASK)) {
>                  return -1;
>              }
> diff --git a/target-i386/monitor.c b/target-i386/monitor.c
> index fccfe40..47d3c2d 100644
> --- a/target-i386/monitor.c
> +++ b/target-i386/monitor.c
> @@ -130,12 +130,12 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env)
>  
>      pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
>      for (l1 = 0; l1 < 512; l1++) {
> -        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
> +        cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8);
>          pml4e = le64_to_cpu(pml4e);
>          if (pml4e & PG_PRESENT_MASK) {
>              pdp_addr = pml4e & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
> +                cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8);
>                  pdpe = le64_to_cpu(pdpe);
>                  if (pdpe & PG_PRESENT_MASK) {
>                      if (pdpe & PG_PSE_MASK) {
> @@ -145,7 +145,8 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env)
>                      } else {
>                          pd_addr = pdpe & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
> +                            cpu_physical_memory_read_debug(pd_addr + l3 * 8,
> +                                    &pde, 8);
>                              pde = le64_to_cpu(pde);
>                              if (pde & PG_PRESENT_MASK) {
>                                  if (pde & PG_PSE_MASK) {
> @@ -156,7 +157,7 @@ static void tlb_info_64(Monitor *mon, CPUArchState *env)
>                                  } else {
>                                      pt_addr = pde & 0x3fffffffff000ULL;
>                                      for (l4 = 0; l4 < 512; l4++) {
> -                                        cpu_physical_memory_read(pt_addr
> +                                        cpu_physical_memory_read_debug(pt_addr
>                                                                   + l4 * 8,
>                                                                   &pte, 8);
>                                          pte = le64_to_cpu(pte);
> @@ -335,13 +336,13 @@ static void mem_info_64(Monitor *mon, CPUArchState *env)
>      last_prot = 0;
>      start = -1;
>      for (l1 = 0; l1 < 512; l1++) {
> -        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
> +        cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8);
>          pml4e = le64_to_cpu(pml4e);
>          end = l1 << 39;
>          if (pml4e & PG_PRESENT_MASK) {
>              pdp_addr = pml4e & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
> +                cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8);
>                  pdpe = le64_to_cpu(pdpe);
>                  end = (l1 << 39) + (l2 << 30);
>                  if (pdpe & PG_PRESENT_MASK) {
> @@ -353,7 +354,8 @@ static void mem_info_64(Monitor *mon, CPUArchState *env)
>                      } else {
>                          pd_addr = pdpe & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
> +                            cpu_physical_memory_read_debug(pd_addr + l3 * 8,
> +                                    &pde, 8);
>                              pde = le64_to_cpu(pde);
>                              end = (l1 << 39) + (l2 << 30) + (l3 << 21);
>                              if (pde & PG_PRESENT_MASK) {
> @@ -365,7 +367,7 @@ static void mem_info_64(Monitor *mon, CPUArchState *env)
>                                  } else {
>                                      pt_addr = pde & 0x3fffffffff000ULL;
>                                      for (l4 = 0; l4 < 512; l4++) {
> -                                        cpu_physical_memory_read(pt_addr
> +                                        cpu_physical_memory_read_debug(pt_addr
>                                                                   + l4 * 8,
>                                                                   &pte, 8);
>                                          pte = le64_to_cpu(pte);
Brijesh Singh Sept. 22, 2016, 8:55 p.m. UTC | #3
Hi,

On 09/22/2016 02:24 PM, Michael S. Tsirkin wrote:
> On Thu, Sep 22, 2016 at 10:52:28AM -0400, Brijesh Singh wrote:
>> updates hmp monitor to use debug version of memory access apis when
>> accessing the guest memory.
>>
>> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
>
> Does this cover the gdb stub as well?

Yes, gdb stub works. gdb was already wired to use debug version of api

target_memory_rw_debug
   cpu_memory_rw_debug

Only part which i needed to take care was to ensure that page table walk 
to find a physical address for a given virtual address goes through the 
debug version of apis. changes in target-i386/helper.c takes care of this.

-Brijesh
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index 84c3520..48dc4d1 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1725,7 +1725,7 @@  void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
         l = sizeof(buf);
         if (l > size)
             l = size;
-        cpu_physical_memory_read(addr, buf, l);
+        cpu_physical_memory_read_debug(addr, buf, l);
         if (fwrite(buf, 1, l, f) != l) {
             error_setg(errp, QERR_IO_ERROR);
             goto exit;
diff --git a/disas.c b/disas.c
index 05a7a12..382cc2c 100644
--- a/disas.c
+++ b/disas.c
@@ -356,7 +356,7 @@  monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
     CPUDebug *s = container_of(info, CPUDebug, info);
 
     if (monitor_disas_is_physical) {
-        cpu_physical_memory_read(memaddr, myaddr, length);
+        cpu_physical_memory_read_debug(memaddr, myaddr, length);
     } else {
         cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0);
     }
diff --git a/monitor.c b/monitor.c
index 5c00373..4773ee1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1299,7 +1299,7 @@  static void memory_dump(Monitor *mon, int count, int format, int wsize,
         if (l > line_size)
             l = line_size;
         if (is_physical) {
-            cpu_physical_memory_read(addr, buf, l);
+            cpu_physical_memory_read_debug(addr, buf, l);
         } else {
             if (cpu_memory_rw_debug(mon_get_cpu(), addr, buf, l, 0) < 0) {
                 monitor_printf(mon, " Cannot access memory\n");
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 1c250b8..88fa4fa 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1034,13 +1034,13 @@  hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
             }
             pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
                 env->a20_mask;
-            pml4e = x86_ldq_phys(cs, pml4e_addr);
+            pml4e = ldq_phys_debug(cs, pml4e_addr);
             if (!(pml4e & PG_PRESENT_MASK)) {
                 return -1;
             }
             pdpe_addr = ((pml4e & PG_ADDRESS_MASK) +
                          (((addr >> 30) & 0x1ff) << 3)) & env->a20_mask;
-            pdpe = x86_ldq_phys(cs, pdpe_addr);
+            pdpe = ldq_phys_debug(cs, pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK)) {
                 return -1;
             }
@@ -1055,14 +1055,14 @@  hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
         {
             pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
                 env->a20_mask;
-            pdpe = x86_ldq_phys(cs, pdpe_addr);
+            pdpe = ldq_phys_debug(cs, pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK))
                 return -1;
         }
 
         pde_addr = ((pdpe & PG_ADDRESS_MASK) +
                     (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask;
-        pde = x86_ldq_phys(cs, pde_addr);
+        pde = ldq_phys_debug(cs, pde_addr);
         if (!(pde & PG_PRESENT_MASK)) {
             return -1;
         }
@@ -1075,7 +1075,7 @@  hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
             pte_addr = ((pde & PG_ADDRESS_MASK) +
                         (((addr >> 12) & 0x1ff) << 3)) & env->a20_mask;
             page_size = 4096;
-            pte = x86_ldq_phys(cs, pte_addr);
+            pte = ldq_phys_debug(cs, pte_addr);
         }
         if (!(pte & PG_PRESENT_MASK)) {
             return -1;
@@ -1085,7 +1085,7 @@  hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 
         /* page directory entry */
         pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
-        pde = x86_ldl_phys(cs, pde_addr);
+        pde = ldl_phys_debug(cs, pde_addr);
         if (!(pde & PG_PRESENT_MASK))
             return -1;
         if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
@@ -1094,7 +1094,7 @@  hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
         } else {
             /* page directory entry */
             pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
-            pte = x86_ldl_phys(cs, pte_addr);
+            pte = ldl_phys_debug(cs, pte_addr);
             if (!(pte & PG_PRESENT_MASK)) {
                 return -1;
             }
diff --git a/target-i386/monitor.c b/target-i386/monitor.c
index fccfe40..47d3c2d 100644
--- a/target-i386/monitor.c
+++ b/target-i386/monitor.c
@@ -130,12 +130,12 @@  static void tlb_info_64(Monitor *mon, CPUArchState *env)
 
     pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
+        cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
+                cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 if (pdpe & PG_PRESENT_MASK) {
                     if (pdpe & PG_PSE_MASK) {
@@ -145,7 +145,8 @@  static void tlb_info_64(Monitor *mon, CPUArchState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
+                            cpu_physical_memory_read_debug(pd_addr + l3 * 8,
+                                    &pde, 8);
                             pde = le64_to_cpu(pde);
                             if (pde & PG_PRESENT_MASK) {
                                 if (pde & PG_PSE_MASK) {
@@ -156,7 +157,7 @@  static void tlb_info_64(Monitor *mon, CPUArchState *env)
                                 } else {
                                     pt_addr = pde & 0x3fffffffff000ULL;
                                     for (l4 = 0; l4 < 512; l4++) {
-                                        cpu_physical_memory_read(pt_addr
+                                        cpu_physical_memory_read_debug(pt_addr
                                                                  + l4 * 8,
                                                                  &pte, 8);
                                         pte = le64_to_cpu(pte);
@@ -335,13 +336,13 @@  static void mem_info_64(Monitor *mon, CPUArchState *env)
     last_prot = 0;
     start = -1;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
+        cpu_physical_memory_read_debug(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         end = l1 << 39;
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
+                cpu_physical_memory_read_debug(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 end = (l1 << 39) + (l2 << 30);
                 if (pdpe & PG_PRESENT_MASK) {
@@ -353,7 +354,8 @@  static void mem_info_64(Monitor *mon, CPUArchState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
+                            cpu_physical_memory_read_debug(pd_addr + l3 * 8,
+                                    &pde, 8);
                             pde = le64_to_cpu(pde);
                             end = (l1 << 39) + (l2 << 30) + (l3 << 21);
                             if (pde & PG_PRESENT_MASK) {
@@ -365,7 +367,7 @@  static void mem_info_64(Monitor *mon, CPUArchState *env)
                                 } else {
                                     pt_addr = pde & 0x3fffffffff000ULL;
                                     for (l4 = 0; l4 < 512; l4++) {
-                                        cpu_physical_memory_read(pt_addr
+                                        cpu_physical_memory_read_debug(pt_addr
                                                                  + l4 * 8,
                                                                  &pte, 8);
                                         pte = le64_to_cpu(pte);