Skip to contentSkip to conversation

tests/avocado/reverse_debugging: Disable the ppc64 tests by default

PATCH In review Thomas Huth 7 participants 22 messages Nov 14, 2023 – Jan 8, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/avocado/reverse_debugging: Disable the ppc64 tests by default

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
 tests/avocado/reverse_debugging.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tests/avocado/reverse_debugging.py +4 -3
index fc47874eda..2585c78f34 100644
@@ -11,6 +11,7 @@
 import logging
 
 from avocado import skipIf
+from avocado import skipUnless
 from avocado_qemu import BUILD_DIR
 from avocado.utils import gdb
 from avocado.utils import process
@@ -241,8 +242,8 @@ class ReverseDebugging_ppc64(ReverseDebugging):
 
     REG_PC = 0x40
 
-    # unidentified gitlab timeout problem
-    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
+    # Test seems to be broken right now
+    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test gets stuck')
     def test_ppc64_pseries(self):
         """
         :avocado: tags=arch:ppc64
@@ -254,7 +255,7 @@ def test_ppc64_pseries(self):
         self.endian_is_le = False
         self.reverse_debugging()
 
-    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
+    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test often fails')
     def test_ppc64_powernv(self):
         """
         :avocado: tags=arch:ppc64
Signature · 1 line
2.41.0
#2 lore raw
In reply to Thomas Huth
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

#3 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---

  1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 5 lines

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

Thomas

#4 lore raw
Quoted 10 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---

  1 file changed, 4 insertions(+), 3 deletions(-)
Quoted 8 lines
Quoted 5 lines

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"), which causes this halfway through the test:

2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| Traceback (most recent call last):
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/core/decorators.py", line 90, in wrapper
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     return function(obj, *args, **kwargs)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 264, in test_ppc64_powernv
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     self.reverse_debugging()
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 173, in reverse_debugging
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     g.cmd(b'c')
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 783, in cmd
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     response_payload = self.decode(result)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|                        ^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 738, in decode
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     raise InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| avocado.utils.gdb.InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0046 ERROR|

It doesn't always fail the same gdb command
(I saw a bc on line 182 as well). It seems to be receiving a zero length response?

No idea what's happening or why ppc seems to be more fragile. Or why changing console connection affects gdb connection?

Thanks,
Nick

#5 lore raw
Quoted 15 lines · Nicholas Piggin
Quoted 14 lines · Thomas Huth
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Maybe wait the fix gets in first?

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

Thomas

Quoted 28 lines

which causes this halfway through the test:

2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| Traceback (most recent call last):
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/core/decorators.py", line 90, in wrapper
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     return function(obj, *args, **kwargs)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 264, in test_ppc64_powernv
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     self.reverse_debugging()
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 173, in reverse_debugging
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     g.cmd(b'c')
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 783, in cmd
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     response_payload = self.decode(result)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|                        ^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 738, in decode
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     raise InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| avocado.utils.gdb.InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0046 ERROR|

It doesn't always fail the same gdb command
(I saw a bc on line 182 as well). It seems to be receiving a zero length response?

No idea what's happening or why ppc seems to be more fragile. Or why changing console connection affects gdb connection?

Thanks,
Nick

#6 lore raw
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 18 lines
Quoted 18 lines

which causes this halfway through the test:

2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| Traceback (most recent call last):
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/core/decorators.py", line 90, in wrapper
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     return function(obj, *args, **kwargs)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 264, in test_ppc64_powernv
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     self.reverse_debugging()
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/tests/avocado/reverse_debugging.py", line 173, in reverse_debugging
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     g.cmd(b'c')
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 783, in cmd
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     response_payload = self.decode(result)
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|                        ^^^^^^^^^^^^^^^^^^^
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|   File "/home/npiggin/src/qemu/build/pyvenv/lib/python3.11/site-packages/avocado/utils/gdb.py", line 738, in decode
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR|     raise InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0045 ERROR| avocado.utils.gdb.InvalidPacketError
2023-11-15 10:37:04,600 stacktrace       L0046 ERROR|
Quoted 6 lines
Quoted 6 lines

It doesn't always fail the same gdb command
(I saw a bc on line 182 as well). It seems to be receiving a zero length response?

No idea what's happening or why ppc seems to be more fragile. Or why changing console connection affects gdb connection?

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:

if self._console_set:
self._cons_sock_pair = socket.socketpair()

+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);

os.set_inheritable(self._cons_sock_pair[0].fileno(), True)

