From patchwork Wed Oct 9 16:38:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13828831 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 C9CB6CEE32D for ; Wed, 9 Oct 2024 17:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding: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=DelhEmlnyMPfXXgn2PlMEYi6TuNVLiyt/1iWyZikR8w=; b=1BwO7enRhPcWBqJI/lzB9as2lb dlGZ7vZKh0hC1IL0ZMB4EViUdG8wSPJPruXy2VCcAErFTjEkkjPgEGAXVT+F8X4WR/pJaKIAD0CEm 1zYSDONEIjVqaMG7E0cclgcMrTa1Cj76TsrDHv7no0/bzP2uE5QoO8V3ehOVNyoLkrYv6NUJtdh1M LHSZBH6JNqKi+MMvkbxsVn72oPJ0wCyDGJwkNpzyd+yO2M60WhpVQXuJf8h7hkL7IXQ+huqVWnWYR 0nxwyWT+/64sKgkeOmmXLOw+a5olXzrGh0gDhxWUY3tQbZW1zXtwIB09eVI+pdBElgBjcqZO8VF9e fACnZcbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sya8J-0000000A7DV-2gNH; Wed, 09 Oct 2024 17:05:55 +0000 Received: from mail-co1nam11on20607.outbound.protection.outlook.com ([2a01:111:f403:2416::607] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZiU-0000000A0Wi-0bFj for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:39:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZkiPdGbo6BA7Xxyw4VmuZUTaoKAs7UQZe6YxxTSMaIUu2RCfkQdzxifBVuIV2ko2Ap/HFM5vTBu7ypvNvzOxiTaKSHZu439f5aHCHA7QryynQpoAFdy40N92lIOdJVyV3OrkkFrdcxuoMp0w6uP/669rSyhIWkCmtogwFc7w3/kLZBSxgf9jXrfP/tpRF+v/9KPAUxJMoo1hqOrwB3UpVByZGiRcMXqb83JvkZMa034xKYXHLmMRNlqcmnDlSbMozrBvh2m2JF7wBnYzuW47mloq7CmD0d0ooTgnT0Q166MmiZBXxkGhad3+zFlYDnzf/Ujg9n98yDr++2qRqiUvLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=DelhEmlnyMPfXXgn2PlMEYi6TuNVLiyt/1iWyZikR8w=; b=dG6g1+ZFPVmp+cZP/WF79vnWsfXL3+W8RUYgiSEVqSIBoDum/rQ8MJ80JfIGrt30MdwwJUHOW8v+90rURItyBWDFKEWieAezLQZWIH1nJ04QI7wz687fWG/Ulf1IN1FyVX3j+Oyob7gsc5d+7V7dl+37H0Uwvjd3pEZwpiM/LzR3Sehl4AX5LoeMIxMpo3uyH7ajbr6k4CgKAITGhLP1bbkVByiVrerYokHPZBYAbWHx1Ej8nxNXNg5mIR2vGUKCiiRULDpv6xOOxGHiEXBywAgtxCOSnmiiMysbTvnqvymfw/tklbEuMUc2VltjFQJVgoipeanZ3CSubbLrw9UVew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=DelhEmlnyMPfXXgn2PlMEYi6TuNVLiyt/1iWyZikR8w=; b=SdNEsAvBX1v2GnvLAVBsNOlYkgACmQCxTDvWSzej7EQhC4nNMmwxcFVEvSTSZ0H3AYYD7LAwU3PI7rEnV3O2vsv3gkypN3EuDpujjMDk1RbVqZWBLzYMRPlL27IYSCVCGdbRpGp7ExcHKH63n/V+NawKO/NVacZGEdj/FCEXL/5Ezyx8lloiuiw5NHA27/KZAGendwlGXuLCIFe2Pt7YfR2AW+BHJ/0TVxX6XgAUsWEvlj4XnEnb6wkOoDwTzgvOS/6A9WDqlWeKxeZ8sPBAtZEWbNBHvAg+kpwPHpEJORRfxrhcBytz3ACWr9bDB81YZlRDvYGUKyiUWE25+fCyxw== Received: from DS7P220CA0007.NAMP220.PROD.OUTLOOK.COM (2603:10b6:8:1ca::14) by DM4PR12MB6422.namprd12.prod.outlook.com (2603:10b6:8:b9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Wed, 9 Oct 2024 16:39:05 +0000 Received: from DS3PEPF000099E2.namprd04.prod.outlook.com (2603:10b6:8:1ca:cafe::e1) by DS7P220CA0007.outlook.office365.com (2603:10b6:8:1ca::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18 via Frontend Transport; Wed, 9 Oct 2024 16:39:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099E2.mail.protection.outlook.com (10.167.17.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 16:39:05 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:58 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:58 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 9 Oct 2024 09:38:57 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 02/16] iommufd/viommu: Add a default_viommu_ops for IOMMU_VIOMMU_TYPE_DEFAULT Date: Wed, 9 Oct 2024 09:38:14 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E2:EE_|DM4PR12MB6422:EE_ X-MS-Office365-Filtering-Correlation-Id: 16f46474-795c-48f4-9034-08dce880e3ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: bAnycWOBSR4K8bXxQ/Y25uwvnTBzP6IfroeClhTW18uM6FqMBld4/gW5iRleO3TUn3Iyf8oW5v/0P6/54pLTSW3r+s2A6+AyvMoCLfwrRU25mdDvH9p8KLs3Mrs+uDtywz3VGbj6i2+UsDy3KrAPMnoE9tUbY5kewXl+eXWa6wNUX5oN0maXF2FSGXgpRCHBvARCukfpbt4m5JOCankilmJdN4fx9M+weTJOKJjRssDuywhC/H0kRFVX7MOwX61jWsK9ix2bjDYiSakRGH89xnwkQ6Gb4QjhPxrDeqDh/IPphb1qIgobM+ALHZzwLGVaKD4xSLxuupWpE3MvbcqHdAB3rN5kzIdigT2XqrY8SUciFIppP8IK4eYEFAp979MohgjhsuXhnEPMdCZh0p9VfpAyojJOXa4AKRAtlWIGYEe26rV/7uEoDroSHLUGF3Xlu1wrDlY0FFdoxNRClHrwIWY2vWQjVy2MnAZz/QqDwq5yg8c1EeAd6P4xHpEjT7IkMKW9caWid+wrWF7mv3x4Oj1Y5xf68Thu+UNc0IvB1CO0OUnArcgpBWYEjw4/OycyOxVfWVBVadb/4yItSXM0OLI6Nxwkp4GuavXoKBK9N6a/bC2y8iiA2HwR8kwsGfIQHLnKVDUYJGubvzBrKAYi1l4xzKXLdNBzoN+OsP3EdlQ0mPEke9xBJX/nyK7Ka6/QRxsOezg11GtkbwCqa+rHKtGlKU8pj9nDY0lbWfCDpucUL2nDx3uMPo6Wa6DPdmnu8O4HabBtuOVRCH7rJLyHOdUo/KTRklgFrj1YHEHD99eVxEytTGRkDZucemMmc6edmKz2UochnIqn7OaL/dZFq/GPbnMcrseJEQtrWurA2a2Goziw8o0WhBwjr0XhEffBqTLhR9QMIPC+R5soN/jA+EYO7g/Gb9jKC3e6JvgG7o0WOripcWof6qNJ7RSOuhak5Gy5AGL4X/TAHI9cV3TMYntemsUs/xjlx8J9podLkcfjWQKEpeyBEAEb5fZ7345RNfCWCbQNZFKSd14bg0h6VjLf9qjxWp2/6miYaXbe/sFG0dzWN5N5M/GEk/7UxO3Si4LjGFgJvQ8nBqd9hWpD+P8kuP+1yiCeY5jWeeFRacfDUrRv5WSNHKV/AeM6gz4nxsCoplam3Vx5w8Z8fNpS13xDBxyIcM2EIlXpuVP3pRuKZ384oEdW+IHxG2NTR6yFolsBMSG3kJTTdCwJoFSv21qcJwEVTLgvQkJKoj+R2QO8WCjQQsSICTyM/av7XfJtT+Z7yqDE6p7bKeuAf1OPhSoeHgYIp5cnVnuJSYh82Oshe5YB+Mq8L/et+Yz2tLhVv1F913V3oyP7tWlMsEMLeNK2xDTghPYYt4SZ4nXI7ZzQwMXGC5+1Gj9bgz3Tu2ZS X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:39:05.5881 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16f46474-795c-48f4-9034-08dce880e3ee X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_093914_585870_1AD4D21A X-CRM114-Status: GOOD ( 16.36 ) 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 An IOMMU_VIOMMU_TYPE_DEFAULT doesn't need a free() op since the core can free everything in the destroy(). Now with the new vDEVICE structure, it might want to allocate its own vDEVICEs. Add a default_viommu_ops for driver to hook ops for default vIOMMUs. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 4 ++++ drivers/iommu/iommufd/viommu.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 9105478bdbcd..1de2aebc4d92 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -44,6 +44,7 @@ struct iommu_dma_cookie; struct iommu_fault_param; struct iommufd_ctx; struct iommufd_viommu; +struct iommufd_viommu_ops; #define IOMMU_FAULT_PERM_READ (1 << 0) /* read */ #define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */ @@ -551,6 +552,8 @@ static inline int __iommu_copy_struct_from_user_array( * It is suggested to call iommufd_viommu_alloc() helper for * a bundled allocation of the core and the driver structures, * using the given @ictx pointer. + * @default_viommu_ops: Driver can choose to use a default core-allocated vIOMMU + * object by providing a default_viommu_ops. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops * @identity_domain: An always available, always attachable identity @@ -605,6 +608,7 @@ struct iommu_ops { struct iommu_domain *domain, struct iommufd_ctx *ictx, unsigned int viommu_type); + const struct iommufd_viommu_ops *default_viommu_ops; const struct iommu_domain_ops *default_domain_ops; unsigned long pgsize_bitmap; diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 3a903baeee6a..f512dfb535fd 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -44,7 +44,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) if (cmd->type == IOMMU_VIOMMU_TYPE_DEFAULT) { viommu = __iommufd_viommu_alloc(ucmd->ictx, sizeof(*viommu), - NULL); + ops->default_viommu_ops); } else { if (!ops->viommu_alloc) { rc = -EOPNOTSUPP;