From patchwork Tue Jun 25 12:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0B75AC30658 for ; Tue, 25 Jun 2024 12:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=iDvKfLmkd4Zjmuan1scBW4M/zN kZTp6+kOcean7E4yxqGv7pOPI3xxqgBykvyGDYPD3rwGIskw9CYU4VAjRceFx7CtFL0XJpyag0C88 c3V3DgZX0lxNle+aW61wH5/tfza50SgB/m8jglF7gy04fSNBW/xFI8lsfyvK2hikuiwJ09HHoSvBv ZP9YZFtvrjs2Dpq8hcuKFEXTu6DkdlOBhZjWydjNlS/PjZ98shegv1fZhJnwh/BTsVvij7tT1KsYB TWy9YDyQXRvBSfvVvVgegdBcpagSTpZyk2QjlJYxBR9bmowcymIxuLFUC0cCldtATsbDVu1X8A5CM GpuPhkQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5RZ-00000002o9f-296I; Tue, 25 Jun 2024 12:38:41 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qy-00000002nfA-2MlK for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:38:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eVdcUKYE1LHGgKUpeqk6O60z1zCiEQUCbOYSzabRzrwslRUQekwMyxDRbU3MjUJQ5Hw/1wTx0OkjYMG7XkHxm5Q/Y41S/WwsneUC9LvYT6zba24g7CUDfBVGpYpEq3DlvLVyDR+Cp2mLgvuz2dU00oWdHgf3f6iZQDG1n/9gU0f0Y+nT/n2m4aocKzKgqnTmoMSWLJVZo+5ZeyUirSO8UaW6qxTDnztlq5nX59XCqj03XF5MqTZ8v5M7tXyPnEbQ8ie8rTU3nX3qFQGFthM2ZAQFwYphIRWm4P7F2nGQX8Ieq8LcKRotum6KaLedYWn+doHJTehWmeDSo9ASbu29Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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; bh=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=NeFKEZrAAprlW37EBrDpNShDZaTuhUeR/SLiXWVYEwIfLDQ/mzowUI4nE8CgOSBksauyAt/8fAXUEERSMm4i7TvSzEmrPyvU8jo0efCN99dQ2pBnD4sbHC+nZ4NGBu3fVrhrOLIEjoNJI7uZOgGV2xCfztouy9ttYCusIngV2WVSTCxCTmlFVCQYc40vAwe3srJrLYnigJe0umNW/wGRdoVumN6zb2vbJ+hMPMKbRtTR0EgI9ERt/tW3jrOTQO1fMnEhtPkUxxfFLF/1WMfz+gfrUQuwVkVPDazEzAMUepDbUT+0P9fM33d3jWNY6m6m1AqEz5R/wuKBlB4htLOl1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+X3WjW4RXlZV8/opPZ85LBFlYMENPROAjYdO236yOBE=; b=BPFGdFPtPtuYKPPDBbG0nA0Z9CGX/uv6QVR7G4+laHdUGi/HEeryh+Z2DOhu0pY8iMyApXtSEmXFH0iZ0MDXaLWAtTLAFwRqVrIlHyf5IbEnA+LFhENi8OfkPtuEUkhOG053P6z9KWAMxYFmxqRjfIlIwSyuA/yQ6mWhHy84D4Jh2xdbIeBQvWvs4GYMIXCcY7JNINSsbOtBThOZDlvtXiBCimWuAySPAUMk5mycrEzta4Y/3KRWSbHd1R2+wQlt55Y4+qnzYCY6oPXH5r6VCYGNnVBBbZQ1yZ7IMENgfQhd0jlHEJPFKi6QLnRh5MpCujPf4N1XFT6VpFobz5L/5w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:48 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:48 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 13/14] iommu/arm-smmu-v3: Allow a PASID to be set when RID is IDENTITY/BLOCKED Date: Tue, 25 Jun 2024 09:37:44 -0300 Message-ID: <13-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0028.namprd08.prod.outlook.com (2603:10b6:208:239::33) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: b63a69bd-13e2-4eb6-6d7b-08dc95139dfc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: vjMXXi4tYI7sQIF+0+gGkE4Jbdo3iAqQ+8d4BTwpcVf9lO3UIZGGiM6nAT9xm9CnrNnpCGelRHkNCZUB6BUSC2pwT4ocKOxki3TkYWxsxS/psqgFCETzuYXGGSpf1ph2q9H8pFEGHY3OzLWypJ/+w0HbpfAFY7htpOBvdm66VCxNnzwoB3RuJIl9uWCtxfmfwufBQ0QF10/LjZVLYPNcTJWLmv272W1Ei173ve2/o2y2aIp2sF72mAJ5sZp1nytHIr6rRaUFxqmVwYHe+yKEUhZ0hPotGzqwTYzuzIpJrFa/35JB+cpLcGVz7/8qYjia/uwFA49lTYp8HSEn9XBxQemA/lDtX1XLZ8FjPkUujNWjXAsZNi/I+ZN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(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Da4q/hgr/7f4QzJNfjN0yZDD+qTbw2U3VXuIUREwh7BzjsT+FiqWIyhEJJMQykTSImvSu3g+8qqYreRiuYvSwKidHtMp9vps5M84LtquedkfUBpY2FyMjuieb7KouPQRra1nRWvHNJT8fCktmcPSGbx/UbJJUDJzaj7F1kIJokfAWYGAmkFcB6o/rbIk7q3vq6QF+4rRDVnIsuLm1gastS1G+frZcmkGWVEnwfMu9d+FPy9wcXwzAxwHoKxN3cotY/tzqgQVfHzLbyOZYczMTLES8Z2hkJm9HaElc28f41HqFpmSWSiQdrX/8YSoon6jCzjn36ug3do84fKh4iEDXy236Dz1PjUe+62nsmlwein9P4iGmdMcK2CkEcUkekvl4+wUgtIBzyq1wQU8jk8oY6libxAqOEp2YMT6sPMftApbJxsdIs6Ui3gVGuIzurF5q+QUdwPYra9+cX8x68sajywv0+/GW8NwCofTXMuTMJYglxKr/C4pb6pUxt8Qs6K/+tLBHTJJhMXIi5brkbeIsjvAxeI/2NpuatysfpNKD+Yy7SYH3doU/I9GfSGoJmyuoYeJ6EBfsbwHU+tzb0asBbGCSDmpHZd9DS8lloIkT8UwBPI87zj9yiL3uglfL5PvvkS9rFUJIJ51nxzE5CFGO5YjgKWWJjLLQFo/61hY2CdrSihD1q4ELzBDM1wqNenaUOXGuBPwri0HwNzycWHPw55hL7ncWmOQYo/UuReRT3KwNh0P6uewvLFj4d7tqJ1QVeYLQ9QQfnC45B9fpMgfYdm2IOSIflYRTw9sUhrABJIHkoFRbJyujnC2aBQ1yAGepOn+v24Tbnvw4lTWc8tIx+vG/8Sxi8+hWaSJuC/S10Q8TEioyM3SGeABC1l60IEqiUGW4dgO4tEvkIVwI2FJU+nNtvGNvqpkbObpk7BEBBF6H/lUA3QtX300WBeKiQAwI51m9HI9Cqhf+iRpwsrgZMm0wAz+Z/mzsXrpR/YeLW5ScUVnjYum2gQ7HKs/4drN6EYSoOeUMeZe3cEoRiK2kwo9ITepLc1onnrDfulYH+YTwPe9slUYaFQIlY+BxXH5MkNxbR0hr2VKZgZ1lwd3mtjFeUoQ6R0IpNUG7k9T3lrgMf7UsJW7ltMGKerwW3gV1rv+TyWnAtH0ea3q+OUYcS42vr30smBj7LLwjNW2Xd2fShl7TOV9pJ908vJvE8Rbv4kWSNuY4BaVUkxAAxxdtxwGyJnRwZyfcGFeRS7jlwRz1bo7EiZRvtNywoYUsMG8Xj5Sabx6KL9D0834SisEIsHv8DPyclxi511et37Mauw77HbHi9WbLPOFRmBPgYQs7JIrBZA9i+eJoj4TXaHClxtWsgggJ7R+JPvzh0fSwbcmQ1vMHgpP9WJn8IBrrPDEoMCCatPKAwVpGbF8vL4Io4d//Oft+1ifSZUZ5fVazwRnETbjJBTRT7gvOXE3U+zN7bzIw6evxFKtpPm63N71g/1tCYm3o4GXlc2SYdxgaG9gzCxTurGgQbXjs92/Qa6aAa96iT+GmNat0tMqCV+csJD1sBmFkG9grqrsGXCwFxwosY1lBbH/w1JKAd0Xxf2R X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b63a69bd-13e2-4eb6-6d7b-08dc95139dfc X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.8234 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7h33LbJiNQdF3HX5RxMH78+hPKe12EHjW04r+fN6jMO5Z3cdhYbVamhj6tSO1yjl X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053804_720818_D767F110 X-CRM114-Status: GOOD ( 21.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the STE doesn't point to the CD table we can upgrade it by reprogramming the STE with the appropriate S1DSS. We may also need to turn on ATS at the same time. Keep track if the installed STE is pointing at the cd_table and the ATS state to trigger this path. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 49 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 10d140a5cd0f38..fbe14466f5f379 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2435,6 +2435,9 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, master->cd_table.in_ste = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == STRTAB_STE_0_CFG_S1_TRANS; + master->ste_ats_enabled = + FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(target->data[1])) == + STRTAB_STE_1_EATS_TRANS; for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; @@ -2795,10 +2798,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +static void arm_smmu_update_ste(struct arm_smmu_master *master, + struct iommu_domain *sid_domain, + bool ats_enabled) +{ + unsigned int s1dss = STRTAB_STE_1_S1DSS_TERMINATE; + struct arm_smmu_ste ste; + + if (master->cd_table.in_ste && master->ste_ats_enabled == ats_enabled) + return; + + if (sid_domain->type == IOMMU_DOMAIN_IDENTITY) + s1dss = STRTAB_STE_1_S1DSS_BYPASS; + else + WARN_ON(sid_domain->type != IOMMU_DOMAIN_BLOCKED); + + /* + * Change the STE into a cdtable one with SID IDENTITY/BLOCKED behavior + * using s1dss if necessary. If the cd_table is already installed then + * the S1DSS is correct and this will just update the EATS. Otherwise it + * installs the entire thing. This will be hitless. + */ + arm_smmu_make_cdtable_ste(&ste, master, ats_enabled, s1dss); + arm_smmu_install_ste_for_dev(master, &ste); +} + int arm_smmu_set_pasid(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, ioasid_t pasid, const struct arm_smmu_cd *cd) { + struct iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev); struct arm_smmu_attach_state state = { .master = master, /* @@ -2815,8 +2844,10 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, if (smmu_domain->smmu != master->smmu) return -EINVAL; - if (!master->cd_table.in_ste) - return -ENODEV; + if (!master->cd_table.in_ste && + sid_domain->type != IOMMU_DOMAIN_IDENTITY && + sid_domain->type != IOMMU_DOMAIN_BLOCKED) + return -EINVAL; cdptr = arm_smmu_alloc_cd_ptr(master, pasid); if (!cdptr) @@ -2828,6 +2859,7 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, goto out_unlock; arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + arm_smmu_update_ste(master, sid_domain, state.ats_enabled); arm_smmu_attach_commit(&state); @@ -2850,6 +2882,19 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, arm_smmu_atc_inv_master(master, pasid); arm_smmu_remove_master_domain(master, &smmu_domain->domain, pasid); mutex_unlock(&arm_smmu_asid_lock); + + /* + * When the last user of the CD table goes away downgrade the STE back + * to a non-cd_table one. + */ + if (!arm_smmu_ssids_in_use(&master->cd_table)) { + struct iommu_domain *sid_domain = + iommu_get_domain_for_dev(master->dev); + + if (sid_domain->type == IOMMU_DOMAIN_IDENTITY || + sid_domain->type == IOMMU_DOMAIN_BLOCKED) + sid_domain->ops->attach_dev(sid_domain, dev); + } } static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 30459a800c7b2d..cdd426efb384d2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -705,7 +705,8 @@ struct arm_smmu_master { /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; - bool ats_enabled; + bool ats_enabled : 1; + bool ste_ats_enabled : 1; bool stall_enabled; bool sva_enabled; bool iopf_enabled;