Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp348324imm; Thu, 11 Oct 2018 22:22:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV60i173nAFV2x0UhNVffr+FRS+fhWit1RGcN2da5BfaEkzDDC7fHAqKGh0rcMAT41YXT7zDJ X-Received: by 2002:a62:36c3:: with SMTP id d186-v6mr4477991pfa.133.1539321720190; Thu, 11 Oct 2018 22:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539321720; cv=none; d=google.com; s=arc-20160816; b=JdHWHIUM6d636FF3ZAB7yuSJ+lEsoRZ4E4xpyv52Zgwem6tW3u936cVxQCC6g1lF0G 3WCM/Kf8J/SmMK3C7PHyGfhPav4l40M5e7REg0fewxLNCLFTIEqrRGYVNS8un3jg8Oag xJFr9+0CFQCvLWXPmI3yaXlFhjj3s/Q3j0/PoYpmsdBVZmkS/45FgcygcU0tCHhKBYbH bqUTp+a0rBn5rD9OEnJ0Dq8kLh2v3jRbYebXmay9OazMIvuYvoKmwc4VrPse3fUqn9ZJ F30cbwdyF8BTpy7xeOfemAw4xV8PV543nfwdlH64BlDD34DGVhVD5tJKiMvZwjMV/gIu NnYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=44/O85UW2AXiYKa51vccPu7akaFlnk3zn1GbG5vugF0=; b=yu4QrW9/r6S2FXgvhY8DXvCA0ZzJMyH70d+a0mOfzs9FjLtrA/KaJ4rwFjBmA1uG04 HfgKTHHODfn8v3GC/t/6z/76kc3fbUGO1fsATTm4zTgvarcAHTg4aMQ4mHK3foj6UvtR B06PI17KmIz4X+mNqjukW14KphvNjjHqmOHU7keftXGsVOHVUCoX9bsXrYKLCr9FIZ7H oVggHMeHboKYF3M/DxSCXYb7I1EB+yWQdZThJMGi8Wv5tlHpvPX3m4G+La9LYkM4r8hx 94bSIQQX8yjySXCXMfHnuiw02s6q49KghRS5ANBazMQNVGocNZZP1y3DLsa85V4gJHzu 5C6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si96590pfh.232.2018.10.11.22.21.45; Thu, 11 Oct 2018 22:22:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727745AbeJLMuK (ORCPT + 99 others); Fri, 12 Oct 2018 08:50:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:62564 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727227AbeJLMuK (ORCPT ); Fri, 12 Oct 2018 08:50:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 22:19:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,371,1534834800"; d="scan'208";a="80842274" Received: from allen-box.sh.intel.com ([10.239.161.122]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2018 22:19:05 -0700 From: Lu Baolu To: Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, Jean-Philippe Brucker , yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, tiwei.bie@intel.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v3 8/8] vfio/type1: Handle different mdev isolation type Date: Fri, 12 Oct 2018 13:16:32 +0800 Message-Id: <20181012051632.26064-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012051632.26064-1-baolu.lu@linux.intel.com> References: <20181012051632.26064-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds the support to determine the isolation type of a mediated device group by checking whether it has an iommu device. If an iommu device exists, an iommu domain will be allocated and then attached to the iommu device. Otherwise, keep the same behavior as it is. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Signed-off-by: Sanjay Kumar Signed-off-by: Lu Baolu --- drivers/vfio/vfio_iommu_type1.c | 48 ++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 3617499c95c9..471a95e6da66 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1411,13 +1411,40 @@ static void vfio_iommu_detach_group(struct vfio_domain *domain, iommu_detach_group(domain->domain, group->iommu_group); } +static bool vfio_bus_is_mdev(struct bus_type *bus) +{ + struct bus_type *mdev_bus; + bool ret = false; + + mdev_bus = symbol_get(mdev_bus_type); + if (mdev_bus) { + ret = (bus == mdev_bus); + symbol_put(mdev_bus_type); + } + + return ret; +} + +static int vfio_mdev_iommu_device(struct device *dev, void *data) +{ + struct device **old = data, *new; + + new = vfio_mdev_get_iommu_device(dev); + if (*old && *old != new) + return -EINVAL; + + *old = new; + + return 0; +} + static int vfio_iommu_type1_attach_group(void *iommu_data, struct iommu_group *iommu_group) { struct vfio_iommu *iommu = iommu_data; struct vfio_group *group; struct vfio_domain *domain, *d; - struct bus_type *bus = NULL, *mdev_bus; + struct bus_type *bus = NULL; int ret; bool resv_msi, msi_remap; phys_addr_t resv_msi_base; @@ -1452,11 +1479,18 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, if (ret) goto out_free; - mdev_bus = symbol_get(mdev_bus_type); + if (vfio_bus_is_mdev(bus)) { + struct device *iommu_device = NULL; - if (mdev_bus) { - if ((bus == mdev_bus) && !iommu_present(bus)) { - symbol_put(mdev_bus_type); + group->mdev_group = true; + + /* Determine the isolation type */ + ret = iommu_group_for_each_dev(iommu_group, &iommu_device, + vfio_mdev_iommu_device); + if (ret) + goto out_free; + + if (!iommu_device) { if (!iommu->external_domain) { INIT_LIST_HEAD(&domain->group_list); iommu->external_domain = domain; @@ -1466,9 +1500,11 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, list_add(&group->next, &iommu->external_domain->group_list); mutex_unlock(&iommu->lock); + return 0; } - symbol_put(mdev_bus_type); + + bus = iommu_device->bus; } domain->domain = iommu_domain_alloc(bus); -- 2.17.1