From patchwork Tue Apr 23 13:14: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: 13640066 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 4870CC4345F for ; Tue, 23 Apr 2024 13:15:07 +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=ntao+1JxCy2Gw2aSm2sThED286Nx75GEdVYJK8pIUZk=; b=NVtYz54IdbLDdr FKGrPtkY+21ymRbQ6cuVqaKLlygURvqBSGfPUoU9cq19VTU/uRDEH+5GxdPCYJUlnFNM3AzxYTBSY SXoQNjbmN1MxE+oEm85bJbRlexR744lfcYco/qPNhBXQZ1+wU4s8fI3bsM6/xW43gMWCU4fSn8WFA OAmtq5JZoJSbG0/wjlK717PZbrKWiALdmD7xEAbVD+/oGc5tCTQsvMV6cJkAEtsAkokZ564BV45iN Sdl2d53m+3IwnbrxZ3ZMFuMhcCMw9KR/4ds1NcaCwUPwinNNlE+8MXH/8MHZ/cPQ27eEU8duVp/AE HRmrRWAy1MhuOder55bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzFz6-000000000gs-0mSe; Tue, 23 Apr 2024 13:14:56 +0000 Received: from mail-dm6nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2415::600] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzFyp-000000000Uj-3B4L for linux-arm-kernel@lists.infradead.org; Tue, 23 Apr 2024 13:14:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BUsyz8I7pjsnCmuG3qhuOWq1VAEa22CcQ7FR8/YBXjxD0pvXEOhedDEntTnpS8LR7DiKtk48UXioJPNqfch9NzjK99FC/F7i4oWIl/W8mIje1MRkrIYubn3lMN5kX/hawgi0lbihf8b2wvpoIXsMxfkA8pZdFyGZjHPMwk+RMSJ2YLsNC8aAHnnvJJPjoWVZPqTevQA2cF1zgYFGEe3yXjV7QiWh395seuw1hDU7rXWSNasmbHbr5u/k6mmwFKJd8Oe095mfKqAO5cw4IlVRSskjBgsiwB0oxLN7o6dXvYvSUxwYK8+K0nMA+yBlmfi/gBMFR/59d0vVRChauT12Kw== 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=HoxuEuTKO3vt7K3spL90O5PQpKLp97Iq8VUpON58p4c=; b=cU2PVMJAya8OFk3W2Ox/gm8e63KffHv6PXU3x2lptS3pge6o0+4++YWQpxd5Li+Pdj+PZ7rGCLk7fdsPY8HJjAYn2HphSqVib9IRt4tvZ3p4XiFQHWBpFkANfqVYPJZnkFLZlEiG0UbeyvV5f4RjOhlGB1k2DcyYF+QhdxTuds9aZ9MN4nMxpVSw/WygBG9UE066DdUsjVxOan9+s1tDAsREKvKMcGTB9KeugHMTLFjPMGkkbSqslfyd8rc7bF323v5ZvrFE5rfDuCa7/cbsnru/Oj5Xw0PDn+roABTMSa+kjAhOm4s9tol8kfuWmf40CnUcEZWfYAS/rvIhje3XKg== 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=HoxuEuTKO3vt7K3spL90O5PQpKLp97Iq8VUpON58p4c=; b=DRo07vM7J/e3x+nmK5CzPOP7to3feShS4IWwwJRtzIqNwWXganyQajV3kyAJ11In+LxGxB79yePdhm4VlSs/Cq31eMmGIxLZHc1t7geukKpVZknvAEToCnwYhiAvfdPfFzeJG8yWpv5YIgW+xg5I8jZ9AqSgwOFSYZvctUEaTGpReaS8fESXXLavO2qbKBNtIS3T0SxAgRQX3I51dWwBV0jf92E8jgM2VmN/yJHFpTcCSTohEKqKwkK5Ji3FfS8rNiS/DVkew0r7Rhkoao42BYK0DQyU5wo27O3Gn/e+tYytAZSgq+tIf+p9NXoX2VYD9og+7YHMyFVDdeTlDXDWaA== 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 SA1PR12MB5672.namprd12.prod.outlook.com (2603:10b6:806:23c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Tue, 23 Apr 2024 13:14:22 +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.021; Tue, 23 Apr 2024 13:14:21 +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, Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v8 6/9] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Tue, 23 Apr 2024 10:14:11 -0300 Message-ID: <6-v8-4c4298c63951+13484-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v8-4c4298c63951+13484-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0381.namprd13.prod.outlook.com (2603:10b6:208:2c0::26) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB5672:EE_ X-MS-Office365-Filtering-Correlation-Id: d60c8f3d-b827-47ef-694b-08dc639746ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/M4VwajGzlsq2B0plVqLrcrFt4+7ykzy0dwQz/QI99g1iHnViPcV/lAXLBNAY1eOmFtmMFtjalzj+eP0++BPsFoZgqZrVhejXXdB6miDZYXk5lkX2+CKIX6adzajlHz2I/cjMH3Qm7B0VTZKAN3UUpH8gA7O6LKxLMpYbRYr3vQVN29L/tq1orvfWqI+hOFh97NF4+/6kUx6bwGljBYBJRxKyZnSoOrGupD3rLfFDk2KDodCXt15stvsohtn9aD5AsEWTyGI8snoTrWjyx+HwqdDH3ur+xTPW77G9QV1Ap27hdWo03ybP/l3QxmF0R1iR5l5tJh6ie1ckrplTXUTDvJnNI3BYAKHAzV2J0M03VtXmeq1OyXEo+uRnyXKnmk5J4l9jcm4yd4ouGGb9diUVvSDy7EXaPPbWB8fGZbDljGwMvIUEI3beNgQpq6SR+eFG81JZhbTSHvsf0Z8lrN1OOTcbiNe9/ocprY5WUTyPU2n/R8DlNqWpOC5A5phM6gOyXFvTaXyEOIV/JSqxtDlV6MnRmIm+pdp+46T1yLpT07ZI0Nz5zxUiSRDMjERL3rP5Z3K/UjEvIXH3e35n6J3q3OQSy46ENfDzTSsPr1O3Sp9DYhVkii2I4uDR3UDvW1S8DG+NBi+iCcs221yZLA90rQH7ae2lPbDynGX2JR8Mtbcy40+Gx3z2c7Q54lseuGE2mg5uTUbT8DXYXCV50mJYFohN1+3Hcldof1tif7QaOJ2lZFpLKMYhVNpc9kXs3h2zGFesevaTUAJeuG8kv5fOOpi8ZsimLn1geKqBBmKaHu7LHMW+e7zxtd71/YnAOow8rCv2FaTGsj8YD+xY5f+2XHVyQrAmit6Eu93Jnh0DhPEVUexZ0HyH7kfVZkjb1ZT1TshWD8WoWX+hQLkVUjepipms4TYE2XRtHijp+SDbsCiDUhJQlJHvJ09WY5ULKgrRfjkzU4x5hO+UmV1QVbtx2T1mKClZ2ZbBbvJItAJuULqvvKRyurZatiaQntb4DiANkpMMWBBZWpjueQKXqBckLwm5U/aSDWc+5crueiS37Snz2iSms+9IroCM1HSHRMnrJo+nnYD5cacAIIgCpMT7StrJGWlOQdbxAjO0SThuvS+WZtLcwrVjAIkfHbyB3RN2g7TNxmqHAobdbkpkorGTMhPF9MiMhknQgqaGDitUGKOKumacQqEaWQywaPt68vsWvMXbx9kWTse3DzaEV5ZFEi1Jiqz0XuD8+Ccs1VcWzQdHLrPK9Kqp8QyRh2NjQaZuJJXhaITFQbFtPD7rWuoA== 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)(366007)(376005)(1800799015)(7416005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KtOG3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qXpZ0dXvqhSs9vo1QQdIhrlPKUFjUdNJ+MyEPmscj6G3bc65CaGT/dgyNi+rPg4Y6wl7JDMrYZguey611pKHoT4JZrZ7+q43oZbFjK+aXN7SEvSyD8uncehY2Thzg6d2yRUpOR8/RZCuktgt+88uz/hxwmUC1cIWe6+Gp9EM3MxjgwLk7nzeUOtSIyMUkQGWi1hF7LMJMxiTF2gZeYei+jtiOltDAvpRrSGLpgIAR5m23gxII71z6HxbW30y/AkiOv7a1NygHkNteT7HQVs/Zcf68flbcbtnUawqF0dwTTsKOvH90+mxCuDfPItJ9BsWiQOfKh6IoTbAaC9AOpKX9ZVNE0QAGpzW0okYv6KezSUiPUagRR38rch5bNtspsibz1EvlIA9eNdkUxpoH3G0uUNVfUnDGzp7XlH90Rq0iO3D6GkGCc65mMEUuIh3Hhu+oTWAFRddztPBbE0xNZiOSKuORHO7iZnAeZW5lploIcftOkqYUBxs7sZiS/D2Mk6B2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d60c8f3d-b827-47ef-694b-08dc639746ab X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2024 13:14:15.7659 (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: jpGIvvevUIuogj2N0CPLQeomNiwd1O58AZ06e8HSENBuPW5b5vrsv69537MQ3VJS X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5672 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240423_061439_905780_B59280B8 X-CRM114-Status: GOOD ( 15.34 ) 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 e8da2f7763d102..3039b01e3fbe6b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2647,6 +2647,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; @@ -2675,6 +2676,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. @@ -2694,13 +2701,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, @@ -2717,16 +2717,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,