# NOTE: Make sure any opened resources are *definitely* freed in

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw
Quoted 43 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 6 lines

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
         if self._console_set:
             self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
             os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
         # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

Thanks,
Nick
---

tests/avocado/reverse_debugging.py +5 -0
index fc47874eda..128d85bc0e 100644
@@ -12,6 +12,7 @@
 
 from avocado import skipIf
 from avocado_qemu import BUILD_DIR
+from avocado.utils import datadrainer
 from avocado.utils import gdb
 from avocado.utils import process
 from avocado.utils.network.ports import find_free_port
@@ -52,6 +53,10 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
+        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
+                                    logger=self.log.getChild('console'),
+                                    stop_check=(lambda : not vm.is_running()))
+        console_drainer.start()
         return vm
 
     @staticmethod
#9 lore raw
Quoted 111 lines · Nicholas Piggin
Quoted 43 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

   # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 6 lines

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
        if self._console_set:
            self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
            os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
        # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Quoted 7 lines

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

I think what he is saying is to add a new property for QEMUMachine() with which the test can explicitly tell the machine init code that it is going to drain the console logs. By default it can be false. When tests use console_drainer, they can set the property to true and inspect the early console logs after draining it.

Quoted 28 lines

Thanks,
Nick
---

tests/avocado/reverse_debugging.py +0 -0
index fc47874eda..128d85bc0e 100644
@@ -12,6 +12,7 @@
 

from avocado import skipIf
from avocado_qemu import BUILD_DIR
+from avocado.utils import datadrainer
from avocado.utils import gdb
from avocado.utils import process
from avocado.utils.network.ports import find_free_port

tests/avocado/reverse_debugging.py +4 -0
@@ -52,6 +53,10 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
        if args:
            vm.add_args(*args)
        vm.launch()
+        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
+                                    logger=self.log.getChild('console'),
+                                    stop_check=(lambda : not vm.is_running()))
+        console_drainer.start()
        return vm
 
    @staticmethod
#10 lore raw
Quoted 114 lines · Ani Sinha
Quoted 114 lines · Nicholas Piggin
Quoted 43 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

   # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 6 lines

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
        if self._console_set:
            self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
            os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
        # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

Quoted 6 lines
Quoted 4 lines

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

I think what he is saying is to add a new property for QEMUMachine() with which the test can explicitly tell the machine init code that it is going to drain the console logs. By default it can be false. When tests use console_drainer, they can set the property to true and inspect the early console logs after draining it.

Hmm... well we do have QEMUMachine.set_console already. Is this enough? If the test case is not going to drain or interact with the console then it could set it to false. Or am I missing something?

Thanks,
Nick

#11 lore raw
Quoted 120 lines · Nicholas Piggin
Quoted 119 lines · Ani Sinha
Quoted 118 lines · Nicholas Piggin
Quoted 43 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

   # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 6 lines

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
        if self._console_set:
            self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
            os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
        # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

Quoted 5 lines
Quoted 1 line

I think what he is saying is to add a new property for QEMUMachine() with which the test can explicitly tell the machine init code that it is going to drain the console logs. By default it can be false. When tests use console_drainer, they can set the property to true and inspect the early console logs after draining it.

Hmm... well we do have QEMUMachine.set_console already. Is this enough? If the test case is not going to drain or interact with the console then it could set it to false. Or am I missing something?

Yeah, set_console is enough - i missed that that exists.

Thus problem is more specific. It hits when a test calls set_console(True), but then fails to read from the console.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw
Quoted 127 lines · Daniel P. Berrangé
Quoted 122 lines · Nicholas Piggin
Quoted 120 lines · Ani Sinha
Quoted 111 lines · Nicholas Piggin
Quoted 43 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
 tests/avocado/reverse_debugging.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

  # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

Quoted 6 lines

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
       if self._console_set:
           self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
           os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
       # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Quoted 7 lines

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

I think what he is saying is to add a new property for QEMUMachine() with which the test can explicitly tell the machine init code that it is going to drain the console logs. By default it can be false. When tests use console_drainer, they can set the property to true and inspect the early console logs after draining it.

Quoted 8 lines
Quoted 3 lines

Hmm... well we do have QEMUMachine.set_console already. Is this enough? If the test case is not going to drain or interact with the console then it could set it to false. Or am I missing something?

Yeah, set_console is enough - i missed that that exists.

Thus problem is more specific. It hits when a test calls set_console(True), but then fails to read from the console.

So then it is a test issue in that the test requests console to be enabled but does not look at the console o/p.

