From patchwork Tue Jan 24 07:48:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9534143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 03AAA6046A for ; Tue, 24 Jan 2017 07:48:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5F0823E64 for ; Tue, 24 Jan 2017 07:48:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D81462624B; Tue, 24 Jan 2017 07:48:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5132D23E64 for ; Tue, 24 Jan 2017 07:48:56 +0000 (UTC) Received: from localhost ([::1]:46586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVvqY-0004Ye-TZ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Jan 2017 02:48:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVvq1-0004WL-LR for qemu-devel@nongnu.org; Tue, 24 Jan 2017 02:48:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVvpx-00071e-2Z for qemu-devel@nongnu.org; Tue, 24 Jan 2017 02:48:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cVvpw-00071B-Q1 for qemu-devel@nongnu.org; Tue, 24 Jan 2017 02:48:16 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 C6ABE4E05F; Tue, 24 Jan 2017 07:48:15 +0000 (UTC) Received: from pxdev.xzpeter.org (dhcp-14-110.nay.redhat.com [10.66.14.110]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0O7mB54029497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 24 Jan 2017 02:48:13 -0500 Date: Tue, 24 Jan 2017 15:48:11 +0800 From: Peter Xu To: Alex Williamson Message-ID: <20170124074811.GC16400@pxdev.xzpeter.org> References: <1484917736-32056-1-git-send-email-peterx@redhat.com> <1484917736-32056-11-git-send-email-peterx@redhat.com> <20170123121244.78cc7e49@t450s.home> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170123121244.78cc7e49@t450s.home> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Jan 2017 07:48:15 +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: Re: [Qemu-devel] [PATCH RFC v4 10/20] memory: add section range info for IOMMU notifier 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, qemu-devel@nongnu.org, bd.aviv@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Jan 23, 2017 at 12:12:44PM -0700, Alex Williamson wrote: > On Fri, 20 Jan 2017 21:08:46 +0800 > Peter Xu wrote: > > > In this patch, IOMMUNotifier.{start|end} are introduced to store section > > information for a specific notifier. When notification occurs, we not > > only check the notification type (MAP|UNMAP), but also check whether the > > notified iova is in the range of specific IOMMU notifier, and skip those > > notifiers if not in the listened range. > > > > When removing an region, we need to make sure we removed the correct > > VFIOGuestIOMMU by checking the IOMMUNotifier.start address as well. > > > > Suggested-by: David Gibson > > Signed-off-by: Peter Xu > > --- > > changelog (start from vt-d vfio enablement series v3): > > v4: > > - introduce memory_region_iommu_notifier_init() [Jason] > > --- > > hw/vfio/common.c | 12 +++++++++--- > > hw/virtio/vhost.c | 4 ++-- > > include/exec/memory.h | 19 ++++++++++++++++++- > > memory.c | 5 ++++- > > 4 files changed, 33 insertions(+), 7 deletions(-) > > > Acked-by: Alex Williamson Thanks for the ack! Sorry that I want to tune this patch a bit - I'll loosen the limit on the range check. The original patch will notify if iova is inside range (start, end), while I am tuning it to allow the notification happen as long as (iova, size) and (start, end) has any overlapping. The diff against this one would be (for your better reference): ------8<------- ------>8------- I'll post with the complete patch along with the series's next post. Thanks, -- peterx diff --git a/memory.c b/memory.c index 89104b1..80ab3c1 100644 --- a/memory.c +++ b/memory.c @@ -1672,9 +1672,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, } QLIST_FOREACH(iommu_notifier, &mr->iommu_notify, node) { - if (iommu_notifier->notifier_flags & request_flags && - iommu_notifier->start <= entry.iova && - iommu_notifier->end >= entry.iova) { + /* + * 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); } }