From nobody Tue Apr 30 05:42: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 1543482693432431.0581678721418; Thu, 29 Nov 2018 01:11:33 -0800 (PST) Received: from localhost ([::1]:52985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIM8-0002oN-At for importer@patchew.org; Thu, 29 Nov 2018 04:11:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIKP-0001sH-Hf for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSIKM-0007rw-GC for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSIKI-0007pa-OS for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 073C4307D986; Thu, 29 Nov 2018 09:09:37 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0904A18353; Thu, 29 Nov 2018 09:09:35 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 10:09:31 +0100 Message-Id: <20181129090933.30622-2-pbonzini@redhat.com> In-Reply-To: <20181129090933.30622-1-pbonzini@redhat.com> References: <20181129090933.30622-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 29 Nov 2018 09:09:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/3] memory: extract flat_range_coalesced_io_{del, add} 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: Atsushi Nemoto Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Extract two new functions from memory_region_update_coalesced_range_as. To avoid duplication in the creation of the MemoryRegionSection, use MEMORY_LISTENER_UPDATE_REGION instead of MEMORY_LISTENER_CALL to invoke the listener callback. Signed-off-by: Paolo Bonzini --- memory.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/memory.c b/memory.c index d14c6dec1d..119b6e46d5 100644 --- a/memory.c +++ b/memory.c @@ -850,6 +850,33 @@ static void address_space_update_ioeventfds(AddressSpa= ce *as) flatview_unref(view); } =20 +static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as) +{ + MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del, + int128_get64(fr->addr.start), + int128_get64(fr->addr.size)); +} + +static void flat_range_coalesced_io_add(FlatRange *fr, AddressSpace *as) +{ + MemoryRegion *mr =3D fr->mr; + CoalescedMemoryRange *cmr; + AddrRange tmp; + + QTAILQ_FOREACH(cmr, &mr->coalesced, link) { + tmp =3D addrrange_shift(cmr->addr, + int128_sub(fr->addr.start, + int128_make64(fr->offset_in_regio= n))); + if (!addrrange_intersects(tmp, fr->addr)) { + continue; + } + tmp =3D addrrange_intersection(tmp, fr->addr); + MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, coalesced_io_add, + int128_get64(tmp.start), + int128_get64(tmp.size)); + } +} + static void address_space_update_topology_pass(AddressSpace *as, const FlatView *old_view, const FlatView *new_view, @@ -2136,34 +2163,12 @@ static void memory_region_update_coalesced_range_as= (MemoryRegion *mr, AddressSpa { FlatView *view; FlatRange *fr; - CoalescedMemoryRange *cmr; - AddrRange tmp; - MemoryRegionSection section; =20 view =3D address_space_get_flatview(as); FOR_EACH_FLAT_RANGE(fr, view) { if (fr->mr =3D=3D mr) { - section =3D (MemoryRegionSection) { - .fv =3D view, - .offset_within_address_space =3D int128_get64(fr->addr.sta= rt), - .size =3D fr->addr.size, - }; - - MEMORY_LISTENER_CALL(as, coalesced_io_del, Reverse, §ion, - int128_get64(fr->addr.start), - int128_get64(fr->addr.size)); - QTAILQ_FOREACH(cmr, &mr->coalesced, link) { - tmp =3D addrrange_shift(cmr->addr, - int128_sub(fr->addr.start, - int128_make64(fr->offset_= in_region))); - if (!addrrange_intersects(tmp, fr->addr)) { - continue; - } - tmp =3D addrrange_intersection(tmp, fr->addr); - MEMORY_LISTENER_CALL(as, coalesced_io_add, Forward, §i= on, - int128_get64(tmp.start), - int128_get64(tmp.size)); - } + flat_range_coalesced_io_del(fr, as); + flat_range_coalesced_io_add(fr, as); } } flatview_unref(view); --=20 2.19.1 From nobody Tue Apr 30 05:42: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 15434828161272.4633235573195407; Thu, 29 Nov 2018 01:13:36 -0800 (PST) Received: from localhost ([::1]:52993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIO2-0004EM-7X for importer@patchew.org; Thu, 29 Nov 2018 04:13:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIKQ-0001t3-Fi for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSIKO-0007sq-EC for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSIKL-0007qF-NG for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:42 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 688E330C41BD; Thu, 29 Nov 2018 09:09:38 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 701C718353; Thu, 29 Nov 2018 09:09:37 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 10:09:32 +0100 Message-Id: <20181129090933.30622-3-pbonzini@redhat.com> In-Reply-To: <20181129090933.30622-1-pbonzini@redhat.com> References: <20181129090933.30622-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 29 Nov 2018 09:09:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/3] memory: avoid unnecessary coalesced_io_del operations 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: Atsushi Nemoto Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Store whether the FlatRange has had any coalesced I/O ranges applied, and if not avoid calling coalesced_io_del. This is useful in preparation for the next patch, which will call coalesced_io_del when rendering memory regions. Signed-off-by: Paolo Bonzini --- memory.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/memory.c b/memory.c index 119b6e46d5..072769aa06 100644 --- a/memory.c +++ b/memory.c @@ -217,6 +217,7 @@ struct FlatRange { bool romd_mode; bool readonly; bool nonvolatile; + bool has_coalesced_range; }; =20 #define FOR_EACH_FLAT_RANGE(var, view) \ @@ -650,6 +651,7 @@ static void render_memory_region(FlatView *view, fr.romd_mode =3D mr->romd_mode; fr.readonly =3D readonly; fr.nonvolatile =3D nonvolatile; + fr.has_coalesced_range =3D false; =20 /* Render the region itself into any gaps left by the current view. */ for (i =3D 0; i < view->nr && int128_nz(remain); ++i) { @@ -852,6 +854,10 @@ static void address_space_update_ioeventfds(AddressSpa= ce *as) =20 static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as) { + if (!fr->has_coalesced_range) { + return; + } + MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del, int128_get64(fr->addr.start), int128_get64(fr->addr.size)); @@ -863,6 +869,11 @@ static void flat_range_coalesced_io_add(FlatRange *fr,= AddressSpace *as) CoalescedMemoryRange *cmr; AddrRange tmp; =20 + if (QTAILQ_EMPTY(&mr->coalesced)) { + return; + } + + fr->has_coalesced_range =3D true; QTAILQ_FOREACH(cmr, &mr->coalesced, link) { tmp =3D addrrange_shift(cmr->addr, int128_sub(fr->addr.start, --=20 2.19.1 From nobody Tue Apr 30 05:42: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 1543482693559114.33067645790834; Thu, 29 Nov 2018 01:11:33 -0800 (PST) Received: from localhost ([::1]:52986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIM8-0002ph-CW for importer@patchew.org; Thu, 29 Nov 2018 04:11:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSIKT-0001tk-PN for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSIKR-0007uk-Lh for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39192) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSIKQ-0007qs-Gl for qemu-devel@nongnu.org; Thu, 29 Nov 2018 04:09:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9C5831256A7; Thu, 29 Nov 2018 09:09:39 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF1BB5DD8A; Thu, 29 Nov 2018 09:09:38 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 10:09:33 +0100 Message-Id: <20181129090933.30622-4-pbonzini@redhat.com> In-Reply-To: <20181129090933.30622-1-pbonzini@redhat.com> References: <20181129090933.30622-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 29 Nov 2018 09:09:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/3] memory: update coalesced_range on transaction_commit 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: Atsushi Nemoto Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The e1000 driver calls memory_region_add_coalescing but kvm_coalesce_mmio_region is never called for those regions. The bug dates back to the introduction of the memory region API; to fix it, delete and re-add coalesced MMIO ranges when building the FlatViews. Because coalesced MMIO regions apply to all address spaces, the has_coalesced_range flag has to be changed into an int. Fixes: 093bc2cd885e ("Hierarchical memory region API") Reported-by: Atsushi Nemoto Tested-by: Atsushi Nemoto Signed-off-by: Paolo Bonzini --- memory.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/memory.c b/memory.c index 072769aa06..5759f74034 100644 --- a/memory.c +++ b/memory.c @@ -217,7 +217,7 @@ struct FlatRange { bool romd_mode; bool readonly; bool nonvolatile; - bool has_coalesced_range; + int has_coalesced_range; }; =20 #define FOR_EACH_FLAT_RANGE(var, view) \ @@ -651,7 +651,7 @@ static void render_memory_region(FlatView *view, fr.romd_mode =3D mr->romd_mode; fr.readonly =3D readonly; fr.nonvolatile =3D nonvolatile; - fr.has_coalesced_range =3D false; + fr.has_coalesced_range =3D 0; =20 /* Render the region itself into any gaps left by the current view. */ for (i =3D 0; i < view->nr && int128_nz(remain); ++i) { @@ -858,6 +858,10 @@ static void flat_range_coalesced_io_del(FlatRange *fr,= AddressSpace *as) return; } =20 + if (--fr->has_coalesced_range > 0) { + return; + } + MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del, int128_get64(fr->addr.start), int128_get64(fr->addr.size)); @@ -873,7 +877,10 @@ static void flat_range_coalesced_io_add(FlatRange *fr,= AddressSpace *as) return; } =20 - fr->has_coalesced_range =3D true; + if (fr->has_coalesced_range++) { + return; + } + QTAILQ_FOREACH(cmr, &mr->coalesced, link) { tmp =3D addrrange_shift(cmr->addr, int128_sub(fr->addr.start, @@ -920,6 +927,7 @@ static void address_space_update_topology_pass(AddressS= pace *as, /* In old but not in new, or in both but attributes changed. */ =20 if (!adding) { + flat_range_coalesced_io_del(frold, as); MEMORY_LISTENER_UPDATE_REGION(frold, as, Reverse, region_d= el); } =20 @@ -927,7 +935,9 @@ static void address_space_update_topology_pass(AddressS= pace *as, } else if (frold && frnew && flatrange_equal(frold, frnew)) { /* In both and unchanged (except logging may have changed) */ =20 - if (adding) { + if (!adding) { + flat_range_coalesced_io_del(frold, as); + } else { MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_n= op); if (frnew->dirty_log_mask & ~frold->dirty_log_mask) { MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, log_= start, @@ -939,6 +949,7 @@ static void address_space_update_topology_pass(AddressS= pace *as, frold->dirty_log_mask, frnew->dirty_log_mask); } + flat_range_coalesced_io_add(frnew, as); } =20 ++iold; @@ -948,6 +959,7 @@ static void address_space_update_topology_pass(AddressS= pace *as, =20 if (adding) { MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_a= dd); + flat_range_coalesced_io_add(frnew, as); } =20 ++inew; --=20 2.19.1