From patchwork Mon Feb 26 17:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572538 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 6E59AC54E51 for ; Mon, 26 Feb 2024 17:11:47 +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=Z5nq1jEgldpuITWu7ceYMvKQ5kB6BaChLTObL1FCTsI=; b=puWwBt36gnsJh3 2j8fuTwp4KGGe0f4fGv16r9ZO7/4pv6qeLHTynk77CRW6TIBBM/3HL1B6MApH7arcXa7XFmhQR/BN JWk2UeZaZyHJI7AwXeniato/YBhvjajg7E9QcI26gKcdxEBYKKXT0Qy7z/ojLSsNfs6sKKrjhGVA4 R21p3RJCHnwsXrJMLnGNnLH5IQCOAJpEC5VmmrGWFIjeEfLE8LWnxoKSBURZAHxJjIw0HsnX/lovA w59Any12Nn+PSjUisICSbiUXDwTvzwIrDf7YI+7Cp5nR2CXhB7TtZYCWxdEyPKckfyXgDbmZ8kKI2 aN/X2o3dGCLzMlGRy9Tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVk-00000001rTV-19l1; Mon, 26 Feb 2024 17:11:28 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSI-00000001ph5-1Uea for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bk+4KDuBUWBRtL5vh3t8V5+/71reeouctdxe9HLyXkxV8kYeA6/9OXju2GTm2tEa53401HqVwFC5p0prvNow7ir3SBUH0D9pyVz97h0BMuRL57TMR5OvDGU7igdjbtdi+YoVdQs88cTTXw/m6l7kBLm9qFIFGvBHfj769kqnUdxKRSYfVgkUfQZYLTh0N0ETFRrVw6y6sHxsIPpkh13lqC+nkU8Ja/oYbOSq6PAkAhpJYaCuPzwFIxL2uaADq6jsJ4ifOGN2y3t/O/JBcFILjebAAZPv3iQTdigQuiveN0xO+tTpR9FOtZKypzTq9pDMb276+8zvWctsT8jhVt9gxw== 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=9HKnHrBwb+Z+1l+yckkMjT3Wrn3vM7nTUOTP4JZIUD8=; b=oSRceYM3sKF1XvQq9cB6OKZ9f131Bd7r4coivOKmoOjv+/zcK6ZxsDV8ccVuDqtBjQcqM/LtRcdbUvVDXp5De6yyzLGOs5f1RFRw9xZa6dpN9ohn6vCVCSOte+rfddfq5CV/T0SIIFeL/+luBgCed4IQiqGPMv2170Ifci6HW/MTVYF57TtuTazkyl1pr5xWnUMAVwsYL3d6ISAUKhSKn+WzSXu+OnZ6cZc8x/f9Bk16gI9jGNcBb6CuLJDI2NQ7dceSZi+I/e+cBqAmJyz8+c8FXj53CXCJQqnEJARV6A+WsA3RI7dz+Dbdejy2MajZPijuNKVyzcU3MuQYVz8HrQ== 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=9HKnHrBwb+Z+1l+yckkMjT3Wrn3vM7nTUOTP4JZIUD8=; b=Tr+nSZsCnHOashcbtSws+2MmRjuIBPQWV8pjoUubl7cCTzCqSWtMJaot6CHh8rt9UMFvuOI9fBsp+E90ilaVo5o+enxMe8qXignfGdPInyXIsE4ovgvKcY4F9JHp6WHsN4iw4zWXapp7LBkAi2+7+PhJ5e2ShrHIPd2Wsfeo53gk6OA8tMfv2IgPsCE1uDT51iEuqNYy/aL653LN5j1Koeyg8AfQPpRZrCZXbMk+/T7fIsUokNXYQzk8hN/D2ZV1yXI/CaB+cadER7qEUO0uLuDoeegXLehjBBbcik8VMHniJptSA8goU+zhT3kLzCJjh1zQ76PS5+p6n92WpDo6VQ== 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:35 +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:34 +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 16/16] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Mon, 26 Feb 2024 13:07:27 -0400 Message-ID: <16-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: MN2PR16CA0037.namprd16.prod.outlook.com (2603:10b6:208:234::6) 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: 2ae04752-1fab-49f0-ce70-08dc36ed6aa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8gmq6hnMkTkpgqNJYRsFfvQ2JRo3Ekc0EI6IrKlbeGw8hwfXF3IjbxrK93OUmdZDMe1elK2EKqUNh4kvYt2jSgPG5Jxb3y6aMBwKVJ2C5do3RQu72taPC63LWrh5SQkbN6okiZWRexTTI81kKXugbMjHTka99o6k9rr/fWQ/yQqryEfCj0X2ScCyvGvfwKAMYuXZM+Nu3JJTjST5TA/MFK9XFql30TiWSrCuApmXPBEG5gnpRMaK9iL7BTJRjvZDLLsqEzX75QvFdjYpwLS1OMnpMVFZ6kAUQTHK5da7kSFjCiHE2b86KG+hEDv8yUHGYxGM51qEB5DmocAH7/FkMHA+aKccNSrtoR1zIjIphkLLgY8EaaQzl4/ZfUlNvO8cfwlQCoJraB4jhA7RinTeAtt99uaye8p9EIoan/0RsHKozq4x/6ux973bfShO5QTL8EK99rDYcX2MLz0pkSjS2MuGmx/ijCA1wi00Bvvzv2UC9RrXpsCuiYYeuXMYxEMtS47TX0qnjsG/xf5TaGsMBCMpZWH7ixXhj21bV+dNvbRVqHEXQSX3ov/96h0L7kOrK0EIGYYRmDwogXUGjuXgzIrZ0ncINU2jIEceEsJi4xej5ugm13n5tnXyLyOgfe8cP/ZkH0/QSE7Cxt3uZYADMg== 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: EyJxObzagnR8Sx25qZbOVq8kmHwNasVTl+hNBIEquw869ykaMbXRXYi0xkpDUl6NNTfa/Z4znOKZnKZwEQItbuNp4IL6CviHGe7tqnCzsubzljGmuezIzufE0teb6ZCdr5bR5aZlxlEX4Ue6OmpGzsmpaBsP1BrU92bQRHzQYH4K9s3NqOtGirLxEGHp5JbGpuT7MMgWAk/5FhvfzUuZVLh5o7TBWI8ilfWDiEV9RuQqBl3rSb/104WWz15bswU5b9ev0xvQBbjYAkNCXuu9VR5m+9wrI0pinhtuGkpGNJIhwlDIYbYhNqat8P8XiUsEyJicyu9xKw93/tKDybQ/1t6cfqynT6B3IH1vWSEnE3+vhYJwlV4BKQgJC0+FkwAz9QQF8cnaxmvjO00yvVaDS/qDNmZsymx0MxxxETLjr9FJojckwm3F1H+fPUj0ZWfKPYlduOZS9axT3yrYWlGGOid4172p29gnTBPm5uLoV67yzUNYdy0luB8wW98+I+BUhEmqdIA3ex9vXDAd0wow8zhH2whgbK99h+nDAHzWjuR8Vd3pn9WuUuOmnFdEZFmTi8G+4NvWj6LBg5m583dAyYkddw/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-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.5318 (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: R8JW88GMGh2FiEEf716Tz42g8gLvvKcQWrC7YswtG4OHVKtcH41cLr5fJQ+g2eLE X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090758_177164_AF3CC2BF X-CRM114-Status: GOOD ( 13.01 ) 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 Now that the BLOCKED and IDENTITY behaviors are managed with their own domains change to the domain_alloc_paging() op. For now SVA remains using the old interface, eventually it will get its own op that can pass in the device and mm_struct which will let us have a sane lifetime for the mmu_notifier. Call arm_smmu_domain_finalise() early if dev is available. 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 | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 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 ebd8362c8aa3ac..b7938f17222b4d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2197,14 +2197,15 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) { - struct arm_smmu_domain *smmu_domain; if (type == IOMMU_DOMAIN_SVA) return arm_smmu_sva_domain_alloc(); + return ERR_PTR(-EOPNOTSUPP); +} - if (type != IOMMU_DOMAIN_UNMANAGED && - type != IOMMU_DOMAIN_DMA) - return NULL; +static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +{ + struct arm_smmu_domain *smmu_domain; /* * Allocate the domain and initialise some of its data structures. @@ -2213,13 +2214,23 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) */ smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); if (!smmu_domain) - return NULL; + 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); + if (dev) { + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + int ret; + + ret = arm_smmu_domain_finalise(smmu_domain, master->smmu); + if (ret) { + kfree(smmu_domain); + return ERR_PTR(ret); + } + } return &smmu_domain->domain; } @@ -3083,6 +3094,7 @@ static struct iommu_ops arm_smmu_ops = { .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, + .domain_alloc_paging = arm_smmu_domain_alloc_paging, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group,