From patchwork Mon Mar 4 23:43:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13581356 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 5C986C48BF6 for ; Mon, 4 Mar 2024 23:44:46 +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=feojwrQE8o+xtYblvGVVaTTLPCWSRPJPeqM3fBZwSAM=; b=nS4E5rhn0lcsbR I4Sqf5anokX8kJVTjgeVGMrNtV2PBnLcvoadxk1uLElCnFmjG//1lOJsTJVI7TgQncTa/NHujLld8 nsdga9CtWBIIxE1hJH9hkd1pHR29AVCp7zoSIms67R3DXvprcz7Ti95ck3oKvw3G638lsSuQnAk+x +cI0xHqrzgMuA+BXg4UfUAGWcy7yiUoCEpwLsZQWdezn+fmKe2DtrXEr6EU/p3ZjNHp/yPoYStSTp ChfTCXBPzTVf19CiEEEyWMV2bamDHeuDJu23WkqDYFIUW9jBsD80rv7zR3x/t3cJL7UMg1xs9mGar LnjaXgctPrKQIn0LxNnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhHyz-0000000B7Fx-0lw0; Mon, 04 Mar 2024 23:44:33 +0000 Received: from mail-mw2nam10on20601.outbound.protection.outlook.com ([2a01:111:f403:2412::601] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhHys-0000000B7Au-39W4 for linux-arm-kernel@lists.infradead.org; Mon, 04 Mar 2024 23:44:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bzAuMVYkdxsIrdBJ9FhTC+W0u63CfNvGwQfv2GAzrarX0V5ByQTAiu7dMAJ6KsYgEATcaDhPeqUTbEWk6Vv5G7I5YNOSPksz/eGFIf5XuyAlvMNY1BA3yS8/k7w/hQxrwCkgg49n6o46mzTStfbxyy5EQsT0qYHxhEkMbinsO4zVcyrEfXW7Y/DtvrKaLBnzS+hxKfRZd7ZvQRUqpbDG6sswGiLUyXAkvEZ+bxce+iWm2WVSeF/dUUXDB7i1uh1TIMOgj4EHSzOoXyagigNo9RR9KbMfZj3vvsUoDa3hadI3DmESoGOW1e1kN5VPxOqAl90U9/eJseqKzsSHoVm8/A== 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=4xKMsGXPP/UBPr/p2eAUG+hBUTxWrVhs7BRkuEQLQOA=; b=RnNwlCtxiD8N/K+u+pO3fGifgTI1GSoiS37ruyOnnkeDvG/3jvV3d9Z6X608MLj4EdgJWj87Lsj2kkfp/70r2TwI35UfJn19tKXzuTKXMd4orsk7DSpVNJqmhMaoGbu5Jr3Trwv6oev9Hq2bwcyVuqKUFrOiepNAGWi3YM+ylnxdyfiextipT3iOJ7fXEC1jSU6zb/nNyIr0kCz+mAQ41FHe7BwDK3Q/SBjUnE3xGnf/R39fGmThw27v7iOJl5RhkBUiLVoJ2Lg4te4Xp/cM2Ci0kbQ/RklIEKs1ybMBpsV8drwITmoOYnOEVTGQzXGqVMHfctKRO0freZ96H38HeA== 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=4xKMsGXPP/UBPr/p2eAUG+hBUTxWrVhs7BRkuEQLQOA=; b=Np5JV7meF1x1HgAFcwOJ7V6Vitf+V6xFr5BvagRQvJD0qVuMexyiNT16IEUn+jUfKq0tdQ1Cv5r+sXI81ynJaqWwHOX/QDEGAsLDRM5Jcvd6wtzCa6CAzLNFTvhGb5bnBQyqoxqZAbLdGjl39D/s76m2a2F0tNO0pWP41goL7ShdGm/w+0vX0avYmLZizI6gnYgEqOEOHZoFYuN1BZnTeAwd9YRH0kCkvqyA7H32iuGWAO2/vsYvweGELYB5Bnq1FLNsy6AcffFT6LbBq6Ezzzstfm37Zna7X9ZqtEfRnEBliw+tMlsNtRSuzzr7SHwdo46tjwgIMvkAYIbZUA2lXg== 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 MW6PR12MB8949.namprd12.prod.outlook.com (2603:10b6:303:248::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 23:44:17 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3%5]) with mapi id 15.20.7339.035; Mon, 4 Mar 2024 23:44:17 +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 v5 09/27] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Mon, 4 Mar 2024 19:43:57 -0400 Message-ID: <9-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00013E06.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:7) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MW6PR12MB8949:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e0c4466-9db4-4818-2be4-08dc3ca500c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ng3V8o3oojDbulpJJa6yliT1cX3YOmEOtAZJ9eo9zGdNKSgc4QwVYuXl0AMf5oPBKnYv52ikzYB/yQjn4Z6RzIGwTDf/hCMtYFM7UcfWKEv8D7T5fT84Tx4znT9PBtBwSNRoznxCMoYmZA++f0t1shSYoZ7Zss4EpzUe+Eb3XpdNLjyd4IhLcmTGHMXBvlfRMqo7DZa26WbM3ZpqZsxnsBeU+s/qrf+j2Ievd1mVVvXfNl3uhCFg5l2uFT6OHqhnHawGrgAnF7+3hLDHL+LcSmTKyhMzLyBb6eT0rwjiZtlfAvtZ772UUs5p4ZiMo0h0KnB7LSSVuzfnzbSB2ZJsE+asUzoJD/VE3h1p8gynS9/dVWUDbejHXg6tFiMUGKGJ/ASkzWb9qd/vlz2wfpHOZeE6NpU9/uYTAIjpVQwLJxRDsnN7VLq7PcY7MiBWpFdyh++Ve3QjJbnb/GL69ezKz3rXNEBVAe/3A6S0LROSqcedlw7dhm3iR8xNB0uZIS4sD6uULYbOOWZwiyCOrpFWHzwr/QYvy9GoOSZ1vgvkprzjphBQur6hzAKBZ5DeyL6x7ptWlo3s0jCb3Gd1feZP4unlODiSWY8vmE1ElTVjprLt7ctaKnn1P68OXq0pxanNAdqk4evOsv5ozLXst3h3yppw+fwlW3GXgQCeh/ba7VU= 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)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wTFcs1BukMKqUvxeS4u5f2T1NOjatjKj++TGEY75wtSCWlda5vSiLiuDU3ZQ8lPnxglA6tQvk+5QsZ4qfzkt0UkdsrKl4HdwAnjYeQo0oun5NamEmd6rsbdaLO7UZ5zOr0TVDDXQECCqZ/7cw1jYeY8scxIUbcWvMLdl2YWB9boOsX6GLOwoL2qs87WleZsh4Diuc8AoGoSrghr+6dWcjIM/HfHpMgYcD2RPNJOIHpoD3uZ3fQCSmdm3k4TWwIBMp8mln+mBd2dmelr6HU2uWLrdP9CWRaI8wFNTHxOetf/VUsX/YXuptX0A4PUp14T+1wA71YRnPGWjR2ExcZ3hZ7zJeujEHikcNWsPBEDFqt2nZN+c90ORVHAYp9TEx3fa/ZP+VwA5GS3KacGJYY4dmI75eTbA4+d8dpTnEOc4+PCf98XuEAEQXpTgSwZ0obGbSn3n8AUMGnP7MJQyagcuqsz1pycGmtpr+yuGqIshBPVeOYbHBrfdatqB75ixD5brrnz7kw3sGSuxTMxyC4gN0z4VfxMH4OeqABlIV8PR+tlc3WlPDcU69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-Network-Message-Id: 3e0c4466-9db4-4818-2be4-08dc3ca500c4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 23:44:16.0959 (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: 5aHTkWGuq9Zv1qKFvOGo1Ib+mBZZvLsHcGhVzqlNzUknLGrJpUZjarGEGHX6EUQj X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8949 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240304_154426_818680_E3BA2655 X-CRM114-Status: GOOD ( 16.33 ) 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh --- 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 2dd6cb17112e98..39081d828a2132 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2676,6 +2676,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; @@ -2704,6 +2705,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. @@ -2723,13 +2730,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, @@ -2746,16 +2746,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,