Quoted 8 lines

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#13 lore raw
Quoted 90 lines · Ani Sinha
Quoted 90 lines · Daniel P. Berrangé
Quoted 84 lines · Nicholas Piggin
Quoted 73 lines · Ani Sinha
Quoted 73 lines · Nicholas Piggin
Quoted 8 lines · Daniel P. Berrangé

On Wed, Nov 15, 2023 at 01:14:53PM +0000, Daniel P. Berrangé wrote:

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

Quoted 26 lines

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

Review def _pre_launch(self) -> None: · line 369

Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
       if self._console_set:
           self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
           os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
       # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

Quoted 6 lines
Quoted 4 lines

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

I think what he is saying is to add a new property for QEMUMachine() with which the test can explicitly tell the machine init code that it is going to drain the console logs. By default it can be false. When tests use console_drainer, they can set the property to true and inspect the early console logs after draining it.

Hmm... well we do have QEMUMachine.set_console already. Is this enough? If the test case is not going to drain or interact with the console then it could set it to false. Or am I missing something?

Quoted 6 lines
Quoted 4 lines

Yeah, set_console is enough - i missed that that exists.

Thus problem is more specific. It hits when a test calls set_console(True), but then fails to read from the console.

So then it is a test issue in that the test requests console to be enabled but does not look at the console o/p.

Yes, any test cases affected by this are broken already, and need to drain the console. We might easily miss if we only test with x86_64 QEMU and not other arches, as eg ppc firmware appears more chatty on serial port than seabios

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author Tested-by
#14 lore raw
In reply to Nicholas Piggin
Quoted 2 lines · Nicholas Piggin
Quoted 1 line · Daniel P. Berrangé

On Wed, Nov 15, 2023 at 01:14:53PM +0000, Daniel P. Berrangé wrote:

...

Quoted 36 lines
Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

Thanks,
Nick
---

tests/avocado/reverse_debugging.py +1 -0
index fc47874eda..128d85bc0e 100644
@@ -12,6 +12,7 @@
 
  from avocado import skipIf
  from avocado_qemu import BUILD_DIR
+from avocado.utils import datadrainer
  from avocado.utils import gdb
  from avocado.utils import process
  from avocado.utils.network.ports import find_free_port

tests/avocado/reverse_debugging.py def run_vm(self, record, shift, args, replay_path, image_path, port): · line 62

Quoted 10 lines
tests/avocado/reverse_debugging.py +4 -0
@@ -52,6 +53,10 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
          if args:
              vm.add_args(*args)
          vm.launch()
+        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
+                                    logger=self.log.getChild('console'),
+                                    stop_check=(lambda : not vm.is_running()))
+        console_drainer.start()
          return vm
 
      @staticmethod

Could you please send this as a proper patch, with a S-o-b line, and a short comment in front of the newly added code explaining it?

Thanks,
Thomas

#15 lore raw
Quoted 49 lines · Thomas Huth
Quoted 2 lines · Nicholas Piggin
Quoted 1 line · Daniel P. Berrangé

On Wed, Nov 15, 2023 at 01:14:53PM +0000, Daniel P. Berrangé wrote:

...

Quoted 45 lines
Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

Thanks,
Nick
---

tests/avocado/reverse_debugging.py +5 -0
index fc47874eda..128d85bc0e 100644
@@ -12,6 +12,7 @@
 
  from avocado import skipIf
  from avocado_qemu import BUILD_DIR
+from avocado.utils import datadrainer
  from avocado.utils import gdb
  from avocado.utils import process
  from avocado.utils.network.ports import find_free_port
@@ -52,6 +53,10 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
          if args:
              vm.add_args(*args)
          vm.launch()
+        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
+                                    logger=self.log.getChild('console'),
+                                    stop_check=(lambda : not vm.is_running()))
+        console_drainer.start()
          return vm
 
Quoted 3 lines

tests/avocado/reverse_debugging.py def run_vm(self, record, shift, args, replay_path, image_path, port): · line 62

Quoted 1 line
tests/avocado/reverse_debugging.py +0 -0
      @staticmethod

Thank you.

Quoted 2 lines

Could you please send this as a proper patch, with a S-o-b line, and a short comment in front of the newly added code explaining it?

Yep, just testing it now. Should have it sent out in an hour or two.

Thanks,
Nick

#16 lore raw
In reply to Nicholas Piggin
Quoted 47 lines · Nicholas Piggin
Quoted 46 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

Quoted 8 lines
Quoted 3 lines

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

