Skip to contentSkip to conversation

target/i386/monitor: Refine `info tlb` command logic

PATCH Superseded [email protected] 3 participants 6 messages May 24 – Jun 10

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386/monitor: Refine `info tlb` command logic

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

---
 hmp-commands-info.hx  |  10 +-
 target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 195 insertions(+), 45 deletions(-)
hmp-commands-info.hx +6 -4
index 82134eb6c2..33b4604d11 100644
@@ -188,17 +188,19 @@ ERST
 
     {
         .name       = "tlb",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show virtual to physical memory mappings",
+        .args_type  = "file:s?",
+        .params     = "[file]",
+        .help       = "show virtual to physical memory mappings (optionally save to file)",
         .cmd        = hmp_info_tlb,
         .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \
                         | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
     },
 
 SRST
-  ``info tlb``
+  ``info tlb`` [*file*]
     Show virtual to physical memory mappings.
+    If *file* is specified, the output is saved to the given file
+    instead of being printed to the monitor.
 ERST
 
     {
target/i386/monitor.c +189 -41

362 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 16 lines · At 2026-05-24 20:41:29, [email protected] wrote:

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

Quoted 6 lines

---
hmp-commands-info.hx | 10 +-
target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------

2 files changed, 195 insertions(+), 45 deletions(-)

Ping for code review :)

Best Regards,
Alano.

#2 lore raw
In reply to [email protected]

Hi,

Quoted 38 lines · On 24/5/26 14:41, [email protected] wrote:

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

---
  hmp-commands-info.hx  |  10 +-
  target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------
  2 files changed, 195 insertions(+), 45 deletions(-)
hmp-commands-info.hx +3 -3
index 82134eb6c2..33b4604d11 100644
@@ -188,17 +188,19 @@ ERST
 
      {
          .name       = "tlb",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show virtual to physical memory mappings",
+        .args_type  = "file:s?",
+        .params     = "[file]",
+        .help       = "show virtual to physical memory mappings (optionally save to file)",
          .cmd        = hmp_info_tlb,
          .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \

hmp-commands-info.hx ERST · line 204

Quoted 10 lines
hmp-commands-info.hx +3 -1
                          | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
      },
 
  SRST
-  ``info tlb``
+  ``info tlb`` [*file*]
      Show virtual to physical memory mappings.
+    If *file* is specified, the output is saved to the given file
+    instead of being printed to the monitor.
  ERST

What about passing count or range by argument instead, keeping the default behavior?

author
#3 lore raw
Quoted 54 lines · Philippe Mathieu-Daudé

Hi,

Quoted 38 lines · On 24/5/26 14:41, [email protected] wrote:

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

---
  hmp-commands-info.hx  |  10 +-
  target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------
  2 files changed, 195 insertions(+), 45 deletions(-)
hmp-commands-info.hx +3 -3
index 82134eb6c2..33b4604d11 100644
@@ -188,17 +188,19 @@ ERST
 
      {
          .name       = "tlb",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show virtual to physical memory mappings",
+        .args_type  = "file:s?",
+        .params     = "[file]",
+        .help       = "show virtual to physical memory mappings (optionally save to file)",
          .cmd        = hmp_info_tlb,
          .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \

hmp-commands-info.hx ERST · line 204

Quoted 10 lines
hmp-commands-info.hx +3 -1
                          | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
      },
 
  SRST
-  ``info tlb``
+  ``info tlb`` [*file*]
      Show virtual to physical memory mappings.
+    If *file* is specified, the output is saved to the given file
+    instead of being printed to the monitor.
  ERST

What about passing count or range by argument instead, keeping the

Quoted 1 line

default behavior?

Hi, Philippe:

Your suggestion is good,
I can add several options,
so that users can control the output range and count.

And just as I described earlier, we should modify the default behavior:
only print the first 32 entries and the last entry.
so that users can know the range while avoiding
the output of all the entries (there are too many).

Alano.

#4 lore raw
Quoted 69 lines · * Alano Song ([email protected]) wrote:
Quoted 54 lines · Philippe Mathieu-Daudé

Hi,

