From patchwork Sun Mar 18 16:16:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 147393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CFE6DB6FC4 for ; Mon, 19 Mar 2012 03:17:32 +1100 (EST) Received: from localhost ([::1]:39725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9InS-00033A-MG for incoming@patchwork.ozlabs.org; Sun, 18 Mar 2012 12:17:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9InM-00032h-1C for qemu-devel@nongnu.org; Sun, 18 Mar 2012 12:17:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9In1-0002kZ-GX for qemu-devel@nongnu.org; Sun, 18 Mar 2012 12:17:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9In1-0002jc-7k for qemu-devel@nongnu.org; Sun, 18 Mar 2012 12:17:03 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2IGGvDT018964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 18 Mar 2012 12:16:58 -0400 Received: from balrog.usersys.redhat.com (dhcp-4-85.tlv.redhat.com [10.35.4.85]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2IGGunl005766; Sun, 18 Mar 2012 12:16:57 -0400 Message-ID: <4F660A78.4040409@redhat.com> Date: Sun, 18 Mar 2012 18:16:56 +0200 From: Avi Kivity User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: malc References: In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] Breakage X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 03/18/2012 06:12 PM, malc wrote: > 97161e177b4ea2730dff13c4df01475762ab6048 broke booting of a DOS image > i've been using for years, the VM stalls at "Booting from hard disk" > BIOS message never making any progress. Can you post an image that exhibits the problem? Also, try the attached patch. From bb363db2608dfc9b49b53994dc20d68169e66774 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 14 Mar 2012 16:19:39 +0200 Subject: [PATCH] exec: fix write tlb entry misused as iotlb A couple of code paths check the lower bits of CPUTLBEntry::addr_write against io_mem_ram as a way of looking for a dirty RAM page. This works by accident since the value is zero, which matches all clear bits for TLB_INVALID, TLB_MMIO, and TLB_NOTDIRTY (indicating dirty RAM). Make it work by design by checking for the proper bits. Signed-off-by: Avi Kivity --- exec.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index 8fd50a1..d8b089e 100644 --- a/exec.c +++ b/exec.c @@ -2031,14 +2031,19 @@ static void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr, cpu_physical_memory_set_dirty_flags(ram_addr, CODE_DIRTY_FLAG); } +static bool tlb_is_dirty_ram(CPUTLBEntry *tlbe) +{ + return (tlbe->addr_write & (TLB_INVALID_MASK|TLB_MMIO|TLB_NOTDIRTY)) == 0; +} + static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry, unsigned long start, unsigned long length) { unsigned long addr; - if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) { + if (tlb_is_dirty_ram(tlb_entry)) { addr = (tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend; if ((addr - start) < length) { - tlb_entry->addr_write = (tlb_entry->addr_write & TARGET_PAGE_MASK) | TLB_NOTDIRTY; + tlb_entry->addr_write |= TLB_NOTDIRTY; } } } @@ -2091,7 +2096,7 @@ static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry) ram_addr_t ram_addr; void *p; - if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) { + if (tlb_is_dirty_ram(tlb_entry)) { p = (void *)(unsigned long)((tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend); ram_addr = qemu_ram_addr_from_host_nofail(p); -- 1.7.9