Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4344359ybi; Tue, 11 Jun 2019 05:14:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQf/lFRfxDcQVNHYaZwo/GO4LcRjsJmIDUcMjpaM+QbJN9i6F/Qvn9TVvzeH5ZEXr60JMq X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr75142793plg.190.1560255252061; Tue, 11 Jun 2019 05:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560255252; cv=none; d=google.com; s=arc-20160816; b=Quy+H6x/aXxKZ8KGATWqZon/J6M3I1jUzPrxUAQZu1fnPTgAv0Ju6donXm6qkkdEvA UPd8pEs0Z349g9mNP38ZBGSN+UyOba7wTHGjgz6pOIjARlxvjI6/u5rhRn17c1AB5B/R JN1DBFuaBtdpSLXA+48z8kIdXxUurnAIkdEBfIFqewkr4h6bzvITuSb2AHQYbVQRQ4u8 tE/k+ke5XKq/xrMLvwCqHie8v7e2PBZJI1HrlLqlF8h8PDhVaupwXRFiX1nBZew/n5zp MVp6bFFXTzoez8Jat+ST06TP3z6pPM30LnP8RCI9p5PHI2Xx53xJ5ahOIhji/eRt00+1 d/og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=hqV3qIKCGpfUzxKKI1Yeej5QjPhl5MQip4I9uAkXAO8=; b=u623bLpm09t54IfnOqPD+d4VjYRC2A6UdVtwIFs2q1EYm/MZdUp/DRxeWoRTXVD8Mp aBkV4j80UySvbagFnhv66mAs0qJ81lBbYv4RueFDm9ycpNsbjzw01KmLnootvp9CT77F zfuIVk44UNHpDWg7ffX3mxEwxujRzvoO2kb/RB7AOjZ5IcgJTswfUmHJTiB6jKnuHfkC jghdGTUrO339+R+/7inQzsSZmou034p7DtSbBGIYmWOdyfSvCqffB+XK8qGkz90sC9qC Zk9VQkNL2UGtBB+I7kCB39VjbPqX2F7oxqL0OxTq8dJfQbMjW11VZCBWRLJ2urzzZ0Oi MCqw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si13064638pgm.531.2019.06.11.05.13.55; Tue, 11 Jun 2019 05:14:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728607AbfFKKp6 (ORCPT + 99 others); Tue, 11 Jun 2019 06:45:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:18547 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726713AbfFKKp5 (ORCPT ); Tue, 11 Jun 2019 06:45:57 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6A2DE477F75B8C656581; Tue, 11 Jun 2019 18:45:55 +0800 (CST) Received: from localhost (10.202.226.61) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Tue, 11 Jun 2019 18:45:52 +0800 Date: Tue, 11 Jun 2019 11:45:42 +0100 From: Jonathan Cameron To: Jean-Philippe Brucker CC: , , , , , , , Subject: Re: [PATCH 8/8] iommu/arm-smmu-v3: Add support for PCI PASID Message-ID: <20190611114542.000021f1@huawei.com> In-Reply-To: <20190610184714.6786-9-jean-philippe.brucker@arm.com> References: <20190610184714.6786-1-jean-philippe.brucker@arm.com> <20190610184714.6786-9-jean-philippe.brucker@arm.com> Organization: Huawei X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.61] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 10 Jun 2019 19:47:14 +0100 Jean-Philippe Brucker wrote: > Enable PASID for PCI devices that support it. Since the SSID tables are > allocated by arm_smmu_attach_dev(), PASID has to be enabled early enough. > arm_smmu_dev_feature_enable() would be too late, since by that time the > main DMA domain has already been attached. Do it in add_device() instead. > > Signed-off-by: Jean-Philippe Brucker Nitpick in line. Thanks, Jonathan > --- > drivers/iommu/arm-smmu-v3.c | 51 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 50 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c > index 972bfb80f964..a8a516d9ff10 100644 > --- a/drivers/iommu/arm-smmu-v3.c > +++ b/drivers/iommu/arm-smmu-v3.c > @@ -2197,6 +2197,49 @@ static void arm_smmu_disable_ats(struct arm_smmu_master *master) > master->ats_enabled = false; > } > > +static int arm_smmu_enable_pasid(struct arm_smmu_master *master) > +{ > + int ret; > + int features; > + int num_pasids; > + struct pci_dev *pdev; > + > + if (!dev_is_pci(master->dev)) > + return -ENOSYS; > + > + pdev = to_pci_dev(master->dev); > + > + features = pci_pasid_features(pdev); > + if (features < 0) > + return -ENOSYS; > + > + num_pasids = pci_max_pasids(pdev); > + if (num_pasids <= 0) > + return -ENOSYS; > + > + ret = pci_enable_pasid(pdev, features); > + if (!ret) > + master->ssid_bits = min_t(u8, ilog2(num_pasids), > + master->smmu->ssid_bits); > + return ret; > +} > + > +static void arm_smmu_disable_pasid(struct arm_smmu_master *master) > +{ > + struct pci_dev *pdev; > + > + if (!dev_is_pci(master->dev)) > + return; > + > + pdev = to_pci_dev(master->dev); > + > + if (!pdev->pasid_enabled) > + return; > + > + pci_disable_pasid(pdev); > + master->ssid_bits = 0; If we are being really fussy about ordering, why have this set of ssid_bits after pci_disable_pasid rather than before (to reverse order of .._enable_pasid)? > +} > + > static void arm_smmu_detach_dev(struct arm_smmu_master *master) > { > unsigned long flags; > @@ -2413,6 +2456,9 @@ static int arm_smmu_add_device(struct device *dev) > > master->ssid_bits = min(smmu->ssid_bits, fwspec->num_pasid_bits); > > + /* Note that PASID must be enabled before, and disabled after ATS */ > + arm_smmu_enable_pasid(master); > + > /* > * If the SMMU doesn't support 2-stage CD, limit the linear > * tables to a reasonable number of contexts, let's say > @@ -2423,7 +2469,7 @@ static int arm_smmu_add_device(struct device *dev) > > ret = iommu_device_link(&smmu->iommu, dev); > if (ret) > - goto err_free_master; > + goto err_disable_pasid; > > group = iommu_group_get_for_dev(dev); > if (IS_ERR(group)) { > @@ -2436,6 +2482,8 @@ static int arm_smmu_add_device(struct device *dev) > > err_unlink: > iommu_device_unlink(&smmu->iommu, dev); > +err_disable_pasid: > + arm_smmu_disable_pasid(master); > err_free_master: > kfree(master); > fwspec->iommu_priv = NULL; > @@ -2456,6 +2504,7 @@ static void arm_smmu_remove_device(struct device *dev) > arm_smmu_detach_dev(master); > iommu_group_remove_device(dev); > iommu_device_unlink(&smmu->iommu, dev); > + arm_smmu_disable_pasid(master); > kfree(master); > iommu_fwspec_free(dev); > }