linux-user/s390x: Fix single-stepping SVC
PATCH 2/2 tests/tcg/s390x: Test single-stepping SVC
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.target | 11 ++++- tests/tcg/s390x/gdbstub/test-svc.py | 64 +++++++++++++++++++++++++++++ tests/tcg/s390x/hello-s390x-asm.S | 20 +++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/gdbstub/test-svc.py create mode 100644 tests/tcg/s390x/hello-s390x-asm.S
tests/tcg/s390x/Makefile.target +10 -1
@@ -74,7 +74,16 @@ run-gdbstub-signals-s390x: signals-s390x --bin $< --test $(S390X_SRC)/gdbstub/test-signals-s390x.py, \ mixing signals and debugging) -EXTRA_RUNS += run-gdbstub-signals-s390x +hello-s390x-asm: CFLAGS+=-nostdlib + +run-gdbstub-svc: hello-s390x-asm + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(S390X_SRC)/gdbstub/test-svc.py, \ + single-stepping svc) + +EXTRA_RUNS += run-gdbstub-signals-s390x run-gdbstub-svc endif # MVX versions of sha512
tests/tcg/s390x/gdbstub/test-svc.py new file +64 -0
64 lines not on this page · raw message
tests/tcg/s390x/hello-s390x-asm.S new file +20 -0
@@ -0,0 +1,20 @@ +/* + * Hello, World! in assembly. + */ + +.globl _start +_start: + +/* puts("Hello, World!"); */ +lghi %r2,1 +larl %r3,foo +lghi %r4,foo_end-foo +svc 4 + +/* exit(0); */ +xgr %r2,%r2 +svc 1 + +.align 2 +foo: .asciz "Hello, World!\n" +foo_end:
Signature · 1 line
2.40.1
cover linux-user/s390x: Fix single-stepping SVC
Hi,
I noticed that single-stepping SVC runs two instructions instead of one. The reason is that EXCP_SVC masks EXCP_DEBUG.
Patch 1 fixes this problem, patch 2 adds a test.
Btw, there is at least one more problem in that area, namely single-stepping instructions that cause e.g. SIGILL. Using the existing signals-s390x test as an example:
(gdb) x/i $pc
=> 0x1001740 <illegal_op>: .long 0x000007fe
(gdb) si
Program received signal SIGILL, Illegal instruction.
(gdb) x/i $pc
=> 0x1001742 <after_illegal_op>: br %r14
# So far so good.
(gdb) si
(gdb) x/i $pc
=> 0x10017b6 <handle_signal+6>: lay %r15,-344(%r15)
# Missed the first signal handler instruction!I'm not sure what to do about it - the trivial fix to add gdb_handlesig(cpu, 0) to the end of handle_pending_signal() caused GDB to hang, and I haven't looked further yet.
Best regards,
Ilya
Ilya Leoshkevich (2):
linux-user/s390x: Fix single-stepping SVC
tests/tcg/s390x: Test single-stepping SVC
linux-user/s390x/cpu_loop.c | 9 ++++ tests/tcg/s390x/Makefile.target | 11 ++++- tests/tcg/s390x/gdbstub/test-svc.py | 64 +++++++++++++++++++++++++++++ tests/tcg/s390x/hello-s390x-asm.S | 20 +++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/gdbstub/test-svc.py create mode 100644 tests/tcg/s390x/hello-s390x-asm.S
Signature · 1 line
2.40.1
PATCH 1/2 linux-user/s390x: Fix single-stepping SVC
Currently single-stepping SVC executes two instructions. The reason is that EXCP_DEBUG for the SVC instruction itself is masked by EXCP_SVC. Fix by re-raising EXCP_DEBUG.
--- linux-user/s390x/cpu_loop.c | 9 +++++++++ 1 file changed, 9 insertions(+)
linux-user/s390x/cpu_loop.c +9 -0
@@ -86,6 +86,15 @@ void cpu_loop(CPUS390XState *env) }else if (ret != -QEMU_ESIGRETURN ) { env->regs[2 ] = ret; } + +if (unlikely (cs->singlestep_enabled)) { +/* +* cpu_tb_exec() did not raise EXCP_DEBUG, because it has seen +* that EXCP_SVC was already pending. +*/ + cs->exception_index =EXCP_DEBUG ; + } +break ;case EXCP_DEBUG :
Signature · 1 line
2.40.1
Re: [PATCH 2/2] tests/tcg/s390x: Test single-stepping SVC
In reply to Ilya LeoshkevichQuoted 3 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 3 lines · Ilya Leoshkevich
Currently single-stepping SVC executes two instructions. The reason is that
EXCP_DEBUGfor the SVC instruction itself is masked byEXCP_SVC. Fix by re-raisingEXCP_DEBUG.
Is it a -stable material?
/mjt
Quoted 10 lines · Michael Tokarev
Quoted 5 lines · Ilya Leoshkevich
Currently single-stepping SVC executes two instructions. The reason is
thatEXCP_DEBUGfor the SVC instruction itself is masked byEXCP_SVC.
Fix by re-raisingEXCP_DEBUG.Is it a -stable material?
/mjt
While I would personally love to see this in -stable, I don't think it fits the official criteria - it's not a security fix and it's not a regression.
Quoted 7 lines · Ilya Leoshkevich
Quoted 1 line · Michael Tokarev
Is it a -stable material?
While I would personally love to see this in -stable, I don't think it fits the official criteria - it's not a security fix and it's not a regression.
I'm not sure I follow. It's definitely okay to include a bug fix into -stable, this has been done countless times in the past..
/mjt
Quoted 10 lines · Michael Tokarev
Quoted 8 lines · Ilya Leoshkevich
Quoted 1 line · Michael Tokarev
Is it a -stable material?
While I would personally love to see this in -stable, I don't think it
fits the official criteria - it's not a security fix and it's not a regression.
Quoted 4 lines
I'm not sure I follow. It's definitely okay to include a bug fix into -stable, this has been done countless times in the past..
/mjt
Okay, then let's include it into -stable.
It's just that I'm not too familiar with the QEMU -stable process, so I read [1], and it sounded quite strict.
[1] https://www.qemu.org/docs/master/devel/stable-process.html
Quoted 6 lines · Ilya Leoshkevich
Quoted 5 lines
Quoted 3 lines · Ilya Leoshkevich
While I would personally love to see this in -stable, I don't think it fits the official criteria - it's not a security fix and it's not a regression.
Quoted 6 lines
Okay, then let's include it into -stable.
It's just that I'm not too familiar with the QEMU -stable process, so I read [1], and it sounded quite strict.
[1] https://www.qemu.org/docs/master/devel/stable-process.html
The text there reads:
If you think the patch would be important for users of the current release (or for a distribution picking fixes), it is usually a good candidate for stable.
:)
Please Cc: [email protected] the next time you think something is good to have there.
/mjt
Quoted 28 lines · Ilya Leoshkevich
Hi,
I noticed that single-stepping SVC runs two instructions instead of one. The reason is that
EXCP_SVCmasksEXCP_DEBUG.
Patch 1 fixes this problem, patch 2 adds a test.Btw, there is at least one more problem in that area, namely single-stepping instructions that cause e.g. SIGILL. Using the existing signals-s390x test as an example:
(gdb) x/i $pc => 0x1001740 <illegal_op>: .long 0x000007fe (gdb) si Program received signal SIGILL, Illegal instruction. (gdb) x/i $pc => 0x1001742 <after_illegal_op>: br %r14 # So far so good. (gdb) si (gdb) x/i $pc => 0x10017b6 <handle_signal+6>: lay %r15,-344(%r15) # Missed the first signal handler instruction!I'm not sure what to do about it - the trivial fix to add
gdb_handlesig(cpu, 0)to the end ofhandle_pending_signal()caused GDB to hang, and I haven't looked further yet.
Quoted 6 lines
Best regards,
IlyaIlya Leoshkevich (2):
linux-user/s390x: Fix single-stepping SVC tests/tcg/s390x: Test single-stepping SVC
If there are no disagreements, I can take this through my s390x tree. Queued it for my next pull request now.
Thomas
Re: [PATCH 2/2] tests/tcg/s390x: Test single-stepping SVC
In reply to Ilya LeoshkevichQuoted 4 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>---
...
Quoted 7 lines
tests/tcg/s390x/hello-s390x-asm.S new file +1
-0@@ -0,0 +1,20 @@ +/*
tests/tcg/s390x/hello-s390x-asm.S line 11
Quoted 10 lines
tests/tcg/s390x/hello-s390x-asm.S new file +10
-0+ * Hello, World! in assembly. + */ + +.globl _start +_start: + +/* puts("Hello, World!"); */ +lghi %r2,1 +larl %r3,foo +lghi %r4,foo_end-foo
Hi Ilya!
While testing your other currently pending s390x TCG patches, I noticed that this is failing with Clang (v16.0.1):
tests/tcg/s390x/hello-s390x-asm.S:11:10: error: invalid operand for instruction lghi %r4,foo_end-foo
^
make[1]: *** [Makefile:121: hello-s390x-asm] Error 1
Any ideas how to fix this?
Thomas