From patchwork Thu Dec 19 16:30:21 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: 182132 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702198iln; Thu, 19 Dec 2019 08:31:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzTzojdA88jPcWdH4tBisyhm/wWBZbWezlc3F32rwEG6/f3izsnfTS0hSx3NzZie8QiVDIO X-Received: by 2002:a05:6830:1e46:: with SMTP id e6mr6816696otj.245.1576773084117; Thu, 19 Dec 2019 08:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773084; cv=none; d=google.com; s=arc-20160816; b=n9PdUcnOjQ2WdnnWt6qTBgeIykoDRcaO4+jU1hYwt8pQAtKnvJEg2B6ypDt/Vb3BxA uDsi5tCf3ASy2kYhvfcwSu5eQCRMR2Y1iwIrFr6laJ2Au9N7RDfy6g5gv+YN5EQ63oeR FjtnbutAs4eDgBBGx1NRK3PMFaM1HJSMeoAhmnBQ/WEZVQASAZ/x/Moj+8y4cnFvxfK+ u2V+G1yiNlljCTKWjuexr4UmWb5/vEMRyCjbDQb1J+IEbKFQS1IhDSCUYWbYdYNHqHZW kNLpJlh5Xxt4qcdnYjGMwUpa9RRQ0qjbwH3oO87xvhdJse2B8hyTDL7uU7Oij9a4Yyjv k7sA== 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=qvpO6T6lCyQjsFcC/B3MAQOfFJPvli4NlBcE8bVnq2o=; b=uqWeWuQpNfbmVbb4K4dqZ5tZQeiocDQvosUE6UlO6SObjsidgTbfq3qAHEss4kiwi/ Z/qXiFD3Xp6TLhwNEDfsBhiGS1wf9PfRR6E2QurvuVStjwJqUZKIbMs5h5iTOJ4ptlnI KbSbhOUbXUK2Vv3Okq2jZM8ASfUyqJSWy3QOuiX/UHQdJP0OPMNwyY/2ZUIy4rNmpxIH 6xnCXqnkCyRFPlvT99/diJ+Ec/P/yDCZckGBFgFfOzsmjamxMgfqvYJ9p5QDG723IYIU KR6PR2sMoBvgdBNhyFsj7OJ4rQvkmhiZS2zudmI0R54JCvCbVt8hNWOnJDOQLSKpuGTO pVzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ybmj/yFM"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.23; Thu, 19 Dec 2019 08:31:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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="ybmj/yFM"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726869AbfLSQbX (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:23 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37260 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbfLSQbW (ORCPT ); Thu, 19 Dec 2019 11:31:22 -0500 Received: by mail-wm1-f65.google.com with SMTP id f129so6285476wmf.2 for ; Thu, 19 Dec 2019 08:31:20 -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=qvpO6T6lCyQjsFcC/B3MAQOfFJPvli4NlBcE8bVnq2o=; b=ybmj/yFMV4WPp7svNei7QMmCl8bEZOgf5I1OmMiNuceKiEvs5FOwc+5QNBcmfQrlON DofenBUgXZTyi4JhcRiIepGkKcdGY4BtKidQwP7/JHO1FEOJNjzrzX8jKjeJNf5cwrSN tS2rRvNKSfBvhZDS+GHaReUR5s84Sru30RnnKkOevGMAjdhnFV1FNoTdrYF5xTS2C5Pz pBv91NSiFLc4P/2cJ1BRlji6oxczL+VzlLLYhsrAz88xLoCnUc9XjeqfwlqEjDnliWJA 9uGe7CZ4PKzluz2OcGmuwW1v9QwotUUAWENXlNB7vZEd8IAreHDTExzizhbd8YlzdFMR HnXg== 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=qvpO6T6lCyQjsFcC/B3MAQOfFJPvli4NlBcE8bVnq2o=; b=SkmezmyYi8jZuaIoz/MkzG1JqeWvzWQXBX2Gahu0pYLJGRTyC0R8Bvo042I0nUrG5b xmtdAyBcwPPBVJDDvylRnBIqB1FbxUURWOICj92QXfiX2E3jBDswBRl9ole6GXKq7+6H m8dNv/q4wexJ5hYPGaRLL0478LeJHU4dMnCGIkZTziqoMtfspdFEckOcCcrS7aDlyXXI gEKcW1bZKQ8v+N6sWPgAQpZkjz/qdumg6RRGqtojXy9S5qwYfniWSUZdPzwkrjMVRIY6 wkeK3ddZPHyt7ihRcn0ZMb0ertsxVGaC0V0DTSMiHvIRuf6LQNhNhir+eJmHSGRlvbx5 2K7A== X-Gm-Message-State: APjAAAXEeD7T44YFE/zfzCeWNYmCEmElOQBItR2jwlOoD10rPpf/Fbbt h/MdyEFo2juNeslCwlZyioCd+w== X-Received: by 2002:a1c:b456:: with SMTP id d83mr10758320wmf.172.1576773080107; Thu, 19 Dec 2019 08:31:20 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:19 -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 01/13] iommu/arm-smmu-v3: Drop __GFP_ZERO flag from DMA allocation Date: Thu, 19 Dec 2019 17:30:21 +0100 Message-Id: <20191219163033.2608177-2-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since commit 518a2f1925c3 ("dma-mapping: zero memory returned from dma_alloc_*"), dma_alloc_* always initializes memory to zero, so there is no need to use dma_zalloc_* or pass the __GFP_ZERO flag anymore. The flag was introduced by commit 04fa26c71be5 ("iommu/arm-smmu: Convert DMA buffer allocations to the managed API"), since the managed API didn't provide a dmam_zalloc_coherent() function. Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index effe72eb89e7..d4e8b7f8d9f4 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1675,7 +1675,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) desc->span = STRTAB_SPLIT + 1; desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma, - GFP_KERNEL | __GFP_ZERO); + GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -2161,8 +2161,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, return asid; cfg->cdptr = dmam_alloc_coherent(smmu->dev, CTXDESC_CD_DWORDS << 3, - &cfg->cdptr_dma, - GFP_KERNEL | __GFP_ZERO); + &cfg->cdptr_dma, GFP_KERNEL); if (!cfg->cdptr) { dev_warn(smmu->dev, "failed to allocate context descriptor\n"); ret = -ENOMEM; @@ -2883,7 +2882,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, - GFP_KERNEL | __GFP_ZERO); + GFP_KERNEL); if (!strtab) { dev_err(smmu->dev, "failed to allocate l1 stream table (%u bytes)\n", @@ -2910,7 +2909,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma, - GFP_KERNEL | __GFP_ZERO); + GFP_KERNEL); if (!strtab) { dev_err(smmu->dev, "failed to allocate linear stream table (%u bytes)\n", From patchwork Thu Dec 19 16:30:24 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: 182135 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702319iln; Thu, 19 Dec 2019 08:31:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwQUvvHTmpeZZ/Tm3us6vB/OqSdjN5MZd61VZ2ciHae6qbX+XJ+oUaL7IvQH3NwYxDGho0J X-Received: by 2002:aca:f1c2:: with SMTP id p185mr2539043oih.87.1576773089118; Thu, 19 Dec 2019 08:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773089; cv=none; d=google.com; s=arc-20160816; b=um2OpTuAEox2A0HNqSgSXcGmNtbapPFhK3eU9v49mFbEsdyDggdxhL8/vYqykAkqXY UERlAw2E/ydpM99xC+j0xqC7lgT7+xJjI/CUm++3wJ+huoAj9r02WzCkXTmqTrKoTzdT W7z4EF4/rjSlfFUdqDT9LCUZHdV2hyubrz+Y8UNUUV+Z10OlTs09o/0CmETulM4KM7OS CehLyTj9FOGjmBG4HxiFqxExW+7JfyAHBiegjcIderFeRI0D6zpOeIToR33Keu+v0Ehm e9AVAEpTVWkSyh4k2fKAAiBMtJoysuyFH4R5yu6lP6q+g/sMq2YQG90ZqK2HYLmyNWIG Rafg== 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=SVox6K0aClSgQAj4ZePzlVYlKOAA5RM1JxWE0eeJ+CM=; b=YtqAozdug+eOaOHeDJILdcCXIzqAlU1g5iSho0zEG/pT4ZUHfVQDEtCgOERRa9NL6E /BCYiZPXV+rxjH9Ri4FlPO5yrNacY+Y4p0obTr064ZwfU1iNCZZqP0dsHfwrBCAu3HHM oqkYgRXaiRbVa9BS0xeH4vmDFJD3p9MR59HkeCzJ1pC62GnI4Ag2P0KwLu3Gi6cqCEDm 95c3f1UUxKS1s5CVtPOCz0plc29v4tumfhTgZiF10Fza6uXuqD07la5b7DRISvl+VmSJ vlyueoQL7u41ifJf3x19H4aJvNx56tsQzIkI2/MXkV0ISfIUk0fM/9b5ettO9AUwVgfX blgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KsJmWTGB; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.28; Thu, 19 Dec 2019 08:31:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=KsJmWTGB; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726963AbfLSQb1 (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:27 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43176 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbfLSQb0 (ORCPT ); Thu, 19 Dec 2019 11:31:26 -0500 Received: by mail-wr1-f67.google.com with SMTP id d16so6592418wre.10 for ; Thu, 19 Dec 2019 08:31:25 -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=SVox6K0aClSgQAj4ZePzlVYlKOAA5RM1JxWE0eeJ+CM=; b=KsJmWTGBulFgtHxInjLbvLy9PpRX0GteBfzNXmUrDZJrH+ZYaBQIa1dHh47VnHT3Us G2OJX3xgvKyS2XK3zuqcw1ZOXlKDVBJQRRMVF0nOr9xyj+lDw01Q6Jd6vR/rkeYccEHt yJOWYb/rjfBgXbMc7wgknxeamdVg+ZZN29ommW/LnpTHOjUz0VpuiDmfABbg1QOhKWEP BK79LYU2nE8gQz8QcvCdTDHowZsM7F9ia5UVAVVs4wcvu3pPH0s1tj25cZ4VQrLWBmC5 SAfWsR+i6gOKs+s2DrspT9Ahp+NfOeXnTsawx79CvIM08A0Wu8V+jAyezZPtTeJVSYeM zLKA== 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=SVox6K0aClSgQAj4ZePzlVYlKOAA5RM1JxWE0eeJ+CM=; b=OhD6875XFOTdtSgFcDdu9YHyE7P8K1tM0Wcq7fSviHmMHKLwyrz6/uNSNrPwpIIrTq o91cJeIjoGk2whtlJtRk8yewTzUeUaUb8mSyzL1uYcOI1ihZDSaFp15e3LwOGwFoKDX9 YeyROP8zkLf9bYRUvKA0ZdmgAV6dLTbMkqT8X29oxsuCQqKEVhpJGrqQkaDYFNvjmHRZ Kmv25BlX/ASCkrxm5r+jUqi9uESlfyY//9E0sFnWP0r8hKEFOq8CUWgqxPrXPiN6eGWB qhX+TPLSYAVMa6e25o/pc0gE3JTRDLIPpezW2CeXKzzj4E/CmjPI0yPaqsl4voKRFMIQ HfEA== X-Gm-Message-State: APjAAAX/bknP+w4kVqErlx04p4Xh3/OX27w1/BR21laTrgwUsFAYE8cY i83wW5iVWMURzP+fP+ZuQH05Jw== X-Received: by 2002:adf:eb48:: with SMTP id u8mr9977279wrn.283.1576773084271; Thu, 19 Dec 2019 08:31:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:23 -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 04/13] ACPI/IORT: Parse SSID property of named component node Date: Thu, 19 Dec 2019 17:30:24 +0100 Message-Id: <20191219163033.2608177-5-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Named component nodes in the IORT tables describe the number of Substream ID bits (aka. PASID) supported by the device. Propagate this value to the fwspec structure in order to enable PASID for platform devices. Acked-by: Hanjun Guo Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/acpi/arm64/iort.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.24.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 33f71983e001..39f389214ecf 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) "ACPI: IORT: " fmt #include +#include #include #include #include @@ -924,6 +925,20 @@ static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data) return iort_iommu_xlate(info->dev, parent, streamid); } +static void iort_named_component_init(struct device *dev, + struct acpi_iort_node *node) +{ + struct acpi_iort_named_component *nc; + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + + if (!fwspec) + return; + + nc = (struct acpi_iort_named_component *)node->node_data; + fwspec->num_pasid_bits = FIELD_GET(ACPI_IORT_NC_PASID_BITS, + nc->node_flags); +} + /** * iort_iommu_configure - Set-up IOMMU configuration for a device. * @@ -978,6 +993,9 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev) if (parent) err = iort_iommu_xlate(dev, parent, streamid); } while (parent && !err); + + if (!err) + iort_named_component_init(dev, node); } /* From patchwork Thu Dec 19 16:30:25 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: 182136 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702337iln; Thu, 19 Dec 2019 08:31:29 -0800 (PST) X-Google-Smtp-Source: APXvYqx/ODvxt4UfwcJpvs4edIZsgi6Neixp6kTle+Lqm8DS+hXzjlaF+J2KTuAXU88egPf+wxvO X-Received: by 2002:a9d:760f:: with SMTP id k15mr9588857otl.65.1576773089845; Thu, 19 Dec 2019 08:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773089; cv=none; d=google.com; s=arc-20160816; b=QSdC45yI9yCc47mUx53qw9czFvdnpkW7ccdZY1tE6jEG9v5gppFy7NVH6xvtbus175 fZPX3SSxYttKbM600/2iy6UQxWkU09m6rsgynXHfJmEI0LJB2n16VGJSa+T4GWhHmeaI dUeWxv4lom9J4FG0IE2jr+SrTfjaHMZTaCnSHivvvmbm+DAP4tjae9xiP7sqaO51DCyy TzGZJY/M827+HhGMUsCJPFWgexzVDbKnc9TUgbmDmPi4mfeQC/fALIUf07VuBdgMpo+w /h3FBXTtXak77XXNPfpgGQCrrQOg0euRqPTbBpQaJHg1I97yIICAm05o8Q/eWUnkxyPq /L+w== 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=Y2ql+LZRHzKAFXmCII7idFGR9pobHaST91PSU352afA=; b=msID2maWTiWBMY2uY0pVpfDwweY9AVCsvLQJ3MKV1q05KDqFu8tnD0l5eJrCVWStRI KgMaUaKf1aTIzFouDcLBgN2sErFS77w0DGSZ9GOtrVX1hiXOSrX6uN1q77pRGDuf1EmA TUTVGnrNV9LHdOq9hMxUfwEvmdUPzRUwhMVS2/nvm/3hORP+mMiD3+Q7jH+sk8gjkbis 1QAK/hBnVnnhjzK40XhCOuVI3YUrWIkkOgrVh6XMJLYOAVrOKkxfEbuiMHTTbIIxyNjt oMp2gZnht3ZkRr1hBt6iJEbf/0d8AgeH4VINZRG7p3fk5+k1yhFJGBveu2HRQkZzvM/R 33+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OlzF5Xba; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.29; Thu, 19 Dec 2019 08:31:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=OlzF5Xba; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726877AbfLSQb2 (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:28 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40092 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726945AbfLSQb1 (ORCPT ); Thu, 19 Dec 2019 11:31:27 -0500 Received: by mail-wr1-f65.google.com with SMTP id c14so6611654wrn.7 for ; Thu, 19 Dec 2019 08:31:26 -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=Y2ql+LZRHzKAFXmCII7idFGR9pobHaST91PSU352afA=; b=OlzF5XbaVii57zrhytb/hwfGmYY4T7zMd5P2PTa89/4Vy01jLCbHqt7K0XyMZgnegn JbGdWFoGavtJMLBnbSNDbH0SIeT8uLqLacuLaI4B9rXcVV/gOHlQjkjK0vUQZcIKDL5F s+JrJ0Fnt/RpzGXCy8Y+mDgeLc3MR2slZvuKXYYLOtpqgO1HD+FxzZIHOguitSlBdnH1 KjqDahZXqO/cGkh7XElSuIP6Mb9ED2Tq2UIo7t0t8YUfIIV2o58EVF0sWTMkz/tvE7Uj c24OEPkN+xpsuKzgpKA+f0Sb+IZaGA+K5wdsa9fFDgHk4+ZU8M0Z7/czyhJ/SpvTD+BW qWJQ== 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=Y2ql+LZRHzKAFXmCII7idFGR9pobHaST91PSU352afA=; b=pv0vwOOVYKzfROwdRfKlexnbsUECeqkgXNJ519IcS5o4rkdTC5Fseh18JQEM9O4Vhg ZQ+H9JeeycXO/H2YMi3NjneNRUz3pM3Wj+/Yv4AizKTGDeuCzY6H1A3gslZsRZd3SmDD J69g2RzVL/obT5iCqKTli31Qb/er3Fwmeq+tTqTcmbNpf8KG6z5hgRVmm/ij0XB2KcqN lXr9hxNzH8LINtfVFZSGmXOFJR7gtC1icRvggADo/7olmUunS3+acgRvhkbyLuGVA0Ia KGliexSSC0+TRWVbElI+7KQ/I1ppV8Lt4MVfDqLjwxh78aJz5U4T2e0bCO+/By1bFPkd 9yHg== X-Gm-Message-State: APjAAAVgxkAZ1vzpaR5d7kLGoCvCuny3wGjrqs8HU2DVcUkH123zZuAW t2Bd9dTl2EVZCecL5lHYdpPzuQ== X-Received: by 2002:a05:6000:367:: with SMTP id f7mr10132123wrf.174.1576773085466; Thu, 19 Dec 2019 08:31:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:25 -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 05/13] iommu/arm-smmu-v3: Prepare arm_smmu_s1_cfg for SSID support Date: Thu, 19 Dec 2019 17:30:25 +0100 Message-Id: <20191219163033.2608177-6-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When adding SSID support to the SMMUv3 driver, we'll need to manipulate leaf pasid tables and context descriptors. Extract the context descriptor structure and introduce a new table structure. Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 837b4283b4dc..b287e303b1d7 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -553,16 +553,21 @@ struct arm_smmu_strtab_l1_desc { dma_addr_t l2ptr_dma; }; +struct arm_smmu_ctx_desc { + u16 asid; + u64 ttbr; + u64 tcr; + u64 mair; +}; + +struct arm_smmu_cd_table { + __le64 *ptr; + dma_addr_t ptr_dma; +}; + struct arm_smmu_s1_cfg { - __le64 *cdptr; - dma_addr_t cdptr_dma; - - struct arm_smmu_ctx_desc { - u16 asid; - u64 ttbr; - u64 tcr; - u64 mair; - } cd; + struct arm_smmu_cd_table table; + struct arm_smmu_ctx_desc cd; }; struct arm_smmu_s2_cfg { @@ -1471,6 +1476,7 @@ static void arm_smmu_write_ctx_desc(struct arm_smmu_device *smmu, struct arm_smmu_s1_cfg *cfg) { u64 val; + __le64 *cdptr = cfg->table.ptr; /* * We don't need to issue any invalidation here, as we'll invalidate @@ -1488,12 +1494,12 @@ static void arm_smmu_write_ctx_desc(struct arm_smmu_device *smmu, if (smmu->features & ARM_SMMU_FEAT_STALL_FORCE) val |= CTXDESC_CD_0_S; - cfg->cdptr[0] = cpu_to_le64(val); + cdptr[0] = cpu_to_le64(val); val = cfg->cd.ttbr & CTXDESC_CD_1_TTB0_MASK; - cfg->cdptr[1] = cpu_to_le64(val); + cdptr[1] = cpu_to_le64(val); - cfg->cdptr[3] = cpu_to_le64(cfg->cd.mair); + cdptr[3] = cpu_to_le64(cfg->cd.mair); } /* Stream table manipulation functions */ @@ -1624,7 +1630,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, !(smmu->features & ARM_SMMU_FEAT_STALL_FORCE)) dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); - val |= (s1_cfg->cdptr_dma & STRTAB_STE_0_S1CTXPTR_MASK) | + val |= (s1_cfg->table.ptr_dma & STRTAB_STE_0_S1CTXPTR_MASK) | FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS); } @@ -2138,11 +2144,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; - if (cfg->cdptr) { + if (cfg->table.ptr) { dmam_free_coherent(smmu_domain->smmu->dev, CTXDESC_CD_DWORDS << 3, - cfg->cdptr, - cfg->cdptr_dma); + cfg->table.ptr, + cfg->table.ptr_dma); arm_smmu_bitmap_free(smmu->asid_map, cfg->cd.asid); } @@ -2167,9 +2173,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, if (asid < 0) return asid; - cfg->cdptr = dmam_alloc_coherent(smmu->dev, CTXDESC_CD_DWORDS << 3, - &cfg->cdptr_dma, GFP_KERNEL); - if (!cfg->cdptr) { + cfg->table.ptr = dmam_alloc_coherent(smmu->dev, CTXDESC_CD_DWORDS << 3, + &cfg->table.ptr_dma, GFP_KERNEL); + if (!cfg->table.ptr) { dev_warn(smmu->dev, "failed to allocate context descriptor\n"); ret = -ENOMEM; goto out_free_asid; From patchwork Thu Dec 19 16:30:26 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: 182137 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702391iln; Thu, 19 Dec 2019 08:31:31 -0800 (PST) X-Google-Smtp-Source: APXvYqzUAwDsgbp8S5XqQNWTbkObTOD7EZAIoYPKcOXC/oiy6t2nKoRUYzNYeH/sQm2HpwGEKwrI X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr9244907oti.276.1576773091909; Thu, 19 Dec 2019 08:31:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773091; cv=none; d=google.com; s=arc-20160816; b=PIUZh/ScKEWRdvHWIrjAznXM5d2p1mTXsr5KVW7asQL57DIUHjRbsERZJbSJv4UWZv t3vJUo1cZYm46O/bA6zyr42ch+z2E8Qetm9gL1rDnDfcB4fbL8itTbYElI4YQc0LupUd y2gLAN6AT1tORoIA2OBTKlyACCPmx7KQsIeMWntaBzd4vH+EasyVAEADam+cDpcKZHBt 7ivSnjO9gUA8MK3K0Y9m01BvlZr37G+xr1GjvhSr8M3MykF7kkRBNTY7P3UCVYO15vnt GuibRdb8bclqY0sl3RJs++aGcw9KrVUswOrrAUeM4LnDXcyVwBv0T+/PYDMXc46E1sC6 60VA== 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=dMO+Cx5tpHWBU9PvT9K3Ldxua2I75lUQvV4E3iN+Pd4=; b=RMtMHuv+mAmKOZMsD5tV6AkLM9Y1Cz9yh21T75gMQwp/Yn7F+tJqIlbSmYbEBL6ljn XZntG5pX+6slFN3PG/KSpt2WAiII3KmOtt+vt6opXW3cMMD0nsOl8T1qOqX87tlA1yHF sYTML+Lt/o+zlBttHtWvm0StTgJnyoAKHoXMHT4keN+eidIbgYEe6QKI4Qy5DEZODZ+6 SwFnlA6biDFmy10ZUnZhNrJXLIUQkIjNVOe+XDVsL2p0rpvURFQ7lfbbMJ2z3EvhuWCl UzOZI81FIRQQMxFCi+bPAFqIAQTRFe4/Nnx0k5nuWklTUFbspkoElzoCE+HG0sqEaVhE t8pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="L6Y6F/bZ"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.31; Thu, 19 Dec 2019 08:31:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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="L6Y6F/bZ"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726976AbfLSQbb (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:31 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36217 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfLSQb2 (ORCPT ); Thu, 19 Dec 2019 11:31:28 -0500 Received: by mail-wr1-f68.google.com with SMTP id z3so6637743wru.3 for ; Thu, 19 Dec 2019 08:31:27 -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=dMO+Cx5tpHWBU9PvT9K3Ldxua2I75lUQvV4E3iN+Pd4=; b=L6Y6F/bZ0X6GnA6kcBZgaXAVjxtjAyEeEzKHLOb7dyE7Xra2EWhN3E2FV1pD/3jeqF Yl8MP7t7E6fc/B1SRXICTfrmmBAqXUHJRLw5pJcf29pPUWZ1hZGmH2wiA4Q4PGQA5yp0 drBOPo+Htx1MMDuIrvO0MavmC3p3Oar5PL9ngjx84tC3hJqd1xQdZ22JINufiVYFahyt GQ4Ctzcx0fW8SfJ45uPErgBMYQESIqhJ9DHjaOzF4X5fsvpQM9FzqurIZlWcCEO3++B3 Y7uc8Bvn0GLBhxmFJ814rKwcuODaQ3avmBF9ttywapAxu57HzjwpSg6Vq2j/vEVr+wcg pXvw== 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=dMO+Cx5tpHWBU9PvT9K3Ldxua2I75lUQvV4E3iN+Pd4=; b=CzNkJeQ14pj+f5DdYkO7me9sSZqyICfAgh3kF4DF8v5s94Q2DpfATeBRdE16UGNepl FMiJOYOcRv3MLFpcawhjIrdCyxbJpR9J7Jaea4301ucnbS9WiIV1Rm1mdwA6BQmb6HO1 ib6CnpNWeXhVJIgY97CHItRitWCRAL7cPziv6ibmp2yZKn6lW/FZA7erGQS+cuwMCi1N P5KzKesC5YYUtZ8uOKL6czobBD0a27tK6yFdTz1grccAdA3xuOnCZLeJUVfQnpNJvuE0 ZhgZQ/eN8y3DOrlPjincLh0TRWOClFfc+Sd1bXAAlLVEoX2NTkIfoPFQgo/2cpmIqAhN jPhQ== X-Gm-Message-State: APjAAAWeqScWatuzM9PTFC+FWopDLSqoXx1sFaaDU48PYA9UftJ66nTv 9szwwf0LBivQC9bOqbSrZT+1kA== X-Received: by 2002:adf:ce87:: with SMTP id r7mr10031904wrn.245.1576773086823; Thu, 19 Dec 2019 08:31:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:26 -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 06/13] iommu/arm-smmu-v3: Add context descriptor tables allocators Date: Thu, 19 Dec 2019 17:30:26 +0100 Message-Id: <20191219163033.2608177-7-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Support for SSID will require allocating context descriptor tables. Move the context descriptor allocation to separate functions. Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 11 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index b287e303b1d7..43d6a7ded6e4 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -568,6 +568,7 @@ struct arm_smmu_cd_table { struct arm_smmu_s1_cfg { struct arm_smmu_cd_table table; struct arm_smmu_ctx_desc cd; + u8 s1cdmax; }; struct arm_smmu_s2_cfg { @@ -1455,6 +1456,31 @@ static int arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu) } /* Context descriptor manipulation functions */ +static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, + struct arm_smmu_cd_table *table, + size_t num_entries) +{ + size_t size = num_entries * (CTXDESC_CD_DWORDS << 3); + + table->ptr = dmam_alloc_coherent(smmu->dev, size, &table->ptr_dma, + GFP_KERNEL); + if (!table->ptr) { + dev_warn(smmu->dev, + "failed to allocate context descriptor table\n"); + return -ENOMEM; + } + return 0; +} + +static void arm_smmu_free_cd_leaf_table(struct arm_smmu_device *smmu, + struct arm_smmu_cd_table *table, + size_t num_entries) +{ + size_t size = num_entries * (CTXDESC_CD_DWORDS << 3); + + dmam_free_coherent(smmu->dev, size, table->ptr, table->ptr_dma); +} + static u64 arm_smmu_cpu_tcr_to_cd(u64 tcr) { u64 val = 0; @@ -1502,6 +1528,23 @@ static void arm_smmu_write_ctx_desc(struct arm_smmu_device *smmu, cdptr[3] = cpu_to_le64(cfg->cd.mair); } +static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain) +{ + struct arm_smmu_device *smmu = smmu_domain->smmu; + struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; + + return arm_smmu_alloc_cd_leaf_table(smmu, &cfg->table, + 1 << cfg->s1cdmax); +} + +static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain) +{ + struct arm_smmu_device *smmu = smmu_domain->smmu; + struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; + + arm_smmu_free_cd_leaf_table(smmu, &cfg->table, 1 << cfg->s1cdmax); +} + /* Stream table manipulation functions */ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) @@ -2145,11 +2188,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; if (cfg->table.ptr) { - dmam_free_coherent(smmu_domain->smmu->dev, - CTXDESC_CD_DWORDS << 3, - cfg->table.ptr, - cfg->table.ptr_dma); - + arm_smmu_free_cd_tables(smmu_domain); arm_smmu_bitmap_free(smmu->asid_map, cfg->cd.asid); } } else { @@ -2173,13 +2212,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, if (asid < 0) return asid; - cfg->table.ptr = dmam_alloc_coherent(smmu->dev, CTXDESC_CD_DWORDS << 3, - &cfg->table.ptr_dma, GFP_KERNEL); - if (!cfg->table.ptr) { - dev_warn(smmu->dev, "failed to allocate context descriptor\n"); - ret = -ENOMEM; + ret = arm_smmu_alloc_cd_tables(smmu_domain); + if (ret) goto out_free_asid; - } cfg->cd.asid = (u16)asid; cfg->cd.ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[0]; From patchwork Thu Dec 19 16:30:27 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: 182138 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702435iln; Thu, 19 Dec 2019 08:31:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzlgfVY+76S1EdfHzLgsmfqFCloCl0Hb9tTqAbCYEFOAujlUs7LHIwVOZcMLJgUGHwEKRRl X-Received: by 2002:aca:ac0c:: with SMTP id v12mr772760oie.123.1576773093416; Thu, 19 Dec 2019 08:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773093; cv=none; d=google.com; s=arc-20160816; b=BJeIA8xQcF8DNDRiUvk+67fScX3OSVdt5AtuWtvm4Arl+0S3IEEWRPaJziN741Ee50 rI6XKEzbfq/c1IjlHnvW7neVZsTbzY3zxsLfN3/8vwqJvIel1L3rtM8zSACQvCPm1FgP B5OsjYI1tDZKOM4Yk3YmSjXz2xsVB0Od8CcB57DIYb60Cu8TNPiT75BBrnX+7653TZn6 EsLefHJusmKB3gXgQhB0SJr2nf1w4aeiYYLBcRktnslKssuFnuJB5yBzIz/KhVRM2fVA sllRee3xGQAXyiOz+PWQWCkMfiI0aqIFNXhE1EwIK9KmL1jh+6Y8j6UJfsNjjCXGMunt XNCA== 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=cMiD9xXHdCOYK/OOYrbVJk2Cu2WyO2IEe8IasRD6J+o=; b=FeHCW9QXzVsSAuu1cPkZKFO6YOTBLDoEtt8Le0sY0ElcM5O2M7ow4BRO78hFrKfUde JFaNd5o+yUt42nJIClMx8NJ7KOEhYSGpJUQRCHN4fYJ5wyjqE/6lCEV4KYBFPbUGF+Rm 3IDgcRWkGnM02578pLqR2G/CtoTg2DNvfMawww8FKNzmKY4oY7YES3nO/VA4qPSPkmHa 0XwbQ4Fi9AakCeKE4pzvjMg4J1O+GoWQztjUvp/kje5n1pM0CnuRHBFlzEJQ2Mc426C/ hLXHrWmcGbQJqwJM8wkHS4d3CPH/CA6LUZ+D5M0F3Q9N7iLYXJtrHYOGX5pYScZ1IFF+ Sq6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="FPvMouB/"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.33; Thu, 19 Dec 2019 08:31:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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="FPvMouB/"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726890AbfLSQbc (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:32 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33550 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbfLSQbc (ORCPT ); Thu, 19 Dec 2019 11:31:32 -0500 Received: by mail-wm1-f66.google.com with SMTP id d139so7437546wmd.0 for ; Thu, 19 Dec 2019 08:31:29 -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=cMiD9xXHdCOYK/OOYrbVJk2Cu2WyO2IEe8IasRD6J+o=; b=FPvMouB/TrdUiuIAV7DSjFF+ArgJA3nMc+sPptqaksrCtPKvhekrfhySNLDRrwXdeK x3nKhxCQy1SwZnv7ZwxwqaDWSh/HQ7xNm1sA6bTUktrxE39E/ZlC+GlAJugeJXFULrHi 6qQ6wk18yd1iwjHq0wlmGL3zSYAWo8fd1AGIz6R88CxCCVUNltH/hZGvsHPyYWcyzUFH rSupMLC0O+c7f1E/R+G9/BLXjQlABsbgmoiSiveqwrDumrpci4PdF3MN29LWdw3h7ZUj 70W7C2XLh5j4O7QzpTKQyWVBIIICXFYVIFav+/tPl8Q69UeodBBp1mvOLsXE+MpuYpAC ZPeA== 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=cMiD9xXHdCOYK/OOYrbVJk2Cu2WyO2IEe8IasRD6J+o=; b=J8llXoUjvKbbEsAm3tVTEPADiuO2HsSRWa95N5xtV0bZ5uFVvp141ty12ZaOmDrFij M8EhLUzWvyRN+mYy/n+wpJSoJ7EJyAhO/sDAHds7D1AEtrt7K9UBXLnjrIGi2ywnKsKw UrN7TFoXHpMVU2CJOCl4tio6NkVM/0oHqz1tVt1H51DFHA9LU4AORoqen+72QOvuiZ/y YoHUljUEuOTAei+gWXio6aV04OB5vWE6IoDeCHoV0uu1yDJNahfTcd8XGN68R5Ce75Rt ZgRNYpRTULdt4JtINndEibzQUk56OcknGN2j558uull3go1tRfKlDgVty149VmltvAuL LUzQ== X-Gm-Message-State: APjAAAWWNEFDVO7sK26k28p1nArlmX1NngTG3/JegZuk9BuV0CsTYbMF DceagTY9kzx2+iGS5Boo5Xkeqg== X-Received: by 2002:a7b:cf18:: with SMTP id l24mr10470564wmg.95.1576773088302; Thu, 19 Dec 2019 08:31:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:27 -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 07/13] iommu/arm-smmu-v3: Add support for Substream IDs Date: Thu, 19 Dec 2019 17:30:27 +0100 Message-Id: <20191219163033.2608177-8-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org At the moment, the SMMUv3 driver implements only one stage-1 or stage-2 page directory per device. However SMMUv3 allows more than one address space for some devices, by providing multiple stage-1 page directories. In addition to the Stream ID (SID), that identifies a device, we can now have Substream IDs (SSID) identifying an address space. In PCIe, SID is called Requester ID (RID) and SSID is called Process Address-Space ID (PASID). A complete stage-1 walk goes through the context descriptor table: Stream tables Ctx. Desc. tables Page tables +--------+ ,------->+-------+ ,------->+-------+ : : | : : | : : +--------+ | +-------+ | +-------+ SID->| STE |---' SSID->| CD |---' IOVA->| PTE |--> IPA +--------+ +-------+ +-------+ : : : : : : +--------+ +-------+ +-------+ Rewrite arm_smmu_write_ctx_desc() to modify context descriptor table entries. To keep things simple we only implement one level of context descriptor tables here, but as with stream and page tables, an SSID can be split to index multiple levels of tables. Tested-by: Zhangfei Gao Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 125 +++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 23 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 43d6a7ded6e4..e1bec7e552b9 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -227,6 +227,11 @@ #define STRTAB_STE_0_S1CTXPTR_MASK GENMASK_ULL(51, 6) #define STRTAB_STE_0_S1CDMAX GENMASK_ULL(63, 59) +#define STRTAB_STE_1_S1DSS GENMASK_ULL(1, 0) +#define STRTAB_STE_1_S1DSS_TERMINATE 0x0 +#define STRTAB_STE_1_S1DSS_BYPASS 0x1 +#define STRTAB_STE_1_S1DSS_SSID0 0x2 + #define STRTAB_STE_1_S1C_CACHE_NC 0UL #define STRTAB_STE_1_S1C_CACHE_WBRA 1UL #define STRTAB_STE_1_S1C_CACHE_WT 2UL @@ -329,6 +334,7 @@ #define CMDQ_PREFETCH_1_SIZE GENMASK_ULL(4, 0) #define CMDQ_PREFETCH_1_ADDR_MASK GENMASK_ULL(63, 12) +#define CMDQ_CFGI_0_SSID GENMASK_ULL(31, 12) #define CMDQ_CFGI_0_SID GENMASK_ULL(63, 32) #define CMDQ_CFGI_1_LEAF (1UL << 0) #define CMDQ_CFGI_1_RANGE GENMASK_ULL(4, 0) @@ -446,8 +452,11 @@ struct arm_smmu_cmdq_ent { #define CMDQ_OP_CFGI_STE 0x3 #define CMDQ_OP_CFGI_ALL 0x4 + #define CMDQ_OP_CFGI_CD 0x5 + #define CMDQ_OP_CFGI_CD_ALL 0x6 struct { u32 sid; + u32 ssid; union { bool leaf; u8 span; @@ -568,6 +577,7 @@ struct arm_smmu_cd_table { struct arm_smmu_s1_cfg { struct arm_smmu_cd_table table; struct arm_smmu_ctx_desc cd; + u8 s1fmt; u8 s1cdmax; }; @@ -860,10 +870,16 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) cmd[1] |= FIELD_PREP(CMDQ_PREFETCH_1_SIZE, ent->prefetch.size); cmd[1] |= ent->prefetch.addr & CMDQ_PREFETCH_1_ADDR_MASK; break; + case CMDQ_OP_CFGI_CD: + cmd[0] |= FIELD_PREP(CMDQ_CFGI_0_SSID, ent->cfgi.ssid); + /* Fallthrough */ case CMDQ_OP_CFGI_STE: cmd[0] |= FIELD_PREP(CMDQ_CFGI_0_SID, ent->cfgi.sid); cmd[1] |= FIELD_PREP(CMDQ_CFGI_1_LEAF, ent->cfgi.leaf); break; + case CMDQ_OP_CFGI_CD_ALL: + cmd[0] |= FIELD_PREP(CMDQ_CFGI_0_SID, ent->cfgi.sid); + break; case CMDQ_OP_CFGI_ALL: /* Cover the entire SID range */ cmd[1] |= FIELD_PREP(CMDQ_CFGI_1_RANGE, 31); @@ -1456,6 +1472,33 @@ static int arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu) } /* Context descriptor manipulation functions */ +static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain, + int ssid, bool leaf) +{ + size_t i; + unsigned long flags; + struct arm_smmu_master *master; + struct arm_smmu_device *smmu = smmu_domain->smmu; + struct arm_smmu_cmdq_ent cmd = { + .opcode = CMDQ_OP_CFGI_CD, + .cfgi = { + .ssid = ssid, + .leaf = leaf, + }, + }; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master, &smmu_domain->devices, domain_head) { + for (i = 0; i < master->num_sids; i++) { + cmd.cfgi.sid = master->sids[i]; + arm_smmu_cmdq_issue_cmd(smmu, &cmd); + } + } + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + + arm_smmu_cmdq_issue_sync(smmu); +} + static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, struct arm_smmu_cd_table *table, size_t num_entries) @@ -1498,34 +1541,65 @@ static u64 arm_smmu_cpu_tcr_to_cd(u64 tcr) return val; } -static void arm_smmu_write_ctx_desc(struct arm_smmu_device *smmu, - struct arm_smmu_s1_cfg *cfg) +static int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, + int ssid, struct arm_smmu_ctx_desc *cd) { - u64 val; - __le64 *cdptr = cfg->table.ptr; - /* - * We don't need to issue any invalidation here, as we'll invalidate - * the STE when installing the new entry anyway. + * This function handles the following cases: + * + * (1) Install primary CD, for normal DMA traffic (SSID = 0). + * (2) Install a secondary CD, for SID+SSID traffic. + * (3) Update ASID of a CD. Atomically write the first 64 bits of the + * CD, then invalidate the old entry and mappings. + * (4) Remove a secondary CD. */ - val = arm_smmu_cpu_tcr_to_cd(cfg->cd.tcr) | -#ifdef __BIG_ENDIAN - CTXDESC_CD_0_ENDI | -#endif - CTXDESC_CD_0_R | CTXDESC_CD_0_A | CTXDESC_CD_0_ASET | - CTXDESC_CD_0_AA64 | FIELD_PREP(CTXDESC_CD_0_ASID, cfg->cd.asid) | - CTXDESC_CD_0_V; + u64 val; + bool cd_live; + struct arm_smmu_device *smmu = smmu_domain->smmu; + __le64 *cdptr = smmu_domain->s1_cfg.table.ptr + ssid * + CTXDESC_CD_DWORDS; - /* STALL_MODEL==0b10 && CD.S==0 is ILLEGAL */ - if (smmu->features & ARM_SMMU_FEAT_STALL_FORCE) - val |= CTXDESC_CD_0_S; + val = le64_to_cpu(cdptr[0]); + cd_live = !!(val & CTXDESC_CD_0_V); - cdptr[0] = cpu_to_le64(val); + if (!cd) { /* (4) */ + val = 0; + } else if (cd_live) { /* (3) */ + val &= ~CTXDESC_CD_0_ASID; + val |= FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid); + /* + * Until CD+TLB invalidation, both ASIDs may be used for tagging + * this substream's traffic + */ + } else { /* (1) and (2) */ + cdptr[1] = cpu_to_le64(cd->ttbr & CTXDESC_CD_1_TTB0_MASK); + cdptr[2] = 0; + cdptr[3] = cpu_to_le64(cd->mair); + + /* + * STE is live, and the SMMU might read dwords of this CD in any + * order. Ensure that it observes valid values before reading + * V=1. + */ + arm_smmu_sync_cd(smmu_domain, ssid, true); - val = cfg->cd.ttbr & CTXDESC_CD_1_TTB0_MASK; - cdptr[1] = cpu_to_le64(val); + val = arm_smmu_cpu_tcr_to_cd(cd->tcr) | +#ifdef __BIG_ENDIAN + CTXDESC_CD_0_ENDI | +#endif + CTXDESC_CD_0_R | CTXDESC_CD_0_A | CTXDESC_CD_0_ASET | + CTXDESC_CD_0_AA64 | + FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) | + CTXDESC_CD_0_V; - cdptr[3] = cpu_to_le64(cfg->cd.mair); + /* STALL_MODEL==0b10 && CD.S==0 is ILLEGAL */ + if (smmu->features & ARM_SMMU_FEAT_STALL_FORCE) + val |= CTXDESC_CD_0_S; + } + + WRITE_ONCE(cdptr[0], cpu_to_le64(val)); + arm_smmu_sync_cd(smmu_domain, ssid, true); + return 0; } static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain) @@ -1533,6 +1607,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain) struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg; + cfg->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; return arm_smmu_alloc_cd_leaf_table(smmu, &cfg->table, 1 << cfg->s1cdmax); } @@ -1664,6 +1739,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, if (s1_cfg) { BUG_ON(ste_live); dst[1] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | @@ -1674,7 +1750,9 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); val |= (s1_cfg->table.ptr_dma & STRTAB_STE_0_S1CTXPTR_MASK) | - FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS); + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | + FIELD_PREP(STRTAB_STE_0_S1CDMAX, s1_cfg->s1cdmax) | + FIELD_PREP(STRTAB_STE_0_S1FMT, s1_cfg->s1fmt); } if (s2_cfg) { @@ -2479,7 +2557,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->ats_enabled = arm_smmu_ats_supported(master); if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) - arm_smmu_write_ctx_desc(smmu, &smmu_domain->s1_cfg); + arm_smmu_write_ctx_desc(smmu_domain, 0, + &smmu_domain->s1_cfg.cd); arm_smmu_install_ste_for_dev(master); From patchwork Thu Dec 19 16:30:31 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: 182142 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702545iln; Thu, 19 Dec 2019 08:31:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyN3IzYTdZzbeTQx8WdZoss/GcX3POR7DyRD/vxdJZtKp/wFP0ZB+D9nWsEcqR3YmogDslI X-Received: by 2002:a9d:708f:: with SMTP id l15mr10021868otj.286.1576773098416; Thu, 19 Dec 2019 08:31:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773098; cv=none; d=google.com; s=arc-20160816; b=SwmvfjHv+713NEHybaGLXDjjC7Y15mDqKZTDUP4yKMn3wQ/mPHnESROpCcGUhN86Ad TTEvIzpNxa4RdK2Jl9G4eOwzjGllg62l7mwqkktfEHaLvih7/IrjCrTXmXgM9rHQmGfL 9M6+x8Et2ARTzF/GmEHJyfjNs1chM2qV4S30rRlM0VCYKqv8j89TEvXI+sG/lbRmK7RY MQuAzj61kbM3gf0LX9NkmlOECNq9amsoojz2EfZVvGFpXgeGn2M6NdtlhZadnbvF+H8k oIIt/YPJgaVEnuELYRT2BF4BF/mkBB98qcGSuf9+hAOApVi4e0APGfKsTrwbKIilYHCN uiTg== 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=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=S1BXwV0DfDqu8UA3UXh+Ln0RvVLC1hxIwKf1kYhWbj9YB2cukVUqnt26VpeT0mXao3 NtWR0Za4lcInuLigzg/0DQs5fi/ivbuZVOBgtFst253BhHwe+G8nxUjqdKW99OLDBbDb h5phHSygR0xuaMSMMzE4bEkgp3m8ZGJwH9s9VIEksZeUkT36AXzJkYepB4Z5fDycRZnA CKJnaFrMFQoLM1IDV0yGoH5bmTsmaXWYJors/vddqu8gNkWqElgpswo7RcQ6DPxIAGnl +yXWwOwJYKeu3wTuSOxQ+lOhViadBb4tU3RdKKxZu1QZl7OIcNmMHZiPupodc8tricuP fr5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgEdguI1; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.38; Thu, 19 Dec 2019 08:31:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=dgEdguI1; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1727014AbfLSQbh (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:37 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56074 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbfLSQbg (ORCPT ); Thu, 19 Dec 2019 11:31:36 -0500 Received: by mail-wm1-f66.google.com with SMTP id q9so6084225wmj.5 for ; Thu, 19 Dec 2019 08:31:34 -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=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=dgEdguI1vFCV7YNVUg0oEi5hoedAB5SCo0EHqrgrYN2fDZQP1jM0e2gVFmXjAsarm9 sE3jEiVBfo9bIxoraETghmWio/hExZaK0G2MlaAUWWPlH/s/lgj8y2aPluLIJwIiWDO5 nPCsL9EFTnWUXXPdeHMf2mqD8ncvbLtOVcjLDDmK20sqR/zY19gWGF0iPqJMOqrpBHzU P5l5nDoT+24rRDoL/bDgoMasOpqDS3TpLXI4nHsZ6shxvb0a59G2E8TD5mPZoPT7AZm0 TE/nR/n+4AfO7nup111L94qgV7A8exhXah9vnGXYO9tpJuoHYa73upM3pfuz8aU4XUjD EyRw== 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=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=UDNHGS9vvPHVsTC7fNX7dOLJ/eM0R3LTm1bRBiXLefibm00IKcSdQZZ4RM8IlaTrKx Zx3Ykl1n6hmJJ9kw9VrU6hJ+2AWjJ0QIuG/XS9O/phdhIDOon5KKWLCZ9bE403ZKnMP5 /dhMaSvX1vR5zoZQEd/QQ88ZCTMa06DqGgN35b3pXRf+fE+UAHpCZbMWYJfewdNe9L55 frx/kc+P7pXPHKu+Yyi9QjcGM/+J+KPVNorvSBvjylZ5VpWjEI3i9vGxLAhQGK9xc1Sg MHnpG6rFilhrX9DkxryoQXbMtsuHSuARrj3U1BO5JLi496Wm4aDST2FG3leC1QjZsqEi OGHQ== X-Gm-Message-State: APjAAAVpkbM7NzpDb6rB48KyPFixxzrw+StzvecqCiPJRUkzsWOK6DeF QWRvVDEYYey3ttWhWCf1dmaXRA== X-Received: by 2002:a1c:7d93:: with SMTP id y141mr11448751wmc.111.1576773093503; Thu, 19 Dec 2019 08:31:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:33 -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 11/13] iommu/arm-smmu-v3: Improve add_device() error handling Date: Thu, 19 Dec 2019 17:30:31 +0100 Message-Id: <20191219163033.2608177-12-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Let add_device() clean up after itself. The iommu_bus_init() function does call remove_device() on error, but other sites (e.g. of_iommu) do not. Don't free level-2 stream tables because we'd have to track if we allocated each of them or if they are used by other endpoints. It's not worth the hassle since they are managed resources. Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index bf106a7b53eb..e62ca80f2f76 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2837,14 +2837,16 @@ static int arm_smmu_add_device(struct device *dev) for (i = 0; i < master->num_sids; i++) { u32 sid = master->sids[i]; - if (!arm_smmu_sid_in_range(smmu, sid)) - return -ERANGE; + if (!arm_smmu_sid_in_range(smmu, sid)) { + ret = -ERANGE; + goto err_free_master; + } /* Ensure l2 strtab is initialised */ if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { ret = arm_smmu_init_l2_strtab(smmu, sid); if (ret) - return ret; + goto err_free_master; } } @@ -2854,13 +2856,25 @@ static int arm_smmu_add_device(struct device *dev) master->ssid_bits = min_t(u8, master->ssid_bits, CTXDESC_LINEAR_CDMAX); + ret = iommu_device_link(&smmu->iommu, dev); + if (ret) + goto err_free_master; + group = iommu_group_get_for_dev(dev); - if (!IS_ERR(group)) { - iommu_group_put(group); - iommu_device_link(&smmu->iommu, dev); + if (IS_ERR(group)) { + ret = PTR_ERR(group); + goto err_unlink; } - return PTR_ERR_OR_ZERO(group); + iommu_group_put(group); + return 0; + +err_unlink: + iommu_device_unlink(&smmu->iommu, dev); +err_free_master: + kfree(master); + fwspec->iommu_priv = NULL; + return ret; } static void arm_smmu_remove_device(struct device *dev) From patchwork Thu Dec 19 16:30:32 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: 182143 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702596iln; Thu, 19 Dec 2019 08:31:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxgs96MCvf8jF54xj/5gSB36vZn6n9wRFUTzCZf4OLt8TK9JIeFH60cZQdV2mykhKxqkWMM X-Received: by 2002:a9d:590b:: with SMTP id t11mr9794255oth.161.1576773100513; Thu, 19 Dec 2019 08:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773100; cv=none; d=google.com; s=arc-20160816; b=YWipPijyhthn0nTMxVUPSEOZyP88hwAnrgDA/3Ml7457hTbJJyYWzX6kF3GygTixAg cER3nfMWbydz5iSupPGz/154ES/mhrCVnz7yvYbA4szqKpF9HGq9maiEmtoc8/AB3Ob3 r4/Bj7Bhubk6pXgmurTLY5QgO9jnsnAYRsgcbd+oyB5pWmiGZ5XwX8Db9Oq/QVo6ftq3 ZKFQLVumjTDg5BbbWVIc08kTr0qcKoqI4DvGY18JrhmoIA9zQCcKh7mObZmwj7ReWacQ U2MGBAYeoEL4jNhhTIgOCcoa3e+1JiGIUs7g7dGbEVb6A8YnTU3fHDliLiMqe+KgnzUX aLTA== 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=k0PTgEa8Z2EtxKNp+bXlU3gMIeIQMMd4dvAJJmx7ucE=; b=LeatkeqQGWTg1fbP9+9qBVvQlQ7bjp7xveDoTMjOK+XL3BkY+9matMG9phFBR0fIeT tZZvjCoI4+L19E6iWeZTLXC/SJjWxhcazOA0iAR4n5ezseXWta7BhMBxfNAlzXlpb/D9 bZdOqvb+joFv+vXFitT7LUkz5pntjlaUUcAz6MRp0du13BJ7tcdQ9FIhVJvp3RgdHefs jwEuQqaMqoF0WLAZBa6XIav4rR7YbZn8rELK/GvVP7eneG7O7TtklWxQiUSNEF0i8YRB kCpu+quRchTBeDiApH38VKdcHE/F8fcgMCDYhOocZEhGJQsvCLqXkmSHohcXkENUpQZl 2VsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+Iytwj4; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.40; Thu, 19 Dec 2019 08:31:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=W+Iytwj4; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726984AbfLSQbj (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:39 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38536 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfLSQbh (ORCPT ); Thu, 19 Dec 2019 11:31:37 -0500 Received: by mail-wr1-f65.google.com with SMTP id y17so6640327wrh.5 for ; Thu, 19 Dec 2019 08:31:35 -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=k0PTgEa8Z2EtxKNp+bXlU3gMIeIQMMd4dvAJJmx7ucE=; b=W+Iytwj4wvUZ2mbwDVM7FzjhurcQ7XEm74cJFZdKNOpWZtf7wK2eBP0X8FsMZeSJ6x iR0hoMFIuiITseQd974oYuP4t6sCXPRf3CBmd6yCV89pn+xP+xk+w7DoS2RBpcJj2xkt 9hAy9ONlO9aTHj8k3D5PUqhPlRW8+9sBhjji/UXYjHTc2kU0B/rcTeoqySC1prww1Kh5 lDK2rbNnj95q+9W/YHUT8aL/yY4xujuGQ3Gqt7+IIi+uCEaUwCmo0aNTuAmGuF4PphBE eH7TqxdLwqXapRzKuHr8uFQZKVtKa1+hpBYpYNgTi8ckKxL0EE66EGNi9XNuHJ5DvbFx fRpA== 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=k0PTgEa8Z2EtxKNp+bXlU3gMIeIQMMd4dvAJJmx7ucE=; b=tk4pL7G1w+TW0Phj+UcLT9bP66AnjrN4w3Gg3N7c+rWnPAlJKfbDFW+ku30nas3Jnv lEvWFbl2VzQ/HGHdXYPeq5V4l3g77Ko6IcjbnvOde/dGuThk3u7o9VK0pbEOkDjSm03q R1VPBTj9gZObdMBWCVnQzy9U2XUUn1K6ifnXdXGM3/4CUEEwA/6g/xefZgL2iKnC5eHW Oz/YkGUjtb7G4aPeXBEtabxDMkezj4zDkfeIGpiAejhR2Hp361xQrFjNrHYi2651RgcG AMcTDPQu2HDdNxKnXE+lvmNEkL7fFsQ4pmrq3hGrpaIj9ALg7RggQZL0tri99AAlWSe/ SiOQ== X-Gm-Message-State: APjAAAUrcQWARlOf3LvVxZl96ysW65vYRv2OUkOTHlAPsdAjuTv9wSeE z3X/fEWi+kRJKgAsJHY/3+GLXQ== X-Received: by 2002:adf:fcc4:: with SMTP id f4mr10390218wrs.247.1576773095285; Thu, 19 Dec 2019 08:31:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:34 -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 12/13] PCI/ATS: Add PASID stubs Date: Thu, 19 Dec 2019 17:30:32 +0100 Message-Id: <20191219163033.2608177-13-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The SMMUv3 driver, which may be built without CONFIG_PCI, will soon gain PASID support. Partially revert commit c6e9aefbf9db ("PCI/ATS: Remove unused PRI and PASID stubs") to re-introduce the PASID stubs, and avoid adding more #ifdefs to the SMMU driver. Acked-by: Bjorn Helgaas Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- include/linux/pci-ats.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.24.1 diff --git a/include/linux/pci-ats.h b/include/linux/pci-ats.h index 5d62e78946a3..d08f0869f121 100644 --- a/include/linux/pci-ats.h +++ b/include/linux/pci-ats.h @@ -33,6 +33,9 @@ void pci_disable_pasid(struct pci_dev *pdev); int pci_pasid_features(struct pci_dev *pdev); int pci_max_pasids(struct pci_dev *pdev); #else /* CONFIG_PCI_PASID */ +static inline int pci_enable_pasid(struct pci_dev *pdev, int features) +{ return -EINVAL; } +static inline void pci_disable_pasid(struct pci_dev *pdev) { } static inline int pci_pasid_features(struct pci_dev *pdev) { return -EINVAL; } static inline int pci_max_pasids(struct pci_dev *pdev) From patchwork Thu Dec 19 16:30:33 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: 182144 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702613iln; Thu, 19 Dec 2019 08:31:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxxQ1ZMQ30a7uNKufrKJzWpLfwxrllU532w7qavCRxnP3VVVYk276zNteXJh/BRKWBxlGE1 X-Received: by 2002:aca:aa81:: with SMTP id t123mr2476380oie.92.1576773101506; Thu, 19 Dec 2019 08:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773101; cv=none; d=google.com; s=arc-20160816; b=sDfDk7etd6WSLVLW50Mop+n5j2epj0oZifQOh4nzwfIpYdEx1ZjJfS/U9SuYOMdw65 LlAficWltjuRY0npW71zKLrjQqjRGpY3NpKsoyMj6XtiruSHXAi9qymXf1e302tdqgKY mq7Zvo8f6o5cyUPo16cqX4Jc4c9iIJcWyGPZF1t/D6kwaW4Rn0oj75t2+/sJc496ssro KQ/TMMF1ZR2NvlwHXmQFJ1PGMool5Qr5XzJxGnSNWV1Pet3BVWAsVklYvPgNgMRrhPxO KEAIe2gKrWzNRHae2PGtm4hKc+gWkvn9Bg9J0VtQrDcRuXo0w0qdQgDsp1TNb2CxCS8F 9PtA== 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=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=ccxo9ljaCx0esXBzSbNnU6qkDUjtg0S1Pr2nHdaa5Fd7e48w7o7UwzjlBTKOaAKJ1Y fwa1DNL5grdAKgf4maKE3/aQLWqwaX6Wjiyo6DV4s8zjc04WrL9cijpWYIR/SRwbJRDM gt8ZS9NUb34z6G3NsPt9gLnfrIW6tKwr9STzAUmRADloeHL1eSHzErMK3zScg9Y+7ue3 KXiNQZHjSvAyZ7SWFX4oqbPvDBm1d9h5N9MdoypRW/cTcC/l98hEM5YhFHexZtFmmBMT o+OFDIskPUbJ5T2SVbCKwMrgCMzvDGANvwOD8tm/Dq1Iy3f/ohpJggOYvt3CDM/vCcbw xdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hH3b80Wj; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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.41; Thu, 19 Dec 2019 08:31:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=hH3b80Wj; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 S1726965AbfLSQbj (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:39 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42939 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbfLSQbi (ORCPT ); Thu, 19 Dec 2019 11:31:38 -0500 Received: by mail-wr1-f65.google.com with SMTP id q6so6597089wro.9 for ; Thu, 19 Dec 2019 08:31:37 -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=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=hH3b80WjL1UfLkeRj1KaYK2xXE9kCJqYv3IfxG/t0piRVkIEPEUriaWxmUbpRUG4Fq 1k4YH7bs2VDmawOY4Ebix453yuxAxC2sbnROIZRwLQvY7OvLOXgFy/TmXEfK8P7l47eN dX7k8lSRFzJO+MKenvWY8EegeAUWz+s7gbOrYX00KG2aT3ygF3N+B7D30eheZ3koHxzj uDhVQVW0qwmeuvx00tfSyjjW4lZx7I/dbMTo3eCCRLmzgO3m1oH86DGHt1HFdggdqAHd DzIYrIar+5lr7sDIBSRuf4W1WoYmC8U0q2tRT6n3rfDQY1FOLTQqyNkw6XyKGZTogK8O 81MQ== 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=DFKSWV5x7hWib4ywLyYZ2Xpzoe8h6HBPQg/y9idEIyA=; b=Evc04BnSex8fuQXLJnFYA7UbEfnNFp4A98eEFUAIpUEbMaNyjpuLjcWB0ToKjyKtUt WDPMbhE3g2C4kbbG+i0prSuPPk+9Gkvxji327j4lyTcVHQmnxDXNMuQ3uLg76y2e596X 5P9ITMy84m5zV9psXP7TSRamMz0g2lYvCPlERuVZJwaBcO+YC0r3w+l+63KKK9sR67BB U3z/PcgRVj2Fv5/yL6JzL42LgxTIWwmJTLVI5IBx5c5nOcXpETHfcw6mNFcr61hgLjYN 4ixkAVe2LHFOzm2wlhSAIcgmr/O7QarxBWXKAhDOo/92ctnvEqQm8PbYDxDmtX8hCqXv 4Z9Q== X-Gm-Message-State: APjAAAVnIJhgJcQYB2U8KqaXJR2GBOl6d9B/tzU/qruTpuRKO0eW1MTX bjf6RPtyqroXedCXk4D5v/2rZQ== X-Received: by 2002:a5d:640d:: with SMTP id z13mr10506261wru.181.1576773096482; Thu, 19 Dec 2019 08:31:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:36 -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 13/13] iommu/arm-smmu-v3: Add support for PCI PASID Date: Thu, 19 Dec 2019 17:30:33 +0100 Message-Id: <20191219163033.2608177-14-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: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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. Tested-by: Zhangfei Gao Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index e62ca80f2f76..8e95ecad4c9a 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2644,6 +2644,53 @@ static void arm_smmu_disable_ats(struct arm_smmu_master *master) atomic_dec(&smmu_domain->nr_ats_masters); } +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 -ENODEV; + + pdev = to_pci_dev(master->dev); + + features = pci_pasid_features(pdev); + if (features < 0) + return features; + + num_pasids = pci_max_pasids(pdev); + if (num_pasids <= 0) + return num_pasids; + + ret = pci_enable_pasid(pdev, features); + if (ret) { + dev_err(&pdev->dev, "Failed to enable PASID\n"); + return ret; + } + + master->ssid_bits = min_t(u8, ilog2(num_pasids), + master->smmu->ssid_bits); + return 0; +} + +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; + + master->ssid_bits = 0; + pci_disable_pasid(pdev); +} + static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; @@ -2852,13 +2899,16 @@ 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 (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB)) master->ssid_bits = min_t(u8, master->ssid_bits, CTXDESC_LINEAR_CDMAX); 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)) { @@ -2871,6 +2921,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; @@ -2891,6 +2943,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); }