From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F88EECDFB8 for ; Sun, 22 Jul 2018 06:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F05A020874 for ; Sun, 22 Jul 2018 06:11:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F05A020874 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728599AbeGVHGx (ORCPT ); Sun, 22 Jul 2018 03:06:53 -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 S1728408AbeGVHGw (ORCPT ); Sun, 22 Jul 2018 03:06:52 -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:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,388,1526367600"; d="scan'208";a="218015851" Received: from allen-box.sh.intel.com ([10.239.48.172]) by orsmga004.jf.intel.com with ESMTP; 21 Jul 2018 23:11:18 -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 04/10] iommu/vt-d: Get pasid table for a mediated device Date: Sun, 22 Jul 2018 14:09:27 +0800 Message-Id: <1532239773-15325-5-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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the support to get the pasid table for a mediated device. The assumption is that each mediated device is a minimal assignable set of a physical PCI device. Hence, we should use the pasid table of the parent PCI device to manage the translation. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Signed-off-by: Lu Baolu --- drivers/iommu/intel-pasid.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 1195c2a..9b4d462 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -129,7 +129,19 @@ int intel_pasid_alloc_table(struct device *dev) int ret, order; info = dev->archdata.iommu; - if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table)) + if (WARN_ON(!info || info->pasid_table)) + return -EINVAL; + + /* Use parent PCI device pasid table for mdev: */ + if (dev_is_mdev(dev)) { + pasid_table = intel_pasid_get_table(dev_mdev_parent(dev)); + if (pasid_table) + goto attach_out; + else + return -ENOMEM; + } + + if (WARN_ON(!dev_is_pci(dev))) return -EINVAL; /* DMA alias device already has a pasid table, use it: */ @@ -190,7 +202,7 @@ void intel_pasid_free_table(struct device *dev) int i, max_pde; info = dev->archdata.iommu; - if (!info || !dev_is_pci(dev) || !info->pasid_table) + if (!info || !info->pasid_table) return; pasid_table = info->pasid_table; -- 2.7.4