From patchwork Tue Jun 4 00:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684507 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 F1FF9C25B75 for ; Tue, 4 Jun 2024 00:17:06 +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=wKRWkQBedf36XC6fno2dIuYTRPorwMz7FftQUl7Hqm0=; b=Ll4ewVwyT7h+mx HUri/yi/vZ9bvAVSXD381krdSoN6vWiUCX51KULPB3nNBhd1qxkHkFOqcxtRBHOnJXP/1zykTsxka yEh97VC0VzWWYPcZqYqhxgKhrICWsNdxdiZeU6sut4oGKe+VTkxt75FjSubRowTvPowNvfvFf30HZ 1eHl6PyTxYmCiDTSk3BYxGy48Z/ESpFw/xNxazXqSR4zDshLKnl42mwFof6gphdTQSyzCGGyQKrQU cVctB4R9HL2qXFLLJf8O5fhiA3gIBl1FCBrChBe9Ma+VdP02TFvMdhUDVN01WfS9TJKi91LORWRVd naS7vmJggOQdi4QUcBwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHrD-00000000i7Q-03q2; Tue, 04 Jun 2024 00:16:55 +0000 Received: from mail-co1nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2416::600] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqh-00000000hZp-1y7E for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mLccCi+LfVGcstxTvXOknJCg9MepLWrB1gLsdWOa0qaW0xDgK/Cyu+BkfDanKnYHhlu043QmC6Q0AYhTi73QG3FQJ6UBDkJmr84q1VcHymIcelci0xGpTHHZKCZ+d2pCqqNaUKlVp9ZAEx5jH1Filp3oivnZdAJldyulAlFAB+lFGrktPuyfw0rfAA5elWbJS+i8ci5UCmpr2T/LKZmZTSKwVZqpIKyZllIKQ0yPwpMHYLXCa+J/06QTdzT6A+hJ/MRkCFuwpgnaATig+MbLgA87p1UT1X9/ULCE1KlS5MVRZdUmyezeBW5sW+nOHDMFUQngSLLG/q6xXePvJVDKWQ== 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=XoqgZ1Hungdfk0zBr3VeYdSIqPlnOd92FRLm/zECP3w=; b=PwmxeeIXQzyQdrSAwyx3nOd+VDRyi7l6AfAOmJVUyDYDftdAU81RFl4HAmwsGnxI2o+ygUZV0XnQb/C322i7srI8Rh/oHq9qP4OotIFQ/45+/CDRhS4KRGh+omf1vmGwxioXCfL/OvUBd+nGdH83GSECanE/xrCZvCkljyUezaiZYY9A1eMvji1zlQ683vtgAoUyBTKvXKdid2MPMFB/r/OBB+ajLUUOxZkALwhVzqk15Vegxm/6MH7Z8xyOPbJxXLlT79oJNGZ9D2hHV4PtzAek9oca5Qe9MqgWhH2HdJclPZsClqJH6G9DI5QAYl/TqzpdDWURoIw3akT5EVbmmg== 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=XoqgZ1Hungdfk0zBr3VeYdSIqPlnOd92FRLm/zECP3w=; b=jJSbf79/RpjA9AB4TfnPQVBOWBR7RBUbX+9xjLmJpDFWwzp1P174prxKZty/UPEfP5TxHQM3NrfuofHu1jTDGGFCQZDZuS9iSnaoS18Ga7f+77HTEpaA8Z/ElYbG+jFstfJsgCBvl/K2pY9MBpxnkRwlmxtUm2fongI1oHve4rR0H/T5QcycH2MNGDVXqyH9niCT8Qkddrt4UrlYEujt9vF/G4A1jtX07iDMyymE3qO2MCVXO9I1qQAjS3mlNG1ynNemlMHO5E//GZPnbTUaM9xbu8NkgYx+hSH4IOP9Qb+AbTFED94F22wwD83SnXmoNmESSL3rdvy6CvOUu4wUig== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:08 +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:08 +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, Shameer Kolothum Subject: [PATCH v8 01/14] iommu/arm-smmu-v3: Convert to domain_alloc_sva() Date: Mon, 3 Jun 2024 21:15:46 -0300 Message-ID: <1-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: BLAP220CA0003.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::8) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: 77b5f20f-df77-4817-a805-08dc842b880f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: pHqrWkb4wBScz3/WtwIkwSrJuSW6XSzhR9jBf+46dexVTxemgHzBpjJOJaf3/lkgUVXoZD6NaRV+MwEI2vEZDq4il+dDz2H4gkqhhAyk7izfOisXBC+53RAIG0VsZYmScjushF7IexajtqCXKFaoRObh1E2lf3ImGPH7RMeZqIToItSbhH030n/FeW8sXKiFTr33NZyoEWGlmcAoZ9SpAKzB7c5Ee64SAFtJlH93F1Fwjnc5k8M7DqDhf5nG7J8gDM3vlP8kQ8rmxFsdqq5GIvMs7Q1v5P9G3X44IFGAkM593QOUdgY5+qkR7c/elXCJWu2JGjEmCzPqksPD77KOgyOGZNGShuiEzQb1z7hWoCVlNdB3H2XGhqVuQySE4lWIW3+AisjohUCo/CLhSUyD6kntVQGZANdrQ3/xNF4Z4p4MVcl+hI/q2EU/VrzNbW2p9q58KyOrGcfk6Q0dfThKulswKa6q+A92Le+8GsjFsehQiqWdW/xr0cW7yESlS699Y5uYS2fhxYtRuimAq88k3IpKNV5mRN4fhzt+JSRdblK7adYyKz7Mk37NJLcRNMTLrHMfm3oxHMCz7YqKR7OWLxlGs1rJh1qCEB776PDGY7Q++rlTiiOn0S2vxVHvJDFjjqpD6CutrXsrzzuYemIM9CJVKd5vt1yIHKaky/3toseX3z44h0+ObfmQ+WTaEZQZqtqonlkMIQiRJWyMNVvZ9LHJ4sBIp2npU9+JQlz/SQ6FEverZO2iFbeqOOlowUyg4fS6Aa5XdKhquhh7u8C1kFYThSEXm8BXdJTJJfi2ZIlQ3b2zaAF+XwGiWrEUgMheU2AE23LGKYUam3Y3BtnvLk2A/ypeKH8WeLyqwdCB2yU8X1dx9DzRoCcHvgOxEIJLsGwEhnksfbofOnpByNc8+mg24Ltbene6OMzTBpyzpVVjH4yflf5yrO4A/3i3AzPY0VNAlIDbCcUzOlNddlhyXFZgv2pXDOeLIjOrHWrRJU/WEQAf/DSRKY6oGik910EWZrkJ3Kqi49+aOMxpcAkZtDuzLmX1rDudEK8duwNqhMSQD0KOCZH+W2JmPjtOazXg0/clkLjVgsav/ehUIAOCOuHyrZ/VbisRC+jIYpPTnmIOyfuR+MXmwvag+Zso5Is8+OgygaM4S48eyoAA+j8Y0lM1z7Jcu6Y5lA4QAA/Y165Q346mnJRN5bq0iWBZ7L2kEhXxZL/5Q3ZQDjImQCzUMaLe78FRN8xeKMsvK12ZZeYtZhqoJ0L2XY39nAWKvXG0byMO/iyHy52pb9LI554aVw== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J6ieUCiCcXcaHZW7R94U9JWlWBcMrM4IyBktGon1/8t8aiJRcEXZWiBdc5ONKQIqqOBj7BBKCc0TwNewG2Ehd1synOM3c6TSCFpYiTqlRmyzrX+FbJSDsmhm5Kv2jt4WzThwf3F4w1Bj+45MneekcP8TViPReZNh2b2qVSUhqTsDb6rvMJpynH6+y93N3secQjRN9VdqiZxR/Utb65Uz3KYNkPv0XVQmg0pF4f1ydhtJKr/YA6S4dcn0i5FxdID3ouAG67IIHI9pNuwteLCxwZgpCX2XWAOdXhROi8/+ERKkZEAAKgLz92D46ZbbiK+CODOTQ/qRJkGIL5pmZdskO5tF0ORctafBGqzxfc+SlGpICgmEH94fDagb4/a6YdyA5j+5xJ0dCD/o7HnPphQrYQ4wb/NjfssCXBp6wK+OHDsdd6BfwMa0kB8bTV+rqCYeF/7jow+z5iekk0o+BFs1QpARBWVWQfc3Zo+qzQmlpXdAkws2GOsR7V2eAor0+V7Qx1dCdIFOBZOKmgTuszrUSm81xd8vldORCzdxx/U8GHnGA4LblYNojkmQyEE2HGKWQRTTy7SZY5iq0csOM7typ87ZGd52XL83j4WtqrBemy50LNmTM7pdtyUi+rxvTqpX3zWig4j9cX15hMGS1wqaYmkV2Fue50vwJ/kkmSSVT79S6g9h0bi9PrR76+J4Ay0ETZRtBpDU2JQN8Kt6kCEWbpLefDQX6ZkmM4YNEh1WynMQFEDCp0PX43VE746lRi7UvIBVdkijHMCoA3fxI6ts8PaGJmW2SWPRdy3ICd11tzZ0DPBlwskWQnZAHHkKlweFPULZhV86zY9nZ3kDVuyFZhCvkW71wMTmevyEZYkgQoJxLIHYp5FhheWD0Co/VMOvjgAU6hLEAJ4bW6oFdxCj+feUTCVrTjLdKA8ldduXCcAlHPBT0A1jSwnt3TudHbK8cHufZipHSBLiciOm6nWs3rFsEMCCpcVIfJS4qZTsO0ax1430xbWxlajntMvy1wGmXH8TVwwxNA7CWSABw6fCZQVcBRXaNMqaF0sUkMq6YXUfm9rMi5QtENGS54j+ra+upI/9Ld8907pDU57vvKTyf+ucAT9h1QkD8pinzFcFjCfOk5WfKSAs6TxG4N2rLD5f8vOzWPRKmfkfdDdfxgXXSRjFXa9VTdOYeLH34P9wAfPQ4WXIhMpBzASdMC7Jb9xzQrk17pFLc4m4q9uvttGa3x/96pkbA018E9YiLmNwf3QkKB1WxdcVxvOR1b0FK84VLtCP0+kcqDGXZZdVDCUXh+LH07i26KmeoItgGTkvXZFiAaJSaxgrZcTKAlSjkWGvj2kiG8jIBvvKHx+mMhEOUSaGvmTaDTg33rERMdjVmhx4Gl/2nw2ibWJYFSG7TB4T1M5C3GGoirXdt7tWB52tD+4QVKd/YAYP8IUnZ8AIv1MEBtzLalmpTikfwYdAWyJC/KotlpNm80LBEgdr387X+EGjZPjC3eM5OiHhPAs+vyeVKbBuOQjIL8nElW+omKlDYHKiiMko/cG1JZI0Z59VQQ2pMFTo9Kp8D6mPk6rnfrc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77b5f20f-df77-4817-a805-08dc842b880f 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:08.1865 (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: oN7mKBuWz0PPTiERzGwxt/3O/ogbcO6L7MAl7j6MLmNVnOSFBMmspd0qUXXVwqWg X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171623_657636_19728E33 X-CRM114-Status: GOOD ( 12.16 ) 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 This allows the driver the receive the mm and always a device during allocation. Later patches need this to properly setup the notifier when the domain is first allocated. Remove ops->domain_alloc() as SVA was the only remaining purpose. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 6 ++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 8 +++----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index e490ffb3801545..28f8bf4327f69a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -656,13 +656,15 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { .free = arm_smmu_sva_domain_free }; -struct iommu_domain *arm_smmu_sva_domain_alloc(void) +struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, + struct mm_struct *mm) { struct iommu_domain *domain; domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) - return NULL; + return ERR_PTR(-ENOMEM); + domain->type = IOMMU_DOMAIN_SVA; domain->ops = &arm_smmu_sva_domain_ops; return domain; 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 ab415e107054c1..bd79422f7b6f50 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2237,14 +2237,6 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) -{ - - if (type == IOMMU_DOMAIN_SVA) - return arm_smmu_sva_domain_alloc(); - return ERR_PTR(-EOPNOTSUPP); -} - static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) { struct arm_smmu_domain *smmu_domain; @@ -3097,8 +3089,8 @@ static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, - .domain_alloc = arm_smmu_domain_alloc, .domain_alloc_paging = arm_smmu_domain_alloc_paging, + .domain_alloc_sva = arm_smmu_sva_domain_alloc, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 1242a086c9f948..b10712d3de66a9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -802,7 +802,8 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master); int arm_smmu_master_disable_sva(struct arm_smmu_master *master); bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); -struct iommu_domain *arm_smmu_sva_domain_alloc(void); +struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, + struct mm_struct *mm); void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id); #else /* CONFIG_ARM_SMMU_V3_SVA */ @@ -838,10 +839,7 @@ static inline bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master static inline void arm_smmu_sva_notifier_synchronize(void) {} -static inline struct iommu_domain *arm_smmu_sva_domain_alloc(void) -{ - return NULL; -} +#define arm_smmu_sva_domain_alloc NULL static inline void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, From patchwork Tue Jun 4 00:15:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684505 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 4706EC25B75 for ; Tue, 4 Jun 2024 00:16:48 +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=e+i3iSVsggY3G+zxD5jronKTdYqHi2E7TKywyIJAXdk=; b=cpnxJCqepfDqvA I1z27Pvl1fzINavD2fL/OFJW/IAx4j3He7W5Qc7bYcq7W68wegHHYiZYbrVMuMmYixGwuu6Gvu8N6 hiufhr+4acq35BaKpENd0tfmgM/UlyN2Qr5soUFMb1QUnNN1CM6oRglZpubmJEPWeGqco2hEeAZuB 0WzLlJGEjDlJBJhD/a3Dc+WVQTPTRgPzeDl+y935Q3Rjsy94H0U1BpbjACcOq0mI7qMkaLn9We7O2 6iaQ547zsWsw7utzSLJaEwyQZfgWRwu2Ab51mqjHJOnCyQqRCIr0D+3sCHAD1QvqN1IKD/NvNvQhM yPvRSBDlgY1T2s/EdX+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqt-00000000hsJ-12oH; Tue, 04 Jun 2024 00:16:35 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqa-00000000hYg-1r7K for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H5sRd2bVuTZurROvypfNppi7CdEIafRWJv8vM/NlPVD+bju7EHEx9hlY8NrOSJY+6IVgUbbt9dqWk3B5/OvW3uRfL1IhHCsHicQlml4cne9AQ54dSUozMrNPAVP9zodAHB+R7YL1/EqnvTefiktciR15a3ORWuStaeF8eosmbqk4ygZZPvAF9HgIM32Gfond9B9pz5KpkplWSW4wD9tC4JxaFIPjXPHS3j6bGCLY3oVbuS7nOovxE+mdZp5uPhL0P5i30xGwejCMCjOFX4Mq7vCO8mQVAQt7kqprU25NJQMojxROzFPEwp7zuK8ULXsvtA2pnfevx/q9wCBSPnMz/Q== 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=fTThI9TNufJe256yfBubbCVPrVing+bW0N5N7FCb8JQ=; b=gue/pddkk1RHJwv7lQYmX00YiEN8jJAFkG1eThKeGpUDk2UJuZXnor1t3fYJdznLa06XvD8WftLbV1iYZvzjZw4EYRkzC7z+upXJbC8FbX2c9gk9KPlxJzEzr17yDiVrT++h1df2bOVDvau7Ox7w1b5Wnrfo8lYKmtTJCvzF1YyGSzhMsydO43/STzGFwiJ9zrK4WGXJmxwIMT7qa7IpXyT/APGIs3H5TAKSYcVtDF3ElgxaQq35YooT27fZaKUMkrbxzAitY736Y79HQAQi+oImlc5Bv0lXO4nZkWHuh1y71C3uuwjPsiZftKjBPL8wCbxHJQ6SII/Cy6ZEn5k+CQ== 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=fTThI9TNufJe256yfBubbCVPrVing+bW0N5N7FCb8JQ=; b=o6+GTe//11XT5XVjU0+MaNzKuBgkizQcffRS3dI3J2P6PVl3ScW3pVVOsEmBJiR6+6QTxl46r1FDlEVxDEtZgUIRfhrM4blRmbxlrVC1B/XNFz+OIDysoFC8x8GwWP44O6ApE8EgU0AqQsdiMu451kYocRWzMTa0zx7O+HUYtPsEwWIQGrG8sGUQiQdyC/AGW2ygi0bT7Z89lUHLJsMahmgh2A/rpkf2X05bRSlJoVgDqNMPj/qjMJO9gYIKlVhdLM1ZFx2lNkASEb/V4WvmBXK2FnxegiE/oBbJdz/ayQcYgZf8H/PJMSyRbLAG8ZbGUFSubKX9Qd2tC9HuHGIbbQ== 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:04 +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:04 +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 02/14] iommu/arm-smmu-v3: Start building a generic PASID layer Date: Mon, 3 Jun 2024 21:15:47 -0300 Message-ID: <2-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: BLAPR03CA0113.namprd03.prod.outlook.com (2603:10b6:208:32a::28) 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: 65b76e14-69e1-4ee4-938c-08dc842b84bc 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: VSWtBZxvhVzqYyQAIWgQ84BScm5cW3zp/FNSnH6zMpJC02sg6w1RgV49qadxc/B9teHG7Ec3UsLYDyUCBLtknU6oE7vR1W1AVCDFLSBh0d54HReCrgHeCI+z4UUVL+rS5H+wjoAkKhVt/LPXc0TiTtBlOxuCOtQk9Bmt4HenwxmSJB0JpRsGK/2i4AJ/WvuZbYZc0ulfquzl7ZrtBfUpXHk9tg3rAQoEds3sAJ9pmnNqFWv6m8eVg3n4JCCKLWnGj11w/YSp3TNk9pei/iIGj2p1dx6SebNC2ffbjhWF+0rs2vruQmUWh+EjD+nN8y6CbrJ+gl3YDy330ujQcs4CvJeNNfTvYZ5BtLfwEurxbyL6XRet/bqSEcXgs/drKFMiSm2SfaL+jrmGGstroLgq8ZPNqpI0bomieFgnjmdCj1DeLaEKuS3U0pX3PMuKSOQcl9tYD+ClzqN3uePGJj6PD59IVT6HJWBG/Uzx8exUqYvzvvqpKfnTF3So8jCzdu5vity6VAmuzbsBXC+pbGiEGe9/585Ox6paWGg8EWbYsaLvvC2+dyAq5V5FHakv1G99PGlr/DBbLsaT60ErxlQR4oMKKQVSG8OYvOjXSM+OamuN7L/0OVWvzxuL5Its4dr/WeF/jAkUFAxbVMEX6ESjdLC1S0Utx1j9INQNxgFp6HWK8kkdwwxYDvo2eBn7YxYUAtHZJnRbR3XlOna6zyG/MnTYylQKHFs2NjuS2g0/1oJ8DYtFRFDZFa/QsVllLnPzuwm9BBZNsqWmyXkrlL9JFShpF2DJGzagIKRPrCETaLp0qEMz2JEpBv+T7GSpR2fDGJEL8ebgqbR3R7qJnRf/t5ERFnQAbzD7PSKbwJ+YiI7QIldMxL905rVnZib/HFiBx2FG52ENV/Ey8DkPC1BFoOBQHyAZMhmazz9JkILzBepA2K+uJu3cjVJnAGhD8Um2NUISpmIoLxU33VaJ/Cf/WXSw0t+LAn17MF6fndpl92OEG9v0FyYHhd0deOT18w1lDthdt1Xb/AgEMLSChi5QPomUYY8Ud/AxBOQQwGju4dRxa7l9QfSihTTdBGtrQDvsFlJYjHDICQ0y9NsMDtdM64U9SSJXeO/ahzT9BoYr7WukVgIWqe4JXRhmYAzlw97hfYBzo/iQeqGxyT/ygkRWHYv01qGbK2QM+GOTw7PaYd2hqcaY8sdv/kan2jQCx4m8zuzsG8Fb24EzkdcRMz5xP62GI2M1YYVx91PdyXzHMpEFzsNdz/NDdDzTxivTC1OXoPczhp4uvdh9n4iaHGQXUQ== 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JJNqgx/Q+/aAsqHN0UcHESdVM+oF3sYB7fhUodcBOJWNJWBnfgeSTj+8D9zrKQPEyi+YYvcjDA38PvitzcOD1SkRJ5swSH5ys7uQOTRUmkZSPvvbZk7nv5LZH/PAniIIoA2TgdtDa+ZOMLzIYz99CTxUpsnSEjIuRvHRquKJrHYZICpufcTX6KqpRJ57O5AJqYlQqUx/INO359GaXJsAKsTqNsrkXz75p2QOnFYyI3QLejxRmU1u7bbLM/pAH0bXQ9ZDLAxvc7xuPKlFu0GGzNx7UOeIsdO9MaqByW0LIeD4XymEftksuLuNZnKG638je0/BVpdbfmowUnIz/mPDrKs5nUjTEORUM4GrVzFbT2k273LmHJTsA+l+9+cKUIMQKfK/+P6Km4jtRVO+gippd6BB6xYJXXvWekHjNwpF44QIcbUwcVfHA2yxpQhYIKXUMkHSgLz4e8qnq2ZftU28wUzGSo/wPMg1P1GTyHZWjvx81yxgAXMfUzaYpWuMmInTgHrORKYtz989nLl1c6JDE0gMV2/E+LrtdzIPNoOMbDHrh76ouM7Ov5Ml5uSzGrI6UTk7bZ/cIY9awga8DrobJKHwCIdVO48bcv9LGSrchdAZW/KtLtBGmg6BBpvoX9sPGiHHhVjLzORTKpwd9cie2Kbd/dcnM9Prc4R0FW+0z93glhcpQjVlPThbSBK0/vdbQSugaZJaWX3ZROqEMcFyL0hnePi3/1akxLhysjMM/q5uo25JDli/KVBe4RlWycoUeWsjGCibUj0xOxJmVLJpRVkjOY3K+T/J6tRO8qvKVfmit3ADA70Td8oKNuezZ8D/Zair7ka3QQykFcrj9VGJQrpMgmhUrhg/gnU2xCyqNqRvPTRT69Vmjn1pPRLC5b17/0re6mLp5HppwLnXK1oeXqNErh2Ozn/wnFEwKGMyMPkL62xcZlKc3nDsEUViTDuaWQWhksb9sETwvNIrqSWTE/9GqkN0fAr1HFbK6L/5JwJOIYrBalVAz75fojlt+dPQUikhDurHvL3h3ENV7WJYtmBJrGy/oSS8VQnU+5LjYG3m+2jiJyfU3KfnnZNG2MJJR6m2pZcnLFUZE+WJhUi8ajigCvO1ZewaTXxrBMIQVgkJf1oOa665RWvkMJqOHgMh0FEmlmocWit678+884fuy4y5ZGRdtKFSbrtL8PlM5l2xfLgFI4knQkweGj+8iLvqB6328kWwDImkxmCE7E0JjnlOFcNiszh699y1C58aFESEzZDospansg6Z5ypmX0urM9hEPf9tALcs8jntXh/YzE/QXsaqXzbgHx1fFRPDM5ldmgpBI5EodiQK3wVe4AkRrJH6/Nz6SWbJQG1Oc6M4atrAdc2w+JfsjcV9n2fyYqwzNozFa9txH9dwffELQr9NlSPhBcf6wo4UIEqeKXhhvgk1NaFkfFwLw93ONkNhrJw7PtUnub6smKghJjesLv2VLwCFXkbz+zqx11paCLmNB4WhyLTgV72Z4vWokhYUMSOoguZvTDGIy5w++V66hfk8/7pckOEJNGLe0mxzT4wkY7wI0VXuUxK6pWWQfGvT3gI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65b76e14-69e1-4ee4-938c-08dc842b84bc 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.7021 (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: XehwwgykQixNJmGFgWWeaWvESYhWQ+IDBDe3nUVf2FDxl4H6TdmlJ7KJsevjfiQL X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171616_762626_1D4EBE73 X-CRM114-Status: GOOD ( 19.96 ) 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 Add arm_smmu_set_pasid()/arm_smmu_remove_pasid() which are to be used by callers that already constructed the arm_smmu_cd they wish to program. These functions will encapsulate the shared logic to setup a CD entry that will be shared by SVA and S1 domain cases. Prior fixes had already moved most of this logic up into __arm_smmu_sva_bind(), move it to it's final home. Following patches will relieve some of the remaining SVA restrictions: - The RID domain is a S1 domain and has already setup the STE to point to the CD table - The programmed PASID is the mm_get_enqcmd_pasid() - Nothing changes while SVA is running (sva_enable) SVA invalidation will still iterate over the S1 domain's master list, later patches will resolve that. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 57 ++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 ++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 ++- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 28f8bf4327f69a..71ca87c2c5c3b6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -417,29 +417,27 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) arm_smmu_free_shared_cd(cd); } -static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, - struct mm_struct *mm) +static struct arm_smmu_bond *__arm_smmu_sva_bind(struct device *dev, + struct mm_struct *mm) { int ret; - struct arm_smmu_cd target; - struct arm_smmu_cd *cdptr; struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct arm_smmu_domain *smmu_domain; if (!(domain->type & __IOMMU_DOMAIN_PAGING)) - return -ENODEV; + return ERR_PTR(-ENODEV); smmu_domain = to_smmu_domain(domain); if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) - return -ENODEV; + return ERR_PTR(-ENODEV); if (!master || !master->sva_enabled) - return -ENODEV; + return ERR_PTR(-ENODEV); bond = kzalloc(sizeof(*bond), GFP_KERNEL); if (!bond) - return -ENOMEM; + return ERR_PTR(-ENOMEM); bond->mm = mm; @@ -449,22 +447,12 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, goto err_free_bond; } - cdptr = arm_smmu_alloc_cd_ptr(master, mm_get_enqcmd_pasid(mm)); - if (!cdptr) { - ret = -ENOMEM; - goto err_put_notifier; - } - arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - arm_smmu_write_cd_entry(master, pasid, cdptr, &target); - list_add(&bond->list, &master->bonds); - return 0; + return bond; -err_put_notifier: - arm_smmu_mmu_notifier_put(bond->smmu_mn); err_free_bond: kfree(bond); - return ret; + return ERR_PTR(ret); } bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) @@ -611,10 +599,9 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct arm_smmu_bond *bond = NULL, *t; struct arm_smmu_master *master = dev_iommu_priv_get(dev); + arm_smmu_remove_pasid(master, to_smmu_domain(domain), id); + mutex_lock(&sva_lock); - - arm_smmu_clear_cd(master, id); - list_for_each_entry(t, &master->bonds, list) { if (t->mm == mm) { bond = t; @@ -633,17 +620,33 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { - int ret = 0; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct mm_struct *mm = domain->mm; + struct arm_smmu_bond *bond; + struct arm_smmu_cd target; + int ret; if (mm_get_enqcmd_pasid(mm) != id) return -EINVAL; mutex_lock(&sva_lock); - ret = __arm_smmu_sva_bind(dev, id, mm); - mutex_unlock(&sva_lock); + bond = __arm_smmu_sva_bind(dev, mm); + if (IS_ERR(bond)) { + mutex_unlock(&sva_lock); + return PTR_ERR(bond); + } - return ret; + arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); + ret = arm_smmu_set_pasid(master, NULL, id, &target); + if (ret) { + list_del(&bond->list); + arm_smmu_mmu_notifier_put(bond->smmu_mn); + kfree(bond); + mutex_unlock(&sva_lock); + return ret; + } + mutex_unlock(&sva_lock); + return 0; } static void arm_smmu_sva_domain_free(struct iommu_domain *domain) 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 bd79422f7b6f50..3f19436fe86a37 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1211,8 +1211,8 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; } -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid) +static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, + u32 ssid) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -2412,6 +2412,10 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, int i, j; struct arm_smmu_device *smmu = master->smmu; + master->cd_table.in_ste = + FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == + STRTAB_STE_0_CFG_S1_TRANS; + for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; struct arm_smmu_ste *step = @@ -2632,6 +2636,30 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +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_cd *cdptr; + + /* The core code validates pasid */ + + if (!master->cd_table.in_ste) + return -ENODEV; + + cdptr = arm_smmu_alloc_cd_ptr(master, pasid); + if (!cdptr) + return -ENOMEM; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + return 0; +} + +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid) +{ + arm_smmu_clear_cd(master, pasid); +} + static int arm_smmu_attach_dev_ste(struct device *dev, struct arm_smmu_ste *ste) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index b10712d3de66a9..6a74d3d884fe8d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -602,6 +602,7 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; + u8 in_ste; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; @@ -777,8 +778,6 @@ extern struct mutex arm_smmu_asid_lock; void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid); void arm_smmu_make_s1_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain); @@ -786,6 +785,12 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, struct arm_smmu_cd *cdptr, const struct arm_smmu_cd *target); +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); +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid); + void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, From patchwork Tue Jun 4 00:15:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684530 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 224ABC25B75 for ; Tue, 4 Jun 2024 01:31:26 +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=RwsDOXxUkvnaRkBk28purQtGgAtDhemKb/OqIAqMA5A=; b=0Icj/IuofrQLLe 8d2+z8ko9vAfvLngX31dYeMe//iOsj8GohIM9+Da1cVx8/FqrWnIpMbUa6PTVoCiaAF/SwXn22J77 1X9yVqjZ5yez99o/fsg1iVAYGpkVoO9y2gnGHVGOpMmafTWRV+jp38yOpGKZwRbGNKZwru5QN74PJ 1V2fUPZAqzUCD1yElAl1Ej48PKPy6JV0LzYOMbbFP9k6WKa+gMhzNdR33wKRznHGlxSKIQ1FtwL8z EYpdfpSDT1UmKw+eyC637U/B/+QdTBqPAPkRB0WAnRPnq3NK1jaz0Xk/HokNGIcefPYZFVuwKTLH9 tNHCK/JOJlbkt8BsMpsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEJ1B-00000000ovI-0BRd; Tue, 04 Jun 2024 01:31:17 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqc-00000000hYh-1Sue for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P1+yxjMwur7U+nH73TDhNIAgd56XVdn4729z9kRHVJGBAFlp/eNJkNjlM28jAzgnemH6W0aZgAmaFkjqVH+zrsm/cYZY4wCjVbTH645wkidYw9S6UNx9CggHyt0S0jw2LJ29dgW6uhyjpnvIMkHX5VAcN2u5J+WLoMt0hPHKmlpZ4TORwTgXaG8IuLCHouOWwIL1Wxtak3pO8fZAg7mTVioTXNKG8zgA2EzSLdo9GAtic0Mvn45QzowV3MktlU4aLh8ESomWwIbUmY7q8mtS9/FFdZJGLpn3CeY3RHCj1TQ7dtP0th3QpUGs0CdMRM+GR8aALGja9mudSE/5mi6IBg== 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=4bSNGu6tQCzzJLAcHFS1wQqKfLhgXoSFyjeA6C5JJTg=; b=loomH1yF1R94fdFp8VLzL6//60mUGthc5rhLHy40h4Rf1QlRDTCF2b7fFSTiLUdA4jiiXYn+Fv8x8vIbOm5tNVo9xr8EGkuxZeqKH7+hA4+zQt1u/vEPYK6x+62GXZNj7bbeZP8gO7ts1BP9Db+GPZ492YbHkjTQj7QzWo8J7W3nR/4kjQCAD8Q/+uBSEWJi8RO4BoXc4/aQxvCJawvK9uNvfRkgNK+JargvvWn4j/106PFJwVT8kv13Pu6uGC1q7gbPjb5e6EftT4KNP0hTIdoy3tCsjj1i9ijUdsjjTMYAYjxLKr09Bs3lkluk0V+1ag1fZLO4143CE2OfgJuaTQ== 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=4bSNGu6tQCzzJLAcHFS1wQqKfLhgXoSFyjeA6C5JJTg=; b=Kakmpo2njG9rEtyz/Rubp7sJKejPnSsCjJmI8+k9kPHRzJlWEMx7PFRwv0Il9WH8bHzEpVM3uIva+spYj1x4Zb83A70MMXXVuOqpZjl5PxKexCcqLLV1RrxlRoJ7xB+jNSPd07gizlGFI8fy1bLqeU/KeWfL9Yr++5xhxBc5uZUufjimhhJSquGMlqPa+NFP12ElycJwT13uIr+6M+8ED4DHP7hn3jpGotsSoz1gpyCvRtN7envCIU5lHqop1VGxM6UVqD2u42KQgSe3jFt7T982UyCX/Y2canX9ugpdjTAm7NgqPbhLDdc0aGVjLW7RhM2K83MqDHyH98Nn6MXhBg== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:07 +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:07 +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, Shameer Kolothum Subject: [PATCH v8 03/14] iommu/arm-smmu-v3: Make smmu_domain->devices into an allocated list Date: Mon, 3 Jun 2024 21:15:48 -0300 Message-ID: <3-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: BL1PR13CA0429.namprd13.prod.outlook.com (2603:10b6:208:2c3::14) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: 31a869fc-9546-4ad0-133d-08dc842b85b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: Ir+D3UHNv+iUk31d6pufabtrCuBz2rGcNVQ8C0xjwdwfES7LBJceU517MoNgXvRbvDkp+v5G/7uvkLsEesJDLjip1NrqyokTPaJeCjLhZRYelPv6mEWRQsUYHkPT2AGbT+f2t2h0FVDVqbKanSakn8Fn0KDWxQ27pB/vUjk+SJnpGunoSdoTi9VX3Jp46tsVWNsppv1fgjRDCUIzwLzWJghIpJKpAM3msXR5yQWUXQq107fmgtcS5PRgTaxhwLF+rHmbyQUuq7jfWMgacVhBFilSJ7PKahiMz0TwtdTdjysuvSmsRrKoYhGjYIDKYGQ3FTXGuV9QDOOzG8SCtdv+FdC9vLm64JvP+faF4LL5LlBZVR17jc/ZIpRqiyWhnMHbGs3IbsFwNzf9vUkKEz/RSsYd0D10rTUWyCR4jY6nMIJb0frWXDclAfEONZsWPjZiir8uAykTbmVRxeKm8wmqAPKlp5pBrCkV9chgLhI++AOtlhmVDQywFTdk7vyjy2yYsEh2eVDiKd/KnQNDDLzYqkdgm8PkJWB8UAZNZBgwKj8yxsaL6jIni72caiFc6vEMlKQngux3++orLkcT3AfIiH1nvAUcdAJ589n1EUfFHvkQ9GvGebkEIDtzLzBou2VCGSbwgH42mdWxQmYyd9fIjXl15Qu9pH5/9aVL8dhVvzce4AwQ6vbxZ7MNALalBctJJ+FAo8852ByDXFpRQKynJno6SV8P6ZVhFoJ26r0vFKVGsxuLFx+1BdNOrAP3tjCcuYZBtG1qgECsMQv2BO6ihf9ialHixTxJiI18k0gJICG3L0DWWDMGhjzkTSubGNUwWlTnqo8hbhBbph3mfRPLAAggk276qfmU8JIGXcY9g5KzNBRQw0KCvqvYjEeOJQ9fjjmNLuZw2WxaCTvbVITNv/poFKpWkcixGFIh/uHkPFYB47WWiUpwn28zRjMIpRWSsAk9saQrQDqI3QfKy42iEgmL0yYLVNNwj71llxMVKujg178k1qwKxe+OxdIjchd0ROv3J2SB54uzxhAKdX9CdGhJe6tiGRlR4tfJ/i1Gdo7LMd2rr8+/7wt03c2GamSWEoAU8ZvulT1HYFiuoHNrtbj9YsnUta375eF7UeQOc13SDcZARRzbHFe45krf9LHiOIp1PF3LTWMP4FhbPeh+MRImBZ9efgvpwcUJeT8LdzMh0kGfM++QiVCjJCZIQxTXAc8RwBgZBDh15j+wJkXz388qrP9agS/dQwiXiwkxaJ1+IZX/pEp0bExfDcCvlHUfhovcmb0U/tvR2goRXS9Dgw== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uoDPsxXReYF2gZgejRQrpdE5ckTVqM9KRqPd/N6ATv4kb3WKHG0sHlQGAt2n5UFjjFHjKp+SlCkxWgtLC/X2/LhGamf9T5L4hD/u8exfGxEZZoQIqytNk9/nXmp8aezy7hAQmWsfBpzR81CsfcYCUVDKYYKi46qXMuNBY85EQj2cXXoVyeeEImSVUvsRHxo5xG9YXTSG1XVDK37RSshlZ/rneG6UFOLHghR5rmhLsc4qhqzPFcTwwBPG8/W85mdrtxlXlF/APpF+OgHeF51C33cfkw5a+4ROxoBs8v5IVpW1VrW5IMCy7lXMw/Hrl07zbqUFcPZ/wa7GfLIDZxAwR8+NSsU8VaPB5VFNXachsTSri8RnoPf14wpLfLiLKBFPOsjG6a8D5ANhp9/eb6YXSTVmLyVsTRi9KZqI9NTuNrWFaeCLg0FHvGj338q9aofUbQOsTEmzfYKvK6uvEscnOGlGfWPABz3LrC9KCEINT7xIAQZ02VYsHDQT18/HfERGRl/DUEsQ1oaFLhlEeJ1s9g60d65Bn7H3Zv2B9X4GxlHYdXy/yryk2pHuduKxGp6xvmvskNuYSP7Q450WpOgl7KxDzDAHCpUv7LAqkIS+nHIsFpBcEHDuwHRmly/wqSdyqalyiPbR1lA14EQJHVs8tMnPgrqcjrFHzcTwCB3qgfm+nlGy8V9Ey0rw61LgiuZXW+y5+zu6VzkZYo4iV4o06tVWc2fktXZm/rqppA2uMljOJ4oJ9GOt2LnmAyF4eWfHjeuGpky6N+Uve6QV5lmqQKco1ONis25KxJh5P2CIBv8YU5k6yFm+sPVhoN0m5slIQt60mmfX5Wicu7HBd6Le7mmHHS5BUMgesj3T5JSQKSKW+B0Od0N3BwIR3jvb4N5Dsx1/4DG/njibBCVUYpmCrU1Z+3PG74UpONUh7EzwBAIR93U39xRj8K5A+InofYOslC51fMxqCjFKuoBKUSKI3nT8QVm3bcwNzl5OS3kZbD0u4r495jeXVbr9djUfLLyJ51D9bp4bb92UxK1rOaALaN+JeLH2MvOSE9226q2BH9WMLSxCsxEqR2MIb8312TPYf9YbyJ2AfuluiiY7D9AdVOu/6+w/q7EgcthrqM3YyOHmW33USxCLAgU7rCRGjuEdCLv+H4osc6JUl0TZTyALAu7w+tfx1ibBgEdeWvd90/nNOfYruqndmnXAMhLC32kF1F4tj2ipxCtHY1seAjbTNrPsMheqzO31h138wwo4oMyby9wNBX1ieLALWUn93C/gCUj5LEiCpLZGphHrftHb698gHpTB3vL95KnLWQTvDADzvlOX01qvj8iRRfiurwQ3ZogwEpvIyupW3uXJGltXgZCoBm8ZEnHZ5iP3gNcfMpKDWX8fA7ikcBOz7QHPwL/Y6EvuT5G5D5OUlHI7NGn8cP7c/czk2dBUm3HDO7wg8sPr4F1DIVPAXGBOhBkdhSCyZ0cgIK0jiaiNtIg5vqQcacJEnku2sgP6Yasb+MECn0PRkzer44vVot5kmdIkyiCU0zQlKQl876mju5GVlBHdSORqJmbtompfIs4j+/WpKrc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31a869fc-9546-4ad0-133d-08dc842b85b5 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:04.3613 (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: y7Fjtomy25QGsiFuKGrYkqLC65wtNriGzWPkKVXKDQwsb4DqeqyeloEagkKlkZaB X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171618_631087_0502CCBA X-CRM114-Status: GOOD ( 16.53 ) 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 The next patch will need to store the same master twice (with different SSIDs), so allocate memory for each list element. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 11 ++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 39 ++++++++++++++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 71ca87c2c5c3b6..cb3a0e4143c84a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -38,12 +38,13 @@ static DEFINE_MUTEX(sva_lock); static void arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) { - struct arm_smmu_master *master; + struct arm_smmu_master_domain *master_domain; struct arm_smmu_cd target_cd; unsigned long flags; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { + struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd *cdptr; /* S1 domains only support RID attachment right now */ @@ -301,7 +302,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) { struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); struct arm_smmu_domain *smmu_domain = smmu_mn->domain; - struct arm_smmu_master *master; + struct arm_smmu_master_domain *master_domain; unsigned long flags; mutex_lock(&sva_lock); @@ -315,7 +316,9 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * but disable translation. */ spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd target; struct arm_smmu_cd *cdptr; 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 3f19436fe86a37..532fe17f28bfe5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2015,10 +2015,10 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, unsigned long iova, size_t size) { + struct arm_smmu_master_domain *master_domain; int i; unsigned long flags; struct arm_smmu_cmdq_ent cmd; - struct arm_smmu_master *master; struct arm_smmu_cmdq_batch cmds; if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_ATS)) @@ -2046,7 +2046,10 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, cmds.num = 0; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + struct arm_smmu_master *master = master_domain->master; + if (!master->ats_enabled) continue; @@ -2534,9 +2537,26 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) pci_disable_pasid(pdev); } +static struct arm_smmu_master_domain * +arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master) +{ + struct arm_smmu_master_domain *master_domain; + + lockdep_assert_held(&smmu_domain->devices_lock); + + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + if (master_domain->master == master) + return master_domain; + } + return NULL; +} + static void arm_smmu_detach_dev(struct arm_smmu_master *master) { struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); + struct arm_smmu_master_domain *master_domain; struct arm_smmu_domain *smmu_domain; unsigned long flags; @@ -2547,7 +2567,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) arm_smmu_disable_ats(master, smmu_domain); spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del_init(&master->domain_head); + master_domain = arm_smmu_find_master_domain(smmu_domain, master); + if (master_domain) { + list_del(&master_domain->devices_elm); + kfree(master_domain); + } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); master->ats_enabled = false; @@ -2561,6 +2585,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master_domain *master_domain; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; @@ -2597,6 +2622,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENOMEM; } + master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); + if (!master_domain) + return -ENOMEM; + master_domain->master = master; + /* * Prevent arm_smmu_share_asid() from trying to change the ASID * of either the old or new domain while we are working on it. @@ -2610,7 +2640,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->ats_enabled = arm_smmu_ats_supported(master); spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_add(&master->domain_head, &smmu_domain->devices); + list_add(&master_domain->devices_elm, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); switch (smmu_domain->stage) { @@ -2925,7 +2955,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; INIT_LIST_HEAD(&master->bonds); - INIT_LIST_HEAD(&master->domain_head); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 6a74d3d884fe8d..01769b5286a83a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -697,7 +697,6 @@ struct arm_smmu_stream { struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; - struct list_head domain_head; struct arm_smmu_stream *streams; /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; @@ -731,6 +730,7 @@ struct arm_smmu_domain { struct iommu_domain domain; + /* List of struct arm_smmu_master_domain */ struct list_head devices; spinlock_t devices_lock; @@ -767,6 +767,11 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, u16 asid); #endif +struct arm_smmu_master_domain { + struct list_head devices_elm; + struct arm_smmu_master *master; +}; + static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) { return container_of(dom, struct arm_smmu_domain, domain); From patchwork Tue Jun 4 00:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684502 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 EFF96C27C50 for ; Tue, 4 Jun 2024 00:16:35 +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=mt/RVSvE1AzWSbXAUAhngecd+uMTCHcKS0bzIW8aQow=; b=HUGuSuEqnSTjDR OE7gEwShS4bAlCM5xJp3cdpS2O9yvGMtZCkseR/3dgYbA4sMwP0QXHwQH7yXDDtA04JEnBCTj1Sm8 8C4Jh19RSS/dULwlSHAV3NpL7YKfao5XCH7UVsOF1w4S6vxDkK+lw0IQN2WGMbXzLs/bVky8Y1nuX Zl0cit7RxTH6/362zwdDps+oHWL97k/JELPN9TSHW08be9qqV1TJvaCQhOxoZRyYO/NpiM/hbAxzC cw2GVg9R9nZ+PfaN1adnT0qO8XkNqwPpQhBh8G6KvpVT1FiwfUDQi9YoQsO1+Alfr/sEuxj4yVktR 4KSr23bsjCadmtYwdOtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqf-00000000hhP-3VFA; Tue, 04 Jun 2024 00:16:21 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqX-00000000hYh-41l9 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RcfeihlrA0ggzFwiv/gFE1Ox71r+6TPYQfPI7EjEP+vYrxDrxanaN76solenG4IR+dra30k9wL2udQQavr1KT/2KehCmtZR6IEW+b39qTKFkzafyC+KA8H3ucqTCmV4aJUOOWzPgPkpS9tWEfzPti6cOKMg+9/TPbt3onY1wsFVytb7kp20eWRYNed+slObd9MEnEOrmu0UyIw1nPA4u/dkEZrP2FDdlpMw2Ou3FcKgw7YMYngmV08vMm1bBp4kQJESs/PE+SqEcE+mn+GSDr3yVi3PvYed3AjG1VAijsNfXjWGAmaykrRVOYaboUC4umaeI36YSIZqidt5n7dnSaQ== 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=1UiAN3lkYuJyAD+KkD5sC9LRM53icJKfANhch8J4n2A=; b=XTi9N0LA65Bf/3kWGlvsoOB+YaFQTP1TPQ3YMm2RLT0NoxO140VmJVxMF/nDtqEMvCs96XV++uwMED0yDeB+asVjcA7Y8cL+BnSDeFvrFomuVPBSrJScUfEbd2Odf3S4s32lF6AQFCuw1FAIZTZIloMc8UIzFqjUkzNEMgL4wKpsOFsyc876VfCttQbeEIAp8108S8xOaRrpFT8BQ+3+89OA0bOG9QkBPPVwMU3CCmVCFg4ndplxZc1sr/tEjql1dX7OIDK7sBodweYsFTTZvyoz+sZGJScBfN2233KOg2uJqyo3VrBpoCI+iORK9Pt65Kzyj+Ih6ficsz9iozKrFQ== 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=1UiAN3lkYuJyAD+KkD5sC9LRM53icJKfANhch8J4n2A=; b=Oo9PqRK/oDG2IJ1EhvvwCf7Fdhj/C9jQrdXlFkUggnJMP32lqJMf/0X61nO9WJbATfKsrwJqd7ZfdOh+mDMSZpW3GTf7mZ75lS1iE8qxfHG1fVvh2ZLMA5kAqtY2cVFeQsHaBl4HwsXnMbJh5uMU9fZGJAVg1pdZeQp8wZsUNTgKha30MNbfM+2BxckZJY/XL86w7LEOYmgZBIOJSp/hDNAHwZ2iNPYEvK0MBubVEWx4kbaMFikE1t8Nl4wYwMdPdAQyDkE1GbV7V11LpyDikkVj+M8E5LfqKF90ZebsPJzkBJEHfOPRGufZh5aZux/fjkW9sniu8z1h9nAwEQ/YdA== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:06 +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:06 +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 04/14] iommu/arm-smmu-v3: Make changing domains be hitless for ATS Date: Mon, 3 Jun 2024 21:15:49 -0300 Message-ID: <4-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: BLAP220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::13) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: 45977101-7236-490b-3864-08dc842b857d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: LKPwrx7tdsQvOD8Xsd1r5vtwtNmQhEzkgd0dtbQXApB+jZmtmq7Y2ywV9QHXhRgxv3B3eawN79GL1MBbv78lsfpQTASKKgNh8CriFeEerveAUiAls7km2ne3arAgVz8ClMSMrwvilten3sPrAv510B7vMRc2wAmQLeHyHYVESJyPYsLFlqExWY4cLsW7gk5ghzqq5H9oW5dlTz2lEGFzH2apTaEWEc6P8sFb0SaYMcm6OVgJOnrKKRAvnimFEEKfJ03CNPeADMSfxBypF8L52JwcjJ7EJX0wJlmtxnTapSS6Orwm+cw+AkY6gqW/mimyjjhNr/hAW4Iqd4Nu1Wtcp+xfrYqkgxXIGACkx4PMuA6SF/Mytb/lz3t5wP+ljqanAUoquFptT2Jy3VCVnbQ2BXW1yOXwlBQEeUpgZ0f47MAuK2mKe61NZAIHdSW/RR0MDblzUSQIsH66QzvJAoM6om4bLRGoD4HLff+X3g4lWMRncDOE/vXoe4VcHAa4KFhl4Jhjg/p25lWpMbkMpLJAfxIzX+ynb52ydtAfsmtjTomKZYqB154ydZpiMRApyNgWcn52O097A5CG+zSzSi+8z5Mayp8jui5Xxu3zsBrlOUVgj+2rKj2e4ZdGhi/D+8VcIoBgCiQcRcmRKQZDnsloOKBq78YMcKtnpDkIOUscbTl7hn41Y0LkDsdQrTpPBS/8I9WYatR3EXzrzv6U54PKpzB9w+Epf8UNDXKSLLHLak9y4ye99vNqjU0HqhF5lrXMP2+8GF/lMRIo75vKKaw2DbI60ZxNbIvAQeRjThl2BjPBRixo6eb7/ZG1OD9iE177dYJYVa5u4tVKcnm+Cw2G+SSu9arUiDhAA8D5kFbBWTg2RbVzXAptg+GqyXNhcvhpZ7QvWEuqVNaJFVXMawFz294Fxf/tnQhX6zki3VOYciGCm4lPn2m0lSF26bVbN9+GIopA7v+lwCR9rtLzOiLAdz3R9tpvFD2OQfCCCBA06lx0ChwwoHs6lb7m6ACebItdrK034sBJAUgzAun5T4NNZ2WnPIR3eM4nyqKs3cEgyVOY2hHH/UZL7z/kToOaHDgCi2zDQa7QwXVWUgfiNjlG/R4rVNr12NCVF9KAfJCyZyKr1mXgfQ+HNEzrH30O++BXnVERxClVxMxoKB3lHispCiXvOd4QuLtk2cCbw/WO/6ZV7T2U7zmTfrMWjo7GHtYU1rJsufaiP01ShqHjN+xKnoZlKvj2NWMud/jPHzMIM1ckErPLRtpsaUQ7+llBhQ/gAdj20T6Oc2e9+LFgkmMvuQ== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c6ccXQAe9z8ote6e1h8yWZgOuVAB9RlTo0BEx/L1iLtwPIw2EB2pe300VNWNhAt9qihvdIREzmume8rSFkz1y3ndoPFsjVv5LnsVCGZfxfTLqKHHXf2BV+nCidJl3DB6pu6hfQHZFPpBEVqKJ8giXrCQXn8a+GM8mlaAJxD63yeyANeVKZOYwoEc6rxjwaWxCClwhvK1b6ZXEM6oYki0BUKe3xuyM73m91k6CXerxVpwX6rM7MGwWTie2pWT7xBlueDMfzCVRxQa6uWMkOj3lt3wFxJHzjYpHGfLx1V9+07dOFJUjbWcLIB/Rks2ZqQVxb0wznEk0BhWP+PcJtcfMC0gvES7O8qLEJWCbmyBWoyJDALhLsK1zMeVvPOGG4MFBVH8iiIt3VLL8Jhg4x7arERDn5WKmqRHu4esw4+0FS6zMWVTm8gMw3PUfwGVRenNHazn8+kRDnaPVnlfOtxI6oA4TIPuftMDS+I1t3TcDpfUb85Pq/oj4Y2Wk414p1uTzvDPHqfr7DYHEfgSEWdip9v5mhKgoafkQNcZYXV58kBQnzuezg9OpTx/rNn8Dzm5DSt1NNV7xHEIay3+LnbWWS+Qr4MRoYdFJtZkRpeAVMwkTlyveL5oWuA0Km0lO6vfpy9crFbj50wKDHGNpX8hs1HXSugVDbzdX83s5lYs8UbLPSlyKzQGDipRblE42J6LXskl0vIj5zB672wiQXIcURNbYRDMoF9gjMxwMEKL9R8zd7Rt/nM1spI4SHxKR2h8PqguCLlPOrO8lXV0dPBxKJSuurwZDt+molcgi5iLL1XySfeJZBcoz1oFEo66BTPL6ixdx3xp5O9o1jskX+6HN1JeFvQ4qVqx/H9GIHWpCgfuqgfey0kdrlVxpgXmd0KCYS51ZxjY+8YgJWT50n/Ylif/flcJ3KjZHw6XWeoP2U8NOEHguwdc5mhOFkTYfCSpb6QIOEY8m81YeRxp5mcYx5MDb+J3J1+fnRn/GFJV9zbPNoIsSE0gQBUGqSUKtsLps3PK48ghSjwLaWrxNezPUN7ALtGG5OKf7El9/5X/fKTLfgxoFr18jzNK3TR7UP5i9HRLJeVuH9i9WXrvNjRproy0ash7lHjNcf6/AJYqkvKWRcmnIiz7Lmj8tyAoG5mK9J9JMK6u/5dmrp3lEZNISr3iUSgs2OfmvFnIQitrboSviFKupbF7pGN3VGE+6w6jrP5b9WlyhSFpRV32qlrjehrp3vS9t2lYX8iov5aKSdChW31s0AVKJs/bahEg03TofRLy+oEkixf/G3TPgMVb2OjoltS3tNMXyoO8AONza/+R7O/uyPNRlMNNVQUJAz8ASE7PjI94WAlwL45pGdovr74ypODmilb2mSKp2d5shj2P1DxmIHbqgGj6W4JWzDiRu3+P7Lise5qHJ5oLFn7cmpHqwKpFdO9BpmCwzAS62XnGsT3Gqk5wO1VVI/QHpQkauIKvigQYtd+K7G90pO8B7iWUtRedQ+UTB9H1+/2HKpDd2qQ0QfZsK1YwtqzcrLk9SgkfkTmOrNkdiqLXAr+ROnho2iaByVARMBJUKMvYX+8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45977101-7236-490b-3864-08dc842b857d 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:03.9945 (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: PPuDzCpdaKPNxCNv6hJzJr40VDP9rvYGE9NvwPJo7uTNzyrM4aTCF9u1+1vaBbVo X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171614_062219_F3DE235F X-CRM114-Status: GOOD ( 25.27 ) 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 The core code allows the domain to be changed on the fly without a forced stop in BLOCKED/IDENTITY. In this flow the driver should just continually maintain the ATS with no change while the STE is updated. ATS relies on a linked list smmu_domain->devices to keep track of which masters have the domain programmed, but this list is also used by arm_smmu_share_asid(), unrelated to ats. Create two new functions to encapsulate this combined logic: arm_smmu_attach_prepare() arm_smmu_attach_commit() The two functions can sequence both enabling ATS and disabling across the STE store. Have every update of the STE use this sequence. Installing a S1/S2 domain always enables the ATS if the PCIe device supports it. The enable flow is now ordered differently to allow it to be hitless: 1) Add the master to the new smmu_domain->devices list 2) Program the STE 3) Enable ATS at PCIe 4) Remove the master from the old smmu_domain This flow ensures that invalidations to either domain will generate an ATC invalidation to the device while the STE is being switched. Thus we don't need to turn off the ATS anymore for correctness. The disable flow is the reverse: 1) Disable ATS at PCIe 2) Program the STE 3) Invalidate the ATC 4) Remove the master from the old smmu_domain Move the nr_ats_masters adjustments to be close to the list manipulations. It is a count of the number of ATS enabled masters currently in the list. This is stricly before and after the STE/CD are revised, and done under the list's spin_lock. This is part of the bigger picture to allow changing the RID domain while a PASID is in use. If a SVA PASID is relying on ATS to function then changing the RID domain cannot just temporarily toggle ATS off without also wrecking the SVA PASID. The new infrastructure here is organized so that the PASID attach/detach flows will make use of it as well in following patches. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Michael Shavit --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 5 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 238 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 +- 3 files changed, 178 insertions(+), 71 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index 315e487fd990eb..a460b71f585789 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -164,7 +164,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master); + arm_smmu_make_cdtable_ste(ste, &master, true); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) @@ -231,7 +231,6 @@ static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, { struct arm_smmu_master master = { .smmu = &smmu, - .ats_enabled = ats_enabled, }; struct io_pgtable io_pgtable = {}; struct arm_smmu_domain smmu_domain = { @@ -247,7 +246,7 @@ static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.sl = 3; io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.tsz = 4; - arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain); + arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain, ats_enabled); } static void arm_smmu_v3_write_ste_test_s2_to_abort(struct kunit *test) 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 532fe17f28bfe5..24f42ff39f77a9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1538,7 +1538,7 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_bypass_ste); VISIBLE_IF_KUNIT void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master) + struct arm_smmu_master *master, bool ats_enabled) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -1561,7 +1561,7 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, STRTAB_STE_1_S1STALLD : 0) | FIELD_PREP(STRTAB_STE_1_EATS, - master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); if (smmu->features & ARM_SMMU_FEAT_E2H) { /* @@ -1591,7 +1591,8 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_cdtable_ste); VISIBLE_IF_KUNIT void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) + struct arm_smmu_domain *smmu_domain, + bool ats_enabled) { struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; const struct io_pgtable_cfg *pgtbl_cfg = @@ -1608,7 +1609,7 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, target->data[1] = cpu_to_le64( FIELD_PREP(STRTAB_STE_1_EATS, - master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); if (smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) target->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, @@ -2450,22 +2451,16 @@ static bool arm_smmu_ats_supported(struct arm_smmu_master *master) return dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)); } -static void arm_smmu_enable_ats(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) +static void arm_smmu_enable_ats(struct arm_smmu_master *master) { size_t stu; struct pci_dev *pdev; struct arm_smmu_device *smmu = master->smmu; - /* Don't enable ATS at the endpoint if it's not enabled in the STE */ - if (!master->ats_enabled) - return; - /* Smallest Translation Unit: log2 of the smallest supported granule */ stu = __ffs(smmu->pgsize_bitmap); pdev = to_pci_dev(master->dev); - atomic_inc(&smmu_domain->nr_ats_masters); /* * ATC invalidation of PASID 0 causes the entire ATC to be flushed. */ @@ -2474,22 +2469,6 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master, dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } -static void arm_smmu_disable_ats(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) -{ - if (!master->ats_enabled) - return; - - pci_disable_ats(to_pci_dev(master->dev)); - /* - * Ensure ATS is disabled at the endpoint before we issue the - * ATC invalidation via the SMMU. - */ - wmb(); - arm_smmu_atc_inv_master(master); - atomic_dec(&smmu_domain->nr_ats_masters); -} - static int arm_smmu_enable_pasid(struct arm_smmu_master *master) { int ret; @@ -2553,46 +2532,182 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, return NULL; } -static void arm_smmu_detach_dev(struct arm_smmu_master *master) +/* + * If the domain uses the smmu_domain->devices list return the arm_smmu_domain + * structure, otherwise NULL. These domains track attached devices so they can + * issue invalidations. + */ +static struct arm_smmu_domain * +to_smmu_domain_devices(struct iommu_domain *domain) { - struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); + /* The domain can be NULL only when processing the first attach */ + if (!domain) + return NULL; + if (domain->type & __IOMMU_DOMAIN_PAGING) + return to_smmu_domain(domain); + return NULL; +} + +static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, + struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain); struct arm_smmu_master_domain *master_domain; - struct arm_smmu_domain *smmu_domain; unsigned long flags; - if (!domain || !(domain->type & __IOMMU_DOMAIN_PAGING)) + if (!smmu_domain) return; - smmu_domain = to_smmu_domain(domain); - arm_smmu_disable_ats(master, smmu_domain); - spin_lock_irqsave(&smmu_domain->devices_lock, flags); master_domain = arm_smmu_find_master_domain(smmu_domain, master); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); + if (master->ats_enabled) + atomic_dec(&smmu_domain->nr_ats_masters); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); +} - master->ats_enabled = false; +struct arm_smmu_attach_state { + /* Inputs */ + struct iommu_domain *old_domain; + struct arm_smmu_master *master; + /* Resulting state */ + bool ats_enabled; +}; + +/* + * Start the sequence to attach a domain to a master. The sequence contains three + * steps: + * arm_smmu_attach_prepare() + * arm_smmu_install_ste_for_dev() + * arm_smmu_attach_commit() + * + * If prepare succeeds then the sequence must be completed. The STE installed + * must set the STE.EATS field according to state.ats_enabled. + * + * ATS is automatically enabled if the underlying device supports it. + * disable_ats can inhibit this to support STEs like bypass that don't allow + * ATS. + * + * The change of the EATS in the STE and the PCI ATS config space is managed by + * this sequence to be in the right order such that if PCI ATS is enabled then + * STE.ETAS is enabled. + * + * new_domain can be NULL if the domain being attached does not have a page + * table and does not require invalidation tracking, and does not support ATS. + */ +static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, + struct iommu_domain *new_domain) +{ + struct arm_smmu_master *master = state->master; + struct arm_smmu_master_domain *master_domain; + struct arm_smmu_domain *smmu_domain = + to_smmu_domain_devices(new_domain); + unsigned long flags; + + /* + * arm_smmu_share_asid() must not see two domains pointing to the same + * arm_smmu_master_domain contents otherwise it could randomly write one + * or the other to the CD. + */ + lockdep_assert_held(&arm_smmu_asid_lock); + + if (smmu_domain) { + /* + * The SMMU does not support enabling ATS with bypass/abort. + * When the STE is in bypass (STE.Config[2:0] == 0b100), ATS + * Translation Requests and Translated transactions are denied + * as though ATS is disabled for the stream (STE.EATS == 0b00), + * causing F_BAD_ATS_TREQ and F_TRANSL_FORBIDDEN events + * (IHI0070Ea 5.2 Stream Table Entry). Thus ATS can only be + * enabled if we have arm_smmu_domain, those always have page + * tables. + */ + state->ats_enabled = arm_smmu_ats_supported(master); + + master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); + if (!master_domain) + return -ENOMEM; + master_domain->master = master; + + /* + * During prepare we want the current smmu_domain and new + * smmu_domain to be in the devices list before we change any + * HW. This ensures that both domains will send ATS + * invalidations to the master until we are done. + * + * It is tempting to make this list only track masters that are + * using ATS, but arm_smmu_share_asid() also uses this to change + * the ASID of a domain, unrelated to ATS. + * + * Notice if we are re-attaching the same domain then the list + * will have two identical entries and commit will remove only + * one of them. + */ + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + if (state->ats_enabled) + atomic_inc(&smmu_domain->nr_ats_masters); + list_add(&master_domain->devices_elm, &smmu_domain->devices); + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + } + + if (!state->ats_enabled && master->ats_enabled) { + pci_disable_ats(to_pci_dev(master->dev)); + /* + * This is probably overkill, but the config write for disabling + * ATS should complete before the STE is configured to generate + * UR to avoid AER noise. + */ + wmb(); + } + return 0; +} + +/* + * Commit is done after the STE/CD are configured with the EATS setting. It + * completes synchronizing the PCI device's ATC and finishes manipulating the + * smmu_domain->devices list. + */ +static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) +{ + struct arm_smmu_master *master = state->master; + + lockdep_assert_held(&arm_smmu_asid_lock); + + if (state->ats_enabled && !master->ats_enabled) { + arm_smmu_enable_ats(master); + } else if (master->ats_enabled) { + /* + * The translation has changed, flush the ATC. At this point the + * SMMU is translating for the new domain and both the old&new + * domain will issue invalidations. + */ + arm_smmu_atc_inv_master(master); + } + master->ats_enabled = state->ats_enabled; + + arm_smmu_remove_master_domain(master, state->old_domain); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; - unsigned long flags; struct arm_smmu_ste target; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_master_domain *master_domain; + struct arm_smmu_attach_state state = { + .old_domain = iommu_get_domain_for_dev(dev), + }; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; if (!fwspec) return -ENOENT; - master = dev_iommu_priv_get(dev); + state.master = master = dev_iommu_priv_get(dev); smmu = master->smmu; /* @@ -2622,11 +2737,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENOMEM; } - master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); - if (!master_domain) - return -ENOMEM; - master_domain->master = master; - /* * Prevent arm_smmu_share_asid() from trying to change the ASID * of either the old or new domain while we are working on it. @@ -2635,13 +2745,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_detach_dev(master); - - master->ats_enabled = arm_smmu_ats_supported(master); - - spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_add(&master_domain->devices_elm, &smmu_domain->devices); - spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + ret = arm_smmu_attach_prepare(&state, domain); + if (ret) { + mutex_unlock(&arm_smmu_asid_lock); + return ret; + } switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: { @@ -2650,18 +2758,19 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, &target_cd); - arm_smmu_make_cdtable_ste(&target, master); + arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled); arm_smmu_install_ste_for_dev(master, &target); break; } case ARM_SMMU_DOMAIN_S2: - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain, + state.ats_enabled); arm_smmu_install_ste_for_dev(master, &target); arm_smmu_clear_cd(master, IOMMU_NO_PASID); break; } - arm_smmu_enable_ats(master, smmu_domain); + arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); return 0; } @@ -2690,10 +2799,14 @@ void arm_smmu_remove_pasid(struct arm_smmu_master *master, arm_smmu_clear_cd(master, pasid); } -static int arm_smmu_attach_dev_ste(struct device *dev, - struct arm_smmu_ste *ste) +static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, + struct device *dev, struct arm_smmu_ste *ste) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + .old_domain = iommu_get_domain_for_dev(dev), + }; if (arm_smmu_master_sva_enabled(master)) return -EBUSY; @@ -2704,16 +2817,9 @@ static int arm_smmu_attach_dev_ste(struct device *dev, */ mutex_lock(&arm_smmu_asid_lock); - /* - * The SMMU does not support enabling ATS with bypass/abort. When the - * STE is in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests - * and Translated transactions are denied as though ATS is disabled for - * the stream (STE.EATS == 0b00), causing F_BAD_ATS_TREQ and - * F_TRANSL_FORBIDDEN events (IHI0070Ea 5.2 Stream Table Entry). - */ - arm_smmu_detach_dev(master); - + arm_smmu_attach_prepare(&state, domain); arm_smmu_install_ste_for_dev(master, ste); + arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); /* @@ -2732,7 +2838,7 @@ static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, struct arm_smmu_master *master = dev_iommu_priv_get(dev); arm_smmu_make_bypass_ste(master->smmu, &ste); - return arm_smmu_attach_dev_ste(dev, &ste); + return arm_smmu_attach_dev_ste(domain, dev, &ste); } static const struct iommu_domain_ops arm_smmu_identity_ops = { @@ -2750,7 +2856,7 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, struct arm_smmu_ste ste; arm_smmu_make_abort_ste(&ste); - return arm_smmu_attach_dev_ste(dev, &ste); + return arm_smmu_attach_dev_ste(domain, dev, &ste); } static const struct iommu_domain_ops arm_smmu_blocked_ops = { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 01769b5286a83a..f9b4bfb2e6b723 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -758,10 +758,12 @@ void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_bypass_ste(struct arm_smmu_device *smmu, struct arm_smmu_ste *target); void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master); + struct arm_smmu_master *master, + bool ats_enabled); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain); + struct arm_smmu_domain *smmu_domain, + bool ats_enabled); void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct mm_struct *mm, u16 asid); From patchwork Tue Jun 4 00:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684500 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 15F72C25B78 for ; Tue, 4 Jun 2024 00:16:29 +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=OgCMoWK+2ZGOhMQQoHXLj+Pg7jmfvEhEWW/MAdCBRFA=; b=jQciHRDGocyKGA Ud1yVZ6C2paUyENvZXRRLbyJoA/IjToNmB/CAH9u3FjmPMfOzNF0A/VykaUyKwnj5VyMp2bK7EjeH pgnT4DcXbBOypyS5/Sg4DcGjnDp5jjBOHkmRtxyoCxs/vTHpxBH+LbPUEs/MIQJJrX5Z4xBW1xO/7 e0dQD+r5sMxoOxLQbnfquyO6M9hwZIgRSOCsGujTq8YXsSer19blR43Sedypy6wdEXBjGyA96pVb3 QQYLB3nogvaOe1FDwGMsYbby2JJiEaV2alWu2XP2zCl7Ik3u3c6/TQ3eLSDRL9v3PkcWO9kAH6/tp OsR1JE/Yl0DDpsYImGjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqa-00000000hb6-0Vzy; Tue, 04 Jun 2024 00:16:16 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqW-00000000hYh-1cPB for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VM4A9eDhEmbQ+5mEfSDZTxajslDPLpHL5ZqypJiUTs7/8bEQDuXdweZUSWXGloblL8NmmeQOdS8aqOX5BTdVmikVz4Vjp+FNjBGzzy6y//x5Nc/VyqU273F2Nul6jr4W5n8uJEP8kRM7+gk7LPbK0PaT4ijGE1AEtftUllylY83YgPd6KjwOG52hEKLOmX0oIc8VZabrLd9Vj9VGjkwa4+NZZ+HH5SNzzeuOXRaeS2peZpuw4A5Bwu1BiCeiBsUdfgKJldEHkdzUe38bOCGvO7GO7v0lGMFfu+zaECqlcOyMjgHXCjg8OniSxE7Y9pXW2u3wkE458EnAIXwaxPVysg== 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=cQ+oXPaH2Dvdsl8ipr4Ab/UcVTtIlrC+HUgz666jeGw=; b=S+2mI5w2JLgAu4tPH/2gFsSz7wf8Un46pude3zKd+3VcQExPasdZFJBi9+QxcZlltKeixJMy5xi3aYGgK6WDzC6b+zITSfERZkmkeT46zxeOmqOHbWLfSOS/tTWt/R3hdiRjHv4ljrH65kaUiDPeM9V2ZJQ6eIYTtFRQ6lTQRbWbPe7OL2fyFVN33hAHRKAvhtdcV0xX9O6gqOpDDKfuhuqZcXaZuFRdVa/et8Qtgn+/PuYC/H51waO77LiD7MQZXtniLT0ZBIzBTfHnIWD9I77rEGwVbyhWSsKwOV6t9I3h3D10llFp61/qWJFjlyOEE6qAcYjDoNsJGMtPK1kdjQ== 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=cQ+oXPaH2Dvdsl8ipr4Ab/UcVTtIlrC+HUgz666jeGw=; b=kQtebnv+dtuzlM7n0HmyMb/csINOaS9BPVQwHOMXJVVfRp8QQLp6HsghKkrw65I/XUBnR45SuEPDm9SKf6NpXBBkuzQp0Cgw7AFF2B6thnoGj22VAnq7BHY7+wHpIQKMGccmc0zhmC5lK/rPb9ZQuMBwAbXs0pj+VIN0een5ipuTkPYKiEVEPDUaimkta3HbCv9IT7qALi99b9WGTwms5FlPPraNbGZPO+9Nt1gcthhYHm5vEXkZYKjZXN8xR6ayEeDAIpojUQzpI0+IKa+LERhlJyqzzDE8Xh6suY1/kU8TT09u8sHH0ntJEBXksH123hZq8qpOAvVChrFSMVZFdA== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:06 +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:05 +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, Shameer Kolothum Subject: [PATCH v8 05/14] iommu/arm-smmu-v3: Add ssid to struct arm_smmu_master_domain Date: Mon, 3 Jun 2024 21:15:50 -0300 Message-ID: <5-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: BLAPR03CA0092.namprd03.prod.outlook.com (2603:10b6:208:32a::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_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: d32fc7e6-d5ff-474e-8cfb-08dc842b84dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: medzyDOTDGGuoWXoPwj1jX8E1FzDV2Lql9DCXKPozra0JOQKefVeGi7ROupTqn3X+vsfHPomaWUrM3hmeBy/Cwf2IeKxIytsF6Jnw4k47K1hYjiLhkIU1FCxVBFZ4m6ChS5H/l7H6cFJdU5IWWpGdFaQnr3x806dHO0cFrx+oOHhfpDu+OEsFA6zgUZfDow6XuqO+dNxu5/rPbX7F3MpBbNTMODYtebSFRvMGZfgDbDo8LreRWYqUq65cKtNvc7wN052hdMx6F9umI7AhDLeFOwp5SVYwzTsc1cIPa5wjcTq6H0sD1xEgAGvI2zCxU9kTjGjmFVZ9u8VSMSQa0mLSKEyK1yBoFjkxRSl1AO8c1nzacCnk/KqWRrGf8ApQ4dTzAHBBnsPbMZP/n/BSEE3cgXyCYFASdVn47rb1v+nciEVaoSZD19oDZ8fnSsJ/PNbQMYhYjg1eUfrS6jbjpc/wJwyndzEKPjs/mhGcv2S39QXK2qD6n0brRpri7WSXucKCEk4u5aIQ0G+UKRsn5dT0nc0wBgKaOVlm34yEPTp1nEOM3O6k/qwd6KzoyEVTaRMJ/DmfLfdR/7ifu5S1BmZVh6rq9bX7Kf2/Tw0c9owHk321+QgLbM2MSlcU7775kd0cjxcmCBFbw/aek5WhJ8eX/1JJGL9ozvHjJslODFd0i8v8jZLN43XUkhSnDXrp09hzNR3V+eMCeTvFeFpzZLCxKTgJ00YNmrnXvOdFwaWb6BPsaFWZNwfw00BHtOTMBqaj76Ur8bwgduanJber7GNmfqCNZRAkcONxlPcXPW5eC4DifwXQDjMpRGH6b2sHXTifqWNJe2mkxA2DRNEy3PDgcEIsrmYbnmOszsdgEknIiLtc5Es9k/FttHJAxka1+S+gRH5ishlRsuc7ZlFUHMnRqLAzRY2Q3jY7CaZghzfOnDvnSqm6UGdlNCDGxtJ3tAKJa8IGAT8EMlZQL8IUbThKtULtH5vVkPgABzk0w6pBfyeXsGmeauzuTsd4ZBD6WL86m+nmKaGCSVHoMW+pztzo7jB8tEVGzmSj5TEO0LPMoMfEnAsJf88FFxufOvau5uAbn8nj+ph2H6YBrZjLU99YCkzpsQcAHM+HttAriHcg9svuvgiKXf85p0e/NfHhO0oAhL+XaOP0xmPl+XxiI5MDyeSDRjcDrfBVXfidfxcQXyZGQgoIgjDmD1FxubjVPcjyr36XbIUDzS7k1kExu1iGEGmXe2QcCv81hdCwMX6REg4PR3V3JOMWG31xukw8vfymwH/31kOyl7OobCdTwbKcw== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Idh8VR1xBUROFzlKDVoAkYVCF87oMpncIz/KcjQ7JxmMtPG576THq8MGyOoMAJuHF4znVDvTKlY9zqxk8Rmt8i8KLdhiNyLfMqlaWYYXBobLV9190BbRsNbZajMx9MMOUCnq8Fd8qQ8a9e3HehcdqGkSz2RpbJlE9goBKjt+4ft3TVBk0tA/Yd0eQou474QaV0TjLf9Ot6Vtemzxy66BiiXpHa8CKD9m46nyvoDs4TOu9HUlwQ32M9n4aU+jsk9GoAprgqXlBw14KMZGWDFkr2DCtSECRRogN9b8W0aim57X8cs9uM+13N+C2hcxe0RRRXXkFrkeITHHj8XpP+M7D6dDAE+YcdJIiMbIAjXkKajq1o68JDU9tsbb+E/QePnIHpqMmV3ruu6Yv2FmVDzGr01ZKEvJxV39jXXIX9B93yohVQrlORcwEp4w2MRm0+EfavhfmlA74aiQJjoTlUSuuBTn/EvNkldXVoYXfPkEcww8WBfyZCv6vmEdkBZexbSjrPaSequ5enE6CssAHWsDBt0Gq4Lu45duP7Dxnf9Pqetl2dMXi9/mFS2dlstMTuQ9OGSUUJv68anJJj5wNtJIUr4oUcGJqyGzECRN83xknk6KSe+1098a8C/R3p72UtkPKG/eFHDl/Lq9fOAGAHj5/tP0m3eJBA85Dg8wn9wK2wNY4fA0UrlopndtznK8uPwBltoyU1w4eZD9L/0yRMrZtJ8HgPg+b8xtMy2pxFolbwBtojYyOhuCid8cW5QG60yaS4LQDAXmSYpmG/XwY7/HRV+7pJ+IJvXkUhypXldpn+98ILWZ1RRg7/1tu4AQnemDtj4RwvfXKeYTlw8W3YrqFRXKYk8Qq0XAC9GRk9S4dbE4+VShbyvZB/d9NpzpYj3zhMEUO768teuogbrSxtViA85kpIeQL6Rs+ew1iZJlQIps/D8nfIz7QMbitxUD5RC1gMGQIEafMjqoeEAtlC5WyVLyrHTxtbT96ClHfN4j1mERuJL2SJdHPVeg6p06Y+XBUtrkzLJHvUZgNmBPE7C9b2akB6jR8tdV+gnbbf4S6YwePSo30AHfMM8Jbw68Vy/3i7LZULQLTwu+6z6TJDc9CAFDSiaXSAHB0AAID7WOx2P/ou2secybtFfTtYrR/IySxkA3w90/Lrdolup26Vov5rJuuSUfjYFGG+WpKAAkaSc5tLTXn/498vM8Rb/ymTSpUchRo8AU/jZLLr7iStv6yUMAYsqbGNaaJ8S7lrA51/qJVVpvXoGmtIUMNRmn8fEkIY/maz3ckMtDZQmFtuLTP0RCOdKic97rddA6NuGgCvdR2yJ3eHH71ayOtYs5vUM3xBbdyJ1scqiobg52i/3blEFDnAoM640yTH5UBkWlsZSY9Q/ijJ6ozxRXZYb0HsHZkHnRE/pacF+p0njUEeJuUujN0yV7h6BHOrJoG6j3S4P/nP+zTwky/BJG/1nqQRYue8obV41RKjzGlKqxq4y5vbkTjZWefdmJR1pHyiDf23sIASVmQSsIiuv/an/+slFbLrDVw0DuHgf1g7d654NASIcbxAZ/RbFmOYf92Pgl0h0= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d32fc7e6-d5ff-474e-8cfb-08dc842b84dc 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.9130 (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: CrWgfYvxojsKhLIzq4ThcAWCEuRLQMyqgHuqz8slKdlEWvXJOJSTRSkT8jPol9Dj X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171612_513694_C37DE947 X-CRM114-Status: GOOD ( 15.76 ) 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 Prepare to allow a S1 domain to be attached to a PASID as well. Keep track of the SSID the domain is using on each master in the arm_smmu_master_domain. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 15 ++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 42 +++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 5 ++- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index cb3a0e4143c84a..d31caceb584984 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -47,13 +47,12 @@ arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) struct arm_smmu_master *master = master_domain->master; struct arm_smmu_cd *cdptr; - /* S1 domains only support RID attachment right now */ - cdptr = arm_smmu_get_cd_ptr(master, IOMMU_NO_PASID); + cdptr = arm_smmu_get_cd_ptr(master, master_domain->ssid); if (WARN_ON(!cdptr)) continue; arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); - arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, + arm_smmu_write_cd_entry(master, master_domain->ssid, cdptr, &target_cd); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); @@ -294,8 +293,8 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, smmu_domain); } - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), start, - size); + arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), start, + size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) @@ -332,7 +331,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); + arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); smmu_mn->cleared = true; mutex_unlock(&sva_lock); @@ -411,8 +410,8 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) */ if (!smmu_mn->cleared) { arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm_get_enqcmd_pasid(mm), 0, - 0); + arm_smmu_atc_inv_domain_sva(smmu_domain, + mm_get_enqcmd_pasid(mm), 0, 0); } /* Frees smmu_mn */ 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 24f42ff39f77a9..674884a8fe25ba 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2013,8 +2013,8 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) return arm_smmu_cmdq_batch_submit(master->smmu, &cmds); } -int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, - unsigned long iova, size_t size) +static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size) { struct arm_smmu_master_domain *master_domain; int i; @@ -2042,8 +2042,6 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, if (!atomic_read(&smmu_domain->nr_ats_masters)) return 0; - arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); - cmds.num = 0; spin_lock_irqsave(&smmu_domain->devices_lock, flags); @@ -2054,6 +2052,16 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, if (!master->ats_enabled) continue; + /* + * Non-zero ssid means SVA is co-opting the S1 domain to issue + * invalidations for SVA PASIDs. + */ + if (ssid != IOMMU_NO_PASID) + arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); + else + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, + &cmd); + for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(smmu_domain->smmu, &cmds, &cmd); @@ -2064,6 +2072,19 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, return arm_smmu_cmdq_batch_submit(smmu_domain->smmu, &cmds); } +static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size) +{ + return __arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, + size); +} + +int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size) +{ + return __arm_smmu_atc_inv_domain(smmu_domain, ssid, iova, size); +} + /* IO_PGTABLE API */ static void arm_smmu_tlb_inv_context(void *cookie) { @@ -2085,7 +2106,7 @@ static void arm_smmu_tlb_inv_context(void *cookie) cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } - arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, 0, 0); + arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, @@ -2183,7 +2204,7 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, * Unfortunately, this can't be leaf-only since we may have * zapped an entire table. */ - arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, size); + arm_smmu_atc_inv_domain(smmu_domain, iova, size); } void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, @@ -2518,7 +2539,8 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static struct arm_smmu_master_domain * arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master) + struct arm_smmu_master *master, + ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; @@ -2526,7 +2548,8 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { - if (master_domain->master == master) + if (master_domain->master == master && + master_domain->ssid == ssid) return master_domain; } return NULL; @@ -2559,7 +2582,8 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, return; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, + IOMMU_NO_PASID); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index f9b4bfb2e6b723..f4061ffc1e612d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -772,6 +772,7 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master_domain { struct list_head devices_elm; struct arm_smmu_master *master; + ioasid_t ssid; }; static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) @@ -803,8 +804,8 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, struct arm_smmu_domain *smmu_domain); bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); -int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, - unsigned long iova, size_t size); +int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, + ioasid_t ssid, unsigned long iova, size_t size); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); From patchwork Tue Jun 4 00:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684501 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 6A410C25B78 for ; Tue, 4 Jun 2024 00:16:34 +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=gRUriUWXCAepnD1ncQhmymMEiOI6I6HI5FNZN/eZZlY=; b=4QwCJ4HgcSxNfl GfCjD22Pq6uUUsoKaJs5sNakRbTw+GOEFkehg0z4XFMNczhSnkcqggEB9j8DzmJiZ8E7TKFNy84ic KzNcBl+Gg0SENogw5Vr/ZefaGNajrFFDsDUEb6ZiCkJnYJg2wK99OgqCGkReyyuODk0noMJWZNDtQ YvrhVBnZcEZmHpVrfcg0t+B6PFaTWK4jynhqn6mrXFEiB6sh94flximNWX5tCy6l0Ssx7gaCYVa1P pVjTWp/G/x5pB6NPY4U6CPLXMFkZ4PQ+ji0PpnontJt60kz2I4ITalnw/IfR2bfwpgfuoVUA43O2K mU9vXpETo38PIvoxLGGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqh-00000000hjj-3q4i; Tue, 04 Jun 2024 00:16:23 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqY-00000000hYg-2Sol for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SobPOetwL4LQ16TN4l/ODjgs7kjn/NrS64FtagdMGSf1hP3GkWeIb2vYRAToRkZtYDfzlwmvNPzJB3OIeRLxvDJw+JEusnfvCAFDnmeazYruQM8om8F8HmLBFPb/lnir1u0uoukgHyg+bMRf3yvjTvBNlzZMrEk4BvS0BrqLoUrSopXS24JrJuDPWQCJ/ChvJ9Ugo7Fjb1FfwtaOVpseUiv5FMMMWGRaAJWfacuylyk2UXISTuhNmfrj2ARezKBjZp3DES10qVsbKK0nSCiY+OzcsigjAFF3c/toM3Xooe99hat09LSQtfghl7FKnK/Gsl2dtrFaIAIb/7sx+aKtGQ== 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=ruK9xLbDf+EHyfO+ItDfSn2PL0RAG5FtKdpPgajNoiM=; b=mxjfTsaMgr2jeSAd2jK6xxFI/bmgs/B8H+9tcUOZw7oW+MbWP/Utiu7IDzeT5kR/ggxCzuZ4UpoCcKFD7xvQUfzWH3oZhcCGvQd4s7jiwV0X0iChy0dbSi3/sfnoLZ05jlLARX0NIc1BbCU5p7KdSiioWK7xXXhdlmtFLAdTeinHU4+5UCbY1hEus7kwm0WUYQFPZ48EoqgtMWKD2vs3MZyw54iSxE/LoFgmLOhtcMUQyWadfSaZlk5j6/zsr2TVn3bJBKj3qTRIrE4T9jaiYhZvAgS9c4oRccqrXS8WMY4Sy4Uy+fag6fFBs591+kbScdqbyGEB15qCJEo3x8zU6g== 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=ruK9xLbDf+EHyfO+ItDfSn2PL0RAG5FtKdpPgajNoiM=; b=ah1fC73ARqzPplPuvgP9ZOZqT+8Eoq5lH9dGLGjnO0hchFW/wlmgHfEOE6cfihz68ZZAqqYijsDyw7PbA+jyvF9w2Hnnh/jwRaVVVB+Dd7znQH02nJWXd5XY+24PI+OCV+ugUPyXuU4Tvd52oKoWGDeV+ckp1UoJPqYTJllSKSlo8dBfBfzvXivLRwYt4jVShuwt+WppLkQteZwBQbG0xDRdAyMYtNoXMTPTmw6/iy8s2gbw9AFY94+xrZI6zeOdh5eJr1cwmzLTVaTVw0dqpjIjCmEnVW0osCKPs6IGo/g9wgmsqxpjgrh148YxtkB9IL7UvTmtQr/H5efLBvQR9w== 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:04 +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:03 +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, Shameer Kolothum Subject: [PATCH v8 06/14] iommu/arm-smmu-v3: Do not use master->sva_enable to restrict attaches Date: Mon, 3 Jun 2024 21:15:51 -0300 Message-ID: <6-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: BLAPR03CA0111.namprd03.prod.outlook.com (2603:10b6:208:32a::26) 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: 9c4021ce-a84a-4e55-6b71-08dc842b84ba 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: oH8cakvVHxT9FJfe6uUDI0Y/Vr+9ASb0LF8+MYNieaZNiOzJb5NMJ9MdcUuQwrz8JNPm8AirYAQsKLMD+mZef0tOvrSK5774dd4u0te7M1mbmA629xFvVoGuI8USIxOzvYLenkpN5EOIU6WNHW4viRsw1GG+fyWiXGBIjICTdWcx49yG6jRDjdJUMSqJo+1qG96kdUAnX9W47ll3kuv93VYscwORnkUI1zHlILVbEzqN9LVPhCLw6+V5f9VltKj8q1S05MfYjrHCcQt3Nm32CWvNCvd0UGhTNk34j2WbYYoSMB7IuGYh0yb2cGfmt/LNy5UFA7jkn20BOPj7SPy/XSsTK7iTFkIO40U7U3C3kNjuUoACjfYiPwyYr7B5p1FN5l+TY+uO5+EFCRsqulLCz9JaHpexazVsF3621vlYo+n/GRHRygYbRvwcJxn5cmzJp3kWK40l8/xrF0uALkH+BrGedURdYtGHoLzHhF8iCrpaxZVA2dI6lQglHUM7a6wKWP25BHDAew9tzGVXsKGCAN15xjT/C804j0QWe3eApLAPtP5jpVRAYOlfXkHdh9928u+kLXMuUPiBevKPLx3BTm1hAP/XRj2KaD5WxnEc0YZN++hLdE1nguE5iWfO1V/g57AfohFmeBH+d8LrWkPDbV4RyVViYjQczHVPkpW+k7pdCJ+U1Mf8uEcpfXo0pYhGQlOs2XNCxjGxmDhnDgZL32kHiK8vzIfm8Z7/SzOR3cfHhJ5tj6Smx+OgU1+JNAAZZiDIi6c9E+9PF3v2HeIqF4RLIARd//qU1ll+t6zojECsSmVcKkMQRBdGq4BFh5HhznD1bqq03d1UXJExWwFhmI3widqbQDinxgIFv8EZcP/X3peeUvH8jXUW+SIsPrxBE08wD9OZ9krRlD1HYyet46kafyJt4OOfgsk6fulkMumVat72HpQK4vDgt1Aa8VnZq+hOA4MfG6JjEakU3TYOwI0Ue3G0cmQQkBkK8IkWqFFIJ8daoutHssW+xLZKbXX0ulI6rkfFTsAQT7U8Cgxrxnr6Rczib16iECHkvGJHqQXmiIaus5p9q1W576NITCI/dqPrWSbBBH4iUtQfOolmHimetiydVEdO6MyMZZnQgqzFTC9l+fwUlA1zfV/B4psvOwDJYzXQ4jl4kVxUBLCcXhVGRCIP6QQtW8Kg/VQMoSFLXXAMC35mg7YfcDtJmoaLpA+8wPbDnddsrKSrvfV5tL4+308WKs51bnuuFGl1GJKsPSn2tLC19rEVccCj3RsfIlQ09p3eHRXQI1MOCfsLXw== 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hlxcE3HLfRqgTND1ENKwbz4W0WM/HVeBPS+07qEMqNZt2si9MhPGOolmp+mD8mbL4LnEEAULKNF7+UE3wguhNfjlkF5sd1ZLKSoEwwDZAVbBqqikVVLHtLJzP0RE8D5nmGRKYowwKk/N43quUt05a1PQgKpWd7ixfnkFDsME8wmrc771k63uMpzSscHYLF54VxW+5Ez/2YG/gopJuZpEcIqzUM+JlxgQdvW2kaxrcn56Poq2sUWA6q2BP1E9phjruU0Lr7IYB01TNI/xjMP5wpqd6aDQGXQUERewrow99Pt7WAITWRRIucK5KJSb5LxUTvEkz+VU8x+q9SFBdkRXzp1BYjGs3dae4ZG1SoNVFM+v8CqQybYLabadQAFIRFCRWr93fwTC3XaEo2UtuVm1uhkzjjw1MO3CRBUqReJwOyZ3T4OUUnU2gHpiwZX/aZ44BPssC6p2bUjcZn/MzTGUlRBUJXenkmy5kDya5sb7skgs2P7kn6I8Wps2bh0zRsWZERezGQws1LSw2qtUrjYbIrCrWbcHwladxQEid5w8kxXJliMSSwLwyVNvrwyXPeQ9ReZhG81MVBW3rBYewrq2XrzNnX4SJzSC0vNS0InBEnYUM7cvSoNXyFBOEZDja20FjeIjqxWbulI25cQfxMLpjTxDo7NOd1ymt/RCnuE2FwfFoJTaq+sUzILc3/9L8NQojpyTPRvTNJUGqopxVRwk0l6X/TNeonXImCxunxMkXXOHcfNrSYOM5CFBLsZKtbUgnyAJf1UR2hA+LH11jVoxmAS37FPDyTeZsb/2xDofjlEbQnQXJM22n050IRPuU3UsJbEY3Suo9AjEapRx3OV4nlwXYg1bbbcYrqllX/xxGmxxyDV3sp7FKBdaR0HIEq4beOxg3bgP7TWDC59Z4+ZaoVUIkoSlJ5nvou29A2gw8wuZbncWkp1ppwel4HXozC0kjyDI4SK+N6naiDeL6R/VbmaBXZJ+NJktmSfVzgHWPiShafw2FfNusUiQmPz68PDydvYkiVD2BWr9hGiD+RFpy61ISvZoAdU1sMgrFAQlLeQtWts914u3nGSGvvVsPcCI16816j0ccJn7Kg6NoUGCF6DkYPyGk8erU8ZezUaBgf8XSRmd+8drBdqjLOwKs2AsyFs7/ONaQIVB46Dzp9dh+VF1ppxI3v53St2dI8hI1WcbdXMlW8bY6WRqeECGcM/FheARx4rBsMA3Tzmiux5IqBdFapmTIhCDb2Nrnv1f2u7bierX97R/sK6JrXhSzWFWNfJ0Pu0yAO/1cJlqy9RvMoAh22p3D109iJARvDVYEaPZp9iykADgC5KISrbBvV/tKNrhF5gLTSz8T08eizjcNhzwNyfpMNGUHJFnkRMCrmK1/os8GwIyBWEvKNT+B8HXBNp/JLfJGS9xpwk93oCon15BQC4YJWaxedaWc5rwg1af/uFvO/Y3oK1Uoam25fIMdyIg7dXTmOr7C19IV188pfhxkLNK6r4RBGhoFyerBItfpQybo/srtmIlmOAksDPYmNRhQgQf7UTrOIpWE+O0wGhb/UC9pu/phTwln+6RKgw= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c4021ce-a84a-4e55-6b71-08dc842b84ba 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.5855 (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: sJSmsLtUpF09mtI0+WszpsXHzP0WBKqKA53znWQJe70BN6JhS3r/jz6nTEKKe1AI X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171614_683984_3BBF7944 X-CRM114-Status: GOOD ( 20.93 ) 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 We no longer need a master->sva_enable to control what attaches are allowed. Instead we can tell if the attach is legal based on the current configuration of the master. Keep track of the number of valid CD entries for SSID's in the cd_table and if the cd_table has been installed in the STE directly so we know what the configuration is. The attach logic is then made into: - SVA bind, check if the CD is installed - RID attach of S2, block if SSIDs are used - RID attach of IDENTITY/BLOCKING, block if SSIDs are used arm_smmu_set_pasid() is already checking if it is possible to setup a CD entry, at this patch it means the RID path already set a STE pointing at the CD table. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 ++++++ 2 files changed, 19 insertions(+), 12 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 674884a8fe25ba..e7cd1ddc03517d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1289,6 +1289,8 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, struct arm_smmu_cd *cdptr, const struct arm_smmu_cd *target) { + bool target_valid = target->data[0] & cpu_to_le64(CTXDESC_CD_0_V); + bool cur_valid = cdptr->data[0] & cpu_to_le64(CTXDESC_CD_0_V); struct arm_smmu_cd_writer cd_writer = { .writer = { .ops = &arm_smmu_cd_writer_ops, @@ -1297,6 +1299,13 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, .ssid = ssid, }; + if (ssid != IOMMU_NO_PASID && cur_valid != target_valid) { + if (cur_valid) + master->cd_table.used_ssids--; + else + master->cd_table.used_ssids++; + } + arm_smmu_write_entry(&cd_writer.writer, cdptr->data, target->data); } @@ -2734,16 +2743,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) state.master = master = dev_iommu_priv_get(dev); smmu = master->smmu; - /* - * Checking that SVA is disabled ensures that this device isn't bound to - * any mm, and can be safely detached from its old domain. Bonds cannot - * be removed concurrently since we're holding the group mutex. - */ - if (arm_smmu_master_sva_enabled(master)) { - dev_err(dev, "cannot attach - SVA enabled\n"); - return -EBUSY; - } - mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { @@ -2759,7 +2758,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) cdptr = arm_smmu_alloc_cd_ptr(master, IOMMU_NO_PASID); if (!cdptr) return -ENOMEM; - } + } else if (arm_smmu_ssids_in_use(&master->cd_table)) + return -EBUSY; /* * Prevent arm_smmu_share_asid() from trying to change the ASID @@ -2832,7 +2832,7 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, .old_domain = iommu_get_domain_for_dev(dev), }; - if (arm_smmu_master_sva_enabled(master)) + if (arm_smmu_ssids_in_use(&master->cd_table)) return -EBUSY; /* diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index f4061ffc1e612d..65b75dbfd15914 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -602,12 +602,19 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; + unsigned int used_ssids; u8 in_ste; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; }; +/* True if the cd table has SSIDS > 0 in use. */ +static inline bool arm_smmu_ssids_in_use(struct arm_smmu_ctx_desc_cfg *cd_table) +{ + return cd_table->used_ssids; +} + struct arm_smmu_s2_cfg { u16 vmid; }; From patchwork Tue Jun 4 00:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684498 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 42CE7C25B75 for ; Tue, 4 Jun 2024 00:16:28 +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=z0uzfHWO+WAwdxAPJzquHXfq+emUnAlQIR1jrZLrqXY=; b=SM8y6gE9sQMt+v SF2CcGsEGTILMoEifw/H4quOJoG1fbyQHs3LnE7pjVq+PJL+3T0hrAhq8Tkur+1alATd671PvgtGE KsteGy6ngX1hTTCTbHxzuKszRhPx96p05L70YM62zc+O44GGfoiRSRQS0wBZdJPKWTEZRJ04/ihsz kqipMMTWlgob7ZESKK7UcOsbvAY++KO++o0lcPhuaRb3bGSytJvbMMI8y1/JosVxMwdim4NJNVkT/ BwSS4R9CZNI7a3bMi+9iLeBDGFfR7VFMM9fFh5pKq5tWpOicL+f3fbs4gPTTiMGEF45S4ADocfSUc y/mC54ljNPPrwNi+OkBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqX-00000000hZV-1Ezr; Tue, 04 Jun 2024 00:16:13 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqV-00000000hYg-07VX for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jIr6DmEjSa0v3eTC3mpW+yiALalUy5Wlw692ZOyURG2FszQdp/CiWPrBvaGtgteLNrxoxLXaFmdLx/5/Hgo+8ALAkQay98fW8fACd+PdMsNGcmf0yYOBfVDk8y/MMQZHLaTEQvCmJXOEUQv7g+AI1DiIidxUKdpVOLM7xSqEqP4ralnnIauarNS0+S+1I4hX2blWB7VQFgq0wsT6BdWsrMnr4aqrNIQmu8W571QzJDDdOIHg7g9XwuDTJm+H1ip+Ytu4r3fIovBZK5lkl977Qtp/B6D41wzCwti78KuEVcIPKD5nIPBOp91GEayMdP4w6Xrw/gXjhxkBSPIKJOzH2g== 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=avdBgAJxEmMvTklD4lK2mlU8xg+oDLKwffa5vs/jyok=; b=II3feL8LkOdrARLpvBbziVtaIjDjIwD1FPefHEGoOw+QS89fuklwWdXBZkYYr/qAhyLf4WzNPjMzjC294xRAacM7UlkewhdcuxVv4q3CLq2XuwfnqOzXw4KYmZsARbHFkHYXvNgswTcg7Xg3vofBZHGZw5vE/gJ3gliujM5H7VCjszN0nhsAipt5e9S1+t0yC95WTx9S78DUArBWG1W1EOARQIE41t7WsIOst4BhrCaOv9OWmyQs2X2FSXNVwPnmTs9H4/LvdjXo2gKoorVOUT5yZ0hjZnnUG0Ano+hp/SOeUsMekpPJwjoU7mhJMynhaZSY+2dYjhiwLPmpMmFOog== 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=avdBgAJxEmMvTklD4lK2mlU8xg+oDLKwffa5vs/jyok=; b=jqeVHnQKOiUwoJ/SBcf0GTmJ09HfWzG/aqcg9vNlSJp0LOz6JUkP8DFaJaQTkBE9McoG2yJUIH2m0cRso2nj6lBaCaGkWcjfTWdgkevI/X1babJtwlx19p0x49kbQC6lP3uAOa3R/X9Vd5wHE8qj6P+JDc67eU75wudRzJaR0YFRDO8jn25CjkfN307vNqw77fKfODmLo7m6ZRIlXSiDy9xdiO4VlFf6aUPtpl/jmEisvV20I07Z9EtcWzMJHDXOtwbSqHUkyFZETrVdYnf/GZL1kprgv93JrTj/VwXeFUBsSBA4tl7x0zX50WgRNmBdHUuh4TgNUXC+7+vy8rpFcA== 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:03 +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:03 +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 07/14] iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface Date: Mon, 3 Jun 2024 21:15:52 -0300 Message-ID: <7-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: BLAP220CA0005.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::10) 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: 2300a7e2-0261-42bc-581b-08dc842b849c 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: ECFv/XVQXazhb3CvaXKV8hR9eicKg7cd9scOz9wIFD3eK4IeaJE/GS+KCzPbbvr6grfgjBldEaVsM+YVJGHv4KYngO3UyKNtE++tkZCkmzIMRotPGrQie0hL+VOtz+OeZ8ULVb+O8aLXeaU+Lgs5nsNOUlZ0xUaPR0tEwVz330zxKTMkNbjwNkp61lIGp0R5UGSHYCA8tvOXsFtq+cJ6LbETc9F799+Ih9Joi0uAEu6aaZzxHXQjJZfC9G+9Lg2Oouz9UgY0XxE4rojA2mzp/4nlEzKJtN6eZst+ry/WTRkS9Z7lAyKy9wD4I1DuXJ7tzciUS0GsGD2hMzlcvgrKTU7epUXFPvwNL4I4lPLINkJXFLA7L3QNGOnLHoX6aTeuH6ToF1V4G1EkQ1B1V4m5iPkB0vdUOUa+Mqxig+KtH/CBtmWyGSjnQlRxXW6iJxontnpDfSWeAnA7vZItR4SD4k6RJlasJjabfZmVCZ3lHVQXu4wcaT9Pupmfb0akYMp68DWRHvJ/xIyzRq6noH43ELv7+WF4O885B4LKSh4SoRomxOcW5/EBL/tkMhvYIxtN+karRB5EQWAxRKQ/mAp7tvJT3N6+1tp1AvLnVAlNKjM7uw7nKBGCecZaFvlAws2RgJuABW5goWFwD6IlI45opT/bpEbOq0eBEx904Fg3MEfOK612BgMCnS2PWF+oGpNEsnHoWGaOxUme0nO+HsNITqPf+uMC6S18oMYzyU3aOgaENuHD9HlEhjQb+OqQ6iI6WvqZSu4AVWdeVbUwTVPNVYVqquLNTw4uixeQ/5D+4fwd9nsDvDnF3qz5GpOYqOyWcpMl2TVOvKHjEWRyPTFpoj6MV+KA5yJ5E5b6gGrZ8RgcAK+tOqjB1wnklWGWzIvONDONlN1/jx0WqVWXhescxF/moxK8VxF58BVNyxw7jY1B+tXXYpygoCgpqJ/wgGaIy3fV0GO6EISA8HgCwaVWbLtUJWaieBLpywKdc0Ki5a/vNcGVWbzWkldInTYrPbrukRmWAk+vm/yJS2JbpkTCqewsAtki7/2NUeJU68KlBW7awqjw3W1tB4Qij/BXp63qIauYwewqaLMfXXmLjNjvqfJb7sodtn8iRRAJ8QbINq4J8oCWX2e7CFVXe9HyfG7IoHVntVOkrbuiC8vSGJvR5EyN9/JRmzswt7k93VjUPeNaFKLueSiODb6wZxOZRrfMAVsvhBollo6hrGRPE24n6gkIRqpDEeR3H9JUWNUf0HMFOopOuHMmEfo17AqUSoD8zQQSjjriHKSFiXANhqJ1/w== 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OmUZ9SjUUp4Zjr8LNv4wr//u/MIQJwBeKIpJKLpVU+oya+4kqzbdfAGfbtWCDL8huhmTS0lG0HykzMq1ZoODHXuNZl1FE3g0a2x0LbEXe4vchA0eJ0CeLGZScuc4xxNzuGaHgZbEZ1AXbF96qxyCJUO7/PNhbFvx9RqHEw64Wja3uFI5ydS1WUgyoYV1xQO5+QCt6FzEzEz5YK9tHll56SK267BmpiHYFD5v7g3R79bWAM2h7jpTKmipZvsCaRC2XhcdHBVlvoWhX9jpKTu2jOOV7HYEf/2Q96NjgcMnuhiEgcmeM9Z5K3uNwkLARYdaOFuJeczF1jFn1vtbkjOVEYFSFHpj9FIdiRRmvja22QvtQk6YWCRK4lkvJB3Y+jO12bg+9LI/hNWMkd53O90mmFnqNxAojvyLd9e2SdSSlBZ7VddXQaaq2lKwvDKfjmIIIobSxd1u67pBZR/lPzouxwtqecwR3SJeAwFmyGSA4jIVYm8oxVcffbpeDYSytuK0gyQQjGWlZl60PjLnVPeToReO3XIeGGUIyPBT1mODuay7huhzCn0VLHvEecWVFNhpDp3s/ExBuJmCd0IcWiI154VNAihmx/ELE/odTjH5JuKp5wXevaLK+3ygwYa3XcxbiUVDJpYmrNxx3yiuBB0HKQPIvDBP+FOYN9iidVMlsXONQx55p4Q1FCp/4UCJzAqRfYE/acgWe8EsbITgSRZ1vg55caJal9Q8lMZBRqYRwEaFUxB/jt1gDeVn/aGjHpSn+NpAQTDG2ufTSbWRbtC/PqXB9kQBExeQwyqRMTCNEpBH7rkAvi8lX4ma6Xvt7Tt7qYh3jbUrGvLlIQosNVeY3DEIxegShx3DlN2uOwc5h8e560gBN+ZgP1YoirbfV0UkgW98vTspia+nOu8wZMIlUK+Bb0cMGRmlYRJXcNzvco8mOzVZ4TcxJL2dm3RfQb7UgOkFXbbnj45/9VqNo6kgi/Sz6UIZvVVEzWrIoBiCQSgZdbW6+es/LEs0P8tGoFT8n9Z72aeWqMjAUfMN0rxUDYC44lyHR80XD+TEjmPOgCT61NBxFT6KRA/oVUOG17GaPi/TVcMSA9+NNxnfW0PX4jBpj3u0T6nh0jtEfOROG5bKHuRiyb3iNcuZUHV4qOrAJCQ0XQNghhLJS3l910e5ZknvfEMc7kyLm47DfaSpsQJ5jYpfl6M80jpfrmrGe32bwJvcElLYM+n8roS9t0eIX/3buGM1pcZC3ja1GW3QR6oBH+di23pZ09ralSeD5PO4kQoPB8ld1ysOX7mYwGVKR6QBKIUPKbEMENempZbM7M1pfIIWwqJohjiPMMk6tfdqXbrhU/e3X9Q8ZPuAwnFEsa7TuuZUF8giAwGi12o1DcEoBjSvrIc1HDI5YWxcs6pwwtRBGxUVTxO2Rwgeb6RegNY/vjKNAM81EvjNvJY4hpsTH02Gh8I47aiLgEQR3E73eFxX37r90AtzyCrTX4dyGWbqwM+JhwkKzLBW4X/hvsIxLogjfXcgDm2vukKct0o29aPizWkClqFLmiNd8zwcMtl5vIOfvujM7jSvQH9RtJU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2300a7e2-0261-42bc-581b-08dc842b849c 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.4201 (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: nyQeUAoxyfwT+C23oGr1IXYjH6Vc6QblIZ+k56IZr0Jw/hO5Qvj5EvCtDSDILt0q X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171611_171972_329104BD X-CRM114-Status: GOOD ( 16.05 ) 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 Allow creating and managing arm_smmu_mater_domain's with a non-zero SSID through the arm_smmu_attach_*() family of functions. This triggers ATC invalidation for the correct SSID in PASID cases and tracks the per-attachment SSID in the struct arm_smmu_master_domain. Generalize arm_smmu_attach_remove() to be able to remove SSID's as well by ensuring the ATC for the PASID is flushed properly. 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 | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 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 e7cd1ddc03517d..56e2fe52df530d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2005,13 +2005,14 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, cmd->atc.size = log2_span; } -static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) +static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, + ioasid_t ssid) { int i; struct arm_smmu_cmdq_ent cmd; struct arm_smmu_cmdq_batch cmds; - arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd); + arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); cmds.num = 0; for (i = 0; i < master->num_streams; i++) { @@ -2494,7 +2495,7 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) /* * ATC invalidation of PASID 0 causes the entire ATC to be flushed. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); if (pci_enable_ats(pdev, stu)) dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } @@ -2581,7 +2582,8 @@ to_smmu_domain_devices(struct iommu_domain *domain) } static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, - struct iommu_domain *domain) + struct iommu_domain *domain, + ioasid_t ssid) { struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain); struct arm_smmu_master_domain *master_domain; @@ -2591,8 +2593,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, return; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master, - IOMMU_NO_PASID); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); @@ -2606,6 +2607,7 @@ struct arm_smmu_attach_state { /* Inputs */ struct iommu_domain *old_domain; struct arm_smmu_master *master; + ioasid_t ssid; /* Resulting state */ bool ats_enabled; }; @@ -2664,6 +2666,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, if (!master_domain) return -ENOMEM; master_domain->master = master; + master_domain->ssid = state->ssid; /* * During prepare we want the current smmu_domain and new @@ -2711,17 +2714,20 @@ static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) if (state->ats_enabled && !master->ats_enabled) { arm_smmu_enable_ats(master); - } else if (master->ats_enabled) { + } else if (state->ats_enabled && master->ats_enabled) { /* * The translation has changed, flush the ATC. At this point the * SMMU is translating for the new domain and both the old&new * domain will issue invalidations. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, state->ssid); + } else if (!state->ats_enabled && master->ats_enabled) { + /* ATS is being switched off, invalidate the entire ATC */ + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); } master->ats_enabled = state->ats_enabled; - arm_smmu_remove_master_domain(master, state->old_domain); + arm_smmu_remove_master_domain(master, state->old_domain, state->ssid); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -2733,6 +2739,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_attach_state state = { .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, }; struct arm_smmu_master *master; struct arm_smmu_cd *cdptr; @@ -2830,6 +2837,7 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, struct arm_smmu_attach_state state = { .master = master, .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, }; if (arm_smmu_ssids_in_use(&master->cd_table)) From patchwork Tue Jun 4 00:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684529 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 3100EC41513 for ; Tue, 4 Jun 2024 01:31:26 +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=aslY4taAXJP4SEEybiaaKDYqMe8pDJTEtunPMaWyj9s=; b=36o94Q4TFP3/of Nw7Pnxr9ajtmTd3Ls5NmGRBfbsvNT5sWWBvRmH0zakETkvfIZAoG4RT2+S2Un6xup4HjYgoMhClLK Ap5gW9ILZ9nGv6iqPAT8VXrwr9UtDlq1IPmRIAsdD3Qv67An+TECdVvrruKTHSOJ5nqHdPEowRcXP zFHWJZCghEVJvHNp3fAvLXQNcbb/7I+Hxr2e7puorzGrsOdeaplCWcyFIwql8ZadwyK/jo6iw5q5X OLSjN9FqTg78XsPBc9sJUdBTKtyKBibCLDxYEzT+nhYBWgyUl9cb5oRssobTWbiF8ljnQvFnE5P+u iPeuDJggisG3pzJ5MvmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEJ1B-00000000ovb-3U7K; Tue, 04 Jun 2024 01:31:17 +0000 Received: from mail-co1nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2416::600] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqc-00000000hZp-267z for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k79mKmvUPGuC7AbUWm3JZ32fgOIFU6U+/N3h27Af7L3ne7j1VyEJ6d5+j/MUZukFCNSgqbqJr6Kw+pbRco9TcBmtjl2mxx1y1ghgOBJxdckthreiEjtrsmy5xIDWxpGsWLcPcy75LaCPw8Xs9UdSWjwbpUTOK0Ng5kEb0HgaehPyvKAKVCGQLMoICU0NjoIJ3AutfVBJP6gM5fwpXc8fVIUvtc8fbLggB3tHupoR8I1dL9DiGcVPbRczsEVAtrec+l5rNqhr73a95WJ/tp5VA8EcvTSehWtWbrhbCawpX7ksTr3kT+2iPeiyWMOiEpcwtgPMc9dbXJuKKvNXIrJQoA== 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=TD4CyZh/RNzVohInMGcPgepXhSkiHpsmPr8IKRgtlbE=; b=gTj5/xYsgeEJmg48xP2tNfCwPRFLs8zpS84UOojvmImIusM2xT70nPfOZrl1osqhjybutUVYQy+JoW1Y0FeoR7pdAzrw+cKQbNSeeGAA0RrBXtvOuBhxGd9qw7jyU2n5D8Z+Wn56mZQz2BswWrEtg0d4n9GXfQQayGvDSZ+s/01BQuysyVeiRhPTwrlrdkm+p61jVeskIe2TwBGJ+ZrNx5N36EcxW4pB7/IzxiNqMChV7KW66oTGZUzve2PreS+4gaXYKnIf6ZA59w0RkvahjCTfUuqjHOlLu7cRQvEBKMxylmAS2vNWWwPirH6vgVx6xgri+N2uD3VroYPwLgNSzA== 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=TD4CyZh/RNzVohInMGcPgepXhSkiHpsmPr8IKRgtlbE=; b=X/LBbxcveW1ikg9HghGDHb090kxGEye3C9Gwv6FUYNdPklLZssBCG0zQDt5y6SiXJ0rRhU4xNfbI+FwC9avLTYqZk5AbRy93QND1cCudsetlumuuveUoFczfTnzsfuB27wF/cNo/4FevGMQkOppBFXEtWzf+OyphrgwA+/g9N4FlCAhxk2JTBPo3/0gsLuTwz+i1pRWTmRGUGuvghie5BbloUpZZ7Eb8cN3JxS2SunvgX4XSMotgKfqpL4L0XTXDXZ03vH4UsoE3VZ+KFNnrb4kQOYx95cYUp6xapo2l2/FcNcmTUPRhcGK0C5HRglmcEGRUhhZ0U7Dkbt9wrm95Fw== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:06 +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:06 +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, Shameer Kolothum Subject: [PATCH v8 08/14] iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain Date: Mon, 3 Jun 2024 21:15:53 -0300 Message-ID: <8-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: BL1PR13CA0432.namprd13.prod.outlook.com (2603:10b6:208:2c3::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_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: 510e2541-8e00-421b-9b79-08dc842b8599 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: slopRetXtWLiu6dwe9Xy1sfvL/U415lFihT4OjaDtHkGbKDZIC+Z9OgmYlqxfcQ9lyRq8oRoI3iUNVPUt1/MfhzzOH8/Mt3+BrRMjGA9ebySDaIFgVpkdY5ryyF0rdNGheJcjzLupTswQD37H1d7wOJ3Ql2HaHRtSwxNba6eVG0au+/ZRPaIkYgEdrrqKNlQ81lREspCbmSf8zum0Q0PW6PzC6knCyr+8AlAexgIiKLFGvkv8VbVwh0fTahT3/TkH8CJc6C3RckBD7o97MXR0SbTz5d6pMbSlNMIEhr5gkGdh73RfvyRcZA55N63gBgWEbmNoFlmEnzzhCzo/LU16z1w1A5U2RjFSLxSW0X+b/kP/8VG+ZI6e71hnLnO7/UdNNW793BL+psqRk0LrwR0NLojLGECmfNYrBYvF14uqeyVYcotIrMohpnsqSwFACDbIUDO23guchOUmw3jbrW3jbds58pvIJlIG3TaNwXXh4t8XyhFuXJmcW6W/qdMi2ZemjvwIiJuDUVbEW4oJNaAwAJ8nTLWDn7wFX1oSVmtJ0MCMHlMMaMyI/TbkaHNWtCkY5Lyjl9RgCmbl6u5iSDObGozhsIBRZa0apQWVVyLnd1UFNbiJht8Wvnl4tSch80XvzpO1vTDaU6Lwmxui345oOj0QA0pEielWTYHW3lGr4qkrijho4daPwNZTzRpopTXvyI0JP0NGves6d9RMHCZ10YqWbRZhvs4A68gjycG1Nm+HvPoG69Cpwj5f3oUWXYmXylstUyU1VXvZOCDlCN4+domgxYrTRe9yS+LB+ahyCawpy9qPkEa7aFJnlBimDdXG9peQ+xNNHtiURIWIFhpANizEYbkzOPZxp/A0coOot3N8+Pvdic7jEmcsZZtTvmxhJr2/M5BFuqFUgAI+t9e1qJVOw8PdFycqjHyTwhhilY1C3QDdY7StBqvLtD/j0gAbS38t8nK+0xgSsgJJhlLKYhMMOkYytm9WJe/vfnfk6TmvQ+ZvcRi33e67SEyumiFMFVZNiaifXrISriUufiUksRhK/wnY90kJUyxX3IaX/0WB6dr+sX7wCNoEbkTeFS8NxJg6KVod1cn/m2sTSroCdlcq8QidXNJobUI81BMhyBWZOWp1Ng/kmuQFJiFR4qiaQ30f0uOlZweapMZYcuoavmI5wJ0xxd0Z1bXq5s8i1uk/+ZNH9Bv0BWMPOJVyX2SzboJUKehI51hT6OSl9AVagbDf9IRBGBf3A5aQrxV2KjNDQVCRIB+LSVQweKMQwPSR+QmCNGM/Z+SQYbphrDRdQ== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hcmzAdlXtvJKnrH/2AucSQi3oY8vtfRwlUZsSuv/wNQLUn1Xv77FWEHUL/pl44949VL7UgIN4Yb6RZvua6nymnlctJBlRWJXOQjc4uQnB7V7/MTV9gTwgEa7me4BFbRhGthvs7sBvqcemk6ggNT9yh91vG1/8a8+48Wf1u8CsDsVxirA6cGweVb91Rdc6Ntx6z9g2ZLQHBWShKwVrhsDvGYKThppNXI3gI6Q5kIPVOZeU0gMX2mPIaSPkJcOilX7H4GMyZ7r+Ru3Zhc48+LDvjbz4Fm86jNxu867LCk4raGEBzgQHAe8a+Xslk1keQqiiABJKtO7lnyfEmoRKEow5x+k6qigw27Nb4SCzQUMnw4PZDALjuEjpQOkcOMlHPHxU5oytI3DNnb68eeH2O3BtiMh6f7nRcukby881h8etYvtqLBcB7iKrHm9X37g0STGgED/nPMnYtzHe4YQx24L/e9+gvQ7YAEj5hUXDkqPegFXc/GQJQO9i5/vQbwcAjo0kMNQcnWG3rD74QOFa6kKvoo5W9mNPzoORQhTqtqEvj9uzWVLJyRMMq/UOJ3juL/9uOnoo67txhjBO6y+W+43k+nkhM0xtyxQlKzASCVlVb7PVyivfD8SYKiT440Sc3fb3Wwg1UunrV+xQN2EJotWoGb/qfrOo+3VwdfPOsE/W8XIyOWqeX4XhnHQ5poIzJxn1Ou1HzwEmacLAUly6BA79M6coMyeM5MmmKZzss7vuOr0e5yrhvX1TvOuCMQbB07kDCozArI5tyMJixintBMJtgcV16AP3hCHpBfSFzH9ZPM9tlD80LZa7YCTWlqMtbn7eMyFFsTucTkVvkLA8HgbPsBEfR1Rby+JBwPZ/whM+j8P7v6W8HesPfg+fG1+jPiDv4/2E1QZSszneSJ5u+P5m9ZPpn7UkTug5dZJx206dDN5ToHXiRy9OP2e5hoGDAFzAwzbMHO/MwfhOyAq9+uVip9KsAAZR0mRSO9cYqrDAtNMAzKBFXBRXn2BMOiXXsW0Tuy1lnbgci0IaoY7OeMu9R1QIex0CjkQAZjeYY4Iq4F5fgITdrG8FMWf1W8FecdsegoM3DCrKipHZiXmgOKRSLXr+b3OwQRyilQML6rDKB/vxqKmt9EZ7aEyd1j1hNFNibWd7kMNdx2Xgx6ORdiNK5fs0AFiU9fPy9IkqmM9yi8y8zQOfMqkU5JETarkQyXK5Lt0hXTEOqiJsaKtIGee8u/90F2JlCRbC1Wo60Yw5beR5IMLGB3IRuUsE1BQYbKSQsEtD03lg7f4sAh5ylUOi29gZ/hPA91HVPh76f20dzbNSqNIx2A+AtV4qzE4VuSfE8cBXEuzH/t3xq74zhsKUyO8ilEYHEgz9PNPYV2jOxWztc84QOf6BfHpcOSVdxYQzg8WWFQrPlPgKl+AsGbEOY4R2E0iaab2k8wEUSaWPPmN0I2BUqmCqCdWRJ6hutqEBJZwmWQWloKzljD2sEFbWJwh01P9LdXRLg8C9gbS/hV7No1B4cT72WTEDzTyPw+YEu2HSDmwi3m7WAOoo5w9gxnYjtJXfp3FSHuM4EsEQJo= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 510e2541-8e00-421b-9b79-08dc842b8599 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:04.0515 (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: egSYuTg6FS3J0nJaIwZUAvVBa3SzW5wv2+4TIxf3IdgqM2ttodtraiJEKEGh5PUF X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171618_813782_5B272838 X-CRM114-Status: GOOD ( 14.59 ) 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 Currently the SVA domain is a naked struct iommu_domain, allocate a struct arm_smmu_domain instead. This is necessary to be able to use the struct arm_master_domain mechanism. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 21 +++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 31 +++++++++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index d31caceb584984..aa033cd65adc5a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -639,7 +639,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, } arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - ret = arm_smmu_set_pasid(master, NULL, id, &target); + ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target); if (ret) { list_del(&bond->list); arm_smmu_mmu_notifier_put(bond->smmu_mn); @@ -653,7 +653,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(domain); + kfree(to_smmu_domain(domain)); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -664,13 +664,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm) { - struct iommu_domain *domain; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_domain *smmu_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return ERR_PTR(-ENOMEM); - domain->type = IOMMU_DOMAIN_SVA; - domain->ops = &arm_smmu_sva_domain_ops; + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + smmu_domain->smmu = smmu; - return domain; + return &smmu_domain->domain; } 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 56e2fe52df530d..c6dba933d2c38c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2272,6 +2272,22 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +struct arm_smmu_domain *arm_smmu_domain_alloc(void) +{ + struct arm_smmu_domain *smmu_domain; + + smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); + if (!smmu_domain) + return ERR_PTR(-ENOMEM); + + mutex_init(&smmu_domain->init_mutex); + INIT_LIST_HEAD(&smmu_domain->devices); + spin_lock_init(&smmu_domain->devices_lock); + INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + + return smmu_domain; +} + static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) { struct arm_smmu_domain *smmu_domain; @@ -2281,14 +2297,9 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) * We can't really do anything meaningful until we've added a * master. */ - smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); - if (!smmu_domain) - return ERR_PTR(-ENOMEM); - - mutex_init(&smmu_domain->init_mutex); - INIT_LIST_HEAD(&smmu_domain->devices); - spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); if (dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); @@ -2303,7 +2314,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) return &smmu_domain->domain; } -static void arm_smmu_domain_free(struct iommu_domain *domain) +static void arm_smmu_domain_free_paging(struct iommu_domain *domain) { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; @@ -3306,7 +3317,7 @@ static struct iommu_ops arm_smmu_ops = { .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .enable_nesting = arm_smmu_enable_nesting, - .free = arm_smmu_domain_free, + .free = arm_smmu_domain_free_paging, } }; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 65b75dbfd15914..212c18c70fa03e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -790,6 +790,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; +struct arm_smmu_domain *arm_smmu_domain_alloc(void); + void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EAHPlHZndgg0+eD5b9JxcktlGs/ilMxlyHPgVKFSn0bp6Y24/yCgEGlEoiQWpE6GtIoRobDfywliktdVnwiMvuT+qI1krlSPxKcEGaKCrVjJHtvfm6uw8j2qZScHLSIIrnZy0hpqF4mVS+0+bNieQhboFemPXf+2KrpD9TodmkXFr0XS5OgHjuZFr7zEqzoGBWYkA1FewiMh3StDGe/3H8jRiYS+IL6bMnAmkxtBwHZm3zBOoTiWxh11ETV0yBbW8vrD9uMiENHT+0uaEtXcHELZtGwSiI+qpU/f6Yf973gtWecoqUIeblqHbiWWE7ByxWJGa72GLnQns675oWjKXuHgtJjcLP+x7jOMcBOO9d2m/GB620rLuo99PmE6exAUUT/B8SYJjnbI2LPpEczZvt7yIcXPdVYnhuxl1q1Bqv18X0FEoib4/sQhORnVa+wn7diOx9V+dhsSsXGsPOuu18stQVIMypOU908D9AxR9wlydCaZmwhFkUc8UYpnFHaG4LLaeucB8/cxUoa9dJzcSAJroI35mHeWDY8bugeMdThiFKWWjbNvrIwnJ/c3PJ3KQlflA3F7a10R0poqTlruLZP/FRlhkR+QxQ39GAAdsblLShSy2r3rpPz10t57v7aSMf4u+326FC6awPJeLUiRJK3dQmgpCAAw6apxxHdE3ZyE4kL9pVlRK10hQoSREjZPwgMZs5cVIn3d0kAI6YM0g/KVo+4EDS/z1adCxYXVcpxsdMVSSWwetKNTK4jxP1MOar4Wsl6/3LfQq2PCnx9xJtNldfcZDfRpHgcGsXSXWCaIc9QmyL1sUXydmA6Rim7yuwpyKwIdIBMrt3UclFd2liMQToBy+TjinR2vO39bdXVM8xveg3HE4igPI/vTej5QvcDzfTCbzyQ87Hg0CMGT+n6zvDIBx/7Fnt/Vq3qfQf5sGWqwtB8VrkcdKPVt7OfSrweBpyRg6xO795x/u53VXX4hWAY2llWZ4YGw/EJ+xicGIL+zy71IS6hPSV3SFlDlOpMVz7TuDuMFyya5yzT4SrdOpzevR3GkmIQxv+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, From patchwork Tue Jun 4 00:15:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684533 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 BEE06C27C54 for ; Tue, 4 Jun 2024 01:31:30 +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=4uxZBOVeJTnU330wHSDbGTVZ5yp6w9vU5B0QCwlJ7dQ=; b=1rKqMWCoUtr9Ty x4Ns9RfkT/x7KAJIM20DuY+aoA/OlqJL2JHk8LCPQfruVpFg7csX4/T4tBDYe2emckYcBSN8JpI/s 1S5i161WWEW+/TES0X0hYs2WHkh9mY+8WxRMvaD7YJWWv1oZGrly2mthSA+QZ1QBT6ubIY8CRW9YJ wGk7Yf6U0lerg94C6lRUbl53BC9xQbocHRuvmxLiW2vN2XkztiQKs1DX9QUIMaGuGdlfX6q/UEl2B CgSc7o4e3vmDH8eiRYzryNPSboCCgmodPjyMzis2GIRkNOug3YTzZpz4exvsH8vbv4ezibf+qPBM3 d9lp3JaJTZV5WG52+PlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEJ1C-00000000owE-48Jf; Tue, 04 Jun 2024 01:31:18 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqd-00000000hYg-0lCc for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LZbSV4cB4/iu03qsj5atWTBmvGx/k202OnxL1MQNmgVU1DVw/qCybKdFk0aOFea5H0aZvum4GNtIkWeVIUYZYyraX/G2RbNryHm+IDHb2XDlzSn0kfNFVae4fwx1GlAPzzRXbeiZF21ptJT81yHXyNYrows28k7UNvS9keJdySRvCzfiWmArHSHbllYel1uonAC0/3D1oxSgqT3eI8f/ZTGkuhJkF2GDKR/7Y/ZwHhJTBjPgmZilx4axeptHiiwpHnYMLc1oY43oW6p+yZTVdkf1ZieRxgHFhnQm3zjjGESm84ZJZqByVaHRPdJFaFXGCuSeFpoEq/q5/pMgUzPVag== 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=zCViqEJgStcJGscgrMxol72yz9mezU75OSTyutXrxDg=; b=UNu8Mkn56DeLo+ebAnDhaczRUjm1kfxqEvegxzzGYYJVbzjs9ZerZUE4C86cw8xWGjiewDDuWUGqPSeXsshnBly8pn9zeZa03HuN51eu07XZ8ezN4ggERYKZkVgsQ4txNjNwKMEETxgGkZRy4pX2OsKU8HXNfx4IcD5QkJc9FdG93fN5IW1EK3V2ralcG0+ze1cHiEQj8hQ3E5j9NAkZ5bAlrFPrfJWypqgghAGns6oAhoRIO42/rfVZrjPz2zOK1lPv5F8goNQsCQ8ohdQ0j1sOI0azbm3jvRFMazSqKv7wmihvLOpJSz+HVTBb7pe5cdOxDp69cyoH9EhLrc+5Pg== 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=zCViqEJgStcJGscgrMxol72yz9mezU75OSTyutXrxDg=; b=oXn6xBXDJG71h6fLIj4zajNdtsLJJI6vlUmlAUi5H4mbArMoVBJ3yir4F9O6RI1CP1EtahlTlInlR/UrB7SR1VV2LXj+E8l2Nf8GYVDcqvXxL70hxxa+GZ4hptgasUo77gC6+AenpJV3jzqccFxje1EAqUP4kpyXAi/Pyt/exwzoQPLtCauw9M91vj0IzF8GolgEGEOOZEYDltrf0xJP8VFtXUrn2rPRAAtX/W0cEkt+kWelO1mDz9OYCgvTbvA+dRv/+lqLOpCwXeauqC3lETVqjxelQPLiwGKxngrldLiawnF7pyeiq5+A6MmULU3uI3l+KgansLr3AB7BqaUuWA== 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:04 +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:04 +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 10/14] iommu/arm-smmu-v3: Put the SVA mmu notifier in the smmu_domain Date: Mon, 3 Jun 2024 21:15:55 -0300 Message-ID: <10-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: BL1PR13CA0430.namprd13.prod.outlook.com (2603:10b6:208:2c3::15) 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: 2e9b8bd4-a17e-4ef6-2d3c-08dc842b84ae 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: yeixSiUGp1ZC58+9kG9TR3WKb8yyHXkNw+OkMLtSV7IsqTigFdV6gzS1cRH1FSnT64GwKnlH78Tp80vfAeE5xSU8EEoHZ2KEm9YDgeue/ljvf82RXVa+vf5Cpsqznt6e3fXpHrDCFuXBNUHXOfRwXJHgWZyKBpjcFze/CCMhbzOFr7x2m5tR25UF8Rtnif0cUhhTUFSeHD8k2dnvYZDwcwLLNH22EuzYN1791fIRAEA+vOmlf5hiUHYPvH2TCWNCenR4RsxW4uMuVx49qlT7EnQ1RjQO9BX689Y418DI8xXucJu8j3fQ40pV5/1yqoziv/cjmqoauAuVyumrxypGQXR1JYnN3qx5xAcW+abI+DbcXpVtF+tEBLnvkB1wrxoxFao1pu8YjIN95UbkiISUiKTCUJ+LcEx9hDMBPRjG6p9yPrXQ8mXtP3wZ6Y8ejqnJ438JJeGKJxcqPNDI41Q38fg4QNdpMQBVzN87cXQUR0dLYVfK6yT6vty/BxwUK0HE6RFEgfnAanMNA6FNwoKFEF1i2B5wTiYtsHWx/4Ah4wheMSn8eICFX4GxsINlMWJKjn8Lps8i7Qsdg2efV2B0QCXgV1et9CMmWFBXdbHN97SLEc90bAQHt2hQ+NkUjs/DKm8wJVt45t+NCIyLsb5zf6KkMiyIkSojoNxA/HYyAZu5xqlAMFF1XSCUpBMOujQk9Awgsn7kUYPt86eXQfzogpuCBSjlHXhyX2EZTOAcCePiG5R9RZsnX2e6VDhDxf1LDzaKunkSBkPig3einNQob4CLq7aXkLRFP9SKatxPn3qUzgT9r3mR6Og7rFBPiJrLUVQiT09QLbvn84fO/+8dPZyXrbCQnT040mYjLOf7htPIHm0HaoK0Mo5kxYBMF1DawuIw1bTDf+XX8AN2/r3azlyF8FXijaH1GPGTVB2QaEe3ukbtZIkAN8+d+FMEC46sFHogTIYHWPJdRw0059EB5y224rku7cXGhFheeB6ufK5pwD0Nf+r1TcB5VxDwvAVW67GRWtFKu51bSa3A5U5RLROSFExF4zg+UH0YO61P0VltdP9f1EbJ8qhGWtysA8aT4QErRK5kASTwJnRbwX23MV4sAsx9z+Egv5Xj1m6gV5AsXTweurXQk+I9fUSTLdEO5GydS0zRUC2+8D841d4wiU/MxLHRsJQ6S7Hw0C7NTgJxwuydq7+LPIHi1TglByPBAGzxRHeicds+yOZIqMkE4vMZ0lcEIIDQL7JHgAwkQKFgK78hZg6WcMWQEGrQF8aC/13GrM2Ywyg57wblzG3+MY/9Zobo7aR/T+4ZWTMNyqk= 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ib6BA6Vs2Yar9qEe2SsLY5vnXh0NEDEbJmedZccgm95KULyiiSFewlTZWEAyzyjp3Tus0ghxo8o6W7KaLG2VgVCjXTg+DgiYNECLlKWUuVYtqGSYbIcuqCJsytHU7fhSOD45h4vO2uNKABPG9dORVfwo6g+iVSgWGOF2JLz4WrqSB5zTjrQNfHFSVHMMDyE5jB4FHKVbGI+vY/AhmMJSb6DuguJhidSvVOvXDnVEQVHg0xKORXIQ+7VxEIjbbUr3exNGs5GBdtGafIp07SxZbeaOCJjJ3eZzivjT55vShM59mLO2MuixQg+SA5gxRJFQIfB8GhgcB/DuHiu9XyL1AWFzrjVZivBxFfM55n4hY/xiGSO9GoNOnJmqBhFsm8/M4e88uRfi2yqeZfJA/vUGvfyVI/e7WlelwKIm7JIu3IGBm5oFJKPe4NwT+UFhluBCVP938BJ9XArhd0MKEuey4qCv7SOc6UW/60ZMA7MEH0KgDKvV2FH9E+Hn3/Smc0WtdhpJxv6c92E6iAlC6Jxo2aaVjNJumHoOAtopw3emEKAgDBX1iQIAG6BgqHYf01f5gDKlSCqBFCQ8JmOCw2mfBzQrhjHCR7rozBsQjgpMbunkFGHEhQ/ZxwYPysLXYWp+g43gbrYyEBBKdpvE9JOaLOiYUggqKS++KnDoinH3Dt6s1DwbH8wvcYxs8a9tzNib3dRm3YVfWGbn3kmcbZoLtwIP0iEnLBKlHginmzmXp76HJDmGzjF4woDwb18IVVqSIulq426j8aSpcXo5C3yUFrjMYMVGg8CrScrykqaz8hdZon63w5jz+d8zT0kob0l9OzgSzMkqOI6Iscdwp9+z2LzghphdQvGnUAluibpU+h7dnLoH9t5VnyT6kxkJg+WyhGlSJqzZhAyUKnp6/i+KvuTh5+zZ7c2DzGPwzaJhol42PUe1l7beLJPne8+gu2AyvWplbZxf0Y2zLoKY1Hjbx3WPvpKr4nvVfgmsXFmOufaOBAvJtRKXNODu3yVRBf8QZO7rW6W4AUF23R/iWNUe+7ZoN6mZLxjAj7u36iqTpPr4wv94irX/obsKY4ajK+fdiWKsWQweTDdWrs2YebWV5gmthIN6WJEaFUKwt45o9LNE3Hke95TcodAwTbJ7iogIlujLtYYie7Mk0i4iWgp2CehkkYO63kLbdVlhGiUFTuwmd6qusKW/BfT61ofzNcYwbG1pQKJWdd+P9Wp0Oe0JiWhwLUl621FZCMc056p1V7Ef3Y18zsEToIAmSEmIKYaglieltyzQj41yVm60ewSH+f4zuPBFW/GBOLWK25mRiatJ3rZNa/AVOcjcynioGutqkO8yJfUhp85lzKJIc3RIP3HOhlbxAc3XQ3sfQcaL0z1+rzvjEoXKEv1J0t6dSSNf7QmVBcDeYYvI1tokU779yAElOMyq/WJ6ukx8YNHAPJig4ZGV9yBW/CoVGqVg5Hsza1wSHZQxIkiGDt/EMTwOullNeyC0dzVTwvnveelaT24HBRqAC0NodpgYp0RscJyYYYljpprh8diRxibfFnKP/0IzR7P7eZ+7FmzuIbWLkJI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e9b8bd4-a17e-4ef6-2d3c-08dc842b84ae 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.6640 (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: yo0MNAqmDQYQ3BEVvJqkor1FNOgQtacHGs5mU5nMSWM8cy0oieMNfjmezXjYClIV X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171619_440060_3CCE2CB3 X-CRM114-Status: GOOD ( 22.11 ) 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 This removes all the notifier de-duplication logic in the driver and relies on the core code to de-duplicate and allocate only one SVA domain per mm per smmu instance. This naturally gives a 1:1 relationship between SVA domain and mmu notifier. It is a significant simplication of the flow, as we end up with a single struct arm_smmu_domain for each MM and the invalidation can then be shifted to properly use the masters list like S1/S2 do. Remove all of the previous mmu_notifier, bond, shared cd, and cd refcount logic entirely. The logic here is tightly wound together with the unusued BTM support. Since the BTM logic requires holding all the iommu_domains in a global ASID xarray it conflicts with the design to have a single SVA domain per PASID, as multiple SMMU instances will need to have different domains. Following patches resolve this by making the ASID xarray per-instance instead of global. However, converting the BTM code over to this methodology requires many changes. Thus, since ARM_SMMU_FEAT_BTM is never enabled, remove the parts of the BTM support for ASID sharing that interact with SVA as well. A followup series is already working on fully enabling the BTM support, that requires iommufd's VIOMMU feature to bring in the KVM's VMID as well. It will come with an already written patch to bring back the ASID sharing using a per-instance ASID xarray. https://lore.kernel.org/linux-iommu/20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com/ https://lore.kernel.org/linux-iommu/26-v6-228e7adf25eb+4155-smmuv3_newapi_p2_jgg@nvidia.com/ Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Michael Shavit --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 395 +++--------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 69 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 15 +- 3 files changed, 86 insertions(+), 393 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index aa033cd65adc5a..a7c36654dee5a5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -13,29 +13,9 @@ #include "arm-smmu-v3.h" #include "../../io-pgtable-arm.h" -struct arm_smmu_mmu_notifier { - struct mmu_notifier mn; - struct arm_smmu_ctx_desc *cd; - bool cleared; - refcount_t refs; - struct list_head list; - struct arm_smmu_domain *domain; -}; - -#define mn_to_smmu(mn) container_of(mn, struct arm_smmu_mmu_notifier, mn) - -struct arm_smmu_bond { - struct mm_struct *mm; - struct arm_smmu_mmu_notifier *smmu_mn; - struct list_head list; -}; - -#define sva_to_bond(handle) \ - container_of(handle, struct arm_smmu_bond, sva) - static DEFINE_MUTEX(sva_lock); -static void +static void __maybe_unused arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) { struct arm_smmu_master_domain *master_domain; @@ -58,58 +38,6 @@ arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); } -/* - * Check if the CPU ASID is available on the SMMU side. If a private context - * descriptor is using it, try to replace it. - */ -static struct arm_smmu_ctx_desc * -arm_smmu_share_asid(struct mm_struct *mm, u16 asid) -{ - int ret; - u32 new_asid; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_device *smmu; - struct arm_smmu_domain *smmu_domain; - - cd = xa_load(&arm_smmu_asid_xa, asid); - if (!cd) - return NULL; - - if (cd->mm) { - if (WARN_ON(cd->mm != mm)) - return ERR_PTR(-EINVAL); - /* All devices bound to this mm use the same cd struct. */ - refcount_inc(&cd->refs); - return cd; - } - - smmu_domain = container_of(cd, struct arm_smmu_domain, cd); - smmu = smmu_domain->smmu; - - ret = xa_alloc(&arm_smmu_asid_xa, &new_asid, cd, - XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); - if (ret) - return ERR_PTR(-ENOSPC); - /* - * Race with unmap: TLB invalidations will start targeting the new ASID, - * which isn't assigned yet. We'll do an invalidate-all on the old ASID - * later, so it doesn't matter. - */ - cd->asid = new_asid; - /* - * Update ASID and invalidate CD in all associated masters. There will - * be some overlap between use of both ASIDs, until we invalidate the - * TLB. - */ - arm_smmu_update_s1_domain_cd_entry(smmu_domain); - - /* Invalidate TLB entries previously associated with that context */ - arm_smmu_tlb_inv_asid(smmu, asid); - - xa_erase(&arm_smmu_asid_xa, asid); - return NULL; -} - static u64 page_size_to_cd(void) { static_assert(PAGE_SIZE == SZ_4K || PAGE_SIZE == SZ_16K || @@ -187,69 +115,6 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, } EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_sva_cd); -static struct arm_smmu_ctx_desc *arm_smmu_alloc_shared_cd(struct mm_struct *mm) -{ - u16 asid; - int err = 0; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_ctx_desc *ret = NULL; - - /* Don't free the mm until we release the ASID */ - mmgrab(mm); - - asid = arm64_mm_context_get(mm); - if (!asid) { - err = -ESRCH; - goto out_drop_mm; - } - - cd = kzalloc(sizeof(*cd), GFP_KERNEL); - if (!cd) { - err = -ENOMEM; - goto out_put_context; - } - - refcount_set(&cd->refs, 1); - - mutex_lock(&arm_smmu_asid_lock); - ret = arm_smmu_share_asid(mm, asid); - if (ret) { - mutex_unlock(&arm_smmu_asid_lock); - goto out_free_cd; - } - - err = xa_insert(&arm_smmu_asid_xa, asid, cd, GFP_KERNEL); - mutex_unlock(&arm_smmu_asid_lock); - - if (err) - goto out_free_asid; - - cd->asid = asid; - cd->mm = mm; - - return cd; - -out_free_asid: - arm_smmu_free_asid(cd); -out_free_cd: - kfree(cd); -out_put_context: - arm64_mm_context_put(mm); -out_drop_mm: - mmdrop(mm); - return err < 0 ? ERR_PTR(err) : ret; -} - -static void arm_smmu_free_shared_cd(struct arm_smmu_ctx_desc *cd) -{ - if (arm_smmu_free_asid(cd)) { - /* Unpin ASID */ - arm64_mm_context_put(cd->mm); - mmdrop(cd->mm); - kfree(cd); - } -} - /* * Cloned from the MAX_TLBI_OPS in arch/arm64/include/asm/tlbflush.h, this * is used as a threshold to replace per-page TLBI commands to issue in the @@ -264,8 +129,8 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, unsigned long start, unsigned long end) { - struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; + struct arm_smmu_domain *smmu_domain = + container_of(mn, struct arm_smmu_domain, mmu_notifier); size_t size; /* @@ -282,34 +147,22 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, size = 0; } - if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) { - if (!size) - arm_smmu_tlb_inv_asid(smmu_domain->smmu, - smmu_mn->cd->asid); - else - arm_smmu_tlb_inv_range_asid(start, size, - smmu_mn->cd->asid, - PAGE_SIZE, false, - smmu_domain); - } + if (!size) + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + else + arm_smmu_tlb_inv_range_asid(start, size, smmu_domain->cd.asid, + PAGE_SIZE, false, smmu_domain); - arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), start, - size); + arm_smmu_atc_inv_domain(smmu_domain, start, size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) { - struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; + struct arm_smmu_domain *smmu_domain = + container_of(mn, struct arm_smmu_domain, mmu_notifier); struct arm_smmu_master_domain *master_domain; unsigned long flags; - mutex_lock(&sva_lock); - if (smmu_mn->cleared) { - mutex_unlock(&sva_lock); - return; - } - /* * DMA may still be running. Keep the cd valid to avoid C_BAD_CD events, * but disable translation. @@ -321,25 +174,23 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) struct arm_smmu_cd target; struct arm_smmu_cd *cdptr; - cdptr = arm_smmu_get_cd_ptr(master, mm_get_enqcmd_pasid(mm)); + cdptr = arm_smmu_get_cd_ptr(master, master_domain->ssid); if (WARN_ON(!cdptr)) continue; - arm_smmu_make_sva_cd(&target, master, NULL, smmu_mn->cd->asid); - arm_smmu_write_cd_entry(master, mm_get_enqcmd_pasid(mm), cdptr, + arm_smmu_make_sva_cd(&target, master, NULL, + smmu_domain->cd.asid); + arm_smmu_write_cd_entry(master, master_domain->ssid, cdptr, &target); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); - arm_smmu_atc_inv_domain_sva(smmu_domain, mm_get_enqcmd_pasid(mm), 0, 0); - - smmu_mn->cleared = true; - mutex_unlock(&sva_lock); + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } static void arm_smmu_mmu_notifier_free(struct mmu_notifier *mn) { - kfree(mn_to_smmu(mn)); + kfree(container_of(mn, struct arm_smmu_domain, mmu_notifier)); } static const struct mmu_notifier_ops arm_smmu_mmu_notifier_ops = { @@ -348,115 +199,6 @@ static const struct mmu_notifier_ops arm_smmu_mmu_notifier_ops = { .free_notifier = arm_smmu_mmu_notifier_free, }; -/* Allocate or get existing MMU notifier for this {domain, mm} pair */ -static struct arm_smmu_mmu_notifier * -arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain, - struct mm_struct *mm) -{ - int ret; - struct arm_smmu_ctx_desc *cd; - struct arm_smmu_mmu_notifier *smmu_mn; - - list_for_each_entry(smmu_mn, &smmu_domain->mmu_notifiers, list) { - if (smmu_mn->mn.mm == mm) { - refcount_inc(&smmu_mn->refs); - return smmu_mn; - } - } - - cd = arm_smmu_alloc_shared_cd(mm); - if (IS_ERR(cd)) - return ERR_CAST(cd); - - smmu_mn = kzalloc(sizeof(*smmu_mn), GFP_KERNEL); - if (!smmu_mn) { - ret = -ENOMEM; - goto err_free_cd; - } - - refcount_set(&smmu_mn->refs, 1); - smmu_mn->cd = cd; - smmu_mn->domain = smmu_domain; - smmu_mn->mn.ops = &arm_smmu_mmu_notifier_ops; - - ret = mmu_notifier_register(&smmu_mn->mn, mm); - if (ret) { - kfree(smmu_mn); - goto err_free_cd; - } - - list_add(&smmu_mn->list, &smmu_domain->mmu_notifiers); - return smmu_mn; - -err_free_cd: - arm_smmu_free_shared_cd(cd); - return ERR_PTR(ret); -} - -static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) -{ - struct mm_struct *mm = smmu_mn->mn.mm; - struct arm_smmu_ctx_desc *cd = smmu_mn->cd; - struct arm_smmu_domain *smmu_domain = smmu_mn->domain; - - if (!refcount_dec_and_test(&smmu_mn->refs)) - return; - - list_del(&smmu_mn->list); - - /* - * If we went through clear(), we've already invalidated, and no - * new TLB entry can have been formed. - */ - if (!smmu_mn->cleared) { - arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); - arm_smmu_atc_inv_domain_sva(smmu_domain, - mm_get_enqcmd_pasid(mm), 0, 0); - } - - /* Frees smmu_mn */ - mmu_notifier_put(&smmu_mn->mn); - arm_smmu_free_shared_cd(cd); -} - -static struct arm_smmu_bond *__arm_smmu_sva_bind(struct device *dev, - struct mm_struct *mm) -{ - int ret; - struct arm_smmu_bond *bond; - struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct arm_smmu_domain *smmu_domain; - - if (!(domain->type & __IOMMU_DOMAIN_PAGING)) - return ERR_PTR(-ENODEV); - smmu_domain = to_smmu_domain(domain); - if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) - return ERR_PTR(-ENODEV); - - if (!master || !master->sva_enabled) - return ERR_PTR(-ENODEV); - - bond = kzalloc(sizeof(*bond), GFP_KERNEL); - if (!bond) - return ERR_PTR(-ENOMEM); - - bond->mm = mm; - - bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm); - if (IS_ERR(bond->smmu_mn)) { - ret = PTR_ERR(bond->smmu_mn); - goto err_free_bond; - } - - list_add(&bond->list, &master->bonds); - return bond; - -err_free_bond: - kfree(bond); - return ERR_PTR(ret); -} - bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) { unsigned long reg, fld; @@ -573,11 +315,6 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master) int arm_smmu_master_disable_sva(struct arm_smmu_master *master) { mutex_lock(&sva_lock); - if (!list_empty(&master->bonds)) { - dev_err(master->dev, "cannot disable SVA, device is bound\n"); - mutex_unlock(&sva_lock); - return -EBUSY; - } arm_smmu_master_sva_disable_iopf(master); master->sva_enabled = false; mutex_unlock(&sva_lock); @@ -594,66 +331,51 @@ void arm_smmu_sva_notifier_synchronize(void) mmu_notifier_synchronize(); } -void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, - struct device *dev, ioasid_t id) -{ - struct mm_struct *mm = domain->mm; - struct arm_smmu_bond *bond = NULL, *t; - struct arm_smmu_master *master = dev_iommu_priv_get(dev); - - arm_smmu_remove_pasid(master, to_smmu_domain(domain), id); - - mutex_lock(&sva_lock); - list_for_each_entry(t, &master->bonds, list) { - if (t->mm == mm) { - bond = t; - break; - } - } - - if (!WARN_ON(!bond)) { - list_del(&bond->list); - arm_smmu_mmu_notifier_put(bond->smmu_mn); - kfree(bond); - } - mutex_unlock(&sva_lock); -} - static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct mm_struct *mm = domain->mm; - struct arm_smmu_bond *bond; struct arm_smmu_cd target; int ret; - if (mm_get_enqcmd_pasid(mm) != id) + /* Prevent arm_smmu_mm_release from being called while we are attaching */ + if (!mmget_not_zero(domain->mm)) return -EINVAL; - mutex_lock(&sva_lock); - bond = __arm_smmu_sva_bind(dev, mm); - if (IS_ERR(bond)) { - mutex_unlock(&sva_lock); - return PTR_ERR(bond); - } + /* + * This does not need the arm_smmu_asid_lock because SVA domains never + * get reassigned + */ + arm_smmu_make_sva_cd(&target, master, domain->mm, smmu_domain->cd.asid); + ret = arm_smmu_set_pasid(master, smmu_domain, id, &target); - arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target); - if (ret) { - list_del(&bond->list); - arm_smmu_mmu_notifier_put(bond->smmu_mn); - kfree(bond); - mutex_unlock(&sva_lock); - return ret; - } - mutex_unlock(&sva_lock); - return 0; + mmput(domain->mm); + return ret; } static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(to_smmu_domain(domain)); + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + + /* + * Ensure the ASID is empty in the iommu cache before allowing reuse. + */ + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_domain->cd.asid); + + /* + * Notice that the arm_smmu_mm_arch_invalidate_secondary_tlbs op can + * still be called/running at this point. We allow the ASID to be + * reused, and if there is a race then it just suffers harmless + * unnecessary invalidation. + */ + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); + + /* + * Actual free is defered to the SRCU callback + * arm_smmu_mmu_notifier_free() + */ + mmu_notifier_put(&smmu_domain->mmu_notifier); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -667,6 +389,8 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_domain *smmu_domain; + u32 asid; + int ret; smmu_domain = arm_smmu_domain_alloc(); if (IS_ERR(smmu_domain)) @@ -675,5 +399,22 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; smmu_domain->smmu = smmu; + ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain, + XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); + if (ret) + goto err_free; + + smmu_domain->cd.asid = asid; + smmu_domain->mmu_notifier.ops = &arm_smmu_mmu_notifier_ops; + ret = mmu_notifier_register(&smmu_domain->mmu_notifier, mm); + if (ret) + goto err_asid; + return &smmu_domain->domain; + +err_asid: + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); +err_free: + kfree(smmu_domain); + return ERR_PTR(ret); } 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 24000027253de8..2a845ab6d53b57 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1439,22 +1439,6 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) cd_table->cdtab = NULL; } -bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) -{ - bool free; - struct arm_smmu_ctx_desc *old_cd; - - if (!cd->asid) - return false; - - free = refcount_dec_and_test(&cd->refs); - if (free) { - old_cd = xa_erase(&arm_smmu_asid_xa, cd->asid); - WARN_ON(old_cd != cd); - } - return free; -} - /* Stream table manipulation functions */ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) @@ -2023,8 +2007,8 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, return arm_smmu_cmdq_batch_submit(master->smmu, &cmds); } -static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size) +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size) { struct arm_smmu_master_domain *master_domain; int i; @@ -2062,15 +2046,7 @@ static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!master->ats_enabled) continue; - /* - * Non-zero ssid means SVA is co-opting the S1 domain to issue - * invalidations for SVA PASIDs. - */ - if (ssid != IOMMU_NO_PASID) - arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); - else - arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, - &cmd); + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, &cmd); for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; @@ -2082,19 +2058,6 @@ static int __arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, return arm_smmu_cmdq_batch_submit(smmu_domain->smmu, &cmds); } -static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, - unsigned long iova, size_t size) -{ - return __arm_smmu_atc_inv_domain(smmu_domain, IOMMU_NO_PASID, iova, - size); -} - -int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size) -{ - return __arm_smmu_atc_inv_domain(smmu_domain, ssid, iova, size); -} - /* IO_PGTABLE API */ static void arm_smmu_tlb_inv_context(void *cookie) { @@ -2283,7 +2246,6 @@ struct arm_smmu_domain *arm_smmu_domain_alloc(void) mutex_init(&smmu_domain->init_mutex); INIT_LIST_HEAD(&smmu_domain->devices); spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); return smmu_domain; } @@ -2325,7 +2287,7 @@ static void arm_smmu_domain_free_paging(struct iommu_domain *domain) if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { /* Prevent SVA from touching the CD while we're freeing it */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_free_asid(&smmu_domain->cd); + xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); mutex_unlock(&arm_smmu_asid_lock); } else { struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; @@ -2343,11 +2305,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu, u32 asid; struct arm_smmu_ctx_desc *cd = &smmu_domain->cd; - refcount_set(&cd->refs, 1); - /* Prevent SVA from modifying the ASID until it is written to the CD */ mutex_lock(&arm_smmu_asid_lock); - ret = xa_alloc(&arm_smmu_asid_xa, &asid, cd, + ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain, XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); cd->asid = (u16)asid; mutex_unlock(&arm_smmu_asid_lock); @@ -2835,6 +2795,9 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, /* The core code validates pasid */ + if (smmu_domain->smmu != master->smmu) + return -EINVAL; + if (!master->cd_table.in_ste) return -ENODEV; @@ -2856,9 +2819,14 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, return ret; } -void arm_smmu_remove_pasid(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, ioasid_t pasid) +static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, + struct iommu_domain *domain) { + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_domain *smmu_domain; + + smmu_domain = to_smmu_domain(domain); + mutex_lock(&arm_smmu_asid_lock); arm_smmu_clear_cd(master, pasid); if (master->ats_enabled) @@ -3129,7 +3097,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; - INIT_LIST_HEAD(&master->bonds); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); @@ -3311,12 +3278,6 @@ static int arm_smmu_def_domain_type(struct device *dev) return 0; } -static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, - struct iommu_domain *domain) -{ - arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); -} - static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 212c18c70fa03e..d175d9eee6c61b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -587,9 +587,6 @@ struct arm_smmu_strtab_l1_desc { struct arm_smmu_ctx_desc { u16 asid; - - refcount_t refs; - struct mm_struct *mm; }; struct arm_smmu_l1_ctx_desc { @@ -712,7 +709,6 @@ struct arm_smmu_master { bool stall_enabled; bool sva_enabled; bool iopf_enabled; - struct list_head bonds; unsigned int ssid_bits; }; @@ -741,7 +737,7 @@ struct arm_smmu_domain { struct list_head devices; spinlock_t devices_lock; - struct list_head mmu_notifiers; + struct mmu_notifier mmu_notifier; }; /* The following are exposed for testing purposes. */ @@ -805,16 +801,13 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, 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); -void arm_smmu_remove_pasid(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, ioasid_t pasid); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf, struct arm_smmu_domain *smmu_domain); -bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); -int arm_smmu_atc_inv_domain_sva(struct arm_smmu_domain *smmu_domain, - ioasid_t ssid, unsigned long iova, size_t size); +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, + unsigned long iova, size_t size); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); @@ -826,8 +819,6 @@ bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm); -void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, - struct device *dev, ioasid_t id); #else /* CONFIG_ARM_SMMU_V3_SVA */ static inline bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) { From patchwork Tue Jun 4 00:15:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684499 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 962B1C27C50 for ; Tue, 4 Jun 2024 00:16:28 +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=Chmpc6ZbkAiWmLoorzWUIlauaO7jA5KMBH6LjUXYA9o=; b=io1RALKxqHqY6F W2O2iKQ/CVygOFfHfuFQ7abkH/DGv4Trtv2ZpVJ2ANsgYy+taAqy5xBHA/Sv2uTMgFYfdlrkdB/ip YTih7MYX+T+57svKwaojzU0tn5pNkcfSo9xwK8pK6v+J1vDNXeADr4S0uCTA8IOzW7+/EJgPIiyHs FK2NjhgDgTzcE5M4vh7Xy0jEHNQzjwYCyHRju01ZRVeks+idyvFXVzSPjaWkhpZB3zCmDfvtAZlt5 Ah4EDm+SmlBUz8e8zCo65Ije/gFurEu1gh76knhFvLJvdWqD11CwFXUSoehFq5u4AcCndgc3jrGo2 91eD0LjeAUJnm7jJKHpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqb-00000000hcc-38ne; Tue, 04 Jun 2024 00:16:17 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqW-00000000hYg-3u6t for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hrWKFWbyZndVVvfpdjjcJeflH5J5+VMn6cSylbPNBtEjEG6Z2YJ85SNNSh6844rHuymayiyt+J0OnBzuvNp1HJuGM599ASe6rqT+Dd42Dz1HxRWez5tLjqxGUxLyDtWUdRRtGVXKlevgvSgyu4BvZqNibhbLc4tr83WyYP/26Hvpp3oTqZdo1hbUQEzrTVkbagy20+s1UUH9Nud8OLlDzzbeHEYsf1Sg0EzvLIQjBGB3E0mMesVr+aJD1zOzjxlQsGEGcl5c8MjyuwtcjLoYfcSarHHlnt3iJ/RswC2RkKCCFgetD2K0L+A9Ot7c0Nb3PjdJwg+TeWQ94EoEpHZ42w== 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=LFGnmC08nDxpDc7TIKR3BN1D1je7H6LGFfYUsnAkzC0=; b=ftTwUCo+l+Mzc8jESGVfpfQjSLZBh4zaGuR++Jnf/z0/ir7tFyhK3e4clWax/cz1tKLG5p/yLLVKkQgJEPKAAsXKZQGJOK9wlpfFfA5agvn4AZobZZeauIsZ8Cab8ohmIMPx/6IRiZ7pB46Gi4j41G5yr7TkTi8P/dFHmv1z0tP50taP9rKAEgKZfhp0YgOW3hL5RuNSu6JSTkfWUCiAAg/dn2fUUMaSCm4YG7oW5oxMqnkLH/88bNIbl8RLMkNKlOzQ7oFzle0Q72avNf+95siv+banKnCt4Sh+Tx/3lZs9LF+HHzhlMRJl0ETM377To41GhnD1mLUn93O6Ffj5tg== 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=LFGnmC08nDxpDc7TIKR3BN1D1je7H6LGFfYUsnAkzC0=; b=MedyiXXuJimlwYVPUaYGrSU3y3ynF539SkRxeT25/5rjA530j4uR7aZaFjc9U36jXCqL6aYsn5dccysBaeREnBUkWbchonC15zO95Myrw4BsQ6Mz+hRFlOe9OlKebS7eQrM4I+ZufnmN9hNIhMJmSJiUEMHQ9aTNFpf8OngrEJEoOwPp4qjTP+335+RjOCcmnnrFZBA11vOjPOY2Qcc0JQTiIUAA5gm+Oj98W+4j8VbgKkiQdUPDiMh4GsRr7QHEQUrJ8g5wrHffYr21IoWxGGUIt4xpjZ2pUb8+lukxOwgnJ1aZ6AXzRIif5uKK1IEriC40EnaDeZNr0YE756kzew== 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:03 +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:03 +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 11/14] iommu/arm-smmu-v3: Allow IDENTITY/BLOCKED to be set while PASID is used Date: Mon, 3 Jun 2024 21:15:56 -0300 Message-ID: <11-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: BLAP220CA0010.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::15) 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: 3c4e506b-01ed-423f-b758-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: IKaH3MVcGUdDq2q7Grc7jfaWx6nmvoG7q/86E6UOJ987vv01ZQalMx455bYOei3w57D/lZu2iZi30K6HAzrDwoBhaiFo/MyO+soWaPlkERqgxHaSlRdCjkVjNq5A8r+GISkp1v/U3OG0olr+xRtrc/0wM1UR5uYvUN8YXkvY4glZEOcmUnSrr5L0W5p7jYVnAhW3glPgOI9PxwEnflTltzjonaBFOso9PBU2+Hz9pWmxqHttfDm9ciDXQqujc+QYL1FU2W/eOpYeYb4Bdv3mGu7jRCsSWGKi3Mitzq3xrzOu+Z13fupeB8WpsxwkgY7pgFpz30Mwy0dI9Onb2YAITvmp01giOiA3DAINaXqFgnjxdoinzLrtLpJ2ryr785k3bvKpONVJl0247bhIhcYzuPCgfKOMNMGeEyASvhptfoYEFNRthM+aNkRUBAjpoWHUW9XcZxd3tJl2J2G9gC6A8Gescz67PVLWckaXkhMPTc+nCf5RwldyGN0rxFvZsCF6F+ejxY3zcg7OKeEpXKw9yxHXb1Msf1wH9sWmoSWISlBMqc7+BV5gE78TMbOGcO1beiSe/7tfOGjGRggLKI73+Vfa6DuY2D2FfDbliaGNniYkpr6vSmU2ftoTyK1A/9/n8bx7X25CQcrVw0Q4QDnsC7CbftuIsczTedfCGXUTeth2H6CJHhhXKMI2yghCfFzHdBKS2pT7orW9ickC6STKpPsHAh6eRAy1xVA35B7r3CFvbWVA+1yntLwUVL3Y9S7b4WodbIwrxOZ+ohwIBv9xAsyUHpo6icx0FweImPAtZfamj9YDgyELvP+aH5J1xvXvmT/VQozAlvcH9qT1/pvdaxC9wEXrbCv5xV3I/Mud2TJM4K46PRcjpg03DMjidTkln5AlBepr34Zc5hbR7uCQMU5tb3vNIE3YEUrMGS7gbzuTDr1gnyg7jIdtE6yKNvECO6MKhOuO75a7Imj+CI1E5RCRXuFlENh4ApVoniN7tPm3SrhWZQhLCyEuB6p5Jkd3C3pjH6vw6Yl3lY5cEmPiAjs2EaYC/FCIR5b5R1IlPu/A3HX8dbwRAkJG9t+mwD5q34/1aQWEdU9TVBrsfSngPmp3ubeNo0z947bWjV0Kv+Ms1Gd0z4UOV/z9gMR5WVgrXL3aFGUuDMMebc5fO6CWNViVrbgXlFEskT6TlyNbL5mHO8oa8L0+jQs377132BNYjwbKphavxLsM/aGvU3ROxs63yI74Xhzc13nZCPy9TFPLlrM6V3oud7XTi2uwgzyVDswXvISp+fhEh/osD+27qw== 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HB5WbFNTUpp2QXWUqLviWSVD8yQ6ti7i0bzbto37GLr4wH4fOPoU+G/4myL4L0gYgsM7qhQfg3QSDOdjbH9da7hxueMQrB4j0485ckIEUESc6E/5UGOajQk1NGjpbgvg617gfXepMefQzLX6Ji0u4uq/JXCyf+iXwdWYri6cEd0y6y1j7onQBKp6+0e0cuV/k1j/eA72eUlSjAuJJpmS8iOKQ58Bn1LpJ4vfL3oHMvN/OYY7cA0WVVRWgRjXdaCv6Y/FNomRxdTUjdDrRYxDGwo96zzs6qoUZ/HeJVgczlAUJNNw2T8TJfgEpL3daXBDnNjsE50QH9qTkYKM/ua9joytV+kgqF75JTJ6flf57BPpWcMRgbwNddOBmGkufORqfBsrm3ew+H7E6RTtY+gDWcGMqCEY1do7+y0U1+c+JQruHO7aTT+0s9SbiQPGoSL9tASzNy+gk1WsR2q1WGy131xBthnlAV073x3lGliNKoSq+UlNMOnG9xKTmuIhXZqrH4UG39HckUnHP/ii+VWJF8NLC1K1YlWjSBYa/u5VEblaYo0RDoBiP90jCnK2JnwKAZJSqcoAMM4ApVrvsASWf5IHsVsgHNTPh7TkmT2vNPsF+kx3WpeBu3rCClifS6IzWj0RoB8DWqcP3n91uN/69v7s2TbM+ndZT0+aICPA65Otszq9tbMzKIcUoCSU6BsPJKy9RGKNOdcl6l24LeLRRsGDc1tcjMtHQCxQtt26PR4j/PYrYM3f6J5kXyNh/EW7lyzeF+8AkYDnwPJBDnjFIrJC9p5Y9vebZUpTU76jEt5v54uGoQzhcvoLXepHhdFJ1Xl8UlAGLvEbOvL73yfCMJ6KiaKGDxhYAyTbPLJnKu+M0K5bhriV36lenlNtKZJwx3ARGP+ZfRl3bVIfPo0HgzE+PwiPRVCpMxBFfO65o1Sbsv14a3Q96B+mG0NQbb48J0800E/Nq60LDD9YLXk3X6jbjbcTD+oM+PWLcc2Qe1Lx7s3AW0K17dhk8+499FTE6nv8FIciNJn3FY4QC3FGWGQ/VPFu5RPQnJrP6SPJJPuexIWM+ilHWhOjxwBymb46GsN6SiuaFC82oBysZY7R6bFq3GhAAkPVvMvgpetrsmDV6p7ir9gtt+Q2AHN8giOPC1SfFIW6lYD7JJknm7KerTezEZ3SR4GodLorZlwctx3Xf571zUxox+b7m32fu0V19ZGxWUvemO8R05u3+WAOYzeL737kl+Mx1EbJhViC3zMVoqmWMygXAXgyjz9WnyrmCloeZJ9HgHEBXaRKygYZAVqamcEcyplrc+Nrm2qawFhsJw7EG3kQMb7g1jgveRa1QxJFpgSgoLDad2mVMlR3yzw1r/f2nLJYdYpLGaOzMvIjoAUX/by4hxZ5S5olmxIY8EjV2v2NCGQXx7pGkQi4cmv5/osmoGzTRBBt0jVEPry1EUE3QLUHG4P5PcUJdmkwhw0E4Jj6NCj6Ffh2HNALoeEWn28yfncMvarBRZd4g9ayETwNcswMFp057Ahwe64OHbYzpGnyuV/fVcYFDz7kyBROK/wxO6vPRyL68Wtfvyo= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c4e506b-01ed-423f-b758-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.5058 (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: H3yhqUf49YxXQWR0X7pZreXwOVShFD7bF5SNk57oMjgJ1j5dUezd5I2JPLQQWjto X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171613_008059_CF0121BF X-CRM114-Status: GOOD ( 27.25 ) 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 The HW supports this, use the S1DSS bits to configure the behavior of SSID=0 which is the RID's translation. If SSID's are currently being used in the CD table then just update the S1DSS bits in the STE, remove the master_domain and leave ATS alone. For iommufd the driver design has a small problem that all the unused CD table entries are set with V=0 which will generate an event if VFIO userspace tries to use the CD entry. This patch extends this problem to include the RID as well if PASID is being used. For BLOCKED with used PASIDs the F_STREAM_DISABLED (STRTAB_STE_1_S1DSS_TERMINATE) event is generated on untagged traffic and a substream CD table entry with V=0 (removed pasid) will generate C_BAD_CD. Arguably there is no advantage to using S1DSS over the CD entry 0 with V=0. As we don't yet support PASID in iommufd this is a problem to resolve later, possibly by using EPD0 for unused CD table entries instead of V=0, and not using S1DSS for BLOCKED. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 60 +++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 +- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index a460b71f585789..d7e022bb9df530 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -164,7 +164,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master, true); + arm_smmu_make_cdtable_ste(ste, &master, true, STRTAB_STE_1_S1DSS_SSID0); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) 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 2a845ab6d53b57..1b43fc1fe85387 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -991,6 +991,14 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits) STRTAB_STE_1_S1STALLD | STRTAB_STE_1_STRW | STRTAB_STE_1_EATS); used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); + + /* + * See 13.5 Summary of attribute/permission configuration fields + * for the SHCFG behavior. + */ + if (FIELD_GET(STRTAB_STE_1_S1DSS, le64_to_cpu(ent[1])) == + STRTAB_STE_1_S1DSS_BYPASS) + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); } /* S2 translates */ @@ -1531,7 +1539,8 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_bypass_ste); VISIBLE_IF_KUNIT void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master, bool ats_enabled) + struct arm_smmu_master *master, bool ats_enabled, + unsigned int s1dss) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -1545,7 +1554,7 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax)); target->data[1] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | + FIELD_PREP(STRTAB_STE_1_S1DSS, s1dss) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | @@ -1556,6 +1565,11 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_EATS, ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + if ((smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) && + s1dss == STRTAB_STE_1_S1DSS_BYPASS) + target->data[1] |= cpu_to_le64(FIELD_PREP( + STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); + if (smmu->features & ARM_SMMU_FEAT_E2H) { /* * To support BTM the streamworld needs to match the @@ -2579,6 +2593,7 @@ struct arm_smmu_attach_state { /* Inputs */ struct iommu_domain *old_domain; struct arm_smmu_master *master; + bool cd_needs_ats; ioasid_t ssid; /* Resulting state */ bool ats_enabled; @@ -2621,7 +2636,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, */ lockdep_assert_held(&arm_smmu_asid_lock); - if (smmu_domain) { + if (smmu_domain || state->cd_needs_ats) { /* * The SMMU does not support enabling ATS with bypass/abort. * When the STE is in bypass (STE.Config[2:0] == 0b100), ATS @@ -2633,7 +2648,9 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * tables. */ state->ats_enabled = arm_smmu_ats_supported(master); + } + if (smmu_domain) { master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); if (!master_domain) return -ENOMEM; @@ -2761,7 +2778,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); arm_smmu_write_cd_entry(master, IOMMU_NO_PASID, cdptr, &target_cd); - arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled); + arm_smmu_make_cdtable_ste(&target, master, state.ats_enabled, + STRTAB_STE_1_S1DSS_SSID0); arm_smmu_install_ste_for_dev(master, &target); break; } @@ -2835,8 +2853,10 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, mutex_unlock(&arm_smmu_asid_lock); } -static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, - struct device *dev, struct arm_smmu_ste *ste) +static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, + struct device *dev, + struct arm_smmu_ste *ste, + unsigned int s1dss) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_attach_state state = { @@ -2845,16 +2865,28 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, .ssid = IOMMU_NO_PASID, }; - if (arm_smmu_ssids_in_use(&master->cd_table)) - return -EBUSY; - /* * Do not allow any ASID to be changed while are working on the STE, * otherwise we could miss invalidations. */ mutex_lock(&arm_smmu_asid_lock); - arm_smmu_attach_prepare(&state, domain); + /* + * If the CD table is not in use we can use the provided STE, otherwise + * we use a cdtable STE with the provided S1DSS. + */ + if (arm_smmu_ssids_in_use(&master->cd_table)) { + /* + * If a CD table has to be present then we need to run with ATS + * on even though the RID will fail ATS queries with UR. This is + * because we have no idea what the PASID's need. + */ + state.cd_needs_ats = true; + arm_smmu_attach_prepare(&state, domain); + arm_smmu_make_cdtable_ste(ste, master, state.ats_enabled, s1dss); + } else { + arm_smmu_attach_prepare(&state, domain); + } arm_smmu_install_ste_for_dev(master, ste); arm_smmu_attach_commit(&state); mutex_unlock(&arm_smmu_asid_lock); @@ -2865,7 +2897,6 @@ static int arm_smmu_attach_dev_ste(struct iommu_domain *domain, * descriptor from arm_smmu_share_asid(). */ arm_smmu_clear_cd(master, IOMMU_NO_PASID); - return 0; } static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, @@ -2875,7 +2906,8 @@ static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, struct arm_smmu_master *master = dev_iommu_priv_get(dev); arm_smmu_make_bypass_ste(master->smmu, &ste); - return arm_smmu_attach_dev_ste(domain, dev, &ste); + arm_smmu_attach_dev_ste(domain, dev, &ste, STRTAB_STE_1_S1DSS_BYPASS); + return 0; } static const struct iommu_domain_ops arm_smmu_identity_ops = { @@ -2893,7 +2925,9 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, struct arm_smmu_ste ste; arm_smmu_make_abort_ste(&ste); - return arm_smmu_attach_dev_ste(domain, dev, &ste); + arm_smmu_attach_dev_ste(domain, dev, &ste, + STRTAB_STE_1_S1DSS_TERMINATE); + return 0; } static const struct iommu_domain_ops arm_smmu_blocked_ops = { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index d175d9eee6c61b..30459a800c7b2d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -761,8 +761,8 @@ void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_bypass_ste(struct arm_smmu_device *smmu, struct arm_smmu_ste *target); void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master, - bool ats_enabled); + struct arm_smmu_master *master, bool ats_enabled, + unsigned int s1dss); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, From patchwork Tue Jun 4 00:15: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: 13684506 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 774C8C25B78 for ; Tue, 4 Jun 2024 00:17:01 +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=cOCb9aSDXfcEyFGnqp4BJWArIH7vJEUdkPt3/J99CLI=; b=UbzLtb3ibsnGNS qWrgrl5KrEweBKx2BHLyZCCZWNiNLG8hbsZuPeNDw1cOmG8E/LaSZJrBVk3V+zzorD62aOMPpRviS em1ZZ+H0PhHnAG5rz2TiGNcY5H87Ir3ElWrHbVsE/02BpKMe3cHjJ6xLpBx+NEbwflMoeVfo59eVp PDRahTRxbydRIbuAnsyDJFWHukuQASafrXFybskBDhBRvKmHrBeVuhwD4w8ZFrf9V2KGkoTguonol 2qDSBwzwRM1JQxafcS4ZP4GjbRLc3donXDIZCwljYGyrLkvGP6sc0xKcAbKT5F1ZvHBRRhEjDdq6E wTZ+q/yBFcy9/Ykl39Gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHr8-00000000i4Q-0iCo; Tue, 04 Jun 2024 00:16:50 +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 1sEHqb-00000000hZE-3iq3 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cTyWmc4v0oct8nDYnhiyHUoOC/nJH9V8CoM6XwY2ex8Jm9lea+ZXHHTzfdqrnHto9wmMnrLvTdb0ocEXSPJd47szy1nPaqm94b8jn0EqlbX0Xj6O/MqvSjCM0nZFjXi5uNasB7KHHpOUA3OBTUbpestb7h7KyOX689w7B8+KQ1hnZYSSiynU/XJo3Kt7db/dvWpYi+4kqVHe2hNitx5cDs90CTqdqVcAj1h80fEt+NOV5a+8QI7iqqu00YJkC8Oi52HPwZc9ouBWy9rD/KkubTiMPDOuBEoHcR4pvnBCcdpI7sKwf4cGRD7l0TgxVD6uWF6toxTa4RoCr0acZmELgQ== 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=6AlqI4tMSD8sTiY4rQTFvp3rNKpaA+uSeIf7pGRpoZo=; b=BhPmlrRXatNJ44PP7sAAqJorJczOzP9UVyj0grTP88ndjefuhlW+zKroNB0+GEotbCwmj7XgwgObdqSt/mhYbdHx3GXkIazW/+DurPOM4fWMH8nn3aLJKHyqBgY9VAv706GTItcfXpDSVHhP6/rcgJ5v6fKCix6G4XEpXAJYF9YQwgpiR7Z0ryfu+/N9goa695EhYrp26AH8Rgr6D5A/E5ggDovAJplGpaLudMaHHT3YcvdUengJYbeVPWK/j1JQLq8wue87yTskSwWiFI1FUbD/mxYJ2ZAya6ZCysWk42JfnhO/YGAYX49PhiL5PT3ulP94qVCboaTbHwXTHqgJdQ== 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=6AlqI4tMSD8sTiY4rQTFvp3rNKpaA+uSeIf7pGRpoZo=; b=T1YmO/TyjKD5kUX3dRXEJUoTnsPwnZrvh0WwLI2ZmEKimEMwhtRxIBpg80MUYXWqZY2F2bv/hZTuuR5psYbZN7d/GszEkFmUIcrP6urfyo8cugpYv0lBipk2hQUoApEY7mDvJyw7vBhOH1lg9uV6V2tpkoUzdp0NSuYs0wIhohOoe5dnn/x7p88aCHk5BuF9ZzaNZSKJiluNvHAxdo3Hng8luknme7juiXEnn11V+tblbABDrNvA+CWYk/v4PdYQNgXjZ8cmCwqQJRF4YhhZYCeV4E5xPP7ZLQRRo/QU3QPVo9VA4GOgjlj01j0Hu+T1l9zhw5PShe+9pCeA/+5Wcg== 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:05 +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:05 +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, Shameer Kolothum Subject: [PATCH v8 12/14] iommu/arm-smmu-v3: Test the STE S1DSS functionality Date: Mon, 3 Jun 2024 21:15:57 -0300 Message-ID: <12-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: BL1P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::9) 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: eb006444-4b9d-4d38-dcde-08dc842b84d3 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: +XpzGMEnUWz8VCjn97UMh/TGclu6/l6AsIiW8fpyw1Rpa4rKxUYthW9p8mB308+ymr3Es7uGKEPrh+S0aOsRnwHGmbMH0fft1sktizNT2rpUlteGSuVeoNbDqEUjz6r5686NCl/+XxuvFpurRlW++5ijFkgPV3x0mD5aNeYc0wVQ8sg8JbwYNsasq7gYathxC8XzXJsOFeMDBkb8gP/g90gmF6x1uKu/d1GVnVmcwp44Lflgr0JpjfLXQejMGxf21tkGLHHVTMicrCevfywy7VrJJdfI9cwNiqKyBC2tdWdZuaY3qpzjQAPYGKVgT6ArXyDHwvsamSVk5Cpuyl5AbKmz3GtTF6gAqxHQJKYRqaaLlq6pppKCSeCd+MnX4hjMD6Io37EZHyUJb/dJHlKhDguSfcMe7HwCQ30Ea2U2BJNVgue2mj7f6Oi/WlxvysCnnXKfF1fJZMGTGUcM/UhFbeqpwgYoP/jyVKVdrPBqdE4O9gkoLyyZ36SRGjCC7fStmfOTzj3WG7MZM3xkfQ+u/QDhN3/mbY5wrzMcjVxiJSEIWr5O5Y8lm2vRJtDIKnpwd0Lf7pSaSPaGlmTMArF2HYDyqlZRWBwQTCxfvs57Kb+w9nI3SdbTAROLYSmIbiGpFT9ouOgeU07YPG6l2lHbO0FnymzGsYPK6NF19jrXdzXmsVW15LBRfSUz8NZ0hzqC9i+jbwnt+MVkMmUme+pBwsMR49MgiXlAXRBodhzjXwXxmOB6oITzyGnwvpaTzH2nh2Iq3oowqxSe46KVAbL58su+bHOMPhZA43cNSrWPPg7UcUXSFKw5JtNOgGBtjM21yCIWvUxHAxewJn+wK920A+WvtGmMoKFq7yZwf6MB1Rygwzg3AWhiTsSf8gm0HKijROScFIsJ1O7sY90poDlAFLFWX4EoxrAbLVJZth725XhEqjZFq7HpeIfmGDCJCROqLKWhHDsBOAg102tAJqA48fAQ+sVSPxhLNkSQV4rR64gahJVnB5D1zZvERlFzgTiewhQp9W/wLcYXdfDCD9hr45Eu6755bYI8+Uh72lfZUxu2kbyCTWgt0sDlIOs/3Jdab0wYIeZ8ThEhdU11mqeqOtodSdIvSAqZ7yjGloLNBKly3GdkiT5BQg7lAvB2oDeRbPzCcv/lLC0I8P6UNcseq77Xiu/cvtlm4dwRD5ZhmRk8borevT6iC0M95xHpey6zafBc2bubeyV6MYXAYBZYlS1j63kt7NDZ4CzfRBG6apczH7l5WZuoKPzGCDyEOtwnlq9u3GOdbt2R5/1HmOKgww== 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-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DL37Pu+GZSMGtSVRGnsMCztSycs1aIbnjSuYMXmUQiOAAOqnD8d7KTd00qDJ5fFTvlY42b4FAwYkjwraFA86EbAFmOzSlMHYH6j8dSeNxJVVvPuJj84jGEoEdNwbhlVPLkhGEVxTj6TGva9Rjh8ulKf6H3glo6p25Wbh/E5PorP+BPrFk0sFR5NMLe/QAWehSm+wYajQyP+lz+qHrb5mMq//MaHmBnwn+gzPBghYpKhKkYvsTJIUaGqZNs2hR97E4zBP9YcmkyNKca8MHF+RjuJz1G+i7gSCyMuFNbbe3ja7DNMYwafeIU+JSv4B28k3TNao+wViBXI14XNl4+JdipJj9iZRQ13PDJzt4G1gy1TyvLL0rX49L+SL3ZGPV73ycQy6pa8oauwN9DCllIID5YSOjTgTNylTtpS8jGpgq+xMEMswz+k8qILZDWxG1FeBwLfmJTNTB9Ka7t0CCvFmfaxFtltmcpGq4ZGeoF2NNwdu4f5UpjCKfu15IWYbMpyqOdaWHA4OE/EPRoCf3+vmtyzJFGuKNLpxR3vdxiDHNGd1gVwVRyzuABVmb9J32/aa1ANUpyX/5aXwvv6z3pAbWjQJlN7TqUayxklz7wnudvWQzDHR5NVaveTy0tLx0FSck4RcN/6rbWZldMS2V2XM2qJw/m+He1+s5L33VbAEvFELGscndR5/euBtXZtHmq9Hbo4OMKbkZPUU/tXFo5lg7i9HZhG8vQtXmqZOPoe6adiqP4R233yzBwrr2wNQuWYCTjoTfEUVFA2ztv+5WLt2BRUXdHpThhYMA8RVPo1gvAW3KaUOcL9pwVtwUToWgU1+UW6FkiRNlpKz/7cODkNuj6wilApKXAYQ2fpWk6FPtXDRorkRavdhCyyGiAW35nnhQHg9bfvFujJf9amrUbYBT/lxV5MofG3qjjIsTlMWaXeb5/XLB5VAWATyaUW96lGqL211TmK3755hx17fMY/CKvxxb3DwWJPpFlGYYdbCVTIqW/fJPG5AUQfnlzWvCI+Jv0JUDfuJ/BbTOKcH/0pipcQr6lRb325yHGLbOblaxmy3DCxFr4kHPDI//YW8aRSrGc+cZjhVadUsG+Z35/a0sung1SOCD73MlijbglKHMOd4WGLbQVEdRTrEkvoBUk/jtqiC7ts/09NY1ct+Tef87ehR2oQO13YLlaXHt9IeYk6pl/azah/WgFRoHpm2l8IhyFgMKKnk5DWmmo8+3MKkJFaooqi9YskvUhEsJ0tUNaBTrUzkl3FtM/mxKVrQqJfaC+I632v4xZ0t7PyXw3qnE28HxAmnYH9wsDhENAe7tNtzMKySDnARhP5X/EQnPcEBzTNnHxSn6okfxpgNAohbpIBCf3Tfea+/R2lskBn0Wl3mMhzxwD6ZPQa6i9Lzw5UE3nlGKcsKOtNUveG0y2WFcBTKL8d8Zd4k76YgGSThaPrEFFmuhKsElAKobQvsGPU5jXAGgUGPJxCLl8uef2NwDf6Y1mF7VkC+XV4KyRp1k9sJr4vfthEPJhxMIDmU+BMWpBelcpmQPinhA5qL6wHCgLV/K4CfmzT1BGzTHVnRZAo= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb006444-4b9d-4d38-dcde-08dc842b84d3 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.8352 (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: jSOQs9wUaFusGRR7iFccNYaq4l/j0xJMFEzCxJqwaQCjt7ujLxh/LEypsxT3ZzGh X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6296 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171618_109473_C521DBC9 X-CRM114-Status: GOOD ( 12.08 ) 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 S1DSS brings in quite a few new transition pairs that are interesting. Test to/from S1DSS_BYPASS <-> S1DSS_SSID0, and BYPASS <-> S1DSS_SSID0. Test a contrived non-hitless flow to make sure that the logic works. Tested-by: Nicolin Chen Signed-off-by: Michael Shavit Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 113 +++++++++++++++++- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index d7e022bb9df530..e0fce31eba54dd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -144,6 +144,14 @@ static void arm_smmu_v3_test_ste_expect_transition( KUNIT_EXPECT_MEMEQ(test, target->data, cur_copy.data, sizeof(cur_copy)); } +static void arm_smmu_v3_test_ste_expect_non_hitless_transition( + struct kunit *test, const struct arm_smmu_ste *cur, + const struct arm_smmu_ste *target, unsigned int num_syncs_expected) +{ + arm_smmu_v3_test_ste_expect_transition(test, cur, target, + num_syncs_expected, false); +} + static void arm_smmu_v3_test_ste_expect_hitless_transition( struct kunit *test, const struct arm_smmu_ste *cur, const struct arm_smmu_ste *target, unsigned int num_syncs_expected) @@ -155,6 +163,7 @@ static void arm_smmu_v3_test_ste_expect_hitless_transition( static const dma_addr_t fake_cdtab_dma_addr = 0xF0F0F0F0F0F0; static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, + unsigned int s1dss, const dma_addr_t dma_addr) { struct arm_smmu_master master = { @@ -164,7 +173,7 @@ static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste, .smmu = &smmu, }; - arm_smmu_make_cdtable_ste(ste, &master, true, STRTAB_STE_1_S1DSS_SSID0); + arm_smmu_make_cdtable_ste(ste, &master, true, s1dss); } static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test) @@ -194,7 +203,8 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_abort(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &abort_ste, NUM_EXPECTED_SYNCS(2)); } @@ -203,7 +213,8 @@ static void arm_smmu_v3_write_ste_test_abort_to_cdtable(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &abort_ste, &ste, NUM_EXPECTED_SYNCS(2)); } @@ -212,7 +223,8 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_bypass(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &bypass_ste, NUM_EXPECTED_SYNCS(3)); } @@ -221,11 +233,54 @@ static void arm_smmu_v3_write_ste_test_bypass_to_cdtable(struct kunit *test) { struct arm_smmu_ste ste; - arm_smmu_test_make_cdtable_ste(&ste, fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); arm_smmu_v3_test_ste_expect_hitless_transition(test, &bypass_ste, &ste, NUM_EXPECTED_SYNCS(3)); } +static void arm_smmu_v3_write_ste_test_cdtable_s1dss_change(struct kunit *test) +{ + struct arm_smmu_ste ste; + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + + /* + * Flipping s1dss on a CD table STE only involves changes to the second + * qword of an STE and can be done in a single write. + */ + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &ste, &s1dss_bypass, NUM_EXPECTED_SYNCS(1)); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &s1dss_bypass, &ste, NUM_EXPECTED_SYNCS(1)); +} + +static void +arm_smmu_v3_write_ste_test_s1dssbypass_to_stebypass(struct kunit *test) +{ + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &s1dss_bypass, &bypass_ste, NUM_EXPECTED_SYNCS(2)); +} + +static void +arm_smmu_v3_write_ste_test_stebypass_to_s1dssbypass(struct kunit *test) +{ + struct arm_smmu_ste s1dss_bypass; + + arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS, + fake_cdtab_dma_addr); + arm_smmu_v3_test_ste_expect_hitless_transition( + test, &bypass_ste, &s1dss_bypass, NUM_EXPECTED_SYNCS(2)); +} + static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, bool ats_enabled) { @@ -285,6 +340,48 @@ static void arm_smmu_v3_write_ste_test_bypass_to_s2(struct kunit *test) NUM_EXPECTED_SYNCS(2)); } +static void arm_smmu_v3_write_ste_test_s1_to_s2(struct kunit *test) +{ + struct arm_smmu_ste s1_ste; + struct arm_smmu_ste s2_ste; + + arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_s2_ste(&s2_ste, true); + arm_smmu_v3_test_ste_expect_hitless_transition(test, &s1_ste, &s2_ste, + NUM_EXPECTED_SYNCS(3)); +} + +static void arm_smmu_v3_write_ste_test_s2_to_s1(struct kunit *test) +{ + struct arm_smmu_ste s1_ste; + struct arm_smmu_ste s2_ste; + + arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_s2_ste(&s2_ste, true); + arm_smmu_v3_test_ste_expect_hitless_transition(test, &s2_ste, &s1_ste, + NUM_EXPECTED_SYNCS(3)); +} + +static void arm_smmu_v3_write_ste_test_non_hitless(struct kunit *test) +{ + struct arm_smmu_ste ste; + struct arm_smmu_ste ste_2; + + /* + * Although no flow resembles this in practice, one way to force an STE + * update to be non-hitless is to change its CD table pointer as well as + * s1 dss field in the same update. + */ + arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0, + fake_cdtab_dma_addr); + arm_smmu_test_make_cdtable_ste(&ste_2, STRTAB_STE_1_S1DSS_BYPASS, + 0x4B4B4b4B4B); + arm_smmu_v3_test_ste_expect_non_hitless_transition( + test, &ste, &ste_2, NUM_EXPECTED_SYNCS(3)); +} + static void arm_smmu_v3_test_cd_expect_transition( struct kunit *test, const struct arm_smmu_cd *cur, const struct arm_smmu_cd *target, unsigned int num_syncs_expected, @@ -438,10 +535,16 @@ static struct kunit_case arm_smmu_v3_test_cases[] = { KUNIT_CASE(arm_smmu_v3_write_ste_test_abort_to_cdtable), KUNIT_CASE(arm_smmu_v3_write_ste_test_cdtable_to_bypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_bypass_to_cdtable), + KUNIT_CASE(arm_smmu_v3_write_ste_test_cdtable_s1dss_change), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s1dssbypass_to_stebypass), + KUNIT_CASE(arm_smmu_v3_write_ste_test_stebypass_to_s1dssbypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_abort), KUNIT_CASE(arm_smmu_v3_write_ste_test_abort_to_s2), KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_bypass), KUNIT_CASE(arm_smmu_v3_write_ste_test_bypass_to_s2), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s1_to_s2), + KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_s1), + KUNIT_CASE(arm_smmu_v3_write_ste_test_non_hitless), KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_clear), KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_change_asid), KUNIT_CASE(arm_smmu_v3_write_cd_test_sva_clear), From patchwork Tue Jun 4 00:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684504 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 2A475C25B75 for ; Tue, 4 Jun 2024 00:16:42 +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=Zp8oxbtZBBpoP7SodvLwJ6UTtoskTUXv7u2m5IeDaLY=; b=og5zAPpyYE1/FN mejV5rag1VbFIXNblR09RWAMXl5PNuz2CFF3/qorvphUtRNCQwssRiuYZMYxKwFvsGWScTNfi4JO0 X81HcsoN+yWptho1ULjgHQCgfrikDliBCg8S6nw4JbS6DltOD4zqjZ9tIqjKIegMKmCf8RDPqLCb1 HhB+ZxtAGRbahIs12K12oK+mu2m8nbqENypF0PdiqKfpvoY8tlhhnuCwwVEjx0ngULwQzUQ4xUPqW Y/F6DwP1v24vLJDF8mguNjPjVasmlGX7WC48Z0Q2vLCsrtoclUIMAWzxuyy7+k0TbGXeCWQ+mOsUN 6XES4YTsKbEBDJ9OkZmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqo-00000000hog-3q84; Tue, 04 Jun 2024 00:16:30 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqa-00000000hYh-1AD2 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UcE86rvtS2vbpjdEk3PwQwhoCINqcsySXdBVc7uCCMyChPbkXaIC8j9EhiODs3oJ9MmA1XNuDVX2iiojEr2lkl/+rtj+NDWkrAt51p1b3tHqW5woUlMACWZQM4o+O0W0kQE80VgTwBrfgvjkgkGQHQlxEgtZjej44KvCFEKhtZibQNT9iPuWpCbfb27/9HcTms1AeSdNQ6zogaPJPdd/BgWUsG691YVDDQ/Kb4caCShf6i2HpY4xck87TEcBcYJ3UFGXGHCJwugk5nSxW0deGXGGoYelNs79MGQSwnpHD8xBCewn90wEnbHXwCqJSsCXvkav+zdXAAzkjBnIbOJuww== 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=H7RA9pcPidzQQWuFFcNv9fvfaIwjby+gEoYGK6Dfg9M=; b=G5ARW14+H+VmWpCplvcnZqVMc4YayeHUBc8yCZRevPndWwnmXz4Kgtxmpqt8TMTLFgv/gQZ6zwsnniZ1a4A2kMIdh4zU3+S76XX7bY51mZRDLk/uoh7BtdnWuHdsDaAKqP3OvA4TrVTIOviwKRIhK+NsJtey+/GA+y/vxp5qQ8IjPX3VdAWaHey+PgYf8o8yG93pU2pxCVq2CXmjeepPjdlU6/4KLxQUk2wo1GUFL4KZfHzuS2EO/gxDjUseOwv5OjjSDQac5KSa1s2Updr9AvTdQTDaZVTsEnTzqihvSrI2bhjeeINgUneqkhMmg3q7Ugf/BkQNAv3fI8uNseTGXQ== 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=H7RA9pcPidzQQWuFFcNv9fvfaIwjby+gEoYGK6Dfg9M=; b=X4HX8iN8v9gLajka7E1fvEshxMPgNRn1Vp4rMzco4Hb4SzE3J7o37NYM9U6HpUJivtu3F4yj7mIo8LG4CQV3mp39VLhzB6WWS2yQdMU2PAlBhydQoZWocYIaxXKULDrAB2RkSIWKgi9G0bULNfCbAttaUDyTIGWiQ/W61x8CcEcTS8hxy3dYJ2cZBJsZ2nidyVTGHtQsTAb2OKC68kLbbr/Bi4R6dSazwzPD8GMBSf2kCgk89qTLygSt2lIIyKS3VlF3mYRvgDj33Hvl8/LAno+qoPOosMa6pPl/qjFcsaQc6gIjP8HecsoMupvIhrVD32Z7c3emhevVtCp37J3ONQ== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:07 +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:07 +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 13/14] iommu/arm-smmu-v3: Allow a PASID to be set when RID is IDENTITY/BLOCKED Date: Mon, 3 Jun 2024 21:15:58 -0300 Message-ID: <13-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: BL1PR13CA0441.namprd13.prod.outlook.com (2603:10b6:208:2c3::26) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: bf738b78-abd2-4810-1a9d-08dc842b85b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: V7yAFgD3H/8ORCshwo3zxLmUiMUvbs8HS/Ci3dcUNzRkh3785+hPgdEIJ40erS6zN/K53StnFX/6yYCd7wAV9a067adn3DKIVcpzqjZFyvBA8gqmZ2Vj2wQ26DxURs7Z71ajraGmv5fIPM+u0rlVZFUdPwAP40RoozU9RhjzjfeYxYtRX0gzXfciqTOvBzwCbtUIdcU+oV1OWu612o2Z/U6Hmquck1+J4lI4m3JCrLEklQYlUzANJ6fmiMORKQn1jDbGuGIxcJikrENqkelJ7Bw12nNY3m5xcjDJ0X6EQBOSxEfHKpDSbOb4uITR3+Ng19pjWbGoR92mIoDLnM630wq7wDl7jlyscAvaBol+TMvPiMRr8rY9snJ6QFR7+sAt3lMlvc4z5efatK1Exaqa3mlg3uv6NED8jJ3/0mUJCwt7PcX3pW2Q5hUxJJGgpWFBAtCT9qdr2vssylyudK8Mnq4xqNpocM1ZoChoSXd1Pfy3MiZNZFJdee5PAnbIytHhKh90ySEeqtNuAAFRIzj7oLjdATTumvJ4jXNjg9zaH0cfACDF1bfmIt6HqgNAjSFCrzvokcA2+ZfiYHVDGGozM5PCsr0f1fG854IiEEw4FrKdTWgssspe1mdUhGxVbwqvxyiuovJ9HZHCpmwmN9PyzWkphbaxksMeyNCKXzJd9azxZvwVcD0/jfjHm3FV6scBGix6CdPG2niVYL582civLUR4th4zJ50eOIu172BJtIxLFoUhZDtwIruzLSuJvZHSbNIeO1Tk0p+AxHPC3l8vxfPOqErhunMP9c6/jZwlaNopee2Fd8OUEkrHvZxuJWV9fkPOp+OCvEeWtMzN/vnegW9IN8r9zyk2MN5Va2wW4aan2AR1WlyK1elU0QS90BOONqWn2qXQtk1HMIVz5Sw/3JO02k9asOr4mJrkKNdjXN7psAT9RumHwjc9da0w5GAfI4EgW60kXfirVUKO9BtCKemxdJ3Q5xXsl3vpGhs/q6CRg/vHVbzGWBN5uqCD+VIWmoQikNsKTiPdSeuFpcfxCrFNJZWGcms+ZFsFJ5x/ZSVt+4o2BJ2ubrLhrjj+mFRFGIpdUDF3lt8ArvJGWWmFRL+pigvHtk2YXSCZpaVYsV//ULjA6FlSLKzHwxQG/ji7MuH7d+tS99GnWzD8yIjYxYume3OEfr4F3kmvV/RXwdEPIUJ7iGRgJVHGShlBox/MRMuTF7/TpmFhPo3LF5ayvxIlDW7lxNmHmSNnebjjY7OM778gXJ80nQ8IXvtUP1iD8vQQoEmX4zP8oXnqNcsu9w== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Nb2PR3ciPiAoNmYfK6miQMnbkWkAlzcUfSAtM6nn745sNtJiZwwx5eUbXCR4ZAnPS38sNQleOtSeBNUnRC41kpXK3Av3HwU8YVCtiTJdwi6pChxtFNy6xLP4WcjTfFQCbd1oQYfjYn3tVnS7Sc8uYzL7me1ALDNCTsqVRDpTAUj2lkeEmBeFqQJYDMogDpYJqz1vNVDJzvySuX8wqOZthP6c5w63i5H4MZm+vPWyVHzoFSps9TK4ZjAdayj06mXqeQHq1AkQcrISGhRnxXNaDuXyd7uew+UJ1dNMBC/5YFVLMTBxuoRFEi5WOtmnA0rCE+5LcmLgHvazJGgej2mnw3ijjHaz7ayo2TH1BJxh73qm3xsB9xevCHumiAoqtxhFcbxqOsfVS60HZC6K4RUGGXJD1ufvVYKjloLKfjkoTbUwqBpFoCQDxp7/+vC9q+azD6t7jqwy9OGJXOGIasYuCbL5cHGZxJgXmx/pBWW8hn/D6bso5ALCzTq11dv/FepUvDS2oe4iBSvhYsOX2Vii6NmomseO/PbPvaEJR9N2mhiZZteKwpX3DcQ+s6hbaSC8PAzLLZ6h1fGMbVQpFgLLcw+6MxBzJLlA7j/Mh5W0O7ZRajzZKHF0QJGneLEFy3VQ3kDjDsKpsnSp675kYR0xUA4DJyCf5OIJpG86m/f4KOb2S+6qjf7plNmdW14VMRzze5iW/br8NDd/waJ3oXfx8hJUrvrddt7g1Ni++CQGnvRbZSP+EMFJhJD4Tqxy0GYl82cb17aSiZ2RKjtSJOxUfkEqfMchcrxCPHGNzYKGNZuOYPLcNerBqXHD10/WVHSuAtTqHUTo0ujQ3l6sI9cMWG3QnMkRNbimxnVb14us/5PJx2HKlkd2KJQ2bah9sML3pBsd0PzoYkXBG81jKk/jN6V5PSGu7/q9g+gyR109yhB0HIjEMCyAMY89dYRkspRj0DzIFIilmqeIk3R6XgsS/gzVCwCiJjnCOW6EMZMl2OU/w3Bhu+I8SB5RKleI6L+lAA1JkuPgpPD0m1N97fVb8GlyJJMZ5JRqaCRWFdwd5MRdHwxzqzDz/kFpY/AGHJpk+Km5sCnxajoA5hBmCm/6C7dccjV6r5M2caP+MDSPClcwbH30HWIlnQhdWEf6PZudObnp2AO9LPuSdTVbKK6ebpe5QMgIc4rCrkOdl4wzxyfYuL2xnQSruvSXssokY199pp9UqELmB6l5D3/5AeRssf0k17c9egQbaE5Zp4T8jr5U1/GCaEoINxkpDqGpB0vjLfhZyvLlqoUvVgmgXvAIUX/dUJSCKRo/pFLvfiOUgIVbnOirlfJ+niBeXTpUPJWuciUFHTJDktqJjoxq2ipQ4iJxSP3d/jijPMk4D5obAfJfPjWH6npuFSKmpWnXs0FS7P26FitmT+bnd2rIF7pFcl6LmWBxmAZ7Q72tfn0gce19nhZjVRj8y9QxGXkDoAoZVyZ0qbaSxzjLwX5Ql12Z5OwsfoiPv8+gS3+E/bFDXzHZ3ALwNW9y9rqoWhJhS2aDjtR8ZNLNsU+WhNcRZtNs3XH7jBo3w1yK7LD2C3DwYdU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf738b78-abd2-4810-1a9d-08dc842b85b7 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:04.2481 (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: 0OJ/xmpQNZr8mLe0f2LiqwdegTV+7CzI9oHpMzH5XI4ghH+1dhzElaiaX10wgCRh X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171616_458938_21D33552 X-CRM114-Status: GOOD ( 21.72 ) 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 If the STE doesn't point to the CD table we can upgrade it by reprogramming the STE with the appropriate S1DSS. We may also need to turn on ATS at the same time. Keep track if the installed STE is pointing at the cd_table and the ATS state to trigger this path. 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 | 49 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +- 2 files changed, 49 insertions(+), 3 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 1b43fc1fe85387..f54be4f32d30d1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2435,6 +2435,9 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, master->cd_table.in_ste = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == STRTAB_STE_0_CFG_S1_TRANS; + master->ste_ats_enabled = + FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(target->data[1])) == + STRTAB_STE_1_EATS_TRANS; for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; @@ -2796,10 +2799,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +static void arm_smmu_update_ste(struct arm_smmu_master *master, + struct iommu_domain *sid_domain, + bool ats_enabled) +{ + unsigned int s1dss = STRTAB_STE_1_S1DSS_TERMINATE; + struct arm_smmu_ste ste; + + if (master->cd_table.in_ste && master->ste_ats_enabled == ats_enabled) + return; + + if (sid_domain->type == IOMMU_DOMAIN_IDENTITY) + s1dss = STRTAB_STE_1_S1DSS_BYPASS; + else + WARN_ON(sid_domain->type != IOMMU_DOMAIN_BLOCKED); + + /* + * Change the STE into a cdtable one with SID IDENTITY/BLOCKED behavior + * using s1dss if necessary. If the cd_table is already installed then + * the S1DSS is correct and this will just update the EATS. Otherwise it + * installs the entire thing. This will be hitless. + */ + arm_smmu_make_cdtable_ste(&ste, master, ats_enabled, s1dss); + arm_smmu_install_ste_for_dev(master, &ste); +} + 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 iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev); struct arm_smmu_attach_state state = { .master = master, /* @@ -2816,8 +2845,10 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, if (smmu_domain->smmu != master->smmu) return -EINVAL; - if (!master->cd_table.in_ste) - return -ENODEV; + if (!master->cd_table.in_ste && + sid_domain->type != IOMMU_DOMAIN_IDENTITY && + sid_domain->type != IOMMU_DOMAIN_BLOCKED) + return -EINVAL; cdptr = arm_smmu_alloc_cd_ptr(master, pasid); if (!cdptr) @@ -2829,6 +2860,7 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, goto out_unlock; arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + arm_smmu_update_ste(master, sid_domain, state.ats_enabled); arm_smmu_attach_commit(&state); @@ -2851,6 +2883,19 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid, arm_smmu_atc_inv_master(master, pasid); arm_smmu_remove_master_domain(master, &smmu_domain->domain, pasid); mutex_unlock(&arm_smmu_asid_lock); + + /* + * When the last user of the CD table goes away downgrade the STE back + * to a non-cd_table one. + */ + if (!arm_smmu_ssids_in_use(&master->cd_table)) { + struct iommu_domain *sid_domain = + iommu_get_domain_for_dev(master->dev); + + if (sid_domain->type == IOMMU_DOMAIN_IDENTITY || + sid_domain->type == IOMMU_DOMAIN_BLOCKED) + sid_domain->ops->attach_dev(sid_domain, dev); + } } static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 30459a800c7b2d..cdd426efb384d2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -705,7 +705,8 @@ struct arm_smmu_master { /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; - bool ats_enabled; + bool ats_enabled : 1; + bool ste_ats_enabled : 1; bool stall_enabled; bool sva_enabled; bool iopf_enabled; From patchwork Tue Jun 4 00:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684532 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 2C4FFC25B78 for ; Tue, 4 Jun 2024 01:31:29 +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=Ej9Kt1Q9bpaRxrDPolrdDob10jndi6v/pTcEVnvjp9M=; b=XK/D6Rgv8ppolW gNHfRv7wYOoQNKBCLfFCyOfhn2nCcZEEjMvZsj8ttE7TSSme3aBCh/1lBfhojIWxHhOGF9tW0/uXQ ndG1r95tXe6UTtuaSYiAQt3wV5zlKtbB3MCjTvPBqrB+lOyf5CIZ/09KKv61YqpPtAtv8M2h6BBcJ xH/6jNiBpfTbyQiqrAmt+nK97PcnpyjoTawJCTg6RWW9axSJziI898QKc0VjRbwcSGQFvikJZ1u/e NaCWw2I87MYoMnEjgGocQywKGeDzlFVr/o5CTuh9L9PmhskCfMf4VUDVg1Ttm76I4L5z8pM9xQpAl lkwOf5Wfc9qGAPrt9CRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEJ1E-00000000oxA-1U92; Tue, 04 Jun 2024 01:31:20 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEHqg-00000000hYh-2iWZ for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 00:16:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EBr+K43Y867LNt5yB4LmlKTRZydW+eKtvO+pc0kb3MtNUznJG+D0/vGR8xs38p40XD+C/AqRTroq75uapZ/P80zIN+DLyC2X4T8+07is+TcV4RPMqWgL1JKvuhh/pYFqQLoBjSER+1nexPgSkxpcgyJmVcUoUTKJDoZP8iCrUXzIhztEUC8RoW6k0CK9ZPNRHK2foMSQwGSphSRb7NesBnQtS71t/shmHXHISPQkIZtRezfZ847kbykOq84+TR+xZ6KEE4fE8ZQhfDw6TD3U5lZAPwlyxdbxdf0Hxp4EMmsvIIw6b+4CfWvsH97k7SluPHK0a0fuDnxX3OGFOxvzag== 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=6zdESbDRq244oFLCJ0opKNkjFSD2iqt5hoN4csFU1Vc=; b=Yvc7OihggYuLNk6PoNklX4ZlmbNaSNdLHY0CGW1nIAf7eswBt3hH6KRvRN8JCQsyLFtq37fKEWYcuxJ1Zls3HxMlc4T5OmPZroWa9PqEOiucCmuIeZsMF02gv3AEOFh0EXrJZSVBd0sj6Q/7DfhYphrbjfINVzjYOpolkWfs8gP6mvgRJiosHb8uTCoORHHqrSoIQ2iGe2geB8bg/jPTGKDkn4/I+gaTSEtkVNVES4L6WjWXcOfvXd/UzGRrypgvTgQdkOOrhuUMBDzjfj48VvOPQYheEISUfLO/gXNRMsUKCXDSjx0wVk80FLMM3pbk8diK1hVx6T9N8KmLsS5Lyw== 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=6zdESbDRq244oFLCJ0opKNkjFSD2iqt5hoN4csFU1Vc=; b=EjAGixP7sMVwlBmjjLTNGW9LstPTccdTXfhfH2t3ZiB2/8zdSFyACE6E52z3y6D3dAA3VYGCWqJEwBXeiMY14FJbNSKOZHgB7b4Ieai48ufb7mjBVzoBn71/wf0u2DdO9ZvXu0FjT7dPyIlKmPCgwukmrStDq/y+Soo2NFGH26nAHgr2+k8nqhiiFomQkytu4M51yCCIus9cdIcvUQHxR0RFhm1b3d8qTIbswANn5+wX7CDhMioPo2RynYnk/2s+gaK/FgnMGbbU7h8ouSRx3vZABrJQJ5mmw7lbBL5ABUePHJ9lHG+shltQy3sEYTZzXCHE9uYu6kiK+17DPSOZDQ== 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 BL3PR12MB6451.namprd12.prod.outlook.com (2603:10b6:208:3ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.24; Tue, 4 Jun 2024 00:16:08 +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:08 +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 14/14] iommu/arm-smmu-v3: Allow setting a S1 domain to a PASID Date: Mon, 3 Jun 2024 21:15:59 -0300 Message-ID: <14-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: BL1P222CA0006.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::11) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6451:EE_ X-MS-Office365-Filtering-Correlation-Id: 65cf1043-1b55-4e70-1484-08dc842b85d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: IyAyiyFH/1/4ayIoEs1Ph8hB7vfdRyq8JhhqPT6xUfGUpAmmlYu1m/iKLxFF3SsnU9YBEYcP44BevTkUmStmnKsccg6Ld4fRryzoxfCw868sorwt25ajLSKV/qBuNwjpXmpDUo3/dg8ErQlKpSKMaOrSZ8mDu+xnRUBg48imD/YbtdyfAVb5n15BylmheJFnGVul+6WPTnkvuOFCjGHsUtStORi857DNxDgJQE5TsMtJRFjLv6kC0XEo+znpNFbw6Lv3yNre6UwDiMWYo4ZxMUMhk6A9l271qye7CzNQWJFe3mSZ2rmHEIRssrHoU/j5WFIzn4H5Kyg4eJ6MrOvoLqP1pfBXab+URX2L9aAF0j9KcQcI1f+ywIBq3tKrI2A05RYAdIWfPCuHskpAFcF7y39XK+P3AbcNDPsKepAUeYpNXTQPW6PejrI3Oen6jGjiaAb1JVWD56zPHEmWomyA1STQcrpoyNFr6/3v7qjBQxVWYGzTKPtO0YxfElmtrf52lH+/suD5csohXls0ibZHVLGaiV9XHWaKCLUnG6c2sAvkIhKRXnfjBY7LWqlq42jWcGkKSURDUkuD7IdXRbTocQjltYDxFogr6ezpERk8agFuxPio1lk0DzA6cthSfePkufr5E9Z6Eg/g8YF2c9rgrsNOaghfUR7cQ0BUPSrX4a9Q/HJHsRGJZEtT/8SchJ87htGuBFAAZ80AnHP9KZiaS29pwbSqBP8076FGI7EDcKdyTJWqHu1cqztcOockf54yIKAt0dcyEweX2PH7Q+UTCQGnz/BKz9TJ19t1vAAZ5EKFuvP6+yVRcuiVmE5iRaP53kpNNr/nR5LThBFm9bHf9n65kaNZk3wAKk0sLSj8FsnhJksEqmuv1baWxpT6Bd43JNnGRjwHjmooZh72/9Ny4dM9rPRKXjf19/qD7Ud5fe5xjYn+TMPrax4TOpwpd6W0T2lk/b4cnzHeLX+SiZ+bjWbUl0aUWYxgHJC0Br2WnoEcJ/aJaHLSXTN4zEh7P6Tu2gO2etTJGQny4EmSLbfBLKJ0/DwjCRYBaGfFyUqxEvUttxAsL9ugfSch/4qKd61yB+XzsDyBNGNwbASbGZFx32GSbpZRBhqWIQNyRmX0GRoeXF9C3lRupavdCQfwNBkKPxUbinmuRkH+t1NFjSxzhTVb3issjLdq4RPqbKQodU/Z60gz3oDt6GrlFshI3n42XBNwJmXSRmCL+jwh6PjjOOXEC+a0+MukWZwcdVy3Hz8LR5PDYn8RPOTPWCrFgRUYlifrPhaFV8odoLvpCu11EQ== 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)(7416005)(1800799015)(366007)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ChpaPRYhgh6/acmbM5btPNMB8fbtAzvuiJj7xcIkXDecbyvTppKJiobD1jQsT8sHJJof782wCipVBXke48ZzKsKg3TPEF5sR971aLcWxr8uwhpLD0kblOP75WQp3DKW7NRbBbU0VdeKMikG1orHsZ6w5RsZLtBFUQKWD7fUclRLeQ14bC4JbAL0APRARL9Vxay3HuiYvXEh8IZQmSMiReO/gwDmECgaO5NEfu25v7qELx9pUn6jJhNMUfvUNNUJGgTeLRvF0seY/7gjcHoJerTpW4Sg0ioAhfI9kKZo440QIzSzv5AEOT1HC8f15rXpf93qjYl3iUvl+OSlQ8wgvmmUvLpWS2vR7+N8+UmNtAlXfgQ1E1YHSC6Tv0drbRPyELhqpi8eP+SnAKeClR5v6O2QmfTwgxWZQCHFSyvE5xdIklz8kqFrg3eNcHHEOjYc6eXJxbRegQkzXubSVEcZlQvS+hy1Nox6VrEpVvgvcy+Xmvj7LDd0nDHoxDyV9O8qi7fKidMNsvy55Eq84ebRaIUAxBaGzsWWi/G5gbvWz+bEy31fSw0/gqGTCnvdy935LgALbhTiCTPuZMeAWOZw9ClE4f21TCGqtONoSfjZ2ElbiQ1liYCUqu0WGAbju+Yt6e7kGMIMcbFA/vQzqH9q3rwKFaSQSNT97C6DgI60zap9pIMXwBp1lxWGWhuqM6LbD91WF3pmzsyDeuE1YgbS5ZSQ24vfVo9OpLrCrlDU1IEYv8tklv6YQzCwSRxZyCAjjUuFdf1s5kGSQcCbfYTKffxiY9e1/NPcIb3PAjyds3BD0rn/xbM3tLJS56DLnK35blqll4c0+s8fRPJ0HURRHLWS1sqKlbtqbY+tVf1m/2nuLaYtwDcFCfUK1HHCEhOomYS73+QNhsHQ+oUy47zGyfP58y3CkAsnJbF9Jv/uH4xXTm75xvYR2xvWjxCmWMYYmoM7S5S5+rF7vt0OxBM1SC09vQp81kDsEBnt904g5b99ryd4WWIg8yn2L2N8k4SHNuoFRPkgXCGJ/8DP44LNfEETwBmxqF3SI3zpzr02/L4bUlM3w2iZQp5QY5qHN5dXlkdnnaaTQ+qHlyU5BVKBzThksr2QR4pCpvCeddNEjt6ZGZKZfZ3ofvtpP2LgQUTe/jnC4cIqxbxAmzi4HmdT083wlTWDxu+Ib/aKBBSPznys68q5IVLBTc3Q269K90MIG2nj/HRuvz7RukdD78cAzvkU/wsz8QxRilOwa5JrAqBZALoevTG6R/QVON9VSH8qgLKeGdyBlvcXM8T2oJqOapvmkkv9APJk1NOD28VbbEKuCAO25QCMW4agKqdlgODVferMuD0Fmzdh/2Og8XcLeZz3/J1toeTFnMafq084QhibtspakF/qlJ6a9R+QCWZeaaZ4BTYD2bp3lfm3OwVNFDmKRxP3OeEvrMDXlfvCaZCNGyS7p+Mvd3vdufNIsG/z/TFh2cCvEj30xc//ZRnwAbYxX45+8YS8t4ovGnJG2BpNE/9VOhxxK+71Ol+7VZz1RCpPS2vkU8uAyqUmmKTw8pm1BzQD+x35fKYtWWjG2Xl8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65cf1043-1b55-4e70-1484-08dc842b85d1 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:04.4170 (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: f5xDde6I7KhbIgQDc3lN9AfD+0XiHY0eVmL7njye7SIe47USgPCxKvxoIBfA6hw8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6451 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_171622_948849_806937CD X-CRM114-Status: GOOD ( 17.53 ) 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 The SVA cleanup made the SSID logic entirely general so all we need to do is call it with the correct cd table entry for a S1 domain. This is slightly tricky because of the ASID and how the locking works, the simple fix is to just update the ASID once we get the right locks. 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 | 41 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +- 2 files changed, 41 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 f54be4f32d30d1..85d0b4fd7943c5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2799,6 +2799,36 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +static int arm_smmu_s1_set_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t id) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_cd target_cd; + int ret = 0; + + mutex_lock(&smmu_domain->init_mutex); + if (!smmu_domain->smmu) + ret = arm_smmu_domain_finalise(smmu_domain, smmu); + else if (smmu_domain->smmu != smmu) + ret = -EINVAL; + mutex_unlock(&smmu_domain->init_mutex); + if (ret) + return ret; + + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) + return -EINVAL; + + /* + * We can read cd.asid outside the lock because arm_smmu_set_pasid() + * will fix it + */ + arm_smmu_make_s1_cd(&target_cd, master, smmu_domain); + return arm_smmu_set_pasid(master, to_smmu_domain(domain), id, + &target_cd); +} + static void arm_smmu_update_ste(struct arm_smmu_master *master, struct iommu_domain *sid_domain, bool ats_enabled) @@ -2826,7 +2856,7 @@ static void arm_smmu_update_ste(struct arm_smmu_master *master, 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_cd *cd) { struct iommu_domain *sid_domain = iommu_get_domain_for_dev(master->dev); struct arm_smmu_attach_state state = { @@ -2859,6 +2889,14 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master, if (ret) goto out_unlock; + /* + * We don't want to obtain to the asid_lock too early, so fix up the + * caller set ASID under the lock in case it changed. + */ + cd->data[0] &= ~cpu_to_le64(CTXDESC_CD_0_ASID); + cd->data[0] |= cpu_to_le64( + FIELD_PREP(CTXDESC_CD_0_ASID, smmu_domain->cd.asid)); + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); arm_smmu_update_ste(master, sid_domain, state.ats_enabled); @@ -3377,6 +3415,7 @@ static struct iommu_ops arm_smmu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = arm_smmu_attach_dev, + .set_dev_pasid = arm_smmu_s1_set_dev_pasid, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, .flush_iotlb_all = arm_smmu_flush_iotlb_all, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index cdd426efb384d2..91ec2d49ecbf2e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -801,7 +801,7 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, 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_cd *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid,