From patchwork Tue Apr 16 19:28:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13632430 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 EAC9FC4345F for ; Tue, 16 Apr 2024 19:29:15 +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=TvTdnyl68bprYes554o9eyhlRP1pPp9B193uqUy4Z3Y=; b=eGuVQEJFCDBKOS rrATZywJRFxOfclGO/UBwFf2F7OlXuxGx2eDbDayfNF6yJ8D0EVEou4/HF6YfC1LZnL4dR3sWrPVJ MMVpUefluevmBOwym/NgyeTrBHPbftJpBRIsemPPSwql5LOvTvt+plRsxyRNORprdVr6jxaHFuV1I irEqvgbcDGuyCy+87SNQdXoQFJvK8o8tbZzM1QZ8psQrIpk4yA0bFD1C6IK80yd+y1VgXFvmEC4d3 cPYNvYYLGQfOIXlb808pylGAbVk1z6QEJ8BWv1UDb0B7bzLlTB8/t99Bujl3hyUtt22O92pNWtjcs fFiWWF8huI9BZC7mps+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwoUM-0000000DXYO-0Ybe; Tue, 16 Apr 2024 19:29:06 +0000 Received: from mail-mw2nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:240a::601] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwoUE-0000000DXR2-0WZ6 for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2024 19:29:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gng72XtWHkxhn4JWHlws/9Av3sPLuMvyRArPVwalE14afSwma4spLCHzM8DnW2iMiCXUwNpV+NFmm2ukT/Jtox+3psxBfuFlB0WVjbnq2ZqV6jO2C1aKWKYoB8/RpoyG/bqKGsgRsa5QnTMjVcp7hrur0higUIovMd+Qq0zwoAeCB/0uESGXjl7WGxyAyEmFUtVC2+J9kTxyIPEi91PhWMmjgX7mErs+vES8/lm7SNNbJjls3rnceuGigmcXBdA11cVtHK/tF4ijohQ28HCJXMlO/TcNeSY61p3i5MW2yaFFXXaTHc0KxD29aOZrjAhzPlX4oKvdjQKpE8wz2BzvfA== 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=MGJWq/IwWubTSvQESDQ2LoocBJQ+Q/Eg0VdRZOpSZ8g=; b=cEp5h+4mKdW41eMHJGcTpFu6zJLrDYW3QhJFdhYgNzXova5QXSvARU+5WMviSqugXiUU2KHUNL04cqzPt6DVJ6W7l7q8d2VCgKv7/ag+7Sjmn2LdtOVneLYoJRuKKpgHan1bcyQCjphAO2QlhKSwz/s3IKxj7kkwtQMNMptIZdomKyIWiTxCkk2MC+pogzTCIDEFQksWyiVF8fjXLHb32NFOG1K76vTgUJU1D7cLdHHpwtFgEhsUEELUaa4wHYl/wW0f5xMqzb22U4zKM4mtgEXGl4FsBYzVHQnpvpUmLGfQZA4Mmrs22mLsSY9YmQ37gYDFdvkZHTuJ95miiT237g== 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=MGJWq/IwWubTSvQESDQ2LoocBJQ+Q/Eg0VdRZOpSZ8g=; b=hikEl3l3LE0OciBT9BmfzmWejI6DSLqbODAFBkDDoVrrssGDxyyYBB4ceTtDX7mdF74S11Lp91qNE7rwkVD6ijaBnL6TynetE6aBb3OCoZ+wOwfWEWY4seethFnLqVWLCPEWR9JTxgEoUFvF38GKkvHkbcCktqNiW6P6Fko7mbEPrvYSSsEG4EhQ+r8h9Uei/BqmqIxqmUXqs24ixP35k3BX05/WPdunvQMy4mCy2T6mTdW3QEEr0RvHatWdZlsORohYZ6DFXNfVqAlJhXXI1EJAYW2d0n9t2z5/Co1nCSUBsKywR+OTb8U0NYQcKJTnFsKEkTskmu683Bwy+K/8pg== 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 CY8PR12MB8213.namprd12.prod.outlook.com (2603:10b6:930:71::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:28:23 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::6aec:dbca:a593:a222]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::6aec:dbca:a593:a222%5]) with mapi id 15.20.7452.049; Tue, 16 Apr 2024 19:28:23 +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 v7 6/9] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Tue, 16 Apr 2024 16:28:17 -0300 Message-ID: <6-v7-cb149db3a320+3b5-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v7-cb149db3a320+3b5-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN6PR01CA0004.prod.exchangelabs.com (2603:10b6:805:b6::17) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|CY8PR12MB8213:EE_ X-MS-Office365-Filtering-Correlation-Id: ce4d2837-2eef-40cb-271b-08dc5e4b6070 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: scfsq3rf5sZtTM6uj0KT6/5QNQDqCB+IFBu96USFwFzz59nv5QSUiDK0A6H7wWjQZv6FCdsxhh6pMKPdmA0af8Z/ZoUIka5OVXtNmlfKW4FGYlc2jfNfspCMSQQHO/B5u+r4rJmq/aiZkaAo1rVI8AhHgCAIcOXE3bVF4Kug563zKLo9uX+CQG+ngY4/m8RvGrc/ISMZw/1vQxqQyqHqAMNQUz+QnYTCXXnF4YWrNtRDmZUgsBjTKp0u3hyauYvgQNLHNDVIr0YXlC5671UY+8YXfshqzqlCAlP5oxqZstDqA44jN3jYYDy+aWdxA7jaYIE6PVCQ1B2YMbS0eJWZmabMWFN5E9ce7mI3fqk8F3/HDQLE7SlNvPITsmJH498of+DdS2hUw6wmM0+m5oyzEQ3VRGcASmHQ1rUXqB2AlUJY/3I95siOf4GBol6GZvy0RqR5Ybl4/Hj4TcJMYHx2evy2FVVrwU3MwpbF9zQoyqPueiuEL1aJ/nYG/FTUiS2mnvEpvU3Q7V0wC3oPe8H4sM3cDE9KVh4JAbNzQlZE/jxXhcm8vLF73FxnOSEbbRHzb5e7Yi+NCICYenNoyGqPwU5XrBPChOiS83TMPhJoiSNrtSlRECRGLq2deE5Oe+310IHeoDdz38UI4visar5+NDsUdC82M05qTeDOCDh/xN4= 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)(1800799015)(376005)(7416005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g3ONQZFpyXDGQ9Ckptiv1E2Eg+r5N9yrF+mSCVL4kbyfGT75O9qEGVHsFEo1qBeSlS7h4gcxr8LIVJwxtTD7Xz2FA6VJZs2/YF8MTFM9MR7fbXpQgSR9MuHwxEeVmh6rjJu+WFJRR3vk/TV47CYG/yRDPq63eLXP+At7AZ5vcAQ6sUASYnzF2HzuEDZ+p71GlAReGwTHQCLz3juRsJDEpkdQ/wVfFQzRNf4pdovO4wBXWIhapjJ+6lckgs8/qYsuJejHqY6l1fF7pS95BrZ9GS47MRac9OeDHq9qLgMBlmqfiN8LhBm5GEp7xt15zzkpeUot9ciquTRF27EWjjGLZDjAVd4eYaith+A55Ih9ImFWzkSKz9OTYtKmKzhdgdNE+ug9M0QNie46ujDEwntsqcDAlOvpecxu37xIaGxpgpHrUYmX90R4B6uNK1rKytudfBQ4tnoMdz6qfnmqUrzYRDWjw2wUy6kbo70yKAUvJr7R0P0xCcCENBwXXe4UFIE/AZed8mATkzBXy+YfUi34iggtG1rm04eFZm1NdOc884kZseOL65UvOY7XSKvu6lcgJ32nNFGZ20ztgkth3SXRp/RaaDDoC63WaSA2NGCpV9sdxNAMEnMnnpMUy3oTM+d1fAQiF3P8oJjurktoW08EYyG3KesY4RqCCo4YiuSfjFxghFLaDzcfy8IRY0GflqYknGbgr8FTJfM8ePGIZdQNFGT3tni1JPV5BG4nAxiTkRMC97umMUGb7MBSYtsMf0tMWB16XaFDS9AycOckxc+t6QTZgaRx9ZZsPrBB2Vat765/Qt3yIXztmltESU59kZSktHh9L3tFgv10qZ39hhu6lvs3PdFB034LEaxar31bAjiWBkF0r35poCXl/XfAdKWUEMJJWQDbmaLGy3937bhOfIKNJIVkUjGaupE/RrAxAk1HVW4JQeWnnSdddiYofEfzZ6gQWlpO9E7DgHxC94vI4HEbKuDul+gwn2OG+MLlmKEMtRWEs1x70y2OdxnN4aWUmP73IDKG8ekxUu9prZfG9p6Q6AeSVMpztb2UQPw4ak5MDx2CzhZyuxQ3OZLiwPA3fRzi+m1ptb1T5NIAelm5PohHT0+KfBw+71G2URTmV2A0ynknLNAF/T3srhmdnh+bTSOkpb7LDOLpPFBwPx74fqRoZ1rrJAycZMqszBUzb1lrPb1J8zYhZo2M+M0OHkhyyrqi/Ie6v07BMaW2mc/bJnO2zwm2+uELBc3oB/aJ8ESZKrFPn6s8ePOkfW5JwzPLtPaaRzMMmILb9oOGdozRbl9VzCK9XtjlFIxTWrfGt7eWnkZIpiqw7IaIdAJKpw8XK2cVD0TQzsvBS4LxMP8gnHq9ZwSE2pU9nojlAukoc6hs/hu7G4CzwlzebvVlD1sJIP/efQ8nnrtSb+ZyNIT0yytJ1sooLGagt6nnQt3FackA7OiGEE8p+iT54xhqLrrBcNCbYjeg57IPpsuIsTWzT8nA20tcJIATFmwIqxhk52hlPOHlxUmaNSTLEPyAK9HakTjqshcQHk5xnBAJmRYyblQyMviyx5o1yl8RwlvYbKC6/I/YnhmosLY8pqYAP/1x X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce4d2837-2eef-40cb-271b-08dc5e4b6070 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:28:22.1190 (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: UjOMe/MZDUDQymC3cGougwnuNLWLCRNDSONdTtVzE+SjmE28twa1OH3X2txw74TN X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8213 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240416_122858_198166_4CE63423 X-CRM114-Status: GOOD ( 15.48 ) 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 a0d1237272936f..0aacd95f34a479 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2661,6 +2661,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; @@ -2689,6 +2690,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. @@ -2708,13 +2715,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, @@ -2731,16 +2731,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,