Skip to contentSkip to conversation

i386 translation: fix typo in xsetbv implementation

PATCH In review Dave Hansen 3 participants 3 messages Jul 20, 2016 – Jul 23, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386 translation: fix typo in xsetbv implementation

QEMU 2.6 added support for the XSAVE family of instructions, which includes the XSETBV instruction which allows setting the 'XCR0' register.

But, when booting Linux kernels with XSAVE support enabled, I was getting very early crashes where the instruction pointer was set to 0x3. I tracked it down to a jump instruction generated by this:

	gen_jmp_im(s->pc - pc_start);

where s->pc is pointing to the instruction after XSETBV and pc_start is pointing _at_ XSETBV. Subtract the two and you get 0x3. Whoops.

The fix is to replace this typo with the pattern found everywhere else in the file when folks want to end the translation buffer.

Richard Henderson confirmed that this is a bug and that this is the correct fix.

Cc Paolo Bonzini <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Richard Henderson <[email protected]>
---
 target-i386/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/translate.c +1 -1
index 1a1214d..53a065c 100644
@@ -7170,7 +7170,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
             tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_regs[R_ECX]);
             gen_helper_xsetbv(cpu_env, cpu_tmp2_i32, cpu_tmp1_i64);
             /* End TB because translation flags may change.  */
-            gen_jmp_im(s->pc - pc_start);
+            gen_jmp_im(s->pc - s->cs_base);
             gen_eob(s);
             break;
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Dave Hansen

QEMU 2.6 added support for the XSAVE family of instructions, which includes the XSETBV instruction which allows setting the 'XCR0' register.

But, when booting Linux kernels with XSAVE support enabled, I was getting very early crashes where the instruction pointer was set to 0x3. I tracked it down to a jump instruction generated by this:

	gen_jmp_im(s->pc - pc_start);

where s->pc is pointing to the instruction after XSETBV and pc_start is pointing _at_ XSETBV. Subtract the two and you get 0x3. Whoops.

The fix is to replace this typo with the pattern found everywhere else in the file when folks want to end the translation buffer.

Richard Henderson confirmed that this is a bug and that this is the correct fix.

Quoted 7 lines
Cc Paolo Bonzini <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Richard Henderson <[email protected]>
---
 target-i386/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

r~

#2 lore raw
Quoted 28 lines · Dave Hansen
Quoted 19 lines

QEMU 2.6 added support for the XSAVE family of instructions, which includes the XSETBV instruction which allows setting the 'XCR0' register.

But, when booting Linux kernels with XSAVE support enabled, I was getting very early crashes where the instruction pointer was set to 0x3. I tracked it down to a jump instruction generated by this:

	gen_jmp_im(s->pc - pc_start);

where s->pc is pointing to the instruction after XSETBV and pc_start is pointing _at_ XSETBV. Subtract the two and you get 0x3. Whoops.

The fix is to replace this typo with the pattern found everywhere else in the file when folks want to end the translation buffer.

Richard Henderson confirmed that this is a bug and that this is the correct fix.

Quoted 7 lines
Cc Paolo Bonzini <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Richard Henderson <[email protected]>
---
 target-i386/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line

Thanks, queued and CCed qemu-stable.

Paolo