qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] SH4: Privilege check for instructions


From: Blue Swirl
Subject: Re: [Qemu-devel] [PATCH] SH4: Privilege check for instructions
Date: Sun, 14 Sep 2008 14:26:22 +0300

On 9/14/08, Shin-ichiro KAWASAKI <address@hidden> wrote:
> Thank you for the comment!
>
>  Blue Swirl wrote:
>
> > On 9/14/08, Shin-ichiro KAWASAKI <address@hidden> wrote:
> >
> > > This patch adds check for all SH4 instructions which are
> > >  executed only in privileged mode.
> > >
> >
> > The checks get the privileged mode status from translation context. In
> > theory, the same TB code block could be used in unprivileged and
> > privileged mode, so the status that was true at translation time may
> > no longer be correct at execution time. Of course normally kernel code
> > is not visible or executable to user processes.
> >
>
>  As you say, this patch has the restriction that you pointed out : the
>  generated TB cannot used for both unprivileged and privileged.

Qemu will happily use the same TB for both modes, if the TB flags
match (cpu-exec.c):

    if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base ||
                 tb->flags != flags)) {
        tb = tb_find_slow(pc, cs_base, flags);
    }

>  I guess the codes generated by tcg_gen_qemu_st/ld() have the same
>  restriction, because those tcg_gen functions take the argument QEMU memory
>  index flags, which is decided at translation time.  If it is true, the
>  restriction might be allowed for privilege check.

The loads and stores have the same problem, the generated code assumes
that the privilege mode stays the same as what it was during
translation.

> > The TB flags are handled in cpu-exec.c:tb_find_fast(). If I understand
> > the SH part correctly, the flags copied from env->flags don't contain
> > the privileged mode bits, isn't that in env->sr & SR_MD?
> >
>
>  Right.  In
> target-sh4/translate.c:get_intermediate_code_internal(),
>  the value env->sr & SR_MD used to set ctx->memidx.
>  We can use ctx->memidx to check the privileged mode at translation time,
>  and can use env->sr to check at execution time.  Both implementation
>  can be done, I guess.

But ctx->memidx value will be accurate only if the TB flags contain
the SR_MD bit. Then if the bit is different, a new TB will be
generated using ctx-memidx that reflects the SR_MD bit.

> > Alternatively, the check could be made at execution time, but that's
> > less efficient.
> >
>
>  If QEMU means *quick* emulator, more efficient way seems proper,
>  so my current opinion is that privilege check should be done at
>  translation time.

Right.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]