From patchwork Fri Jan 26 18:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13533109 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 C7E02C47DDF for ; Fri, 26 Jan 2024 18:16:31 +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=lqXJwUnoDOx3eamrpk09Qbyz2My9AQza5R2gXkRe1mQ=; b=2stWLn5q4r/Hlg 5eNb9JiJ3vYpy3vraBiP2Q9ZjOl0Osl2UJ1J2/5R+kRszn5JQsQtGPdXr9Dp0gqMpSTwzB5jwHB0u W7FUi4u5+FIOMl08jOWABdB6+1J1vT443rfq5gbWVsGGuufUF5V/1ecTaWtid+VcxFPGQKI+AvQsJ UGK2SggClt5PJbc9RYmSeZEf3ggCAcTx4dhz8WkgW1vOyukxww2+Xejy3deIeWkqbw7RQeiyLdjwl egolqhxsZxtutSGXoBOd3Ufik0gocYTw4BMH9TUAHhvVBPCL/pPejT+6OKsAW0my+Qfq7rAfz2qEZ dPBBIg+yVMCMXiXa23SA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQkT-000000051u9-03ah; Fri, 26 Jan 2024 18:16:17 +0000 Received: from mail-bn1nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2407::601] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQk0-000000051Wx-148K for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 18:15:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iUER1WAgnNclg933HEkL9ND7TeoXx8r6SYGoN2cNrXEwVb2dH7mxJdJecltQJJpnFtNqO+oBZy3CBSv/n3UqqIwpz6iTgLm5B5Sz7J92DPG5AHFb1bwZAZbjdme6ML3fU1b6MKgFSikGVXoSSVINUM3q/8Wi1UWPkkAaI90+hMTmUp0S8c4TRzNVGVByKBf/Qiu08lB38eH4tGpOHBmjVI0t40t+bj7zoAi8ZkLsByap9CEPqV8e43FGodL9mbuZq07AQCNBfM6yoWfIf3qDngwR6mSNw4r+MGaZyMDsWFTrzyQD+ilJBPZeqK5JFcOtZisJdJSYg7RmbYYPpfpAzw== 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=RLQBkKl46ZXDARLc2F56yqEqk2Pe6CvmAAh+XAZwv+8=; b=Hm6Z0E6inNe4vWn9AsSwX0STqA2r3X3ThQkRo/n3qIRwqHURFshemMlwu5upEJObHK8DsdeA0ynWxaKPBtQAg06ahS+PHrkYGRXNS2aEU96bySxdQho7vyyVkkbR7uqAKidoGiDfDZejJi88TGemL1WgC4DGEnLkwD6jXMqXQswJBhafqNFfYDe5zo+rTLxwLZK+HGNnekXBx3UnjuyB01TAj06C1Iaq9s0SG6YItHw6v65XewRy2h1JrYvdmmLhSB/mnMdMEUOUcX8XpzLukM65zOh5Z6MB65KK6jgB+ZgCFzNtG1yl1qlWi+W0Wwl8dHq7N55/iZkkzLRAZm6E7A== 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=RLQBkKl46ZXDARLc2F56yqEqk2Pe6CvmAAh+XAZwv+8=; b=e08WORlO7ht/olTtUMR/BN+t34OgaZTgjhn7lBydUyukemmxebeqki4ge4S/mlqM6MbUPr7lcGeV5C/ch7s9bYzQ80aHiDsIbVtWReZcVbaI81pUJZ5ydt0TuBXJXXIm6pJFETe7oQpltfk5DMYtCx572zAgOvSSNhtmkYIY/3w8eLKS5e0pCee4L0FmYhcQ4+p9pHuw6N+YIhiDlOaNiqnE2FJSAPGfN7jje9v7OZLvh9psSjgUdXaTdBaUzUqxIOQagRp+brmOdujNU8h8LJa7ysNXvIwOTdqY72wQ1Lky42FyolOktJlXTsJ9ZrEiHjpSzRj0r6NLa8lsTo2gzw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CH0PR12MB5186.namprd12.prod.outlook.com (2603:10b6:610:b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.28; Fri, 26 Jan 2024 18:15:41 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 18:15:40 +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 , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v4 09/27] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Fri, 26 Jan 2024 14:15:11 -0400 Message-ID: <9-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN7PR04CA0231.namprd04.prod.outlook.com (2603:10b6:806:127::26) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5186:EE_ X-MS-Office365-Filtering-Correlation-Id: e00e0a14-24ae-465f-1a6a-08dc1e9ac94d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qDa65HyG8KwKpwMpch5H/17LkZ8+JxDvA1bMHmiwKk9pjDkSjfkL/A4KdJ3uXd/RNSJWtU6hpjDxR8F2+GWSMQl2GGGwD/D5ZCMf7hRT6ZIhP3dSXOg9iO86lBCC70n4Mfi8WcnyIxlRB90MZOj9JrPcUiKw448zPVvWDRbItMQmCq5cyNRONNFeD9XlLycoeeihzU2RGeo576oyJTVBaiiOp76B56EJM8O8fVXSMhHr+0A99v3yEwqqfPc2DnC5siZGhuJIWsI1JBwkTHgRociZI7ReVCJCcX4PfR1tNM+ufO/Tj2EGa7MeutIXDrFbwRRdFgEozqjKZL45+s/LEntyW9Hszh7YdsOFXvEaicft4HKuRXrvt9KZmg4WbfU3mAOMJ626g35/3PkYnV2U+a18vZbxW7XRHgOZ4TsCianzZejZWYAPaO1ewxxAfOj+GLDlFi6+/CGwKmASl8rgFBOBpGcbhRb4mICLy7LKcZeSDJiZq5bW8YA8/Q4mBkz/Pdw5PADi1vQY3OHyfYOfGDi6v5FYRZ0fEwH36BcrBZ0PFWLFsT2sgvl+Bu0iexBtbY25DpEyk+RRQWsr9dF4/yWsYez1YLTYXjOoL+Cw/M8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(136003)(346002)(366004)(396003)(376002)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(83380400001)(36756003)(86362001)(8936002)(8676002)(4326008)(5660300002)(26005)(2616005)(38100700002)(316002)(66946007)(54906003)(110136005)(66556008)(2906002)(7416002)(41300700001)(6506007)(66476007)(6512007)(6486002)(6666004)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fFj3ob7TG3Q+so92MCCcruv21B3QTDM5TCLNbQkbGho+SyQ83ZPwxXkk3qAv/R4Ivj230lkVUC67NXDZZGDXzLgViHY2Vh80PJBg4V6g0IV23LG+f1GS5VUHc4vC1GpWNl+QDYR0SNs2kgL71tdu/+x4N7ZtPJ2i/Nhiyvwt2rFPiZ6xG9x7KoYw7mTCm93tkwlszacJz+4u1kMHB3Vg7gSZw5ItuOeORLauldY615bb/t2DXFhnPppnAnfoV62eM1azN+uZfdYN3pmpZVxVr3pECAIkhp8b6tTNQI+FnGjkNkmlXy2t6noNNmpTepwBmsW9RmhvmWKFFZtDCG7F8UXXmGA2rF9xb11GJp9V7uMTZ1ly8NzmKoQC1l65JMCBHAYfYjg3jCj+c2WM5OsUNoxVXRrULchc1VYaBhw+KLJMZPq/dMhgrecOZHv+Wsg0vl8HFzaKcupyUiOwn+ccbrxftZ7N8indQzJdmS/NbDoMaQJoto3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D38HSkc7R1tbuZMKZuCewuY384mA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00e0a14-24ae-465f-1a6a-08dc1e9ac94d X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:15:33.1959 (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: Q83rBDFbpO4WlcknuYdw2+mtxKzs6xiPJfCZj/lcl6pbP4TLFGlMmz4EGJxNEJ1C X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5186 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240126_101548_376911_472FC111 X-CRM114-Status: GOOD ( 16.06 ) 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. 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 7562d7577f3940..79d80de4c0a60f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2665,6 +2665,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; @@ -2693,6 +2694,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_get_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. @@ -2712,13 +2719,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_get_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, @@ -2735,16 +2735,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,