Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp276688imm; Wed, 29 Aug 2018 21:14:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYpYjIJJuGWFdZtaw7SdQiesDi+jZhTnc/A/5dEWoi18r8ZGhrMH6u2V9nak7HPPUbD7Owi X-Received: by 2002:a17:902:4601:: with SMTP id o1-v6mr8672139pld.202.1535602455200; Wed, 29 Aug 2018 21:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535602455; cv=none; d=google.com; s=arc-20160816; b=UMzLbyvKZmwiwNf8dD3MJ44sSpj3HS3eW+z51RdSCPkpAW7AUypK0AD53uD8JWzMW2 WxgZ/6yxS2EDjoOWUF/IMwZKYOidm0EIpPLsyHsVPDjJGTBvPTj7hMDlQaiVSfUO1v4D h9qIXBPNLqUp1cvD79VjobiJbV/zX8bToHZc6TVrZCOG+Hp1LFIs+yPcvPqkPQIamqA/ JedlvKGwanBl3JeS857ow29SDNnLJX4PTlxe34Q0VzvPpCTwmaWrN16esde3DpUskbtw WqTUhhWfSVfYBqDWuSEXfPCh3/lijUh5MT6F4BrH/bK4o2Zk3HaMZwQFs6dVkDqU1IhP Gcdw== 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:arc-authentication-results; bh=aaYJ/LUE9I6ytBjLvUaDAo1kDrBjAlCpewm3HNAXda4=; b=C6KsoOgMw8wmKfdt4AwjOSam1txi1ZBP0uHzX9pgFONTGqatO7IaxQCe0Sqy15vdBO la+H6uaM2UBkNbV9Vu7+11EdY/v2M7r0jVqIQSEgjsTHCXnBfkmLmnRXvTEv7MxWa5Gp YLsLCKOBBj360oVnO/SjL+bCheFLttqOjsc8XVoWBhZyXhR9WjE951nlCwn4Wx7bbo3u kIzrKiFI51XHcKbgMF+W+xxeDvZqXuDcqaI+Hp549h6+srMPGk1Vh8TK49FNRyUcfUXM 5WEsznYERukOuF58Gz8WdWgUaXLBULVD0XFONJ56W+KuFQ4f/Ev9sDuqIuSA9iO7VRWv I1Sg== 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 l5-v6si5735664pgh.451.2018.08.29.21.14.01; Wed, 29 Aug 2018 21:14:15 -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 S1727713AbeH3ILX (ORCPT + 99 others); Thu, 30 Aug 2018 04:11:23 -0400 Received: from mga02.intel.com ([134.134.136.20]:31597 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727694AbeH3ILX (ORCPT ); Thu, 30 Aug 2018 04:11:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2018 21:11:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,306,1531810800"; d="scan'208";a="68959991" Received: from allen-box.sh.intel.com ([10.239.161.122]) by orsmga007.jf.intel.com with ESMTP; 29 Aug 2018 21:11:10 -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: [RFC PATCH v2 09/10] vfio/type1: Determine domain type of an mdev group Date: Thu, 30 Aug 2018 12:09:21 +0800 Message-Id: <20180830040922.30426-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180830040922.30426-1-baolu.lu@linux.intel.com> References: <20180830040922.30426-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 domain type of a group of mediated devices according to the domain type attribute of each device. 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 | 47 ++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 89e2e6123223..64bf55b91de1 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1390,6 +1390,27 @@ static void vfio_iommu_detach_group(struct vfio_domain *domain, iommu_detach_group(domain->domain, group->iommu_group); } +static int vfio_mdev_domain_type(struct device *dev, void *data) +{ + enum mdev_domain_type new, *old = data; + enum mdev_domain_type (*fn)(struct device *dev); + + fn = symbol_get(mdev_get_domain_type); + if (fn) { + new = fn(dev); + symbol_put(mdev_get_domain_type); + + if (*old && *old != new) + return -EINVAL; + + *old = new; + + return 0; + } + + return -EINVAL; +} + static int vfio_iommu_type1_attach_group(void *iommu_data, struct iommu_group *iommu_group) { @@ -1433,9 +1454,19 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, mdev_bus = symbol_get(mdev_bus_type); - if (mdev_bus) { - if ((bus == mdev_bus) && !iommu_present(bus)) { - symbol_put(mdev_bus_type); + if (mdev_bus && bus == mdev_bus) { + enum mdev_domain_type type = 0; + + symbol_put(mdev_bus_type); + + /* Determine the domain type: */ + ret = iommu_group_for_each_dev(iommu_group, &type, + vfio_mdev_domain_type); + if (ret) + goto out_free; + + switch (type) { + case DOMAIN_TYPE_NO_IOMMU: if (!iommu->external_domain) { INIT_LIST_HEAD(&domain->group_list); iommu->external_domain = domain; @@ -1445,11 +1476,19 @@ 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; + case DOMAIN_TYPE_ATTACH_PARENT: + /* FALLTHROUGH */ + default: + ret = -EINVAL; + goto out_free; } - symbol_put(mdev_bus_type); } + if (mdev_bus) + symbol_put(mdev_bus_type); + domain->domain = iommu_domain_alloc(bus); if (!domain->domain) { ret = -EIO; -- 2.17.1