From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Keopg-00046d-Fo for qemu-devel@nongnu.org; Sun, 14 Sep 2008 06:27:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Keopd-00045y-NF for qemu-devel@nongnu.org; Sun, 14 Sep 2008 06:27:54 -0400 Received: from [199.232.76.173] (port=46750 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Keopb-00045g-5D for qemu-devel@nongnu.org; Sun, 14 Sep 2008 06:27:51 -0400 Received: from vsmtp02.dti.ne.jp ([202.216.231.137]:49404) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KeopZ-0000HM-Qq for qemu-devel@nongnu.org; Sun, 14 Sep 2008 06:27:50 -0400 Received: from [192.168.1.21] (PPPa1372.e11.eacc.dti.ne.jp [124.255.91.108]) by vsmtp02.dti.ne.jp (3.11v) with ESMTP AUTH id m8EARlDZ016091 for ; Sun, 14 Sep 2008 19:27:47 +0900 (JST) Message-ID: <48CCE727.7000203@juno.dti.ne.jp> Date: Sun, 14 Sep 2008 19:27:51 +0900 From: Shin-ichiro KAWASAKI MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] SH4: Privilege check for instructions References: <48CC8D3E.1040401@juno.dti.ne.jp> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Thank you for the comment! Blue Swirl wrote: > On 9/14/08, Shin-ichiro KAWASAKI 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. 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 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. > 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. Anyway I'm not yet sure about QEMU internal. More comments will be welcome! Best Regards, Shin-ichiro KAWASAKI