From patchwork Mon Jul 21 15:06:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 372114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 961EA140181 for ; Tue, 22 Jul 2014 01:07:32 +1000 (EST) Received: from localhost ([::1]:34638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9FBa-0006zJ-Dj for incoming@patchwork.ozlabs.org; Mon, 21 Jul 2014 11:07:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9FBA-0006fP-BL for qemu-devel@nongnu.org; Mon, 21 Jul 2014 11:07:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9FB1-0001Y8-92 for qemu-devel@nongnu.org; Mon, 21 Jul 2014 11:07:04 -0400 Received: from mail-we0-x22f.google.com ([2a00:1450:400c:c03::22f]:57448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9FB0-0001WD-R8 for qemu-devel@nongnu.org; Mon, 21 Jul 2014 11:06:55 -0400 Received: by mail-we0-f175.google.com with SMTP id t60so7725185wes.34 for ; Mon, 21 Jul 2014 08:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=MXivgaGaDKwVHnoOkgVVGrNsVL8/3FBCet6WztrbcdI=; b=ZDpiPiBy9TVr2xdoP8m6pX0OHlqVQWKEC27Patb5FTr2qu+BYTqKhcoOv9PF5s/edC vUyA6TRyTaTH4Y2N1bqsGw9fHEAVKlUM8FGG8D6KyH+gKFu8SalaheaeICYAc26sOZDf N743zOWuWkf32RVDxsKVG6/eflOLTkH/hm1cGtf0Zek/HhG2FD8vB1Es6K080oslFv4w G24nj3oO7/0KS5U9YfbEhVMxPsJQNe7L6OIZ08MktF9YGcUtA1/+EaWTwRsNgIcCVBx0 M01WgAxw2gp8gzLdyK0kvALSBi0g5iieK97BmoFc9JlfQA0YZnShZHFjgSt8NwiR8AWR 6VbQ== X-Received: by 10.195.13.102 with SMTP id ex6mr23271930wjd.48.1405955212005; Mon, 21 Jul 2014 08:06:52 -0700 (PDT) Received: from playground.station (net-37-117-143-217.cust.vodafonedsl.it. [37.117.143.217]) by mx.google.com with ESMTPSA id x3sm42893898wia.11.2014.07.21.08.06.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jul 2014 08:06:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jul 2014 17:06:44 +0200 Message-Id: <1405955204-10438-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::22f Cc: peter.maydell@linaro.org, mst@redhat.com, kraxel@redhat.com, dgilbert@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH for-2.1] exec: fix migration with devices that use address_space_rw 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 Devices that use address_space_rw to write large areas to memory (as opposed to address_space_map/unmap) were broken with respect to migration since fe680d0 (exec: Limit translation limiting in address_space_translate to xen, 2014-05-07). Such devices include IDE CD-ROMs. The reason is that invalidate_and_set_dirty (called by address_space_rw but not address_space_map/unmap) was only setting the dirty bit for the first page in the translation. To fix this, introduce cpu_physical_memory_set_dirty_range_nocode that is the same as cpu_physical_memory_set_dirty_range except it does not muck with the DIRTY_MEMORY_CODE bitmap. This function can be used if the caller invalidates translations with tb_invalidate_phys_page_range. There is another difference between cpu_physical_memory_set_dirty_range and cpu_physical_memory_set_dirty_flag; the former includes a call to xen_modified_memory. This is handled separately in invalidate_and_set_dirty, and is not needed in other callers of cpu_physical_memory_set_dirty_range_nocode, so leave it alone. Just one nit: now that invalidate_and_set_dirty takes care of handling multiple pages, there is no need for address_space_unmap to wrap it in a loop. In fact that loop would now be O(n^2). Reported-by: Dave Gilbert Signed-off-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Tested-by: Gerd Hoffmann Reviewed-by: Juan Quintela --- exec.c | 20 ++++---------------- include/exec/ram_addr.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/exec.c b/exec.c index 5a2a25e..765bd94 100644 --- a/exec.c +++ b/exec.c @@ -1568,8 +1568,7 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr, default: abort(); } - cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_MIGRATION); - cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_VGA); + cpu_physical_memory_set_dirty_range_nocode(ram_addr, size); /* we remove the notdirty callback only if the code has been flushed */ if (!cpu_physical_memory_is_clean(ram_addr)) { @@ -1978,8 +1977,7 @@ static void invalidate_and_set_dirty(hwaddr addr, /* invalidate code */ tb_invalidate_phys_page_range(addr, addr + length, 0); /* set dirty bit */ - cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_VGA); - cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_MIGRATION); + cpu_physical_memory_set_dirty_range_nocode(addr, length); } xen_modified_memory(addr, length); } @@ -2335,15 +2333,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, mr = qemu_ram_addr_from_host(buffer, &addr1); assert(mr != NULL); if (is_write) { - while (access_len) { - unsigned l; - l = TARGET_PAGE_SIZE; - if (l > access_len) - l = access_len; - invalidate_and_set_dirty(addr1, l); - addr1 += l; - access_len -= l; - } + invalidate_and_set_dirty(addr1, access_len); } if (xen_enabled()) { xen_invalidate_map_cache_entry(buffer); @@ -2581,9 +2571,7 @@ void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val) /* invalidate code */ tb_invalidate_phys_page_range(addr1, addr1 + 4, 0); /* set dirty bit */ - cpu_physical_memory_set_dirty_flag(addr1, - DIRTY_MEMORY_MIGRATION); - cpu_physical_memory_set_dirty_flag(addr1, DIRTY_MEMORY_VGA); + cpu_physical_memory_set_dirty_range_nocode(addr1, 4); } } } diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index e9eb831..6593be1 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -71,6 +71,17 @@ static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr, set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]); } +static inline void cpu_physical_memory_set_dirty_range_nocode(ram_addr_t start, + ram_addr_t length) +{ + unsigned long end, page; + + end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; + page = start >> TARGET_PAGE_BITS; + bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page); + bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page); +} + static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, ram_addr_t length) {