mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 11:04:58 -06:00
target/i386: Make translator stop before the end of a page
Right now translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. An implementation, like the one arm and s390x have, would require an i386 length disassembler, which is burdensome to maintain. Another alternative would be to single-step at the end of a guest page, but this may come with a performance impact. Fix by snapshotting disassembly state and restoring it after we figure out we crossed a page boundary. This includes rolling back cc_op updates and emitted ops. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1143 Message-Id: <20220817150506.592862-4-iii@linux.ibm.com> [rth: Simplify end-of-insn cross-page checks.] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
ab12c95d3f
commit
950936681f
3 changed files with 116 additions and 26 deletions
|
@ -10,6 +10,7 @@ include $(SRC_PATH)/tests/tcg/i386/Makefile.target
|
|||
|
||||
ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
|
||||
X86_64_TESTS += vsyscall
|
||||
X86_64_TESTS += noexec
|
||||
TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64
|
||||
else
|
||||
TESTS=$(MULTIARCH_TESTS)
|
||||
|
@ -23,5 +24,5 @@ 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
|
||||
%: $(SRC_PATH)/tests/tcg/x86_64/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
|
||||
|
|
75
tests/tcg/x86_64/noexec.c
Normal file
75
tests/tcg/x86_64/noexec.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "../multiarch/noexec.c.inc"
|
||||
|
||||
static void *arch_mcontext_pc(const mcontext_t *ctx)
|
||||
{
|
||||
return (void *)ctx->gregs[REG_RIP];
|
||||
}
|
||||
|
||||
int arch_mcontext_arg(const mcontext_t *ctx)
|
||||
{
|
||||
return ctx->gregs[REG_RDI];
|
||||
}
|
||||
|
||||
static void arch_flush(void *p, int len)
|
||||
{
|
||||
}
|
||||
|
||||
extern char noexec_1[];
|
||||
extern char noexec_2[];
|
||||
extern char noexec_end[];
|
||||
|
||||
asm("noexec_1:\n"
|
||||
" movq $1,%rdi\n" /* %rdi is 0 on entry, set 1. */
|
||||
"noexec_2:\n"
|
||||
" movq $2,%rdi\n" /* %rdi is 0/1; set 2. */
|
||||
" ret\n"
|
||||
"noexec_end:");
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct noexec_test noexec_tests[] = {
|
||||
{
|
||||
.name = "fallthrough",
|
||||
.test_code = noexec_1,
|
||||
.test_len = noexec_end - noexec_1,
|
||||
.page_ofs = noexec_1 - noexec_2,
|
||||
.entry_ofs = noexec_1 - noexec_2,
|
||||
.expected_si_ofs = 0,
|
||||
.expected_pc_ofs = 0,
|
||||
.expected_arg = 1,
|
||||
},
|
||||
{
|
||||
.name = "jump",
|
||||
.test_code = noexec_1,
|
||||
.test_len = noexec_end - noexec_1,
|
||||
.page_ofs = noexec_1 - noexec_2,
|
||||
.entry_ofs = 0,
|
||||
.expected_si_ofs = 0,
|
||||
.expected_pc_ofs = 0,
|
||||
.expected_arg = 0,
|
||||
},
|
||||
{
|
||||
.name = "fallthrough [cross]",
|
||||
.test_code = noexec_1,
|
||||
.test_len = noexec_end - noexec_1,
|
||||
.page_ofs = noexec_1 - noexec_2 - 2,
|
||||
.entry_ofs = noexec_1 - noexec_2 - 2,
|
||||
.expected_si_ofs = 0,
|
||||
.expected_pc_ofs = -2,
|
||||
.expected_arg = 1,
|
||||
},
|
||||
{
|
||||
.name = "jump [cross]",
|
||||
.test_code = noexec_1,
|
||||
.test_len = noexec_end - noexec_1,
|
||||
.page_ofs = noexec_1 - noexec_2 - 2,
|
||||
.entry_ofs = -2,
|
||||
.expected_si_ofs = 0,
|
||||
.expected_pc_ofs = -2,
|
||||
.expected_arg = 0,
|
||||
},
|
||||
};
|
||||
|
||||
return test_noexec(noexec_tests,
|
||||
sizeof(noexec_tests) / sizeof(noexec_tests[0]));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue