From patchwork Wed Apr 26 10:06:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Yi L" X-Patchwork-Id: 755373 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wCbpT4Q8Rz9s2Q for ; Wed, 26 Apr 2017 20:26:25 +1000 (AEST) Received: from localhost ([::1]:54047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K9P-0004D0-2u for incoming@patchwork.ozlabs.org; Wed, 26 Apr 2017 06:26:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3K7A-0002g6-Qs for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3K76-0002JK-Eq for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:04 -0400 Received: from mga06.intel.com ([134.134.136.31]:52653) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3K76-0002I6-4f for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:24:00 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP; 26 Apr 2017 03:23:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,254,1488873600"; d="scan'208";a="79066360" Received: from sky-dev.bj.intel.com ([10.238.145.47]) by orsmga002.jf.intel.com with ESMTP; 26 Apr 2017 03:23:56 -0700 From: "Liu, Yi L" To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Date: Wed, 26 Apr 2017 18:06:37 +0800 Message-Id: <1493201210-14357-8-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> References: <1493201210-14357-1-git-send-email-yi.l.liu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [RFC PATCH 07/20] VFIO: check notifier flag in region_del() 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, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kvm@vger.kernel.org, jean-philippe.brucker@arm.com, jasowang@redhat.com, iommu@lists.linux-foundation.org, jacob.jun.pan@intel.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch adds flag check when unregistering MAP/UNMAP notifier in region_del. MAP/UNMAP notifier would be unregistered when iommu memory region is deleted. This is to avoid unregistering other notifiers. Peter Xu's intel_iommu enhancement series has introduced dynamic switch of IOMMU region. If an assigned device switches to use "pt", the IOMMU region would be deleted, thus the MAP/UNMAP notifier would be unregistered. While for some cases, the other notifiers may still wanted. e.g. if a user decides to use vSVM for the assigned device after the switch, then the pasid table bind notifier is needed. The newly added pasid table bind notifier would be unregistered in the vfio_disconnect_container(). The link below would direct you to Peter's dynamic switch patch. https://www.mail-archive.com/qemu-devel@nongnu.org/msg444462.html Signed-off-by: Liu, Yi L --- hw/vfio/common.c | 5 +++-- include/exec/memory.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e270255..719de61 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -501,7 +501,7 @@ static void vfio_listener_region_add(MemoryListener *listener, section->size); llend = int128_sub(llend, int128_one()); iommu_notifier_init(&n, vfio_iommu_map_notify, - IOMMU_NOTIFIER_ALL, + IOMMU_NOTIFIER_MAP_UNMAP, section->offset_within_region, int128_get64(llend)); @@ -578,7 +578,8 @@ static void vfio_listener_region_del(MemoryListener *listener, QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { if (giommu->iommu == section->mr && - giommu->n.start == section->offset_within_region) { + giommu->n.start == section->offset_within_region && + giommu->n.notifier_flags & IOMMU_NOTIFIER_MAP_UNMAP) { memory_region_unregister_iommu_notifier(giommu->iommu, &giommu->n); QLIST_REMOVE(giommu, giommu_next); diff --git a/include/exec/memory.h b/include/exec/memory.h index d2f24cc..7bd13ab 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -85,7 +85,7 @@ typedef enum { IOMMU_NOTIFIER_SVM_PASIDT_BIND = 0x4, } IOMMUNotifierFlag; -#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) +#define IOMMU_NOTIFIER_MAP_UNMAP (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) struct IOMMUNotifier; typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier,