From nobody Fri Nov 7 00:47:20 2025 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; dkim=fail; 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 1544629209504698.0953418814605; Wed, 12 Dec 2018 07:40:09 -0800 (PST) Received: from localhost ([::1]:45643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6cK-0005ni-Bu for importer@patchew.org; Wed, 12 Dec 2018 10:40:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6Mc-0000tc-C2 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX6MZ-0000HX-9T for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:54 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:38516) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gX6MY-0008Rd-HN for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:50 -0500 Received: by mail-wm1-x336.google.com with SMTP id m22so6399228wml.3 for ; Wed, 12 Dec 2018 07:23:31 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id u10sm15878859wrr.33.2018.12.12.07.23.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 07:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=rd2Vyu38hRvfe0+5R7hABpqckE2TpPeLieSeYkqFf+Q=; b=t8pHyYUn1Or5p9NAloMvr+SqW/E4aRS7g82dx/BQnBOOTpa5s726I9aYfhivEW0oY0 JAiZ4ZM/rTfJ3eoIk/4pispq/K+SUmRsGDEGify0M5b72dsuLweoG4KSNyMm8Jtjy3hZ j8jdxNfFgITwhcIvVGOvWa9cuqV6c7Qe8o1HUFkpDxv0hSaYaEosZiIdupIfL9xtv0zw Y5VpPS1gu3XCqI241DwfJpwj/it03rT9Onnf4A83s7hyW4guTG8CtNQzxvf4SR8ZcYrR Wk1vgp9UogttTLGyi3bildPcQDKn3GomO5c0cHD1USUDsGwzUn87LqrWadkthGmwv56L Ihow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=rd2Vyu38hRvfe0+5R7hABpqckE2TpPeLieSeYkqFf+Q=; b=r0ZkOT+raSwMsjw6fRNjLmdaFhD8g+yhdI3hxSwksqijcFScTxEClYakPvLmj0yjOi 4lsCFQdFQ7q3WppRuU/JCmi4vlGsANR/esG0FVo2wuiYv6E/OYhALarxGKJcdp+o0SCg 7Nh5nQMxoPkv1NgHCMp9jkPiEAtmKYse6uf8vLNs2oblJxPbJ7p137WepJpLfaEEewWU 2aI798Ke2RayQkleBtPNZsKs8hmr+66fkjZ0GQtg4lUi6NykIlM0TNmy3GbSxBXRwIPh xRhRvsVI0QPfTY6pn83qF61C6Kc14YjB46HIUHifTBErn+CXC6MiNLjmCWwKY6R1W5fs 7LoA== X-Gm-Message-State: AA+aEWbLZwL751Ug4pkUeDjnZLKQuDIIiC8PK+6uGZUZnmBlW4oLDMnR 0y8dhMUtRMAZ1BXV6swkU8JRlTTA X-Google-Smtp-Source: AFSGD/UG7kJIR4JRZuzopTEyQB6ZIcw/KXrQuDIPcIbLNW9SUFbLM3cQxBSfnpmnW4dEIZfiMX5uIw== X-Received: by 2002:a1c:2d42:: with SMTP id t63mr7041731wmt.9.1544628210401; Wed, 12 Dec 2018 07:23:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 12 Dec 2018 16:22:31 +0100 Message-Id: <1544628195-37728-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> References: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 Subject: [Qemu-devel] [PULL 10/54] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 Signed-off-by: Paolo Bonzini --- memory.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/memory.c b/memory.c index 072769a..5759f74 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 1.8.3.1