qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
To: Peter Maydell <peter.maydell@linaro.org>,
	"Konopik, Andreas" <andreas.konopik@fau.de>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	qemu-discuss <qemu-discuss@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-discuss] Segmentation fault on target tricore
Date: Wed, 18 Sep 2019 17:54:18 +0200	[thread overview]
Message-ID: <c60f34de-daef-3985-9bce-b780611222e7@mail.uni-paderborn.de> (raw)
In-Reply-To: <CAFEAcA8q=QvwroUA3XQji5bqR5W4nXR=oUxbA16J0qP4Ch5sjA@mail.gmail.com>

Hi Peter,

On 9/17/19 3:45 PM, Peter Maydell wrote:
> On Tue, 17 Sep 2019 at 14:06, Konopik, Andreas <andreas.konopik@fau.de> wrote:
>>>> Using gdb and valgrind I found out that:
>>>> - 'gen_mtcr()' and 'gen_mfcr()' access uninitialized values, i.e.
>>>> CSFRs,
>>>> which leads to the Segfault
>>>> - The uninitialised values were created by stack allocation of
>>>> DisasContext in 'gen_intermediate_code()'
>>> This definitely sounds like a bug: do you have a stack
>>> backtrace from valgrind or gdb of the bad access and the
>>> segfault?
>>>
>>> [...]
>>> Thread 3 "qemu-system-tri" received signal SIGSEGV, Segmentation fault.
>>> [Switching to Thread 0x7ffff10a4700 (LWP 146730)]
>>> 0x00005555556edb67 in gen_mfcr (ret=0xab0, offset=<optimized out>,
>>>     ctx=<optimized out>)
>>>     at /home/akonopik/qemu_src/target/tricore/cpu.h:274
>>> 274       return (env->features & (1ULL << feature)) != 0;
>>> (gdb) bt
>>> #0  0x00005555556edb67 in gen_mfcr
>>>     (ret=0xab0, offset=<optimized out>, ctx=<optimized out>)
>>>     at /home/akonopik/qemu_src/target/tricore/cpu.h:274
> It looks like tricore_tr_init_disas_context() isn't
> initializing ctx->env. If this is the problem then this
> patch ought to fix it:
>
> diff --git a/target/tricore/translate.c b/target/tricore/translate.c
> index c574638c9f7..305d896cd2c 100644
> --- a/target/tricore/translate.c
> +++ b/target/tricore/translate.c
> @@ -8793,6 +8793,7 @@ static void
> tricore_tr_init_disas_context(DisasContextBase *dcbase,
>       CPUTriCoreState *env = cs->env_ptr;
>       ctx->mem_idx = cpu_mmu_index(env, false);
>       ctx->hflags = (uint32_t)ctx->base.tb->flags;
> +    ctx->env = env;
>   }
>
>   static void tricore_tr_tb_start(DisasContextBase *db, CPUState *cpu)

thanks for the patch. I'll add it to my queue.


>
>
> Aside to Bastian: passing the CPU env pointer into the
> DisasContext isn't ideal, because it makes it quite easy
> for translate.c code to accidentally use fields of the
> env struct that aren't valid for use at translate time.
> I think the only uses of ctx->env you have are for checking
> feature bits -- I recommend following what target/arm does here:
>   * in tricore_tr_init_disas_context(), instead of copying the
>     env pointer, just copy env->features into ctx->features
>   * have a tricore_dc_feature(DisasContext *dc, int feature)
>     that checks for the feature bit in dc->features
>
> That way you only have access in translate.c code to
> information that's safe to bake into generated code, and
> it's harder to accidentally introduce bugs where generated
> code depends on CPU state that isn't kept in the TB flags.


Yes, this is not intended to stay this way. However, it was a necessary 
change for the translate_loop conversion. I'll try removing ctx->env 
from TriCore.

Cheers,

Bastian


>
> thanks
> -- PMM
>


  reply	other threads:[~2019-09-18 16:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9cf47438fa943b28ee987cea7b76a459@fau.de>
2019-09-17 12:32 ` [Qemu-devel] [Qemu-discuss] Segmentation fault on target tricore Peter Maydell
2019-09-17 13:06   ` Konopik, Andreas
2019-09-17 13:45     ` Peter Maydell
2019-09-18 15:54       ` Bastian Koppelmann [this message]
2019-09-17 13:07   ` Bastian Koppelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c60f34de-daef-3985-9bce-b780611222e7@mail.uni-paderborn.de \
    --to=kbastian@mail.uni-paderborn.de \
    --cc=andreas.konopik@fau.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-discuss@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).