From patchwork Tue Apr 30 17:21:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13649705 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 81F73C4345F for ; Tue, 30 Apr 2024 17:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=KCQ3Y9gKeLAXyopGp+HXG99hvLQnhf+zIwtaT6M3PJ0=; b=HaNzufndQ7n2dO yuw6ZEHchlxlIXbUr9Jd3Clp6KWaZkapb1WfsAtRSx6GuWsZLQ9LlLiStRVFgWVXCG6KqgnF2nLsc 4JPmFdcVYvDDOWPXfJc2Bgjr/cNX0zCjDIN453TMhMr5hs6OE0AHA7HzeNR9DaIRFmux4yeZWdxyP W8I9yfrJK6DQgmDV25+c/9mg8RMa7XHt/gWAEpTq2JARj3KLhRAM8OQQf/EY8deU+QD7XSy2LHkDw hAGSVGVRPULChr36qL6by3cAxRT9PZg6QGxBlAZEWp9N+sX1jGvyCa0JmydKdja5ASBfPmjhXq401 Fr1a8XVvkr1ac0QJvMaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rBD-00000007Og1-1iYr; Tue, 30 Apr 2024 17:22:11 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rAz-00000007OX2-27VO for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2024 17:21:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LWNOSwUxKAO8UU3K8Rtsk+8v4yIoXBfHIeJKTnIfna8w6/4SAOMRhpzlVzF8aStibbQaws9qH1EaPZ1hb5zvaqrpZJuXrQLQWRGE9ARE8axv6+SwljBEqf2CISH+ckZ8A8C/qs6CP49HaDoum6Hf782S/Pj/MIM+Er0Ck72a6KVxWVUyOiglRE/iuAd2ailK6m0CDjxCMfW78t9J8xGx87z/ScmFezcu3gvjQWIRkuqW+ymXpPGPqcYnTE14Hgdgv/DMTQFtbDwDMECj1wRwZEL6euNJmyHXecTUuHFANf4dQHw9ii9RgLL48DOTu3z+caQHetsrfzlfbh2+n1pJpA== 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=Erk8uyaJedaiNiUmPnCRWPE/PXYm9GKIR7KkBe5beww=; b=CKF35W8y7CpvNjUeCfgCdBKb1KN5xCGitHYWv7vPYvgjVU0/Di/CwKwElhibo+vH3IlAwa4GpLA1JPAMPUVXjebimiyaoWPRiHKG2vsF7117AVpCYjXQE2C9wET8S/VYE/qo9DWi+joV17yPMFouKGRf2Npt3r1TJrQjm9J2OH95lL4r3g6EXRC27n0l2iMCw8G6/KCP7Y7/4u6EbDtrF3INBN1YDCdjF/aBXh/4Yo2LT7YLOS4mJZVAt1tzoCSs+KSB05BQmUznLY6EQUxUOzKipLdPBVtX0Z+N1mXy5lPEDhPeg/c1KFAnEiWfxh0bgoKk8axZScDUcpLxe1T1dg== 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=Erk8uyaJedaiNiUmPnCRWPE/PXYm9GKIR7KkBe5beww=; b=BTNQ2e1SpVUPOZlDJGZFFr9vIx/MnrtFTx9MTdZvxXuoQn2mAKzXm3nPmUwgIKKSB1w661x5wX2MQOw3qKdQzZw0y87G4iCUojr116v5RTEjz+AV9LV6koL2jtMR4hU0hewXup0heboYv0reW0ooH/ygJHH68rpGtumrBJrnod4S4BlrOQO/SS7fq36mhkqA4EUFeeuII1O2n6MQ+KoQ25HTlT7mGXqokaesqweZbqlTT7MWPFJqXEFFXkaCZ5cBPm5csMN/9cA6HLfo70Ymz2BdP4hvmpH99qWm1X5Gv+kdW8DvjvYaik3uHtwotgeqH9tjmygxNi/XZW873axiuw== 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 DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 17:21:44 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%3]) with mapi id 15.20.7519.031; Tue, 30 Apr 2024 17:21:43 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum , Mostafa Saleh Subject: [PATCH v9 6/9] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Tue, 30 Apr 2024 14:21:38 -0300 Message-ID: <6-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR17CA0009.namprd17.prod.outlook.com (2603:10b6:208:15e::22) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|DM6PR12MB4172:EE_ X-MS-Office365-Filtering-Correlation-Id: 795f9bf4-a842-47ab-1268-08dc693a012f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|7416005|366007; X-Microsoft-Antispam-Message-Info: ea6goo/l0ry7WfFidEr8VxYCdnuGMEMa9GxVXIylLIu3YikaQ1UAZOrH6jAnjZV6rEkQJ4WiyRBl+aJ4ig43sLOqcjAMaYjw1CF2N57RPoKYVRfuEZSmG/lXOQhGjBJqdvHmVTFKmJvfWBxIym8aQuayDf/HkBXnzEbfcUtrwQX9EyKSusywx6wMYiKQGHczKIN550MkHQfMFDUmUHSfXBz6+BqkpMZBjj2pZa0i8re8dh2E9JQbz41r9bC9ljkZf4tF5VNDKXM73B9B9+cNDXLBG47JOydti7VAIcxaGIfcUk7dgsw7SRcB5jDBNq/kYyRQtxZN32u33yxZ2VISVii2jtPJWZ2rWbq4u2+L84Ioh/M8X40PpSZbAkCHg+atRj/DL2MSFmUVzeBRQPmwlk+rFgnBsQz4js91DY2COPesPDu8zUyJ9lPhBhjInojpqk8fgPKcWwOGfUxjKP8XVNjNV/XFLBNp5H9NJXjFewB35zIHHaxgTZQqQalIFHdkynN6sURiKhHGEsLaDfxnkOzCgvl9h8Li2Y1OZHLw4fmxiP0O6oz/3zJ/5abd7ckB0+ZIXxye1TqsLkkVmNnh5+kn5Ox3YgAU5zO62dBAeCrLUMp586iUF/D4WNupsMVE0j0YeFvbYCOJtAX6z36L1V00V37lRS5FQc2wd4cBFp5d8WqHj99iPm0FMa7xI/Bt00/SYHywoSI7pFZyJS/YQ9FW1OpMmLg1N+HgXPQxrO0SyT2wCM2ESoLjPBybDc223ZXGgHBUQw0hFZvmt+BCkAoFLGzVzEX2EjjQ7iatTF7lEOw1Q9JWlPa8YBaOuY7Z5pmUL379I5YaczfUKVEtZp7hfo0vNG8lJiP3RYcXJurEC5Tf45z4OKOqdS2mWW7G5/zY1iaxRbgAUUavWRo7ZNXKP4tfoLsGAWO9H03aDAa7/JqE0RkTx0219OGtv38EA7QAoBkf0eBF9sGJleK4fzpj/TG76DxaQaOzdHYXhtCTlJwxUGL53/z5xU4yGUjryVFvgqR/F3sWRTGgHNVyCOKoCDAZl2P9r8/zFjpp56Gh8vcTbIl5ql2Ldvbqibs7qFYwzvrZFR1rgiucZ2fZlj4zeZHBa1qac/AdGmCAkF7yUr4C9Q+3KfATvnY7EqpIvCBHTZzJc/HM2qW6vzPU3ZkOAXEH5ulKGj35d6EWRJ0Mg1ajU8rJ5QgnaCdUrxNaawCSzt+E4TbjyeWIZu9ScElLsLzW0vKU5eTZNh86bdYUVtqHaPdFiCXyfXBmycDRSFmZjZfHzisxuSJeVB07sA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(7416005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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X91VhfOk42ZQRnvb3R+skPecbAVRTCRHTUNJX1aKfI/mIxR77cC9ClO6VdVtw89zLyKpENF4cNVD3amfHMdISnISZIW6by4qMxLyrfJYSFNveefSreh+3vuuAgdE14ufTBLPKWkLIFH2YdALhYL9y/RQGFLVVxVMwMo4pmlbhD+zZfYpZDLoCMlgquL9QEhsV7S49cY9RnIdK1EaHE2WH2qXJSoYlSMC1jLZe1H0bx99wLTlmbfUPMk1kTYgXTljFd7+Czwd8WgdGsIHm8MTuE2oDkm7Gg15a+EoSJkhAynoaLrmUjUgP7hN2/XSnEuUvZ+KZ6X0/E8qdnOHkkLtReFuyZyD6z0Nxa+M42vrKJKuCUtZBCUtdi1UaHKjQWsyvvNeLBSXWwPBu0cCqSYuIjvpNm31TrmsNDzddzk1lXYHZ8o+YVxhqUJ6mNwfP3YnGaKf0KK+BsckDCr6VIPVTdl2z/W5AnrX4sMCbZ8OuyBqZrxECjLP0372dn1MbLvnY0X3de3qGTv3F29mv4mdMUImB8jLAkymm8K9PB/5jOYmLuoO3ljG+LFhipO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 795f9bf4-a842-47ab-1268-08dc693a012f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 17:21:42.9652 (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: cc9GXGC4E1BzlzaKh9jP2KKGngucn0nWHuvN6s3vm6buBRSOS6H9nAxnuMoo7FXd X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240430_102157_666764_17ED4B1B X-CRM114-Status: GOOD ( 15.84 ) 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 Avoid arm_smmu_attach_dev() having to undo the changes to the smmu_domain->devices list, acquire the cdptr earlier so we don't need to handle that error. Now there is a clear break in arm_smmu_attach_dev() where all the prep-work has been done non-disruptively and we commit to making the HW change, which cannot fail. This completes transforming arm_smmu_attach_dev() so that it does not disturb the HW if it fails. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 +++++++-------------- 1 file changed, 8 insertions(+), 16 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 7dce9cf52ee37c..d0ab49300acde9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2645,6 +2645,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_master *master; + struct arm_smmu_cd *cdptr; if (!fwspec) return -ENOENT; @@ -2673,6 +2674,12 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (ret) return ret; + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + cdptr = arm_smmu_alloc_cd_ptr(master, IOMMU_NO_PASID); + if (!cdptr) + return -ENOMEM; + } + /* * Prevent arm_smmu_share_asid() from trying to change the ASID * of either the old or new domain while we are working on it. @@ -2692,13 +2699,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: { struct arm_smmu_cd target_cd; - struct arm_smmu_cd *cdptr; - - cdptr = arm_smmu_alloc_cd_ptr(master, IOMMU_NO_PASID); - if (!cdptr) { - ret = -ENOMEM; - goto out_list_del; - } arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, @@ -2715,16 +2715,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) } arm_smmu_enable_ats(master, smmu_domain); - goto out_unlock; - -out_list_del: - spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del_init(&master->domain_head); - spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - -out_unlock: mutex_unlock(&arm_smmu_asid_lock); - return ret; + return 0; } static int arm_smmu_attach_dev_ste(struct device *dev,