Received: from eggs.gnu.org ([140.186.70.92]:57465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RMLaH-0008Dk-A7 for qemu-devel@nongnu.org; Fri, 04 Nov 2011 11:21:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RMLaE-0002hL-Sz for qemu-devel@nongnu.org; Fri, 04 Nov 2011 11:21:33 -0400 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:52277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RMLaE-0002fX-88 for qemu-devel@nongnu.org; Fri, 04 Nov 2011 11:21:30 -0400 Received: from csmailer.cs.nctu.edu.tw (localhost [127.0.0.1]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id A16514F4 for ; Fri, 4 Nov 2011 23:19:35 +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 984404F3 for ; Fri, 4 Nov 2011 23:19:35 +0800 (CST) Received: (from chenwj@localhost) by alumni.cs.nctu.edu.tw (8.14.4/8.14.4/Submit) id pA4FLKnL045677 for qemu-devel@nongnu.org; Fri, 4 Nov 2011 23:21:20 +0800 (CST) (envelope-from chenwj) Date: Fri, 4 Nov 2011 23:21:20 +0800 From: =?utf-8?B?6Zmz6Z+L5Lu7?= Message-ID: <20111104152120.GA3043@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] How QEMU handle self-modifying code? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, all While studying how QEMU handle self-modifying code I took [1] as an exa= mple. Running QEMU under GDB I found tb_invalidate_phys_page is called in two different call sequences: 1. do_syscall (linux-user/syscall.c) -> target_mprotect (linux-user/mmap.= c) -> page_set_flags (exec.c) -> tb_invalidate_phys_page (exec.c) 2. host_signal_handler (linux-user/signal.c) -> cpu_x86_signal_handler (u= ser-exec.c) -> handle_cpu_signal (user-exec.c) -> page_unprotect (exec.c) -> tb_invalidate_phys_page (exec.c) =20 Both eventually call tb_invalidate_phys_page. If a guest page is being modified, I think tb_invalidate_phys_page that page once is sufficient. But it's apparently not in practice. After doing some comparisons bwteen those two call sequences (see below= ), I can only guess this has something to do with TARGET_HAS_PRECISE_SMC. =20 --- 1st call sequence --- #0 tb_invalidate_phys_page (addr=3D134512640, pc=3D0, puc=3D0x0) #1 page_set_flags (start=3D134512640, end=3D134516736, flags=3D31) --- --- 2nd call sequence --- #0 tb_invalidate_phys_page (addr=3D134512640, pc=3D1612947916, puc=3D0x7= fffffffd080) #1 page_unprotect (address=3D134514145, pc=3D1612947916, puc=3D0x7ffffff= fd080) --- But what TARGET_HAS_PRECISE_SMC is? *If* we don't have to support TARGET_HAS_PRECISE_SMC, does it imply there is no need to call tb_invalidate_phys_page twice? Thanks! [1] http://web.archive.org/web/20080618094733/http://public.carnet.hr/~jbreca= k/sm.html 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