Great work.

Why does this make the gdb socket give an empty response? Something just times out?

There's no empty response - avocado is sending SIGTERM to the test because no response ever arrived after 10 seconds

Quoted 10 lines
Quoted 10 lines
(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
         if self._console_set:
             self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
             os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
Quoted 4 lines

Review def _pre_launch(self) -> None: · line 369

Quoted 1 line
(quoted diff) +0 -0
         # NOTE: Make sure any opened resources are *definitely* freed in

So perhaps ppc64 fails just because it prints more to the console in early boot than other targets?

Yes, that's exactly it - the ppc firmware is very verbose, so is enough to tip it over the limit.

Quoted 36 lines
Quoted 10 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

The below patch makes this test work. Maybe as a quick fix it is better than disabling the test.

I guess we still have a problem if a test invokes vm.launch() directly without subsequently waiting for a console pattern or doing something with the console as you say. Your suggesstion is add something like vm.launch(console=True) ?

Thanks,
Nick
---

tests/avocado/reverse_debugging.py +1 -0
index fc47874eda..128d85bc0e 100644
@@ -12,6 +12,7 @@
 
 from avocado import skipIf
 from avocado_qemu import BUILD_DIR
+from avocado.utils import datadrainer
 from avocado.utils import gdb
 from avocado.utils import process
 from avocado.utils.network.ports import find_free_port

tests/avocado/reverse_debugging.py def run_vm(self, record, shift, args, replay_path, image_path, port): · line 62

Quoted 10 lines
tests/avocado/reverse_debugging.py +4 -0
@@ -52,6 +53,10 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
+        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
+                                    logger=self.log.getChild('console'),
+                                    stop_check=(lambda : not vm.is_running()))
+        console_drainer.start()
         return vm
 
     @staticmethod

Yes, thus should do the trick.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#17 lore raw
In reply to Daniel P. Berrangé
Quoted 91 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
  tests/avocado/reverse_debugging.py | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

   # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
        if self._console_set:
            self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
            os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
        # NOTE: Make sure any opened resources are *definitely* freed in
Quoted 5 lines

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

As in https://gitlab.com/qemu-project/qemu/-/blob/master/tests/avocado/acpi-bits.py?ref_type=heads#L395 ? Some other tests do this too.

Quoted 13 lines

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#18 lore raw
In reply to Daniel P. Berrangé
Quoted 91 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
         if self._console_set:
             self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
             os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
         # NOTE: Make sure any opened resources are *definitely* freed in

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

Quoted 7 lines

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Tch. I see. Thank you for diagnosing this.

From the machine.py perspective, you have to *opt in* to having a console, so I hadn't considered that a caller would enable the console and then ... not read from it. Surely that's a bug in the caller?

If you don't intend to read from the console, you shouldn't call set_console().

(The async rewrite I have been toying with on and off has a built-in drainer that writes to a log file that would probably remedy this, but the client tests should still be fixed, I think. Otherwise, do you have any suggestions for how I might make this failure state more obvious/friendly? I wonder if on close of the machine.py object I could detect that the pipe is full and emit a warning about that.)

--js

Quoted 8 lines

With regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#19 lore raw
Quoted 102 lines · John Snow
Quoted 91 lines · Daniel P. Berrangé
Quoted 34 lines · Daniel P. Berrangé
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nicholas Piggin
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Thomas Huth

The tests seem currently to be broken. Disable them by default until someone fixes them.

---
   tests/avocado/reverse_debugging.py | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)

Similarly, I suspect https://gitlab.com/qemu-project/qemu/-/issues/1961
which has a fix ready:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe wait the fix gets in first?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, I applied Richard's patch, but the problem persists. Does this test still work for you?

I bisected it to 1d4796cd008373 ("python/machine: use socketpair() for console connections"),

Maybe John (who wrote that commit) can help?

I find it hard to believe this commit is a direct root cause of the problem since all it does is change the QEMU startup sequence so that instead of QEMU listening for a monitor connection, it is given a pre-opened monitor connection.

At the very most that should affect the startup timing a little.

Quoted 7 lines

I notice all the reverse debugging tests have a skip on gitlab with a comment:

    # unidentified gitlab timeout problem

this makes be suspicious that John's patch has merely made this (henceforth undiagnosed) timeout more likely to ocurr.

After an absolutely horrendous hours long debugging session I think I figured out the problem. The QEMU process is blocking in

qemu_chr_write_buffer

spinning in the loop on EAGAIN.

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

