From patchwork Thu Feb 13 10:14:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11380113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2190A1800 for ; Thu, 13 Feb 2020 10:14:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F264A24673 for ; Thu, 13 Feb 2020 10:14:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Q9LL3pOp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VOc/AgqC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F264A24673 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fFWN22XjHH67dSPGY45rH4BUcMNEQA1HWYvc1TJMclo=; b=Q9LL3pOptkw+W9 jmbnyoL2NkL1TodpyL3yGJEVYcrfQtBMQzDVdKUI/MYNQa1UlY/gsk8+B7FofTUwOVzri9AdgPdtH xJLUgNVEqKRGRYkc+YU1u2N3TgSL0K5hsxzi8q9Qirppn3uVm9kPqanOo0bbuPUiTQeyQVCz/d8+P fK0vTe6dt0+mOyh8Kiaj7ZORK2gQjsQuJCie1DMp1wByjvHjc2fqSlk6CG5fBv6sgOUK2SQ6uTG3u cyOmp0WArKa2gacYO3m2SvrnqycqPbXZ8Nk8FZxwrX6t7t1aumW+tPBJ9hQ2PH2lgnIBZm6LnMUam FNv3Mu8cmevlEqET4Q7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWD-0002zz-JG; Thu, 13 Feb 2020 10:14:49 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWA-0002ym-Jw for linux-arm-kernel@lists.infradead.org; Thu, 13 Feb 2020 10:14:47 +0000 Received: by mail-wr1-x444.google.com with SMTP id c9so5919689wrw.8 for ; Thu, 13 Feb 2020 02:14:46 -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=ffFCJH69MWS3gu5TdGiWJyiqlV+lu2ttPiLstT+myYY=; b=VOc/AgqCKj2uTb+3PxiP+vBussxkp9Xnkbwfwzzx43saT/PGOSRy1wb3R9u4IgsK4H QgtZXTOA8HRdd+QcPOE+4QaCBUzelwLymRIyf4YS4nbzZy999MRyw3Gmdb9+lqXo9o+x cSvl76aBS1KTII8O9Sjj1wtfsi3eqx84csvK9F4ALVE3r1MwmAJ7UnQYUyo+qXg44Ck7 Rzm3M0YkppAGyWJDQjiKghiJpi3EopMafcdcxQQf7qBr5Su45pBtfRQMKyfT/Y3eL+ox drtFFFENjIz5kvdy+A9naZ5w8nxw6A1hFcgvMhUgOOBUMShrobEgffwcpxdcOXCLIE+l rAtw== 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=ffFCJH69MWS3gu5TdGiWJyiqlV+lu2ttPiLstT+myYY=; b=srryhe7ZzmEXz7wkJRO5HtHwkrZJ8fqOfXEZeJHe7xg/2yM2yTuu7Z/qPr1XGpFz9F nqHxZQcQoS+fq02jnyyCjEa4g2827s8FOacF6KhvVztW/tNO71Mucvyo5y5Ax0wGju53 xT+O6XTkIvwBriwoTccntS/NsToeRgqaUzjDHzVEIvNHa9WLqAJG/4IDYNn4bQccAP2q rwtPZHWic+WGeQAGCZVfvR4PivG11eGSoiQKJtSnauoyvSuxEcu2HeNmH/aOeYzi18+O 9Y3MtuAyGQA7BuMyVn5+GvP2gSYSFUOJDxnqGUdxIWbU/jqftbLmmqdwOtAY6VPg7W9z 1gWw== X-Gm-Message-State: APjAAAXxVFge2uDZUtwzHGQHCaUzO2ytcjSD8XalzHwUY+vR7mVBvHfs 9RzXpmJthkjERSDTql0Vk8nW2w== X-Google-Smtp-Source: APXvYqyGI8je5B1PaESIUTiNN6WwNtME2/884yAwDWfvmieJ+C+jPQfGseYc8+Y0Ju3V7vGv/sHu1Q== X-Received: by 2002:adf:b193:: with SMTP id q19mr20678957wra.78.1581588885058; Thu, 13 Feb 2020 02:14:45 -0800 (PST) Received: from localhost.localdomain ([2001:171b:2276:930:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id y131sm2428059wmc.13.2020.02.13.02.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 02:14:44 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, will@kernel.org, bhelgaas@google.com Subject: [PATCH 1/4] PCI/ATS: Export symbols of PASID functions Date: Thu, 13 Feb 2020 11:14:32 +0100 Message-Id: <20200213101435.229932-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213101435.229932-1-jean-philippe@linaro.org> References: <20200213101435.229932-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200213_021446_652112_A2282209 X-CRM114-Status: UNSURE ( 9.14 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangfei.gao@linaro.org, joro@8bytes.org, robin.murphy@arm.com, jonathan.cameron@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The Arm SMMUv3 driver uses pci_{enable,disable}_pasid() and related functions. Export them to allow the driver to be built as a module. Signed-off-by: Jean-Philippe Brucker --- drivers/pci/ats.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index 3ef0bb281e7c..390e92f2d8d1 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -366,6 +366,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features) return 0; } +EXPORT_SYMBOL_GPL(pci_enable_pasid); /** * pci_disable_pasid - Disable the PASID capability @@ -390,6 +391,7 @@ void pci_disable_pasid(struct pci_dev *pdev) pdev->pasid_enabled = 0; } +EXPORT_SYMBOL_GPL(pci_disable_pasid); /** * pci_restore_pasid_state - Restore PASID capabilities @@ -441,6 +443,7 @@ int pci_pasid_features(struct pci_dev *pdev) return supported; } +EXPORT_SYMBOL_GPL(pci_pasid_features); #define PASID_NUMBER_SHIFT 8 #define PASID_NUMBER_MASK (0x1f << PASID_NUMBER_SHIFT) @@ -469,4 +472,5 @@ int pci_max_pasids(struct pci_dev *pdev) return (1 << supported); } +EXPORT_SYMBOL_GPL(pci_max_pasids); #endif /* CONFIG_PCI_PASID */ From patchwork Thu Feb 13 10:14:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11380119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28E7C109A for ; Thu, 13 Feb 2020 10:15:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3CF3217F4 for ; Thu, 13 Feb 2020 10:15:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BpHrQ+xP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LiIOnGXo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3CF3217F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZkCLzdeTVmklZps9hRjYqlHQnout3kE6IZ+RpkdsARc=; b=BpHrQ+xP9IVPj2 5t5iA88dkFsy88SrLNovU9EzJjOxSXSpnwj2mUhHYJeb3BTzr7K2xPcv+INmwXBfhXtxHRenP/mjA u3etBuqHlK+XOjl5u0/UJRBBjGQcgssQpen8uvH0kvPOV0X7Tyc3VnSe5WRnwAqR04j/c5rlvdp+d rF2YSMepT+8+K0faN32AmIU7Ka01Gpq+phVChlKLhYxySVcUg63/e9RP9b1qwj3acSPr4zChGEkyU 2DX7MR5S3I8aB6tOUh3CrKNiW/plVUkI9GwPCz4YJ1n8KYzDREILpd071ZFUZdAGtKb0nlBNiRMyE bEwBQwfy/WSwhU9FDZqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWZ-0003P7-2e; Thu, 13 Feb 2020 10:15:11 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWB-0002yx-29 for linux-arm-kernel@lists.infradead.org; Thu, 13 Feb 2020 10:14:49 +0000 Received: by mail-wr1-x442.google.com with SMTP id y17so5921664wrh.5 for ; Thu, 13 Feb 2020 02:14:46 -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=L9Q0qcxnkV13c6MhKRP3gkBpAW/Xjj6KTCyBYPPUbo8=; b=LiIOnGXo+1V5X4BBKECkUfbWR73U9DnrPU1pNO8cxMgeZIEroezVjURh8NbYtZC3Uq 7g/McoLvPT54IaXv77TmDcfIz9XkxAJW0y/z+aaNhUtd4yleQcmOkWDjKc+9fIE3IkBi RZXmj77XMU7r3GLU5vVtyisnlRaHZmAxriLxL2nbxuw8BT7TE1h96cCAssdBa6IEbqsW jOI1Mx55wwplBlekHQLSW1xsreMKFUSXkAPbX95yhKcIdBpMO1v3o67YP/vyON5z8zES B6UfwVZ4qNdFptn9nc3ekb8wOL0wtrcKHNjknbmM7g6ZNbKbrXjBehtJ9yCmd0ifVMIL BghQ== 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=L9Q0qcxnkV13c6MhKRP3gkBpAW/Xjj6KTCyBYPPUbo8=; b=g9sNowl2PCdr5RttJaLc6jM+HRAgoGRTMLE1hAheIhMgug+NvX5tRILsHmwoktEiee HvW8YE5CEMEDHWM/FXQc8a0Z6RTXO5rqEEI8mT51vv9EWH28pKFCDDP0bvqizMj8Zeny 05yLDtDh6tPk/IAOwKSdFSJylcbViRe5JQSR7l02LelCbCbtsOQOnC2amcf4pcvsZr6J JFOpQF2iOZLHpZWU/sR9zkrXSxRa8sAM+yIxD8xG4J0XP3UPcM9BhhjwWxjZtMHO5EPh V4TCQ7ijdoAKm/wnut5TOCa2eTuxeyUBpY/eLGrQWnY7kthI5Z8/CEu3jQW5nd6ZlUHe /b+A== X-Gm-Message-State: APjAAAXOwAJBtB11RhlV3zyfSxpB7N/tVCnXOwXyz6ia2v8GjFVLJKum itdp2jdyhlrclm6YTUdC3TsjyA== X-Google-Smtp-Source: APXvYqwSxpKXbSMy45Iflgb/oggW3gSVdZ3l436ykNIVtfT1vHBYjdOvlXejPjzPm37riWjiclruZg== X-Received: by 2002:adf:edd0:: with SMTP id v16mr20491760wro.310.1581588885858; Thu, 13 Feb 2020 02:14:45 -0800 (PST) Received: from localhost.localdomain ([2001:171b:2276:930:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id y131sm2428059wmc.13.2020.02.13.02.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 02:14:45 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, will@kernel.org, bhelgaas@google.com Subject: [PATCH 2/4] iommu/arm-smmu-v3: Add support for PCI PASID Date: Thu, 13 Feb 2020 11:14:33 +0100 Message-Id: <20200213101435.229932-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213101435.229932-1-jean-philippe@linaro.org> References: <20200213101435.229932-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200213_021447_099904_91668D91 X-CRM114-Status: GOOD ( 15.82 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangfei.gao@linaro.org, joro@8bytes.org, robin.murphy@arm.com, jonathan.cameron@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Enable PASID for PCI devices that support it. Initialize PASID early in add_device() because it must be enabled before ATS. Tested-by: Zhangfei Gao Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 62 ++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index aa3ac2a03807..6b76df37025e 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2628,6 +2628,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; @@ -2831,13 +2878,23 @@ 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: + * PCI Express Base 4.0r1.0 - 10.5.1.3 ATS Control Register + * + * Behavior is undefined if this bit is Set and the value of the PASID + * Enable, Execute Requested Enable, or Privileged Mode Requested bits + * are changed. + */ + 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)) { @@ -2850,6 +2907,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; @@ -2870,6 +2929,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); } From patchwork Thu Feb 13 10:14:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11380123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A75191395 for ; Thu, 13 Feb 2020 10:15:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8528820873 for ; Thu, 13 Feb 2020 10:15:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="o6JvJLO4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ITOJlvKt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8528820873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vdpwaxV8QEDNAxKR9N8XdM1jAzW6NPwieLi0DBBJuvM=; b=o6JvJLO4mqDYn8 C6keJzZq1wyPG7vzJKCmY2NHzB0jOIK5eXlBuVfNob4NYLbCvqavJ3c4P1LO151Kge6Flypej71xC BV5A1WJ87I6r6W81b9NWs4G5ac9ItT+X5GctDPhqMQKqhZ0S7TlYQ17yeswawz2NUHJnHH3HSTlle kmnQkffrVFnAdrnxtoDWZDBQKDH6BsEZ3642qDDSAb0LeUSTgBGEN8pleA/ffhLZRCQl6KWhPPruk 0i1Y832p3UuL3o34OL7S0QRpWnmXyY86UyHxBxpBIKx47VZxzqiDHvdHyWMf6tbVXAo04Crr6+Awp jxzGI2xx1/tpAdK+Fzww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BX3-00040f-AC; Thu, 13 Feb 2020 10:15:41 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWH-0002zP-M5 for linux-arm-kernel@lists.infradead.org; Thu, 13 Feb 2020 10:14:55 +0000 Received: by mail-wr1-x441.google.com with SMTP id z7so5889015wrl.13 for ; Thu, 13 Feb 2020 02:14:48 -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=y+lM1OggU9vK/FviSwCUPaJKK1SLUZczy02wSxpHTGA=; b=ITOJlvKtsqox/MA6KOfSi+vJ4namB81DtZOp6kWDIQxD7b+TlFocFAIVJlOuqeOJLw jnAwAYyOuE6iT1yKNsgrNsdlEVUXwo0f3f5XuFfWJeuedyhb6vC8ALBJtqp0b6WqHzE8 qcrcDhLWP3E8SPA1MNxxhfnEcRr0f1sF8smyS60fScZh4qfp1bR0L2/19nrMx0VVcLtI R8R3J4ILmTuTwu4U4gig0mCX91+1y3N5G1JCG1U2azXLUt2MiXV280vRSIQCkl3byt1t V4PuXsmwZIfmXYs2bhHjNKBDr/fRVv7wge5cBW1xYX5hvuhkTT1LsLrJ04K0mX/sWEIs Z+qg== 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=y+lM1OggU9vK/FviSwCUPaJKK1SLUZczy02wSxpHTGA=; b=V4nAcjKGkVN2m2S1flnM9ncqJdkGkkzvy8mwKBPTo0YuX6o9dqOxbSq8l/gqnpGrsp FmFU20ZQvBnHiZsy7v7OG41hNvNHjvSWjZ5Bo6l0AU0ZqAF7Q2SW3u7CNkNX8Qei8a/N oW8dYE7SQP1VclF+Gkzo2og4T7lVQYHQXuK8rZIypQHDlhrDwfkh4knnRp+AV0WGYq8z XPD3FuzjTk8XLEshFH16jEGiPiXgT4lLJwFhgb9XfTdTrBWZiF467xzCBFId2U0QXLCL cJ/zlTRKwVoachsb6ATmU2QZJlHiBemqJNcdDkNdJQYPIaFJ+8rq55Y6HVGqA96ItkY5 futQ== X-Gm-Message-State: APjAAAUoPlSFHxtUo44ZNmDGXgcYAT5HUzbSLag5cSZxo6Px43lF+cPV /IdaxVTLdPQR2g5W6TON80cXbg== X-Google-Smtp-Source: APXvYqyIF3pDX0A+K0urbcmvtOzcjcAguWoWW+hZyO7RemW9wjkDXElnYRLpdtxPkurp4xCvx2E5jQ== X-Received: by 2002:adf:df90:: with SMTP id z16mr20487511wrl.273.1581588886767; Thu, 13 Feb 2020 02:14:46 -0800 (PST) Received: from localhost.localdomain ([2001:171b:2276:930:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id y131sm2428059wmc.13.2020.02.13.02.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 02:14:46 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, will@kernel.org, bhelgaas@google.com Subject: [PATCH 3/4] iommu/arm-smmu-v3: Batch context descriptor invalidation Date: Thu, 13 Feb 2020 11:14:34 +0100 Message-Id: <20200213101435.229932-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213101435.229932-1-jean-philippe@linaro.org> References: <20200213101435.229932-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200213_021453_748725_2DDE642F X-CRM114-Status: GOOD ( 13.54 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangfei.gao@linaro.org, joro@8bytes.org, robin.murphy@arm.com, jonathan.cameron@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Rather than publishing one command at a time when invalidating a context descriptor, batch the commands for all SIDs in the domain. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 6b76df37025e..11123fbf22a5 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1487,8 +1487,10 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain, int ssid, bool leaf) { size_t i; + int cmdn = 0; unsigned long flags; struct arm_smmu_master *master; + u64 cmds[CMDQ_BATCH_ENTRIES * CMDQ_ENT_DWORDS]; struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_cmdq_ent cmd = { .opcode = CMDQ_OP_CFGI_CD, @@ -1501,13 +1503,19 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain, 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++) { + if (cmdn == CMDQ_BATCH_ENTRIES) { + arm_smmu_cmdq_issue_cmdlist(smmu, cmds, cmdn, false); + cmdn = 0; + } + cmd.cfgi.sid = master->sids[i]; - arm_smmu_cmdq_issue_cmd(smmu, &cmd); + arm_smmu_cmdq_build_cmd(&cmds[cmdn * CMDQ_ENT_DWORDS], &cmd); + cmdn++; } } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - arm_smmu_cmdq_issue_sync(smmu); + arm_smmu_cmdq_issue_cmdlist(smmu, cmds, cmdn, true); } static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, From patchwork Thu Feb 13 10:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11380121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AB5B1395 for ; Thu, 13 Feb 2020 10:15:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6879320873 for ; Thu, 13 Feb 2020 10:15:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ol7RBpVo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LxfZfpNC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6879320873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B3X3QduZJKm3Vayxd9Q6xDNmTMK6Fuy6R6vLSo2l97M=; b=Ol7RBpVod/1xDW vcCnEZksNeluU7UG3ueQZFh69NhPhbAYJEzwBCq8txmXmOLkXv6q1Iw6MaLBo5HOR6wOjTqMli5Rs csBgsh+SwG2wDtg9ysXfmpEATw2ggbQUsHizhinE2gnExiIQdbpVN8GEa4+RnYEOp4zjp0VKWburl raDXGMwk5s7P5MSHo9XyxjLt5ND1oGF4hfpRg0HFjkrKtxJfe14/0h3RYBPbOqn96zHBERA+W7uFA IBqVjEAMWcJ0eCzcaKBr42wMkCdDlezevfeEq7T2pvk6He7gEmN01ZRcLz1+20Q+aZBekHuXCtPEB aS0Uo3TRyEYAFAzvWm/w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWl-0003co-8w; Thu, 13 Feb 2020 10:15:24 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2BWF-0002zX-4l for linux-arm-kernel@lists.infradead.org; Thu, 13 Feb 2020 10:14:52 +0000 Received: by mail-wr1-x443.google.com with SMTP id c9so5919847wrw.8 for ; Thu, 13 Feb 2020 02:14:48 -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=x5dk7qiKtWru6EN2nFzBqe4Wug6V5GV2jfq/LzU0wiw=; b=LxfZfpNC9g2Kao3Ca86IBRs1BVelmn8AvrmBdYYcvu/Ke2cjSOzIyL4tYo+CSK06ir w3b22BZqfdo7gA4OGIO7IPlmKXPutox8+BQRijvmJOLUFg76kRhQNt87DPJR4X9qAiMM +A7sCzIh/nwBLfWMREpCrSBlAqcRv1kBTi7+wkAkOLYjSyYzxvIfzyWCPOhfF2PIoZMr 68xchnfm0tHysAcpb+CfWLgd+nrsjJ/carvqlZNvfgjhupYg/vPbGHa8oLMduRWowQxN SEyTmYq+kC8yFTfIDpTSzTGunUntmDOwNm/FB/pRONEy4RDWQgjDrBAGU67PZ2o+JbRW 6vGA== 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=x5dk7qiKtWru6EN2nFzBqe4Wug6V5GV2jfq/LzU0wiw=; b=SnvTzxBW+uKk+LDxtebQrkrxYmtNLctK1u7ECBNZiaHdSMuvc/kOe2p+fAEdGgUHoe GGV8AiNLcHvJggdTtcI8AtHTH9FJDNznA2w2wtY1V4IiA+/HjYlZ6ly0eFT7mMJw68wt C957OqGUrgtY4MUiU7xc9YtuIWoFB/uLmUKW3zAlaMOEfZ6yURbAZyiiGY8uSfI/JsiF cJs/vN+hIt1plrpMjC6FQ2C+hG+Fvi2pdn9odaZh2Xd+35JGAnkEJ37FTyAOVsmW0Om5 jhZKH3in4NC3BVJfEgQchnB+Wt2A1bWIhkOLRnk8acMoxX410lYqbHhOqudpI45McgKu 7KQw== X-Gm-Message-State: APjAAAWXkIWSEgnd600v8s5Ef9VmtoJHBgxK7IbjMTKCnlGFH3qJaELQ 9b3nUVA17CJTtvBguJXQnT8/JxklcKw= X-Google-Smtp-Source: APXvYqw6o99I0CZZyiTcqdl7ceH4XsBTkQw3w/87dL8LUwOg4DxhwdracytpcV7NsxduI66j7hSHCQ== X-Received: by 2002:adf:f787:: with SMTP id q7mr20817905wrp.297.1581588887619; Thu, 13 Feb 2020 02:14:47 -0800 (PST) Received: from localhost.localdomain ([2001:171b:2276:930:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id y131sm2428059wmc.13.2020.02.13.02.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 02:14:47 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, will@kernel.org, bhelgaas@google.com Subject: [PATCH 4/4] iommu/arm-smmu-v3: Write level-1 descriptors atomically Date: Thu, 13 Feb 2020 11:14:35 +0100 Message-Id: <20200213101435.229932-5-jean-philippe@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213101435.229932-1-jean-philippe@linaro.org> References: <20200213101435.229932-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200213_021451_196956_D1D98A32 X-CRM114-Status: GOOD ( 11.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangfei.gao@linaro.org, joro@8bytes.org, robin.murphy@arm.com, jonathan.cameron@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Use WRITE_ONCE() to make sure that the SMMU doesn't read incomplete stream table descriptors. Refer to the comment about 64-bit accesses, and add the comment to the equivalent context descriptor code. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 11123fbf22a5..034ad9671b83 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1539,6 +1539,7 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst, u64 val = (l1_desc->l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; + /* See comment in arm_smmu_write_ctx_desc() */ WRITE_ONCE(*dst, cpu_to_le64(val)); } @@ -1734,7 +1735,8 @@ arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, desc->span); val |= desc->l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; - *dst = cpu_to_le64(val); + /* See comment in arm_smmu_write_ctx_desc() */ + WRITE_ONCE(*dst, cpu_to_le64(val)); } static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid)