diff mbox series

[v1,25/34] linux-user/elfload: add extra logging for hole finding

Message ID 20220105135009.1584676-26-alex.bennee@linaro.org
State Superseded
Headers show
Series testing/next and other misc fixes | expand

Commit Message

Alex Bennée Jan. 5, 2022, 1:50 p.m. UTC
The various approaches to finding memory holes are quite complicated
to follow especially at a distance. Improve the logging so we can see
exactly what method found the space for the guest memory.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 linux-user/elfload.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Richard Henderson Jan. 7, 2022, 12:11 a.m. UTC | #1
On 1/5/22 5:50 AM, Alex Bennée wrote:
> The various approaches to finding memory holes are quite complicated
> to follow especially at a distance. Improve the logging so we can see
> exactly what method found the space for the guest memory.
> 
> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
> ---
>   linux-user/elfload.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Philippe Mathieu-Daudé Jan. 10, 2022, 9:53 a.m. UTC | #2
On 1/5/22 14:50, Alex Bennée wrote:
> The various approaches to finding memory holes are quite complicated
> to follow especially at a distance. Improve the logging so we can see
> exactly what method found the space for the guest memory.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  linux-user/elfload.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

> @@ -2391,6 +2403,9 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
>      }
>  
>      guest_base = addr;
> +
> +    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %"PRIxPTR" for %" PRIdPTR" bytes\n",
> +                  __func__, addr, hiaddr - loaddr);

TIL PRIxPTR / PRIdPTR!

>  }
>  
>  static void pgb_dynamic(const char *image_name, long align)
> @@ -2447,6 +2462,9 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,
>                       "using -R option)", reserved_va, test, strerror(errno));
>          exit(EXIT_FAILURE);
>      }
> +
> +    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %p for %ld bytes\n",

"for %lu bytes", otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +                  __func__, addr, reserved_va);
>  }
>  
>  void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,
Warner Losh Jan. 10, 2022, 9:50 p.m. UTC | #3
> On Jan 5, 2022, at 6:50 AM, Alex Bennée <alex.bennee@linaro.org> wrote:
> 
> The various approaches to finding memory holes are quite complicated
> to follow especially at a distance. Improve the logging so we can see
> exactly what method found the space for the guest memory.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> linux-user/elfload.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)

Reviewed-by: Warner Losh <imp@bsdimp.com>

I’ve added similar things in the past for debugging bsd-user.

> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 767f54c76d..238979b8b6 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2221,6 +2221,9 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
>     if (test != addr) {
>         pgb_fail_in_use(image_name);
>     }
> +    qemu_log_mask(CPU_LOG_PAGE,
> +                  "%s: base @ %p for " TARGET_ABI_FMT_ld " bytes\n",
> +                  __func__, addr, guest_hiaddr - guest_loaddr);
> }
> 
> /**
> @@ -2263,6 +2266,9 @@ static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk,
>             if (mmap_start != MAP_FAILED) {
>                 munmap(mmap_start, guest_size);
>                 if (mmap_start == (void *) align_start) {
> +                    qemu_log_mask(CPU_LOG_PAGE,
> +                                  "%s: base @ %p for %" PRIdPTR" bytes\n",
> +                                  __func__, mmap_start + offset, guest_size);
>                     return (uintptr_t) mmap_start + offset;
>                 }
>             }
> @@ -2342,6 +2348,12 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_size,
>     }
>     free_self_maps(maps);
> 
> +    if (ret != -1) {
> +        qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %" PRIxPTR
> +                      " for %" PRIdPTR " bytes\n",
> +                      __func__, ret, guest_size);
> +    }
> +
>     return ret;
> }
> 
> @@ -2391,6 +2403,9 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
>     }
> 
>     guest_base = addr;
> +
> +    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %"PRIxPTR" for %" PRIdPTR" bytes\n",
> +                  __func__, addr, hiaddr - loaddr);
> }
> 
> static void pgb_dynamic(const char *image_name, long align)
> @@ -2447,6 +2462,9 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,
>                      "using -R option)", reserved_va, test, strerror(errno));
>         exit(EXIT_FAILURE);
>     }
> +
> +    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %p for %ld bytes\n",
> +                  __func__, addr, reserved_va);
> }
> 
> void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,
> -- 
> 2.30.2
> 
>
diff mbox series

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 767f54c76d..238979b8b6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2221,6 +2221,9 @@  static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
     if (test != addr) {
         pgb_fail_in_use(image_name);
     }
+    qemu_log_mask(CPU_LOG_PAGE,
+                  "%s: base @ %p for " TARGET_ABI_FMT_ld " bytes\n",
+                  __func__, addr, guest_hiaddr - guest_loaddr);
 }
 
 /**
@@ -2263,6 +2266,9 @@  static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk,
             if (mmap_start != MAP_FAILED) {
                 munmap(mmap_start, guest_size);
                 if (mmap_start == (void *) align_start) {
+                    qemu_log_mask(CPU_LOG_PAGE,
+                                  "%s: base @ %p for %" PRIdPTR" bytes\n",
+                                  __func__, mmap_start + offset, guest_size);
                     return (uintptr_t) mmap_start + offset;
                 }
             }
@@ -2342,6 +2348,12 @@  static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_size,
     }
     free_self_maps(maps);
 
+    if (ret != -1) {
+        qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %" PRIxPTR
+                      " for %" PRIdPTR " bytes\n",
+                      __func__, ret, guest_size);
+    }
+
     return ret;
 }
 
@@ -2391,6 +2403,9 @@  static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
     }
 
     guest_base = addr;
+
+    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %"PRIxPTR" for %" PRIdPTR" bytes\n",
+                  __func__, addr, hiaddr - loaddr);
 }
 
 static void pgb_dynamic(const char *image_name, long align)
@@ -2447,6 +2462,9 @@  static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,
                      "using -R option)", reserved_va, test, strerror(errno));
         exit(EXIT_FAILURE);
     }
+
+    qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %p for %ld bytes\n",
+                  __func__, addr, reserved_va);
 }
 
 void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,