From patchwork Tue Feb 6 15:12:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547573 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 F269CC4828D for ; Tue, 6 Feb 2024 16:16:08 +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=6j+X/tFrRuwwWm2HjGdSiroIfixJ4XRUJvNbnbvkkIg=; b=oJ9oVYULoMkcv3 F9c2ssviCCJ+lkzAoJpUos0CQZZTSM5TlZkrJRlatX5RkArkR3YJWuGBDY2YXYr5O1Ew+hD+fZ8yS WgmSz643p5XD0AIbF1h3LeTrmOxuZ6C6etpYiKcyYyfcfrxJOhtOCMg/QXtdGpzS5e9L1I572snTs GIC2qT6qVpg7T98Lm0w+zf+8YIq5Hob4WW9bpj5olKo19etNjrvvCMpvhW748OdWl9qAZIo9NcXuY L2iqaIRqJpt0kYJy1XxQmiqgl1dg0VENL+cv+B7oRwxHSCQ4dOooMmvA/dN2QRtFZ8V3HJn7nQ4yn rzBrzVpVlkNx8aYTw16w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO71-00000008E2q-3AIW; Tue, 06 Feb 2024 16:15:55 +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 1rXN8d-000000081Kg-0NBx for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+1NOuVIKVJA33Bh/BFuFbrKK+mC0/VNuAL+FszmwcF/9OzZvF3rfDjtejAuBBkFAwnIUwEPn/GbkrMyGmN+EWXlxlBAI8eGHVoYp0qYH0q+qPgUZKNgEVgRz4Fn0a8N0XJh1L4eYYiRlRkpHKuPtyjr/VtjU2/JeCkDOsg+QjyO2+EXA/Z4EaNe+p9AVrReAoQkg3NKJMnONCO/9rUrwt+egwoOJN+phUaL+BeF+CzmjSUZDaGmU78VX6gSe87U5Z9LyJexEfQ57I8rGcReif/ac1pOyx21+rYHtrOWV8fsUp0O+KMHC8pKzh4kLVJ2x0W1GmMOaNr7Mpgp7ydCMQ== 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=qoyh75BViievlqyr0zoccpkZVfxb9X8pkM3NWQ8Ut+w=; b=T1lAN7Kfk+LJYmqLQFfLyIyogLkRwkppYLrDki5FtJugd2j1To7dy5OeBe0Y3yCKCCxcAQ1XCYpyxrWANX9GUsKfSbX3uCFtJchZ5ITCwkDbgHtScoYCwRmvXOP3/1BCatgpikYfK5u0Eodmp1epV0G29njtLWlTQg5n8yx90wMRO62N7kWigcE4Af6tqZocgHoDSKG5PLUBs5ud9PWqXnipuY8u5dh6TfotOahXM0SjjCfdc/qHl5c+NwSEWDHc3O2zA0P3rqtEucdtocs3Ig0Heh+/9aavdX61k8m/1gH0TyE5pVtFyQNxO9bSUMLxTjF/Myqv0RuUs9X+0v2sHw== 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=qoyh75BViievlqyr0zoccpkZVfxb9X8pkM3NWQ8Ut+w=; b=IB4AhPXSL9Bw1purrVRxwsEKJr5ZP9RkjKypkwhIGq+v+01J+fpDBsvjtElQtBubLIS0cQ+gafMFvAZGGU8D9AXMtArniWxHQlRyow4auOVh5sReWN5bzd2tHcQPEcMexvjWaewGoX5AJopUO7McFB4PQPsyNDob5zNJPBL34yBgFS3k4PQfO4usE/X/9VORHUHvq+CBdMNRPuu3V6QdsETuBGME5StNdsHCLZHhGvPdz3XB0GXNwGOs+BYL0eWwYqCNvqP5zyBH11eOCcWMUQEAEmD/D//uaMy9ZynvEW9tV25lMa/NAcJmBci/v5i8mY21/KWhZuTG5mdu8wNMKQ== 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:07 +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:07 +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 17/17] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Tue, 6 Feb 2024 11:12:54 -0400 Message-ID: <17-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: BL6PEPF00016411.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:9) 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: 371f71d5-40e3-4277-ee84-08dc272619e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bmkeY2adzF4SVKZ09q9+YCiKZIvpddFTBdBKZP04T42iUT4ooYnkbrtfzepS/s0mGykbwkmjHwTBvWQFQTlH2wRmrq20eCGWPhGR2WhRCxx4e7x+SsMMtzKxqnNK6AoNnYQbYOhdYt635KI55Z9VsBeR1R9Ixg5VzIoeWCB846p9y1bvehy2UsroICaCLbAEjcLdoCBKIMD33fchLG5tg+ToR5ziokg6okiAn8BApYChYT/aD2ZphWhjGbgocIIAoEhL9fy1h+KvysUDLZoArjW1Pj2S48xF3Jh2reb8tdjQ+93ZYqpmBpovgKDasSI90mdRryO/JI2qq9GciQ4Vx3RbYv+3MZdwNmlxclYr1znqUN3gSQaUAywT6WWqF3ER4M+6bYsfYh5oxdtcK6gXXYlrFaLaLI34IQLt8Tx1HmLU+89VZ47MGBafp0HWtd7eWsIvk7AZrzz7joyj+LhVtWOBFcwQ+4OfmRFjSSSXbE08xtqqQWmDApIuzRsowd68byKAmn7NagdVwDFWf/OhuEC/jnvoIyP2Xj9FJ0UtnIZFBoUDo6q/jDF9kDTrfGTb 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: HHkRzIJcdmVUHCvSt9hil2wRpqApkzM2upTKY6wAtM3xA52fJM8KUBmuutS7RdhtdOO1HXcvsfolqR4MUdINurchTU3gDt9CkJgUa1Zj+eU09ZNtB1zm+n3pCGAmIHia8Wt5LXDxTEobGvY4oeb5kK8vpO8j6MyZf6CI1XdUG8MS7eZxSbG1f2qXS6ZZqTMIh9L+zswwmpIpx02S5PF4rjrUcQyYLLraD/dGAps7kghbq2eLPQ1u00XQXoiwCwN6F0HNqZ1pWhhgd/zDX8wpuUD+Md7HgeFYz/zVXH01h5DD/zX6qTdFbXM1cVSaAo7UCK+96q8N2AHAs43EvPaYaxUhZfBSe5bChmktFPAvkQCEJHPCdRmOyo1Z81WlgIxuQAQtEBi+v8fW8odqYFUhvOutanNb2ZQtDkVt9e/71NPpYQekMsaQoNl+N/7UV7hKgJ6b1U83quP9a3cMvvCRbn1t98cRYFzD39/uD9JJ8QTTzoOZ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xc0fMWIwPrnEIZ+re5QXsC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 371f71d5-40e3-4277-ee84-08dc272619e0 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:57.7343 (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: 6Q+icFWjD/f3WEQozOcrmbg5GD282iBP+J19kLH730AT2Izi7gJQhfT0oX3oRt1s X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071331_645286_0AC2ECD5 X-CRM114-Status: GOOD ( 13.25 ) 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 7116874c332ffd..ab2f5ac4020d71 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2249,14 +2249,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. @@ -2265,13 +2266,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; } @@ -3135,6 +3146,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,