From patchwork Mon Feb 26 17:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572676 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 7B8EBC48BF6 for ; Mon, 26 Feb 2024 18:16:40 +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=kyyXJ7t9vmR2olpJbjV+e552zbu0sNG9qf3de/JiHDA=; b=gKTy4YnnTFNKx2 M8kj4246mB6doj21sBp5UIsEoJUMr+PqdVbJAaBrLVRMUPtEpuGKcKUm8+hY4wVn9b0/UP5Uto7t2 MxjE9KSfOFfrizoiRi6ZI7Hni56ZU107Y84Sr/qsUrzcb1YSa1OZyZnsuv4bhxLfSWFPLsMMKo9KP h4laupjWyz09LbdQKHag4NcDZ+GgTqFwU2CC3Vax/PdfZj9IjvAQigEfB3KrMt6SFezEluYnA2SNl 3Mx9r0yUJXLHifbxANZ3HLxQZxeLkfBvGKvtulVFhV2fS/I+5Kz9xN8wcG3zQrJZA2m2Zzt0Ezdld ikPVpyCP4eTbmsR0o1RQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1refWg-000000029DU-2O2Z; Mon, 26 Feb 2024 18:16:30 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSF-00000001pjD-01bC for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jfvEWh19vBVL3jloXjXPsRd9IA4+hyLuLJEyKNQGKbRGeHA0DU9mdYmhZOJIbs9eUOYKP0hjrRNscZAhsPXXEoKDYveVFTD4SDigse1Hz87AMkldWHgpLGgaa+sEhfYBVfT7bLVOkoNbgOADHF1cWIu4boUreQ1BAEspKAJqjjteB7m3zCCwgavo9xLwmVE93G4lo/fNqzi08u3YKsSXiRiwlufZgq0nKl8sD2F0o3PEi0Y6mX+GsH8NdDYcRhgXUvMXg9KwmhSSkUqkPWEyw6wB1CinvNZq6SrEC6fek2Jf+0pbkdYIAlMpA4wCGxnITm/8+Q0jFM2oDqoZcjbD0A== 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=/GzaHdu8XubOBxsSutXbFquuYh3EtV6Ivkf67pBgTM0=; b=b1RxZJ4fcvDgAfhkBFlZ3Hj7XkrNO399XW/+Njqk4d4Q4Qt8upmQ490nPEvu6hDk85PsXzOvYcLqgZFQN7SJoRQ5aRPYUsXEDECHYQ3BzQADACgPaME1NW8fEI+gtA7vJMSMmPwndNm6XQA4Lfub/Q2xPkGNd8sy1gbmZU5kIiOIl7SLBTpLE/hcF9/xSZ0dFxi8vU/ccgsP9zELL1Hsfbs23QVFw6vy/J2HanxcfKTHsf1jtmVw4n8Ozs1HtaoRhqmCX955ibnbR0EJpaHoB+oSwsFnmA7UDmFfSQOLC8JeSl5AklMLAobcbw59dIMeGYocK6Mzjv2ZpMGm64L2zw== 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=/GzaHdu8XubOBxsSutXbFquuYh3EtV6Ivkf67pBgTM0=; b=dABJ8X9tODDQGnB3cXE7XftfkY/qyc9+LPCcZSd5Qs9NBlN6+I8p0UfgGsf1hGWWb9ADKHvC6KodeBxOEz7ktRQsuJc9/9oS/fwdzvOJSjXRb0AUI2TEEGv6yMBLY5ozgH14fyOT262g1HG+J6FA/vbjinh3gdhPMaEMUmIKCj63nbRMZ883R7jBzPixcYg1LoOcM0fafP8OGA0Oz1AAmqQ5XojOE6ElnRRHQNj44FOV4NCbOQqa+6//NKyn8LJAnn3djLFdZkiaqDeeMoEwldZY80p5bw+do1JK1U3AYoJjO6wD3RY/uibn3hqvZiFXeMOUCjvLJ21WhykTpS5K6w== 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 PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:33 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 10/16] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Mon, 26 Feb 2024 13:07:21 -0400 Message-ID: <10-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0046.namprd16.prod.outlook.com (2603:10b6:208:234::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_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: c3b9e8f6-3439-4da8-2d33-08dc36ed6a65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n4k/O9Nd56UY/e5rAFsQD8EZZLZAA7ElINDD+Pbg8TLVhtWeMcA238h7BwnbHgdWQKhgadryzQff0Y2941F9mYBYB4v+x6ycQl63DLlv+k2qloaTBAMDvAOrtOzBVJUYSc9jjqpmTd1tANRHUlY0pNReJo9s6Hx77vTVoj3n7VMN9XA2x8bLgwWqo/rA8h1u9lbU9EDrB+oNrOsK3V4veDARQbhwFRx2fw19KrWKx/O/qyYZJezGGq6a/Qqh8wCk0Kv2OpoU93JNFl4WaqnIAVR+e0R7zZhXPa5BMqB3pTMc1iDMFfQ/kDH5T5UPJrlhZvwp6RzqKFbiSM5hNR/QAVm/pBRmrWtL3WIMN6r/PP3KRuHXSqZkkjtvzV1AWbxmQYfwKvDKQcvB2WTAFfkFy6qt8DZ0tOxRWHWVj/pDVx6qdsoOxQS7x22jk6yb8pyZOSajFbHl+b0NthF6tJkSWfePgMqgrrdtzDGrg2djJ8fgcxcLGqlvi0Hva2EgdqMhnapShi93OYZ5Ebk5/WFFqrMlXQDm4ueAb04KZgOplaRKsjlSBmIut2mM1TLkbaHgcB2/jCPTInN5RxdmSBjWIrmUCBET+AXhwhk3OsKT2aXv7J4eUZehzG51Fi5l9z1ZBWOgxluo6WXGs6OKK7ojAQ== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hGPqqvkZlkw9Y2IsPSQ3IKmv61ae5kSjCQ57IcPjxyiK6i5NWsaWViJmuJbn7NlL3oz+YxiDppV1uOU56q7fxi0yYHxFwZo99doEI54wI1JjZ8b1M1tecY1NRXMVh1+/2Y/iffc+YCsDN1lye5QyygI4jSQ+6NqLK/4rpKef55B+AbkylxWCBbJLqDi01qtCag/VC2K7tj7LcHIJgavpuNFovImhD5VPYj7HZZV0IKqQyOXuDuus7ylXpPDlle0H9TxPFMuAyX6IgvDn9f6KuFcpn4wymyZdDw7NsU51W51cLOfaaySfRKvoMNbijUOsid/UOVoBCktPmVic6w6IcfBF7a17X2uGe5JVsmYpM1K9IV+Ge71nkaMe/hWmAtmMsREJkYeKaEohrPGmoJASrV7Kru8vC0halfUF5H9Ehxcj3f4xCmHenCVn+a2chjeovcCgaa1HI7ie85G1HZomPAXCKAg5+p5k+BIjUIOEowi8shTLsUNFxFl66uP3zn95CeZE1yGMS5f+S6NpZggacHHgtNYrB8IqSk2cJm7HTvtARzL1Lz57dUmb4WlD0NUsAVRn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-4da8-2d33-08dc36ed6a65 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.1416 (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: 16r/jHl3EqcUEj2BGOwRlxnAyewgWp4eKD9LV4uaYLftEnnwtAifk/u/VB8WwPNM X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090751_340185_E98385D2 X-CRM114-Status: GOOD ( 15.97 ) 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 Introducing global statics which are of type struct iommu_domain, not struct arm_smmu_domain makes it difficult to retain arm_smmu_master->domain, as it can no longer point to an IDENTITY or BLOCKED domain. The only place that uses the value is arm_smmu_detach_dev(). Change things to work like other drivers and call iommu_get_domain_for_dev() to obtain the current domain. The master->domain is subtly protecting the master->domain_head against being unused as only PAGING domains will set master->domain and only paging domains use the master->domain_head. To make it simple keep the master->domain_head initialized so that the list_del() logic just does nothing for attached non-PAGING domains. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 ++++++++------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 10 insertions(+), 17 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 9d36ddecf2ad64..19a7f0468149cf 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2507,19 +2507,20 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) 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_domain *smmu_domain; unsigned long flags; - struct arm_smmu_domain *smmu_domain = master->domain; - if (!smmu_domain) + if (!domain) return; + smmu_domain = to_smmu_domain(domain); arm_smmu_disable_ats(master, smmu_domain); spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del(&master->domain_head); + list_del_init(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - master->domain = NULL; master->ats_enabled = false; } @@ -2573,8 +2574,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_detach_dev(master); - master->domain = smmu_domain; - /* * The SMMU does not support enabling ATS with bypass. When the STE is * in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests and @@ -2593,10 +2592,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) case ARM_SMMU_DOMAIN_S1: if (!master->cd_table.cdtab) { ret = arm_smmu_alloc_cd_tables(master); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } } else { /* * arm_smmu_write_ctx_desc() relies on the entry being @@ -2604,17 +2601,13 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) */ ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } } ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } arm_smmu_make_cdtable_ste(&target, master); arm_smmu_install_ste_for_dev(master, &target); @@ -2640,7 +2633,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) out_list_del: spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del(&master->domain_head); + list_del_init(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); out_unlock: @@ -2841,6 +2834,7 @@ 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 eb669121f1954d..6b63ea7dae72da 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -695,7 +695,6 @@ struct arm_smmu_stream { struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; - struct arm_smmu_domain *domain; struct list_head domain_head; struct arm_smmu_stream *streams; /* Locked by the iommu core using the group mutex */