Before John's change, the serial port uses a chardev in server mode and crucially 'wait=off', and the Machine() class never opened the console socket unless the test case wanted to read from it.

IOW, QEMU had a background job setting there waiting for a connection that would never come.

As a result when QEMU started executing the guest, all the serial port writes get sent into to the void.

So John's patch has had a semantic change in behaviour, because the console socket is permanently open, and thus socket buffers are liable to fill up.

As a demo I increased the socket buffers to 1MB and everything then succeeded.

(quoted diff) +4 -0
@@ -357,6 +360,10 @@ def _pre_launch(self) -> None:
 
         if self._console_set:
             self._cons_sock_pair = socket.socketpair()
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[0].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024);
+            self._cons_sock_pair[1].setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024*1024);
             os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
 
         # NOTE: Make sure any opened resources are *definitely* freed in

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

Quoted 7 lines

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Tch. I see. Thank you for diagnosing this.

Quoted 5 lines

From the machine.py perspective, you have to *opt in* to having a console, so I hadn't considered that a caller would enable the console and then ... not read from it. Surely that's a bug in the caller?

If you don't intend to read from the console, you shouldn't call set_console().

Agree, hence the fix patch for the test case.

Although most tests wait for console, ones like this that control the machine with gdb/qmp are rarer, so less examples to copy paste from.

Quoted 4 lines

(The async rewrite I have been toying with on and off has a built-in drainer that writes to a log file that would probably remedy this, but the client tests should still be fixed, I think. Otherwise, do you

This sounds good because no matter the test, you rarely don't want to log console output. Separating that from what the test does with console would be nice.

Quoted 3 lines

have any suggestions for how I might make this failure state more obvious/friendly? I wonder if on close of the machine.py object I could detect that the pipe is full and emit a warning about that.)

That's an idea. It wouldn't be foolproof (test could be waiting for something else or failed for some other reason), but at least it could give a suggestion (similar to my warning in the chardev code).

How would you do it? Maybe the simplest/portable way would be keep a pipe write fd open in the harness and try write something to it with O_NONBLOCK?

Thanks,
Nick

#20 lore raw
In reply to John Snow
Quoted 18 lines · John Snow
Quoted 8 lines · Daniel P. Berrangé

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

Quoted 7 lines

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Quoted 5 lines

Tch. I see. Thank you for diagnosing this.

From the machine.py perspective, you have to *opt in* to having a console, so I hadn't considered that a caller would enable the console and then ... not read from it. Surely that's a bug in the caller?

From an Avocado test perspective, I would expect that the test case should have to explicitly opt *out* of "the console messages appear in the avocado test log, even if the test case doesn't care about them for the purposes of identifying when to end the test or whatever". The console logs are important for after-the-fact human diagnosis of why a test might have failed, so we should always collect them.

thanks
-- PMM

#21 lore raw
Quoted 33 lines · Peter Maydell
Quoted 18 lines · John Snow
Quoted 8 lines · Daniel P. Berrangé

The Python Machine() class has passed one of a pre-created socketpair FDs for the serial port chardev. The guest is trying to write to this and blocking. Nothing in the Machine() class is reading from the other end of the serial port console.

The Machine class doesn't know if anything will ever use the console, so as is the change is unsafe.

Quoted 7 lines

The original goal of John's change was to guarantee we capture early boot messages as some test need that.

I think we need to be able to have a flag to say whether the caller needs an "early console" facility, and only use the pre-opened FD passing for that case. Tests we need early console will have to ask for that guarantee explicitly.

Quoted 5 lines

Tch. I see. Thank you for diagnosing this.

From the machine.py perspective, you have to *opt in* to having a console, so I hadn't considered that a caller would enable the console and then ... not read from it. Surely that's a bug in the caller?

From an Avocado test perspective, I would expect that the test case should have to explicitly opt *out* of "the console messages appear in the avocado test log, even if the test case doesn't care about them for the purposes of identifying when to end the test or whatever". The console logs are important for after-the-fact human diagnosis of why a test might have failed, so we should always collect them.

Quoted 3 lines

thanks
-- PMM

Understood. In that case, fixing the test would involve engaging's the avocado suite's draining utility to ensure that the log is being consumed and logged.

I think there's a potential here to simplify all of the draining-and-logging code we have split across the avocado test suite, console_socket.py and machine.py, but I can't promise that the rewrite I've been working on will be ready quickly, so if this is still busted (I'm still catching back up with my mail post-holidays) then we want a quicker fix if we haven't committed one yet.

--js