From patchwork Wed May 8 18:57: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: 13659062 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 C97E4C04FFE for ; Wed, 8 May 2024 18:57:53 +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=aBTL+A06eZRZ4/VOMDwlL7/b3YrlE67KnbCDWiPPRSY=; b=1C0qGrOO8cAXGC tYT9LiWKDA5k1d4pBbV176VHhPxW+GI24E7Y5XJiFy2i4oHb0bIBFgvqVoUTUkSq7/v24I4E3eR5b uZ8YsHSqosrZEEj23o8jLrz2v5OLgt/rgpfUWMSMZQqrUDrcCiFvPxqYAt7GYa4QYPSIv/XkBQVOl 1QcRfLiYvxoy9K00+lPHu2v6VVRH973t/mYQj41HDSUWsvzvua8/MmRnFZw/ZWzhQh3b6P3LgWLSX sShQIuQX+JdH3ZUNS1a2vjd2vWBeBhodOhwaajdZ7br4CoAilpk9s6GB8IAzlQInoKSaOszmNWjX9 u8ti7y0/Jj3UGQyt9DAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4mU0-0000000Gc8z-1aaf; Wed, 08 May 2024 18:57:40 +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 1s4mTt-0000000Gc5t-2T05 for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 18:57:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bUgQDJAWDCsj1o9lBUUADb1Fwglf2kBZ5qBb4GLJHpWD9OsVbkxmPJE/bBVAIXC+jSfWUCQYnVUW3/mG1xvjdvJkqte9wc+jNVQ4X4h8zh02+ni2JrKGh2myG99AMUzGNo2Rm5zNhnOlmjF+GAl/7v6HW3jJEJNC7+GPFR2/4uOFC170MUApcqlQSEaZQ3F1cHLqklniEEb0Nowgf7Ruabe/1gG8qrqrc2knctgNrclpoDX4BTfVNCiNA0eJVAD4WYwJqiDLYW2fIzk/AW3X68cdRngWaAmq5OiuET+dEMBsZax3IFqV2Ccz655sxSDcPPxV2VyGRwjDx8xPoBKQHw== 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=2eFo+6WoFpIg+epk1sHwLf15bM46gwJfBKn6cttP35g=; b=kNDkSeW0r4ilPYJtWvpYcdRreRNINYh1MzybneEN1ZHcaBdYXI53Uf2MyDefmguiF3zuSFLR3Lm4dR8sXv8Iy9g9nR8m4yYLOjnZ9FxuKLdrqW59/MIh9Z2ToVr15B46DuEB3xvaEc3VsSAYOFVnmk0kvs/c9Qn9N2ynJepdW2OgYLpjoOa4umwDPSbFs7BBpHOkGYQM3a8CE8DsaW07aby4ZKwl++tOS8oLBRes8j2A6uSwZR8QdMBT6hh4Yi+38rO9bZPdtpc5w8S0DF594lz03TaXJwuYn622yNUQ684AIiWUNyPMXhSGQxYqrRb7Z+XtQ0f27BoF+UwNnR4r6Q== 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=2eFo+6WoFpIg+epk1sHwLf15bM46gwJfBKn6cttP35g=; b=WBTKpaDTSPpj5/YA3xWmiGnB1tVeIJn1rt1RLEyJVNneSDnEds4+S9Qf6J3/Lne96nJowLUE7LazwWmYB8s/vDMyq8wuaIOhPkA/3ADMOK9drl3T3st2YPlwgNoXEn+O953e4VTOHI89frATUugRs0xPeeM4aTF+hphJLaYhU8ETlERS4ujNsJFbp5oiyQTEh07vmb7q8AxUUjwYwe3tPBKKoDamx3KefovoqhJr7awMD8KYFKdkpha7k1Een5NRfDIK67m5g1kufvgaRG6V4eUXPgyT9dvDL2xBVwwrnpCwbp+sDWkjMtRA3sthG3HeoFK7KI/VKHCWwfzzVyLnuQ== 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 CY8PR12MB7514.namprd12.prod.outlook.com (2603:10b6:930:92::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.46; Wed, 8 May 2024 18:57:24 +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.7544.045; Wed, 8 May 2024 18:57:24 +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 v7 09/14] iommu/arm-smmu-v3: Keep track of arm_smmu_master_domain for SVA Date: Wed, 8 May 2024 15:57:17 -0300 Message-ID: <9-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0026.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::31) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|CY8PR12MB7514:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bde1df9-a641-4c1b-2bdf-08dc6f90b28f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|7416005|1800799015|376005; X-Microsoft-Antispam-Message-Info: 0bj2ja3dtW7ljf9I9qpeRbQ4uFyTdsNCjL+OunrtmnLkRwJURR0LxH6RToS/M3wKtrtVX5fQzYZI4gmFdwwBOKK7Te6Lf8b+nTF6Sz2vPCSsiu/yOzpLq2c2DNxsfye8ZSdBqEQNfZRdZU3RQNE5XiMk4CJ80UzGOVAsKpfjkXYaRFoy7tyN3g83OBpPXJpBh/4IUx6mcjrJ+7CJ6EEki1MUlG4t6FhZl1dSk8qsQv14eUfgoo/TTBA97oe/h5YhHWzHBuHm2TpK6EHb7j2xxsFxCG5Eo8WhDAkU1v9+1x2MaTkjLwlBHr4B00Z6UghRmIKJ4h9dlHzNJD7torwXttBQwffwNq1A/g3i+FV0ufdO73FHkg5nvMWp5gAv3FAd9ZMnEpBfXCLBnxx3nlet0xTnyjMmIs71A5PqZ0LByr4p9cF8J9eDF33gV5HmAfiUtB3CB53e4Gs2d59fcp6Xl8c/sCVaLO0FCQGf9LH8aONQ0cLGnvSrNyzTikAVXZn1gylvqhsheYo/CaLzXTgIhL1VobE6KLmuf/z3JlLm9EIDaHM4Py0WcFWJ73O1RZYo4uw8DC130EvzNFTinWWbTQW0c85UcdRgOT0isDTzmc/6RfaOsPZBy2wrNY84tn/fczfae7aWVCHj/jz6WiC/2GptTvwHriCTEmbX7PLL+4z2aLyBMOaZ2/NDx+ogfWN9/jDZi2FfEWSSJj+HugHRAWRzIPrkGSTihtr6FC6pH/TPzReZpy5vierx6IaYijHWFLkjgLgNNE74xh7iqWCwe9pc+U0N5l8fyBXWK9u1CIQcYklTGHEhFHSWJltRDbiRRhghhfiH4VruF6ot+zNgP90rvvGSqWtIikEGwQgsG81uRw0Tvz8RDIDd8C4EOaKvJ1E6/cBkWVdz1dLJ09PllXTTm2B0ZwWl4/9rp1BlvAoCrQG57WOwR1CncJzGsv8Y/ph4T47V3S6mi3IoTBEBc20rG8G+Jnqj7WBZ1AfIlhPGatnm2F0ZF4vLHx8jTXiwik97gO7VFbo55gAqYq3m9H/FMWznFjxtmbKYOFpdrBi9e5ISgAlO4UqlWuwULWhkfPegNlVmxuGyhdS/l9z+PluSgGAjn9ledb7UuhMBmmx19a1S7yf1vth9pE7RE6ZTn2mKn1vMbDojoifmrvAJK1F30f3Mz7rSj7Xl67PusYsk80BhYDFhQ2qwd7clHFPP89W1jJevVIBChvJjDR2aoirSkFSv8T39bNthzY2ktpuwJoae2Ny/bAaHp3aLugUCvDrpBhiSHHbRetdcGPK3Og== 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)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS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FfHsDLE7M76Gxjtt5C9RJpWWkhq1tYJddInzEVy10KAYmXRFvFXp6SbPxLn8MxM9ISkh5+vj529zzg38R878nEJUSoFbRfGZON7ubVqQ74LiNXz/UqBpnMPLS8r6dSH93uD2YXGYYIszwW5iQcZuDdo5jVLMD2pIGkmzGG1wjDmlmlNWyrqpcZANTGorMYUEVE6rw0w1Dsngtd3Int2J+ym8YoPnc0GGRjGtGsWSuZ2+opgp1lNUPziXdFpjwtF/uXJ9Z25U1oleGlakbgfd2NsW8tOFAroYT6FRu7fO+cuJQpyKezex0DdQMRt4euYA10Fu6USouqn0sSOkp40ERH18pnNU9Daw9aXlN157NAI5RYqUNFzqX0EaB2ip5tnS/E/6jjmB+uTK4P1Z/khYTQ2ZaT+Dg5Ko1GkoFUFb45UWcSDvJG5BCbmOQ7aKFPpHvkFaR5pjFxwNlw7Dj2T8QfkZhKnLCttocOVJdcNS3iuv5sSSfrVpTFj+8eSUP0MpmMNBX/z5YGVKTFpW94V7WVljysJTpcy++J1W3uyhkYt8XkrBPHu23550 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4bde1df9-a641-4c1b-2bdf-08dc6f90b28f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2024 18:57:24.2940 (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: 5mwK+hUp8izQpSiY0FuiOJPSWJzQWi0jj+sR7W3/MZRj3VV4cknbS+DQrqsLIEuS X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7514 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_115734_107126_C72C67AE X-CRM114-Status: GOOD ( 14.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 Fill in the smmu_domain->devices list in the new struct arm_smmu_domain that SVA allocates. Keep track of every SSID and master that is using the domain reusing the logic for the RID attach. This is the first step to making the SVA invalidation follow the same design as S1/S2 invalidation. At present nothing will read this list. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 29 +++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 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 3011eb10763bee..020e4efdf8fc06 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2587,7 +2587,8 @@ to_smmu_domain_devices(struct iommu_domain *domain) /* The domain can be NULL only when processing the first attach */ if (!domain) return NULL; - if (domain->type & __IOMMU_DOMAIN_PAGING) + if ((domain->type & __IOMMU_DOMAIN_PAGING) || + domain->type == IOMMU_DOMAIN_SVA) return to_smmu_domain(domain); return NULL; } @@ -2793,7 +2794,15 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, ioasid_t pasid, const struct arm_smmu_cd *cd) { + struct attach_state state = { + /* + * For now the core code prevents calling this when a domain is + * already attached, no need to set old_domain. + */ + .ssid = pasid, + }; struct arm_smmu_cd *cdptr; + int ret; /* The core code validates pasid */ @@ -2803,14 +2812,30 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, cdptr = arm_smmu_alloc_cd_ptr(master, pasid); if (!cdptr) return -ENOMEM; + + mutex_lock(&arm_smmu_asid_lock); + ret = arm_smmu_attach_prepare(master, &smmu_domain->domain, &state); + if (ret) + goto out_unlock; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); - return 0; + + arm_smmu_attach_commit(master, &state); + +out_unlock: + mutex_unlock(&arm_smmu_asid_lock); + return ret; } void arm_smmu_remove_pasid(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, ioasid_t pasid) { + mutex_lock(&arm_smmu_asid_lock); arm_smmu_clear_cd(master, pasid); + if (master->ats_enabled) + arm_smmu_atc_inv_master(master, pasid); + arm_smmu_remove_master_domain(master, &smmu_domain->domain, pasid); + mutex_unlock(&arm_smmu_asid_lock); } static int arm_smmu_attach_dev_ste(struct iommu_domain *domain,