From patchwork Thu Feb 11 22:57:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 45168 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 116C0B7CB8 for ; Fri, 12 Feb 2010 12:19:46 +1100 (EST) Received: from localhost ([127.0.0.1]:42067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nfjqg-0003FW-99 for incoming@patchwork.ozlabs.org; Thu, 11 Feb 2010 19:57:34 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nfjph-0003FH-S0 for qemu-devel@nongnu.org; Thu, 11 Feb 2010 19:56:33 -0500 Received: from [199.232.76.173] (port=58802 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nfjpg-0003F9-Dg for qemu-devel@nongnu.org; Thu, 11 Feb 2010 19:56:32 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nfjpe-0000Pp-Vl for qemu-devel@nongnu.org; Thu, 11 Feb 2010 19:56:32 -0500 Received: from are.twiddle.net ([75.149.56.221]:44813) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfjpL-0000NC-1W for qemu-devel@nongnu.org; Thu, 11 Feb 2010 19:56:30 -0500 Received: by are.twiddle.net (Postfix, from userid 5000) id 26E6DC2B; Thu, 11 Feb 2010 16:54:14 -0800 (PST) Message-Id: In-Reply-To: References: From: Richard Henderson Date: Thu, 11 Feb 2010 14:57:35 -0800 To: qemu-devel@nongnu.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 3/6] 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 | 54 +++++++++++++++++++++++++++--------------------------- 1 files changed, 27 insertions(+), 27 deletions(-) diff --git a/exec.c b/exec.c index 766568b..ebbe6d0 100644 --- a/exec.c +++ b/exec.c @@ -2222,35 +2222,31 @@ void page_dump(FILE *f) int page_get_flags(target_ulong address) { - PageDesc *p; - - p = page_find(address >> TARGET_PAGE_BITS); - if (!p) - return 0; - return p->flags; + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); + return p ? p->flags : 0; } -/* 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,18 +2262,22 @@ 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 */ + /* END must be computed before we drop bits from START. */ + end = TARGET_PAGE_ALIGN(start + len); 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 ) + if (!p) return -1; - if( !(p->flags & PAGE_VALID) ) + if (!(p->flags & PAGE_VALID)) return -1; if ((flags & PAGE_READ) && !(p->flags & PAGE_READ))