Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1086033imp; Thu, 21 Feb 2019 18:26:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IaR5Ktv/Mjx8VQiC/I8+q5yr+BqG7FeILDCyCFQeQMcq3loNGG6xnR2n8GpyMQRxQI/6mYp X-Received: by 2002:a63:ce16:: with SMTP id y22mr1673116pgf.296.1550802385405; Thu, 21 Feb 2019 18:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550802385; cv=none; d=google.com; s=arc-20160816; b=UKAy/W/nV1KNITYunON1cK8l1HryeVaVOuYLoP2Z/6xUUCFUlYj/vocTJE/uqe/PZM qqhH8G3jpaJm/WBEMeIAQQbses/+I9tv0Yj2lphs0VGF3EiUHg4gEeZH4rbz2fFQmht+ dX0TTnX/K6575GCQI54xpKFXKUm51a8ivTKOWKjpfwEo8QTWgX2VuqNvjbnhXkdH90M5 tVYYryzxdV83/KSnYqLxgYgIeQjfLkrcx4TE9Lt9j3We6SvLHjjazo/0NMOECo4X3wI2 ZnJd5w+ttRqbV7AI3DAcb6VknKSz4jGatBGQhbV3kz0gj7bAlkOb2rnL5ydXo91sZP8p t7qg== 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=j0d9p1z7gVx7Vi1JkmCvZcjARD3cbNJUDXJAt48iA2Y=; b=TvWS+LbO+a8zhMnFLb9Y4sUgbfJPXr4SG+GFsc0QwvTWk9T0K8rmBX3ulJutnJVJPX 1Mssp0+Vg12I6Ngnw8+uKyLynIVQ4+myj2wfDJK4xJrUNBgmTVaoUkvzFzX664AUyQYB sAnzumj8LPWpxk1s/ATrFxK6LnYdKMJYu2vzBjXV7fujV3Vq9tOBG2N3cp/VhitGRwzb ch5r121C8n7EeIXc/fRN7vGW+s8G/eNc7MJgcQlwtmOVspLYaSvipd3TxbZewqYwgnFg Ymptybr3+oLKbYj56ujw1mzOVXUHW0m/YV4xQkcwhRkmSDqxQYOks6vUyly+agrUyCwb rleA== 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 cn6si186015plb.242.2019.02.21.18.26.10; Thu, 21 Feb 2019 18:26:25 -0800 (PST) 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 S1727331AbfBVCZb (ORCPT + 99 others); Thu, 21 Feb 2019 21:25:31 -0500 Received: from mga01.intel.com ([192.55.52.88]:59159 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727198AbfBVCZ3 (ORCPT ); Thu, 21 Feb 2019 21:25:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2019 18:25:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,397,1544515200"; d="scan'208";a="116855246" Received: from allen-box.sh.intel.com ([10.239.159.136]) by orsmga007.jf.intel.com with ESMTP; 21 Feb 2019 18:25:25 -0800 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, xin.zeng@intel.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v7 9/9] vfio/type1: Handle different mdev isolation type Date: Fri, 22 Feb 2019 10:19:27 +0800 Message-Id: <20190222021927.13132-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190222021927.13132-1-baolu.lu@linux.intel.com> References: <20190222021927.13132-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 Signed-off-by: Sanjay Kumar Signed-off-by: Liu Yi L Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- drivers/vfio/vfio_iommu_type1.c | 48 ++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index ccc4165474aa..f1392c582a3c 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1368,13 +1368,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 (!new || (*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; @@ -1409,23 +1436,30 @@ 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 || !iommu_device) { if (!iommu->external_domain) { INIT_LIST_HEAD(&domain->group_list); iommu->external_domain = domain; - } else + } else { kfree(domain); + } 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