From nobody Thu May 2 14:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518173321092891.5899315493908; Fri, 9 Feb 2018 02:48:41 -0800 (PST) Received: from localhost ([::1]:33028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6EK-0007vI-19 for importer@patchew.org; Fri, 09 Feb 2018 05:48:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6Bs-0006Sz-05 for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:46:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek6Bo-0006I4-Sw for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:46:00 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44362 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ek6Bo-0006HV-Mp for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31224407604F for ; Fri, 9 Feb 2018 10:45:53 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-203.ams2.redhat.com [10.36.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C9062166BAE; Fri, 9 Feb 2018 10:45:52 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 11:45:43 +0100 Message-Id: <20180209104546.29401-2-pbonzini@redhat.com> In-Reply-To: <20180209104546.29401-1-pbonzini@redhat.com> References: <20180209104546.29401-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 10:45:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 10:45:53 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/4] memory: remove memory_region_test_and_clear_dirty X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is unused after g364fb has been converted to use DirtyBitmapSnapshot. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- include/exec/memory.h | 24 +++--------------------- memory.c | 8 -------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 783ef64570..6779d14a7b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1090,33 +1090,15 @@ bool memory_region_get_dirty(MemoryRegion *mr, hwad= dr addr, void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size); =20 -/** - * memory_region_test_and_clear_dirty: Check whether a range of bytes is d= irty - * for a specified client. It clears t= hem. - * - * Checks whether a range of bytes has been written to since the last - * call to memory_region_reset_dirty() with the same @client. Dirty loggi= ng - * must be enabled. - * - * @mr: the memory region being queried. - * @addr: the address (relative to the start of the region) being queried. - * @size: the size of the range being queried. - * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or - * %DIRTY_MEMORY_VGA. - */ -bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, - hwaddr size, unsigned client); - /** * memory_region_snapshot_and_clear_dirty: Get a snapshot of the dirty * bitmap and clear it. * * Creates a snapshot of the dirty bitmap, clears the dirty bitmap and * returns the snapshot. The snapshot can then be used to query dirty - * status, using memory_region_snapshot_get_dirty. Unlike - * memory_region_test_and_clear_dirty this allows to query the same - * page multiple times, which is especially useful for display updates - * where the scanlines often are not page aligned. + * status, using memory_region_snapshot_get_dirty. Snapshotting allows + * querying the same page multiple times, which is especially useful for + * display updates where the scanlines often are not page aligned. * * The dirty bitmap region which gets copyed into the snapshot (and * cleared afterwards) can be larger than requested. The boundaries diff --git a/memory.c b/memory.c index 93258a6655..9e75bb9526 100644 --- a/memory.c +++ b/memory.c @@ -1971,14 +1971,6 @@ void memory_region_set_dirty(MemoryRegion *mr, hwadd= r addr, memory_region_get_dirty_log_mask(m= r)); } =20 -bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, - hwaddr size, unsigned client) -{ - assert(mr->ram_block); - return cpu_physical_memory_test_and_clear_dirty( - memory_region_get_ram_addr(mr) + addr, size, client); -} - DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *= mr, hwaddr addr, hwaddr size, --=20 2.14.3 From nobody Thu May 2 14:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518173486125966.0297936629497; Fri, 9 Feb 2018 02:51:26 -0800 (PST) Received: from localhost ([::1]:33332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6H7-0002QH-8c for importer@patchew.org; Fri, 09 Feb 2018 05:51:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6Br-0006Sv-Uq for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:46:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek6Bo-0006IM-To for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57840 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ek6Bo-0006HX-Ne for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FF5B8182D3D for ; Fri, 9 Feb 2018 10:45:54 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-203.ams2.redhat.com [10.36.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8342166BAE; Fri, 9 Feb 2018 10:45:53 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 11:45:44 +0100 Message-Id: <20180209104546.29401-3-pbonzini@redhat.com> In-Reply-To: <20180209104546.29401-1-pbonzini@redhat.com> References: <20180209104546.29401-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Feb 2018 10:45:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Feb 2018 10:45:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/4] memory: hide memory_region_sync_dirty_bitmap behind DirtyBitmapSnapshot X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Simplify the users of memory_region_snapshot_and_clear_dirty, so that they do not have to call memory_region_sync_dirty_bitmap explicitly. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- hw/display/cg3.c | 1 - hw/display/exynos4210_fimd.c | 1 - hw/display/framebuffer.c | 1 - hw/display/g364fb.c | 1 - hw/display/sm501.c | 1 - hw/display/tcx.c | 2 -- hw/display/vga.c | 6 ------ include/exec/memory.h | 11 ----------- memory.c | 39 ++++++++++++++++++++------------------- 9 files changed, 20 insertions(+), 43 deletions(-) diff --git a/hw/display/cg3.c b/hw/display/cg3.c index cafd9f47ef..6fff4852c5 100644 --- a/hw/display/cg3.c +++ b/hw/display/cg3.c @@ -108,7 +108,6 @@ static void cg3_update_display(void *opaque) data =3D (uint32_t *)surface_data(surface); =20 if (!s->full_update) { - memory_region_sync_dirty_bitmap(&s->vram_mem); snap =3D memory_region_snapshot_and_clear_dirty(&s->vram_mem, 0x0, memory_region_size(&s->vram_= mem), DIRTY_MEMORY_VGA); diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c index 86e37e93e9..f011ea5b00 100644 --- a/hw/display/exynos4210_fimd.c +++ b/hw/display/exynos4210_fimd.c @@ -1289,7 +1289,6 @@ static void exynos4210_fimd_update(void *opaque) scrn_width =3D w->virtpage_width; /* Total width of virtual screen page in bytes */ inc_size =3D scrn_width + w->virtpage_offsize; - memory_region_sync_dirty_bitmap(w->mem_section.mr); host_fb_addr =3D w->host_fb_addr; fb_line_addr =3D w->mem_section.offset_within_region; snap =3D memory_region_snapshot_and_clear_dirty(w->mem_section= .mr, diff --git a/hw/display/framebuffer.c b/hw/display/framebuffer.c index d7310d25f2..36e3db189a 100644 --- a/hw/display/framebuffer.c +++ b/hw/display/framebuffer.c @@ -83,7 +83,6 @@ void framebuffer_update_display( if (!mem) { return; } - memory_region_sync_dirty_bitmap(mem); =20 addr =3D mem_section->offset_within_region; src =3D memory_region_get_ram_ptr(mem) + addr; diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c index 86452de780..819f8be05d 100644 --- a/hw/display/g364fb.c +++ b/hw/display/g364fb.c @@ -246,7 +246,6 @@ static void g364fb_update_display(void *opaque) qemu_console_resize(s->con, s->width, s->height); } =20 - memory_region_sync_dirty_bitmap(&s->mem_vram); if (s->ctla & CTLA_FORCE_BLANK) { g364fb_draw_blank(s); } else if (s->depth =3D=3D 8) { diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 134cbed607..f4bb33c279 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -1508,7 +1508,6 @@ static void sm501_update_display(void *opaque) } =20 /* draw each line according to conditions */ - memory_region_sync_dirty_bitmap(&s->local_mem_region); snap =3D memory_region_snapshot_and_clear_dirty(&s->local_mem_region, offset, width * height * src_bpp, DIRTY_MEMORY_VGA); for (y =3D 0, offset =3D 0; y < height; y++, offset +=3D width * src_b= pp) { diff --git a/hw/display/tcx.c b/hw/display/tcx.c index daa93e0929..b2786ee8d0 100644 --- a/hw/display/tcx.c +++ b/hw/display/tcx.c @@ -236,7 +236,6 @@ static void tcx_update_display(void *opaque) dd =3D surface_stride(surface); ds =3D 1024; =20 - memory_region_sync_dirty_bitmap(&ts->vram_mem); snap =3D memory_region_snapshot_and_clear_dirty(&ts->vram_mem, 0x0, memory_region_size(&ts->vram_= mem), DIRTY_MEMORY_VGA); @@ -292,7 +291,6 @@ static void tcx24_update_display(void *opaque) dd =3D surface_stride(surface); ds =3D 1024; =20 - memory_region_sync_dirty_bitmap(&ts->vram_mem); snap =3D memory_region_snapshot_and_clear_dirty(&ts->vram_mem, 0x0, memory_region_size(&ts->vram_= mem), DIRTY_MEMORY_VGA); diff --git a/hw/display/vga.c b/hw/display/vga.c index 6e78a4e156..28f298b342 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -1444,11 +1444,6 @@ static bool vga_scanline_invalidated(VGACommonState = *s, int y) return s->invalidated_y_table[y >> 5] & (1 << (y & 0x1f)); } =20 -void vga_sync_dirty_bitmap(VGACommonState *s) -{ - memory_region_sync_dirty_bitmap(&s->vram); -} - void vga_dirty_log_start(VGACommonState *s) { memory_region_set_log(&s->vram, true, DIRTY_MEMORY_VGA); @@ -1638,7 +1633,6 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) y1 =3D 0; =20 if (!full_update) { - vga_sync_dirty_bitmap(s); if (s->line_compare < height) { /* split screen mode */ region_start =3D 0; diff --git a/include/exec/memory.h b/include/exec/memory.h index 6779d14a7b..fff9b1d871 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1135,17 +1135,6 @@ bool memory_region_snapshot_get_dirty(MemoryRegion *= mr, DirtyBitmapSnapshot *snap, hwaddr addr, hwaddr size); =20 -/** - * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap wi= th - * any external TLBs (e.g. kvm) - * - * Flushes dirty information from accelerators such as kvm and vhost-net - * and makes it available to users of the memory API. - * - * @mr: the region being flushed. - */ -void memory_region_sync_dirty_bitmap(MemoryRegion *mr); - /** * memory_region_reset_dirty: Mark a range of pages as clean, for a specif= ied * client. diff --git a/memory.c b/memory.c index 9e75bb9526..8ed809c62b 100644 --- a/memory.c +++ b/memory.c @@ -1971,25 +1971,7 @@ void memory_region_set_dirty(MemoryRegion *mr, hwadd= r addr, memory_region_get_dirty_log_mask(m= r)); } =20 -DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *= mr, - hwaddr addr, - hwaddr size, - unsigned clien= t) -{ - assert(mr->ram_block); - return cpu_physical_memory_snapshot_and_clear_dirty( - memory_region_get_ram_addr(mr) + addr, size, client); -} - -bool memory_region_snapshot_get_dirty(MemoryRegion *mr, DirtyBitmapSnapsho= t *snap, - hwaddr addr, hwaddr size) -{ - assert(mr->ram_block); - return cpu_physical_memory_snapshot_get_dirty(snap, - memory_region_get_ram_addr(mr) + addr, size); -} - -void memory_region_sync_dirty_bitmap(MemoryRegion *mr) +static void memory_region_sync_dirty_bitmap(MemoryRegion *mr) { MemoryListener *listener; AddressSpace *as; @@ -2017,6 +1999,25 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *m= r) } } =20 +DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *= mr, + hwaddr addr, + hwaddr size, + unsigned clien= t) +{ + assert(mr->ram_block); + memory_region_sync_dirty_bitmap(mr); + return cpu_physical_memory_snapshot_and_clear_dirty( + memory_region_get_ram_addr(mr) + addr, size, client); +} + +bool memory_region_snapshot_get_dirty(MemoryRegion *mr, DirtyBitmapSnapsho= t *snap, + hwaddr addr, hwaddr size) +{ + assert(mr->ram_block); + return cpu_physical_memory_snapshot_get_dirty(snap, + memory_region_get_ram_addr(mr) + addr, size); +} + void memory_region_set_readonly(MemoryRegion *mr, bool readonly) { if (mr->readonly !=3D readonly) { --=20 2.14.3 From nobody Thu May 2 14:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518173321096440.44037202646655; Fri, 9 Feb 2018 02:48:41 -0800 (PST) Received: from localhost ([::1]:33026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6EI-0007t5-6k for importer@patchew.org; Fri, 09 Feb 2018 05:48:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6Br-0006Sx-Va for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:46:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek6Bo-0006IG-T5 for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35670 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ek6Bo-0006HT-Nq for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5CAE48959 for ; Fri, 9 Feb 2018 10:45:54 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-203.ams2.redhat.com [10.36.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5153B2166BAE; Fri, 9 Feb 2018 10:45:54 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 11:45:45 +0100 Message-Id: <20180209104546.29401-4-pbonzini@redhat.com> In-Reply-To: <20180209104546.29401-1-pbonzini@redhat.com> References: <20180209104546.29401-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 09 Feb 2018 10:45:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 09 Feb 2018 10:45:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/4] memory: introduce memory_global_after_dirty_log_sync X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is a race between TCG and accesses to the dirty log: vCPU thread reader thread ----------------------- ----------------------- TLB check -> slow path notdirty_mem_write write to RAM set dirty flag clear dirty flag TLB check -> fast path read memory write to RAM Fortunately, in order to fix it, no change is required to the vCPU thread. However, the reader thread must delay the read after the vCPU thread has finished the write. This can be approximated conservatively by run_on_cpu, which waits for the end of the current translation block. A similar technique is used by KVM, which has to do a synchronous TLB flush after doing a test-and-clear of the dirty-page flags. Reported-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- exec.c | 31 +++++++++++++++++++++++++++++++ include/exec/memory.h | 12 ++++++++++++ memory.c | 10 +++++++++- migration/ram.c | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index e8d7b335b6..edfbf4f3a6 100644 --- a/exec.c +++ b/exec.c @@ -205,6 +205,7 @@ typedef struct subpage_t { =20 static void io_mem_init(void); static void memory_map_init(void); +static void tcg_log_global_after_sync(MemoryListener *listener); static void tcg_commit(MemoryListener *listener); =20 static MemoryRegion io_mem_watch; @@ -743,6 +744,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx, newas->cpu =3D cpu; newas->as =3D as; if (tcg_enabled()) { + newas->tcg_as_listener.log_global_after_sync =3D tcg_log_global_af= ter_sync; newas->tcg_as_listener.commit =3D tcg_commit; memory_listener_register(&newas->tcg_as_listener, as); } @@ -2841,6 +2843,35 @@ void address_space_dispatch_free(AddressSpaceDispatc= h *d) g_free(d); } =20 +static void do_nothing(CPUState *cpu, run_on_cpu_data d) +{ +} + +static void tcg_log_global_after_sync(MemoryListener *listener) +{ + CPUAddressSpace *cpuas; + + /* Wait for the CPU to end the current TB. This avoids the following + * incorrect race: + * + * vCPU migration + * ---------------------- ------------------------- + * TLB check -> slow path + * notdirty_mem_write + * write to RAM + * mark dirty + * clear dirty flag + * TLB check -> fast path + * read memory + * write to RAM + * + * by pushing the migration thread's memory read after the vCPU thread= has + * written the memory. + */ + cpuas =3D container_of(listener, CPUAddressSpace, tcg_as_listener); + run_on_cpu(cpuas->cpu, do_nothing, RUN_ON_CPU_NULL); +} + static void tcg_commit(MemoryListener *listener) { CPUAddressSpace *cpuas; diff --git a/include/exec/memory.h b/include/exec/memory.h index fff9b1d871..9ff97f2574 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -293,6 +293,7 @@ struct MemoryListener { void (*log_sync)(MemoryListener *listener, MemoryRegionSection *sectio= n); void (*log_global_start)(MemoryListener *listener); void (*log_global_stop)(MemoryListener *listener); + void (*log_global_after_sync)(MemoryListener *listener); void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *sec= tion, bool match_data, uint64_t data, EventNotifier *e); void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *sec= tion, @@ -1456,6 +1457,17 @@ MemoryRegionSection memory_region_find(MemoryRegion = *mr, */ void memory_global_dirty_log_sync(void); =20 +/** + * memory_global_dirty_log_sync: synchronize the dirty log for all memory + * + * Synchronizes the vCPUs with a thread that is reading the dirty bitmap. + * This function must be called after the dirty log bitmap is cleared, and + * before dirty guest memory pages are read. If you are using + * #DirtyBitmapSnapshot, memory_region_snapshot_and_clear_dirty() takes + * care of doing this. + */ +void memory_global_after_dirty_log_sync(void); + /** * memory_region_transaction_begin: Start a transaction. * diff --git a/memory.c b/memory.c index 8ed809c62b..74917a19eb 100644 --- a/memory.c +++ b/memory.c @@ -2004,10 +2004,13 @@ DirtyBitmapSnapshot *memory_region_snapshot_and_cle= ar_dirty(MemoryRegion *mr, hwaddr size, unsigned clien= t) { + DirtyBitmapSnapshot *snapshot; assert(mr->ram_block); memory_region_sync_dirty_bitmap(mr); - return cpu_physical_memory_snapshot_and_clear_dirty( + snapshot =3D cpu_physical_memory_snapshot_and_clear_dirty( memory_region_get_ram_addr(mr) + addr, size, client); + memory_global_after_dirty_log_sync(); + return snapshot; } =20 bool memory_region_snapshot_get_dirty(MemoryRegion *mr, DirtyBitmapSnapsho= t *snap, @@ -2528,6 +2531,11 @@ void memory_global_dirty_log_sync(void) } } =20 +void memory_global_after_dirty_log_sync(void) +{ + MEMORY_LISTENER_CALL_GLOBAL(log_global_after_sync, Forward); +} + static VMChangeStateEntry *vmstate_change; =20 void memory_global_dirty_log_start(void) diff --git a/migration/ram.c b/migration/ram.c index 5a109efeda..3cb92e193e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -848,6 +848,7 @@ static void migration_bitmap_sync(RAMState *rs) rcu_read_unlock(); qemu_mutex_unlock(&rs->bitmap_mutex); =20 + memory_global_after_dirty_log_sync(); trace_migration_bitmap_sync_end(rs->num_dirty_pages_period); =20 end_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); --=20 2.14.3 From nobody Thu May 2 14:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518173321037682.220695678771; Fri, 9 Feb 2018 02:48:41 -0800 (PST) Received: from localhost ([::1]:33027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6EI-0007tr-Qa for importer@patchew.org; Fri, 09 Feb 2018 05:48:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek6Br-0006Sy-WC for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:46:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek6Bo-0006I7-Sv for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55200 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ek6Bo-0006HU-Nx for qemu-devel@nongnu.org; Fri, 09 Feb 2018 05:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C74CB4022905 for ; Fri, 9 Feb 2018 10:45:55 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-203.ams2.redhat.com [10.36.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3303F2166BAE; Fri, 9 Feb 2018 10:45:55 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 11:45:46 +0100 Message-Id: <20180209104546.29401-5-pbonzini@redhat.com> In-Reply-To: <20180209104546.29401-1-pbonzini@redhat.com> References: <20180209104546.29401-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 09 Feb 2018 10:45:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 09 Feb 2018 10:45:55 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/4] memory: unify loops to sync dirty log bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that memory_region_sync_dirty_bitmap is NULL, we can unify its loop with memory_global_dirty_log_sync's. The only difference is that memory_region_sync_dirty_bitmap will no longer call log_sync on FlatRanges that do have a zero dirty_log_mask, but this is okay because video memory is always registered with the dirty page logging mechanism. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- memory.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/memory.c b/memory.c index 74917a19eb..586de4556d 100644 --- a/memory.c +++ b/memory.c @@ -1990,7 +1990,7 @@ static void memory_region_sync_dirty_bitmap(MemoryReg= ion *mr) as =3D listener->address_space; view =3D address_space_get_flatview(as); FOR_EACH_FLAT_RANGE(fr, view) { - if (fr->mr =3D=3D mr) { + if (fr->dirty_log_mask && (!mr || fr->mr =3D=3D mr)) { MemoryRegionSection mrs =3D section_from_flat_range(fr, vi= ew); listener->log_sync(listener, &mrs); } @@ -2509,26 +2509,7 @@ bool memory_region_present(MemoryRegion *container, = hwaddr addr) =20 void memory_global_dirty_log_sync(void) { - MemoryListener *listener; - AddressSpace *as; - FlatView *view; - FlatRange *fr; - - QTAILQ_FOREACH(listener, &memory_listeners, link) { - if (!listener->log_sync) { - continue; - } - as =3D listener->address_space; - view =3D address_space_get_flatview(as); - FOR_EACH_FLAT_RANGE(fr, view) { - if (fr->dirty_log_mask) { - MemoryRegionSection mrs =3D section_from_flat_range(fr, vi= ew); - - listener->log_sync(listener, &mrs); - } - } - flatview_unref(view); - } + memory_region_sync_dirty_bitmap(NULL); } =20 void memory_global_after_dirty_log_sync(void) --=20 2.14.3