target/i386: Make sure that vsyscall's tb->size != 0
cover target/i386: Make sure that vsyscall's tb->size != 0
This series for the s390-next tree fixes [1]. Patch 1 is the fix, patch 2 is the new test to avoid similar regressions in the future.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2021-05/msg02962.html
Ilya Leoshkevich (2):
target/i386: Make sure that vsyscall's tb->size != 0 tests/tcg/x86_64: add vsyscall smoke test
target/i386/tcg/translate.c | 1 + tests/tcg/x86_64/Makefile.target | 6 +++++- tests/tcg/x86_64/vsyscall.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/x86_64/vsyscall.c
Signature · 1 line
2.29.2
PATCH 1/2 target/i386: Make sure that vsyscall's tb->size != 0
tb_gen_code() assumes that tb->size must never be zero, otherwise it may produce spurious exceptions. For x86_64 this may happen when creating a translation block for the vsyscall page.
Fix by pretending that vsyscall translation blocks have at least one instruction.
--- target/i386/tcg/translate.c | 1 + 1 file changed, 1 insertion(+)
target/i386/tcg/translate.c +1 -0
@@ -8572,6 +8572,7 @@ static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)*/ if ((dc->base.pc_next &TARGET_PAGE_MASK ) ==TARGET_VSYSCALL_PAGE ) {gen_exception (dc,EXCP_VSYSCALL , dc->base.pc_next); + dc->base.pc_next = dc->pc +1 ;return ; }#endif
Signature · 1 line
2.29.2
Quoted 11 lines · Ilya Leoshkevich
tb_gen_code()assumes thattb->sizemust never be zero, otherwise it may produce spurious exceptions. Forx86_64this may happen when creating a translation block for the vsyscall page.Fix by pretending that vsyscall translation blocks have at least one instruction.
Signed-off-by Ilya Leoshkevich<[email protected]>--- target/i386/tcg/translate.c | 1 + 1 file changed, 1 insertion(+)
r~
PATCH 2/2 tests/tcg/x86_64: add vsyscall smoke test
In reply to Ilya LeoshkevichHaving a small test will prevent trivial regressions in the future.
--- tests/tcg/x86_64/Makefile.target | 6 +++++- tests/tcg/x86_64/vsyscall.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/x86_64/vsyscall.c
tests/tcg/x86_64/Makefile.target +5 -1
@@ -3,14 +3,18 @@ # x86_64 tests - included from tests/tcg/Makefile.target # # Currently we only build test-x86_64 and test-i386-ssse3 from -# $(SRC)/tests/tcg/i386/ +# $(SRC_PATH)/tests/tcg/i386/ # include $(SRC_PATH)/tests/tcg/i386/Makefile.target +X86_64_TESTS += vsyscall TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 QEMU_OPTS += -cpu max test-x86_64: LDFLAGS+=-lm -lc test-x86_64: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) + +vsyscall: $(SRC_PATH)/tests/tcg/x86_64/vsyscall.c + $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
tests/tcg/x86_64/vsyscall.c new file +11 -0
@@ -0,0 +1,11 @@ +#include <stdio.h> +#include <time.h> + +#define VSYSCALL_PAGE 0xffffffffff600000 +#define TIME_OFFSET 0x400 +typedef time_t (*time_func )(time_t *); + +int main (void ) +{ +printf ("%ld\n" , ((time_func)(VSYSCALL_PAGE +TIME_OFFSET ))(NULL )); +}
Signature · 1 line
2.29.2
Re: [PATCH 2/2] tests/tcg/x86_64: add vsyscall smoke test
Quoted 8 lines · Ilya Leoshkevich
Having a small test will prevent trivial regressions in the future.
Signed-off-by Ilya Leoshkevich<[email protected]>--- tests/tcg/x86_64/Makefile.target | 6 +++++- tests/tcg/x86_64/vsyscall.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)create mode 100644
tests/tcg/x86_64/vsyscall.c
r~
Re: [PATCH 2/2] tests/tcg/x86_64: add vsyscall smoke test
In reply to Ilya LeoshkevichQuoted 16 lines · On Wed, 12 May 2021 06:02:50 +0200 Ilya Leoshkevich <[email protected]> wrote:
Having a small test will prevent trivial regressions in the future.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/x86_64/Makefile.target | 6 +++++- tests/tcg/x86_64/vsyscall.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/x86_64/vsyscall.ctests/tcg/x86_64/vsyscall.c new file +1
-0@@ -0,0 +1,11 @@ +#include <stdio.h>
tests/tcg/x86_64/vsyscall.c line 11
Quoted 10 lines
tests/tcg/x86_64/vsyscall.c new file +10
-0+#include <time.h> + +#define VSYSCALL_PAGE 0xffffffffff600000 +#define TIME_OFFSET 0x400 +typedef time_t (*time_func )(time_t *); + +int main (void ) +{ +printf ("%ld\n" , ((time_func)(VSYSCALL_PAGE +TIME_OFFSET ))(NULL )); +}
Fails in https://gitlab.com/cohuck/qemu/-/jobs/1267727559 ("error:
control reaches end of non-void function").
Re: [PATCH 2/2] tests/tcg/x86_64: add vsyscall smoke test
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Wed, 12 May 2021 06:02:50 +0200 Ilya Leoshkevich <[email protected]> wrote:
Having a small test will prevent trivial regressions in the future.
Signed-off-by Ilya Leoshkevich <[email protected]>---
tests/tcg/x86_64/Makefile.target | 6 +++++- tests/tcg/x86_64/vsyscall.c | 11 +++++++++++2 files changed, 16 insertions(+), 1 deletion(-)create mode 100644
tests/tcg/x86_64/vsyscall.ctests/tcg/x86_64/vsyscall.c new file +7
-0@@ -0,0 +1,11 @@ +#include <stdio.h> +#include <time.h> + +#define VSYSCALL_PAGE 0xffffffffff600000 +#define TIME_OFFSET 0x400 +typedef time_t (*time_func )(time_t *); +
Quoted 8 lines
Quoted 5 lines
tests/tcg/x86_64/vsyscall.c new file +3
-0+int main (void ) +{ + printf("%ld\n", ((time_func)(VSYSCALL_PAGE +TIME_OFFSET))(NULL));
+}Fails in https://gitlab.com/cohuck/qemu/-/jobs/1267727559 ("error:
control reaches end of non-void function").
I always thought that omitting return in main() is allowed, but turns out this is a C99-only thing. I should have probably used make docker-all-tests instead of just make check to catch this.
I will send a v2.