From patchwork Tue Jun 4 00:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684503 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 926ABC25B75 for ; Tue, 4 Jun 2024 00:16:38 +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=RrzYaloaueJpIKamKl0IvwTfopdS1VqrfaLa1i+ks0M=; b=BhPMs7n63e9vBo UCeO2pdSBdSQzPEUBIz5RFrUyVMMbWqffYZWRnBEL/9PQuQvFcmAozPt0qVYRou8gbG6qEjI9jday CRa8PByi0Da3LE9OydYpQsN/12CBLgyyDEVtmypsgk50rI9sgBkhanly7w1lvgxoqjOdu5bJWcIPX tPeH94AN2jPncgq1/SWxtLy+skFM13h4CGOxjEi2jVkKDml2CfMvxnjd5LrFCd3zuFDFavBxbIMpL 6UipvcqIBAsKkXugayZF++1xGrkT5BsQAYayIXhuGItA0CrNZJ3vTr0LGMekTH1m7iPFexaTi0mMH lItjbIGOZ+Ttl8jBCtkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqk-00000000hlI-1e3G; Tue, 04 Jun 2024 00:16:26 +0000 Received: from mail-dm6nam10on2061e.outbound.protection.outlook.com ([2a01:111:f400:7e88::61e] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqZ-00000000hZE-2RrX for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zo9tOqcRprE5+sSNpBRpLfA6OhXX/IWico8GGxTbSxxcKmiYON7z9XVyJLug2BxIMzgARofStn0VRmlSEg7myz2AUUC2KAaefOIlrpt2k8Px3HU413JpKkybHLl0Wna+pvhthWRXro4+60fuy69Q2i/2I4oN2gCtU+dlh9B4BE3j07iIM3PLYgvinZuHEMBvZDFT2h1lcg+AvxR/pLRMgk6V1auHuodPIXlpLxHUsn9CK2MxHrh4sroA88ZUlBed+33dXvJF6czF4/1HvOC5QLfbp4dFhopGRsyPEBgl0zaqNdCDjb2ZawLoaWNFuzhAzAQHT6nDKCbWaMjecd+wyw== 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=JTVBkEYsj9G/CPf70NAUiHk2pLwRaHrDKXv6mSt2U0I=; b=W5uGfztzydPmPehoH2qUAP1RZgVAOkxL8P1zWLu61TurNzyoni3rOgUlrkgU4tl9f06qTlOmDko3Bymv8Eh0LN5osVkjbNqAH5CjEuAdLMP5PTuVQKdr7H582G9zB/XH8pGmemVjTE3gsNWm35ZQqUHQzJRPE9FlhFPIwVE3XYQAAyVACm0Pa2Z8sy3wGYTrPYUc9ixpzmdokv3d1S3wWpC3Z/CkSiyUPoLvzQLkTFC0KLx8xVj7JPvGWwJTT47ap7KXkPK1lVxgg0yMs3si+yVCQvYgLA0OTh8rLMWi1jde+Q8Pm1LWGVHOnWJpWMaXlgFkaiYq4bWd7an2O3ebYQ== 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=JTVBkEYsj9G/CPf70NAUiHk2pLwRaHrDKXv6mSt2U0I=; b=RaCfIPh9/hRu1gMiBdXw3qarCBUixqwOeJzE5kSBmS8HLOqeG9JDdliGKyCVhOjWwtazkfGmRBNArP0o98nOWZ9MbMIyvfjQWI1pBUWcdA7nQey+S59ZiTZXiZLQk9QGqH1iZAQm6cmfOErZEk65vr5lOKpnglVcyOTzPyOieCvMJkK/H4TJLRjoEeTpy1tfIqELFuOlt0GkGtI0G0WC5r36/KNezWrwNauBBhtqAbCKRcgslVNQLHPL5Kr8Ds7+Yr0MuWqecELh4AzXDAn2DMiBvu27jNSXAvNGsNnHfeNGGqL3Vk42oqZOYefHy3XldxpwQ+8UfBGHoLJJUsAtIg== 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 MN0PR12MB6296.namprd12.prod.outlook.com (2603:10b6:208:3d3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Tue, 4 Jun 2024 00:16:02 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%4]) with mapi id 15.20.7633.021; Tue, 4 Jun 2024 00:16:02 +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 v8 09/14] iommu/arm-smmu-v3: Keep track of arm_smmu_master_domain for SVA Date: Mon, 3 Jun 2024 21:15:54 -0300 Message-ID: <9-v8-6f85cdc10ce7+563e-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v8-6f85cdc10ce7+563e-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0427.namprd13.prod.outlook.com (2603:10b6:208:2c3::12) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MN0PR12MB6296:EE_ X-MS-Office365-Filtering-Correlation-Id: c114f983-58e4-4f7a-a955-08dc842b8497 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|366007; X-Microsoft-Antispam-Message-Info: Gdp2YFjAgmdQJjZ/M2ncNlxDKOIM9fRuVW5qC54TO4Zz29nIM4GY0fAOGPa2P2eV9Dv3uVfcfH9rVmGGDYc3r+TPKUvB7mtHauBfX/0vekQ0PLeGaurFQcjqA9zJl3LTiSp7RNWa3Kf2Oh7F5SDRLvmGPJ+iTXefBL0UiHZgXHBmosIW/D6rdXp/ckj9+FSjZf7aN78CbW3cuowX+l8TXh54npIUwTQ1rvbSnJhvONwPsGpNxJC09vLesvYOeJB+4aFSaLljz3H7iv6dpVZR9JBJqQO/LwsO1BAwEakQcmb/C+++z+PVE9Eu5IysaPK6u9OMZdA7OTswbmmw51x0CngYItCUl2yCbTWf9N5GHIVKQogvNIgNQr8Jl3slTQh0pxs9RbCvxCRXdxR6O0Min9DG+CtzvQLYhbV45ciGpX/rz4QIuyoDp+3zoWcwHGMinQNsIOCZjsYg503RSpHknD19sRU8ukFPOEmVCzBNc5xNJMSTyVVyYxMSY0yU2ikmU9fluAvmX6u+EiC8vjQNMgqI/SxsNAhMLmjv4A1WowwRod3q5xizqXyNdgiEdrcYw2zqiythAzddcU0uH/MzciaOhVDBbtLEH910aVflCmv0liZ4MnJNfO0xCl51ug5Qh8P6+qZMhTSEff5i54yUavmyJr0A+4oieB70dVxb7M+7g6UQ7feQk7T9R5b5StbXxFVgIKN4AlsItA+y3hCmEebGTPflwYxhBnDPuHhr9C7/JqByHdeYW1Y1kympz4bf4CZBL4YZBP/4Zt6s2Osrk4yv6/Gt4EjM+d4Xx22N0HePt0SU4O4yhGXCv+7cqxYXYjGFBk5SICbT6t6uI/FjvHsbysriAdpDKxDVMKZaDHnsRDI1cDWDr9MpFCwBjLJt82+2p8k8Q9UjbjwLyRMhErdsnjSjtLQPPT4f96AWEhd5Z5uNR15zGp24cLAfdyFHq3YxzA0MU1ImPffIg6QtOXP7RLhEOiTzxg3Go8RWJlDUKmipzgpu6LMHlB3F9rE/RdJd66DbBHlI561ONpY+KiTrrEEH3hz7aINQzkJWY5UbCIkTRq6V/4M48pjIzKC25hFNrP1hyrC3R36EiDnADKicrb4GGHRNgOhMvQOozl+GycJmlCJQORoqPLdEb9KVILRsVei24eC+L0ZvArN94Rkn5m3Hc+9IfN6l58pN4ZECWmsb2cLmx+BBpcf+RTZGj8jASiJZtpVRNhBnUYM8eJVVNtq4gdpOPZiiUWmoPDlPmhvz4Bo71jAKe+GCmskyBWVaTBv0GYmnfp/MrA3Xhw== 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)(7416005)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiS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R3GkmIQxv+kyE60J9I/9/+DkPsDw5/uZOrFhRdMA1R7fJTiIeLSML+3JbgUQ+5K6rb61y23mrIDykY0CglFMlREhtNrMddyU/nk97ekj3Q5oFQq9VJt3tnt056iHyLvEvu6e+erBGblig0feq6oXIAU2Y/MSUfx6mBdwy+UJOMeqZvOLMyQXYC6P3d5CxQBx+ugUd2ELXldNi87QQ9QPS4k/HR84R2NkHYu7V2TcCxGAfJ0R6YGOE2AwKWN6YG4SWkRixTedOjWB1QvhoovjdyMTJmq1h6QQlDNtOHvuHjmyT1+KVHiP2MPMWz3p4ohOJvQl5yumyhhrE72wbNythkrP6vMKIH3WKFQ+JiA5TADJLKb6Vmr/XvXeu0p+O4Dtell98t+RxoxezRM/yJX9tB3YE40QQE5pmVCE+FbhWPQlOlFXKDPbxzUsMvhAS+1Y5cUGYT1esKiqz2OV+mw4wE1nugPPMtdoAHAmoMzXOlH6YKZoyRM5reF8p7TKYdmyXHUGFVeRiStb7/A= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c114f983-58e4-4f7a-a955-08dc842b8497 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2024 00:16:02.3878 (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: uem5dv2b9+JGp9Qef2lkj0qaUZNLR2uk26Dpu5hngxxU9XOniGYiZAHnK7IVi6bJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171615_680402_FE560E79 X-CRM114-Status: GOOD ( 15.12 ) 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 Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 30 +++++++++++++++++++-- 1 file changed, 28 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 c6dba933d2c38c..24000027253de8 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; } @@ -2821,7 +2822,16 @@ 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 arm_smmu_attach_state state = { + .master = master, + /* + * 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 */ @@ -2831,14 +2841,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(&state, &smmu_domain->domain); + if (ret) + goto out_unlock; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); - return 0; + + arm_smmu_attach_commit(&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,