From nobody Mon Feb 9 18:44:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566409933; cv=none; d=zoho.com; s=zohoarc; b=SB/D8/D9hcE8SXvNUIQ6Ezjx0qi3k+VpaQcC+kk7gf6rdzV4zcm/9FwRatyvdJiP3boWPW1w+kNcPh42l8xzH4Gudvjz48TV1FyNP+yh0W1RCPPra/vwOI3H54lBnqIAR9EP/tl5pmj/vyq94SgcGSzKSfzolTjQUVuA7k+keKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566409933; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9Hus6FJW0VW6sn0nmlBO7FFk2x4zd4T0VvmgIxasqd8=; b=NigPsJKPu8vWgMGrEXb/bV132QFrUie08IkIA7UYo/IQjemAnThBTH+bqy+vreeauOFklVpmU7fJddpln+wUJpxSQ3vI7A5aE0y2zikyyO6dB9KFMDW4MS55GPBp6Qt+MA+xemFNeBzRoSk0u2++uwMw4tcUeNgg/+mAYkrgrxI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566409933212677.3414706556957; Wed, 21 Aug 2019 10:52:13 -0700 (PDT) Received: from localhost ([::1]:51366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0UmJ-0004ZW-Gr for importer@patchew.org; Wed, 21 Aug 2019 13:52:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40424) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0UPl-000777-0c for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0UPj-0005ZA-PP for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39024) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0UPj-0005Yc-Gl for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC46518C4260 for ; Wed, 21 Aug 2019 17:28:50 +0000 (UTC) Received: from 640k.localdomain.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7942760E1C; Wed, 21 Aug 2019 17:28:48 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 19:28:19 +0200 Message-Id: <1566408501-48680-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1566408501-48680-1-git-send-email-pbonzini@redhat.com> References: <1566408501-48680-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Wed, 21 Aug 2019 17:28:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/13] memory: Fix up memory_region_{add|del}_coalescing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu The old memory_region_{add|clear}_coalescing() has some defects because they both changed mr->coalesced before updating the regions using memory_region_update_coalesced_range_as(). Then when the regions were updated in memory_region_update_coalesced_range_as() the mr->coalesced will always be either one more or one less. So: - For memory_region_add_coalescing: it'll always trying to remove the newly added coalesced region while it shouldn't, and, - For memory_region_clear_coalescing: when it calls the update there will be no coalesced ranges on mr->coalesced because they were all removed before hand so the update will probably do nothing for real. Let's fix this. Now we've got flat_range_coalesced_io_notify() to notify a single CoalescedMemoryRange instance change, so use it in the existing memory_region_update_coalesced_range() logic by only notify either an addition or deletion. Then we hammer both the memory_region_{add|clear}_coalescing() to use it. Fixes: 3ac7d43a6fbb5d4a3 Signed-off-by: Peter Xu Message-Id: <20190820141328.10009-5-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- memory.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/memory.c b/memory.c index 6e4b06e..7fd93b1 100644 --- a/memory.c +++ b/memory.c @@ -2243,27 +2243,26 @@ void memory_region_ram_resize(MemoryRegion *mr, ram= _addr_t newsize, Error **errp qemu_ram_resize(mr->ram_block, newsize, errp); } =20 -static void memory_region_update_coalesced_range_as(MemoryRegion *mr, Addr= essSpace *as) +/* + * Call proper memory listeners about the change on the newly + * added/removed CoalescedMemoryRange. + */ +static void memory_region_update_coalesced_range(MemoryRegion *mr, + CoalescedMemoryRange *cmr, + bool add) { + AddressSpace *as; FlatView *view; FlatRange *fr; =20 - view =3D address_space_get_flatview(as); - FOR_EACH_FLAT_RANGE(fr, view) { - if (fr->mr =3D=3D mr) { - flat_range_coalesced_io_del(fr, as); - flat_range_coalesced_io_add(fr, as); - } - } - flatview_unref(view); -} - -static void memory_region_update_coalesced_range(MemoryRegion *mr) -{ - AddressSpace *as; - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - memory_region_update_coalesced_range_as(mr, as); + view =3D address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + if (fr->mr =3D=3D mr) { + flat_range_coalesced_io_notify(fr, as, cmr, add); + } + } + flatview_unref(view); } } =20 @@ -2281,7 +2280,7 @@ void memory_region_add_coalescing(MemoryRegion *mr, =20 cmr->addr =3D addrrange_make(int128_make64(offset), int128_make64(size= )); QTAILQ_INSERT_TAIL(&mr->coalesced, cmr, link); - memory_region_update_coalesced_range(mr); + memory_region_update_coalesced_range(mr, cmr, true); memory_region_set_flush_coalesced(mr); } =20 @@ -2299,10 +2298,9 @@ void memory_region_clear_coalescing(MemoryRegion *mr) while (!QTAILQ_EMPTY(&mr->coalesced)) { cmr =3D QTAILQ_FIRST(&mr->coalesced); QTAILQ_REMOVE(&mr->coalesced, cmr, link); + memory_region_update_coalesced_range(mr, cmr, false); g_free(cmr); } - - memory_region_update_coalesced_range(mr); } =20 void memory_region_set_flush_coalesced(MemoryRegion *mr) --=20 1.8.3.1