{"id":2228586,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2228586/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/7403163ebf59380f88c7503b3adf0dae07428df8.1777269009.git.nicolinc@nvidia.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.1/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<7403163ebf59380f88c7503b3adf0dae07428df8.1777269009.git.nicolinc@nvidia.com>","date":"2026-04-27T05:54:02","name":"[v4,3/3] iommu/arm-smmu-v3: Allow ATS to be always on","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f15d026a4d8d8a6fd31c5ca9938cc46185025259","submitter":{"id":82183,"url":"http://patchwork.ozlabs.org/api/1.1/people/82183/?format=json","name":"Nicolin Chen","email":"nicolinc@nvidia.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/7403163ebf59380f88c7503b3adf0dae07428df8.1777269009.git.nicolinc@nvidia.com/mbox/","series":[{"id":501574,"url":"http://patchwork.ozlabs.org/api/1.1/series/501574/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=501574","date":"2026-04-27T05:53:59","name":"Allow ATS to be always on for certain ATS-capable devices","version":4,"mbox":"http://patchwork.ozlabs.org/series/501574/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2228586/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228586/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pci+bounces-53203-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256\n header.s=selector2 header.b=oKseFeC8;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-53203-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com\n header.b=\"oKseFeC8\"","smtp.subspace.kernel.org;\n arc=fail smtp.client-ip=52.101.193.24","smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=nvidia.com","smtp.subspace.kernel.org;\n spf=fail smtp.mailfrom=nvidia.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g3t8n4Wtcz1yJX\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 15:55:53 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 76A0A301DC39\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 05:54:56 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A283636AB50;\n\tMon, 27 Apr 2026 05:54:44 +0000 (UTC)","from CH1PR05CU001.outbound.protection.outlook.com\n (mail-northcentralusazon11010024.outbound.protection.outlook.com\n [52.101.193.24])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id F29E636E469;\n\tMon, 27 Apr 2026 05:54:42 +0000 (UTC)","from PH8P223CA0009.NAMP223.PROD.OUTLOOK.COM (2603:10b6:510:2db::6)\n by SN7PR12MB7934.namprd12.prod.outlook.com (2603:10b6:806:346::16) with\n Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.15; Mon, 27 Apr\n 2026 05:54:35 +0000","from CY4PEPF0000EE34.namprd05.prod.outlook.com\n (2603:10b6:510:2db:cafe::5c) by PH8P223CA0009.outlook.office365.com\n (2603:10b6:510:2db::6) with Microsoft SMTP Server (version=TLS1_3,\n cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.26 via Frontend Transport; Mon,\n 27 Apr 2026 05:54:35 +0000","from mail.nvidia.com (216.228.118.233) by\n CY4PEPF0000EE34.mail.protection.outlook.com (10.167.242.40) with Microsoft\n SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.20.9846.18 via Frontend Transport; Mon, 27 Apr 2026 05:54:33 +0000","from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com\n (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Sun, 26 Apr\n 2026 22:54:23 -0700","from drhqmail203.nvidia.com (10.126.190.182) by\n drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.2.2562.20; Sun, 26 Apr 2026 22:54:22 -0700","from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com\n (10.126.190.182) with Microsoft SMTP Server id 15.2.2562.20 via Frontend\n Transport; Sun, 26 Apr 2026 22:54:21 -0700"],"ARC-Seal":["i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777269284; cv=fail;\n b=nZr9L4Fx3MY+Ngn7ipN5M2zIUH3yyGvuTlJBozrARgBa9rvVabBztS0HJCBAMJQhuYPBXfbhgkGdD8k70sgMDnXDygBs5SLvf1U6wk4B2Mp65EbjbVaUQxLEoyFyq3t92ZPXQj8ULkKsmAaOHM7dc+ivVPgqB0imzPdPUyOO5dI=","i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;\n b=quTI24/ya7Sweem6NUWgA2rs4DLRk2BHpPO/y+9BxaFMao6PiPEUf5W07aO9ou2jwCpds9ArqoU4CENAOF9kthO7RIALSto2oGDiRcYS6AR8pZgmqxBBg4YU8DigebCK1nj/sKhoR0iJYyUcUNvUpkbVFVXomNdpgLUjWbvbJ4x5nL6ckGcdG8mUP2MnMnYdvd4pypm/niNQhn0q7vEzjUv3Q51swOmywM7+7VHl991zIQDp5LO+0KSh+cxkAjnRrz2MNsObhSCQFbbrmgPwQ4OqrRtPw8c08BmBttGoGtba/gigI11ICzNPdwVVDSqqcsV9g846uoMjNqXPWtv3og=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777269284; c=relaxed/simple;\n\tbh=Yy6+OCvyof5hh+/KanJbfWK95/yJ9tczfE6CvIEFlZc=;\n\th=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version:Content-Type;\n b=X/fwFNPFQ8p0Jou62kJv/FpGVTtekpm0osLGufgFBMa5ffY2eP4x3i0+KXfuLl3DXy/MOD2qVxcZM7UxHoAwMmkovALApXnc30Epi8WITY8D/BMCVfFBctZHXGo3rWSL4g7YGKEW5ZNhRpRTxjaCTVOzVK8d9js8eofU66sVbSo=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector10001;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;\n bh=WA26ZXMcbyPLMHwVMRJmwkF7x+GStFfCMKYbTLKdT8s=;\n b=QQGei1GNVe8cwknwwVGtxR6W49jKGc3dTZtv0vhEC0EVxNdbRYH29M7N7csuBC+tUAJm6SVJD1b/xh6OIWCu5rJ4HR9TyboFKzgk6KB3hcRM6JXRBniAjoS3cyui309mH6vE7ocVyJNDnifwzI/n9scrj99PD0ut/UyqEr1UBfrrzOEg07pfeDEjiS5f6RiE6BqIVbg1WfQd09UsgVzC4H7jfq1j+Jz04m4AJcSlRC4nJdVjx8nRDmXVD25LT0hmf/c1PBVmTmJq1TO7jyecO+twcjDZHvN1kE8bMw6FsWoJfKzGvalLdb1mMFRHpXo9WkMnDCdHAmkQwICEs1UQjA=="],"ARC-Authentication-Results":["i=2; smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=nvidia.com;\n spf=fail smtp.mailfrom=nvidia.com;\n dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com\n header.b=oKseFeC8; arc=fail smtp.client-ip=52.101.193.24","i=1; mx.microsoft.com 1; spf=pass (sender ip is\n 216.228.118.233) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com;\n dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com;\n dkim=none (message not signed); arc=none (0)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com;\n s=selector2;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=WA26ZXMcbyPLMHwVMRJmwkF7x+GStFfCMKYbTLKdT8s=;\n b=oKseFeC80LPbY7yF+vcEQtkz33H+qVqhS8Wzmq5OWAkIi2znVq7Qdm7fdfycaQPUTnOk/16GyM3OEYPkrgLLLGn6sSzEm6TVLgiAza6Bo+7+S6c69RdLMdUEC5tshi5HsciMrGqrC4zpAZ678nLboienS6tMH/9w56lj2fg+AItCqAilUSRAB1fTHRbsETvvc2h2VB1KfObU4VHP4wxWJog6KEp9kM+MkhgXSa09+Cem7a0uE0KdU4yfJW7Yz49YJ1l01XOkYNbTL/esRDIGmtXgwM4kbQfuwPiDxJD4jJoaBn/0aT9klV97OpxJVaKwR9NJ4ewDIb1XAGiNFlnT1Q==","X-MS-Exchange-Authentication-Results":"spf=pass (sender IP is 216.228.118.233)\n smtp.mailfrom=nvidia.com; dkim=none (message not signed)\n header.d=none;dmarc=pass action=none header.from=nvidia.com;","Received-SPF":"Pass (protection.outlook.com: domain of nvidia.com designates\n 216.228.118.233 as permitted sender) receiver=protection.outlook.com;\n client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C","From":"Nicolin Chen <nicolinc@nvidia.com>","To":"<jgg@nvidia.com>, <will@kernel.org>, <robin.murphy@arm.com>,\n\t<bhelgaas@google.com>","CC":"<joro@8bytes.org>, <praan@google.com>, <baolu.lu@linux.intel.com>,\n\t<kevin.tian@intel.com>, <miko.lenczewski@arm.com>,\n\t<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,\n\t<linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,\n\t<dan.j.williams@intel.com>, <jonathan.cameron@huawei.com>,\n\t<vsethi@nvidia.com>, <linux-cxl@vger.kernel.org>, <nirmoyd@nvidia.com>","Subject":"[PATCH v4 3/3] iommu/arm-smmu-v3: Allow ATS to be always on","Date":"Sun, 26 Apr 2026 22:54:02 -0700","Message-ID":"\n <7403163ebf59380f88c7503b3adf0dae07428df8.1777269009.git.nicolinc@nvidia.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<cover.1777269009.git.nicolinc@nvidia.com>","References":"<cover.1777269009.git.nicolinc@nvidia.com>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain","X-NV-OnPremToCloud":"ExternallySecured","X-EOPAttributedMessage":"0","X-MS-PublicTrafficType":"Email","X-MS-TrafficTypeDiagnostic":"CY4PEPF0000EE34:EE_|SN7PR12MB7934:EE_","X-MS-Office365-Filtering-Correlation-Id":"915ee2ba-c761-4043-fcf1-08dea42174e2","X-MS-Exchange-SenderADCheck":"1","X-MS-Exchange-AntiSpam-Relay":"0","X-Microsoft-Antispam":"\n\tBCL:0;ARA:13230040|1800799024|376014|7416014|82310400026|36860700016|56012099003|22082099003|18002099003;","X-Microsoft-Antispam-Message-Info":"\n\t8i2vnFg4ZZ2/F2IVNzMjWd3UApDbfXHx+mZLjsnrZ5SvOGZVmnSYVsDS+T0nURS43d+Yk85Ie97DL/xKujmg1FLL52owQJyreqo0DWzcrEkbbvGD/WzUK1Aq38qNHohrx9xsa7sryn/MHXdl/o4I3grtYuNDN1krNTV2W8TrMFDPi+oFpN/59vFRNeSSn8LluFAYXqmrBLzjjBQ8rNqCcibYSV8UsidaEiao/mci9OGbiUMGWiElkbCec46OB2kuvj7CIpdPu+pEW4Jmk8gJYkXWSrUzTRURag9XhsTJsWEEg9jUl1NKPSZs5s9MWLdRSDjTZHuEsmoFI7/F1Cn81jyK7TWuKkWcq4EHiAtA3ziJ+nz0TsVxlBBugRVaIKiTUyVdRDOCD1vRmPg15BCsj99NraNaeU0TfGAJ1gQsd0Ir7TfQ65cSnRRSBPWtxU2kAEaI2bZodLmQ745vVlhAHYPu6kFBc2ztdcLDEwZAMaClmyRDFGMXwo++aVuvdecI9AO0wx9mcFLuDRiNxDl/QgG0telmy6lKNi5JquB8PR1mmAkHEIS7bPcrv4I9pDEaj+xOjF/C4+Ze9qiEWGwRI3QppazeeB9sKwX3U3p6FOQHPb5wUVCj4FaXlrzrxDHEwk4BP7zbr/SprcIjRiqS2uPDAi5zuyKJrttIGqFfI3mijym3s72LvnmDWnql13p2mN26+kbekXBPZMlBGGqpjhtGkzwNhlgZIANdDSf31yHRe2VkNhOUyspjyOjPtLa3Oqm7juxOVAf3MvEcW/XKqg==","X-Forefront-Antispam-Report":"\n\tCIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(82310400026)(36860700016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101;","X-MS-Exchange-AntiSpam-MessageData-ChunkCount":"1","X-MS-Exchange-AntiSpam-MessageData-0":"\n\tl++nAeyI0c0XnYBhqVvksEjeoPyfAEQIDrZZA5QiL1AtdhIRmnpq62ZjqSHuob9xQncOnm2MjtW5Wl7Etj+OjmRxtQ7+fwmDK3Ewxp0dsgxChFaKmFc+hc4Js0wXGIGW1hIjbZcpfoTOOkcTIUCy4UlAlDtx7uEje34XecPxMSL+12FQKAxPzBgarEEv6Pse77srucei+3JgSKzEl0qDSXFbf6Agp6sfoBaSlLjG5iOu/sPu93cvAjaO82BRvau7u7CSl1Eb3LzUE6NqN82PMJsrGsn+MfmYJjcuwfggqQfRr8CbTw0YkGvJmOGuZgTyYh1FmUivRaSwG4r1IWc1RVeGOA2PhCbI+QKBEclWvVr3SW0w2KgFupGVvb84g74FElAE9n+0ffJ7XM468KfsYef4raY1Ohko/uI8PnqhbbyGKyIY+8OmPr+be0AoyVEJ","X-OriginatorOrg":"Nvidia.com","X-MS-Exchange-CrossTenant-OriginalArrivalTime":"27 Apr 2026 05:54:33.4056\n (UTC)","X-MS-Exchange-CrossTenant-Network-Message-Id":"\n 915ee2ba-c761-4043-fcf1-08dea42174e2","X-MS-Exchange-CrossTenant-Id":"43083d15-7273-40c1-b7db-39efd9ccc17a","X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp":"\n TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com]","X-MS-Exchange-CrossTenant-AuthSource":"\n\tCY4PEPF0000EE34.namprd05.prod.outlook.com","X-MS-Exchange-CrossTenant-AuthAs":"Anonymous","X-MS-Exchange-CrossTenant-FromEntityHeader":"HybridOnPrem","X-MS-Exchange-Transport-CrossTenantHeadersStamped":"SN7PR12MB7934"},"content":"When a device's default substream attaches to an identity domain, the SMMU\ndriver currently sets the device's STE between two modes:\n\n  Mode 1: Cfg=Translate, S1DSS=Bypass, EATS=1\n  Mode 2: Cfg=bypass (EATS is ignored by HW)\n\nWhen there is an active PASID (non-default substream), mode 1 is used. And\nwhen there is no PASID support or no active PASID, mode 2 is used.\n\nThe driver will also downgrade an STE from mode 1 to mode 2, when the last\nactive substream becomes inactive.\n\nHowever, there are PCIe devices that demand ATS to be always on. For these\ndevices, their STEs have to use the mode 1 as HW ignores EATS with mode 2.\n\nChange the driver accordingly:\n  - always use the mode 1\n  - never downgrade to mode 2\n  - allocate and retain a CD table (see note below)\n\nNote that these devices might not support PASID, i.e. doing non-PASID ATS.\nIn such a case, the ssid_bits is set to 0. However, s1cdmax must be set to\na !0 value in order to keep the S1DSS field effective. Thus, when a master\nrequires ats_always_on, set its s1cdmax to at least 1, meaning that the CD\ntable will have a dummy entry (SSID=1) that will never be used.\n\nNow for these devices, arm_smmu_cdtab_allocated() will always return true,\nv.s. false prior to this change. When its default substream is attached to\nan IDENTITY domain, its first CD is NULL in the table, which is a totally\nvalid case. Thus, add \"!master->ats_always_on\" to the condition.\n\nReviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>\nTested-by: Nirmoy Das <nirmoyd@nvidia.com>\nAcked-by: Nirmoy Das <nirmoyd@nvidia.com>\nReviewed-by: Jason Gunthorpe <jgg@nvidia.com>\nReviewed-by: Kevin Tian <kevin.tian@intel.com>\nSigned-off-by: Nicolin Chen <nicolinc@nvidia.com>\n---\n drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h |  1 +\n drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 75 ++++++++++++++++++---\n 2 files changed, 68 insertions(+), 8 deletions(-)","diff":"diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h\nindex ef42df4753ec4..8c3600f4364c5 100644\n--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h\n+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h\n@@ -943,6 +943,7 @@ struct arm_smmu_master {\n \tbool\t\t\t\tats_enabled : 1;\n \tbool\t\t\t\tste_ats_enabled : 1;\n \tbool\t\t\t\tstall_enabled;\n+\tbool\t\t\t\tats_always_on;\n \tunsigned int\t\t\tssid_bits;\n \tunsigned int\t\t\tiopf_refcount;\n };\ndiff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c\nindex e8d7dbe495f03..d478f148cd34b 100644\n--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c\n+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c\n@@ -1742,8 +1742,11 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid)\n \tif (!arm_smmu_cdtab_allocated(&master->cd_table))\n \t\treturn;\n \tcdptr = arm_smmu_get_cd_ptr(master, ssid);\n-\tif (WARN_ON(!cdptr))\n+\tif (!cdptr) {\n+\t\t/* Only ats_always_on allows a NULL CD on default substream */\n+\t\tWARN_ON(!master->ats_always_on || ssid);\n \t\treturn;\n+\t}\n \tarm_smmu_write_cd_entry(master, ssid, cdptr, &target);\n }\n \n@@ -1756,6 +1759,22 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master)\n \tstruct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table;\n \n \tcd_table->s1cdmax = master->ssid_bits;\n+\n+\t/*\n+\t * When a device doesn't support PASID (non default SSID), ssid_bits is\n+\t * set to 0. This also sets S1CDMAX to 0, which disables the substreams\n+\t * and ignores the S1DSS field.\n+\t *\n+\t * On the other hand, if a device demands ATS to be always on even when\n+\t * its default substream is IOMMU bypassed, it has to use EATS that is\n+\t * only effective with an STE (CFG=S1translate, S1DSS=Bypass). For such\n+\t * use cases, S1CDMAX has to be !0, in order to make use of S1DSS/EATS.\n+\t *\n+\t * Set S1CDMAX no lower than 1. This would add a dummy substream in the\n+\t * CD table but it should never be used by an actual CD.\n+\t */\n+\tif (master->ats_always_on)\n+\t\tcd_table->s1cdmax = max_t(u8, cd_table->s1cdmax, 1);\n \tmax_contexts = 1 << cd_table->s1cdmax;\n \n \tif (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) ||\n@@ -3851,7 +3870,8 @@ static int arm_smmu_blocking_set_dev_pasid(struct iommu_domain *new_domain,\n \t * When the last user of the CD table goes away downgrade the STE back\n \t * to a non-cd_table one, by re-attaching its sid_domain.\n \t */\n-\tif (!arm_smmu_ssids_in_use(&master->cd_table)) {\n+\tif (!master->ats_always_on &&\n+\t    !arm_smmu_ssids_in_use(&master->cd_table)) {\n \t\tstruct iommu_domain *sid_domain =\n \t\t\tiommu_driver_get_domain_for_dev(master->dev);\n \n@@ -3875,6 +3895,8 @@ static void arm_smmu_attach_dev_ste(struct iommu_domain *domain,\n \t\t.old_domain = old_domain,\n \t\t.ssid = IOMMU_NO_PASID,\n \t};\n+\tbool ats_always_on = master->ats_always_on &&\n+\t\t\t     s1dss != STRTAB_STE_1_S1DSS_TERMINATE;\n \n \t/*\n \t * Do not allow any ASID to be changed while are working on the STE,\n@@ -3886,7 +3908,7 @@ static void arm_smmu_attach_dev_ste(struct iommu_domain *domain,\n \t * If the CD table is not in use we can use the provided STE, otherwise\n \t * we use a cdtable STE with the provided S1DSS.\n \t */\n-\tif (arm_smmu_ssids_in_use(&master->cd_table)) {\n+\tif (ats_always_on || arm_smmu_ssids_in_use(&master->cd_table)) {\n \t\t/*\n \t\t * If a CD table has to be present then we need to run with ATS\n \t\t * on because we have to assume a PASID is using ATS. For\n@@ -4215,6 +4237,42 @@ static void arm_smmu_remove_master(struct arm_smmu_master *master)\n \tkfree(master->build_invs);\n }\n \n+static int arm_smmu_master_prepare_ats(struct arm_smmu_master *master)\n+{\n+\tbool s1p = master->smmu->features & ARM_SMMU_FEAT_TRANS_S1;\n+\tunsigned int stu = __ffs(master->smmu->pgsize_bitmap);\n+\tstruct pci_dev *pdev;\n+\tint ret;\n+\n+\tif (!arm_smmu_ats_supported(master))\n+\t\treturn 0;\n+\n+\tpdev = to_pci_dev(master->dev);\n+\n+\tif (!pci_ats_always_on(pdev))\n+\t\tgoto out_prepare;\n+\n+\t/*\n+\t * S1DSS is required for ATS to be always on for identity domain cases.\n+\t * However, the S1DSS field is ignored if !IDR0_S1P or !IDR1_SSIDSIZE.\n+\t */\n+\tif (!s1p || !master->smmu->ssid_bits) {\n+\t\tdev_info_once(master->dev,\n+\t\t\t      \"SMMU doesn't support ATS to be always on\\n\");\n+\t\tgoto out_prepare;\n+\t}\n+\n+\tmaster->ats_always_on = true;\n+\n+\tret = arm_smmu_alloc_cd_tables(master);\n+\tif (ret)\n+\t\treturn ret;\n+\n+out_prepare:\n+\tpci_prepare_ats(pdev, stu);\n+\treturn 0;\n+}\n+\n static struct iommu_device *arm_smmu_probe_device(struct device *dev)\n {\n \tint ret;\n@@ -4263,14 +4321,15 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)\n \t    smmu->features & ARM_SMMU_FEAT_STALL_FORCE)\n \t\tmaster->stall_enabled = true;\n \n-\tif (dev_is_pci(dev)) {\n-\t\tunsigned int stu = __ffs(smmu->pgsize_bitmap);\n-\n-\t\tpci_prepare_ats(to_pci_dev(dev), stu);\n-\t}\n+\tret = arm_smmu_master_prepare_ats(master);\n+\tif (ret)\n+\t\tgoto err_disable_pasid;\n \n \treturn &smmu->iommu;\n \n+err_disable_pasid:\n+\tarm_smmu_disable_pasid(master);\n+\tarm_smmu_remove_master(master);\n err_free_master:\n \tkfree(master);\n \treturn ERR_PTR(ret);\n","prefixes":["v4","3/3"]}