From patchwork Tue Dec 5 19:14:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13480706 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 DA995C10F05 for ; Tue, 5 Dec 2023 20:30: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=KQTqpKOycKq7sbi/dCxFM8XDV787ekd3g92tqhiwCC0=; b=li6wzTSooXo9t/ iVGBwug9Wa3xShAZUTyBE47IZY2Xw/aED9Yau9d3XEqbebY6qsOkwqg10Jmuy4oJNqZYLSa1hnanI 8hU0SJ1sbqnPRr7anvKHzeepkA/Y69M8b786GHO+0mfOOg7JTNJlkocRzw5YSBSOYZDcFVee9Yq3C ITxmCqPNRs955D6AA8lec7lwYf1UwrrOgkB4WWNqwhLcYQHh9iWWkQ8as7PxUzlkpPeJT+u/b8R9n 4Jjo9S7C1dYaVuom15IB5Sq7FJZhh23b4Ww0t6hp4QEKoqtH9wZWd5OdqNBhJ+3QYbshPbmbMoZWV zbVBxKw5zDp694VApYxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAc3p-008NCM-1x; Tue, 05 Dec 2023 20:30:29 +0000 Received: from mail-mw2nam12on2062d.outbound.protection.outlook.com ([2a01:111:f400:fe5a::62d] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAasy-008F29-0g for linux-arm-kernel@lists.infradead.org; Tue, 05 Dec 2023 19:15:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g0DtNyNnoJOmgdAWiunZXDZDYoaKdHNAtOv4J3/EXOsikt0h2k5JgKzMbgduLcPav9QlDDjtK7a120+BR9aF9Cm1YFiocGttZ/t8RDJA4C2Uqq/i1ExbOBAzeYC3LcK3wl4XrkUn3BciftSs/yGspZYqOdKqO+uOXzGiB5BpUZS/dR2AF12OBCpR8mMIpZabqIT2vWlwiZNIh7IVMIYExkkffUVMOCYtisBe5IajQXcs3PgdeeP4p4VcrgMaP6tUxrg9Zmrqzxwm5DwjHCNUle67/wZKyy3oZamkpEGVuyS0kSrAycdD7F7f1WO3UAXgi/w/IET13fQ39dJg7FKb0Q== 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=8eIQmUzP0O/mO7GvmBmw5epn598QLWV/13gSPogNoQI=; b=RrTNDkr0Qt4UzicdWT2AtWneBWpC3jtZ0W+L/O3ndU3jyP60u9GqriGSI6aUaPw1enbAAd+3S3s5LiQ3okduy/LMpLbxwpJYBkChX/q5ZsXj0fR1oKz1vSsrFIBdcTXDnpFu8tiIYpjQLY23JD0z6WUWsraShizOSoMrgsVnuxc6xPCuOwxN0zlfO5waH/+bTur6Adj27r8sBxT2kHbbe7YGj58PGjIi0ZT1xMe6XsU+BP4UU/0yeAIuKa+2CFC6QGw8gxk+WJXzgGyDuZ9dYuF58FtjbY30BMPTlG6bc8kRICEXODehQGgM67xrKhcXZ1CJwSfNclefj+EzoQxsGA== 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=8eIQmUzP0O/mO7GvmBmw5epn598QLWV/13gSPogNoQI=; b=eZRAbNP9oTSm5jDKJChQJe4Hhmmh4rkIuFUoyeRpp2VGTSsdpmYu4bZHIB8oYDaFlaM4Idln9+lhY8YRXHCzGR97tZmg/l0OmxO0oFNnp0O5ocWsCRl30hvaokNOQXH8P+qRIp5vM0P7cri6GKTjOwYZ47R27ctaelzjTawFVZuSRh1aW79gnyfc/dBOq2gKlU+loelggDnXKvItI0i9WRfQxovkQcqC/ODNat4vZxJEb7qY4sZG/IDMiRBsG4B4Lmni44vqUK4XIxYK0UmMbHEYtAXTYiSV0t2n5mitjjRt01iqO0R3tGZhY7yLcx+SyEGGFpXsSNYuHC5yW540XQ== 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 PH7PR12MB6588.namprd12.prod.outlook.com (2603:10b6:510:210::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.34; Tue, 5 Dec 2023 19:14:59 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7046.034; Tue, 5 Dec 2023 19:14:59 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: [PATCH v3 14/19] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Tue, 5 Dec 2023 15:14:46 -0400 Message-ID: <14-v3-d794f8d934da+411a-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v3-d794f8d934da+411a-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00013E00.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:1a) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB6588:EE_ X-MS-Office365-Filtering-Correlation-Id: 9bf36191-fddb-4f1e-5f03-08dbf5c67591 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bNRUfq2NAK5Y2zGzCggfXGUPt1CneAq7egTeqoHPcRXlXWbsuduO16WW+UGrJNYm1RMUwMNKqiKpMVk25FyKnPKcCXnS5Pw46yF+jcfZP+YkRt06robb94OV9ZhWNqiWGsZZfwkw+1nFj61jg8qLWZWCJ2DJugl0ib2cN14rA6CEczZ42vxOmIxwCe2J6YiH9zIuD4PHS5OfW60lvtTeGKxswPfLS26lrKvVYR+1djrUSh53E44onHgW9u2k+ZF2GLxAKQlG3pgEPpmQSk6zHFmp619pRXb87Ep4LJtQMSTlLWoLysnOZkxpL8+wGm2FIbrCX2APiqdTLljwloHPBKmsiaX+EkXSCTUZr1hSbZGZAcWqujYaDtmqFmnm4mpjxMjWa+nCX43+lZE446ug9muEcectqLjgnxI5Jktrdg1VLs2aMl0LgyBRU9qkKcDk1emnr9jge05Evn+/ijsGRxuHYC0312l1zxKpWgI5CJurv2BiDvUo28K9p6p87cfPZQ2J4haaU1jXpMB6JaAmmZ7Qc8x3ssAEbpF5taFxSlTGB5v1fMNsyudIxvYU5WYM 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)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(478600001)(6512007)(6506007)(8936002)(6486002)(2616005)(26005)(6666004)(54906003)(66476007)(110136005)(66556008)(8676002)(66946007)(4326008)(316002)(83380400001)(38100700002)(7416002)(36756003)(5660300002)(2906002)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7s29WrsdmJIvPssZ+WaKXAbGqRD09NxBmPpg0t1R9JypvVq4V+L96Fn7CeulBburJatUL0JO3yG3u7AxmdO4B3CU0xAfoHyk8itCXf1bDnalhjIH9u8gTtpngQRvB9FMXgFVjIRDwFByDghFYa/ORB1vvGuA/eAoZjBAJnbWDTWks2dy0fzZ+A7i8wpJ9wouiacAAL5LrD02yFM/JuywM4R2V6QeB0hgxh9UvrXiapWimGG4+o5DzUe7dkclH9fSKK1UGguPFfSzFaOs17pd7BMZnFCNeddbWP1k9yZm5oikXt9F9CZUKhWZ1B6Ht+NDx+ECN3m9lkC0xwFC5FividTKAj92CxsoMoYM7uelObEK3Ce4z38V74psP69XZjyrUzJYDA0cHDPz90KXt1ACm1PnEwtN2yojIwYaKqwdwtKmCJmOwkN777Qy7z8K//pFfs694PW0J5uc02+E//C9whGW53Po+FeHRHRISAN6xe2WVmE3xROcANFC7z7F+XTO81/hoTP3BoLJC9CqjMhM3UPGfknagXMoGHloTS/avMYUupfoARXyf0J9BDXH9BEWmv0h3m7mSoO2P2ztpyeepHSpU/XNy7uWp6K38XLAIl6NaQKyUu538uPOUZ7AAJ5dYXnsWdFt343WURTPCZijL69LVyNKcORUR/8Rs8rIPO8uCv9dLXk8/YKCCHBao9cquWgaUHMpxZhzISnPlOVgoAngXvEuKJSvazvT9ktU42ygyil/2QsYLyUvJStaHOaS8juRD153VoXDudSmixPwTdHhthw5gZFhBv6nwHlXtdZoGqmKoNN+GQIdjQYB+yfi8/s/QQLf2guOzrQahLUOFbEQBOT5brxviAADk50MA73jNK9/nBbEqUv8FcqvtpYfhoRpna91tDcHz6O8tGQwlPn9KBEol4yKYG+EAlQf9hZjwIffqQbobxhlo6CXYJaFjU62jhIrdLMGEpxPGB7BIG52zZiepVU+dY6jAyV1s29zY19arB+1kqGaHBYhXiTGP0eNnpNyfPIXCbqrX0bWx7SUYqXoF3RJNn6+VAm2FiUEVHfGEjU0kSpaTyqo30EcvF65iGjQ+sYE2iVspNEC2TcvyqKNmPw+CDdYq/WvUGLBsKLuTpowoIjENyY4H8vtUXCx9l1TegqWeXCTdk5dn+IaTMkXMbOcNmw6PjvkT+5avbxGCjugAHdg2fyRc7dvUygfH92Y8UXwUWgUOGdTAVXPz21kIItkWS07J3pOSGoJMfT+C3NY/kEpvgelmcv/10D5oDdGKI9J/AJVwChNXy+9YlUFnmuvAajDwFie3u4LUEPYItUK4FukvN8HfTNIFAq7oz03PrSaiWvFBX3bJCS7oOwgaL/fmIkRN63BDP2twgssAO7YLHMyPAJD8ruBK9BQ/JSWRJ540SWyZyCR5/+wmb7UtTIwkATB3srzV6uJZxyVb1rkHrYQ26CYvc2PwoSFZIOsRs3yv0t/h+yWLBrgiKZvi3VABBXJz4fB3sFdddXDhwuKtPggB2LQ464lZY+pBdjNXdvN0wGzJ8t3/WFJN7BkV5uySOD9HM4aM4WSaD55d950PC3K7qttQkvk X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bf36191-fddb-4f1e-5f03-08dbf5c67591 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2023 19:14:52.9408 (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: ggXFbnbY42SgkXE6zr0tiTL4EqXqahh/yevDucw4/z3w4QXMX2WDHlSvZnbnlzEO X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6588 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231205_111512_292518_16CC0A4C X-CRM114-Status: GOOD ( 16.51 ) 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 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 e1de2799310961..525048a79e8a90 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2480,19 +2480,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; } @@ -2546,8 +2547,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 @@ -2566,10 +2565,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 @@ -2577,17 +2574,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); @@ -2613,7 +2606,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: @@ -2817,6 +2810,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 1be0c1151c50c3..21f2f73501019a 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 */