From patchwork Mon Mar 29 00:25:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 48799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 829A1B7CB9 for ; Mon, 29 Mar 2010 12:08:21 +1100 (EST) Received: from localhost ([127.0.0.1]:46190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nw2qp-0005Eq-TI for incoming@patchwork.ozlabs.org; Sun, 28 Mar 2010 20:29:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nw2nx-0004oM-5A for qemu-devel@nongnu.org; Sun, 28 Mar 2010 20:26:09 -0400 Received: from [140.186.70.92] (port=47789 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nw2nv-0004oA-UX for qemu-devel@nongnu.org; Sun, 28 Mar 2010 20:26:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nw2nt-00027C-9L for qemu-devel@nongnu.org; Sun, 28 Mar 2010 20:26:07 -0400 Received: from hall.aurel32.net ([88.191.82.174]:38830) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nw2ns-000270-2L for qemu-devel@nongnu.org; Sun, 28 Mar 2010 20:26:05 -0400 Received: from [2a01:e35:2e80:2fb0:21e:8cff:feb0:693b] (helo=volta.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1Nw2nr-00033S-Ho; Mon, 29 Mar 2010 02:26:03 +0200 Received: from aurel32 by volta.aurel32.net with local (Exim 4.71) (envelope-from ) id 1Nw2nq-0001KV-KB; Mon, 29 Mar 2010 02:26:02 +0200 From: Aurelien Jarno To: qemu-devel@nongnu.org Date: Mon, 29 Mar 2010 02:25:51 +0200 Message-Id: <1269822354-4878-3-git-send-email-aurelien@aurel32.net> X-Mailer: git-send-email 1.7.0.2 In-Reply-To: <1269822354-4878-1-git-send-email-aurelien@aurel32.net> References: <1269822354-4878-1-git-send-email-aurelien@aurel32.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Aurelien Jarno Subject: [Qemu-devel] [PATCH 2/5] linux-user: fix page_unprotect when host page size > target page size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When the host page size is bigger that the target one, unprotecting a page should: - mark all the target pages corresponding to the host page as writable - invalidate all tb corresponding to the host page (and not the target page) Signed-off-by: Aurelien Jarno --- exec.c | 45 ++++++++++++++++++++++----------------------- 1 files changed, 22 insertions(+), 23 deletions(-) diff --git a/exec.c b/exec.c index 0916208..1b0fe52 100644 --- a/exec.c +++ b/exec.c @@ -2447,8 +2447,8 @@ int page_check_range(target_ulong start, target_ulong len, int flags) page. Return TRUE if the fault was successfully handled. */ int page_unprotect(target_ulong address, unsigned long pc, void *puc) { - unsigned int page_index, prot, pindex; - PageDesc *p, *p1; + unsigned int prot; + PageDesc *p; target_ulong host_start, host_end, addr; /* Technically this isn't safe inside a signal handler. However we @@ -2456,37 +2456,36 @@ int page_unprotect(target_ulong address, unsigned long pc, void *puc) practice it seems to be ok. */ mmap_lock(); - host_start = address & qemu_host_page_mask; - page_index = host_start >> TARGET_PAGE_BITS; - p1 = page_find(page_index); - if (!p1) { + p = page_find(address >> TARGET_PAGE_BITS); + if (!p) { mmap_unlock(); return 0; } - host_end = host_start + qemu_host_page_size; - p = p1; - prot = 0; - for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) { - prot |= p->flags; - p++; - } + /* if the page was really writable, then we change its protection back to writable */ - if (prot & PAGE_WRITE_ORG) { - pindex = (address - host_start) >> TARGET_PAGE_BITS; - if (!(p1[pindex].flags & PAGE_WRITE)) { - mprotect((void *)g2h(host_start), qemu_host_page_size, - (prot & PAGE_BITS) | PAGE_WRITE); - p1[pindex].flags |= PAGE_WRITE; + if ((p->flags & PAGE_WRITE_ORG) && !(p->flags & PAGE_WRITE)) { + host_start = address & qemu_host_page_mask; + host_end = host_start + qemu_host_page_size; + + prot = 0; + for (addr = host_start ; addr < host_end ; addr += TARGET_PAGE_SIZE) { + p = page_find(addr >> TARGET_PAGE_BITS); + p->flags |= PAGE_WRITE; + prot |= p->flags; + /* and since the content will be modified, we must invalidate the corresponding translated code. */ - tb_invalidate_phys_page(address, pc, puc); + tb_invalidate_phys_page(addr, pc, puc); #ifdef DEBUG_TB_CHECK - tb_invalidate_check(address); + tb_invalidate_check(addr); #endif - mmap_unlock(); - return 1; } + mprotect((void *)g2h(host_start), qemu_host_page_size, + prot & PAGE_BITS); + + mmap_unlock(); + return 1; } mmap_unlock(); return 0;