From nobody Mon Feb 9 15:46:02 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=1566409040; cv=none; d=zoho.com; s=zohoarc; b=dYJFCFfIpBPNmM9f51yL8SVn3dloPA2nEDo5UCB6H8veWcnmpoVFTZal0WGx1iQGGtCt6GuDfkNyIj+Q21X1kY9PFJQlIEUpTVK6XZOTpVwNI1hkakaENQR3UJtKfRsT6bCVC98gsIVcj+55WgbwhBU/OQodYepJN6nJ9M2lhPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566409040; 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=q0WIpxt/Gb95FjDlw8upNG/PDQFdd4b7BdvQBJiEi0M=; b=buy24PGbSuSVj/Eb0dlNHpVDORTLj3jLCmeb5pI2gSaVb1O35RlmIyQjXUXsBUVw3iGXyAjd8I05iMecoB3qSA405/L1kxgs1/JznpnHAn7nzTMW4ypVlDWAgfGfVnNYg9wg1/GZnEFrXSiVrD4TVRGMYV2qu8/LUMGHlCAqrIE= 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 1566409040898762.3703908670389; Wed, 21 Aug 2019 10:37:20 -0700 (PDT) Received: from localhost ([::1]:51181 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0UXv-0001B3-Bh for importer@patchew.org; Wed, 21 Aug 2019 13:37:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40355) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0UPe-0006vL-OP for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0UPd-0005Rd-Fu for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0UPd-0005QU-78 for qemu-devel@nongnu.org; Wed, 21 Aug 2019 13:28:45 -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 917211089041 for ; Wed, 21 Aug 2019 17:28:44 +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 8E1EF60E1C; Wed, 21 Aug 2019 17:28:43 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 19:28:17 +0200 Message-Id: <1566408501-48680-10-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.64]); Wed, 21 Aug 2019 17:28:44 +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 09/13] memory: Split zones when do coalesced_io_del() 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 It is a workaround of current KVM's KVM_UNREGISTER_COALESCED_MMIO interface. The kernel interface only allows to unregister an mmio device with exactly the zone size when registered, or any smaller zone that is included in the device mmio zone. It does not support the userspace to specify a very large zone to remove all the small mmio devices within the zone covered. Logically speaking it would be nicer to fix this from KVM side, though in all cases we still need to coop with old kernels so let's do this. Fixes: 3ac7d43a6fbb5d4a3 Signed-off-by: Peter Xu Message-Id: <20190820141328.10009-2-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- memory.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/memory.c b/memory.c index 9a1193a..7124274 100644 --- a/memory.c +++ b/memory.c @@ -855,8 +855,39 @@ static void address_space_update_ioeventfds(AddressSpa= ce *as) flatview_unref(view); } =20 +/* + * Notify the memory listeners about the coalesced IO change events of + * range `cmr'. Only the part that has intersection of the specified + * FlatRange will be sent. + */ +static void flat_range_coalesced_io_notify(FlatRange *fr, AddressSpace *as, + CoalescedMemoryRange *cmr, bool= add) +{ + AddrRange tmp; + + tmp =3D addrrange_shift(cmr->addr, + int128_sub(fr->addr.start, + int128_make64(fr->offset_in_region))); + if (!addrrange_intersects(tmp, fr->addr)) { + return; + } + tmp =3D addrrange_intersection(tmp, fr->addr); + + if (add) { + MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, coalesced_io_add, + int128_get64(tmp.start), + int128_get64(tmp.size)); + } else { + MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del, + int128_get64(tmp.start), + int128_get64(tmp.size)); + } +} + static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as) { + CoalescedMemoryRange *cmr; + if (!fr->has_coalesced_range) { return; } @@ -865,16 +896,15 @@ static void flat_range_coalesced_io_del(FlatRange *fr= , AddressSpace *as) return; } =20 - MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del, - int128_get64(fr->addr.start), - int128_get64(fr->addr.size)); + QTAILQ_FOREACH(cmr, &fr->mr->coalesced, link) { + flat_range_coalesced_io_notify(fr, as, cmr, false); + } } =20 static void flat_range_coalesced_io_add(FlatRange *fr, AddressSpace *as) { MemoryRegion *mr =3D fr->mr; CoalescedMemoryRange *cmr; - AddrRange tmp; =20 if (QTAILQ_EMPTY(&mr->coalesced)) { return; @@ -885,16 +915,7 @@ static void flat_range_coalesced_io_add(FlatRange *fr,= AddressSpace *as) } =20 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)); + flat_range_coalesced_io_notify(fr, as, cmr, true); } } =20 --=20 1.8.3.1