Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp276109imm; Wed, 29 Aug 2018 21:12:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZNWgMzG0ZaROhsnp6LOi72gPLWjpbjb4yXHBkfrlIdNOBkCQP1UOLLPaAcpyPZPyoMf0Uj X-Received: by 2002:a62:be03:: with SMTP id l3-v6mr8734748pff.138.1535602365269; Wed, 29 Aug 2018 21:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535602365; cv=none; d=google.com; s=arc-20160816; b=xIe6FcSD2UpDZaucUirngTbiWB5UWh/ec7lPDhKT15qB4Fz8WuWbvH2/646ZRnFLom ukD24wYdepZJ46c+psaMf/85rn/8Vr+SHNJM0R+deMs/UwbdtW1pOjgA5g4qSx648+4i nSIEcdWxcGvXRnxVDljJuCB6lkKNOVLi3jJ1MoR2Pq+estXD1XiogL0LIvkUvSrsHTQs O44m2koW8YxSK4Ap6uluuNjKglEN6GyRBv3U3QZRK3Jud83aLvELWfHTtZSIKgJNf2xm y8xgZkb8cqinkuQ0T3nQn6I8cLjVwVli1C4jmHli+0N4OHUAoPm4sp1Vjm1ZQVU42b0+ /Muw== 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=vcG0rWONIepPewSVGn/9US0XOJwV5PCZDUgMUOcruvI=; b=IYUUNRtZya3hR44n+HplJghMRQBoeP2Qetg2HoakQes8f+IOgwQLYAzePy5Y5F0sUq 7iTNgsXKtKdvqtjfOBujwsTDkA+h3CR6ETGfXybCMlsVe9ss84G0IIZzo+iHiWYU3niS D0mQ0lwjnBTRts51uAhxPe2+lQCaoOQNxcHs74bdAOJ4er7bwXyW7zRIyQGXb+OuyHPB KJ+Cu6sgDesPnjpeS+fjp8D7yvY1bOsDZ50iHBUa9HWWFs5YH7bMnYQPmikhe3PVwy4i gcWaNFB1bgArCJi6J7dcV52jh+SW2uqnZhAl0X0FlDVPwX60aZgDhwzfgLfxdqcPPo5X 6GNg== 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 b9-v6si5252330pfi.99.2018.08.29.21.12.30; Wed, 29 Aug 2018 21:12:45 -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 S1727788AbeH3IL1 (ORCPT + 99 others); Thu, 30 Aug 2018 04:11:27 -0400 Received: from mga02.intel.com ([134.134.136.20]:31601 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727765AbeH3IL0 (ORCPT ); Thu, 30 Aug 2018 04:11:26 -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:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,306,1531810800"; d="scan'208";a="68959996" Received: from allen-box.sh.intel.com ([10.239.161.122]) by orsmga007.jf.intel.com with ESMTP; 29 Aug 2018 21:11:13 -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 10/10] vfio/type1: Attach domain for mdev group Date: Thu, 30 Aug 2018 12:09:22 +0800 Message-Id: <20180830040922.30426-11-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 When attaching domain to a group of mediated devices which all have the domain type attributes set to ATTACH_PARENT, we should attach domain to the parent PCI device instead of mdev device itself. 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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 64bf55b91de1..c4231df44304 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1411,6 +1411,18 @@ static int vfio_mdev_domain_type(struct device *dev, void *data) return -EINVAL; } +static int vfio_parent_bus_type(struct device *dev, void *data) +{ + struct bus_type **bus = data; + + if (*bus && *bus != dev->parent->bus) + return -EINVAL; + + *bus = dev->parent->bus; + + return 0; +} + static int vfio_iommu_type1_attach_group(void *iommu_data, struct iommu_group *iommu_group) { @@ -1458,6 +1470,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, enum mdev_domain_type type = 0; symbol_put(mdev_bus_type); + mdev_bus = NULL; /* Determine the domain type: */ ret = iommu_group_for_each_dev(iommu_group, &type, @@ -1479,7 +1492,14 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, return 0; case DOMAIN_TYPE_ATTACH_PARENT: - /* FALLTHROUGH */ + bus = NULL; + group->attach_parent = true; + /* Set @bus to bus type of the parent: */ + ret = iommu_group_for_each_dev(iommu_group, &bus, + vfio_parent_bus_type); + if (ret) + goto out_free; + break; default: ret = -EINVAL; goto out_free; -- 2.17.1