From patchwork Sun Jul 22 06:09:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 10539175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEAE214BC for ; Sun, 22 Jul 2018 06:11:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DABD72785D for ; Sun, 22 Jul 2018 06:11:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC3A52793A; Sun, 22 Jul 2018 06:11:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61BDF2785D for ; Sun, 22 Jul 2018 06:11:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729591AbeGVHHM (ORCPT ); Sun, 22 Jul 2018 03:07:12 -0400 Received: from mga06.intel.com ([134.134.136.31]:12836 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729585AbeGVHHM (ORCPT ); Sun, 22 Jul 2018 03:07:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jul 2018 23:11:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,388,1526367600"; d="scan'208";a="218015961" Received: from allen-box.sh.intel.com ([10.239.48.172]) by orsmga004.jf.intel.com with ESMTP; 21 Jul 2018 23:11:38 -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, yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [RFC PATCH 10/10] vfio/type1: Allocate domain for mediated device Date: Sun, 22 Jul 2018 14:09:33 +0800 Message-Id: <1532239773-15325-11-git-send-email-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532239773-15325-1-git-send-email-baolu.lu@linux.intel.com> References: <1532239773-15325-1-git-send-email-baolu.lu@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This allocates a domain for the mediated device if it is able to be isolated and protected individually by IOMMU. 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 | 43 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 3e5b177..496bea6 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1177,6 +1177,22 @@ static int vfio_bus_type(struct device *dev, void *data) return 0; } +static int mdev_private_domain(struct device *dev, void *data) +{ + enum mdev_domain_type type; + enum mdev_domain_type (*fn)(struct device *dev); + + fn = symbol_get(mdev_get_domain_type); + if (fn) { + type = fn(dev); + symbol_put(mdev_get_domain_type); + + return type != DOMAIN_TYPE_PRIVATE; + } + + return -EINVAL; +} + static int vfio_iommu_replay(struct vfio_iommu *iommu, struct vfio_domain *domain) { @@ -1371,18 +1387,23 @@ 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 (!iommu->external_domain) { - INIT_LIST_HEAD(&domain->group_list); - iommu->external_domain = domain; - } else - kfree(domain); + if (bus == mdev_bus) { + ret = iommu_group_for_each_dev(iommu_group, NULL, + mdev_private_domain); + if (!iommu_present(bus) || ret) { + symbol_put(mdev_bus_type); + if (!iommu->external_domain) { + INIT_LIST_HEAD(&domain->group_list); + iommu->external_domain = domain; + } else { + kfree(domain); + } - list_add(&group->next, - &iommu->external_domain->group_list); - mutex_unlock(&iommu->lock); - return 0; + list_add(&group->next, + &iommu->external_domain->group_list); + mutex_unlock(&iommu->lock); + return 0; + } } symbol_put(mdev_bus_type); }