tci: don't write zero for reloc in tci_out_label
PATCH 1/1 tci: don't write zero for reloc in tci_out_label
If tci_out_label is called in the context of tcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because the set_label is past search_pc, causing a QEMU crash when it tries to branch to a zero label.
Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
--- tcg/tci/tcg-target.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tcg/tci/tcg-target.c +1 -1
@@ -487,7 +487,7 @@ static void tci_out_label(TCGContext *s, TCGArg arg)assert (label->u.value); }else {tcg_out_reloc (s, s->code_ptr,sizeof (tcg_target_ulong), arg,0 ); -tcg_out_i (s,0 ); + s->code_ptr +=sizeof (tcg_target_ulong); } }
Signature · 1 line
1.7.5.4
Am 19.06.2012 04:31, schrieb Scott Wood:
Quoted 7 lines
If
tci_out_labelis called in the context oftcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because theset_labelis pastsearch_pc, causing a QEMU crash when it tries to branch to a zero label.Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
Thanks, this might fix a crash which I have seen from time to time. I'll run tests as soon as possible.
Could you please also look at the other backends?
I saw from git history that ppc once had the same bug. The sparc backend (and maybe others) might still have it.
Regards,
Stefan W.
Quoted 19 lines
Signed-off-by Scott Wood<[email protected]>--- tcg/tci/tcg-target.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)tcg/tci/tcg-target.c +1
-1@@ -487,7 +487,7 @@ static void tci_out_label(TCGContext *s, TCGArg arg)assert (label->u.value); }else {tcg_out_reloc (s, s->code_ptr,sizeof (tcg_target_ulong), arg,0 ); -tcg_out_i (s,0 ); + s->code_ptr +=sizeof (tcg_target_ulong); } }
Quoted 11 lines · Stefan Weil
Am 19.06.2012 04:31, schrieb Scott Wood:
Quoted 7 lines
If
tci_out_labelis called in the context oftcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because theset_labelis pastsearch_pc, causing a QEMU crash when it tries to branch to a zero label.Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
Quoted 7 lines
Thanks, this might fix a crash which I have seen from time to time. I'll run tests as soon as possible.
Could you please also look at the other backends?
I saw from git history that ppc once had the same bug. The sparc backend (and maybe others) might still have it.
Confirmed for Sparc.
Quoted 11 lines
Regards,
Stefan W.Quoted 6 lines
Signed-off-by Scott Wood<[email protected]>---
tcg/tci/tcg-target.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines
tcg/tci/tcg-target.c static void tci_out_label(TCGContext *s, TCGArg arg) · line 490
Quoted 10 lines
tcg/tci/tcg-target.c +1
-1@@ -487,7 +487,7 @@ static void tci_out_label(TCGContext *s, TCGArg arg) assert(label->u.value); } else { tcg_out_reloc(s, s->code_ptr, sizeof(tcg_target_ulong), arg, 0); - tcg_out_i(s, 0); + s->code_ptr += sizeof(tcg_target_ulong);
I like this fix. Other similar fixes rewrote the fixed part of the
opcode and not the label, but the fixed part may cross byte boundaries.
Quoted 4 lines
Quoted 3 lines
tcg/tci/tcg-target.c +0
-0} }
Stefan Weil
Tested-byAm 19.06.2012 20:02, schrieb Blue Swirl:
Quoted 8 lines · Stefan Weil
Quoted 7 lines
Am 19.06.2012 04:31, schrieb Scott Wood:
Quoted 5 lines
If
tci_out_labelis called in the context oftcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because theset_labelis pastsearch_pc, causing a QEMU crash when it tries to branch to a zero label.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
Thanks, this might fix a crash which I have seen from time to time. I'll run tests as soon as possible.
The patch fixes my test scenario with a guest booting a Debian ARM kernel on a x86_64 host (Linux or W64).
The following command crashes while the ARM Linux guest is booting (shortly after "Freeing init memory") with SIGSEGV caused by tb_ptr == 2:
$ qemu-system-arm -M versatilepb -m 192 \
-kernel vmlinuz-3.2.0-2-versatile -initrd initrd.img-3.2.0-2-versatileWith the patch applied, the ARM Linux boots correctly.
Blue, maybe that test also works with a SPARC host.
I have copied the ARM kernel and initrd to http://qemu.weilnetz.de/arm/.
Regards,
Stefan W.
Quoted 40 lines
Quoted 5 lines
Could you please also look at the other backends?
I saw from git history that ppc once had the same bug. The sparc backend (and maybe others) might still have it.
Confirmed for Sparc.
Quoted 11 lines
Regards,
Stefan W.Quoted 6 lines
Signed-off-by Scott Wood<[email protected]>--- tcg/tci/tcg-target.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)Quoted 11 lines
tcg/tci/tcg-target.c static void tci_out_label(TCGContext *s, TCGArg arg) · line 491
Quoted 11 lines
tcg/tci/tcg-target.c +1
-1@@ -487,7 +487,7 @@ static void tci_out_label(TCGContext *s, TCGArg arg)assert (label->u.value); }else {tcg_out_reloc (s, s->code_ptr,sizeof (tcg_target_ulong), arg,0 ); -tcg_out_i (s,0 ); + s->code_ptr +=sizeof (tcg_target_ulong);I like this fix. Other similar fixes rewrote the fixed part of the opcode and not the label, but the fixed part may cross byte boundaries.
Quoted 4 lines
Quoted 3 lines
tcg/tci/tcg-target.c +0
-0} }
Quoted 9 lines · Stefan Weil
Am 19.06.2012 04:31, schrieb Scott Wood:
Quoted 7 lines
If
tci_out_labelis called in the context oftcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because theset_labelis pastsearch_pc, causing a QEMU crash when it tries to branch to a zero label.Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
Quoted 7 lines
Thanks, this might fix a crash which I have seen from time to time. I'll run tests as soon as possible.
Could you please also look at the other backends?
I saw from git history that ppc once had the same bug. The sparc backend (and maybe others) might still have it.
SPARC looks wrong; the others look OK as far as I can tell from a quick glance, without being familiar with all of the architectures.
-Scott
Quoted 6 lines · Scott Wood
Quoted 2 lines · Stefan Weil
I saw from git history that ppc once had the same bug. The sparc backend (and maybe others) might still have it.
SPARC looks wrong; the others look OK as far as I can tell from a quick glance, without being familiar with all of the architectures.
Agreed. I think we fixed most of the others as part of avoiding problems with cache incoherency if you write the branch offset as zero and then rewrite it with the right target at reloc time.
-- PMM
Blue Swirl
AppliedThanks, applied.
Quoted 30 lines · Scott Wood
If
tci_out_labelis called in the context oftcg_gen_code_search_pc, we could be overwriting an already patched relocation with zero -- and not repatch it because theset_labelis pastsearch_pc, causing a QEMU crash when it tries to branch to a zero label.Not writing anything to the relocation area seems to be in line with what other backends do from the couple I looked at (x86, ppc).
Signed-off-by Scott Wood <[email protected]>---
tcg/tci/tcg-target.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)tcg/tci/tcg-target.c +1
-2@@ -487,7 +487,7 @@ static void tci_out_label(TCGContext *s, TCGArg arg) assert(label->u.value); } else { tcg_out_reloc(s, s->code_ptr, sizeof(tcg_target_ulong), arg, 0); - tcg_out_i(s, 0); + s->code_ptr += sizeof(tcg_target_ulong); } } --1.7.5.4