From patchwork Thu Dec 19 16:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 182139 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702465iln; Thu, 19 Dec 2019 08:31:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwdrvZLTCGoRJmCapHMA4cJs+NMEfeLpS2mwWJkTQOsJUYdkP2bxRfEwFNGUaAX252evLkJ X-Received: by 2002:a9d:70cb:: with SMTP id w11mr9831131otj.157.1576773094513; Thu, 19 Dec 2019 08:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773094; cv=none; d=google.com; s=arc-20160816; b=VU+E9pkVgpnTXIba8svdh+JsC28LgcRS0fGpH/Mg5Pt2uZR6rDTY8JvJBp080Xq1A+ 2/EVuujv454dzoOF6ENxgyiUmqyMj1JiFPGR/2aet18pBKmQoylm7aGySNCqPX8tFalH iR3G6wLAUwmgz5JJF3bSLHS76U9V/F/g3F86moUlterIm6zBi+JPMfxTkD1vOh8g30bq g0lvEITFx+6gHhIojhFJPADxhlLZnS2dL+IMzYbN+RdoNJhZN4rgRH3mlDbgyCzKGyez oE/oN3iYAR+o+Fz/Sl+Qz2z758l837M7xPKR83YtG2k+EIdAQenN2ed2aqQPi/42QwuW 62kg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FYioDhZ/j/78qMyUi+NbeqzegCC3zzPggnOI7+kacPU=; b=zw5SAa6IgxWr05cGwtiewA+gJhnAVT1V3m3yfH0lt16he6CvdcWd4K0couK2xT5bdF 986fitH+MRTBRbMK6mbxS0DqWLpbwlkqVbi2tq8gCvVizd+F+ma3ogwlo/sNAq7gdzNZ UfPVzViQ89V1Vo1PIkzQNiJHXbxvxQzEgdDxB41IxxkAGLIM6Cgbh/RhEgvftsAHAWeM 3oLSD0HcqnTrjO7+PUl01yUBa80Iap8BKUsWCuZnhfcmgQtCV5EVDHo6w1oGhy3sYB1V ttn7IkHAiTSY1vf+PBSOs7r9ynyGw9y3hlo4RYLIhrQRQdIjP8l32tQRsg2LmaE9mVti 622Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E5aFBHpx; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si2200080oij.175.2019.12.19.08.31.34; Thu, 19 Dec 2019 08:31:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E5aFBHpx; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbfLSQbd (ORCPT + 8 others); Thu, 19 Dec 2019 11:31:33 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39694 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726967AbfLSQbc (ORCPT ); Thu, 19 Dec 2019 11:31:32 -0500 Received: by mail-wm1-f67.google.com with SMTP id 20so6165952wmj.4 for ; Thu, 19 Dec 2019 08:31:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FYioDhZ/j/78qMyUi+NbeqzegCC3zzPggnOI7+kacPU=; b=E5aFBHpxzJkkIdtB9W66GN6ZLoFLgZNBR0wli2z1R1GfTj4GDjCqIV7HMTgweAZs/m ERMXbIUqhoOBDH6Y6yVu9fvJUbv1S/8bk4nVNiphi6Bj9Hr+xJPMF+CM0wdD4p/Nxi15 DDZ2eWHA4Po8SV0rJ2mSAgR36BjhDGY65Cg+Nrvt9skytm0oy8yLdbTRRrrti8PY8sxG GqI3y8AJ1hhG5ISFHxJBz9r9FQVWnJK5gOR2aOQHSLuQPhBDyUQ6M6IhwH5s6ciR9Vts 9/GMh/foacnJ6Etj2gcl6Fz+phGe372ALVmMIdUJmCb95IS4K+ulNixBQU6NY1edO0qz 7V/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FYioDhZ/j/78qMyUi+NbeqzegCC3zzPggnOI7+kacPU=; b=SjA2yCdqSkzUINDYpSu7fNwgJmLX8kIrPwnfiW5fFqIXehqbfTXkY0W8kxtnGxuzp5 TZ4WT7OSItiMnK7C/e/5S/6h/CJ0yqAWp5E8BWtVoCofoyJ7UNnUCXDUoUaPARkFXIlV mufDOJcLA4T4PsTtNqOAsm+i1wqDi6KueRctT1V4fegHxFk6mvbZfN+CQAp0OK8y6+Vp i8FksPDoquilGELczjDerEKNdObibMOA5E8by1E2+zfm0rCY2wWId0rNDvaW5ihXqkYl 5RM6l3NgtYL5q6xa/o14pb1daYBEISIrf95nq11Otwqzbgb/aHIosTazXhIv4oEApabf WvEA== X-Gm-Message-State: APjAAAW0XaPcYFO9N8dVHOFupy7ct9PT5WtS0X1DBhaoDgTChCWqoRPb gaysPUMqlwNO9olQuJ9aVI6qQw== X-Received: by 2002:a1c:80d4:: with SMTP id b203mr10896801wmd.102.1576773089551; Thu, 19 Dec 2019 08:31:29 -0800 (PST) Received: from localhost.localdomain (adsl-84-227-176-239.adslplus.ch. [84.227.176.239]) by smtp.gmail.com with ESMTPSA id u22sm7092068wru.30.2019.12.19.08.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:29 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, will@kernel.org, robin.murphy@arm.com, bhelgaas@google.com, eric.auger@redhat.com, jonathan.cameron@huawei.com, zhangfei.gao@linaro.org Subject: [PATCH v4 08/13] iommu/arm-smmu-v3: Propagate ssid_bits Date: Thu, 19 Dec 2019 17:30:28 +0100 Message-Id: <20191219163033.2608177-9-jean-philippe@linaro.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219163033.2608177-1-jean-philippe@linaro.org> References: <20191219163033.2608177-1-jean-philippe@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Now that we support substream IDs, initialize s1cdmax with the number of SSID bits supported by a master and the SMMU. Context descriptor tables are allocated once for the first master attached to a domain. Therefore attaching multiple devices with different SSID sizes is tricky, and we currently don't support it. As a future improvement it would be nice to at least support attaching a SSID-capable device to a domain that isn't using SSID, by reallocating the SSID table. This would allow supporting a SSID-capable device that is in the same IOMMU group as a bridge, for example. Varying SSID size is less of a concern, since the PCIe specification "highly recommends" that devices supporting PASID implement all 20 bits of it. Tested-by: Zhangfei Gao Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index e1bec7e552b9..e147087198ef 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2279,6 +2279,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) } static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) { int ret; @@ -2290,6 +2291,8 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, if (asid < 0) return asid; + cfg->s1cdmax = master->ssid_bits; + ret = arm_smmu_alloc_cd_tables(smmu_domain); if (ret) goto out_free_asid; @@ -2306,6 +2309,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, } static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) { int vmid; @@ -2322,7 +2326,8 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, return 0; } -static int arm_smmu_domain_finalise(struct iommu_domain *domain) +static int arm_smmu_domain_finalise(struct iommu_domain *domain, + struct arm_smmu_master *master) { int ret; unsigned long ias, oas; @@ -2330,6 +2335,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) struct io_pgtable_cfg pgtbl_cfg; struct io_pgtable_ops *pgtbl_ops; int (*finalise_stage_fn)(struct arm_smmu_domain *, + struct arm_smmu_master *, struct io_pgtable_cfg *); struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; @@ -2384,7 +2390,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) domain->geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; domain->geometry.force_aperture = true; - ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg); + ret = finalise_stage_fn(smmu_domain, master, &pgtbl_cfg); if (ret < 0) { free_io_pgtable_ops(pgtbl_ops); return ret; @@ -2537,7 +2543,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (!smmu_domain->smmu) { smmu_domain->smmu = smmu; - ret = arm_smmu_domain_finalise(domain); + ret = arm_smmu_domain_finalise(domain, master); if (ret) { smmu_domain->smmu = NULL; goto out_unlock; @@ -2549,6 +2555,13 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) dev_name(smmu->dev)); ret = -ENXIO; goto out_unlock; + } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && + master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) { + dev_err(dev, + "cannot attach to incompatible domain (%u SSID bits != %u)\n", + smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); + ret = -EINVAL; + goto out_unlock; } master->domain = smmu_domain;