Quoted 38 lines · On 24/5/26 14:41, [email protected] wrote:

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

---
  hmp-commands-info.hx  |  10 +-
  target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------
  2 files changed, 195 insertions(+), 45 deletions(-)
hmp-commands-info.hx +3 -3
index 82134eb6c2..33b4604d11 100644
@@ -188,17 +188,19 @@ ERST
 
      {
          .name       = "tlb",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show virtual to physical memory mappings",
+        .args_type  = "file:s?",
+        .params     = "[file]",
+        .help       = "show virtual to physical memory mappings (optionally save to file)",
          .cmd        = hmp_info_tlb,
          .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \

hmp-commands-info.hx ERST · line 204

Quoted 10 lines
hmp-commands-info.hx +3 -1
                          | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
      },
 
  SRST
-  ``info tlb``
+  ``info tlb`` [*file*]
      Show virtual to physical memory mappings.
+    If *file* is specified, the output is saved to the given file
+    instead of being printed to the monitor.
  ERST

What about passing count or range by argument instead, keeping the

Quoted 1 line

default behavior?

Hi, Philippe:

Your suggestion is good,
I can add several options,
so that users can control the output range and count.

Quoted 4 lines

And just as I described earlier, we should modify the default behavior:
only print the first 32 entries and the last entry.
so that users can know the range while avoiding
the output of all the entries (there are too many).

A comment in the help warning that they'll get a lot of output would be good as well.

Dave

Quoted 5 lines

Alano.

Signature · 4 lines
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/
author
#5 lore raw
Quoted 75 lines · Dr. David Alan Gilbert
Quoted 69 lines · * Alano Song ([email protected]) wrote:
Quoted 54 lines · Philippe Mathieu-Daudé

Hi,

Quoted 38 lines · On 24/5/26 14:41, [email protected] wrote:

When booting an i386 guest, the info tlb command may walk the entire page table hierarchy and emit an enormous amount of output (as many as 800+ million entries under my test).
It will take dozens of minutes to print all the info, because each monitor print function will holds 'mon_lock'. This effectively hangs the qemu monitor, and even leading to program exit due to timeout.

So it may be better to show only the first 32 entries and the last entry by default.

And if full output is required, the user can redirect the output to a file by specifying a file name, e.g.:
info tlb xxx.txt.

---
  hmp-commands-info.hx  |  10 +-
  target/i386/monitor.c | 230 ++++++++++++++++++++++++++++++++++--------
  2 files changed, 195 insertions(+), 45 deletions(-)
hmp-commands-info.hx +3 -3
index 82134eb6c2..33b4604d11 100644
@@ -188,17 +188,19 @@ ERST
 
      {
          .name       = "tlb",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show virtual to physical memory mappings",
+        .args_type  = "file:s?",
+        .params     = "[file]",
+        .help       = "show virtual to physical memory mappings (optionally save to file)",
          .cmd        = hmp_info_tlb,
          .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \

hmp-commands-info.hx ERST · line 204

Quoted 10 lines
hmp-commands-info.hx +3 -1
                          | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
      },
 
  SRST
-  ``info tlb``
+  ``info tlb`` [*file*]
      Show virtual to physical memory mappings.
+    If *file* is specified, the output is saved to the given file
+    instead of being printed to the monitor.
  ERST

What about passing count or range by argument instead, keeping the

Quoted 1 line

default behavior?

Hi, Philippe:

Your suggestion is good,
I can add several options,
so that users can control the output range and count.

Quoted 4 lines

And just as I described earlier, we should modify the default behavior:
only print the first 32 entries and the last entry.
so that users can know the range while avoiding
the output of all the entries (there are too many).

Quoted 6 lines

A comment in the help warning that they'll get a lot of output would be good as well.

Dave

Hi, Dr.Gilbert,

Good point,
I will add a note to the helper documentation.

Also, per Philippe's feedback on this patch set, I will also pass a range by argument,
so that user can control the number of output items.

Alano.

Quoted 10 lines
Quoted 5 lines

Alano.

Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
\ _________________________|_____ http://www.treblig.org   |_______/