From patchwork Fri Jan 3 19:43:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925846 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 232E3E7718F for ; Fri, 3 Jan 2025 19:45:55 +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=svpw6cbmK6TJVd0yqb1Xbssedvh8RF6/Z//fCfm6jcs=; b=4npFFg+ouZKl9xzd8ow2KGlh0K IUQZg5x7sccasQdGcP9QMI+BczTG1BQNghBQQMwaOFuFXlWHV9V1n3gUbogVYcesxGfC9qS7r9aBn Djv6BmmJ5XfyS1svt75JWI4I01+mKV2iuM3f++7ghB3j2S4dTb8civYYhCs4kpw7s8IxEsAa2F58z dUFou0ODJ14ud4PL1MT0GBJ1PEMtlOt5WrdMRuNUQFDrIji/a5mBTVGG1TtbMhLP56AVkmIiw9cDt u0l2auu0PtsrzY3JHkl6KpBo6Q6zzS27oI/f5H4DqufwZt2j+UY1FJyGH12m6fSAz1pcuxeXmYMfF p537jIjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnc6-0000000Dqv0-30C9; Fri, 03 Jan 2025 19:45:42 +0000 Received: from mail-bn1nam02on2060e.outbound.protection.outlook.com ([2a01:111:f403:2407::60e] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnas-0000000DqOw-3XXw for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ULlC7sfsz8CpjYtxl1J+T2vCHGFUnTfhr4gfu4rIgG7XdGeSoTVJcos3HtyOPfMHRlE5DOkwN4l1Fmo3CGa8Tu2L4C11WD1laIe0irb8w607e3pKcHVd2WB8z1ztzfLstd+krn3YUYauk+p3PByFFI2pBfYcZ62Fn9ZKxdKopkItH3LWRpkkZSJgLGL5kbpYSuSNDiC+jWxrEUuhiGVEMn167URJVr1/s1B1usQ6CS3S7Cjb1YqJkJ1VG2ZUgXi1J+AgnOjrT+314jOgxETZjxm9KDIWprrXTky/xPwEy5ajERuY0lPD9aeIXNXBLmsRJ78JERqgXHlI2CzgJBTzbA== 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=svpw6cbmK6TJVd0yqb1Xbssedvh8RF6/Z//fCfm6jcs=; b=ikar0hS1ZCCxmHZ/KWultxUfMq1tYlFxfoJ8Tg/7rmGt7RdfGwpSvpIrJSdOIEUkIaQXHs6r2/+9m7omjoTvHPbLc7azdE8ObKoBgGaHJbIK4mOH9ieL16ycpBQZOm2ebyMSxHHBefkCBNO4cTcO464bF5wylUsO7JSLLTBoYvDqcpMOGfpbYgdxlBD9FJiigUUrDpY1AO9DMNC6SbiWmN4tM1gjqJrhXqqlVoLvNSkSu9toYYZQmU9erG7VC6zMMoVC9vVgp1tgW4eob/ISpRKLMKUoANu/sV2rje3Q5iXSGO3iBEBIQZABmPN7SKL89PJdJepmHHx2iVvFhgQcwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=svpw6cbmK6TJVd0yqb1Xbssedvh8RF6/Z//fCfm6jcs=; b=cZD66dEJSiiV/p8xE9JzuHVCvp3KZhH3pw5jUm9gPZ+OF+T0/X4uiWGnTWVsMnGPy43dCz9IUpSIqUTphGefdCQXMXJBi0+UjJ9ZfzY79XIHL3a1M4eCDCSQtht49myVMYLeLmIPYELDJLfOqRkYSShGKkg7XkX2SYUAT6R6Dth6yzA93GIjNIwIgJAhGpkFKxUjKqeSrVaZhqaLjyhcIVT9tuB/QA1CAvn3MAHQjUXOVycX+UbUD2rB2YFTTazq+LG/IJsbQFzv67VWSB64L5FYznGKJeNtwjOTDy1FgBkM5CAfMUHf3wsgVLnliO68boGcALBKHSBiltK1eaEjNQ== Received: from CH0PR03CA0054.namprd03.prod.outlook.com (2603:10b6:610:b3::29) by CY8PR12MB7562.namprd12.prod.outlook.com (2603:10b6:930:95::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 19:44:11 +0000 Received: from CH2PEPF00000148.namprd02.prod.outlook.com (2603:10b6:610:b3:cafe::ae) by CH0PR03CA0054.outlook.office365.com (2603:10b6:610:b3::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000148.mail.protection.outlook.com (10.167.244.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 19:44:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:01 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:01 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:43:59 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 01/14] iommufd: Keep IOCTL list in an alphabetical order Date: Fri, 3 Jan 2025 11:43:24 -0800 Message-ID: <32abff935ee97fb0be3f675a2a61b535492e242c.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000148:EE_|CY8PR12MB7562:EE_ X-MS-Office365-Filtering-Correlation-Id: 701f2ae2-4c0e-4dae-2893-08dd2c2efee6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: QBxeT1YwZldEPsieHoMpDtluaNNkDOUJERiOkvjAoULcPA85W0oyye8GWJpaK71EjjIS2QVG6SEF92sqmXWmvwgCYTktOzwl09PAXuuovtFWSZ8+x0VpJNfNs+Y64RPzGjJkxHv5XdnvaLklnwsfjqaP9WVTJkrDxRaaOjeW0+gv0XhDk4GpFKAjHMCvbPQbFhqD6D+pCOhHlnnYhzi+DJEyJuiaVkxYE+ZGw5jRfY0bsLT5nDE8Sa8kqTwykjLfA/bIkN6rFEucEeE2xiVLWnXKmo5/R4rAVfQgxEi3tLJkmrGPx3Dat5uSSqKO8Hii+zygOKVyPf6WHgdGFvggMUctpl48B+ZUkyTafTW1mDvvG13pzN0WW4AgD2i8NlQkeRiJrqc5sPpbZEGTZu2ntuwuJvyRdUrFNtg5gPE8L7qlBWOoYhOxq8vjInM0KOZJqm8Lzi4MYiVbgv1PllgOTnOkINJdAwUK9Dx+dKlaofTQeQjtBMC2ncm4DKDoOCcUsctRbByJmUvdnqo7ijKikrnKfgt/jndsbjhZb9Zv3ilmBw1DO0UuQm+Z3guUlpfi1NzB7mz1EwKqVzNtYu5cMjOTxRZkrmWob+5jNsNNCFO67FxD//l5lFaOThHRF76lgTQRIXDvFBMkrEd9pc8nu0jMFk4z4LiiVRIlrfL3YOFRKndH8LNzrJe0ku7zZL6vOOgrpOYVfqC9NwPLqGfPHP98YYcNYMSq6XnfalURbOJRS+0DbkdOIe58tjTfQh03JOjzuJukCHxxqf0/oOoZi6u23MT6n3ReCNRiqB4JUkIrtG6j+cnCT4E6VDlss1VFO1iMsYXEi7mfC+GjFtAC8fPVYzDGKJ0gn6qiLs5MvXN6/NLWLGK8JvFwx/QgtCDVUpO97uj3S6lwtketo01yvkwZ9YWYmaQsCP2X7s8KOs59ZhIsS7pR3Z6aAnnrCC42NFW4yCuBKUAfsl9vX9T3eyNDCICEWAnfiUFK1qMYujP1CgAa4HsEuXbZyxxhVMe/6Donf+OTBDjPOX6sM20FyhPL6H7VdtkFXBJyWGETm6P+H8thaC4IvgmQGZifajpLLhuIH4JEjJP/ztSELW7Lf3y8f+43p4NQoglGuag/euQrlyewUKCMnXnf9jwfnwfQzL/+VDdbnLHUTGyoD88GDEo2irGK3sM+rXtAQmPPHTHkjJaQvr6XnTZ31cTCFHY0wcgA6IxaA04iUkGkG0YQFVvsl2Vt9BhZiN+qGgU1mjn1oKFTFcB6PzxTdI1Om5v4bYNdUDFlO1H/aAQAEnkX6ekiGUDM3frBhnUzxfNHPc8QvH3sfi+R0cRFj4l3m6gx5sx+mnpdA3YB/S7IorsBSQfQ99YeAmaP1rNFTLrLyZw28pZymZjT3ro8tGSgDgVBVEvy5RClxorPEbCHd6+IjtsRrl8t92h54/NZcC7TlJM3eKfwdD5FPSQ1q86l1nZR/iSCzrF5ZlmMkqhhcd5k/GU80wANS/WbmHa6t2dluxE= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:11.1842 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 701f2ae2-4c0e-4dae-2893-08dd2c2efee6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000148.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7562 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114426_877106_BB92C22F X-CRM114-Status: GOOD ( 10.05 ) 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 Move VDEVICE upward to keep the order. Also run clang-format for the same coding style at line wrappings. No functional change. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/main.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 97c5e3567d33..49be19305d98 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -307,9 +307,9 @@ union ucmd_buffer { struct iommu_ioas_map map; struct iommu_ioas_unmap unmap; struct iommu_option option; + struct iommu_vdevice_alloc vdev; struct iommu_vfio_ioas vfio_ioas; struct iommu_viommu_alloc viommu; - struct iommu_vdevice_alloc vdev; #ifdef CONFIG_IOMMUFD_TEST struct iommu_test_cmd test; #endif @@ -333,8 +333,8 @@ struct iommufd_ioctl_op { } static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { IOCTL_OP(IOMMU_DESTROY, iommufd_destroy, struct iommu_destroy, id), - IOCTL_OP(IOMMU_FAULT_QUEUE_ALLOC, iommufd_fault_alloc, struct iommu_fault_alloc, - out_fault_fd), + IOCTL_OP(IOMMU_FAULT_QUEUE_ALLOC, iommufd_fault_alloc, + struct iommu_fault_alloc, out_fault_fd), IOCTL_OP(IOMMU_GET_HW_INFO, iommufd_get_hw_info, struct iommu_hw_info, __reserved), IOCTL_OP(IOMMU_HWPT_ALLOC, iommufd_hwpt_alloc, struct iommu_hwpt_alloc, @@ -355,20 +355,18 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { src_iova), IOCTL_OP(IOMMU_IOAS_IOVA_RANGES, iommufd_ioas_iova_ranges, struct iommu_ioas_iova_ranges, out_iova_alignment), - IOCTL_OP(IOMMU_IOAS_MAP, iommufd_ioas_map, struct iommu_ioas_map, - iova), + IOCTL_OP(IOMMU_IOAS_MAP, iommufd_ioas_map, struct iommu_ioas_map, iova), IOCTL_OP(IOMMU_IOAS_MAP_FILE, iommufd_ioas_map_file, struct iommu_ioas_map_file, iova), IOCTL_OP(IOMMU_IOAS_UNMAP, iommufd_ioas_unmap, struct iommu_ioas_unmap, length), - IOCTL_OP(IOMMU_OPTION, iommufd_option, struct iommu_option, - val64), + IOCTL_OP(IOMMU_OPTION, iommufd_option, struct iommu_option, val64), + IOCTL_OP(IOMMU_VDEVICE_ALLOC, iommufd_vdevice_alloc_ioctl, + struct iommu_vdevice_alloc, virt_id), IOCTL_OP(IOMMU_VFIO_IOAS, iommufd_vfio_ioas, struct iommu_vfio_ioas, __reserved), IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, struct iommu_viommu_alloc, out_viommu_id), - IOCTL_OP(IOMMU_VDEVICE_ALLOC, iommufd_vdevice_alloc_ioctl, - struct iommu_vdevice_alloc, virt_id), #ifdef CONFIG_IOMMUFD_TEST IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last), #endif From patchwork Fri Jan 3 19:43:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925850 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 22306E77188 for ; Fri, 3 Jan 2025 19:49:32 +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=BSzLz/NB8iZRVakyD8hxE+7xE/j2B7OiQveGEuYl71E=; b=NOYCehxyCBjLI6u3MTDVEmH5Gl BghCOl08UUpuCFUYawCY3O/lW0Sr6Wlk9zz7F0cYJ41tlClLTylti1jeeTjho3CwnTzadCAyfHKiO Rpe/s+1ib67ri/V1JsT+6QtRbi9XmoxENYJzd27kxkTsCw4XhQc3pfaxaqn7IcfNSjJ2aPUkv7wcB nbQH5Nds+Eh6lhQTaR5nLAfcSddcZ8DOSxLUKK52VhuG0p3831Zp74U1fbUaAbmw44UkyMAy/Hd0y mnugb0Hdw6VL1cSa4VZcZIj7MxTcxV8yuN60LSFjPRqAG5WLBsMpbOwgDXXeXGcwh+ZBJod6Pw9nx m1jv7CvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnfb-0000000DsNm-3J3R; Fri, 03 Jan 2025 19:49:19 +0000 Received: from mail-co1nam11on20627.outbound.protection.outlook.com ([2a01:111:f403:2416::627] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnb5-0000000DqV5-25Bg for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jb3/fy+1hD67pdHD1ToRkzVoDgd1BxKTlVzi07bdjujsRe08yP9Z5pjmDXxwekwyeRTCTrJtSkWNrA7l6QgjAsL4eqRB3RRAI4xAGyFMpgWeA0IZfVrf9o6Y3plRPWDIt8daCGA73l2+p/m7skGXkPH14k+k04tpfQVUUKyczsaBlux9aT9g8c5tcBlQoQBkHMfYUOoVwe/1l8HYDmFopQx9JkuaAvM13ukbo+hGyQ5j5MY2mlZRyTcldI6AQbmWnHPD8hN/scFAd1mpnSFIHfkEfVNzfNzR43Lid0htZOB6LCdt1NDTS6U4a4w0UKLu4tA+hPUq90mGMSaPFQdT/A== 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=BSzLz/NB8iZRVakyD8hxE+7xE/j2B7OiQveGEuYl71E=; b=bXIL017CHYM6IcvBxqN5tiYeOttQGFs6brajKJ+DZxYArRlAg+Ovu5Va8G+E0ksAAQ4aLpknMPK2I7CRq+F4lqYOoRAlcZnMNnKHLDGEdYsdQpuaVAF/LSsEavMcqyNfAXE0oRZax5l0Dn33EPaTFNYsHAzdszHTufn5VFSqdpUDgvcvXZ4lkBB8S5EsUJfIuQ1k5y8higSf3AB/+8gR8MlUkbsuAMQICdV1YXc2i1HiBpNzsy+0jIwciO4v8aU9tpFTrWzuxH3TFTZH0lgp5e0XnMfCaDRlVl08oR7Czsd6Hg5Je4Zvi4UAYcdmlpwKsdkJdY8DazeQpJ652ZRTCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=BSzLz/NB8iZRVakyD8hxE+7xE/j2B7OiQveGEuYl71E=; b=ZbtIBhi+FDHavAOk7vrwGc5ii+9mPZCq9CsZU5g3slbHqxb2bstLdV+nlKstBE1XvqIMb4bJT02lUxnCY+hTtZk6h5RjiLa72B1m3caHYiZcQu5tCa9xllZBiWptNzBmfFgfsvr3yw1IfxZGX+e2+nadjwEQBDbxYgwIgR/UlznLuON9dEeU7sKq2lzk9xeRmHm8HGylyIWIyBglu0W+NPCK27bvzHIcmsdneFrmQm8McAtwqA5xMiJrg4UKqBNko/vgt8yc4rx/oAJP1QfnRRCwyuBAo8yAKjD9Fxzkkb7zTWR7esQAYrhxTRCUZEnvw2z4FDBqNyp+uTJm66b/pA== Received: from BN6PR17CA0046.namprd17.prod.outlook.com (2603:10b6:405:75::35) by IA0PR12MB8839.namprd12.prod.outlook.com (2603:10b6:208:493::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.14; Fri, 3 Jan 2025 19:44:23 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::e4) by BN6PR17CA0046.outlook.office365.com (2603:10b6:405:75::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8293.15 via Frontend Transport; Fri, 3 Jan 2025 19:44:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:22 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:04 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:04 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:01 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 02/14] iommufd/fault: Add an iommufd_fault_init() helper Date: Fri, 3 Jan 2025 11:43:25 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|IA0PR12MB8839:EE_ X-MS-Office365-Filtering-Correlation-Id: 51b44f74-e94e-4f6b-92bc-08dd2c2f05da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: kUsqUrljVugUPui8ChmRUxNTd9w6FDwewGveKcRhoEAiKaQB84SShfAyy0qWGIgoJURa/GkpXycl4HsmsYi6w5ySUgs834JLonH0UMduluOAGD/YZPJEWj5Ri5mWE02+sbDD+k67eEn315qQqEac2SZCiZIZxRduQBB0H4iV8cuLWgH3iBvbqtJKcBc9HqqtmfxUjP7k/dUf5eHjCaTnnjjAxLLQoyysE+MlebTH2s/1kr+80iQ+KBIqbaDBKOUsu3VPh9bzfGivhnXp/1C5Lhy96XIFZRkW5IyzsIoYLQFpJ9x72DD31YInodByT3rkkg3kaJe7du7zil7Uwd9GxJExTE0f2T8YSjacMGvW+lNSphP4PYe19kq7dghHxgAmt2VLC56P4576jSunl7mlY8xI1fxgV6d7bTH/AFbhvokrFOGDxuiZWUH6G/lKdmjWp/MlDAtEBQG0QFa/9KO0YyTZl0IA3IBU/7hi/+CYZ3p6+eBE6wuqu2bIYJll0lM2PIizR0Do7O3kpK3ORYY1agvPFhQOGbcCfP4JFWQAyqi2UwKc9SnsdT0Dvqe6AsS01bYVAUm4IDjTsz3NnppB8o4UFXqiW/MQAntzZsDvVP2kwrlqNrligyraUbbHvGFF5wyM/zfhzikVf9aBeV5G+u7HPX2rsNcfizVIkzu0QewcgKlKZSrq91hXLK7ojIWTj7weCoF1HMhUoyancVUwpV6vUzg2MEuSB/C2d0u/CuTeHeDUiYqc1YiEaFVXVJ4As4UtnpVJkLwv9nCkrUnVAmwYf92KvUPxWa/0sCxpz0DqdgqMeq5y7kn6+DDP3r+w4EFzH4tR1hlYCHjfuVrSM8/2c/PP5Kkaz3QOOZNCVE0PKnbJc924IfVo7PTim+urEj5CDfUEMIGAdC8nE6omk3NEvFhq59m6MYvioaE5KapkdDZHxmBZWQMWVizcwoteVNHkhlnr84+83yOp8wWz8uoPa1mLNYiH6BO2Ogg+gVN6pB0BHj974bwmU2Gh+rSa2BpyLZo4Ni5RiwVNFBrdlT1lQWM4oeGV0OR+N94B7pGUtdUXRAF4bO3nDoN37Dj7ctntOPq6oDY8FCHhns5+5mPsuIBEL0BiiW951Q1gRbcYIRbL5D2fGbhR8RLSOyu+GFA/eNBEqmVxdezTWmy1oGyjpQHaBYbGS6BgvklGtGgdOLAFpzsre3AFQCztikFhQg88k3n4yREn51ExWF4veAJTkUHgVaH7VwObplwgCvGJSOPDyKfg+6rHkxMA1jWK6Z7IdTiAl4+EGBnrYXDYpxEQXI/+53rI4YVFD8Hp7nizqdcxQ9p0hFu1v1Nf48CAPD8IwwV5zkCrMmwCbhWQcoedcsf2IE3FvJtCFkD6eo/BItTvS0pZrMso6AtpxIdHPcmPAJvhx28VCgq0ks0GFG4MkQN1I9mmpYamgvQ4YLo5LDqX2pB6jh0UDvYmKgyswPER7oT8RZI6kcuEo3rtuNO2aXML7KJvLm/7Y/TicmY= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:22.7899 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 51b44f74-e94e-4f6b-92bc-08dd2c2f05da X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114439_537903_46E8100A X-CRM114-Status: GOOD ( 15.30 ) 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 The infrastructure of a fault object will be shared with a new vEVENTQ object in a following change. Add a helper for a vEVENTQ allocator to call it too. Reorder the iommufd_ctx_get and refcount_inc, to keep them symmetrical with the iommufd_fault_fops_release(). Since the new vEVENTQ doesn't need "response", leave the xa_init_flags in its original location. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/fault.c | 48 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 1fe804e28a86..1d1095fc8224 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -367,11 +367,35 @@ static const struct file_operations iommufd_fault_fops = { .release = iommufd_fault_fops_release, }; +static int iommufd_fault_init(struct iommufd_fault *fault, char *name, + struct iommufd_ctx *ictx) +{ + struct file *filep; + int fdno; + + mutex_init(&fault->mutex); + INIT_LIST_HEAD(&fault->deliver); + init_waitqueue_head(&fault->wait_queue); + + filep = anon_inode_getfile(name, &iommufd_fault_fops, fault, O_RDWR); + if (IS_ERR(filep)) + return PTR_ERR(filep); + + fault->ictx = ictx; + iommufd_ctx_get(fault->ictx); + fault->filep = filep; + refcount_inc(&fault->obj.users); + + fdno = get_unused_fd_flags(O_CLOEXEC); + if (fdno < 0) + fput(filep); + return fdno; +} + int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) { struct iommu_fault_alloc *cmd = ucmd->cmd; struct iommufd_fault *fault; - struct file *filep; int fdno; int rc; @@ -382,27 +406,12 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) if (IS_ERR(fault)) return PTR_ERR(fault); - fault->ictx = ucmd->ictx; - INIT_LIST_HEAD(&fault->deliver); xa_init_flags(&fault->response, XA_FLAGS_ALLOC1); - mutex_init(&fault->mutex); - init_waitqueue_head(&fault->wait_queue); - - filep = anon_inode_getfile("[iommufd-pgfault]", &iommufd_fault_fops, - fault, O_RDWR); - if (IS_ERR(filep)) { - rc = PTR_ERR(filep); - goto out_abort; - } - refcount_inc(&fault->obj.users); - iommufd_ctx_get(fault->ictx); - fault->filep = filep; - - fdno = get_unused_fd_flags(O_CLOEXEC); + fdno = iommufd_fault_init(fault, "[iommufd-pgfault]", ucmd->ictx); if (fdno < 0) { rc = fdno; - goto out_fput; + goto out_abort; } cmd->out_fault_id = fault->obj.id; @@ -418,8 +427,7 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) return 0; out_put_fdno: put_unused_fd(fdno); -out_fput: - fput(filep); + fput(fault->filep); out_abort: iommufd_object_abort_and_destroy(ucmd->ictx, &fault->obj); From patchwork Fri Jan 3 19:43:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925851 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 1C3FEE77188 for ; Fri, 3 Jan 2025 19:50:42 +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=k+LZ9DTi+hXK1XNyDsq/ydPO+gFKzeDHi5j6GDyNjCw=; b=JSum1drrMIZkzNz6TXpqRx3oYk 4DnnXc6HNzQNg/yZUb7JkG8PnxFvB9iw/K7ochGi7SRRb+f2yHakRlVJJUVE4rGxZ+7s633rpDJ27 UoKrbBLhKLre9H/p09+/HGQHxgK1NmpxbaUU1jei+k2bfcOMR2PcF7ESJJFzqbj+aDiPgI7KXX214 mCXIZHTGJz8EdCPVQwh4qdeBB0BczY59Q+PqN+fYtQWywXGkk1SxNmVftWDEjsRTfgKNvof2zBvRa ndh1caapW6nDzsnUj+Yz5te5Ms26gzFNQjE729QLnKKpChafde8O265bozXYd6BQe6mKTC6pmSoZG l1pfb30A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTngm-0000000DsUf-1qGY; Fri, 03 Jan 2025 19:50:32 +0000 Received: from mail-co1nam11on20627.outbound.protection.outlook.com ([2a01:111:f403:2416::627] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnb7-0000000DqV5-109v for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ezUkuroa2j01/QiF2j+m+39wMS7loOovUyysuMtkS4bHUGdRCFXRA6mdfP/EVkuKfT/53TNNxcRpuR0mSdet1ou5wq/nS8E1gAzP7QojCkpkHAswi/FTR3PS0ITyWY9nr6pt6wk0Bw8RRLkZKhdM7VSIIUatkfEikoIIW9GMc95kGW/YXMfkurFCJwGxnv150LY4jJyDNFNUkM/yhJbDtp5SygviSk6ICrtScDgTgIc7pUX3BS+dDk6VBXZ/A8Xd+Psz3hitILbZmyBOqRs6rjF7eO0vPqGmtyRhfHC3UfL0HTGcTjRJRGv7t+p2rCn/iNqKIM4AYbhO8xXM/sBFJg== 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=k+LZ9DTi+hXK1XNyDsq/ydPO+gFKzeDHi5j6GDyNjCw=; b=YM8sbYtquyiKOL2nf5ytzcBImNdtdWwtQNFkRKTDL6JmkNBbgF/VPZS2B/8j3MRCl1GTG1ilgvL+wW2uYPiKU49hBbp4bDuA62iGrMhjk0EB4Za0qVlN/M6OGDYx6lFPZ6SPvQQ49AuSsDEuQkrIZELbNkKtAztz3aQsvW2xrzI0pjcc57mjosB5LdRsqEOZZCRDztE6q/Qy+BM20dkcF6NRh9/pGQs1sQl39LsgvhhyGB4QTChMJW39Xk4sECowELJ+QKL5u3ANf6iLtejzYX5TG2I6qj18fgEYjxv41ZtOb7mI/6qbvIlmFOV0UkGHkDxXg/LO5HtmMINdZDis8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=k+LZ9DTi+hXK1XNyDsq/ydPO+gFKzeDHi5j6GDyNjCw=; b=Ts/nmwc0k+pM0leG+Z8FHsaGEjaT7cEInT+xHxpKDAhlYnEZN5lbH6TSzNfx6bYwtfycioDaeSaFIcmJhl2YSRFgQM1E2FeDaw2bdo6daWnkDOQfL8LFGeRZeUM7nOUDn13Vn/51bu1ZL3MF3oxqwe0VqhDNwDEORZC3LQdDeM8/L1CmlSwGGubPh23RXydgIzoHbBB1IMhPb91F+1Y3I55WoyS5xW7I9z48b93UDFS5Hw1pmpaNj2zVJlgPTpK3m/HNQf/QGRCIYRF+Yoq2f2hTa0YR1jPIwkErIFfaEX8kPoeyy3y7xdnouZlbGR9G5DvzW0XxUzVvlG5fLCp3yQ== Received: from BLAPR03CA0092.namprd03.prod.outlook.com (2603:10b6:208:32a::7) by IA0PR12MB8839.namprd12.prod.outlook.com (2603:10b6:208:493::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.14; Fri, 3 Jan 2025 19:44:24 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:32a:cafe::13) by BLAPR03CA0092.outlook.office365.com (2603:10b6:208:32a::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06B.mail.protection.outlook.com (10.167.243.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:24 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:07 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:06 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:04 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 03/14] iommufd/fault: Move iommufd_fault_iopf_handler() to header Date: Fri, 3 Jan 2025 11:43:26 -0800 Message-ID: <92a5599bddd915c049fabf4832ec8b0f0c1471c6.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06B:EE_|IA0PR12MB8839:EE_ X-MS-Office365-Filtering-Correlation-Id: bef94e04-ee1d-4c43-9cab-08dd2c2f06c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: cvZzrQsHTEAY6R/+m0Jf/OHC9iHMHXbCQyGn+4YOL1CFnjblCT5TpX25b/lUx0/4hKjOOA06XfZuRVL4v0E8qrTsx8Ov6NTASPDKqoQhnOaYquxI/6xWKAndinqf/kEcif0jjC9SuTFm6frVva/IqJ3fzau4rlUpyhSNXwUJItFv+YhEgT5BlH1jEQWm1eV3oYdQRQX8WsUMaHSBnxSHWYpp85BFuVRmJ+acXnsxMTFUoTXfqWYFGJwvRJHOs2OxWftrW8k/UpAvpY+NRcoQPdzw0Fjl6wJs9YPTakfcpx8A1tJilF4xWb2m5sesHXKXYrXuAOA6DGueanulV/5NnuCLRZ+UvtKt4XTzpaLkbKh/5jRo5163eC4EK6n/G8vt6BE4GJjOwzJMhVTBi6qrp2HgVXzVOR+wLgyZHRnbck0cMkP+kM/kx+SnjyW2YOPTPP69LgliBMJ4PcJM3lPzK1VCumor9I5xgDM1Yb7kBAplhm4tdUbhtNHQVsgtm8lWCV44xNmrEmS7a9FmK8+Wi8FhmOOhbRfdxbZ/iZGu0uYpLpNXqJYcGH2WADefQfK0gh9isRuZoRtd0UyxXaqQ/S7bH6CUIc7C+spVnN2BIQzEX35kiFyIxvJTR/VdBvcJ3g3nVZsrVSlntMam54JWnf0MlvNFRB6Vam1kQfsNTodEKi4Gk6PKPAFsG5pBjXl9y7+z2iAwGpBwCVMiXAz5hAc+82sBGx0jzaIAERgPmU8Wh+51RGcLZo/NtzjOE5Y1JiV/wQg8FQ4tf0F9uzTQd52gXkYKbKwWs+BHS2cyXOGdCcHuirKC6fePXEDNTRmYRrvMGTxTSGJuWJzGs4lT7Iis8Q2aF2XDkPqWO3y0HC38wzHu/GLIOQqLiFyFtT4d4Vk0O/k5LLCqmLxQ10uslZTgxqbmmzos0Vn5h+ktGc7tXRhbMuJr4HwTNj4o//gJpJ1HPX4fcbg1PBAmNVFIAQbjkVThl63uJThr9BC1vrn0WCawfuI7Bzl9hMiUujARiI9BS9rowmci5hsczCB6jiYChKgc8tb+3bKW42udl4NTL3au3AdC8YKcVZfX6aue9SKT76pd/4u2/WNE5hUTm0ClJQiFPiAK9hd94tiNQvui5c/Ve/Glpdg16L80wz41cQRlM/BSPuJVN2YkxHkkEQWoYCm3JZPRpdl+gK1r7GIXGYgOrMj/17EVkfaWzyNLfx4kAGAa5ATJEi8I4otu1ofvvgIjMORd41jlNZOWu81TxZw/89c+E+SvUhMj80Ymeudl7j5QpTqWWsnA8qCf3r6qrHOWQ1TVkcKSwPvcK7oZCnJ998LSt0v/djWNboYgzgzhqeWe/intiEkkXYMV4JUMXm0AjUMV3bx5gLTAkxvF//zE8LF/XlMf7xN/EdhmIdqEHOcJT4t7nSIE83q/xwaGJm1YWn1WosNj4KXjH/WdBSl4H2AhAG7H+9NychKTXprd/5ccivgxP0KaGWf3bnpvdB/RgoFpyF01i3WeFYE= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:24.3146 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bef94e04-ee1d-4c43-9cab-08dd2c2f06c5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06B.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114441_276261_2AEC36C9 X-CRM114-Status: GOOD ( 11.30 ) 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 The new vEVENTQ object will need a similar function for drivers to report the vIOMMU related events. Split the common part out to a smaller helper, and place it in the header so that CONFIG_IOMMUFD_DRIVER_CORE can include that in the driver.c file for drivers to use. Then keep iommufd_fault_iopf_handler() in the header too, since it's quite simple after all. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/iommufd_private.h | 20 +++++++++++++++++++- drivers/iommu/iommufd/fault.c | 17 ----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index b6d706cf2c66..8b378705ee71 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -451,6 +451,17 @@ struct iommufd_fault { struct wait_queue_head wait_queue; }; +static inline int iommufd_fault_notify(struct iommufd_fault *fault, + struct list_head *new_fault) +{ + mutex_lock(&fault->mutex); + list_add_tail(new_fault, &fault->deliver); + mutex_unlock(&fault->mutex); + + wake_up_interruptible(&fault->wait_queue); + return 0; +} + struct iommufd_attach_handle { struct iommu_attach_handle handle; struct iommufd_device *idev; @@ -469,7 +480,14 @@ iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) int iommufd_fault_alloc(struct iommufd_ucmd *ucmd); void iommufd_fault_destroy(struct iommufd_object *obj); -int iommufd_fault_iopf_handler(struct iopf_group *group); + +static inline int iommufd_fault_iopf_handler(struct iopf_group *group) +{ + struct iommufd_hw_pagetable *hwpt = + group->attach_handle->domain->fault_data; + + return iommufd_fault_notify(hwpt->fault, &group->node); +} int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev); diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 1d1095fc8224..d188994e4e84 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -433,20 +433,3 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) return rc; } - -int iommufd_fault_iopf_handler(struct iopf_group *group) -{ - struct iommufd_hw_pagetable *hwpt; - struct iommufd_fault *fault; - - hwpt = group->attach_handle->domain->fault_data; - fault = hwpt->fault; - - mutex_lock(&fault->mutex); - list_add_tail(&group->node, &fault->deliver); - mutex_unlock(&fault->mutex); - - wake_up_interruptible(&fault->wait_queue); - - return 0; -} From patchwork Fri Jan 3 19:43:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925857 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 9E86AE77188 for ; Fri, 3 Jan 2025 19:57: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: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=pVYRE0iFhLpLnxfdW4dHe6rIsP68BjSfNRzJMhKZKk8=; b=ObXaxMV0aJkJ2K6xXMcvsnXkXe OqR5EB6fq6WTg0elotpUGmHpOS9g1Vkrew6k8j8rD/FAYPkU1OkbTbZYZH/j4B4pGiwJxfW3fYXik zkA8KyBBjbanS218XipKlHmxG0TP+HnmZ4qjBjIxcKV1jgY8ThQTSw7EcPR1f4PmR32YJ+JZDbx+Y 6FmpqfTjPA2PXu+oyD/FI6xMKX5TynWw8b8Lga0PSDbL04ZjL3jQ0LxM/0MVFKV65RGxUfKyOO1uE 2ee5TZAMIEEYWfcAHGLWbZtdJdg4r64+JLmwKGdsX9cXrekaQN0Q2PgSw3LnvORWcBViJQIrWKqcR B1zsDUOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnnj-0000000DtAL-1aat; Fri, 03 Jan 2025 19:57:43 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbJ-0000000Dqd2-3YS2 for linux-arm-kernel@bombadil.infradead.org; Fri, 03 Jan 2025 19:44:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=pVYRE0iFhLpLnxfdW4dHe6rIsP68BjSfNRzJMhKZKk8=; b=hN7IpysLQQiYhw+FtJFJZCAd9/ coEhX4tB2TMuWY8Elf1toL3jYVsFdWhoP73lS4EC4TFnuO0U8I2b8IlW0ISvPriVIPH0gU6cI3NQJ kmcwS8FsybPYlm7qE84kP+MWs0kONO98WRJPxf6J+kzJkeqdz8kz5ajdNA5nqqRdCt23CBl5Jt+bu mcn3r5zvx05koRsIViTnN1XN1FFADmwIwgqM20yGHSfVgz2l+8YyMVKn02NRQoX15ShzgwP4jFrr4 ++lOStt4LTJT2xyHpYr42sNoyL6EgvxIF8IPKB1pxU1nl2iGNkhT2euMJDXakfevW/e0GRr8xNoas NqH/+udw==; Received: from mail-dm6nam10on20621.outbound.protection.outlook.com ([2a01:111:f403:2413::621] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbG-00000008RHG-2hD6 for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tLdbm8FzzDt0MkWsqo84ptWEQd2ux0myI5MbffxYc6MkaPKJ4Q6j/QI0Aou8mh5QixxpkqPUHL2o9KnbCWVQCf1bsTjUGN9u+QGGVP9I0yoG/BnMIDrV8f7PCskv0BusLvnJxog2YUNxzkG6ZyEGYepKPNYGu6w9bKp55DNE0McVv5wxX20k3UZw5cvDEj4fBz6ZDZO/63gEt+uwUhFLwqm0e21d4cmMkt75m2jNYPsNBOy6ct8Y7ECZRBI4GIVGu4oU712ENH5b6ZDXwTB0qBZFa59KT8wYYeeD5h9eXJsgjE9lTaPNo5ZlRN8dStvvcGGaayPbqKC2x7/qdB97dA== 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=pVYRE0iFhLpLnxfdW4dHe6rIsP68BjSfNRzJMhKZKk8=; b=pVVxazZpIu6pEdviiuOks5dv7yNaSY0Ba1W4K/hAwVbb1afoHcVScjedGYYpCh5ksUYtMGtVaUKzh51Q05exCLfJ7J/Doty/tW1rK4OQjCmD2HgCy+e6kMXHAh/kSjwvljZQz/BLpvtoU3jxHgFbsk4HFM7i8VSFqkw+cRz3O4FogDs/fxk0IBSxi+7xhTCXWtm/jDZGvk2p7k3UCwD+zyIuEFr54HuW4Ta7J4KGUO1Nwn04aCk6CjEjBoxwEZGy9ooJqvVy3Z83MKDxoq8pt8/QurbDZUxOohDGHNGufaO3JyIXD8jIlOQlo6bQoyeEs3Rmic6yzMXNfBZ3VP1yog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=pVYRE0iFhLpLnxfdW4dHe6rIsP68BjSfNRzJMhKZKk8=; b=HMOZCeIy5DSJr3yEYxBf39+jHle0MJr6j5ORlqda2LshZdRUa8vGcikUAOP9oPmX+T3IDKurAFLNYF0gdlR3sArFt/ousFXGXPRVAvUkcYPREXU2qb12TojeE331QtlHcTCsHBGUJdCnqteD2ZY9jep+JuhyxtvPy/Q4Y1nSfTJGcldLZ/X6nnaqUw7iK1PBt4cf3qATypJ602Otbut/JkcOaN/sXPkYLSFr37W2fUVaw9xgPy+L0yc7d1iCDMdEZNKHo4zSmwt3Stfp6I1bvaEoJ7UMVu9PfpkZvqpBfRMQNftPl1N/kfUUvRwqGdCTaWtSb+39RcWmEN+l7FdOLg== Received: from BN6PR17CA0028.namprd17.prod.outlook.com (2603:10b6:405:75::17) by DS0PR12MB8765.namprd12.prod.outlook.com (2603:10b6:8:14e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.11; Fri, 3 Jan 2025 19:44:26 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::bf) by BN6PR17CA0028.outlook.office365.com (2603:10b6:405:75::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.12 via Frontend Transport; Fri, 3 Jan 2025 19:44:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:26 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:09 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:09 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:07 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault Date: Fri, 3 Jan 2025 11:43:27 -0800 Message-ID: <5d4bf92ce7e64a1c424f1b89d1a78f20bc6d7557.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|DS0PR12MB8765:EE_ X-MS-Office365-Filtering-Correlation-Id: 906c4bd6-e684-4570-18e1-08dd2c2f07c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: rTG/xHxRmMiIrHRoayHAMMfca8mHeSGwei2JJIHx8n8zAM793/cYckRX0BPbmCm1h9XGd+rEavbi1GzqnaMUI4ETIcjsNBAtYMisoARyuaCyLBgqGZqwX/MaClzhCHCRYfx4GbHeIZr7Ntayzdxbu/46Y+VoHnfFkJuvE6oAs9jduJ8YfKxX8jchA8W1pSYYV4cVkCTbIhsSaOXQvbQ8MJjEGyElXePlZo3LSQULtS62r6i4Bvo4xbhChCJ/lgf+LqGQn96YeAVGbwMj23Y93WGDh27U77MbcAA8K0ql4qkRNM1OBvZUeQpEsjWqMA076l6CV6yhOj3fVSLcGT3wWDu62Jd6MpDlndBD96wnSTYXHa6lpkIHsjUjehQCp3nspcs+uEyURMcFfk3WOXlGF6Xy+AmPIRCMR7MLiOvvQinOsvlCEtWysyFDSus9ytpyNTRk3HGJBreZ8BXHActNGlCmWrU6QzKfYlA7GhW0+clcatARDIwLnWFz4+UPLePXemxmjVvqKO+nZxEIFdYe1qF30BrlfUs2KmS4gmInRpeyG3xqrxUE4wYL5Jh9jbo+XFbyLChO8q1OcTeUT1lsOETCvuEEa6bbgCX4ujbE2YSIv8sL9k2g/TGLYqWLRfrJuYUPdMRzTMqBT6cOUZy7CG/ET/XvciRsYteU5MIfzvi/laxiqmxR7E4Yo7ElAOsivqM2HfAESw66UjYPYJaF2AlrmUMrMmVzmj+ftvYJHp6+g4/RISXffcQd4P8elSIS6hK0c14+HJdJObp6f/gS/aTfMY7nGBArfanY7Saz7vqRLbGQ2SNfPrtg3H6dSdHhsiAOJNeRY/xaG403iqVM/2KoBJ46R46JZ/3ATryUtwJf2/16OmlagGSTN6V/r1e2Ll8vAfoNZnHR0/6Oub35yh5CsFo4J6XJLmwlgaQYQQ1djQjbgnlY/qViwhezAEt9F602blCSbkJ77aJgFFuXcksVxFtFwVLU0i5JRITccPmH9a33yWkRcabmfKeXV+HLb20U5Aiq6BUCiOcaS0vBHjSjLwLKR6i2mR9NyygPupeFkTaf4luljFIBp99SxsL3gcM0eYOzXlt297zNJlUgSs0tCVVoaAiQrgoazYOWKGV7AqIke1a2emRRARP9yx4bbPFYKZHB9TW6OBtliUQTMf7LvUs7bU1TMhU/4enOKgo9BNK3ItzG6F2h9PUXEPLZaYByzSvyIKfWYItx7zWUZe0B6ytBEWQGWxl94q9WNVQmU02lfo6yS+mkWYcwbUcGDlnBoKfr3uV65yIv0qsMa9X+lAaW80Ey7OhKo7JBP1Xvb0ucmw7x5Rute04s1t2i7RrGpr8k7lfIhmsTV0xkru/yK3MnDjWJGYrRSxtCeL5Hy4XLmCictxjQIy6k00lLbiVFbd1OFRlu5U98aOid9dTjoQzdhQk2TOkyio+66hqybMVqmr3/VVwHafQe7akKhmVQpw6dCfb8HAAyA7JNZVmEfXztl16G/yMO12Qx73g= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:26.0086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 906c4bd6-e684-4570-18e1-08dd2c2f07c8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8765 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_194451_048214_BF737791 X-CRM114-Status: GOOD ( 18.58 ) 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 The fault object was designed exclusively for hwpt's IO page faults (PRI). But its queue implementation can be reused for other purposes too, such as hardware IRQ and event injections to user space. Meanwhile, a fault object holds a list of faults. So it's more accurate to call it a "fault queue". Combining the reusing idea above, abstract a new iommufd_eventq as a common structure embedded into struct iommufd_fault, similar to hwpt_paging holding a common hwpt. Add a common iommufd_eventq_ops and iommufd_eventq_init to prepare for an IOMMUFD_OBJ_VEVENTQ (vIOMMU Event Queue). Also, add missing xa_destroy and mutex_destroy in iommufd_fault_destroy(). Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/iommufd_private.h | 52 ++++++--- drivers/iommu/iommufd/fault.c | 142 +++++++++++++++--------- drivers/iommu/iommufd/hw_pagetable.c | 6 +- 3 files changed, 130 insertions(+), 70 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 8b378705ee71..dfbc5cfbd164 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -18,6 +18,7 @@ struct iommu_domain; struct iommu_group; struct iommu_option; struct iommufd_device; +struct iommufd_eventq; struct iommufd_ctx { struct file *file; @@ -433,32 +434,35 @@ void iopt_remove_access(struct io_pagetable *iopt, u32 iopt_access_list_id); void iommufd_access_destroy_object(struct iommufd_object *obj); -/* - * An iommufd_fault object represents an interface to deliver I/O page faults - * to the user space. These objects are created/destroyed by the user space and - * associated with hardware page table objects during page-table allocation. - */ -struct iommufd_fault { +struct iommufd_eventq_ops { + ssize_t (*read)(struct iommufd_eventq *eventq, char __user *buf, + size_t count, loff_t *ppos); /* Mandatory op */ + ssize_t (*write)(struct iommufd_eventq *eventq, const char __user *buf, + size_t count, loff_t *ppos); /* Optional op */ +}; + +struct iommufd_eventq { struct iommufd_object obj; struct iommufd_ctx *ictx; struct file *filep; - /* The lists of outstanding faults protected by below mutex. */ + const struct iommufd_eventq_ops *ops; + + /* The lists of outstanding events protected by below mutex. */ struct mutex mutex; struct list_head deliver; - struct xarray response; struct wait_queue_head wait_queue; }; -static inline int iommufd_fault_notify(struct iommufd_fault *fault, - struct list_head *new_fault) +static inline int iommufd_eventq_notify(struct iommufd_eventq *eventq, + struct list_head *new_event) { - mutex_lock(&fault->mutex); - list_add_tail(new_fault, &fault->deliver); - mutex_unlock(&fault->mutex); + mutex_lock(&eventq->mutex); + list_add_tail(new_event, &eventq->deliver); + mutex_unlock(&eventq->mutex); - wake_up_interruptible(&fault->wait_queue); + wake_up_interruptible(&eventq->wait_queue); return 0; } @@ -470,12 +474,28 @@ struct iommufd_attach_handle { /* Convert an iommu attach handle to iommufd handle. */ #define to_iommufd_handle(hdl) container_of(hdl, struct iommufd_attach_handle, handle) +/* + * An iommufd_fault object represents an interface to deliver I/O page faults + * to the user space. These objects are created/destroyed by the user space and + * associated with hardware page table objects during page-table allocation. + */ +struct iommufd_fault { + struct iommufd_eventq common; + struct xarray response; +}; + +static inline struct iommufd_fault * +eventq_to_fault(struct iommufd_eventq *eventq) +{ + return container_of(eventq, struct iommufd_fault, common); +} + static inline struct iommufd_fault * iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) { return container_of(iommufd_get_object(ucmd->ictx, id, IOMMUFD_OBJ_FAULT), - struct iommufd_fault, obj); + struct iommufd_fault, common.obj); } int iommufd_fault_alloc(struct iommufd_ucmd *ucmd); @@ -486,7 +506,7 @@ static inline int iommufd_fault_iopf_handler(struct iopf_group *group) struct iommufd_hw_pagetable *hwpt = group->attach_handle->domain->fault_data; - return iommufd_fault_notify(hwpt->fault, &group->node); + return iommufd_eventq_notify(&hwpt->fault->common, &group->node); } int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index d188994e4e84..e386b6c3e6ab 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -17,6 +17,8 @@ #include "../iommu-priv.h" #include "iommufd_private.h" +/* IOMMUFD_OBJ_FAULT Functions */ + static int iommufd_fault_iopf_enable(struct iommufd_device *idev) { struct device *dev = idev->dev; @@ -108,8 +110,8 @@ static void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, if (!fault) return; - mutex_lock(&fault->mutex); - list_for_each_entry_safe(group, next, &fault->deliver, node) { + mutex_lock(&fault->common.mutex); + list_for_each_entry_safe(group, next, &fault->common.deliver, node) { if (group->attach_handle != &handle->handle) continue; list_del(&group->node); @@ -124,7 +126,7 @@ static void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, iopf_group_response(group, IOMMU_PAGE_RESP_INVALID); iopf_free_group(group); } - mutex_unlock(&fault->mutex); + mutex_unlock(&fault->common.mutex); } static struct iommufd_attach_handle * @@ -211,7 +213,8 @@ int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, void iommufd_fault_destroy(struct iommufd_object *obj) { - struct iommufd_fault *fault = container_of(obj, struct iommufd_fault, obj); + struct iommufd_eventq *eventq = + container_of(obj, struct iommufd_eventq, obj); struct iopf_group *group, *next; /* @@ -220,11 +223,13 @@ void iommufd_fault_destroy(struct iommufd_object *obj) * accessing this pointer. Therefore, acquiring the mutex here * is unnecessary. */ - list_for_each_entry_safe(group, next, &fault->deliver, node) { + list_for_each_entry_safe(group, next, &eventq->deliver, node) { list_del(&group->node); iopf_group_response(group, IOMMU_PAGE_RESP_INVALID); iopf_free_group(group); } + xa_destroy(&eventq_to_fault(eventq)->response); + mutex_destroy(&eventq->mutex); } static void iommufd_compose_fault_message(struct iommu_fault *fault, @@ -242,11 +247,12 @@ static void iommufd_compose_fault_message(struct iommu_fault *fault, hwpt_fault->cookie = cookie; } -static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, - size_t count, loff_t *ppos) +static ssize_t iommufd_fault_fops_read(struct iommufd_eventq *eventq, + char __user *buf, size_t count, + loff_t *ppos) { size_t fault_size = sizeof(struct iommu_hwpt_pgfault); - struct iommufd_fault *fault = filep->private_data; + struct iommufd_fault *fault = eventq_to_fault(eventq); struct iommu_hwpt_pgfault data; struct iommufd_device *idev; struct iopf_group *group; @@ -257,10 +263,10 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, if (*ppos || count % fault_size) return -ESPIPE; - mutex_lock(&fault->mutex); - while (!list_empty(&fault->deliver) && count > done) { - group = list_first_entry(&fault->deliver, - struct iopf_group, node); + mutex_lock(&eventq->mutex); + while (!list_empty(&eventq->deliver) && count > done) { + group = list_first_entry(&eventq->deliver, struct iopf_group, + node); if (group->fault_count * fault_size > count - done) break; @@ -285,16 +291,17 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, list_del(&group->node); } - mutex_unlock(&fault->mutex); + mutex_unlock(&eventq->mutex); return done == 0 ? rc : done; } -static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *buf, - size_t count, loff_t *ppos) +static ssize_t iommufd_fault_fops_write(struct iommufd_eventq *eventq, + const char __user *buf, size_t count, + loff_t *ppos) { size_t response_size = sizeof(struct iommu_hwpt_page_response); - struct iommufd_fault *fault = filep->private_data; + struct iommufd_fault *fault = eventq_to_fault(eventq); struct iommu_hwpt_page_response response; struct iopf_group *group; size_t done = 0; @@ -303,7 +310,7 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *b if (*ppos || count % response_size) return -ESPIPE; - mutex_lock(&fault->mutex); + mutex_lock(&eventq->mutex); while (count > done) { rc = copy_from_user(&response, buf + done, response_size); if (rc) @@ -329,62 +336,93 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *b iopf_free_group(group); done += response_size; } - mutex_unlock(&fault->mutex); + mutex_unlock(&eventq->mutex); return done == 0 ? rc : done; } -static __poll_t iommufd_fault_fops_poll(struct file *filep, - struct poll_table_struct *wait) +static const struct iommufd_eventq_ops iommufd_fault_ops = { + .read = &iommufd_fault_fops_read, + .write = &iommufd_fault_fops_write, +}; + +/* Common Event Queue Functions */ + +static ssize_t iommufd_eventq_fops_read(struct file *filep, char __user *buf, + size_t count, loff_t *ppos) { - struct iommufd_fault *fault = filep->private_data; + struct iommufd_eventq *eventq = filep->private_data; + + return eventq->ops->read(eventq, buf, count, ppos); +} + +static ssize_t iommufd_eventq_fops_write(struct file *filep, + const char __user *buf, size_t count, + loff_t *ppos) +{ + struct iommufd_eventq *eventq = filep->private_data; + + if (!eventq->ops->write) + return -EOPNOTSUPP; + return eventq->ops->write(eventq, buf, count, ppos); +} + +static __poll_t iommufd_eventq_fops_poll(struct file *filep, + struct poll_table_struct *wait) +{ + struct iommufd_eventq *eventq = filep->private_data; __poll_t pollflags = EPOLLOUT; - poll_wait(filep, &fault->wait_queue, wait); - mutex_lock(&fault->mutex); - if (!list_empty(&fault->deliver)) + poll_wait(filep, &eventq->wait_queue, wait); + mutex_lock(&eventq->mutex); + if (!list_empty(&eventq->deliver)) pollflags |= EPOLLIN | EPOLLRDNORM; - mutex_unlock(&fault->mutex); + mutex_unlock(&eventq->mutex); return pollflags; } -static int iommufd_fault_fops_release(struct inode *inode, struct file *filep) +static int iommufd_eventq_fops_release(struct inode *inode, struct file *filep) { - struct iommufd_fault *fault = filep->private_data; + struct iommufd_eventq *eventq = filep->private_data; - refcount_dec(&fault->obj.users); - iommufd_ctx_put(fault->ictx); + refcount_dec(&eventq->obj.users); + iommufd_ctx_put(eventq->ictx); return 0; } -static const struct file_operations iommufd_fault_fops = { +static const struct file_operations iommufd_eventq_fops = { .owner = THIS_MODULE, .open = nonseekable_open, - .read = iommufd_fault_fops_read, - .write = iommufd_fault_fops_write, - .poll = iommufd_fault_fops_poll, - .release = iommufd_fault_fops_release, + .read = iommufd_eventq_fops_read, + .write = iommufd_eventq_fops_write, + .poll = iommufd_eventq_fops_poll, + .release = iommufd_eventq_fops_release, }; -static int iommufd_fault_init(struct iommufd_fault *fault, char *name, - struct iommufd_ctx *ictx) +static int iommufd_eventq_init(struct iommufd_eventq *eventq, char *name, + struct iommufd_ctx *ictx, + const struct iommufd_eventq_ops *ops) { struct file *filep; int fdno; - mutex_init(&fault->mutex); - INIT_LIST_HEAD(&fault->deliver); - init_waitqueue_head(&fault->wait_queue); + if (WARN_ON_ONCE(!ops || !ops->read)) + return -EINVAL; + + mutex_init(&eventq->mutex); + INIT_LIST_HEAD(&eventq->deliver); + init_waitqueue_head(&eventq->wait_queue); - filep = anon_inode_getfile(name, &iommufd_fault_fops, fault, O_RDWR); + filep = anon_inode_getfile(name, &iommufd_eventq_fops, eventq, O_RDWR); if (IS_ERR(filep)) return PTR_ERR(filep); - fault->ictx = ictx; - iommufd_ctx_get(fault->ictx); - fault->filep = filep; - refcount_inc(&fault->obj.users); + eventq->ops = ops; + eventq->ictx = ictx; + iommufd_ctx_get(eventq->ictx); + refcount_inc(&eventq->obj.users); + eventq->filep = filep; fdno = get_unused_fd_flags(O_CLOEXEC); if (fdno < 0) @@ -402,34 +440,36 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) if (cmd->flags) return -EOPNOTSUPP; - fault = iommufd_object_alloc(ucmd->ictx, fault, IOMMUFD_OBJ_FAULT); + fault = __iommufd_object_alloc(ucmd->ictx, fault, IOMMUFD_OBJ_FAULT, + common.obj); if (IS_ERR(fault)) return PTR_ERR(fault); xa_init_flags(&fault->response, XA_FLAGS_ALLOC1); - fdno = iommufd_fault_init(fault, "[iommufd-pgfault]", ucmd->ictx); + fdno = iommufd_eventq_init(&fault->common, "[iommufd-pgfault]", + ucmd->ictx, &iommufd_fault_ops); if (fdno < 0) { rc = fdno; goto out_abort; } - cmd->out_fault_id = fault->obj.id; + cmd->out_fault_id = fault->common.obj.id; cmd->out_fault_fd = fdno; rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); if (rc) goto out_put_fdno; - iommufd_object_finalize(ucmd->ictx, &fault->obj); + iommufd_object_finalize(ucmd->ictx, &fault->common.obj); - fd_install(fdno, fault->filep); + fd_install(fdno, fault->common.filep); return 0; out_put_fdno: put_unused_fd(fdno); - fput(fault->filep); + fput(fault->common.filep); out_abort: - iommufd_object_abort_and_destroy(ucmd->ictx, &fault->obj); + iommufd_object_abort_and_destroy(ucmd->ictx, &fault->common.obj); return rc; } diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index ce03c3804651..12a576f1f13d 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -14,7 +14,7 @@ static void __iommufd_hwpt_destroy(struct iommufd_hw_pagetable *hwpt) iommu_domain_free(hwpt->domain); if (hwpt->fault) - refcount_dec(&hwpt->fault->obj.users); + refcount_dec(&hwpt->fault->common.obj.users); } void iommufd_hwpt_paging_destroy(struct iommufd_object *obj) @@ -403,8 +403,8 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) hwpt->fault = fault; hwpt->domain->iopf_handler = iommufd_fault_iopf_handler; hwpt->domain->fault_data = hwpt; - refcount_inc(&fault->obj.users); - iommufd_put_object(ucmd->ictx, &fault->obj); + refcount_inc(&fault->common.obj.users); + iommufd_put_object(ucmd->ictx, &fault->common.obj); } cmd->out_hwpt_id = hwpt->obj.id; From patchwork Fri Jan 3 19:43:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925852 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 32AD5E7718F for ; Fri, 3 Jan 2025 19:51:57 +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=ixi5UWHGVXrm7JunzOhhOYqV4e1PUcbjLjBcYtc6OZE=; b=F3p0wA546MjBFSMWVbb0yBmJlR SwxpDWaoUDgnJA3SN2T15hnDsDLfIz1/rbTixCEv2GaMdLeHId2/Np8xJlQnwsUOlRonP+T+zUf8U oN67R3aCNoxRFVUhS8p70LqXvR/IeqPDcICIazYiPF8rjvrSazMInyEopM23UpVM2SxGGXrYiHtzt E6Gz5/n8PqtlwcrvHLFlacysmvZ+LfoSpjfwWZXFOyLMit4ub5kcjlko1Tyq0zBbsW5r9ruKWKOpv 8fRtQiUY2X5FAGr3/AR0HngCKNCtEkqkdpJzHHN0CvPB+k5jJ0MyEoMFI4gx0/odhV6X454guLuJ8 2l5Y+xvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnhx-0000000DsaZ-0dDC; Fri, 03 Jan 2025 19:51:45 +0000 Received: from mail-bn8nam11on20605.outbound.protection.outlook.com ([2a01:111:f403:2414::605] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnb7-0000000DqWc-1qJ5 for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e60CFnQhclrA9b/GnrCWXaBIeK5PmPOP8dzioMEO9X54kLhmbp/KHG6viHI2Zke8S+uGFEkoqx/PR3P3h9y0gjpk7mllIBmmWhLf732jrTt0GbZc79wiPeG1Kfu75O/ibTiWw7dOQZa3+IoYi63kRRslF70XXKy4jY4d1GqWUUVFTZgbmC/P7t8NwAwbo66Inmu5mflzvj5EnUfVpj9idlIPtJ4401n9yeZsmVFvQ1klF/D0OM/djlDs4L27W/1PZ5OWzJAVCmxd0EeYtvgV0Vk6fWG3qlgkCTaDZw3+JNBWGC3fi57GkQRGOdgzo+v///AmKt/Hvkz7TtUepZAzyA== 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=ixi5UWHGVXrm7JunzOhhOYqV4e1PUcbjLjBcYtc6OZE=; b=jJ/jmhWXul0sj/BerzACJp0j9FNsXlqOg7/Z/pTgHoHMrtgFGXNtngPIh9f3HqS54rO3XHJKEYHrM1PauCEwnA0iIXhxETgkV09yA4+TLiC9Hl0PXM2HThrlKcwMYUABSNJmI0SPYunyiL9fTmM9doBc1G80hM9rT3b66DEQXkIb8gFl2OqEd/mQrgzaLvbWF/TdEcqtIKKGL7LeYgJ07HqqgmTc3tlmZ9TPgP+u4DgfejDsp3jDUyORHGdY3kKc8OwxNU3xcL5e0LyX5Vip6j1rbisFFOE3voYfG8l3G5MEi7lrmbfdeoRJVKJ9hV+duDc7KtW7ZlKepBRmvG89cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=ixi5UWHGVXrm7JunzOhhOYqV4e1PUcbjLjBcYtc6OZE=; b=hos+yd34q5P6+Pxcfm9IzlGcRNBSHqMVznPxu9FdLy6gaCsRctrJM6VMpwuzFBUApNG+7D2ZkJZCXntsYx9V+57DOXnXLAtQQ9qR7vDH682VIX1v3VY6g4YlbydQ2ETzmRcYTR/SGsyT7nTOcSLtquxT2yzAE2NY83gaDg+zAYQ9/KCC3TsJLKO+V/GpTR1hLhZvtza+dFgKQVLnmJ+o0zysX3h7iqnwueAFy6bLVjQmNCXcwrbevStE8fLZiwAatyG+7b+iq9Gi6hm4R43EyeRlzcz4RC7Gl6q24z2I4/Wui2uIrjj6FtrniZaygEIv/WJ2tTT3G7SDrQz/4cqFcQ== Received: from BLAPR03CA0109.namprd03.prod.outlook.com (2603:10b6:208:32a::24) by CY5PR12MB6369.namprd12.prod.outlook.com (2603:10b6:930:21::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 19:44:32 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:32a:cafe::60) by BLAPR03CA0109.outlook.office365.com (2603:10b6:208:32a::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06B.mail.protection.outlook.com (10.167.243.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:31 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:12 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:11 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:09 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 05/14] iommufd: Rename fault.c to eventq.c Date: Fri, 3 Jan 2025 11:43:28 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06B:EE_|CY5PR12MB6369:EE_ X-MS-Office365-Filtering-Correlation-Id: c34ddaa3-f501-4183-7dde-08dd2c2f0b15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: au7EldK3wXo92ZhhlgfVutacs5TMzhF4qO0BSdWvrhuK4goCz4KJrhIY0MFy3jdBuJgUEXXrRBG8hQJKQmQiUsfW4SlIAMBcI4baOUrOORITGz31HsHbYzkxemXISe89ALiw5vEdBxC7Bre1uTtIUQZOTeBU6zddJDbYxu0cHd4Vb46yKaUraT5fns2EbhPu3s+OzTgskdo+ppgULlLSc0crERA6KZv2Nr00q33x9ozk8cXuDItSN+ZJIReyLjHdSHD8NU8k0xPaO5tB22Ox2O++s4kYagUhqatSc85LyszIsYbULrwbZg3vzO1fuLiSYDDWP1f90+YAQT81CuXwGQ6a2E1gNIL55px4r7apa3voi7kfs0HS2N0k9QBl8CwSoXU4YwTFSSZObyrdi6+Cypi7WHCZJEQAt8Qn4H3tDMXdU6R7Wsa+dhPKakIHX7tEleI9MI75MMsDpwe9VOsbipYrq19CJdp0sHZ2GmgrMg5BpH3E5NliL/6AdRsQ8gA++Mf+gq5ajH71ctABYBbIQzzFRQmkErb09QBK4Q0gOkA0dSUr6/G8536PTsh1Qhsb26yRhlsCyz0LfKmSPcJvAbLV6UrMMqwQ8EKWEcPw1tXOltWrEHToS1LLZJpYBfmxvsaqda5NkXIlRq0OLdP7Y+yrb6dMw0uIjGHJgiQ6rNDb3atnTNbCFnr9iBg+6zTqAkdngIOgQBMfOu6m7lAD+XYNe5MyN8dCUdcBtdJmn4IIeUf87/RjPTM5BWmSWP8jov9kodDPaBT0Oh2qnBmbr/92AjYFMD98ToPCY7jQitOONfwlQradpjdLzHrscBemA5RE/fEocLUSpgKhMHADqYg3tGKQv+5imTZPs+4CPeR6y4Xl7YbboggN+LLuBxXCpvrUvi/2zl4yx0bdzqzMAyAlDgoy5BIxSbiJXHHkmZZL2UExTqr9wX6FdvQqtpUymS7jIuGwzR0tB0xKaD2m1howieI10oe5eT8uXgz1HN5Bot1cm++oECEnxpvKeRfCgUYQkbn2BV2WA8oprh8C/tKtUTf5/Ue0AdWd0aKG0vSBW3q3HLDPIdia7i69Kxu2be4Hr6gW0O+U7c4IM4m2uwwlHVkcOX1k2AP5XBv5dMVavBx7++Be1Ogs/pbkYbKsAgQC7iWC6yKfwanA7HZFcuW3twAeNhL8F63zJ0zMjnDntPrgUzF8/z4Lso/21wjH25yubjTalEw9RjWg6RMF9u9AZ2hpAiKb8zkyBYve+VIpOZC0ypl8SXVfGrk6sjcB463rwnu1XRJMBdbOSMJV2gX5WsGN6q8vB9JsXordtu1a31ik6wPDjvjy38PAFLDwFWwes4QQTRwpLPEco07Ovp6uEe9bokp/l6PAOEvW5xdgO5+a/9GEtao6MWxkt4tdYnq7Wjcov0LOcrvfgBmSRIoZ7uqHbIk3MZ8s7xJn33Q8XObcdicxQ4Bul2ZcrdFMSVlA7fwNICvBmKT07/ewHGXQuLtEJ/+MtdMgY3A7Ls8= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:31.5490 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c34ddaa3-f501-4183-7dde-08dd2c2f0b15 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06B.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6369 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114441_471609_335ABD42 X-CRM114-Status: UNSURE ( 8.54 ) X-CRM114-Notice: Please train this message. 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 Rename the file, aligning with the new eventq object. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/Makefile | 2 +- drivers/iommu/iommufd/{fault.c => eventq.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/iommu/iommufd/{fault.c => eventq.c} (100%) diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile index cb784da6cddc..71d692c9a8f4 100644 --- a/drivers/iommu/iommufd/Makefile +++ b/drivers/iommu/iommufd/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only iommufd-y := \ device.o \ - fault.o \ + eventq.o \ hw_pagetable.o \ io_pagetable.o \ ioas.o \ diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/eventq.c similarity index 100% rename from drivers/iommu/iommufd/fault.c rename to drivers/iommu/iommufd/eventq.c From patchwork Fri Jan 3 19:43:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925848 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 1C702E77188 for ; Fri, 3 Jan 2025 19:48:18 +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=CRkl+fZMxEYykug99pc9ntbWuoGTyAfUXFg8/3nf6rI=; b=i47vEKP4ZwX5I3a2eKtwlI/+Rt x4wPPDMmzWmja0J1R+OZUBluLlAn4PyUrLXn0PeXeXq+UYnoi1NhQYCWq+GE2n/WwtCVmJwEssAV+ sBZpbXO381WoPeHL8DeqYJzG9cMdfIRWSnEkvNkfxK1Qr1MwNCyj0hBpoeQd5/gYAkl2gdyf5epL9 q93lZ46kmOxQkKJqOvXbFnjaG9PueuPRx1XvlxzIFboNNdjsulR6NpQHleCk53eGHN5fZDLw3VSeh uNYmnnqccmU76PUDhXRZLTtSGPrEKo6LdAu/IpNn/eoG87Vr07fhijlVMm5NVHNtvtwBu6ZDX/lv0 DpP/kU9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTneR-0000000Ds1u-0YdH; Fri, 03 Jan 2025 19:48:07 +0000 Received: from mail-dm6nam11on2060f.outbound.protection.outlook.com ([2a01:111:f403:2415::60f] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnb3-0000000DqUD-33Ka for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wWTcY1pYupUz3FE0QmtgKMiat36/i+UwPHWgF6eeWOh/5hsH4vELWo085OKTwJUqxMCEyr9+QYugLZ2E84UOcs6ix3AaexCMJPp49TteM0GcgPmupmt/KRsiTO02WGHrR93uF1ELT8ABka3XBq1lbbGbAayvpPqMyQlnm9YsQwNJJVWmwbmsheAImkKlGqX1wcAUyF7W6qdITEMERmjjNLQCjOTU/iwOnYy4q4EM1xYp+/eKDleQhe5A7RcLYFhqbLT+y5dwrBIo1+q7s7BOZo3GuVFIB6sZKposyqJGFAiFoqqaFRr3r/XeNHYk8rgRK3r03CKqvED4U7s0xdB+LA== 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=CRkl+fZMxEYykug99pc9ntbWuoGTyAfUXFg8/3nf6rI=; b=Q+kAI9XKxI25njCiVmjNprOFTgJ/xpyGirr50R3xUdsSUnYBfyJLywJHYiv65Nhp7CCrZBwEGugnOv6BC26h9aoMx3GYq8Hkc0vckPwDqwvv32b+5KBhuc/NzwA4Di4U0d8Au8o1CrbjLkilU2IGRzuNoxLoh3XUSEsQF/OTYaj1OAtIccWMZ8VXUQuTvd85vcHKaUdnWyFdKMU3OkQ6eD7cX/fsx0+bT51TNDMHz/5Pl8Dc+7IfDWRjsDSIrRuNe9UyW2zuIXdXUq4aNbjpJA3CMRf5BQlsQRY+zn9cKDMiUH246gFpQSk9TAQk0WUte+3cIItN7HJrS5Ktyo3X5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=CRkl+fZMxEYykug99pc9ntbWuoGTyAfUXFg8/3nf6rI=; b=m7ZRZRbHyo++fcF1Q23+H0myIJtlRmGuR3MUGlIA3IKlImd+N6HZCk0mLvrXCy4sY6yRb5ASFvL9tFwbmggkb0VtzOOC/F7vW34rxLKKZv/s5K7ZxhzhBnieIf5qtpBw/lJGf4v8YomChLeH386ezXJHKQmd72OXrabIrlsf5ik5Za94jG9zpDuJxTaJbAi71vL8AP2OVmNjriJ0Q3PbRIHBZ0vq5oWpPYDQcFzQCzjRO88YI9Ht10Q7ewev/8g90lttwVcDt1EIAzemvVS9EEBzgsv3Sua0PHCfT2VcY7FpbpnRYZhDX+cJq2n7bd5yLSHG0h0Vg65a3dP69SKeJQ== Received: from CH2PR05CA0061.namprd05.prod.outlook.com (2603:10b6:610:38::38) by PH0PR12MB7840.namprd12.prod.outlook.com (2603:10b6:510:28a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.15; Fri, 3 Jan 2025 19:44:26 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:38:cafe::45) by CH2PR05CA0061.outlook.office365.com (2603:10b6:610:38::38) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.5 via Frontend Transport; Fri, 3 Jan 2025 19:44:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 19:44:26 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:14 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:14 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:12 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC Date: Fri, 3 Jan 2025 11:43:29 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000014A:EE_|PH0PR12MB7840:EE_ X-MS-Office365-Filtering-Correlation-Id: 9792e41d-ef17-4ec3-ea0c-08dd2c2f080c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: jaoYA6lB+RPcOkHwoTWMuwr1RUOVvL9KTrlOg/s4ZjnSp9b4+jl/B0TwHBYYf+nJ2QQfG4fFEcO7Cj65d0p9POTx9kmohC2U0Iv81rzAyFDFvL37rmFXDC+3PlhZ3QbPZt+I9dwsavMtK5NcFmuVdSiAy38b+/k0rcQczABgeqH0m1PCFFP/GB43H542X++gAFM7NyMyf18RZDud2wqNKl74vifVEYeYdOJdocc6l0J74EEZV3lahuGd0KoGARa4TOqZxmkKMIy7wujUkYJwVCL4tr2QfYKaP0/VGTivK8SRpkuN65BosVmkRT2mst/YujYcRB9YX8mahZZBdrkN1eIuePprFRXGEuj8zO2Z4PlH5McggFyjMQWeA0IKw2qRSfmao0Bwml9z3dAQBO3e21eJstvC7/EtPFn+ACnT9VCzoRQ9DX7a3FEJ5BN14dd0bZhRvCZ5brRy0haOXiojTstGJ74rTCJeC+xDq9048WVgTLt/3T625e5apovyYYsI8enG/jMfae0Jxk0ZudhPh1a/opQSBq46G32iZwCXFtwMZoYHlm+XJZF650smQkRlkb+KRp89zPdGlyZWYHj804dg9QLh+I26Wkx0UZoNUkIHHxAab88Ia+TMW2x6Wu800m1h2kJCbF9kSG9SEpRaBnVKKLIKQs8jFTz+JYHuaO9n746Lfd5nyPHskbJpz3w0B8qOUiNj6OlyVZfEfVG7Nmk5onsbf3w0zU/1/VqYKtYVFk20GRqqsz8xXYw0Z2iBy9xWk4R5DVu25mqWn86ri424e/LnT+QXTAECYq/2Ja1j0zOCULsuWcp04LbHAH8wltu2513qFcpJAhTViJ/kcsBmxFVGcXAoQ03DU9Y1ocbLIcd6S9E+bVE18r58IxiX3kIv3YYjlr1t81x5GU+2qU+JSFddEsagwjnUDG7RdHLCOQBANxqaWsW8nYFfrX2P624cF78Ztjz53ZxGNrmYrHygB6Wvs9UCNXkc0q7vqe387gTKxBRltRG60ruEhGxSXIx9TuLLIEUlLe8m0lWByl3i07TDSwbyxcV3xTeYfW4KYYnbztQzDt5QWKWVe3Xja9su53lefl7ekJa254XQgjZM3MtNY9OtB3zjHQu6EuUV8m4CbYLx/GNjWGaIqEO2oIche5CMIrQgaVqIjSmSqX6Jf5a3yiQ1xNxdbBrKOH+K1R7Fs5KjszXClySNsVQQYJkIwPoUQn6An2Xz+obE6CtY7ul8W3rnk3LYQ3qzxRrItPAk/sUReAdUwauA8oIICq8uq1FhTJh+0aBFgCvukeMIlH5CYedWY0ANME9q1T+WdLQXPV5mJ8Lyra+YDOTfjU7CgOkTHd7RUbXEH7xNzt+vsVflPkHlpr4gaXVvljeeyW7MOw1qfMyc4v1k0mPiMqH7gh1TUIurFZnPD0mrr5RgQnrZvPOW1WW/OhjqGiIjK+PxBE20yzOwNQVlVn8z1jIrwg3UeMdhskHOzFQG6tf9w3s12ChlxCwD9uuG0eM= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:26.5065 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9792e41d-ef17-4ec3-ea0c-08dd2c2f080c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7840 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114437_820993_A1A9C39B X-CRM114-Status: GOOD ( 18.50 ) 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 Introduce a new IOMMUFD_OBJ_VEVENTQ object for vIOMMU Event Queue that provides user space (VMM) another FD to read the vIOMMU Events. Allow a vIOMMU object to allocate vEVENTQs, with a condition that each vIOMMU can only have one single vEVENTQ per type. Add iommufd_veventq_alloc() with iommufd_veventq_ops for the new ioctl. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommufd/iommufd_private.h | 58 +++++++++++ include/linux/iommufd.h | 3 + include/uapi/linux/iommufd.h | 31 ++++++ drivers/iommu/iommufd/eventq.c | 129 ++++++++++++++++++++++++ drivers/iommu/iommufd/main.c | 7 ++ drivers/iommu/iommufd/viommu.c | 2 + 6 files changed, 230 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index dfbc5cfbd164..9410f6275b5a 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -547,6 +547,50 @@ static inline int iommufd_hwpt_replace_device(struct iommufd_device *idev, return iommu_group_replace_domain(idev->igroup->group, hwpt->domain); } +/* + * An iommufd_veventq object represents an interface to deliver vIOMMU events to + * the user space. It is created/destroyed by the user space and associated with + * vIOMMU object(s) during the allocations. + */ +struct iommufd_veventq { + struct iommufd_eventq common; + struct iommufd_viommu *viommu; + struct list_head node; /* for iommufd_viommu::veventqs */ + + unsigned int type; +}; + +static inline struct iommufd_veventq * +eventq_to_veventq(struct iommufd_eventq *eventq) +{ + return container_of(eventq, struct iommufd_veventq, common); +} + +static inline struct iommufd_veventq * +iommufd_get_veventq(struct iommufd_ucmd *ucmd, u32 id) +{ + return container_of(iommufd_get_object(ucmd->ictx, id, + IOMMUFD_OBJ_VEVENTQ), + struct iommufd_veventq, common.obj); +} + +int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd); +void iommufd_veventq_destroy(struct iommufd_object *obj); +void iommufd_veventq_abort(struct iommufd_object *obj); + +/* An iommufd_vevent represents a vIOMMU event in an iommufd_veventq */ +struct iommufd_vevent { + struct list_head node; /* for iommufd_eventq::deliver */ + ssize_t data_len; + u64 event_data[] __counted_by(data_len); +}; + +static inline int iommufd_vevent_handler(struct iommufd_veventq *veventq, + struct iommufd_vevent *vevent) +{ + return iommufd_eventq_notify(&veventq->common, &vevent->node); +} + static inline struct iommufd_viommu * iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) { @@ -555,6 +599,20 @@ iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) struct iommufd_viommu, obj); } +static inline struct iommufd_veventq * +iommufd_viommu_find_veventq(struct iommufd_viommu *viommu, u32 type) +{ + struct iommufd_veventq *veventq, *next; + + lockdep_assert_held(&viommu->veventqs_rwsem); + + list_for_each_entry_safe(veventq, next, &viommu->veventqs, node) { + if (veventq->type == type) + return veventq; + } + return NULL; +} + int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); void iommufd_viommu_destroy(struct iommufd_object *obj); int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd); diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 11110c749200..8948b1836940 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -34,6 +34,7 @@ enum iommufd_object_type { IOMMUFD_OBJ_FAULT, IOMMUFD_OBJ_VIOMMU, IOMMUFD_OBJ_VDEVICE, + IOMMUFD_OBJ_VEVENTQ, #ifdef CONFIG_IOMMUFD_TEST IOMMUFD_OBJ_SELFTEST, #endif @@ -93,6 +94,8 @@ struct iommufd_viommu { const struct iommufd_viommu_ops *ops; struct xarray vdevs; + struct list_head veventqs; + struct rw_semaphore veventqs_rwsem; unsigned int type; }; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 34810f6ae2b5..0a08aa82e7cc 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -55,6 +55,7 @@ enum { IOMMUFD_CMD_VIOMMU_ALLOC = 0x90, IOMMUFD_CMD_VDEVICE_ALLOC = 0x91, IOMMUFD_CMD_IOAS_CHANGE_PROCESS = 0x92, + IOMMUFD_CMD_VEVENTQ_ALLOC = 0x93, }; /** @@ -1012,4 +1013,34 @@ struct iommu_ioas_change_process { #define IOMMU_IOAS_CHANGE_PROCESS \ _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_CHANGE_PROCESS) +/** + * enum iommu_veventq_type - Virtual Event Queue Type + * @IOMMU_VEVENTQ_TYPE_DEFAULT: Reserved for future use + */ +enum iommu_veventq_type { + IOMMU_VEVENTQ_TYPE_DEFAULT = 0, +}; + +/** + * struct iommu_veventq_alloc - ioctl(IOMMU_VEVENTQ_ALLOC) + * @size: sizeof(struct iommu_veventq_alloc) + * @flags: Must be 0 + * @viommu: virtual IOMMU ID to associate the vEVENTQ with + * @type: Type of the vEVENTQ. Must be defined in enum iommu_veventq_type + * @out_veventq_id: The ID of the new vEVENTQ + * @out_veventq_fd: The fd of the new vEVENTQ. User space must close the + * successfully returned fd after using it + * + * Explicitly allocate a virtual event queue interface for a vIOMMU. A vIOMMU + * can have multiple FDs for different types, but is confined to one per @type. + */ +struct iommu_veventq_alloc { + __u32 size; + __u32 flags; + __u32 viommu_id; + __u32 type; + __u32 out_veventq_id; + __u32 out_veventq_fd; +}; +#define IOMMU_VEVENTQ_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VEVENTQ_ALLOC) #endif diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c index e386b6c3e6ab..bf0c04f571a7 100644 --- a/drivers/iommu/iommufd/eventq.c +++ b/drivers/iommu/iommufd/eventq.c @@ -346,6 +346,73 @@ static const struct iommufd_eventq_ops iommufd_fault_ops = { .write = &iommufd_fault_fops_write, }; +/* IOMMUFD_OBJ_VEVENTQ Functions */ + +void iommufd_veventq_abort(struct iommufd_object *obj) +{ + struct iommufd_eventq *eventq = + container_of(obj, struct iommufd_eventq, obj); + struct iommufd_veventq *veventq = eventq_to_veventq(eventq); + struct iommufd_viommu *viommu = veventq->viommu; + struct iommufd_vevent *cur, *next; + + lockdep_assert_held_write(&viommu->veventqs_rwsem); + + list_for_each_entry_safe(cur, next, &eventq->deliver, node) { + list_del(&cur->node); + kfree(cur); + } + + refcount_dec(&viommu->obj.users); + mutex_destroy(&eventq->mutex); + list_del(&veventq->node); +} + +void iommufd_veventq_destroy(struct iommufd_object *obj) +{ + struct iommufd_veventq *veventq = eventq_to_veventq( + container_of(obj, struct iommufd_eventq, obj)); + + down_write(&veventq->viommu->veventqs_rwsem); + iommufd_veventq_abort(obj); + up_write(&veventq->viommu->veventqs_rwsem); +} + +static ssize_t iommufd_veventq_fops_read(struct iommufd_eventq *eventq, + char __user *buf, size_t count, + loff_t *ppos) +{ + size_t done = 0; + int rc = 0; + + if (*ppos) + return -ESPIPE; + + mutex_lock(&eventq->mutex); + while (!list_empty(&eventq->deliver) && count > done) { + struct iommufd_vevent *cur = list_first_entry( + &eventq->deliver, struct iommufd_vevent, node); + + if (cur->data_len > count - done) + break; + + if (copy_to_user(buf + done, cur->event_data, cur->data_len)) { + rc = -EFAULT; + break; + } + done += cur->data_len; + list_del(&cur->node); + kfree(cur); + } + mutex_unlock(&eventq->mutex); + + return done == 0 ? rc : done; +} + +static const struct iommufd_eventq_ops iommufd_veventq_ops = { + .read = &iommufd_veventq_fops_read, +}; + /* Common Event Queue Functions */ static ssize_t iommufd_eventq_fops_read(struct file *filep, char __user *buf, @@ -473,3 +540,65 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) return rc; } + +int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd) +{ + struct iommu_veventq_alloc *cmd = ucmd->cmd; + struct iommufd_veventq *veventq; + struct iommufd_viommu *viommu; + int fdno; + int rc; + + if (cmd->flags || cmd->type == IOMMU_VEVENTQ_TYPE_DEFAULT) + return -EOPNOTSUPP; + + viommu = iommufd_get_viommu(ucmd, cmd->viommu_id); + if (IS_ERR(viommu)) + return PTR_ERR(viommu); + down_write(&viommu->veventqs_rwsem); + + if (iommufd_viommu_find_veventq(viommu, cmd->type)) { + rc = -EEXIST; + goto out_unlock_veventqs; + } + + veventq = __iommufd_object_alloc(ucmd->ictx, veventq, + IOMMUFD_OBJ_VEVENTQ, common.obj); + if (IS_ERR(veventq)) { + rc = PTR_ERR(veventq); + goto out_unlock_veventqs; + } + + veventq->type = cmd->type; + veventq->viommu = viommu; + refcount_inc(&viommu->obj.users); + list_add_tail(&veventq->node, &viommu->veventqs); + + fdno = iommufd_eventq_init(&veventq->common, "[iommufd-viommu-event]", + ucmd->ictx, &iommufd_veventq_ops); + if (fdno < 0) { + rc = fdno; + goto out_abort; + } + + cmd->out_veventq_id = veventq->common.obj.id; + cmd->out_veventq_fd = fdno; + + rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); + if (rc) + goto out_put_fdno; + + iommufd_object_finalize(ucmd->ictx, &veventq->common.obj); + fd_install(fdno, veventq->common.filep); + goto out_unlock_veventqs; + +out_put_fdno: + put_unused_fd(fdno); + fput(veventq->common.filep); +out_abort: + iommufd_object_abort_and_destroy(ucmd->ictx, &veventq->common.obj); +out_unlock_veventqs: + up_write(&viommu->veventqs_rwsem); + iommufd_put_object(ucmd->ictx, &viommu->obj); + return rc; +} diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 49be19305d98..985661a4af07 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -310,6 +310,7 @@ union ucmd_buffer { struct iommu_vdevice_alloc vdev; struct iommu_vfio_ioas vfio_ioas; struct iommu_viommu_alloc viommu; + struct iommu_veventq_alloc veventq; #ifdef CONFIG_IOMMUFD_TEST struct iommu_test_cmd test; #endif @@ -367,6 +368,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { __reserved), IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, struct iommu_viommu_alloc, out_viommu_id), + IOCTL_OP(IOMMU_VEVENTQ_ALLOC, iommufd_veventq_alloc, + struct iommu_veventq_alloc, out_veventq_fd), #ifdef CONFIG_IOMMUFD_TEST IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last), #endif @@ -502,6 +505,10 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_FAULT] = { .destroy = iommufd_fault_destroy, }, + [IOMMUFD_OBJ_VEVENTQ] = { + .destroy = iommufd_veventq_destroy, + .abort = iommufd_veventq_abort, + }, [IOMMUFD_OBJ_VIOMMU] = { .destroy = iommufd_viommu_destroy, }, diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 69b88e8c7c26..01df2b985f02 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -59,6 +59,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) viommu->ictx = ucmd->ictx; viommu->hwpt = hwpt_paging; refcount_inc(&viommu->hwpt->common.obj.users); + INIT_LIST_HEAD(&viommu->veventqs); + init_rwsem(&viommu->veventqs_rwsem); /* * It is the most likely case that a physical IOMMU is unpluggable. A * pluggable IOMMU instance (if exists) is responsible for refcounting From patchwork Fri Jan 3 19:43:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925853 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 76C85E77188 for ; Fri, 3 Jan 2025 19:53:09 +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=KIS+saEdL9KmV30PuFRRR9YLXw4Q/rgjK+XCzIzIlpk=; b=e9mUR0rrb74ChwXuV4Kps9/8RQ dcMIPLlV5ypeMyKgOKyfbMUw0/sjUAPrwEhVyWeMXgqxcnygll7uBzV3ZN3Jl1Ue1XTn1C7rnNj5s WWH1AUjSlV4iOO+q83ZbEbtC/8bKWlrzMfVnN6XUwCjyPcHmCO/M0JfX6Qcmmk9On4qd++yhtppRH Nc/MXEymDOhyZHWSYI1/iUdDmnRmPCB16ukh20VUfa7Y/2RxW/zkpwT7z9MpUk6lyrmydtJr1zT59 BcKjkp4OHM/WQ4Py7EF39gVqF2Za6X8fQpQw3+LIv5tBW6eWCiiobXZ5z8YsHG9R0ph+O1J1t9Np4 jAmJSO1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnj6-0000000Dsho-3IJI; Fri, 03 Jan 2025 19:52:56 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbG-0000000Dqas-0iau for linux-arm-kernel@bombadil.infradead.org; Fri, 03 Jan 2025 19:44:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=KIS+saEdL9KmV30PuFRRR9YLXw4Q/rgjK+XCzIzIlpk=; b=GRjiFaRb0jioeWZQQVuZnJoluM ZNUdHfLMvSDFQMRQV7c+MuCv+0HujuqFSbLdqtgeeNZjpv4nJqVE1Q1GS2SclvFkAZFUEaS/ZCvJG Pq5wRGDRxZLnCiMz24bEi7dXQNxCQOkquH3fGSw95zohlKtw/jk+WIe/YWizCuqq90ZJ0KxaoSY92 BhdTQrzKDVpvf8e4V9ONgObrhCmLNRgNjhA1p9TptinVweCgeNrL2XFIh2zb/wefmrqcQewnqyRLV nK/DDNvgd0cubjbns07YwutVSqR0/GmS56jC8P3CpZo5mHamKcqR+uIsA4KFPiThBhTaeU/D5L2Gg fB+Fgr4A==; Received: from mail-bn8nam12on20620.outbound.protection.outlook.com ([2a01:111:f403:2418::620] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbB-00000008RFA-1n5P for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a9wiHWIBeTuZdGtE5ROq3OWExRbEqvJABo1x4f/wLtNj1f/f6nM86j/Za35sArIk76/QS8QiH1e4MtBXOOaiqYF/MZKlq9uEBQ0GVweT7wa54JaHpRLzPLkU2IokaxT6mOIY0sVZhmKSbZMZsd4YMnNqho++wGCTrpPK3SJFvy/51c1uw0eVP17Fx9utGGxeGSGaXJSWbA0Ok5fDg36qckepbPKxEoDjuLXbCcA7hB0BavUuc3m3UjXhliFATqNSNqo2DKUbrKEjoA1D5opb3ezoT9vwWJ7+PePmYFwi4VCIId6L9YGthZP5Kp+eAyu/ZHzySOTD2qqqUNUuS5uufw== 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=KIS+saEdL9KmV30PuFRRR9YLXw4Q/rgjK+XCzIzIlpk=; b=nB8S/ncfZEEnEoDfK8LS/Wy5SIyCxAiAxqJNaRGZmCi1comfcINwge8WEYIvBYsMxjwEqp1BrUwzSvOqHTuNQa/rQBp7ESd8Z+A4wIedZeWrof7JbJGPxjtVNsjxkfleTBmU8PL4X6gTHjL6NVVNN96W35B9wRW2LqHFFlbaHhJdigI7Lkbn8QK3SUQEScvc4xGriU2K+CcXiPo4UW9RNMRc9av9tOb9IsSbhGC44NBm65SXUspSOJi1ed5/ghDEFyHrzga7qRTXYQTSR6kBWYILal/hA2FZ22ZPjXwYtH5DC9QxgvkVJp4CM6n1TzUAx1RmjbABdWPKDjrwNnU89w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=KIS+saEdL9KmV30PuFRRR9YLXw4Q/rgjK+XCzIzIlpk=; b=R+0Fa6tbAPqd1OpuOyw9tjEQwiYCjzOhJlfmMZvSHZ5WrxEYhzYQwituq4j34T3UdfSo+/LQeCpPwAcBgipeLf5mwb5HzgIiArl/r5MSHr+WCgyeWKOdikcn9FLd3qZar5bCufhYWWFDUKOwEdqzNR5Vk+yRtwCwyLxth8IOgUrVoc2fpauXbuuQP5OjbAoHh/WXikq0c0zlxBD8HfaogcyWdYoIglDei+4BWmLbRdVoIURlfjiFJVd0ETibMY2ocTSxajCN6qUd6F+rjFoZh7OkbKZIJWgUaJaupvTDm/LNsfTCbGaQ6pL7xrBORlLl7J1QM+QDX4d9B/NlwF+ZJQ== Received: from CH0P221CA0014.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11c::12) by SJ2PR12MB8738.namprd12.prod.outlook.com (2603:10b6:a03:548::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.13; Fri, 3 Jan 2025 19:44:29 +0000 Received: from CH2PEPF00000144.namprd02.prod.outlook.com (2603:10b6:610:11c:cafe::b3) by CH0P221CA0014.outlook.office365.com (2603:10b6:610:11c::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000144.mail.protection.outlook.com (10.167.244.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 19:44:28 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:17 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:17 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:14 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper Date: Fri, 3 Jan 2025 11:43:30 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000144:EE_|SJ2PR12MB8738:EE_ X-MS-Office365-Filtering-Correlation-Id: 02ba63ae-b728-4e53-0edd-08dd2c2f0981 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: p0wbRaqMzYzNtPJcqUopw+5T1XIOtjsjMq8Tzeu/ZLyn6sQw6qTj1MdDYQEZluoh7quuc+B0UQNbX7Dlgh2f1jLzuXrGmiSQ5YFWcvFrRg+g/kvaDFAsCntVj5wy6F1KYqZdHMWWUKtyo39PL7GuTkPKx8dI+KO+SPlML9gxGeKnZtr0+YEdDx03La/4NI91L0TsuLcgHpzmr1GWkW6hb5CdMDxhQBP5DacJEO2r0+E/8YQpGCZQ99S0Lyq9Ez8Yu89fh9xVqvdwi+6IZMGyiFjsMz/cUDpEtRaTYsqdXEeKWzNBVp52Q3Bg9Nk84Jw2itqO4oeyqIQa0Lmm1Ia406+wZAYuRDwqZ6B22iGvaFSFGSD+xOBnxoc8ibYrKWX3rP/qvxKw2N/+FMz3d8BhXV7GmztEwnHqPGfLhr9gg6NlJtVHkELMEJCXA0lTpfP3U/6Jder3NxQSEJXXaVziElr+hzugjq/KrY/DnQbAUkh5F5bIc+gDzUES+s0PBRgqsvu9ZPDoW9U3QtsCL40/2tjM8oAwh+wlPJNkQTJcEq5nydrsnaZiuj9p30+s+e8VWOTgxBw4VLV+PNHc+NL7BV773Rope36IAMOjG2fusIhKaohIEW0Tm6fPRp+vbY/IlWuLi4ejg6VYNzNN6WNK2o4wPArSPBDZXSr++Xvr2VWWWzd8eS74uHn9sSx6DApKfgHZRDRh1p7FYAbPjRMQ3EAjuD3vJP0xjiiavfxGi+RsVi759AP2KS354IKk0JLbRwa5wzV3eIL/HlgBGXDrPU1sm3MQ7FpYopiE+dFYZTQmDD+X1PSDv8qCmESTDmfy6IZ+wScx8MjPAq7JZc+XN74PvQr33X+FVAFUfeMmcrz9rVu2oxOTWoPBLVklALMGMtGcdQTKtiRCa/exADeKCmFFXSfOpAds3LVu0ZZFfKSf2rlOJizlXYIW8CK+hxu8u1lbyXaszNcRUrfPY+tc8D9+6Hq66Rt+GlpglCBuGN4akYHXJHZnhGJzMGiCzZmmieGUtLipmvtHdtKz8GCu2fDgAGP7OZ77PY943zjlRdpKMIPG2j3IBmBXg2TIFNBpbzPU5y8BC88UyvERHL3pY+CBiPaz9MVh59SRaN1TKDCDhcA7L241u+hL6Ti+bWFkwB1fYyZGUbsWdmN2zQ6kwpX3zeQR9mzDc8mviX66xMiPiz3mdCLgT62K+S9E2ctc0GKFeT4G/ybmJ60EDMu6/HKFBvK6j4GquPcHSJjtSAyJz6thXdr5iIeUZMN4XpD5OoW+EEhxbnplo+lfiY3Wx0k2KIRAmSuuJAR4wOcmgZPIAqU6UI5RSCw8aXypSjfX1y26tNmNbZKuNo1UlP0c954sTLfF3bHBRlXnVVAGE6Z7OV1IN7Xk6aghQe7FJvIY9S/Cw85q0jt2Pb/RwoDE29hDvNuE92+NglhhXQNNHW0Q6r9+bVdcSVXC2S1tLES95Breu4/ZC585E62dVzPk8bYkrf3Bb233Ohx+ifkCyro= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:28.9453 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02ba63ae-b728-4e53-0edd-08dd2c2f0981 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000144.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8738 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_194446_883106_02C66289 X-CRM114-Status: GOOD ( 12.35 ) 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 This is a reverse search v.s. iommufd_viommu_find_dev, as drivers may want to convert a struct device pointer (physical) to its virtual device ID for an event injection to the user space VM. Again, this avoids exposing more core structures to the drivers, than the iommufd_viommu alone. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- include/linux/iommufd.h | 8 ++++++++ drivers/iommu/iommufd/driver.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 8948b1836940..9c6ba7df3994 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -190,6 +190,8 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, enum iommufd_object_type type); struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id); +unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, + struct device *dev); #else /* !CONFIG_IOMMUFD_DRIVER_CORE */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -203,6 +205,12 @@ iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id) { return NULL; } + +static inline unsigned long +iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, struct device *dev) +{ + return 0; +} #endif /* CONFIG_IOMMUFD_DRIVER_CORE */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index 2d98b04ff1cb..e5d7397c0a6c 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -49,5 +49,25 @@ struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, } EXPORT_SYMBOL_NS_GPL(iommufd_viommu_find_dev, "IOMMUFD"); +/* Return 0 if device is not associated to the vIOMMU */ +unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, + struct device *dev) +{ + struct iommufd_vdevice *vdev; + unsigned long vdev_id = 0; + unsigned long index; + + xa_lock(&viommu->vdevs); + xa_for_each(&viommu->vdevs, index, vdev) { + if (vdev && vdev->dev == dev) { + vdev_id = (unsigned long)vdev->id; + break; + } + } + xa_unlock(&viommu->vdevs); + return vdev_id; +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_get_vdev_id, "IOMMUFD"); + MODULE_DESCRIPTION("iommufd code shared with builtin modules"); MODULE_LICENSE("GPL"); From patchwork Fri Jan 3 19:43:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925856 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 7292EE77188 for ; Fri, 3 Jan 2025 19:56:44 +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=Oc6M4OH8T3svuItgrMAtDs+561KzAXM2M7+KLhCml2M=; b=Rqf04ERzWvopeMUjiFpZQBvnb1 5IgHNWB0CUjzIkmhjzpvfTDc1Z3Pe8Rgrm/hJVMqe61HyX7JTXtbWum2BXxhACWaygPzFTHcMBq0D 3TfUc9dgtRSZkubpeQuTFOLSouqxAEoVVcKJHjLYOplFeZqfnP5Q0y+WaFNRwOhtYV17/EavOD133 JXlG/2Gg78z+ChX0MyhKWDa6wN4gNhsG9hwKPYpFo0Ap5xCswQJfCnrRHkHh13ENLQGGIoUkdZRAF N9NqGJ19ld2FpIesOhgf0yILLWO1Q2e4CfTzycFy1CA7pEiexI643H8j99klU7KgBWGZ8IS6pCXiZ G03dWlKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnmZ-0000000Dt3l-2n5i; Fri, 03 Jan 2025 19:56:31 +0000 Received: from mail-bn8nam12on20631.outbound.protection.outlook.com ([2a01:111:f403:2418::631] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbG-0000000Dqar-1KIb for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nffuCoIEId4/HvCr0VtLKqux58fTExXZn1j9yHSAzL0DoY3qqy3bmLYAfL7Fut36KesHH117yXei9FlhBiydgf6i44z2BlRPToMgDABpnnFfaMjg7aiczOAta69tNKaDATMlNtB6FL9u9s698J0IGOAOJvJc2wf4pcaJF/nI+gV4FlBr7synG5bXFZ/YFu87RKFTJ+cC0daX100YL3xm80YoD6rHR/F01DI9lSYsm/zXu2p4fjCcAyCsNvjKD4NeA9nLpbfeMkDKvSBROI7H83vFJM1+ZmxJd5vxAvgy8rMxkyWaCRszQ0gQ0bfM7Lmaj84fu5blj1TSvnYPYqDbFQ== 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=Oc6M4OH8T3svuItgrMAtDs+561KzAXM2M7+KLhCml2M=; b=Q4vAWuLHdSNBvT9J7M9Ad4ywKbl7O/f7GssJlKa+7SGftTUPINAneSXMkaydGLsn2lZk3Qw59N/hXkbIwOsPsquqLZYYnuC+geybkta6j/2j4+nbKtj885iJ46t56hj1uKDfi6AxWmtqjMPaXzL5K10sml7OH7GZY+hdfb5BjCo5um4vDMNPeNsVhShwmsqG02nAJaEdM4qI+MfIWR8BIX1ba9BMgR3C9D9WBJcY3x2YHpXj+gbjR0sltbu5XUk0QzO8Ym+8oLfm7pJJEArxgSF69E0XPJ1FUxIDwR5b8HFAKZ5G4Q9fnzhmeoxRxxMWWeMModrZoztwJN5ZXNgiRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=Oc6M4OH8T3svuItgrMAtDs+561KzAXM2M7+KLhCml2M=; b=iJJ5NMjdlZqN4KjLT97KhmXIwK8NAjj2tS171HwHO/6RN1+FzzG9BiWxdGpozZk3bpQtVnXLBN2rdcRuXTPoswJudRPfNhGu4bBiAvK69fjpxDLkSBc+x6KDq055xorGW1vTVsfJBAhqgwexY5jRUubAgTTCoqE6eR4FUGX10ch3KEb9o6ER/tISq7I9Q7z8TPv7RMRWTPtrmBpd9ITb5kN4+nwpeaqK4s3Pn2tORVECZFWUYZ7b80A4XMVRcDrjZAE1fL8jWnfJ7bTJf1Y2klCl2HXl3wmqmPEUYxX19jZTM/h+8+AR4RqwyAhQJc4MOwBlaZW66FR+948oZIWfHw== Received: from BN9PR03CA0735.namprd03.prod.outlook.com (2603:10b6:408:110::20) by SN7PR12MB6814.namprd12.prod.outlook.com (2603:10b6:806:266::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.13; Fri, 3 Jan 2025 19:44:40 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:110:cafe::97) by BN9PR03CA0735.outlook.office365.com (2603:10b6:408:110::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.12 via Frontend Transport; Fri, 3 Jan 2025 19:44:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:39 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:20 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:19 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:17 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper Date: Fri, 3 Jan 2025 11:43:31 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|SN7PR12MB6814:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e07d01a-2ea3-402e-178a-08dd2c2f1006 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: eoLfLs6+VhzvQp5dS56A3zh1ih1ECv+w1lIl73LeSPVlvFiVKjcAmJfC5rs1EJpwKtDTRbd4HW4BISqrdmt6keXRb1c6kTaeRiaohtOdb331OK/bFDKqDvs1NlR1jow5pj38ya83kGaLAdJc67waSOw8WLZQ4pdLUCqXIH1w3UAqAm5SigdN1wIXTLY4uBxQqywD5BCBjljAURm924ae9MLPeyWM2cdTAA1DapEid+YXMOO7DBp2+r3DmJoti7h/FniUKq3l4+LMf1q1Djc80nBgpG/8Un9mK8v31vp4RPtVFW1CmgiuEGrfWEOxXMuJ6SGvI6bwuq8y8z4eI9hcK1XjLFWeKVHePqalM6Vrd+KOB6bf4OoAYmUXuwdSTph7InRn3AIHYCiGqsGf+7NLesm3UhGVH3aW1+HXqzp+Z+YR070lOjVdaQSSNqDnjpTxUExYVLqWYiw99kzA6Kt7glbxuJRYltc3hk8F4uSpwUVYF5b6VAOPnhluGcTcJAHbLZaZge0ksBhnZ0/vOHRxxmT+nHu9qN7tEmuAyz6u+gy5QazYGAg4DvLohjgs0iJYgAgS3tvsqGQLDPD02szvpf4FLACMT05aVkhC7d6al7yqTMcml9Z9wXdwnq+571emLwG44TwCeNgkPd+HtAIMNGWJjALsUaa+p2jc+pZUwJdnM47K0BR3M8qokdl1M+vdg5m+ZLTBctNAzfwojb3m/MDIUQQ2cckXG3IcXEJQ1o7yjQ2G6qp2L3sDtZAvl6eQvUUu6wTGMGTMkBqB0A3U64HE1DislQ1Vy7Ebcp01VM3JP7aAGUuxX1RkSuB7kcCl5qV0tSSk65r1M/x/9fm0xvPiTlVRWila1/z7YWNwN+cNUR+s3d5f7Axu98gsaOgi2RFng1h1JbjUuHuaf72uyGyIQzDBfCI9upyCaFd9GXaHnNpKiuGA6xVAdGUDwT0+beV9O5bb6/aSnVKI9NXTZDcGr0Alxm8yejcNH+9YbYr8TZj0LXzfKnKwut1pVropNkijC4vKsR50uqfFAWBZ6xKsLhP6Xj6Omu4leBdhijIdrZ0KnB821uzGQA+/x/lgUFlFYCsigwauyHoxEAku+b45pXlHrTUlTjvanul36/mbNJmoBI0Urg0Sr7Kw54jN0njldJNuhTxQuVxFCjo5Bg/xExL02FzlTK1xTewCjtBptt1SWXOWSPB7ZYcM2O2aBOVZUhlUTBt+y/GYW7zrRKJEqAJud0J+rTwUZK/lnHcOoCaLnHGffrNmw7dbxwmkrdLLrCzWMS31N6lC5yIhzSEu8NSSOZxgfLiEDpp9VsOJxLus2vFgEZoqKfc3/vDeIclsWrYjncDe2GDmneaDoM8gtC7iJX4ljE80YEmNSJKAONiebcNkrd82TFx8ZdcuSeQpfEwMZCAdHIVj5Za6qMr3+eBOC4AraHl1vIdhNaGvLw8S6wFK4W80eiGkASqmfGo22429PCeL8oxidJ54Fn5FkXeVqG8AGKFo9gnJkUw= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:39.8210 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e07d01a-2ea3-402e-178a-08dd2c2f1006 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6814 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114450_383082_5B059918 X-CRM114-Status: GOOD ( 12.72 ) 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 Similar to iommu_report_device_fault, this allows IOMMU drivers to report vIOMMU events from threaded IRQ handlers to user space hypervisors. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- include/linux/iommufd.h | 11 ++++++++++ drivers/iommu/iommufd/driver.c | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 9c6ba7df3994..6b3b46e382f8 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -11,6 +11,7 @@ #include #include #include +#include struct device; struct file; @@ -192,6 +193,9 @@ struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id); unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, struct device *dev); +int iommufd_viommu_report_event(struct iommufd_viommu *viommu, + enum iommu_veventq_type type, void *event_data, + size_t data_len); #else /* !CONFIG_IOMMUFD_DRIVER_CORE */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -211,6 +215,13 @@ iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, struct device *dev) { return 0; } + +static inline int iommufd_viommu_report_event(struct iommufd_viommu *viommu, + enum iommu_veventq_type type, + void *event_data, size_t data_len) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_IOMMUFD_DRIVER_CORE */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index e5d7397c0a6c..77c34f8791ef 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -69,5 +69,45 @@ unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, } EXPORT_SYMBOL_NS_GPL(iommufd_viommu_get_vdev_id, "IOMMUFD"); +/* + * Typically called in driver's threaded IRQ handler. + * The @type and @event_data must be defined in include/uapi/linux/iommufd.h + */ +int iommufd_viommu_report_event(struct iommufd_viommu *viommu, + enum iommu_veventq_type type, void *event_data, + size_t data_len) +{ + struct iommufd_veventq *veventq; + struct iommufd_vevent *vevent; + int rc = 0; + + if (!viommu) + return -ENODEV; + if (WARN_ON_ONCE(!data_len || !event_data)) + return -EINVAL; + + down_read(&viommu->veventqs_rwsem); + + veventq = iommufd_viommu_find_veventq(viommu, type); + if (!veventq) { + rc = -EOPNOTSUPP; + goto out_unlock_veventqs; + } + + vevent = kmalloc(struct_size(vevent, event_data, data_len), GFP_KERNEL); + if (!vevent) { + rc = -ENOMEM; + goto out_unlock_veventqs; + } + memcpy(vevent->event_data, event_data, data_len); + vevent->data_len = data_len; + + iommufd_vevent_handler(veventq, vevent); +out_unlock_veventqs: + up_read(&viommu->veventqs_rwsem); + return rc; +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_report_event, "IOMMUFD"); + MODULE_DESCRIPTION("iommufd code shared with builtin modules"); MODULE_LICENSE("GPL"); From patchwork Fri Jan 3 19:43:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925855 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 45E76E77188 for ; Fri, 3 Jan 2025 19:55: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: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=rS8glOESCY7MtGcKcpxCCp7pQ7TodetWuu5N4pB4Knc=; b=GxPrsG8UtJTwxnLP+XNQR7IvW6 YP13qOmAulMMACZ8z0JP6iJSPa5rGSeiUNp8eiOjb3EhafMqagUVfDRPgr+UirqHDJMjrhJwezRwQ QZ6RuwH316lYumaGEB4SQlNxGRSSz6dIgb3FpPk6X19PUgyBk6+BfHD4zACHGD6vgxLbObQ3z+a27 k4w/rw2Rqr0Q8USFqNg4lCSETdHQnw5i7a4IiCggGjiXEoD8B2ICoQZV2aYsj5lmyb2Txp18LJnqd 6honwXUDGsjKa+x3M7OBnlTVzmvJq+2dTEndA4of/20Pn/Lm1w2diQcEgp+RuoBVrsfRQMVUFwHaX OPBcJiFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnlP-0000000Dsxh-4C1S; Fri, 03 Jan 2025 19:55:20 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbH-0000000Dqbr-2f91 for linux-arm-kernel@bombadil.infradead.org; Fri, 03 Jan 2025 19:44:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=rS8glOESCY7MtGcKcpxCCp7pQ7TodetWuu5N4pB4Knc=; b=So5q2kaSZ22/lWZYEmrgiX3Na0 NLZwxffZzDN2/Ajo4RQdnwSn5Nx1wppP5I45H8mWdBM5VG3pRoOr2Xld0rZA6gGJuqfpq2DqcqtAi 4iPNNCp1lFjRdfsG8qEcidHhFmImxaQnVpfykSz1dtzRdjuljqRFmnWE+qUzmyPa5hKuSiGTe7EG8 7GyYyHMj9tHmLU4ExQdHLeuZMEqBk/tImS7DZOO0M8GGZR65FfB+XM04sxXSmyGqTNRKaYEXD21ci QDqB0B4iCOU6CyDkA5dzhgoKdRQCroo+Bi0fqzavaxXYYPUNjOTa36aB+nnDIBuVVhYyDyWLLnRCe fv9ohnHQ==; Received: from mail-bn8nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:2408::601] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbC-00000008RFX-1WHc for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hgxfb+wi3wPFZz+/t1XECGDcOanw7XXqMADAP/AjSZ2r5bBVvAQcxJ/2OayBNAoDiukyu+46woWLWX5HZ8pOrCfiKTWbjNcKBxtijb/WA/g/2qodcP6eMqPkhy1/RUMgLBW3jpjHA/aAtb2e4s5uQOx/zhdD5Sp4s3yXAJd/cWI+OeCK/USfYqALee7dxk82OFAziKqgM5f4ClqBGSvQhhks4WQd08SKwaDVs+3DHf/xMn2WdE5aS0FxRUGZKSfR/Kkcikr48hdVdNbqMMMZG5ZJnPgFGiasACjTR8sIqnxg28I3CF934dObFVb/0sm7LeK+cyix/pI4F6U1T85ICA== 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=rS8glOESCY7MtGcKcpxCCp7pQ7TodetWuu5N4pB4Knc=; b=HOAcETORGSL3jFVRdkSFuArQaB7AJVauAdjvWCjmrdxWLj2ukMIvKP1iOiUMMX0rx2jlWEdMOhYmkNdR0PcJoqf+eYlW6JxYUCZPJnC6DnRrP+KjafWbwJ1R4Y4ZWs81nX1/uPOoyXJxIr/BnVHHWyN9V9qej5oLoL8pVclTM9Dl5IJzhrNGHEazZ5vsBWApZoGqK+lOoI9dwJwZQMvfPksJJB5NOjB0vnQlh7KG0wOmyng9WFmRkYuKXxCdE3ar//CKiXLB2OWxyt1lriUB9cUJwDGFYmDojAoG1hkvbZiPUe+xrRh6gvvcr4qzs/09eqrqWS2MqjzRVxkRDX8yzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=rS8glOESCY7MtGcKcpxCCp7pQ7TodetWuu5N4pB4Knc=; b=V9HU8vnt1ZrGUuq5PPE0/9FAxMXktTlvjgFlDHPWZscaoN5a3lRQN1jz77jQDz69a5nALKUqMchhTFO1N8FzzcK0T6dnfUZO+yyhikWopcrS6jZOEuqLC8cu7YdvOfkMHQj6DLqtSzdCmyN2cT2yCACBJfpWS6QzXaBRACzy9KWsaUHEVET/3aG5xtfe4qS5spGQJeA6V/2C6n3Cz9efd8/H9uvVODARuSo5imlAoHj7RKK21G3FBjVT9FS+Fr2cFnvhEvcWFXY8r3MOIOqYmAl6UM+cxAyyirqUB7spp0ym+Pe0B6GR9yWHhHz4slXi9/hdGQfz5XDOluUBTgZ4gA== Received: from CH0P221CA0020.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11c::21) by DM4PR12MB7743.namprd12.prod.outlook.com (2603:10b6:8:101::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.11; Fri, 3 Jan 2025 19:44:32 +0000 Received: from CH2PEPF00000144.namprd02.prod.outlook.com (2603:10b6:610:11c:cafe::b8) by CH0P221CA0020.outlook.office365.com (2603:10b6:610:11c::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.15 via Frontend Transport; Fri, 3 Jan 2025 19:44:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000144.mail.protection.outlook.com (10.167.244.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 19:44:32 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:22 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:22 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:20 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 09/14] iommufd/selftest: Require vdev_id when attaching to a nested domain Date: Fri, 3 Jan 2025 11:43:32 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000144:EE_|DM4PR12MB7743:EE_ X-MS-Office365-Filtering-Correlation-Id: 4dde4138-d5f4-4874-1eb7-08dd2c2f0b97 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: iUq8PUuu3x5iMYs81p05loWlOFM1LsRCSFzy2R+1HpK+TRNxaupSFleD/wRXLBITGWtXXAtmLTfH2+64a6ne+nUlu0ajJ/YPvzVyWSZPZZl3qnDQAD45UOFA6x01314YMno2I+f/QELE47J5HZGFVHypyM21RQXwHyiICGmPoZ/ALghR6H/iWxGMboF2xQS45f2msvxRUJm7sVeirP/0YM1jQooyir7zFgKCMuoNTSPZ9XuGzrUh2wq8tQylmusPN0jtXqxWVNXjWXGYiyyuY1U0GuDojf4p/gaaN+gSZJP6QwMoHdkhdPTfBwIUOETp+88Fyh6HQG+TBPg4tRU+dldXAXG4dGjSJUpIE2P5s4Q4QEYijwFOosn67yUk3cKNtsRcedTsaSCH5/VJaDTsRXaZkpTUy2LQUJaQ0F6Set1P19TVpXDHIWGHcJ2jsSc9Thr7ZyjectYMBjydssFnGHSlFYJe1eVL5/7kB1Z7z8CSi08ksay5k3VKQb/C6uMa2vqw5lMMifcFQtaVfUXfOXwjEfLK2aSH0/GJ7qYyqiGB/qi0B9Q0DXDpLatPFG51ydtqtBaf5QlGMK4QrKDD3/MrtCOdXh/n9HXMgPyKP/FIY5MdIvlDj5n5FYD/D7b/TwwDHQEoUvvucKeUX5iG+vCNQJcSpm5PeBfcc+Yw9JCH6ejfvrJ5sWxxw34yT1lcASg81xOXNyRgwrlggTYGIY6DVH1swtrX8kTMhF0svJwlbffXwOD9xYmkntvtA6FPcn2df2mwiTBGS7sdHlvZmQ33VukP0P4UwvA5MlD3kE2IQUx13t+m78iGo46pxIBF//kVUk3i3CHriz16lvQJbNIzUF3Zb1qa+2U8eICUiQeO4KpaOLxmITdPQLCuo+6+XtmW1b0ryHzsmrM7gC0HvWJUxIRhi3AsFpXXec01EmObKD8B9skuQjEUFuSaRb8goB+lLT6mJgAHuL33MYZf0/v87zMDkp5TxAW3L6e3CnKVQ6vVuqYJvQ81DsFqKY+bmOZihN7/2LxiRYgNdQ6c/WAZqf8ni0Np7sm5wB1aeM4eppnvaxB22Kn3JiXwJM0TneN7qQh2VFa+dd5KYAlA5Qxuu/9xhX/dOp1ln/mfUSQUE+E1l+HgvXbckVsmXFe+jPGxRuwXMN54tqsOtdFL0TFGwy8h62q5Z0SNGD6ocCODqDgqlj8bB8zF3Tn8baNysXS+GQAplWwGj+qZx/ykP7n10BfgLIZqF2FuiM0/t77+ncQibJOQSq82ehZ4OO0Uyb/nXsz0KFrG7OiQ+7C0HGw4YzNAbzhFTGOLIyZVUzUG8SOuU35gorkTIEZHsiPvZGYsrTYd/C6U8GtiQ+Q4Iec4jPTddQ+DzJuQpfclbfY6ojTBgGWxhJWRdE3X1ehfeCI4ZP99E+3DFu30wXZHfrCHNAdvSM36eaNFBb/2atOrGwXO1uOPXw8off4n3KuW/d+LKKkRZfIRrICUjvXK2/OpKR00oGXHK44I9I7Qy7E= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(36860700013)(376014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:32.4454 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4dde4138-d5f4-4874-1eb7-08dd2c2f0b97 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000144.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7743 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_194447_208432_058B8371 X-CRM114-Status: GOOD ( 13.96 ) 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 When attaching a device to a vIOMMU-based nested domain, vdev_id must be present. Add a piece of code hard-requesting it, preparing for a vEVENTQ support in the following patch. Then, update the TEST_F. A HWPT-based nested domain will return a NULL new_viommu, thus no such a vDEVICE requirement. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c | 23 +++++++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index a0de6d6d4e68..d1438d81e664 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -161,7 +161,10 @@ enum selftest_obj_type { struct mock_dev { struct device dev; + struct mock_viommu *viommu; + struct rw_semaphore viommu_rwsem; unsigned long flags; + unsigned long vdev_id; int id; u32 cache[MOCK_DEV_CACHE_NUM]; }; @@ -193,10 +196,29 @@ static int mock_domain_nop_attach(struct iommu_domain *domain, struct device *dev) { struct mock_dev *mdev = to_mock_dev(dev); + struct mock_viommu *new_viommu = NULL; + unsigned long vdev_id = 0; if (domain->dirty_ops && (mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY)) return -EINVAL; + iommu_group_mutex_assert(dev); + if (domain->type == IOMMU_DOMAIN_NESTED) { + new_viommu = to_mock_nested(domain)->mock_viommu; + if (new_viommu) { + vdev_id = iommufd_viommu_get_vdev_id(&new_viommu->core, + dev); + if (!vdev_id) + return -ENOENT; + } + } + if (new_viommu != mdev->viommu) { + down_write(&mdev->viommu_rwsem); + mdev->viommu = new_viommu; + mdev->vdev_id = vdev_id; + up_write(&mdev->viommu_rwsem); + } + return 0; } @@ -861,6 +883,7 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) if (!mdev) return ERR_PTR(-ENOMEM); + init_rwsem(&mdev->viommu_rwsem); device_initialize(&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index a1b2b657999d..212e5d62e13d 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2736,6 +2736,7 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf) uint32_t iopf_hwpt_id; uint32_t fault_id; uint32_t fault_fd; + uint32_t vdev_id; if (self->device_id) { test_ioctl_fault_alloc(&fault_id, &fault_fd); @@ -2752,6 +2753,10 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf) &iopf_hwpt_id, IOMMU_HWPT_DATA_SELFTEST, &data, sizeof(data)); + /* Must allocate vdevice before attaching to a nested hwpt */ + test_err_mock_domain_replace(ENOENT, self->stdev_id, + iopf_hwpt_id); + test_cmd_vdevice_alloc(viommu_id, dev_id, 0x99, &vdev_id); test_cmd_mock_domain_replace(self->stdev_id, iopf_hwpt_id); EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, iopf_hwpt_id)); From patchwork Fri Jan 3 19:43:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925858 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 C933FE77188 for ; Fri, 3 Jan 2025 19:59:07 +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=jffRvO4oObA1ZjnpZ/XbEvugjl9rVwaoweriqOMxav8=; b=CcAx3Tx7YOuVhcBmzH2P3ZiJCV RUxCt49JrIXr8laF+o06TLdR/yzosYo6IjZCCcU/b+tFimusKCBpzu3RHToxS6EIwUM6Qc7PPMRGx GOq+YNMdYRXXm74XhCd7Kr7yj+RxbNvLuY6WoZMDPO68GqDMluyKOo7zOQGwwz/m+6ibYrLubVdMq smWvhmgChNYBtFnbK8dJLaeoInqrt7YeYPuAQ1VUsTKg63zENNIcKrx9I1Ee0sn7mAtk405ndECUU GQ5kczp72BO+Lwrr5+H2unOt5I3iz7v9gUUgblssD9owxvzDTXgB0X5i0w3XbVjopUS/vu1on30Hl zl5azo6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnot-0000000DtIn-05Uh; Fri, 03 Jan 2025 19:58:55 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbO-0000000DqfU-2OmG for linux-arm-kernel@bombadil.infradead.org; Fri, 03 Jan 2025 19:44:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=jffRvO4oObA1ZjnpZ/XbEvugjl9rVwaoweriqOMxav8=; b=eTtGuUrL0ar1jd+Spdx+T3+Kik h4XXd2ngjLptQqZWhHNiqKEhiz+NOwgeoT8fC5taIlCPH7FNBKi4q6jSAShQF2PrJot4QEpnzaRz/ OWMTCIrMZt4sECK/5KU8vztrC7bcoqeqy3sbc0u4eiDuJAM8OT6zQh4MHgFtmsnQiacGjveIZw5E7 MwNPOezCfyFC12OX0RzTrJ0ABhmqNQgTSxVU9k24lbQQ98Jf6wiQ6stEy4nFNE5Fy4+zsxeSCS+pd irssCmlw7H0FXFp/eyI7zVSG6dTnBwsMzuUhWwjHj6rWwcydNKCDy4NRJYOlkR6JEO72hBkUlx87k dlYmCEFw==; Received: from mail-bn7nam10on2061b.outbound.protection.outlook.com ([2a01:111:f403:2009::61b] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbL-00000008RI1-2vgV for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mKDXf9SJxwbygkqpFikc4P6vGFDeeuPGzJDWIUjT/GIscZOoyy5OTjywBnyTaSkZsMeJbxG/Y66JjR4/T/1F1GHeUuxweVCLNDLY2IKE1UCDiUxg4rRb3yEU3TI0jrE/SrkCHmLr+cC/mc+GWn0s34tfZ2mTkBinifBhjRbW3h65e4nlvLriszKOcrILtZBq7YG72ixIIBpNFirtedQDhNgbJ7MkIyYpHFaTr6GPLq6mi9PmS/aZgL+uAHZ0sYbsAFFHberTA3mnvS34iervdvjPPk5Ewo9D+QoW/YHXMFwLLd9SZNGUMhYWl5Wy7lghN5i+Gol3DoEOntRoQelSEg== 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=jffRvO4oObA1ZjnpZ/XbEvugjl9rVwaoweriqOMxav8=; b=k1ku9a3BXY1GBeL2PuyQKtS87UH8ufszXdAwN4095VXpZsMkouLddS6ZiHwxeUIjtxLumF8FIpllO4EEf7AdEBuSsJZJt6jPqn0Wk6s6H2S7XNZN5XBll85O9sRGu51+cAc0POXVHSDqlnDp8R/saykywXz3813ht2fKJ7tEBJr6ecMDSlJvhvdw0sh/5Zu9MBsnSuoY1zXYrfsJTi0xiw4tiv/Y2svod7AAxUNUmpPFVwdMv16ZPna8GTQ/PR1dL9b+RjktJ/sfrbpGehOKaicz8SRa7GjzqnEx3OBAyeZ990DtP9z3G3HC1wXfC3X8cUOquSXerj8QdkW4msZGQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=jffRvO4oObA1ZjnpZ/XbEvugjl9rVwaoweriqOMxav8=; b=JRsQHuqbV2XmsZluGf4iHhzsHsUa3S/x2JdaVsMeOOolhOdJf9w5J3jc/xrG1zLXbHtIVXiXUfvXl4XVHZgxE/5x9zC+olqeCXF6DUEOeaXOsLwXoHIrbPS+FSgzsBvKe0EmArlKkWnQoCD6A+TrErwgFcZaJBfCW1NOd3aDJLZaPuRyAoYPxSuMEdZUraw5pDZvWmpaJaDTb5ujwTMWtJvRG9DQH6LUN/cNnwwkJNpDgjCYnVP4lUe1koZw34LC8NmZ5YJyQfCXlkza1NN4dvsEkYU/Mbagoep2kkadbHDVjWtOPerKM9McejczUOLGeRlEP/OXcRZlUQS8vXWluA== Received: from BN9PR03CA0743.namprd03.prod.outlook.com (2603:10b6:408:110::28) by IA1PR12MB8406.namprd12.prod.outlook.com (2603:10b6:208:3da::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 19:44:44 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:110:cafe::23) by BN9PR03CA0743.outlook.office365.com (2603:10b6:408:110::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.11 via Frontend Transport; Fri, 3 Jan 2025 19:44:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:44 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:25 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:24 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:22 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 10/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage Date: Fri, 3 Jan 2025 11:43:33 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|IA1PR12MB8406:EE_ X-MS-Office365-Filtering-Correlation-Id: 04249f4b-68a7-4e3d-6c60-08dd2c2f12c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: hhozgeyQ+TpDRdxLNw6p4AERXwWT3QgsQRMNuMz3D8U1oKfQitBjZ+JDGkK0eW/pfXT0tZ8FDGE00CMpLJNxjfj5JijBE1SkKQZadxfkCz0Xxhna5Ql7OOqIQpvy+fqwd1WUPIu2a9Kge8RWYPCr41jj52uuHFKbnBww7QHTBaA3YU4RJoTpUXbklDYUzRNfSsAiCEncaP4krSatP3XlqRuuhp72wXY8LOcjEtj0qnLVygXJ5uagukA9TBW+fxcxo1FjkDfOh0+IkPddbfYdO6pG28AbeMffwr34eu+hdxF/IS1ZgPshhQFD363Zfxds/Yr0sXFZTL+jgOUQW1rz8oBT8yHOpRpBYHXtogKehjxq1QJeAyMKK5ytpbvL7cw3sW3sxoD+Yj9YwnvMimVwYWEHtGFPbqnV/W65ziZd+heasQaZ8TgGw34dsOmrY6Lt69Vs75o26rRv5TOcTmKzCMiomM4oVVKccdoBYA3+AxXi9FZfpz0hqf8YE/HSw6El6slUR4bVhz46GEo1/QYsI1R5BjKUHGYj+uxKe0XcM5lJBgeLQdFe/tWWhmx1XgX4rm+zQUs2DHmUKML8wo4PeMjx1tPf6yTx2VZ9ertZdnawbFXxXj6EhlCzNI/dCGY4o2jsw1WpV8BPLAFxD0A4KsJcldrGgNAhP9bxUvC/NbKYgfavQvtpYguLMp5OxCDNEywMpnesY3dWTdfYZxyzFTETsV0g+eGeJhJz8sgaS/ktkbttpoWW68jjhngamzvngG41hIv7UMACh2bCZWdIYeXMj9y4oos9E4hzLeBxVWRNLRCBXXCFuv7gAGxVe/gvJ9mHbpwWvk7jaw6HGpKkasM8GHQFPylzYOrwrXBig3q8lKvMKvGazXeimXZ9mC4VfU55qkI82x/Ua0zDDrQELefc6dviO19WUqhan8NLmqdrJMvLz6toM5AiTunPijsypoMZ1nzReA5/5a3ROv1IVK9hZQxC6lzkONMaC8aCHN1u3AChZZXXmIElmXeVe/jCclRf7UMg/6QfsnJgIpL5AoFwZPBzYFkSO/hxM8R5k7fiT7+63TUBDeCmDOyt+FdY8rwP80dhCHB0KmOoTQWnQ5GD7aWQDgJffyU39q3uZLZxFbxV174oSc08b+bzv8YcQscPBkYX0Ag0qBZJ7ZxYEF4BL9xk+7eWa9i+dILH6YUKkQZEJf99FHe/T3ujeLvTtOSXMLW++7No2m9Ken5onvckQh4ti718Qb2mn63TvuEu5GL0ilTasVFZ0LSiSjM7g48mRMdIY95KCw1S9CK/lDuRxvKUH8qkNwhDZIhZKgpLZQOWP2SQrWshR/XLDUHOnEdlPyxyQTZ99XLaGOzNrhBPunxM9R1Jm5W3B9APseJ8DNLKo58hN6SF7QrezG3TIC7+vPprsU5ZQmDT79OxD7j/FN+Keluedu1GMqsYjdLf6EHfH+dI9wTslF+S+PLTxb2hAfyXzBqi7byTvyfVSJv62rp5dNbduqKSHa8hBkk= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:44.4460 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04249f4b-68a7-4e3d-6c60-08dd2c2f12c5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8406 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_194455_915427_11B069D0 X-CRM114-Status: GOOD ( 10.97 ) 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 The handler will get vDEVICE object from the given mdev and convert it to its per-vIOMMU virtual ID to mimic a real IOMMU driver. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 10 ++++++++++ drivers/iommu/iommufd/selftest.c | 30 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index a6b7a163f636..87e9165cea27 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -24,6 +24,7 @@ enum { IOMMU_TEST_OP_MD_CHECK_IOTLB, IOMMU_TEST_OP_TRIGGER_IOPF, IOMMU_TEST_OP_DEV_CHECK_CACHE, + IOMMU_TEST_OP_TRIGGER_VEVENT, }; enum { @@ -145,6 +146,9 @@ struct iommu_test_cmd { __u32 id; __u32 cache; } check_dev_cache; + struct { + __u32 dev_id; + } trigger_vevent; }; __u32 last; }; @@ -212,4 +216,10 @@ struct iommu_viommu_invalidate_selftest { __u32 cache_id; }; +#define IOMMU_VEVENTQ_TYPE_SELFTEST 0xbeefbeef + +struct iommu_viommu_event_selftest { + __u32 virt_id; +}; + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index d1438d81e664..7c20a85ed142 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1631,6 +1631,34 @@ static int iommufd_test_trigger_iopf(struct iommufd_ucmd *ucmd, return 0; } +static int iommufd_test_trigger_vevent(struct iommufd_ucmd *ucmd, + struct iommu_test_cmd *cmd) +{ + struct iommu_viommu_event_selftest test = {}; + struct iommufd_device *idev; + struct mock_dev *mdev; + int rc = -ENOENT; + + idev = iommufd_get_device(ucmd, cmd->trigger_vevent.dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = to_mock_dev(idev->dev); + + down_read(&mdev->viommu_rwsem); + if (!mdev->viommu || !mdev->vdev_id) + goto out_unlock; + + test.virt_id = mdev->vdev_id; + rc = iommufd_viommu_report_event(&mdev->viommu->core, + IOMMU_VEVENTQ_TYPE_SELFTEST, &test, + sizeof(test)); +out_unlock: + up_read(&mdev->viommu_rwsem); + iommufd_put_object(ucmd->ictx, &idev->obj); + + return rc; +} + void iommufd_selftest_destroy(struct iommufd_object *obj) { struct selftest_obj *sobj = to_selftest_obj(obj); @@ -1712,6 +1740,8 @@ int iommufd_test(struct iommufd_ucmd *ucmd) cmd->dirty.flags); case IOMMU_TEST_OP_TRIGGER_IOPF: return iommufd_test_trigger_iopf(ucmd, cmd); + case IOMMU_TEST_OP_TRIGGER_VEVENT: + return iommufd_test_trigger_vevent(ucmd, cmd); default: return -EOPNOTSUPP; } From patchwork Fri Jan 3 19:43:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925854 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 0EF4EE77188 for ; Fri, 3 Jan 2025 19:54:21 +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=owksryRUWHVUTKc9EwdqafuNcbtKA7Z/YWtyFiy6EL4=; b=dp/2CfqUaVOfBv6hxR+5YG0pC4 L032NL3rLiLmNBdLhs8yfofosv/VJC/LFAhp58GlxGx4cTCvutGCRsQ2evjfs4/GJTecw5jaO9vmZ GpE1Cgj2MCUZTtOnB3lpgQmioRRBnj+II5g3lffpSTLLasNxdSse4A2Sj01cfBgm7/I8dT/hKpdsh iBq23Ojhdv89V8I0UfnuMhJFTknl1zmT6KQtluDWfbsK7LOjkV1+jWawBjaiLKkcZZ/1NO4fKDO7+ 6f66HyfsMILhUcDkiLn40PSK+e02jk874EAEE4n/Kpf4R8AebTp/xEebJ61KH9VYGZwCw1xx6w00D atdVXaWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnkG-0000000Dspt-1dOE; Fri, 03 Jan 2025 19:54:08 +0000 Received: from mail-dm3nam02on20613.outbound.protection.outlook.com ([2a01:111:f403:2405::613] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbE-0000000Dqa9-417J for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:44:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aXlG2YU4BBeEmSVJxRK/6h0QVC0Q+hO785WTI/zU5Pvf/WNzeKColp2Tu6P4yZvoNHGvgAclT8dfCwhtk6QUorbCtSNv17rLBmNm3ZYnJ7FeGVDDIJOmBRsBzyhjByrRYtC5Kj/Idbe1+YWvD+VYX+gtz2o6ULX7JewVCGyJjgSEI33zUt1AuqPo9bXIiP47vHZ/cJtLNI2kRAgj0i9uM/4kQzO/6ATMV5EEOpNkULdik9d+YYFoaGEGX/vEWwbkPjuMiJXqG7DcvW9uuyGjCXgamn2vqBPmpOHZBDblyU4xscqgjJWuHHTKHNA0gwk7jH29QYHBEcC+JNPv21XhOA== 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=owksryRUWHVUTKc9EwdqafuNcbtKA7Z/YWtyFiy6EL4=; b=zGvquuxxoJjFesvvx2FqkJu5LyMK9SKhzhBT4RLl62GrrkZxfF4jwLg+XMzUp+b8COhjeyA2jAPd6/BMdiyzIIKCX5ZDdSq15YCr2FVIvdOcKpZZsmJLzLyxrRPKZmrw5T584jVk4AdYeX04PO69B5iWMusXgfSkrnGlZ+ILz63HK9dVsvN+uBLM8/Kwt5zkjAP+ZKCVY9Ik+AGAaai+Xnak+DkWN4O7CgQEUO8WHMNcjgpRefJ8oD+C+7Oe4BdqsLRT3/Vuon7yKsesl4kGrSoin7X6davPb2dtqQ1ZnhTqAiDr9ekLARHqOtCIGyk2UmPyCxjUMVselG8xET/9xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=owksryRUWHVUTKc9EwdqafuNcbtKA7Z/YWtyFiy6EL4=; b=t+XnqttYdALSWCrzHsjfBbDHbKOBhFpehZo5pCB7Icsj8S4NFOR6RlYV1A61SU0hKL2/ohj9vlfr0FscNgT59BDN9dqfboPot4IoK8lr+lCpI0qmTj4aW9a+1UY0hr/WJhjzXcuIDE0fed21Hw6vILqTd7yIcgwr/VQlE3hdEL3VesNMqJme581DJlVAHCpcbJU+W6i6T8+vfdf4kT277wF65gG972fxhXdVNT78v4jNX4pbsYTIXKz+1opp/M9lqpFlzmWOJ8p7/rtgjtCzfKr/IQty5KgNznyBuHNP4JQTC0KRVnxZGRgtxVzm3LYwzgSym1najD/Rge8cJwWqiw== Received: from CH0P221CA0002.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11c::10) by DM4PR12MB6111.namprd12.prod.outlook.com (2603:10b6:8:ac::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.18; Fri, 3 Jan 2025 19:44:39 +0000 Received: from CH2PEPF00000144.namprd02.prod.outlook.com (2603:10b6:610:11c:cafe::7e) by CH0P221CA0002.outlook.office365.com (2603:10b6:610:11c::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000144.mail.protection.outlook.com (10.167.244.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 19:44:38 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:27 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:27 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:25 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 11/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage Date: Fri, 3 Jan 2025 11:43:34 -0800 Message-ID: <4ce5fe8c59a40fff27b27d7e81fd5d80941f2909.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000144:EE_|DM4PR12MB6111:EE_ X-MS-Office365-Filtering-Correlation-Id: 36b49972-e3f6-4ffd-42ae-08dd2c2f0f66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: BXEj2iDSGj4PyBzDAAsUoEOk7MzP8pSTDrMNyNm1PhY9dvIGqW8/kS3NDZ0F+Ym2hJCZIqK+sdXa97sphZQhm7TCc3MDSv2LycBZ0PIyrFkPEtVpjnqmwlLEJXpWooCJh1MQ3qLTUq/2Ohd08YmgUB/6KDggU8Vb/hdZreHYCD+RFSAGD8k8NDljq56m+7Trxeo69D5Dd3WjZNPGfq/sAfsaxyNyqf18RV1f1GMu4O2m+5zkqsTRjaIRmSRhmn64hf0OgeH4KclVVoZwhuQipgGlIn82t1PNUFnSARvORUcB1cV5hpOeIs+2zLZD71/oHbMYdGbYE4JFY0LdcXGndCE1a4MDasGslEAf4R14cDrnYajdhM4KcGzPPfTmNbj2ZCcYOnAtOlYbJv5WK6xa+LsIitvEeo/VrmHfyX+Cy2t+w7/Xpm/I3GH2piF+IULdoHOdEXQZJFIthQ9N1nJuYg2MFyeFxLpmiZJZZH3dvd3nUFC9C8vNU+CTxaEjvmrJf7eIrXcVVc+THSJFwe09F3aipZjTqoEGuD9nclxRH2pbsfsN70kOloe17wt7Js6J9JplKa5/9CRnM/C4PCfwjH1zjRoaBGxrPXkyHObGyDOQI7wSzf4y3R4eWAWUrYSywfKVsaOqTXIFCfBmY4OnMoHLjWFD7v+v6hC9U2TWTcWmO2SxGVrIojEXrEpmZfijL1oeDPIvdi/Oae+VvBRzGRsbNkaLZba3Z6jKy/z1HWA9xSg90YSpS7IEsYuvPe3oxcBRlOaoJO50+X30RZcuxtLVzTEJrklu9j22zh5rLHp/uudeZb+JmXuIIWEOYwcPt7fhNLMLbif2bwq9sWNSB5DxjXuIjKcXd6DOupqxA/cMZKw6z4xSHHjSnlktyto8piRw1eiVDSYR3B+Q5HlRrxDMDNi9hPN0JftcvqfCRjoaXfFLOnVyZzEa7tg3RL/DFDlR0/7HqbJYTt/Pc3QYhvz7bMIf9T4acRVSv7nHTP6iGz6GNXYgfHvDPboBSpDfPhnNs52yaP6zfCcEMCEFcahTMEOLfCvvnXSx7JliHdvna7m2dHak4QaCYrwZ7HNShVwwspZTklc+qw30i9RtQaqcWKFTwWgmXmXDKAvklsimXqxZH8mi/erLEeYKC9W0KQXzZcZkWlqYQdmeEBJjK2VT4Xt8IAYFbedB4R4ElMzPL8omgc0uyBVt+SQq6otB35GHDh8xpy+EAAd1o9GlLexDla987PbnGvxnaSfJsET67ao47/IGrbZ23hToDqD3irpJFIyRaGJEAjYSpp42Cf3swaccXFTmNpyiSibBYv7diIXXLnTj0nuzHVfztD5Rnp1VHKvIEEgwP9eCcVQF18Uw/V05Xiz/ywLLWMRSYul9cjR5JxEJt4eU5LSu8Qe4j0qEG93z7eK5L9TlmvT+ZACGe2c1vNPlUsssLoQwuOWGLmuoq7n/3LHhkRn99EjHOz2d5TClQXw7H30OH0BJJ6wue4bsoPtvy9qvNDBN6Mg= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:38.8360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 36b49972-e3f6-4ffd-42ae-08dd2c2f0f66 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000144.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6111 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114448_993540_402DADE7 X-CRM114-Status: GOOD ( 14.48 ) 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 Trigger a vEVENT by feeding an idev ID and validating the returned output virt_id whether it equals to the value that was set to the vDEVICE. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 65 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 22 +++++++ .../selftests/iommu/iommufd_fail_nth.c | 7 ++ 3 files changed, 94 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index d979f5b0efe8..15cf28b88332 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "../kselftest_harness.h" #include "../../../../drivers/iommu/iommufd/iommufd_test.h" @@ -936,3 +937,67 @@ static int _test_cmd_vdevice_alloc(int fd, __u32 viommu_id, __u32 idev_id, EXPECT_ERRNO(_errno, \ _test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, \ virt_id, vdev_id)) + +static int _test_cmd_veventq_alloc(int fd, __u32 viommu_id, __u32 type, + __u32 *veventq_id, __u32 *veventq_fd) +{ + struct iommu_veventq_alloc cmd = { + .size = sizeof(cmd), + .type = type, + .viommu_id = viommu_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_VEVENTQ_ALLOC, &cmd); + if (ret) + return ret; + if (veventq_id) + *veventq_id = cmd.out_veventq_id; + if (veventq_fd) + *veventq_fd = cmd.out_veventq_fd; + return 0; +} + +#define test_cmd_veventq_alloc(viommu_id, type, veventq_id, veventq_fd) \ + ASSERT_EQ(0, _test_cmd_veventq_alloc(self->fd, viommu_id, type, \ + veventq_id, veventq_fd)) +#define test_err_veventq_alloc(_errno, viommu_id, type, veventq_id, \ + veventq_fd) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_veventq_alloc(self->fd, viommu_id, type, \ + veventq_id, veventq_fd)) + +static int _test_cmd_trigger_vevent(int fd, __u32 dev_id, __u32 event_fd, + __u32 virt_id) +{ + struct iommu_test_cmd trigger_vevent_cmd = { + .size = sizeof(trigger_vevent_cmd), + .op = IOMMU_TEST_OP_TRIGGER_VEVENT, + .trigger_vevent = { + .dev_id = dev_id, + }, + }; + struct pollfd pollfd = { .fd = event_fd, .events = POLLIN }; + struct iommu_viommu_event_selftest event; + ssize_t bytes; + int ret; + + ret = ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT), + &trigger_vevent_cmd); + if (ret) + return ret; + + ret = poll(&pollfd, 1, 1000); + if (ret < 0) + return ret; + + bytes = read(event_fd, &event, sizeof(event)); + if (bytes <= 0) + return -EIO; + + return event.virt_id == virt_id ? 0 : -EINVAL; +} + +#define test_cmd_trigger_vevent(dev_id, event_fd, virt_id) \ + ASSERT_EQ(0, _test_cmd_trigger_vevent(self->fd, dev_id, event_fd, \ + virt_id)) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 212e5d62e13d..c225f6e5108d 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2774,15 +2774,37 @@ TEST_F(iommufd_viommu, vdevice_alloc) uint32_t viommu_id = self->viommu_id; uint32_t dev_id = self->device_id; uint32_t vdev_id = 0; + uint32_t veventq_id; + uint32_t veventq_fd; if (dev_id) { + /* Must allocate vdevice before attaching to a nested hwpt */ + test_err_mock_domain_replace(ENOENT, self->stdev_id, + self->nested_hwpt_id); + + test_cmd_veventq_alloc(viommu_id, IOMMU_VEVENTQ_TYPE_SELFTEST, + &veventq_id, &veventq_fd); + test_err_veventq_alloc(EEXIST, viommu_id, + IOMMU_VEVENTQ_TYPE_SELFTEST, NULL, NULL); /* Set vdev_id to 0x99, unset it, and set to 0x88 */ test_cmd_vdevice_alloc(viommu_id, dev_id, 0x99, &vdev_id); + test_cmd_mock_domain_replace(self->stdev_id, + self->nested_hwpt_id); + test_cmd_trigger_vevent(dev_id, veventq_fd, 0x99); test_err_vdevice_alloc(EEXIST, viommu_id, dev_id, 0x99, &vdev_id); + test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); test_ioctl_destroy(vdev_id); + + /* Try again with 0x88 */ test_cmd_vdevice_alloc(viommu_id, dev_id, 0x88, &vdev_id); + test_cmd_mock_domain_replace(self->stdev_id, + self->nested_hwpt_id); + test_cmd_trigger_vevent(dev_id, veventq_fd, 0x88); + close(veventq_fd); + test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); test_ioctl_destroy(vdev_id); + test_ioctl_destroy(veventq_id); } else { test_err_vdevice_alloc(ENOENT, viommu_id, dev_id, 0x99, NULL); } diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index 64b1f8e1b0cf..99a7f7897bb2 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -620,6 +620,7 @@ TEST_FAIL_NTH(basic_fail_nth, device) }; struct iommu_test_hw_info info; uint32_t fault_id, fault_fd; + uint32_t veventq_id, veventq_fd; uint32_t fault_hwpt_id; uint32_t ioas_id; uint32_t ioas_id2; @@ -692,6 +693,12 @@ TEST_FAIL_NTH(basic_fail_nth, device) IOMMU_HWPT_DATA_SELFTEST, &data, sizeof(data))) return -1; + if (_test_cmd_veventq_alloc(self->fd, viommu_id, + IOMMU_VEVENTQ_TYPE_SELFTEST, &veventq_id, + &veventq_fd)) + return -1; + close(veventq_fd); + return 0; } From patchwork Fri Jan 3 19:43:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925868 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 01579E77188 for ; Fri, 3 Jan 2025 20:00:17 +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=13eNH/j23XIsjdSroVruvt51chchriTKTYTuwZ1uLbI=; b=lZcAgZayFkD2/B3j/sZfCZQDFe QmlPyHTKPDg8QDZyJHPsSB3gqPyxROwK22H2ZOBnQMcbDiP6rlhInLw6Mq5wnor01PmXSMT6hXuqn M3uQ5BDXum+QwMwGsJctSeBuwdRUceqfDT8NxhzM7GX4cu8XN8Y1THcA4/6lKkm/U5PVBe1BLuyqc qxiFBTNs9EAPa0uMpFYdu9SBm1mu8v5EhupJ/1eSB8QyFSZ9tJ/DXXctTUCQWjJGRARCT3aEVqlIG 3fBpw/SzXO1U4MwugMBEf7MnZydC1RP9bRSLCW2s9BsextmMaWPBdc6Fur6LQHq/kDURyVS9mOvxB 6oBrWvrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnq3-0000000DtX3-2OHs; Fri, 03 Jan 2025 20:00:07 +0000 Received: from mail-bn8nam12on20610.outbound.protection.outlook.com ([2a01:111:f403:2418::610] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbR-0000000Dqh1-3fP3 for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:45:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qsCuU4xPddAMU1XAtsvn6qcCdFL7/CT7fl0LTJVt3gfVsUW3ToisKZiMeBm3Bcl0dGED5uqV3tF+LVUrqTe12nvKp7jljfKqx2+LSfiO3PZWyPN3EnfirKLQECIZwrFMexJ//5totK396AqIBnKkeLy/X3n4w13i4YPdIfG11OY3XShSv8y3hlDN5X8Kl2SlPlZqmnsd+DSh0KnhnTM0Mb+1Ny1GAdBW3E7c/fZ4YPJ/TJ2rWp1/6FbaOyK6QXrlEv7RcrJ2/IET0MGIZc1HNzw4JVs5ZyTTCseadC/NkLLrme1lNr397wRg3yuL8hJ6NHea7QKDmjdoWosxgKKmTQ== 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=13eNH/j23XIsjdSroVruvt51chchriTKTYTuwZ1uLbI=; b=uMHiosBKzJ8vH2Yfgj+OkzWNBd5SL1GLktSHXmarr3VpGoyUFTQPPWAav6QiZR9dekqYV5OWUIpEfehhGdXjPnZAFDa0o57wp7JU4EQWWE0hVebeleHeeo8cLeS3Uu9i8AQSLzJXvSt6T02JBe4oT0MgWOpzZfXXnyxhhjmbPoLEhNF0RlZgN9UrPeIbXSeQStw2hpFnmsXCyDvIRcu++vAY0N+XcGM7B4TTbzEUgKqHKMWABP/0529qWIy7wrlKIWpRuVu5FYmDgWclkWLebHYKxwaet7JE/SXPgqlP2xC7lpVlLGEf2+fN2N11+zjghUG1qKc5zXPNTfWC6x3arQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=13eNH/j23XIsjdSroVruvt51chchriTKTYTuwZ1uLbI=; b=U0lcETyq54zKq1oSJtBepg3rZ9NGJn55lLO2lk0j4RdOsRUcajNo/5uRGespeFn7FwPKJio0H92Gkw0JZpM+YS7o9sK6kfpCWucuT33PQwMezuMEVG1Go8xFxszrbuFhqdvCb1S2/TNJ9gMx9YUSGpG3/qQGIW90beD46kLk4++d5gYG+iMcg0oAqyFJNbZ3vUH+X/QVpBrvYCFE2yPC9mtxddCmndXzZncl/S8gRZcGofTAgZ9HfWEAW9yHW7pWwmMnZvsBDgNg0xX+FP+ep7lQKDhymmUEBIo6wzTLTikmZSQmNyXDoxLUFAKcHoVJujdkd27lEDbDEuYc8JklNA== Received: from BN0PR10CA0004.namprd10.prod.outlook.com (2603:10b6:408:143::18) by MW6PR12MB7085.namprd12.prod.outlook.com (2603:10b6:303:238::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 19:44:48 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:143:cafe::23) by BN0PR10CA0004.outlook.office365.com (2603:10b6:408:143::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 19:44:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06C.mail.protection.outlook.com (10.167.243.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:47 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:30 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:30 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:27 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 12/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ Date: Fri, 3 Jan 2025 11:43:35 -0800 Message-ID: <14ee2076bfd7df1d2f7a3322d7f24a71b7417867.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06C:EE_|MW6PR12MB7085:EE_ X-MS-Office365-Filtering-Correlation-Id: 39f2d92f-8661-441f-177e-08dd2c2f14dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: NZyJxisMtFFNe7stZCCuvJEMP5PD3l+LJ0PxUpyzd63BvNK1u+nG4tuksCqPAjjyeFdm9lDEDGdrFpyxkubY7l52G32FRSWyM5LDW1CzNwY7FrOdKV0BYy615JExooyWASLSAdYhgddaChXlPUAkumglkcRNOXza8yDw4mhu8WQBYGZAr4XmuORHiEGt7P6tfPN9lacNpfqnmTQiDBpUyFnaO3lqX244hw2GfTq40th67eLjtEPTSIK/xUSjOKtctKdzTQiO8A2PWZH+zwxwIrQANPeCuBjpqckME6RwVUk4KNBrrotWVV2yrSPvXi2MOlz+niT2U3JmKLaUeB5degQXImCUNF9QP+I72c5CRKpcCrXhD146kYpHtDGV3OLgmjgAyEKV31Cqk6tv3ju8xioRkF4dcZCVkDg9RnwASJuKnfU0zTpizM9Lvdl8U+8/AV2F+YP1j21gDOv13+hByRm/7alMZmSQPNYiy06S/6xbU+oqHedGEKRMVFMd6jcKaX3QE1/QT5goi7uJGtKaYbB8vVOoSucw1m7iwVqFdgnclq2iZ5mkm5llhtGpvmr3jCaGvmrs4NUXOhzpATmCIMcTjh0jiG5q+IUsa2lXiaoLIfHVrdi6o1aNteUbZ/VmoSGRifvku1UUTrp7YyRSZmH+0cv1mgWdehAAifNBUQeOFUWj0NIjxH40N99nZTyNpzMv56O4kcQmHvqwoHLmlgqyOoySq9ZcFIUhZW3I8Bx8lu4+EOEjE5uS3My+X1JHnkShbSBgE6mBeeoqMP/ioaO5Yle+pTYB1KyX2LlzKT4nC7mbd40oGpijx7+LTCmgvXhQcUm6rAl7PUw1stK/BZQsBlvKnqlxxLN1uhqeGPV2pRk1B1sDnFoh1aXs/dLgl8y/KnYeeeCqTGMsvso0Q62bG+/GzIVWSWoQT4ZwGLdmriuAO04cDCMeeEecREPLGT/7Vzqc0rMZ4g/lv/+1KKBfOFGxzqswPZG9JAMjeyjM9jC0VH3UmgXn6JO/h4u7ErTwgtbrB1CnIB36YR61f6rt+oDO8Z6aPVbZtAaXCpZsAlOWlBMfSWaj8vvunZTgFUs9nzS9r+P6oEfazLTxdF+wXmprgNgRQTkZrygNg4jUZLJloUSqvSqqCIWe3Rg0BNx4O8Gr6BjLCzS5cjVpdxcF3V4QUoT+vXiVH3qj1AOPqPgl4b6nMvsJES5SMgedpqOuVw4j4G8sj/32Kdy/yWwEWBIDMPkmAaI5/NMiZatXTsnNFH74CoxGZN66UbxOYJdX2+kvMwoGOVZxoyf6XSjHI6BAo6cISC8decmqEc5ZwkBf8vtk79V3V+KT6LTLEDmFgRnr6fPq8HbbhrLVX452BXN9umlfwCK3IXuVJtFPrlN2VXApIw84vVapujp79pPg6zb4ZZVuH85oApYCZUp0BnYImWaSpi0XhrBPHoli3erUY2Bpv8aktc3NMao4Nk/Mdbk2l5MsnnDN3rIvkVHgT91//p1OPDSQsUgDlOM= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(36860700013)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:47.9656 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39f2d92f-8661-441f-177e-08dd2c2f14dc X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06C.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7085 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114501_907472_2D670977 X-CRM114-Status: GOOD ( 15.22 ) 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 With the introduction of the new objects, update the doc to reflect that. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- Documentation/userspace-api/iommufd.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/userspace-api/iommufd.rst b/Documentation/userspace-api/iommufd.rst index 70289d6815d2..cb2edce6f87d 100644 --- a/Documentation/userspace-api/iommufd.rst +++ b/Documentation/userspace-api/iommufd.rst @@ -63,6 +63,13 @@ Following IOMMUFD objects are exposed to userspace: space usually has mappings from guest-level I/O virtual addresses to guest- level physical addresses. +- IOMMUFD_FAULT, representing a software queue for an HWPT reporting IO page + faults using the IOMMU HW's PRI (Page Request Interface). This queue object + provides user space an FD to poll the page fault events and also to respond + to those events. A FAULT object must be created first to get a fault_id that + could be then used to allocate a fault-enabled HWPT via the IOMMU_HWPT_ALLOC + command by setting the IOMMU_HWPT_FAULT_ID_VALID bit in its flags field. + - IOMMUFD_OBJ_VIOMMU, representing a slice of the physical IOMMU instance, passed to or shared with a VM. It may be some HW-accelerated virtualization features and some SW resources used by the VM. For examples: @@ -109,6 +116,13 @@ Following IOMMUFD objects are exposed to userspace: vIOMMU, which is a separate ioctl call from attaching the same device to an HWPT_PAGING that the vIOMMU holds. +- IOMMUFD_OBJ_VEVENTQ, representing a software queue for a vIOMMU to report its + events such as translation faults occurred to a nested stage-1 and HW-specific + events. This queue object provides user space an FD to poll the vIOMMU events. + A vIOMMU object must be created first to get its viommu_id that could be then + used to allocate a vEVENTQ. Each vIOMMU can support multiple types of vEVENTS, + but is confined to one vEVENTQ per vEVENTQ type. + All user-visible objects are destroyed via the IOMMU_DESTROY uAPI. The diagrams below show relationships between user-visible objects and kernel @@ -251,8 +265,10 @@ User visible objects are backed by following datastructures: - iommufd_device for IOMMUFD_OBJ_DEVICE. - iommufd_hwpt_paging for IOMMUFD_OBJ_HWPT_PAGING. - iommufd_hwpt_nested for IOMMUFD_OBJ_HWPT_NESTED. +- iommufd_fault for IOMMUFD_OBJ_FAULT. - iommufd_viommu for IOMMUFD_OBJ_VIOMMU. - iommufd_vdevice for IOMMUFD_OBJ_VDEVICE. +- iommufd_veventq for IOMMUFD_OBJ_VEVENTQ. Several terminologies when looking at these datastructures: From patchwork Fri Jan 3 19:43:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925869 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 61923E77188 for ; Fri, 3 Jan 2025 20:01:33 +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=Qec6YL77/jkxX2YV1NOAbvOY28hyb313lbUXvtSbt+o=; b=I9KUE8g8iARzfZd+MdberVd/Bk 43DquMC4t/dvtzkr4W73NY8lTHP93yk8LZ1Y9OJFAuOfpmb7YbiEBe03A/DZusG4bo6HT04Gau732 aOSMMgYO/L2+ffSYsNGYSFrUhwLlVAM5kZbKDLCRYmAzbOdzyy/wUSqU2yHQz344ytd3LYGS/nFIW rnW2EvbXOeQjDFCqiGlJHa4hSy2g5+No+O8Dg5DH6YvhftjDPfdW+gErsWCufXqtluEdKhs+vMFds Kf4UeaTilj7BNVh0f+hWP9ikj4r0XXIhZtsYB0pXSPr/D8PnAynmknX+ae9+j7xaTcYRyAyEFP6fN fs2VzEvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnrE-0000000Dtnh-0v2R; Fri, 03 Jan 2025 20:01:20 +0000 Received: from mail-bn7nam10on20624.outbound.protection.outlook.com ([2a01:111:f403:2009::624] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbS-0000000DqhM-1hpq for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:45:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X1m07moqcaWCTV7P5TsgeRpHUx6LsYNOMmyKAbB2eGbMOQ9pvUVhKJHTBbwOqZL+qgpX04FVdU8k5OcAsmhXA778ZyaCf6bkEP0VcfVj8HR4S99QI8UbLvKCHWcPo31pZbovUfY0KxoNrwHr4IOl9l8xYSNV2NFeSlFHuziNfbXhRSVFdDMPu+XwbBpnwcyxBodOEuEfWEG3Eu84x0ISrnSI6SESjYr4aCj/9QD06+ReTGgTq9ApOMh//yWAMj48GSTt8Be+JZj3CaSJQNEPiko4eJd/eIFe7zEfrbhKs1i0mz165eiqjVydbc6lFo9CLroQW+zII/WL+ih/zbjTkQ== 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=Qec6YL77/jkxX2YV1NOAbvOY28hyb313lbUXvtSbt+o=; b=bJwcjSCY8FD904Dqal/0h8DQe8R90Ixf7gvJ+lYTHTKlUIh0ZUxlS3R8iBVXCac3DbIdG/PjPAW617Z8W90aA249217fcZAj1Z16L45Z2u8m2Tw3jpO+dosc5yMakVB89CoiC4cMwhDg3MNc6E7RBr3k0OgYnE0iLZ30uVrk1vpNIrNrp0PDATqqj7S7lM8I8M0/XBAV4LQcJ46q4nXQfvCKNENv4hAY4zK2UwzZ/BaqnGVs+FwSPnYwAmAxGxZStzfglfV3qfyuuy5J+cBzAHcv73GdWnq9SngHjIQDrG6D5uSSXXyrxP0OkZpb8GehsdlKvFEWV3BXepnTxWV1vQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=Qec6YL77/jkxX2YV1NOAbvOY28hyb313lbUXvtSbt+o=; b=DkwONgI7CR6zwHJJAraupgHkOgMJ3YhqKguAp50D2MKBivoK0jGiMZ5hjAFn5Y417FSiVGSr3UkVqj11s5UU7UZOZqTGxGlOtM+Elww7rp7KC36yD3imRDu/791nzh5s2xokoojgBKGe1XIErvslmtem53yrZ5aWql4jeeSC/UA/Bgkc30kZ5eV4mB+xQWP7CMeUzeP+ydduYqTsbQTLYdnvwr5ZgZcFD+urDPBQfaHV0hEQ8ZjCqQy9bsK2CK99qZ+MfrVGLAphXzyU6kXIGn954lM5Bn7VySgsvijJHC9bZXW9sqA3SfGOrc60W4vHSTCtfrgjL9qJQZg07ViSFw== Received: from BN9PR03CA0739.namprd03.prod.outlook.com (2603:10b6:408:110::24) by PH8PR12MB7279.namprd12.prod.outlook.com (2603:10b6:510:221::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.13; Fri, 3 Jan 2025 19:44:50 +0000 Received: from BN3PEPF0000B06E.namprd21.prod.outlook.com (2603:10b6:408:110:cafe::65) by BN9PR03CA0739.outlook.office365.com (2603:10b6:408:110::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.12 via Frontend Transport; Fri, 3 Jan 2025 19:44:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06E.mail.protection.outlook.com (10.167.243.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:49 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:32 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:32 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:30 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster Date: Fri, 3 Jan 2025 11:43:36 -0800 Message-ID: <81bb9842db7b9637c3174974d2068baf3e515e70.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06E:EE_|PH8PR12MB7279:EE_ X-MS-Office365-Filtering-Correlation-Id: acc14493-1cbc-4cb2-1f7b-08dd2c2f15dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: Za5faOi331N2y8tgs0nAEgHL+hnsjjiptfK07G2hvub5Vpeoj06ruKLRB7VKKi9xIBb3nq7gJ/rlhT59HAJ0rhHilDe4ntqjgkk6R6zxYbU9CBvowiDzVqYrcVBFsjTWArJN55p2YkM1rTcst+Btk3/OiYg626thkGCuvxl6HNryu5QraKxgyyXDJDUogLzuKpop5vUuOy+0OX60uOuT4iWrZ0/sd/JE99jH8S4hjLS4KfmMhLa1TK7vy6sHCNeY7bxx69/bdgPQY3hBPAj+BObyynnsb4GtX8rj9gL99CxUuGzrWlO1L6M0BHnDTG5ikTAiUPaTucdZFG66PcgkEO6+XXVJ9sLf5prGVIBLH/bdV/ucOl+nOZpVD1ZMJnXwToiKhsQMMARONCkEjBA48PeCA6sJabvcuDPHrNKuipIf5rVXaTuX8KZ+jotdfJpWcNWvMsNhKRIxJ/zhSZ4q9hqCNXTdu3gbFUToMogqMxwhTpwVMyRwfu1ACgfwHsRACiYCIxTfjc1jrBeKvDAUiQWOtLwIo5Mi+ODjnShk65ag8ud+KXjR+oALCmr6Lc0EACD2POWcNJXvTAE2Swxh0AUdd68JY9pKtceRt8ryI82poO6fy+/x6BS9zAoIdMy6wIR4z4pRaPt5/RygqRkectsrqxA7C2zbm9eGR1Vo2rwMBww1GWyvqyY7JEBlrzSuA3EeKDJbwRpz3A8D0cf/49gm0DaMB5eU/gbnXTRLFB2DGU6xoexi39RoQLsCfAqFRvMMI+ROZhQDsZWcZSQ0uQO1+BNS7bi8eo6f1rBMPwJwCtknThIrSrTnGFa/7lrXQESyu1lctm22UOnwGSCEBCFAsC8MKXvDxiDcsK7B6yqnYUVkvbkg7RPJ51p693xp+a1N5E4/yeGTmHlApk3IMg+RqY4o9GaIk0lRtsHIA0FBJ5sgPjCWap8t4+/5uwyvy9kFngIRLftIZYm2iC6cJW1nXUAVruExT8Z1atJJWlLg9W4gQni6sMH7ji3GsWVF0Gz+E5r0+dUkv507uoXEGDCCKSfK5P2nnkXXZtHLk/M3odNGBXXW84J1dirGzdmTY5TTXqcNuysu4bUv1py8wSHMoaqrranGsf4XofdaqsESSmCrcQNqE0o9qUpOEpQhZgS+FgLAofZzLLwDsP7JGNvH0kfFAKj500VmeT0sq/dNBEOLd1/OhzB5eXt/evz1GUb1Mr0uHMyEi9Bwq9Fl2UG+FGb9D2PeisGmzL4M4E7PWlXU0vuGMIFxZadaCJa1C9/rUtK+pH6QigpwTbWroPezMW7quVie7oCF7LCobIa49VmULl/F4ZWY1Gpz5+AH7YuxFFw77Po8yDuC2tdCMmQNHd3++jApA33rcKL0jFeN8Am9Bg8wTOlPUsWRnHuZpdlb929eImYUEL72o99t5q9qaHkbBSYzzsLN2ld2SMplwERaCyLEzjS+pujtZC4KpU+2juQGwFwpRvSkbf4mGKXfiZVONzMeCIk1NzFgHf0= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:49.6123 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: acc14493-1cbc-4cb2-1f7b-08dd2c2f15dc X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06E.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7279 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_114502_518240_8004228A X-CRM114-Status: GOOD ( 22.41 ) 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 Use it to store all vSMMU-related data. The vsid (Virtual Stream ID) will be the first use case. Then, add a rw_semaphore to protect it. Also add a pair of arm_smmu_attach_prepare/commit_vmaster helpers to set or unset the master->vmaster point. Put these helpers inside the existing arm_smmu_attach_prepare/commit(). Note that identity and blocked ops don't call arm_smmu_attach_prepare/commit(), thus simply call the new helpers at the top, so a device attaching to an identity/blocked domain can unset the master->vmaster when the device is moving away from a nested domain. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 23 +++++++++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 49 +++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 +++++++++++- 3 files changed, 103 insertions(+), 1 deletion(-) 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 bd9d7c85576a..4435ad7db776 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -799,6 +799,11 @@ struct arm_smmu_stream { struct rb_node node; }; +struct arm_smmu_vmaster { + struct arm_vsmmu *vsmmu; + unsigned long vsid; +}; + struct arm_smmu_event { u8 stall : 1, ssv : 1, @@ -824,6 +829,8 @@ struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; struct arm_smmu_stream *streams; + struct arm_smmu_vmaster *vmaster; + struct rw_semaphore vmaster_rwsem; /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; @@ -972,6 +979,7 @@ struct arm_smmu_attach_state { bool disable_ats; ioasid_t ssid; /* Resulting state */ + struct arm_smmu_vmaster *vmaster; bool ats_enabled; }; @@ -1055,9 +1063,24 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, struct iommu_domain *parent, struct iommufd_ctx *ictx, unsigned int viommu_type); +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, + struct iommu_domain *domain); +void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); #else #define arm_smmu_hw_info NULL #define arm_vsmmu_alloc NULL + +static inline int +arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, + struct iommu_domain *domain) +{ + return 0; /* NOP */ +} + +static inline void +arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state) +{ +} #endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ #endif /* _ARM_SMMU_V3_H */ diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index c7cc613050d9..2b6253ef0e8f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -85,6 +85,55 @@ static void arm_smmu_make_nested_domain_ste( } } +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, + struct iommu_domain *domain) +{ + struct arm_smmu_nested_domain *nested_domain; + struct arm_smmu_vmaster *vmaster; + unsigned long vsid; + unsigned int cfg; + + iommu_group_mutex_assert(state->master->dev); + + if (domain->type != IOMMU_DOMAIN_NESTED) + return 0; + nested_domain = to_smmu_nested_domain(domain); + + /* Skip ABORT/BYPASS or invalid vSTE */ + cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(nested_domain->ste[0])); + if (cfg == STRTAB_STE_0_CFG_ABORT || cfg == STRTAB_STE_0_CFG_BYPASS) + return 0; + if (!(nested_domain->ste[0] & cpu_to_le64(STRTAB_STE_0_V))) + return 0; + + vsid = iommufd_viommu_get_vdev_id(&nested_domain->vsmmu->core, + state->master->dev); + /* Fail the attach if vSID is not correct set by the user space */ + if (!vsid) + return -ENOENT; + + vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL); + if (!vmaster) + return -ENOMEM; + vmaster->vsmmu = nested_domain->vsmmu; + vmaster->vsid = vsid; + state->vmaster = vmaster; + + return 0; +} + +void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state) +{ + struct arm_smmu_master *master = state->master; + + down_write(&master->vmaster_rwsem); + if (state->vmaster != master->vmaster) { + kfree(master->vmaster); + master->vmaster = state->vmaster; + } + up_write(&master->vmaster_rwsem); +} + static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, struct device *dev) { 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 ea76f25c0661..686c171dd273 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2802,6 +2802,7 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(new_domain); unsigned long flags; + int ret; /* * arm_smmu_share_asid() must not see two domains pointing to the same @@ -2831,9 +2832,15 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, } if (smmu_domain) { + ret = arm_smmu_attach_prepare_vmaster(state, new_domain); + if (ret) + return ret; + master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); - if (!master_domain) + if (!master_domain) { + kfree(state->vmaster); return -ENOMEM; + } master_domain->master = master; master_domain->ssid = state->ssid; if (new_domain->type == IOMMU_DOMAIN_NESTED) @@ -2860,6 +2867,7 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); kfree(master_domain); + kfree(state->vmaster); return -EINVAL; } @@ -2892,6 +2900,8 @@ void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) lockdep_assert_held(&arm_smmu_asid_lock); + arm_smmu_attach_commit_vmaster(state); + if (state->ats_enabled && !master->ats_enabled) { arm_smmu_enable_ats(master); } else if (state->ats_enabled && master->ats_enabled) { @@ -3158,8 +3168,17 @@ static void arm_smmu_attach_dev_ste(struct iommu_domain *domain, static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, struct device *dev) { + int ret; struct arm_smmu_ste ste; struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + }; + + ret = arm_smmu_attach_prepare_vmaster(&state, domain); + if (ret) + return ret; + arm_smmu_attach_commit_vmaster(&state); arm_smmu_make_bypass_ste(master->smmu, &ste); arm_smmu_attach_dev_ste(domain, dev, &ste, STRTAB_STE_1_S1DSS_BYPASS); @@ -3178,7 +3197,17 @@ static struct iommu_domain arm_smmu_identity_domain = { static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, struct device *dev) { + int ret; struct arm_smmu_ste ste; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + }; + + ret = arm_smmu_attach_prepare_vmaster(&state, domain); + if (ret) + return ret; + arm_smmu_attach_commit_vmaster(&state); arm_smmu_make_abort_ste(&ste); arm_smmu_attach_dev_ste(domain, dev, &ste, @@ -3428,6 +3457,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; + init_rwsem(&master->vmaster_rwsem); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); From patchwork Fri Jan 3 19:43:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13925870 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 08FD8E77188 for ; Fri, 3 Jan 2025 20:02:44 +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=n5CgU9hUH5ic/+yCiu7ISm+Skm6bwlui7GXf5KgZNnk=; b=Sgwn0POFKWVDH+HhOS5Fq68VvX c9vAoFdbYkToS7ppdBR3s8S7xSGFq28AFr1H9sYj5p4sr9N+rzynty4tLGwMOH9dEhPv9AekRClpn pyLyUBIs6sMQnwQqOU2NXOkLtQhfJWY5bc0k467hgGZxlcOlEYgkY+JHquVFhB35JJ5YGDuJEeyKc zX0Deoezp+XgaZ+HyvVCPDUKzjswoa06sRrv9V6trijeq35MGEVghYl1NvYxl9sSecgoJrgPl5wcX w9Tn/6hHEzFjj9izwXkUPgonUj7PMByxklCJuh5aIihByUKFtDSFDfAe9keN/1qWLf1U6EmoOgnxj DHFHkyWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTnsO-0000000Du7p-3jGn; Fri, 03 Jan 2025 20:02:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbU-0000000DqjC-3HKm for linux-arm-kernel@bombadil.infradead.org; Fri, 03 Jan 2025 19:45:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=n5CgU9hUH5ic/+yCiu7ISm+Skm6bwlui7GXf5KgZNnk=; b=hQZNQUUqz3uZ2O/kIc2udP60Jk D248urgYb2eLrSuYUbcfrnbNDCnwNWKTfD/KTZyPGhGYUlJc1/DLdjDjbyhQeZ+nSMW0UqFXBatwD 2HEAJwejAaC1sxKFvU7h9b1SzqDJRpV4jLEs2RbWu8HZsRkrJ2AZKP/QhthVMsqBuC7lC5RRWkv1R OrR/6cMJs8+aCQV+1FkDIBRrY69Wexg3LxjlZSAsibl8bsqWMBvvkzNqyeO/C18uK6XYKMov5miD0 tA5fPpsWAAWal8fA8wbsDnmBR1hWhuCDUPeXKU7VFr3OxRWoNfHNTOi+AzrYFJGmolH0IYiWifjLe ybeY+Ovg==; Received: from mail-dm6nam10on20606.outbound.protection.outlook.com ([2a01:111:f403:2413::606] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTnbR-00000008RIu-3maC for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 19:45:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bG/SKfmaFWqCgtUjtkjKAXhPgUOiyWyvphJ/z0oGDz94wQDWDAkHdeIztvgJjLZ6KJ6ISFeYsK8VfQdQq9VLaXJgdkHhjgdwDpJkVOH8/6gRKYNsiwi+9I6fpjNK+UiSMph6XksE8/fdhEQw9FKLnumwfEvZdrjEpVt9WhyoGwUM3r8sYq8Xnyv2BLUWeSLb3XAfPyssKwX0Yyp8HjLOUNXPkBiIPsBqtZvim0G094SaEpweBQpvkQfQawYGalxhvizB7+WpPcta1Bcv8v/OAfxdMS0J+60dpFZT80RD1hBikyZPEtewn/C1Wrun82atW9kagY/iGv/eRrDDsOGLew== 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=n5CgU9hUH5ic/+yCiu7ISm+Skm6bwlui7GXf5KgZNnk=; b=TWFVntSNfvvn8LxV9rMycMXrw3XKLNSv20She3/AKmyYL8J+aHKfucc2ErLoeGkNZuay24TGm784OmUNTTcDmTCZvveLJZGshJOrZqahxn2T6t904IzNh5+PhRxjjc8pSYRkNYwESV4BIGMAAR4p/9ObXsUCmVJyMofvGrzNk8rvLtgetKIwHuGqjUHF4XXFY7J4JDTwZHvKuscB+/3gAK4dxZjx6UN9FWE1tM6k/SaEwQC0qYQECD9/FJisk1UxBubghg2cdlIxWobTJIr5Kag9Mpy0fy4IgtJ16ey9L1xoaBkEqLvxwTf58OzsPz1J4mt5B8pE4cQNr5rzg0Znmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=n5CgU9hUH5ic/+yCiu7ISm+Skm6bwlui7GXf5KgZNnk=; b=P69UNVUuEkzw8c88uTR26s/nCI3/3bLICdamNJA7fyLWFBh092Pklfnb3dtWhn02JZO3FeyVBquGxR5pQEvm39yuNcKOH6APPfqmsEKCaXrZRfXVrAhmAiqX/f0Y7ulevnQBNPu2PCKLlmnwsmDf+t0/7OAadhDbcTVQCRr+JCeHktSOQNy5hPqxJbRugzpFNinm1Ui/hJQ1ZQHTxIvvSYxMFo0yOv00o1vWb6Unrxzdh/2RHKfD+yGliQzos3EYfDNyLuOMtJ3M4ZGEegO5Dta9yYzFRkLSwOjBk1wzsgQ2K8/itNlrbc5N5+KB7GeBuNee2+nLFOvo+eaLiEQYJA== Received: from BN9PR03CA0742.namprd03.prod.outlook.com (2603:10b6:408:110::27) by SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.13; Fri, 3 Jan 2025 19:44:52 +0000 Received: from BN3PEPF0000B06E.namprd21.prod.outlook.com (2603:10b6:408:110:cafe::cf) by BN9PR03CA0742.outlook.office365.com (2603:10b6:408:110::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.13 via Frontend Transport; Fri, 3 Jan 2025 19:44:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B06E.mail.protection.outlook.com (10.167.243.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.0 via Frontend Transport; Fri, 3 Jan 2025 19:44:51 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:35 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 3 Jan 2025 11:44:35 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 3 Jan 2025 11:44:32 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU Date: Fri, 3 Jan 2025 11:43:37 -0800 Message-ID: <69a46c72e43ed086840be462eef731167d90a9d8.1735933254.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06E:EE_|SN7PR12MB8059:EE_ X-MS-Office365-Filtering-Correlation-Id: c9d7d69b-1786-4f0a-d4b8-08dd2c2f1716 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: 7S1o1ic8wlyjoo9st7m6Qxc4C85sKk6u104buP3bsMQR36Dk7eT0jP1XsQwYB8HDUk95mJtQDF4jJ/5D2GyuvIVDxoLwWt1xGnt4UM6P7sctdmOnDDztfj8WoOLVG1DiMrVQo4Vag3DJEwMXx6klfJ/rZBghB6IOxAT54Kqc8GOBFQd6VhFz7MMHW4O7igOBPbt2ab9m7ONq474wCGbqZNdZH0y0vn3XXlDv3slmUZ6M7vjwbaowRd9jdpckibVtr+8uTLUHxZPVFY32rSzzIPrEZWEEbwLoxnOaPrVt6yluI01Zm9h+zgW7JHgWcWOijJwWfijK486hU+thz23x2xQabRGKr/6JFhpszBJswYwMZ3goQu0LEJywoCx8g7nG/1An4SfkhsdO5UxGC1eiuXw2oBhIW5UWHw+SpwJSS7JOkOu3x97Lgqp644Skj0dDyOQYMLzp84rIsZNEWm/4pY8O178wQ4+uLjcowSbB4Pafpcc3NxEJjyPk0DArebdFeHVgIWVJdjpuiDSJmylFXmAqZNmOWyaiaxNNmGLjQrn8M1gnjZZNOvb31LgxLSr+WTrHuQzCQ2Rw9NtJPV4xACkq78LOIY7XYVMZXH5DS/oFonoT5eUpsu+g67L77TVV0tXXsiZ4G4SqLbTArnIzvYtuHsk0Gavr+yT1GAkXb21l3RZ+65jXxAQ896e+hU3QGzXnn8rrjYlE7lRcW8qbCbtqZChIQnyatb/rCxT3Mh8y3kf66P7DFDNnulMV+MiVyoDuzcDtAa7mIs0a2qf0fLO+5xOmn4icD1AXB8G1yY8z30SKdvn5s0m4QHG3rUUusdj56XR7JGKnvZjM5y8oB16wDQ+xFMU6wn98mJvLtwB6LU1jqreV4cqe/yBk/sThZYZ59n9/8dskyzQsnM7yoW9K5Gl0sIZwNzF/XuMOkIwyIAdac+FrMqPuOWOo7jkGLc5dit7mWZMDcu0IHzjrA+lqSqrEOzQH/PjeHD9jRgp/8YvPLH1a2u4JawWsJlVEFH+oiyoxifOLWvOOirbBeqmy1qTRtV/4Dh8gzy0Y3VLJ7A2s7sSAzOXp4qLlE0JB2083jE6ox/c0ajmv/CASvo96Y4VUpTQBHCLV+uN3SalAX/U9j44FNwS8hI5IuYOQab13S3O3nb0Trh6CKPgD6RqFGG8eXdZOwy/ERmACM/WJeGWYLpUroJmhuJ9CDXnVT1Y8XquZE1FXVyZ28mjd3yo32Ced3+ZLI+vWHwQdYkAoJV1jr+hSuBWnteNzZmT/DxYtPvZS2R+GdKgyWlz+Ro/KjicYiSSEtQnz4z8bZ96V2VO3didP5z6If9wfnUTl00aRLUA2xT/ysp+i0+GFTR0CVxHLbN3R138g8tLMfn61aVc4RTburHhUFKPLYucsCnaCEnXE9cLXcTe1MsBwuK/nrSHN57FrtSHT4sjG4mV38L4eUMKBDWAozkhkh+Qk+N17R+3MbfWyxA5rKL5EEQITK+MxbCDJsD4VRgZHS9U= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 19:44:51.6904 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c9d7d69b-1786-4f0a-d4b8-08dd2c2f1716 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06E.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8059 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250103_194502_075751_ADF4B677 X-CRM114-Status: GOOD ( 17.79 ) 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 Aside from the IOPF framework, iommufd provides an additional pathway to report hardware events, via the vEVENTQ of vIOMMU infrastructure. Define an iommu_vevent_arm_smmuv3 uAPI structure, and report stage-1 events in the threaded IRQ handler. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++ include/uapi/linux/iommufd.h | 15 +++++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 16 +++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 58 +++++++++++-------- 4 files changed, 71 insertions(+), 25 deletions(-) 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 4435ad7db776..d24c3d8ee397 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1066,6 +1066,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, struct iommu_domain *domain); void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); +int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); #else #define arm_smmu_hw_info NULL #define arm_vsmmu_alloc NULL @@ -1081,6 +1082,12 @@ static inline void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state) { } + +static inline int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, + u64 *evt) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ #endif /* _ARM_SMMU_V3_H */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 0a08aa82e7cc..55e3d5a14cca 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -1016,9 +1016,24 @@ struct iommu_ioas_change_process { /** * enum iommu_veventq_type - Virtual Event Queue Type * @IOMMU_VEVENTQ_TYPE_DEFAULT: Reserved for future use + * @IOMMU_VEVENTQ_TYPE_ARM_SMMUV3: ARM SMMUv3 Virtual Event Queue */ enum iommu_veventq_type { IOMMU_VEVENTQ_TYPE_DEFAULT = 0, + IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 = 1, +}; + +/** + * struct iommu_vevent_arm_smmuv3 - ARM SMMUv3 Virtual Event + * (IOMMU_VEVENTQ_TYPE_ARM_SMMUV3) + * @evt: 256-bit ARM SMMUv3 Event record, little-endian. + * (Refer to "7.3 Event records" in SMMUv3 HW Spec) + * + * StreamID field reports a virtual device ID. To receive a virtual event for a + * device, a vDEVICE must be allocated via IOMMU_VDEVICE_ALLOC. + */ +struct iommu_vevent_arm_smmuv3 { + __aligned_le64 evt[4]; }; /** diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 2b6253ef0e8f..f88fd2f5cae8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -447,4 +447,20 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, return &vsmmu->core; } +int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt) +{ + struct iommu_vevent_arm_smmuv3 vevt = + *(struct iommu_vevent_arm_smmuv3 *)evt; + + vevt.evt[0] &= ~EVTQ_0_SID; + vevt.evt[0] |= FIELD_PREP(EVTQ_0_SID, vmaster->vsid); + + vevt.evt[0] = cpu_to_le64(vevt.evt[0]); + vevt.evt[1] = cpu_to_le64(vevt.evt[1]); + + return iommufd_viommu_report_event(&vmaster->vsmmu->core, + IOMMU_VEVENTQ_TYPE_ARM_SMMUV3, &vevt, + sizeof(vevt)); +} + MODULE_IMPORT_NS("IOMMUFD"); 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 686c171dd273..59fbc342a095 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1812,8 +1812,8 @@ static void arm_smmu_decode_event(struct arm_smmu_device *smmu, u64 *raw, mutex_unlock(&smmu->streams_mutex); } -static int arm_smmu_handle_event(struct arm_smmu_device *smmu, - struct arm_smmu_event *event) +static int arm_smmu_handle_event(struct arm_smmu_device *smmu, u64 *evt, + struct arm_smmu_event *event) { int ret = 0; u32 perm = 0; @@ -1831,31 +1831,30 @@ static int arm_smmu_handle_event(struct arm_smmu_device *smmu, return -EOPNOTSUPP; } - if (!event->stall) - return -EOPNOTSUPP; - - if (event->read) - perm |= IOMMU_FAULT_PERM_READ; - else - perm |= IOMMU_FAULT_PERM_WRITE; + if (event->stall) { + if (event->read) + perm |= IOMMU_FAULT_PERM_READ; + else + perm |= IOMMU_FAULT_PERM_WRITE; - if (event->instruction) - perm |= IOMMU_FAULT_PERM_EXEC; + if (event->instruction) + perm |= IOMMU_FAULT_PERM_EXEC; - if (event->privileged) - perm |= IOMMU_FAULT_PERM_PRIV; + if (event->privileged) + perm |= IOMMU_FAULT_PERM_PRIV; - flt->type = IOMMU_FAULT_PAGE_REQ; - flt->prm = (struct iommu_fault_page_request) { - .flags = IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE, - .grpid = event->stag, - .perm = perm, - .addr = event->iova, - }; + flt->type = IOMMU_FAULT_PAGE_REQ; + flt->prm = (struct iommu_fault_page_request){ + .flags = IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE, + .grpid = event->stag, + .perm = perm, + .addr = event->iova, + }; - if (event->ssv) { - flt->prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; - flt->prm.pasid = event->ssid; + if (event->ssv) { + flt->prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; + flt->prm.pasid = event->ssid; + } } mutex_lock(&smmu->streams_mutex); @@ -1865,7 +1864,16 @@ static int arm_smmu_handle_event(struct arm_smmu_device *smmu, goto out_unlock; } - ret = iommu_report_device_fault(master->dev, &fault_evt); + if (event->stall) { + ret = iommu_report_device_fault(master->dev, &fault_evt); + } else { + down_read(&master->vmaster_rwsem); + if (master->vmaster && !event->s2) + ret = arm_vmaster_report_event(master->vmaster, evt); + else + ret = -EFAULT; /* Unhandled events should be pinned */ + up_read(&master->vmaster_rwsem); + } out_unlock: mutex_unlock(&smmu->streams_mutex); return ret; @@ -1943,7 +1951,7 @@ static irqreturn_t arm_smmu_evtq_thread(int irq, void *dev) do { while (!queue_remove_raw(q, evt)) { arm_smmu_decode_event(smmu, evt, &event); - if (arm_smmu_handle_event(smmu, &event)) + if (arm_smmu_handle_event(smmu, evt, &event)) arm_smmu_dump_event(smmu, evt, &event, &rs); put_device(event.dev);