From patchwork Tue Feb 6 15:12: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: 13547569 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 DEECFC4828D for ; Tue, 6 Feb 2024 16:15:54 +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=g9RwF4MA4u6f5QsrdXwMw047PhooNQReXukCJZQ9TcM=; b=vJURbMJTr4xA13 nNZDaOUS76XM+JmZ7MDkOi9pM9I2QcFndReFGjLvkuridHPN6eYAj2WX5mOj6WRoKgGKaH2jNvUvu fTFM9c69ImdyUFD3au7V5kyz8ClHGTgNM4vgyFNt5mUktOjkm+ucbrGaC0HioSqyvdOemCIigySig ygt7KduFhKE0sHv5VXSi9PIrS6yfkLmbW7yNLPA7eGbkSt5D5Z0mCeZgPjzJgJQaNvIXe7oYzqooy 3XeEzijZTOOwuhzdwS3ZYo6Uz7ovTYegwrj4M2stM/wSqOVPr9lr8tdykkJlTi1Qs/AzLXhvXG+td ZYIUo0EISGfSGk4/I/pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO70-00000008E1s-0wrL; Tue, 06 Feb 2024 16:15:54 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8N-000000081Kg-24do for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhRbiNfxEeEmM1RI7mIeKh0SW5khwDoGcRpBhd7k+TBu3t8lw1b8teg1ogD6PWOlskkeWJ6D8i+BuwDxfYg3AFr6r8H9eKTDs7g3oodkImu+E/XesE+NOTfq4S0O8lcK7822mPSFJB+GiAEVAYLsizOCEAVtqoji8f0tLA20Ig6TzRsYmu213gaa+K6CylDroiQeOt1xW1ppvcNhqGXeC/12yiN8EOMGTwgLJ2wDSwqZN6YNvNuH0vZxqANhhL0BQMweCXlIkFf55CZ7wHyKa6gEe4JAFlmYEFSwmFo4f5lJrKLx9AfPvIHmdXOXZVi/j+3tVLCmdD+jww84lw2vjg== 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=zsFErtEFV3maUSqhykvMDMh7NNOem07IZG8xZFo30z0=; b=Kf/HjbX0uhZkj4xfHCOsw7/de45HSgR2TOgKsT+7DGUt79A3KpMtXOPWCtmFo19se3qckM6jVSmR19wPMspZM8m+/7vxFvA4QNZNS9GTWADo3SG8rekBzpYJj6SUDUlYUcIywrvp9CQoqRIqFtsC+SRlM5NzCqkjFaCzOxu8rYyY2wVb6/9bxstngYvoSuNH/fweAOCjVuXD0qOiTz5dlzVjQd86d1/ZWF8H4Q5bzBfqYFQDZ5HhUGAQ0j305gLCvwwnxkySufC3S/2VcJyJcNv36t2vKIctN2gjCqA19Sow59GwT4Hpg/++KfkWmyygPqltydbfNdRwx16TKfKLTw== 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=zsFErtEFV3maUSqhykvMDMh7NNOem07IZG8xZFo30z0=; b=iQX1QLSxezM/3W/RWDWAn+WHFSfBKHQ/kfwrFI7TbQC5CRaU/XzCvgSgQBquB1ejWl4PzlNl5p+kn0ozip46bUy8FRxqcGufpCSkBcd/pQX939y+0r4tYjsLfaPgPTs0ucds9qf0dE0895bVWKwJCCD6YzAoS8AEnz0xISVtS0yfUoMEfiJu1d1UzZbaONobkpG+i2qAyvV4SuS4bcjonOUz9zPodyAfYnqs42HfqWovoyd8gwaSBeHlwyWTqMAVXw+5HRRZUiHIyiwfRAxSb9k2+GD+pC6SgGW9jqeVmFUFP6m8Tmj1QFbCWglBpZo1EX9h7Pas0IC451Z0tKDCIQ== 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 SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:03 +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.7270.012; Tue, 6 Feb 2024 15:13:02 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 11/17] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Tue, 6 Feb 2024 11:12:48 -0400 Message-ID: <11-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0006.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::11) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 7dbad165-385a-4cc3-5874-08dc272618bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dS/xgbIkPBmEZdABCsb1xmV+QP5XbklYLBXLgVgjhLB30kZ0txIUGY6akSleXzj4tmw0lj5k4RMYlpX3TfimisgSRR2NGHuX/Qm3wl+r2FNQ1+it8990H4L7qzSJgiyR+Ltw5vb4V+6jgldAzbYcLacboNXCy7icTQROLfMEN0X/USNc+TqTvwdNjuXHDV2CV0ZRrJ0lyyCyNI6WsOm/ii+kOkqFr3nhJ8wka8tQHa1V6TRJ+H5KAO2a5qWqY0Nx/Qhi88pI52lRty6QI+iNp0lIe/RbkXHxyl4oG82yuc6lI4c3AAG3CZfXF7Tum/emKJCU9ELVrLq0HGUpuXxBm9+MjyeFC5hu/5eZZUua99pKg/GiRsKcgIgRJ57D7ohYh2NJUzbNHMIgrBXNq61ZxYJPjnxM9a+fxAQeTqXPhzMLfMGjDVQpvzNvZiCFi4b1ap4VP44+VU1tXEdlmGyYosX5QiWtqNr49nOCh6Bhn0x4FL9WLlskdGJm87Wj5qEVlKUdRHPURlsLoqWppTv362umW0iWyN4Z9qHLdiADo92Jlq7/EBnIymKFplhALy9z 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)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MJMGH3fFnzIhD7LhJk2JLHArUHcETl4Wd1Roc0u9KySxu1YEKtZZINxpLieoraxw1BWvLOY6LtTtQQ4VTKmNVYKMhvChl3/XoCRAdZQ0UrDEZ1DJvp5MzhdR2UrikpYlkmcGtAsZEh7XxFPYFMJhI//c7Dq61+ODPITnui6WyKDT+RGFnHc9Azwy5TaxYqePEByb79kYKYC4QJGPr8Mm8FKqdAPM1S+63oppSd2OAPtPF8PuRNOqh5zBDkZRc9uuchP5TnHQcMutbEKHgAfNGiEAmUvrZlo2wzVw4bbyrEQb1uGueNZpQRTTYEGsSyphOZDJ5HOYOM4kTTPBxwXeQ+T7flZ3i7SzS4LGTtVPfAK739RZXeC/We2wUhebBchzuvL8L3C5oSbUAx3wKnRHT0yTbO7yf8H2YCbIGx58mbAa7/QrVBNVg6ACtwRph+7cONMtfDWg+PT+xq+uafs58DKA0UGHg0D64Vu+jf/g7icfuaIXafLR2zrdQ5FZ43PzkilmUsflv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riginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7dbad165-385a-4cc3-5874-08dc272618bc X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.8158 (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: UBLWSZNW6hCn0Z4+JsZawq5aN1/kDcLACRtTGEoC5p5iKnEH3FPArQYd/2De7IQi X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071315_690368_70CB8E1B X-CRM114-Status: GOOD ( 16.84 ) 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 Reviewed-by: Mostafa Saleh --- 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 133f13f33df124..a98707cd1efccb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2560,19 +2560,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; } @@ -2626,8 +2627,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 @@ -2646,10 +2645,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 @@ -2657,17 +2654,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); @@ -2693,7 +2686,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: @@ -2894,6 +2887,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 cbf4b57719b7b9..587f99701ad30f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -696,7 +696,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 */