From patchwork Fri Feb 12 22:03:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 45433 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 A5DDCB7C33 for ; Tue, 16 Feb 2010 08:11:54 +1100 (EST) Received: from localhost ([127.0.0.1]:52030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nh89p-0004A6-Oi for incoming@patchwork.ozlabs.org; Mon, 15 Feb 2010 16:07:05 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nh87M-0003lo-22 for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:32 -0500 Received: from [199.232.76.173] (port=59653 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nh87L-0003lH-8T for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:31 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nh87I-0000rQ-9N for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:30 -0500 Received: from are.twiddle.net ([75.149.56.221]:51073) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nh87G-0000qs-Vl for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:27 -0500 Received: by are.twiddle.net (Postfix, from userid 5000) id 2CE4FE86; Mon, 15 Feb 2010 13:04:24 -0800 (PST) Message-Id: <21a95a61ec7d5daea088f2b062ae5452fa70bfbe.1266267595.git.rth@twiddle.net> In-Reply-To: References: From: Richard Henderson Date: Fri, 12 Feb 2010 14:03:15 -0800 To: qemu-devel@nongnu.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 3/7] Fix last page errors in page_set_flags and page_check_range. 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 The addr < end comparison prevents the last page from being iterated; an iteration based on length avoids this problem. --- exec.c | 39 +++++++++++++++++++++------------------ 1 files changed, 21 insertions(+), 18 deletions(-) diff --git a/exec.c b/exec.c index 766568b..1521ce3 100644 --- a/exec.c +++ b/exec.c @@ -2230,27 +2230,27 @@ int page_get_flags(target_ulong address) return p->flags; } -/* modify the flags of a page and invalidate the code if - necessary. The flag PAGE_WRITE_ORG is positioned automatically - depending on PAGE_WRITE */ +/* Modify the flags of a page and invalidate the code if necessary. + The flag PAGE_WRITE_ORG is positioned automatically depending + on PAGE_WRITE. The mmap_lock should already be held. */ void page_set_flags(target_ulong start, target_ulong end, int flags) { - PageDesc *p; - target_ulong addr; + target_ulong addr, len; - /* mmap_lock should already be held. */ start = start & TARGET_PAGE_MASK; end = TARGET_PAGE_ALIGN(end); - if (flags & PAGE_WRITE) + + if (flags & PAGE_WRITE) { flags |= PAGE_WRITE_ORG; - for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) { - p = page_find_alloc(addr >> TARGET_PAGE_BITS); - /* We may be called for host regions that are outside guest - address space. */ - if (!p) - return; - /* if the write protection is set, then we invalidate the code - inside */ + } + + for (addr = start, len = end - start; + len != 0; + len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { + PageDesc *p = page_find_alloc(addr >> TARGET_PAGE_BITS, 1); + + /* If the write protection bit is set, then we invalidate + the code inside. */ if (!(p->flags & PAGE_WRITE) && (flags & PAGE_WRITE) && p->first_tb) { @@ -2266,14 +2266,17 @@ int page_check_range(target_ulong start, target_ulong len, int flags) target_ulong end; target_ulong addr; - if (start + len < start) - /* we've wrapped around */ + if (start + len - 1 < start) { + /* We've wrapped around. */ return -1; + } end = TARGET_PAGE_ALIGN(start+len); /* must do before we loose bits in the next step */ start = start & TARGET_PAGE_MASK; - for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) { + for (addr = start, len = end - start; + len != 0; + len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { p = page_find(addr >> TARGET_PAGE_BITS); if( !p ) return -1;