From nobody Tue Jul 1 05:36:00 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486457413930540.2921205720105; Tue, 7 Feb 2017 00:50:13 -0800 (PST) Received: from localhost ([::1]:52711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb1TY-0001W1-Gs for importer@patchew.org; Tue, 07 Feb 2017 03:50:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb19j-00027k-7t for qemu-devel@nongnu.org; Tue, 07 Feb 2017 03:29:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cb19i-0004gC-6N for qemu-devel@nongnu.org; Tue, 07 Feb 2017 03:29:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cb19h-0004fj-UB for qemu-devel@nongnu.org; Tue, 07 Feb 2017 03:29:42 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07D9481222; Tue, 7 Feb 2017 08:29:42 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-8-29.pek2.redhat.com [10.72.8.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v178SQee025608; Tue, 7 Feb 2017 03:29:36 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 7 Feb 2017 16:28:15 +0800 Message-Id: <1486456099-7345-14-git-send-email-peterx@redhat.com> In-Reply-To: <1486456099-7345-1-git-send-email-peterx@redhat.com> References: <1486456099-7345-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Feb 2017 08:29:42 +0000 (UTC) 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 v7 13/17] memory: introduce memory_region_notify_one() 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: tianyu.lan@intel.com, kevin.tian@intel.com, mst@redhat.com, jan.kiszka@siemens.com, jasowang@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, bd.aviv@gmail.com, David Gibson 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" Generalizing the notify logic in memory_region_notify_iommu() into a single function. This can be further used in customized replay() functions for IOMMUs. Signed-off-by: Peter Xu Reviewed-by: David Gibson --- include/exec/memory.h | 15 +++++++++++++++ memory.c | 40 ++++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 606ce88..0767888 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -682,6 +682,21 @@ void memory_region_notify_iommu(MemoryRegion *mr, IOMMUTLBEntry entry); =20 /** + * memory_region_notify_one: notify a change in an IOMMU translation + * entry to a single notifier + * + * This works just like memory_region_notify_iommu(), but it only + * notifies a specific notifier, not all of them. + * + * @notifier: the notifier to be notified + * @entry: the new entry in the IOMMU translation table. The entry + * replaces all old entries for the same virtual I/O address range. + * Deleted entries have .@perm =3D=3D 0. + */ +void memory_region_notify_one(IOMMUNotifier *notifier, + IOMMUTLBEntry *entry); + +/** * memory_region_register_iommu_notifier: register a notifier for changes = to * IOMMU translation entries. * diff --git a/memory.c b/memory.c index 9e1bb75..7a4f2f9 100644 --- a/memory.c +++ b/memory.c @@ -1666,32 +1666,40 @@ void memory_region_unregister_iommu_notifier(Memory= Region *mr, memory_region_update_iommu_notify_flags(mr); } =20 -void memory_region_notify_iommu(MemoryRegion *mr, - IOMMUTLBEntry entry) +void memory_region_notify_one(IOMMUNotifier *notifier, + IOMMUTLBEntry *entry) { - IOMMUNotifier *iommu_notifier; IOMMUNotifierFlag request_flags; =20 - assert(memory_region_is_iommu(mr)); + /* + * Skip the notification if the notification does not overlap + * with registered range. + */ + if (notifier->start > entry->iova + entry->addr_mask + 1 || + notifier->end < entry->iova) { + return; + } =20 - if (entry.perm & IOMMU_RW) { + if (entry->perm & IOMMU_RW) { request_flags =3D IOMMU_NOTIFIER_MAP; } else { request_flags =3D IOMMU_NOTIFIER_UNMAP; } =20 + if (notifier->notifier_flags & request_flags) { + notifier->notify(notifier, entry); + } +} + +void memory_region_notify_iommu(MemoryRegion *mr, + IOMMUTLBEntry entry) +{ + IOMMUNotifier *iommu_notifier; + + assert(memory_region_is_iommu(mr)); + IOMMU_NOTIFIER_FOREACH(iommu_notifier, mr) { - /* - * Skip the notification if the notification does not overlap - * with registered range. - */ - if (iommu_notifier->start > entry.iova + entry.addr_mask + 1 || - iommu_notifier->end < entry.iova) { - continue; - } - if (iommu_notifier->notifier_flags & request_flags) { - iommu_notifier->notify(iommu_notifier, &entry); - } + memory_region_notify_one(iommu_notifier, &entry); } } =20 --=20 2.7.4