Received: from eggs.gnu.org ([208.118.235.92]:57815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRZF-0005vE-7w for qemu-devel@nongnu.org; Thu, 10 May 2012 07:30:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSRZ8-0001fD-Ok for qemu-devel@nongnu.org; Thu, 10 May 2012 07:29:56 -0400 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:54713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSRZ7-0001e4-Rx for qemu-devel@nongnu.org; Thu, 10 May 2012 07:29:50 -0400 Date: Thu, 10 May 2012 19:29:08 +0800 From: =?utf-8?B?6Zmz6Z+L5Lu7?= Message-ID: <20120510112908.GA64272@cs.nctu.edu.tw> References: <20120510081007.GA53664@cs.nctu.edu.tw> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] What TARGET_HAS_PRECISE_SMC means? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel@nongnu.org, =?utf-8?B?6Zmz6Z+L5Lu7?= > This enables support for handling the case where a guest instruction > modifies the memory corresponding to the QEMU TB which it is in. > For most CPU architectures this will (on hardware) give unpredictable > results because of hardware prefetch / pipelining / caching, and so > there's no need for QEMU to go to great lengths to support it (typicall= y > the CPU architecture requires some explicit act like a cache flush > before starting to execute the modified code, which is where QEMU will > flush its translation cache). > On x86 actions like "modify the next instruction" have historically > worked and so QEMU has to actually handle this. I am trying to understand tb_invalidate_phys_page_range (exec.c) which = has TARGET_HAS_PRECISE_SMC macro inside. --- void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t e= nd, int is_cpu_write_access) { #ifdef TARGET_HAS_PRECISE_SMC int current_tb_not_found =3D is_cpu_write_access; #endif /* TARGET_HAS_PRECISE_SMC */ ... snip ... #ifdef TARGET_HAS_PRECISE_SMC if (current_tb_not_found) { current_tb_not_found =3D 0; current_tb =3D NULL; if (env->mem_io_pc) { /* now we have a real cpu fault */ current_tb =3D tb_find_pc(env->mem_io_pc); } } if (current_tb =3D=3D tb && (current_tb->cflags & CF_COUNT_MASK) !=3D 1) { current_tb_modified =3D 1; cpu_restore_state(current_tb, env, env->mem_io_pc, NULL); cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base, ¤t_flags); } #endif /* TARGET_HAS_PRECISE_SMC */ } --- >From the backtrace I observed, the argument "is_cpu_write_access" is one = only when guest is doing MMIO (see below). And the part of tb_invalidate_phys_= page_range involved TARGET_HAS_PRECISE_SMC get executed only when current_tb_not_fou= nd is one (equal to is_cpu_write_access). I mean only then it finds current_tb, and= executes cpu_restore_state ... etc, otherwise it skips the whole thing. My questio= n is, does MMIO change guest instructions? Because you said, This enables support for handling the case where a guest instruction mo= difies the memory corresponding to the QEMU TB which it is in. I am not expect it's MMIO modifies the guest memory. --- #0 tb_invalidate_phys_page_range (start=3D229376, end=3D229380, is_cpu_w= rite_access=3D1) at /tmp/chenwj/qemu-0.13.0/exec.c:985 #1 0x0000000000508bd2 in tb_invalidate_phys_page_fast (start=3D229376, l= en=3D4) at /tmp/chenwj/qemu-0.13.0/exec.c:1112 #2 0x000000000050c69b in notdirty_mem_writel (opaque=3D0x0, ram_addr=3D2= 29376, val=3D0) at /tmp/chenwj/qemu-0.13.0/exec.c:3120 #3 0x000000000054e3c1 in io_writel (physaddr=3D229376, val=3D0, addr=3D2= 29376, retaddr=3D0x40016031) at /tmp/chenwj/qemu-0.13.0/softmmu_template.= h:213 #4 0x000000000054e4ab in __stl_mmu (addr=3D229376, val=3D0, mmu_idx=3D0)= at /tmp/chenwj/qemu-0.13.0/softmmu_template.h:245 --- 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 Homepage: http://people.cs.nctu.edu.tw/~chenwj