From patchwork Wed Dec 6 17:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13482098 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 6B199C4167B for ; Wed, 6 Dec 2023 17:29:23 +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=oFz85q1o2CzoyoaGqeKfN8V0LuedrLeD4gtcqh1JzP0=; b=Tc7c2L0IYfR7Sp u5sxMou8Rx63mJiijjjBazczqQ0EwPGb32TXxKI1OiyeXH6W6cOAiPLcd1dWQ96br/IqXpnMCVbdx y2hc5SWaG+XQZv8q13BW69O/2kXVfiOZqBlOGdlIQJJsOHJsfSaUp06Bf/pLV7Xlhj29ViiXK0HGU dYS8CZ1bdEwWq3QmYk7G3QvVnNbr+zuaTpoYwdNkcjGeHPZOskamIB0k8ET/YLN4v8tU3eOcY3wJZ BmQ4LKdUdWHV4Qeow4NpFnYEmu4EoVLkjLuqRiGl5+8+aPKJKnWyvjQAXceKAg8YFperfjqugRPH+ GCztL7F63M0YmHmu4chw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAvha-00AtNa-1p; Wed, 06 Dec 2023 17:28:50 +0000 Received: from mail-dm6nam11on2062e.outbound.protection.outlook.com ([2a01:111:f400:7eaa::62e] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAvhV-00AtFn-2d for linux-arm-kernel@lists.infradead.org; Wed, 06 Dec 2023 17:28:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ddq0M1K42FMTw/2/VvcqkMAFcl12cYHhRAQjoT0lYfpNWNiNi6kfll16qJXKtUWOqijntuvVf1j2v4KkGIuKhnOJXfgm2H8SYSOKOeu4hPauWCTUt1CkcrOzB7cd7ChQ54XHGDZ1lXMqa/DS1zHwaJRVV0k0cWIXRX/xAlPsEw4i3POluAgG2cfMzBczt/h+UBffmYLNlxJV664BwJlI3jXVZThDsyqDAQYzx4cX1N6HXcb4Qv5g3+yOq6x8SKa6/UVvYlPu3mwywD5LYiQayMNYOH0R/mdR2jbfnO3mvw2QxmhzT0oaMrzfl73+q5LQL1FtvOA7QLbf+dZIHowMcw== 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=bq9A//P/Fz/X6TWAwXikaNRN+4cbmGhSjzDHwPANg3g=; b=DKuQuvdJYEAAoAWILpBpv2TwHGe+RNfC591HHcIAcqYYMfh/VgGNw/MHuC3q5+bUqOi2dRXMHaXv2FI/UjgDBW1a61pI5GoeFk/ksP5cUjA4CSwqcwiukiwkQ25KPzSFtE4UXtNhVHbH5Ndb7oTW3J44D6J/KL1coMjoio0HQQHdOA3ID9frZ4EGf0uFM+k+Fo0QR9x5aVUYcpgzcRrqVWy3FARlIwwterTt9vCXm7q7ZXNEsBqa6MT8qTumtxpTqA339rYLs30myumwxRAen0dzl/axEJnSQNlPVrj89uwVMxCbwQx/ETd33eGw9TqLOp7NP8NUEqL6JaJewB8tVg== 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=bq9A//P/Fz/X6TWAwXikaNRN+4cbmGhSjzDHwPANg3g=; b=PVtzJv8VJG3Jq3RxceMHbFO6wQ63+05IIpjA7+aqALaYQx5/0CgFystubo5UA0gFw5q+eKZRm+9Xqs8wZ3u97k7LS5Y8F3tQ1AoyMTYVW6OzT+iCAGctYfsxMbcDWYK9cySKzPfGrc4tux3XwtnSQHzAE1lWNXy9z/Hzq7/IUpSYamUPuHtIBTcenGJxV1YwuxwKQ8bfBCpKCe+ZWuLifLYp1t3fUzV1eeLU+8Ud0xrFVKLbyMwFOGrk1/GxfrbBLvVo5A+bt5wUQ4NU9Nsjjrg0VgsOMwClZFKrb0DntvbNuBlGJgBy6HNPix9baYvy1Vx/lcijZ2mIQVe9Y3kS3Q== 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 CY8PR12MB7364.namprd12.prod.outlook.com (2603:10b6:930:50::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.25; Wed, 6 Dec 2023 17:28:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7046.034; Wed, 6 Dec 2023 17:28:37 +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 v3 09/27] iommu/arm-smmu-v3: Allocate the CD table entry in advance Date: Wed, 6 Dec 2023 13:28:15 -0400 Message-ID: <9-v3-9083a9368a5c+23fb-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v3-9083a9368a5c+23fb-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0003.namprd15.prod.outlook.com (2603:10b6:207:17::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY8PR12MB7364:EE_ X-MS-Office365-Filtering-Correlation-Id: 4340af18-e384-46f6-c116-08dbf680c5e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GcYm2GlSrQP7MJ9nxl7SsRGgK1qU9cZfCSnXZBAKl41W4s/4b4/j1Kz5qstZJuiV8php/cAWEzhdAh1VbBiaE0XfiUewjXLbvloWaaDr5FEOKHqdmK0ckuhsiJdLwugXEoVxj/xl80pu5fWQ1JHp2cA0eJAnVwbqq556iECfd+3/QOMZBrzLKKgEXt8oRg2zpemZcgCTCxQWtt0HDHP0NJNx4Y0FLhpUjiUW34L16WrZXkF2iHmicPm1EwLLTnQVucJoCaeRh0ZscFJOub7NdvK2Me0aybPxnGdvLTjZv5A5ByPEQOOAy9HQPyCOL0uRK4ztHKhqslj9bpY4kQexLO52eXgLm0SDx24p7pPNRi3iY2kk/x7niYlFUnxoyvJBwPJMWSoYCeLTg9WvD6XLUgjhSGHKaizxSAyWSrEsM6V2/GveVdmIPOf/ocuBBbrgn2gSfd3ITf7IjZ/pC3fGD7oTan/crQaJ6g1ppIH7fne3IFzi1NwblKMHbHtDY2PSDW/h2R5bSBoniOMAQbMmViYEHh6HpcUexolE904XdjaPDsPy36i4t6wRqurgqnBYN1CcysjUpfL+knJkeW6gfX6Eazx4gDUQ88uBkKs+gnE= 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)(366004)(346002)(396003)(39860400002)(376002)(136003)(230922051799003)(64100799003)(1800799012)(451199024)(186009)(8936002)(8676002)(4326008)(2906002)(38100700002)(83380400001)(7416002)(41300700001)(36756003)(86362001)(5660300002)(6666004)(26005)(6512007)(66556008)(6486002)(478600001)(2616005)(66946007)(110136005)(54906003)(66476007)(6506007)(316002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8+fkJ0trdFO+wLYj7z7wZs4HMtFu1x2yvis9aOl5a/vBIjF13BlMQgWn/yhd3TcQ8IedyS1FETpJzCnwVaM0U4Ijagwwtn1QpBjwPBV8v788I4XWGErEKwfzRsdxKtSrUuLGFPSFzdNpn0JrYbtUM3LuhmXOy1w31lp1zpT988/0lsGFsjyqyFkx9ysHyu/5fzhGKWLeuqFuIOeO/AqAkt4i1axh4phsM8nSaETdUMHsjvzQaWNw+fgKGdvEo7lGAqyQHZKH2/aUvmq6RyagUDwn75WCF6heMfbEfzw2qW72oa8HBsf7Myjb3oelaxo8PLgTvLQHGl7+UT5X3L0B7PfNR07+fQ1hPZzqh0+8F04cqG1CHZhjHYbYCZtEP/swLhfI0keGOcC6BletcpQblh+bA+Plymxv/vMBz9KRrP99lksUxAUP1nHu+KV8ii2kTrJPRNzfgSnD1g5de0Un7A50kqi1c1yBwXO7dl/Ko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QU/1u7gUhL6TMJ5SQlxwjByT95oimUHQ5Fi7nAj X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4340af18-e384-46f6-c116-08dbf680c5e4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2023 17:28:34.1230 (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: fkXHiPBwYzOjHGDACeNKQfFQB8kBrF7GpjsRVGxt60kqWwGkW9fKQzh5PGDEPC3o X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7364 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231206_092845_914473_62B50C88 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. 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 a21589f8729176..eea561edaee908 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2596,6 +2596,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; @@ -2624,6 +2625,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. @@ -2643,13 +2650,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, @@ -2666,16 +2666,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,