Received: from eggs.gnu.org ([140.186.70.92]:35111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtwAp-0004mW-7e for qemu-devel@nongnu.org; Thu, 18 Aug 2011 02:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QtwAo-0007yA-2K for qemu-devel@nongnu.org; Thu, 18 Aug 2011 02:33:51 -0400 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:35760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtwAm-0007xZ-VI for qemu-devel@nongnu.org; Thu, 18 Aug 2011 02:33:49 -0400 Received: from csmailer.cs.nctu.edu.tw (localhost [127.0.0.1]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 0E630B0A for ; Thu, 18 Aug 2011 14:33:09 +0800 (CST) Received: from alumni.cs.nctu.edu.tw (alumni.cs.nctu.edu.tw [140.113.235.116]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 056FFB09 for ; Thu, 18 Aug 2011 14:33:09 +0800 (CST) Received: (from chenwj@localhost) by alumni.cs.nctu.edu.tw (8.14.4/8.14.4/Submit) id p7I6XcAb081151 for qemu-devel@nongnu.org; Thu, 18 Aug 2011 14:33:39 +0800 (CST) (envelope-from chenwj) Date: Thu, 18 Aug 2011 14:33:38 +0800 From: =?utf-8?B?6Zmz6Z+L5Lu7?= Message-ID: <20110818063338.GA69924@cs.nctu.edu.tw> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] The reason behind block linking constraint? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, all I am trying to figure out why QEMU put some constraints on block linking (chaining). Take x86 as an example, there are two places put constraints on block linking, gen_goto_tb and cpu_exec. ----------------- gen_goto_tb (target-i386/translate.c) --------------- /* NOTE: we handle the case where the TB spans two pages here */ if ((pc & TARGET_PAGE_MASK) =3D=3D (tb->pc & TARGET_PAGE_MASK) || (pc & TARGET_PAGE_MASK) =3D=3D ((s->pc - 1) & TARGET_PAGE_MASK)) { /* jump to same page: we can use a direct jump */ tcg_gen_goto_tb(tb_num); gen_jmp_im(eip); tcg_gen_exit_tb((tcg_target_long)tb + tb_num); } else { /* jump to another page: currently not optimized */ gen_jmp_im(eip); gen_eob(s); } ----------------------------------------------------------------------- ----------------------- cpu_exec (cpu-exec.c) ------------------------- /* see if we can patch the calling TB. When the TB spans two pages, we cannot safely do a direct jump. */ if (next_tb !=3D 0 && tb->page_addr[1] =3D=3D -1) { tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb); } ----------------------------------------------------------------------- Is it just because we cannot optimize block linking which crosses page boundary, or there are some correctness/safety issues should be considere= d? I did some experiments myself. First, I removed the if-else condition in gen_goto_tb (always go to if branch) and leave cpu_exec alone. In this case, user mode works fine, but system mode crashes while booting linux. Then, I removed the "tb->page_addr[1]" check and leave gen_goto_tb alone. This time, both user mode and system mode works fine. I use the disk image and user mode tests downloaded from the website as the test case. Could someone kindly explain why there are constraints on block linking? Thanks! Regards, chenwj --=20 Wei-Ren Chen (=E9=99=B3=E9=9F=8B=E4=BB=BB) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667