From patchwork Sun Jul 22 06:09:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 10539187 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 D8764174A for ; Sun, 22 Jul 2018 06:12:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C640F2785D for ; Sun, 22 Jul 2018 06:12:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA9822793A; Sun, 22 Jul 2018 06:12:14 +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 5FF022785D for ; Sun, 22 Jul 2018 06:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728322AbeGVHGq (ORCPT ); Sun, 22 Jul 2018 03:06:46 -0400 Received: from mga02.intel.com ([134.134.136.20]:8994 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728312AbeGVHGp (ORCPT ); Sun, 22 Jul 2018 03:06:45 -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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jul 2018 23:11:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,388,1526367600"; d="scan'208";a="218015822" Received: from allen-box.sh.intel.com ([10.239.48.172]) by orsmga004.jf.intel.com with ESMTP; 21 Jul 2018 23:11:12 -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 02/10] iommu/vt-d: Alloc domain for a mediated device Date: Sun, 22 Jul 2018 14:09:25 +0800 Message-Id: <1532239773-15325-3-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 The PASID-granular 2nd level address translation makes it possible to isolate and protect a mediated device exposed by a real device which support PCI PASID features. This patch adds support to allocate a domain for a mediated device. A default pasid value will be allocated as well for the mediated device. This will be used by the mediated device attached to this domain for non-SVM DMA transactions. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Signed-off-by: Sanjay Kumar Signed-off-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 17 ++++++++++++++++- include/linux/intel-iommu.h | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index fc3ac1c..3ede34a 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -1926,6 +1926,9 @@ static void domain_exit(struct dmar_domain *domain) domain_remove_dev_info(domain); rcu_read_unlock(); + if (domain->default_pasid > 0) + intel_pasid_free_id(domain->default_pasid); + /* destroy iovas */ put_iova_domain(&domain->iovad); @@ -2519,11 +2522,23 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, } } + if (dev && dev_is_mdev(dev) && domain->default_pasid <= 0) { + int max = intel_pasid_get_dev_max_id(dev_mdev_parent(dev)); + + domain->default_pasid = intel_pasid_alloc_id(domain, PASID_MIN, + max, GFP_KERNEL); + if (domain->default_pasid < 0) { + free_devinfo_mem(info); + return NULL; + } + } + spin_lock_irqsave(&device_domain_lock, flags); if (dev) found = find_domain(dev); - if (!found) { + /* A mediated device never has an DMA alias. Ignore searching. */ + if (!found && !dev_is_mdev(dev)) { struct device_domain_info *info2; info2 = dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); if (info2) { diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 7efc632..9f5dcf6 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -423,6 +423,11 @@ struct dmar_domain { 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ u64 max_addr; /* maximum mapped address */ + int default_pasid; /* + * The default pasid used for non-SVM + * traffic on mediated devices. + */ + struct iommu_domain domain; /* generic domain data structure for iommu core */ };