From patchwork Thu Jan 25 23:57: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: 13531908 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 0D39AC47DDF for ; Thu, 25 Jan 2024 23:58:27 +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=JOVgP7fnSPLzaKO4fnXZcdMj+2i6G/w85EK1aulLfh8=; b=D99i/E95TGzqHZ 6079Vc8hZaNrxRilbZPyhCsLgyuhxK9GkP+WCL2iSsVwT6qlEjqe3qVKrUZfbUCWJnFRJLToPvcAY 1DTDGIjMruunbqMK/SoTF3VCX+lKlOTEC1bOsqH/xQIMh4V7JmXHILxw+iW+6bPhasjDRZ69gJ6nX XphdE/IDdlLMewLCCe79gCK4EmjFBE0C62hUCEVyVcEfGzRVa7LIi//BST1stUzJ7B4HaaZy0E+o7 8KS4bNWVl5zJlzI51RvVxr3tB4Rd920NdBwVmHHglLEbHGMTRlbzAOFZXTE5FsZz8vHIBAFWbtXeG VqrN4kOli6moE6jYqivQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT9bl-00000002XUo-1Sij; Thu, 25 Jan 2024 23:58:09 +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 1rT9bP-00000002XD8-2BCT for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 23:57:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iseWeOiNkHs3iNLiYdjJc964I5xMXH2FLtiYXzrN0DOQK6nXpJ5sY5rT8JTLOt10/Hg0FvGVtu1yF47Sxk5Zv4iGAeqyBBzEIsxdgv8/Ya4ZcpPH6P2hj5+94szNO7C1YEn1f5yq+vtD53JLZBdX9Df8iLu9JGYRpqFelIqsHaPgSGRy4Ro31W9D190cESAom4QEaYl7Kf1Kh++I1GAytIUsijxZyydOf1VDi5/aeJnsJ+aIWRYo38TW+niaytjl61zvA6gVMCU11omd2dViXByL9iaIDYXLyBXiSMAMFYVx8RunQaDdTZZV4h1C5wrcXaIjM595afNE/YsTPaRNqg== 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=KZMw1NPFKTEUTo9sC8m2eNQIR+/60UgUWx7GPJrxl/8=; b=TFW4vLBhimPnohwnLVnLP0x1pjNmyLjNnBrC8acm5qZ432g1sQqJG/eu9M5zfPFNQA25U8ZqEzSNVsfP2H8jaEqNzHbIZjWHa/jAikdpiSt29KZaR44YQtWqVGCR5/LwGf30zXKA+4D7BECLq3iOFCqeZc/iEi3nax5XrrYW4cXGXBuicirctbuKeenBxyvvrOg2rcQKZOOdFY0xnh1JP0KX0gFbo0hl4slrXqDsgoyQSPn//Vih8bLt21zWthAyKby5czxhOuDG/B3OwLXhrroDTPXMcJcwLFyiUe9HHoP4M3Ad983L1T2IvkaiPRo7OKdP1Eu4DOuJteTByneycQ== 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=KZMw1NPFKTEUTo9sC8m2eNQIR+/60UgUWx7GPJrxl/8=; b=gQWSzOwZyUrFMRqSZVAXlV0+ZWlK9PUzg8/zHlQhS/OUaM+V7OdmcaH/2JSD5Dkzv0yy/ncZ1Orw087kFvhTmiaNiEszXoZBspQebwGuZIiQ6ldUmmZWxkYoJESf6fpPbwOJIx4mPJB8B4gdymRUYiSjEDGqbzfLFwcu0C0QjHqFJ7pRXhFOFBU9Zvyc3EINPAx/DzggsZdsc1AuxdvbxWK7jdQzAMIa+u+NfF4DuRT+CCxM2qsE5WQwFILLp1+c9SGNqbeOINqgPN78hp6obla21TBKEkj8opRa6Tw2BPAp2FSmwQTy/paf9HENFzq6S3DG+M1k85SoH2vmytmJkw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SN7PR12MB7881.namprd12.prod.outlook.com (2603:10b6:806:34a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.24; Thu, 25 Jan 2024 23:57:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Thu, 25 Jan 2024 23:57:35 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: [PATCH v4 11/16] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Thu, 25 Jan 2024 19:57:21 -0400 Message-ID: <11-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: SA0PR11CA0056.namprd11.prod.outlook.com (2603:10b6:806:d0::31) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SN7PR12MB7881:EE_ X-MS-Office365-Filtering-Correlation-Id: 05609441-9ce1-4bd1-3a02-08dc1e016405 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2wu+vFoeFcWzCQAHXLyARlMcxvDHq42Crbj3O2GUj23btEfeHKpS/AQv2iu9heyUekr0Ivyy04PLDzXQMASd3CMpl9/8g0Ylg3oGTJLi01ht3m+4/LV+uJvv9kytif6hFmHcc7VAft+hma2lrT2yH8DQZ9vcc/9gYPgKUrsUG1UDRudllc5OfNnu/moTVLUTvWQ137+RO+IRboAzEPkOPdYNc3qlr5mBVURGPuJm+95bBJx/h7b7oGGyWdkco+aWPcBPsmorAFLbOw1++SJrSpLV3+VlXmN2PB49g8nb5HzlEWn3FbgAnYfm0FQenIxXTsKUz3ivVW4V4yu3ZTbhbfnOY7OWSjxW+07pBVLeplchKRn3YM1ROF/iIb2hA0DLiFYk8GzXOf4taJ8R2sfV80s8ZPmfhJ8AyzYoclGprhTTqYn6VWE5mghBeotHOc9sX4Usp1rgE15aJ79Daq9eXQzp2oQo10ryWLntXeeSSuaSeQo2b/vh7Ctl0lJuvrBmkVrcEWRoIpiapZGiZ0x/2IRDvh+lG5q1AJq6ZDTSqL64fBAojYPnvVQv+I4O45X3 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(136003)(396003)(346002)(39860400002)(366004)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(83380400001)(36756003)(66556008)(86362001)(54906003)(110136005)(66946007)(66476007)(26005)(38100700002)(6512007)(2906002)(2616005)(7416002)(478600001)(6666004)(41300700001)(6506007)(6486002)(5660300002)(316002)(8676002)(4326008)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 000sw2O9eSD1cN+kq2iM/n7liJDlfvgwU8xRN65g3HWdy9c6584E9PTCpdevPmw+FBePLd5UXcSE7ZqcRRGuquNleHz/sbA0DpuDe8GiVGMhwBtG7oSP1AV7DtM3Bmy/aFRckcs5WDzYtcCCmmmPQIILKZn78XxU1W/OWv5XEkZYSYpqxOqLI2DOBES//0VXxMSLGN+OxWCv0FkKyi5wJB93O/3J554tJzkPGywOnTAFKz75OVXXZfcPemt7ctpUouq1JeyQJpyZ8C/PpqChHo2Myhj459BIF5tSVv8SFFur28gUg5AnxRbxX9evKkjo9sZ21TnN9HHSdAMEOAs5s2D56XxKRrBQ5sn6x9hoXoRMUo4Ob2VO9Ojvzm0qGGkwwOU4HTayuVhAsJKNloMBaoSXHY1it4s4LlHVvEXLb9H+Hp1vbbpK4zT6MtueEAwNg+K5rEJsGqkVmpIYDua2giV/KovFWijsAeBBq4imw4nQpv4iugR7yH95i8cGsWEF4+h5pzNAyqt4aLKqPUdgCpx975fx+Hng1+imxnRlMRtxXUp+MKBBv8o8pvGohDV2J5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e016405 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2024 23:57:30.2676 (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: ShBlJCOuS8XOMndYTcONxdoCTKneUEvtMMwQ1DWkNNmtMXn3ovuzB+9oB06bd9oy X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_155747_603502_7B728D37 X-CRM114-Status: GOOD ( 17.31 ) 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 domain_head against being unused, change the domain_head to be INIT'd when the master is not attached to a domain instead of garbage/zero. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen 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 d7b0cea140f12b..f08cfa9b90b3eb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2533,19 +2533,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; } @@ -2599,8 +2600,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 @@ -2619,10 +2618,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 @@ -2630,17 +2627,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, &master->cd_table); arm_smmu_install_ste_for_dev(master, &target); @@ -2666,7 +2659,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: @@ -2867,6 +2860,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 */