From patchwork Tue Jan 7 17:10:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929439 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 209CDE77198 for ; Tue, 7 Jan 2025 17:26:15 +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=6vY7vxx+Vn8PB9+jCIIbHTRj05Uptls2AQ6Dl8+kiok=; b=PQMK4FroG0RMNQeD+omcj72pF+ Txun3kFRgw+b2SAzxeMnHVWyiOFI+r80hu4/MrZLUa3jiDQTn4C2b5dl9NC706iHe69yF+yNlAlmv JK3kZuavZjXb+pU4VkSR4oXSmy4o73+IVVvPa8JqPyf59z/oCl3vV0a/vRC9t78Dl8QbP0SWg9t3b a+7xlZk/iainJ9X5UTMCcsZ3kKdUbWkH1sYqJdhtPEe5LdoDp3PN4ehlx5FyW+SRlNhbv7OOgEKmO vy7/wpFkJUtLn4L+QPDMwuUI8LifeJRfJRqd8KJsUrR3e5y3RJX4dpB/rmxYYzxqsKwfWLl3TO3fX V4bPaB4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDL7-00000005qkm-42Y4; Tue, 07 Jan 2025 17:26:01 +0000 Received: from mail-mw2nam10on20621.outbound.protection.outlook.com ([2a01:111:f403:2412::621] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6Y-00000005mBl-2I19 for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D53cqb2HjO0IuVY+TzjyYRewTWZUQeYEIwbDRkBGgZSHIQDAGa6E01Reu0oQov3MRUW/mNG8YW2xoL8XLgnm9LbDS/dPtY8MA2+NhAynrVA5WIqEqMS02RZyPYWSGsAYHjBK5umX7ifSugLiF0V2ywOVoiMn9LFuGiRjNy5QLzy3O/hOP78h8gy0vwETuSYKYFtgvCsBpqzIHZ5Q7XhyvAdBv/mL1YbLCfYOFdvLTTI2a+PvyPOnkmhSQcKHSnPt15IcJnov7eyrel/6vFmMWnf+VKbKP45vCLzhoEzB1oBTEJp+OD2QsFk+MpqEtDXLkck18FRWI94SZMW+OVWNww== 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=6vY7vxx+Vn8PB9+jCIIbHTRj05Uptls2AQ6Dl8+kiok=; b=mZUM0Q3JP4n+O3matepahHgGcHMv2pGsNqt74QZEBWrIUYJ+yVfncv48N8Bi9+rqCOiRVRMsqx03HnH0BjCRFbKgu74hNDKw6+bfNi8MGZcdo3+iLVzhBe8nXfbwU1tGBvEb7Rb2AHgxk8H1yw4rl1mKjnpBcNxSa0kQWUTwiRdHigB1lcEDJox/ufZFjCsNBkOyphs8M5pfCMGjj1d5eloAn1a6CeojgMsW+5Riden6OiSST+t8b32yX444Wrh7vKpEQDVwillwvLfMXr86tZZzj4ciynN1NortEnor5++d0HVibr9WngZN1Wv+5fVB5N84E0Z799Lc0BdmqIiyVA== 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=6vY7vxx+Vn8PB9+jCIIbHTRj05Uptls2AQ6Dl8+kiok=; b=QxpVDa5cX4MxVeG5MG1A1E1DJcSeB5ERORShUSWqHrZgPnQcr2PU2lXzV1BiPpoYkPqx1icvrmN4f2x7hwIr4Ja81HxffAJ6bR9liW8g//z7ZsGXiKu/ciJb3igmGYwUjFmSULvyT0T5WGTADWJiWpHhor+9hnnMpNmzXLYMBppozsoj21pHo8HthEsFsWM0HzhpF+FLzXtR+Oa6T95UIybVJuW3wxB3PNVww2HHo4usb7EBRJRkrOZ6s/ioY6fEeq7knknktea0EKK1n3CDmS+oh/q81cc8CnY8eSG5OBFpBFBkJC7sEQbk92ALTkivaud7K9XceobVcvBPSISf+Q== Received: from BL1PR13CA0008.namprd13.prod.outlook.com (2603:10b6:208:256::13) by PH8PR12MB6697.namprd12.prod.outlook.com (2603:10b6:510:1cc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:10:45 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:256:cafe::a6) by BL1PR13CA0008.outlook.office365.com (2603:10b6:208:256::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:10:45 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:10:45 +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; Tue, 7 Jan 2025 09:10:28 -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; Tue, 7 Jan 2025 09:10:28 -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; Tue, 7 Jan 2025 09:10:25 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 01/14] iommufd: Keep OBJ/IOCTL lists in an alphabetical order Date: Tue, 7 Jan 2025 09:10:04 -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_|PH8PR12MB6697:EE_ X-MS-Office365-Filtering-Correlation-Id: a62e0670-fce5-4232-4e22-08dd2f3e3985 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: Wqc0Znuy4VBhZnt2DzkTuI0zVnFC8EuKTWWart0rbYhYmZuSy1hOMnK7mC14QTwEGB8IC09h512/AVcFOdt0xFl+vW+Kf+sHfC9WXEpUqdV0jb0Wj9S+p9OooYo17FloYQr9hcKZ/3UGPI/q4XyhVWlkTzuQ7dzxKe/89F8BN7T0b9G0r1XCixBY7YEi5eGdGEx9RS9NWkZJwJtFEUNWu/YFUexnkixtGKG75aWfvAGIQEyyeK4Z+ul5XO2HHi/j1qNzL9ESzPwuSJGQz1oLbDp2JjDfzhKZKbfZtjaXxpnww5fTgu4jBe87BXQMQHSWIJqy26IKxaXUOhBpdLCssszor/BOMcCd8pQQfwcwXZgEe4jlleN3gECvienxJXVnOsW19RQbscU5G/1dmhVdjUgkq2uRlU11Z9wnZD4EtUNrg79iaLqFXVh9vQ6MP3jr/72WG/H5taR4syWS/hrkDQwAAapVTsA/JaQ1+GXYgA41HAiMIAE6U4J9CRqQa+gSZXCgfT0qnTu3gLuyryJ2ULrC7ugfu/1jvj0m9YS3eFCPBe5GUVc1T70vRuBfy+UpyLCxhjQUZ7I5Uxi8qgpze1RUzbTVNmAGr7gi3JC3XaBvD2DIf3OQYuTdko4SDQofcbM/QgBKxaLgOBSyHfU6m5RmGCWsW7/FzBSqf+ObT6ZCUMuWe6hX9XeDaLtD18phHMXGp01A1LQkTEpq6hIutnUzV05wa7DYne13DaMjCY2aYoQ+GF5Gt4F9dtRRQeH78DkqKDk6l/c7L+IFblL2ROWd+bK02CQsCQjzzfQ5+pfRkDNOMOYjIz8KzkjHbprLGRZRijC4D3BWc9rRhgVMK5DdudKjyTzaeD/jmfFhb/h340AeVKI3/SPKXL0yoThPrMnTsndZ133rL8Zw2wltpfpcxmd1KSYZl8eGEyhSGpNdlNXwhEvPrP6/RGuOb3QcQWx+NOo9HG9PMih3SqrRqMZr1taRuCz1Qn5KOAWKRTzEw3WMgbSLatCNsA0osxjK1Rmn4X0GTfVbswK1yyFhV8QcWShKEIS5QkeDHOhH5PH7vESDUxcBC2lS7HCitXTSiunudXc0ZVBCuKH8ethnlnG/cNTAF3B7WXSKPUvV8eyQI8K7a6gU8jIscvpktZKLy4Zu/VBJqIXlPYvyMAN+fSKZMONhSq+7kaEQl3uwUk2haG5DTHlQvNYoNBHRVN1yMq9pFzZwH5JVK9Grs74pRNOwc1gY3ymccNjpKNRtuWwmt2n/X9Kucxe28i3rOycQfnboc+0/EhH8//vVNXdNZpDqaS/e5HgogMJUPQ6I8mTQ/6YolIqoNEbGD0+8D/oQX5bvZhlxsVO4hgNUC5LBHYupPxeXcQwmnQwpwxxrVxywpyaWO0sv5MSjbjKv3/3t05FKGeHZI7HlWQwj2NP5qcKc8WHRWCB5fC4FWqWqESJTj3j8ApNQXVC3t+ENWWRULpecODG2DZvtsmOTHWJZZw== 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)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:45.3962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a62e0670-fce5-4232-4e22-08dd2f3e3985 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: PH8PR12MB6697 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091058_616203_690028C0 X-CRM114-Status: GOOD ( 11.19 ) 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 Reorder the existing OBJ/IOCTL lists. Also run clang-format for the same coding style at line wrappings. No functional change. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/main.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 97c5e3567d33..a11e9cfd790f 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 @@ -490,8 +488,8 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_DEVICE] = { .destroy = iommufd_device_destroy, }, - [IOMMUFD_OBJ_IOAS] = { - .destroy = iommufd_ioas_destroy, + [IOMMUFD_OBJ_FAULT] = { + .destroy = iommufd_fault_destroy, }, [IOMMUFD_OBJ_HWPT_PAGING] = { .destroy = iommufd_hwpt_paging_destroy, @@ -501,15 +499,15 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { .destroy = iommufd_hwpt_nested_destroy, .abort = iommufd_hwpt_nested_abort, }, - [IOMMUFD_OBJ_FAULT] = { - .destroy = iommufd_fault_destroy, - }, - [IOMMUFD_OBJ_VIOMMU] = { - .destroy = iommufd_viommu_destroy, + [IOMMUFD_OBJ_IOAS] = { + .destroy = iommufd_ioas_destroy, }, [IOMMUFD_OBJ_VDEVICE] = { .destroy = iommufd_vdevice_destroy, }, + [IOMMUFD_OBJ_VIOMMU] = { + .destroy = iommufd_viommu_destroy, + }, #ifdef CONFIG_IOMMUFD_TEST [IOMMUFD_OBJ_SELFTEST] = { .destroy = iommufd_selftest_destroy, From patchwork Tue Jan 7 17:10:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929433 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 3F8DEE77197 for ; Tue, 7 Jan 2025 17:22:39 +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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=vnlSYQ+JVV0+IrYmbVeqIVDz0m dRqopGB6VnPAK2D1M77bBmzaud56+1EtPVQ6y7So4XQyYcauiQHfKrF8VrdZvent+107ZnafaQRNW YkonzHY1mwJvEbo8NsWKaS+Jfb0GvYWxPG0b37r1OkEa+4r3UtZQ9+Yy85fceH9MAPYwoDGVROwFF wdlIBIye4F+FbGolszOfeoUTu7A7aoJQuJ7T3a9HrT/xwy4Xf13dJr0mJd4Uak8JkCutvvi/OCjRn pbnLI9XSmAH5vCDuRCEZp6Skq6oeyxpsNoxwp9YZ7xdgfrmwUOUpswPgjoeGPhsxO50g4oZaJTca0 4ttcCNSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDHd-00000005qD5-0JWg; Tue, 07 Jan 2025 17:22:25 +0000 Received: from mail-dm3nam02on2062f.outbound.protection.outlook.com ([2a01:111:f403:2405::62f] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6U-00000005mA6-2Got for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:10:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sI5q97Nw6d/9qHx5AjWwM3CWxyahrRxIS3iKzhhP1tAEjUCKdF3F+hEu9BeuB8uqFJgohE47R76tstB6Cef9l4R9W8kCdSa83d/pu+rnPXWjABbQbhFskRKddp3o9pdEoQee78yUimFwlDDrZCaNkpbDRUtLgJLQ9lbj7xV19+fOwbMz2z7pXw7oHRQ4WfoPSDmALxAf2+sUSPmYdkLgn3YwYoSvUd2oyNbH7saZfHtWiXNdLikGWRC7yuDLtxiqqawxnIZVv3WEypuJWTb3zEIB12olTlC465LTvCM8WQf5ebUlEicoDzt8GuHcioJjxBacPhrbnSn6OfY381R4Zg== 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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=CEC1aDYCv0q+spq+ifS+vCRy8tCAusIJtxMsGI9Dgu3v2wh8pJNSF2oPwlnt88yVqRdNisNXCbpor0hujHzWY4q4/Wy31a+HVNIEQNiA0HKBeuR6lIE9H8Cv4jEM6Vy18vU7Zvoo2w6IOX/zD6U/koCxRa0vJDnqXKQhN5vZBqEh/nE/vl3Ko3kCfGFj4LkP5aDdgWeUOiVUv1V3wfd3MYowkhLgxfL1VudWPPMq1BEAAzb9R8xfL5ungSC4s1AWRQ3zImolDJthUjjrIOM6R32/10Cs2xXfYN+yx5QAT8mjgTI/5wOoA5140OSQQOvHtIc7UBNh0ruaBKEEBYLrMA== 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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=fW1K0DuwOnwx6cZJ9CmM3aWu3wVUkBq65Ako0cHeNsHPJ50sx2P9op/IJpSXZoUXw7WZ9SQBwijG8c5S1NLbTsvRL/XIlRv1drkbDdZvC+Op0xm0Zr7/Ku3gRtA2RTzZp+oU8ZR7TTHD2jk0QGjm4WlZUiRJ4DopER/Mm1jArX0b82KSBxBi7tgXIJoYpC9LcLShCbMNiDsdjHZ8MftDnTnxnZttAi3wHhHmFe1m+lG/RgD7cwKZdN8DdL71G1HbnWY8bGh294F8hsb4nlVK1n1THoUyNCwR3+IrtV9WsPUH4xEypWHZSKMkLeqGIMG5k8xQFg0d4eocL7xJuMofDA== Received: from BN9PR03CA0418.namprd03.prod.outlook.com (2603:10b6:408:111::33) by CY8PR12MB8410.namprd12.prod.outlook.com (2603:10b6:930:6d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.18; Tue, 7 Jan 2025 17:10:48 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:111:cafe::a7) by BN9PR03CA0418.outlook.office365.com (2603:10b6:408:111::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.18 via Frontend Transport; Tue, 7 Jan 2025 17:10: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 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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:10:48 +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; Tue, 7 Jan 2025 09:10:31 -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; Tue, 7 Jan 2025 09:10:31 -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; Tue, 7 Jan 2025 09:10:28 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 02/14] iommufd/fault: Add an iommufd_fault_init() helper Date: Tue, 7 Jan 2025 09:10:05 -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_|CY8PR12MB8410:EE_ X-MS-Office365-Filtering-Correlation-Id: fe4dea3b-5bde-4398-e0ac-08dd2f3e3b14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: DmBnyKL3ipYDBapsBXyQDOX6tbg7nbqyLJIR45A1GMYky10l4I1j4/11cyR3XDbOhtUWAMPFiTlwcO0Q+YdcwuDJVpHXsLkYONCHNxeQ6SLB7nwd5WQ2NPgK0fANZsaGvBIUzGtMF6vbya03HGlfcqHD7mpmVwsvZFyvmMwCBqZGAu7hWyWziFYIDB8jIjWGQGO90/UD00NifMXxVbEmWVfxYf3pHoVE8BoVrZKkGDd+g2d6Sy0Q679JfOee4HbWYmv0SDYOk0ZmK2NAUGbDvpsBhubU3qq6JQ1it7DoxvyXe4xmWBD2rORLRSo9qbKSf5IyF3CO8YLkQn8pKFQdILk0UIHyQE3FNMjpuDkEpkN4GmQ0H1Bqt+m7egtZPPSrqA/zJqEG79noWi8vvBpGysTHz+/ea3SAqRWLzlm2kl7Uh7n+OSa5xd3GprYCEw3iu5lIviw/vF6qL1JoENQLrQjZWqMC7yl1mprl1yu/ueavTBFUROkD3g0gncZ8g2PGwVARewOITU+AR2ZXTKfH2iOZHoazuP3VIz5hOzOqqgJtq5eCadUb2SkdkgGRBKhAUM978EIYovOTYKrDiAkKcP9Ej9X55FGP60TkWep+4zmbVRoEKvLSuoE+2lZqaxtIyZXuejerPkdCMlcZuBOz9zzotiVzluwHI/g3uTF4JBprb5CBuBQXvKpLY5aojlCQ/1b4ZST+Zi/9EgwzWTAkF+xICpjIpM+JURmMLy4khb8fw9p9xv9y0tovlBNiMnHmXVfxUXvbSfCXbwRUmfuxQ21MgLYrKu89ifYxSZEQzOWjfwNS9vIXBxI8i3WoSQXXCCY7tJSueXBvTyGCH/1vHHtbvgI45eXf1A5j6+qsNvLXVawP4Pq0KzDdTIxyVpJiPq4OOrYF3YxITHQlb2j9BXZ+lCoc2K+v+fSfogbug19q+3oKLVQUd3M73S/oeecJ7W0CaCfpUKiUiM+7kw4G/m9shSqHhnakferzu80RtJnD+WyPt3p9V20TSZavRuKH6hmzeAhUEtbrDi9HX0qHKeFEf9KVN+Xy6xYRA7w/zNnKxZwL+cG3isxVFz8acBfwnS4bZIOfMUlJyXgumVxa/ft1NxvyBLZ6CwUvBSkJHqjqoKho6LVAEcanLigdM/oLq+9ulSg+4pBeOTaI2/ZfcrWGIKwjTwVwqO4bKSyZaqxA4alxeMtJuzUqWA5r9k9AnoD4JaY0yKodR+eYr2US9rieRFlIgs6QT+xrbYcbOHoUndNROg2JKhl4p+pvqBDaCvXzdImnX8irscqQw9XYjaORQxmZG2GCkmKcgC3zOLHSUrhQHYWHbLuD09qttO5ryLizrs7ARt2T6FURcGDuVR8zbZePS1xnQG1FJ3O+3eN6v5Fytq07HvUBH8aRgcA16afMpcNG4gqMW2wfvIA2fh+z733bK8PzSrUOZfTasyBZ/OG17c1XTKGVahJyjbldvjnnDUeMT8GOpfMbCMlN+HNsQzjRUZQvsUxBAr04U4w= 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)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:48.0148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe4dea3b-5bde-4398-e0ac-08dd2f3e3b14 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: CY8PR12MB8410 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091054_582036_E5BC69AD X-CRM114-Status: GOOD ( 15.38 ) 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 Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 Tue Jan 7 17:10:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929438 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 6D420E77198 for ; Tue, 7 Jan 2025 17:25:03 +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=07+ogLYIaTskzPijN/RbveIYZKxErYwRT1XyX+bN7xo=; b=DSZRjH2Ql/J1XTVjDSr5x7x2Xg Ow+u4cczo8ZVZXfIMOTzI90GZUHhL6Y09YHy2vLnCFM7AHi9+LLqmR8gIBQR/s7w1Gkke3HUyp+Bt eTUasDM98ex2dPAVdgTMlfHN3jle08z0epN2eoYMFHPulNxqqlfd5s8+RFeAQ0POfOlJ/JreFoMmc 3OjKJaKoYLkVYAzs66uY8HsS9dY8bkTiFyhpWJEKH5snuCm62eu0jPC6DnR8uDRe8KDhjHSlUxWnS kQcNKuTcfjn+P/e3HcIMNmLPSWUp8rYqNlO2+TBjBeekmWGim+jEUxsrWqsD/f1hGrlF/Qb5ymVVg WePqQgXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDJx-00000005qY7-1GXq; Tue, 07 Jan 2025 17:24:49 +0000 Received: from mail-dm6nam12on20623.outbound.protection.outlook.com ([2a01:111:f403:2417::623] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6W-00000005mB1-2Nxu for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UiU/pHlveGp3/Vn+vpiAV8yx2QBXXyLpPqJzE+i+PpS1BGLO6o4JZ19Y6HmJOZ+J6i5sdm680y13rf1Lv6MY5B4yYKJ46kcjhmL3MU41JwedrDSjGcOffPF4vBG8Hpg2GuQdraKchEylH6iPgqPe1jI0usSYsQpaIxmLdsCiWltDn5xV4pfcBzDrsTB+K70TYXPAf2LOQzQmNHLF1/Td7CZq2nwHAYi9qL3AxzCy3ISLK4PoECcW0SxwTvjopvX8oQ8XhLOXaLO7PsbdQke2IzW94SYC9Etiu+zeAA/T6/HdB9uvX7dxyVBDRgkLCllUiBREeHnzJg9hjfEWr4L3UQ== 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=07+ogLYIaTskzPijN/RbveIYZKxErYwRT1XyX+bN7xo=; b=J4T3WLYJLoDbHSW90QOftxi3xcLHr7EjZQJSnw78mmZ8BYt+eYbJaYcLy52w6k8mnI1CtjdB2jz9l9tP2Vp8g5E+zz2h/SMA9uFkZ9IZ2Af9sxJFl2mI2BHZBNk2Rs8iNmDDKN/iSAtt58dus4w8i3yiDaVAN1vF2LnLg5kGZc4bEOSX58W6e5sPVbOVLJOzN9tciaOtxpe9JLw13OnTAY8iEg+D6hYiU9XkMPWqZP8DiWYfWui5/9xb/mC3VBTDNnWQebHOuyMF8o1SNglaijzPN79ffMoq84W1mPD+oHN8EbocV+l7rVVRFmcdLPqhorgR5TS2fa3yu/YBaWvMjA== 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=07+ogLYIaTskzPijN/RbveIYZKxErYwRT1XyX+bN7xo=; b=KP88pLDFdZBeQmEDWIgoc4dLiGohERLoPJQrHneVketl4Y5/3yoaDADm7NVkcdmJKV5B2rArcmAgZ+76Vem2DfQpapNCScmZyBy8v/i4ah9g05hRyV6lQGbijcNfkMJcDfTcd1JuSdXRBojgcyRRLbSA+ZCaHw1gio5gKxjU7gdpc5olLD0Y03Vl8evKgSh2zldGFfmAi4iBrgaque6T0ne2/D+atGYP0d0gX+G38WrhgJH2cflhn+FxshE4x3Ei6kVTgVeB+5eiCybNJiRKn4ai7XU7M6Xn5gg5AU88OysV8FfDiJwzCPLr5adNmAWbqf8hnvD8onRzSsmX2lNGow== Received: from BL1PR13CA0007.namprd13.prod.outlook.com (2603:10b6:208:256::12) by CYXPR12MB9388.namprd12.prod.outlook.com (2603:10b6:930:e8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:10:50 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:256:cafe::14) by BL1PR13CA0007.outlook.office365.com (2603:10b6:208:256::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:10:50 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:10:49 +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; Tue, 7 Jan 2025 09:10:34 -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; Tue, 7 Jan 2025 09:10:33 -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; Tue, 7 Jan 2025 09:10:31 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 03/14] iommufd/fault: Move iommufd_fault_iopf_handler() to header Date: Tue, 7 Jan 2025 09:10:06 -0800 Message-ID: <6e4f3917e2bcf871b958c0d9f69dd3a182ee8ce7.1736237481.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_|CYXPR12MB9388:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fdcc7f6-101e-4fc1-41bd-08dd2f3e3c42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: U1G5tTq1U7rvXroiohw/G6khePh3jRBlh5o1D2EoVjH7UM4MT8xNFZtYDu7pSHYpw8wxkF6NnETM5Gr3PnJn8fU9N10J4Z7SEPd+hxLaCpGZ8sXK+jUJGJ9y3WAbQFP+aZTk9evaSSxrjdUwNPjFml+yHL+kqh9dMko0LoaKv+UM7/EsC6tTdmNdOY22smowA7BVsla8htOZLwOvQ2m+tO2yn87ldPq2qqvR3B8cdgCwhGlROGY9Rdd3y5R4SYYikcc/g5WzRj66bxAZnlfVCTuA4QpwQsx4MxDNfS2u0X0RYTGdOicok9R/FOpvIfvKt2yC/bxs9A8HcLMr26BHMsYGUP2VhgICb/YZjk59kZCcP25w0Q11CKSJxT21GR/RQMD2AEbui2Zi4H1XEowvyDvR4aP8wxj4vYJyljSqC64uW/eCYTlcmFoZUF7GTmdoQqrM0nfq5D94V8cNPwvlcLM7AWvkC9T/RJCvVTnv4cxp8saPqIxsyM9ewvaffpgrwm2PrKzmW/sfGPRiwyZYyDm6b05VtodnMCH77POkJQpJIFi/tfcIJZevuzhnmET7huygkadnlqLsMKiZAAU9FBFC06ULEPLy18rOk0MDatnzx/ypWNKnFo16gpzyXCgOyaSyCRzuJH2FlyVR8JDz+93SP+EzoxoeIlF4mAAfa+pNRJgLyyt/Kdzva71fRuKtQE0mv3eN7LVGfsW+CDTScrNdaApd3lnkdcUIShGspR21UKcRNL/RVOgICRw2fNV4ZxT77F+DHqZmz6iR0rocJ8U+Oi8DMBw4a9Qz1YbrO8n1WkNxgzQSWJDYoC3PIQVJ7xWlGCTIqWN382WFVT5tOAXo4TJKCOlTHX9upYQOUferJZ9toJj5hYOSmH6o2UZDIRJgMjaFLxjp3u5UZAipSEWLDt57xjIYA4jMeNBk78UAVFAWzNMXJnjWgitimLMbleW+GyXjqtSBX6eVxfYky8Sy5omdo5dLWJuHUD4nxo6Bjo6CW4ru02CAKLkehDvDOX8FEXWaoktCeq/mbTKaoOHJBtPUB+GejXO95frK0rh20yV9umn6GpJUIaZXPZQg0TmFWJLd8qc8xWAZ9mVFKAqyecrtfuxW6ZnhUuDwiT09tWQlPkWcGjpk7xsKFfF1pF9YdNzBix6UvHndc8XzSoAAlByZ6S4SVqfDWIyebNYxgIN11/0RD/2vI2O4Ch2rXcT/jxvvj4rCH8naY9/vFGexI38s7ea4GaLWU/gRZCcIecrWaqM3dQNdu+904BGGWmwL2oBKrW6jQ0OwLD3Im1zw+Rbyed4JvUtIUzlG8XeWo7v6J5/B0aEdImwZrHK6go9vACYfZHf2JKDMLx7XSL9IBR2rfvXAc2+VfCU02BLVDwfBaEmbqa4kP6A3vH0j9elcC0RXFmHOqLaL03950NOjacsElL1KNWWiycNx4tXQd9FtbKZ6BIOLGSdnIJApjc/a3gJLebf0+dk6tkTCrQ6T2oA+jD/AaG/QAYcNXC8= 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)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:49.9743 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9fdcc7f6-101e-4fc1-41bd-08dd2f3e3c42 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: CYXPR12MB9388 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091056_599916_B857EA5C X-CRM114-Status: GOOD ( 11.47 ) 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 Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 Tue Jan 7 17:10:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929440 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 36C6EE77198 for ; Tue, 7 Jan 2025 17:27: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=jqkcjShfS6Dy8gOwjTbeRHzenjQvP1jkdsMcdEpsLbY=; b=iwiC6TBNNsMQ+pJJvYinzrYnPk 2gZ40hR/jym3+krKgq5+5kQRkGh+2P7vLi9Sm/vEo3ThZjm4LmmHbBxL7I6ozVOJL2nb+WdbfOha8 isho9XPQ57iSYjJqsyGriGdLwKHHtCB6EslAUAhyT5hXGa/sh2RWNV2vWHs5uJdEa+Ry609s8ynyj GdsoLrzB3Gdw7ud8n6X7ZRW9NtF7Jv6q3Uofs1zIdSuYWwzc/PbJZ1ADsr3xPSKhXqBnyXlvvQz73 tGRPDBDD85yCDQrpb2LOwWzXV6I07iHZHE7Ay9glk14uoc/3PkBfpzEkGBxv+UEpt+CYMNwR0MkhI c7vAQ47w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDMI-00000005r3C-2cY0; Tue, 07 Jan 2025 17:27:14 +0000 Received: from mail-mw2nam04on2061e.outbound.protection.outlook.com ([2a01:111:f403:240a::61e] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6Z-00000005mC1-12kY for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CCtE2zOENW2ExjbJ2GuqbgU3H88Emhb/c8jID2H78I6e1iZurFVn+Mi/l+mgfV0ohFmyUZmKz4oQrimWTmKSkMPCPreDzt3kEn4IeOP5fin8VwvRO46z6myRSzjg2PcFRezJrAqhshz/FJxwZCXOzXlMK0AKmDyIl5MaPczN9f3d4k6K80YUtxkrouzmjd8uoCECaNkge9TdOJzwKjUc8oYoR1w2MMHxqOcRYFJTGdHEZotpG8j92bdWiXYV5CM7ZSArnCCK5xd/KnZgwlhamaT5Smi3MPtuYmAmr/vR+48TnpSgKRvVp3v1WMkL7uQr/Oll14dqLsTX6Gh45chjDg== 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=jqkcjShfS6Dy8gOwjTbeRHzenjQvP1jkdsMcdEpsLbY=; b=hspifUDXAwNexJmJbS4IijgPlEmyJZseTcyIuNiCGRe2uj0X17o7CP3B2/jJ+Y2AQL2pyZZ8KViUYP4UTbgT1LlBKunPLuN1XWBFEpU8YdgqX7ptYMYEQ8c07mkz8pIXF1LDc7adl+llbjq4UZXob2rLbj7nx+RUGsAd+HACe0MDbVlY4jYOE8JUlJlEqJwZubquVkKmYft7LlrQ8fRSfzjBE1AYZ9G2SXkh5cJsxqvHV8GuOiKe3C7GH/zrgSU1ofe8wubCKOQ/uHVlfpjqItBg55eo55HatQxcctxfoQzonGcCDjI40Y3/TuemFm+TbTpc6hSI8C8Ve6RM+ISUCQ== 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=jqkcjShfS6Dy8gOwjTbeRHzenjQvP1jkdsMcdEpsLbY=; b=rIo3s/mcqTyhrSLqH+qhqn9TFc7mgr9eO15CNtMITtEwHAi1tC++CsfwnaJCIcv2gdYiSsEhJlrBa5EEugrDKZnEPxoMP444CaEQVLurAWEZIAGWK0f9HbzALWboUxZubWTvIDSY0yaQlQ+vq25Ko0CZoQj0o4ymj3zxH9YE/TNzTwILih/pfXX6WvBGgHETo5q5MPez0Vc277bJRCnr7QFTVyTR27elepZ+QX8TmURE1JosuD0cDkVAZzMhgyc2f3Gf8euHx8PGvXq2bXiCzGyeYOe2h/dyVIV8WApnYJJ4SlilQNYH3Z73iB+RoqwmV397UkFZ1v73aUnu7/WfvQ== Received: from BL1PR13CA0029.namprd13.prod.outlook.com (2603:10b6:208:256::34) by DS7PR12MB6240.namprd12.prod.outlook.com (2603:10b6:8:94::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Tue, 7 Jan 2025 17:10:52 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:256:cafe::1f) by BL1PR13CA0029.outlook.office365.com (2603:10b6:208:256::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:10:52 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:10:52 +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; Tue, 7 Jan 2025 09:10:37 -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; Tue, 7 Jan 2025 09:10:36 -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; Tue, 7 Jan 2025 09:10:34 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault Date: Tue, 7 Jan 2025 09:10:07 -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_|DS7PR12MB6240:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cfc6c73-ba35-4479-2f42-08dd2f3e3dd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: lA5JuPylyPznI+/JkHVbDlsh1X7cpUcxPoqdO1ucpvv+GghrEG6a24/AQJQnhUhObR867dD0xXjBkPblzfR3TxaDIjQd4xnNdmRlFo7Pd9YNMuVrTk8leJZl+rVPLGLTkiw0JjOHBVae8MVxFYl316XdKHUhvIorValXwqdu8wIV/lSkWEcudB13P08Ec6YpZX+CQ+nEqZkOpBlyjGYZyDpnx+7odrsJryOIdrAahrBz4XPbU/G9KoGzDSE0NLuf65MFSDsyJSLS8fAkP4FR0k4oe/32P8WqNzLNfoTXDpNHZgygvVwTld7BMsUjyw8CPEVPhVKgdS94RA4NKcgLNL2SZUno6wHh7p8TKQ7d4vmXwQilqzsng/tCzAPZTpNJaFIrKC+MWTy9cRpI3rfwFP5tDdVJ63bp6fRHvYAafuKYelFNKCfeE4sabCCev7wAK5jStMXzBRaZvGnlzE8E9NDnLcXAvWeLFoJ9wBdWjhW+HLDqy4PujmEWaEm3q61fqEf3eeNDZnBu02CEAEi5lDZuZiNURr8i0Prs6dNOkdOBhLpp8Nmz4+F0HgfFRAzYkdizJhT5VWu1QkCrE4npEty4/QY53oHWf08VJlluSj21LGsXZKQdkTgympF4JCCv1eoDM7fZnArTqQZy+I22gsoXugVyih6roCBIHtdPMS5ShmUpxyeB9Pz7D2HUcbEMIx/Y9wokiyD2uXHkPh7R3PaAwD/adLOgMlzaNGNNz1B54D4TyqCBm/+TMqAMITtUyKnZF2uSCMwS5D7Mv9KPqg56wRqz6LJr14PWcRetRe+h1ITmzyhyWqaUk0umlQqAGXPN8djZQHT4bYuIkO48t13t+HHRQ4HUy3FW74nCD4MW6qYckbOYQNOMlI5WRpa86Aq7BY7msXrkUYNQL5dnNmMl7pay+ohKhTuBmOZimDtk/c6xm8jfNKF0QZJN9LOiT1pBwzMG5j7P4jEZ7K9WemN6Kpgax5t0LNjSW6pWPt9MH0hW8KJ8N3KaZjhBma/B6/gHCpUh0UcpJuCtshvJeqk3LMF+89iBT+vxK2J/RS524vyf7aHT4Ag03zRATVCbegt3d0BI8KoH1FYyG/X/edNxAkm0FgsfzKaGYwyiFTKv22rmkKOnsCLtujmcB/2aVLvNtIMu5QseyjlPbmJpKhuR4PHtJ/uQNe+1IBL+Z95z5IRkdIUplrgxzONqL1sssa7WkueECNeEb+9G/oDVknEiiN2NQebktxTS9S5nZ3XpXmozQs34Pk3mygaBe6sav3ir5rerT/oo1zULgUWCnA2aLbwPMdl/4jy+c0s4JO6or4pev2Plq3qiQ/zVvkwBfLHkMGihyP9KzRj/hFS7cWgk+KnXPpagvYMby4wnantuaqnmParEFBjwb/58dUGqdK2hbQ1SI+savMvrvYXI8vXavnz0FRIEoli3yYiEmlSWYRXIxTq6E6m4X4HcbwqWf5XW8uodyYZ2Sb8gbOtnRw== 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)(7416014)(376014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:52.6306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5cfc6c73-ba35-4479-2f42-08dd2f3e3dd5 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: DS7PR12MB6240 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091059_325097_28589986 X-CRM114-Status: GOOD ( 18.52 ) 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(). Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 Tue Jan 7 17:10:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929441 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 B84EEE77199 for ; Tue, 7 Jan 2025 17:28:41 +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=sqWIeKVH4ZVvezMJBQc8VWW9UMvWwlEcM9KiCKB+PH4=; b=nlh/tmBdq3NvBJJy0AJXw4DQXw EHy1OZAI0cseD0rTFNhozArSnVlPX5VAnncIVFXphGdEELue839/QkM5I8vw35an6FnHJl9jhiupJ kpq61OpDMwqNn88mVuF8L5l1pQkgnFOhO0qrqnMdlqRQVNFAr7+IfkNGdSPo2O/aOb23bq5CaSs+H NKZVS6c0/uba9moYB5DIpej+zdj9M4B1v/OG0405BEmLaFSFLU0yP05lJKHbXyzlOaKN4eicsmp8A iXH5ZoZ5yB7mPVbJUaiHL279PF4AL1zB7Zqkk542RjJ+FHzu6l0/gua4mvgupoaccmr4/GfBOUBi6 TIAQmMVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDNU-00000005rNW-1Vkj; Tue, 07 Jan 2025 17:28:28 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6g-00000005mG7-3JN1 for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hprHhcNVe9zeC8hSlcS6NJKSSOCPZsmAEiAsYuq9Y1PIvrQZRdrys3t/c3JYC7jyshlWz5dqTcNEJcI0bmOmmjzIBU4bynHSh74Cfti/am/hqJuxQpru3dvvUWBzYLEt2e75WtCixoXEI8LX8oCpt2bb033Nu6C2KA0HZAulh1gxXI7gTbsZZU8ZsRx4GoDaEvPyBKfAfsS9Pd7NxDA4l3eGL96kLnoHVEEv1Itk8cl0TOnzOkWft/qt2Fj4rhCMTRU/1u7muizuM/cNjoGBJP8jBZJGUY1+l9RyzAYiRT3MpMh/uGiDDb++pOj2HsOTnredMRPtUjTDSSaCC8Wjbw== 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=sqWIeKVH4ZVvezMJBQc8VWW9UMvWwlEcM9KiCKB+PH4=; b=BS3NlSQv6PEYCab0fYBL+lUAvlXLjndWwmugHbXzgvlSDFNUFbIW8lFCrdStb32RiZ5fDQRaA4SAzqUF0nXPGpl0eFb3D7JN00NOqqPk7zRXFtzJWPSweFLuWToKXEL50pyG9Xl3ahMRkifXxjiQ8kd3snn7/pmhsVWapv0gwW1cR1rS2dX1/rhZc/wCL+y+8SUrvxC2T3LrRmNC6QHPwnQF4XXxGkuK7tMGWouHEG0GQ83TskdtfmwQD+A4DlyymCO45lpIKwUGoDjXEpzlwi2qHuIJ4KN/UcsOM+Zjnc7S4agpwVuyDhee8lI+t4vlteZt/2w8ZTnur3BuYCo/hw== 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=sqWIeKVH4ZVvezMJBQc8VWW9UMvWwlEcM9KiCKB+PH4=; b=Rui6VRosto4wV3MNOtOm50o32NGPsq+J8jFjmMEbHLF8W0Yk+3o+yNGDejNVwMb+j5YX8ibm1E7VNBZDc6FD+QpmiMtpukmGISMjQZuFD21Fu+SxhEyPnQfCG6RuHCND2vEYOabdnpNcJh8N8U4eOJwonAm+2gL4NpI78KddsdaJWms9n4yjCzwZjVL6kPQPO7qusZ+SEWbwvorGrQwVO6yHZ/nhXWjQmcO0ep8hycNzAI8nHvz6adA3OgEEX/IWhH1oThrglwPQqU3VUfbEWI7CmvIa7iWM/QivgZbcl/LRz+59wWGmzfl5x+LxBURZ59p3Ujl80S80jhejrf/viw== Received: from SA1PR05CA0002.namprd05.prod.outlook.com (2603:10b6:806:2d2::8) by LV2PR12MB6015.namprd12.prod.outlook.com (2603:10b6:408:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:10:55 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:2d2:cafe::24) by SA1PR05CA0002.outlook.office365.com (2603:10b6:806:2d2::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.11 via Frontend Transport; Tue, 7 Jan 2025 17:10:55 +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 SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Tue, 7 Jan 2025 17:10:55 +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; Tue, 7 Jan 2025 09:10:39 -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; Tue, 7 Jan 2025 09:10:39 -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; Tue, 7 Jan 2025 09:10:36 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 05/14] iommufd: Rename fault.c to eventq.c Date: Tue, 7 Jan 2025 09:10:08 -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: SA2PEPF00003F66:EE_|LV2PR12MB6015:EE_ X-MS-Office365-Filtering-Correlation-Id: 88503494-eeac-4d81-7650-08dd2f3e3f94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: hIPsPgbYyGgbMh5RLoCceazFnXw91ERJ3IUM4+DHmurkJWDpCLxTDabTlIwmBMCnFGGF7MlUzMd0Irl5IyQoBj9BvaJKpskKzmudY8kxjAQnaJFPpi01xKslrp8eQam3e6W8Fokj3IfqEZCgAbMZqsFT0/dYbhPApX1zFwYp5jbJuUhkfk3dWa/CMkQuKf9GScJlZ2FcxjB4IP6OuVNk0gD83JwKpvTOPlTnQHsnv9PPdNLmcuKslQpYtBp/QrW803bR5g8969mtn+GWW4MhjoMuzuDhR5BROACgOqgAMAC4HDBtrBvib/hxUxNiqbfglFqV0Lvkif+kgGnjOp06i5SBEhJrfYSLwzo3gL3iMu1OItj/ZFnP6j8F1pQqX4/J4cQO1FRrDaUabPkXrz6ZKv24oZ3wut1OlR1E5CH8kvvOkm/yRheqczzYSfMuEid0/l4CZgW9kzvCXNzG1r1PI0ID3hSDe0ryomfr7l7m005EtPFb405FG10DHEOZFvJkfcr8fJlxaz8wGJSPvUim+wACUZ1QhwyOK1GBEOxWN1TzWtbrN0wv0eZu1gB0KJTl6ZXAa6wWAGnChcMOuae1RBnlWH9s5LWiugWZBixxo7dHH+Zv7N6SXOF/OvVU5N07OfONQKer7CYvPU9nd9Cf/ubu9aRgAyMpzz+Wsmux+GPCMv6tjZ3Yo1KdO+UWKSRFWCzGj/89GcN/T6FBsnYzKZe1yIrNhYDQU0R6Pi4CBU4vtrmw2LY/SuCGH/LVqLzSq3PcAJflP8sZvlsynkl5HorwbxQj85sAiOFsqLYo9RFnH4TJptOPXo3B7OL8mgD5mIr8EJtYVow0uXh2dGJZmnmTtf5KDwKGcDA+1B1YuEFZlpEg9jpPUW0D1O8Mi20ls/kAbqQ6o6cBeIqT0BGZrI4HNzqxGpFHEAloJ1lJh6LFBUKqVpcn75vUvbrhFAqMUQuikSKGOoxmhf5llo5A+Y6y7Ri4bTboUW/KOf6DswY3zu6GSmMyPBTgH7JhCWM0UyaMeYwjdiMVOV+1ua1G7WH7CDxu9flVzBzOZDpg9rIGmYwUd8HC/rUxTws5SJvD36DSareFVX6PPfB/UKHqSJNHP1Q3cuphervM49cAQeC4REm4Wpgi/+LJLinfwT5OEPPjbVIpcdBcZlqLT6+5IjsB85eQOBhZF8bmZ/zGfVZR/BAoO3o9Girb+GNqVDExbqIyfabWdKWpDESnTs8IeAqrbZHCtryzh7a8Q5spr6s6ZbsXqujSuzKRrZQfSYMitJ84UqyZlDpZR85DH35cRd7+hLEIxAPmdkQ3OGf7ZQ8GfmArcELFaYuXBP38KpsKWYyF7YGBH8nJSKvLx3WZaQbr+8oKmaUSCZ7uIa3/UqMmDWzWy4mDxo2ePPegU/WeGa3Txqnv9T50f+x1p0W9N9SAL6VNu2x75JidDxFXVPn9MCZGnzBmIu8nX/jrp9/gX7WfUVpCQZRFvOWxkP1yWA== 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)(1800799024)(376014)(7416014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:55.6088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88503494-eeac-4d81-7650-08dd2f3e3f94 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: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB6015 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091106_840003_CFDEB420 X-CRM114-Status: UNSURE ( 8.71 ) 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 Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 Tue Jan 7 17:10:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929459 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 1F4C3E77197 for ; Tue, 7 Jan 2025 17:41:25 +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=SD8L+p94ij/cRbnTaS398W97mnn1eUsxlqmIjapeULU=; b=BCQ1TV3S/Fehpp8H1tFGsdC9eX PMFTxk2gi/T5JYOpJ+XEXbPYtgfU3MkPlz4Z+91hxxhWQVUAicn3E2ccAAPQ9IPa5nSVPDMMS9YVf X06FBvxERGpnSG5pC+lL/Lq+RNm0LEtxpMxHQaOzzLjJcaRWwz2IXFZV4K6u0xCoi+vJK6REx1por eudMIq4WK5nVApkrYbyaEPnXZq0+MVQz/16reMR+u7MYwYSe3emb9Gjy0h3last/IReFJ1U+EBVrq pUq1OrpKkL4jGxIehh2wFWrgHsPunu8J3w97xByISwBhIhf0JWhxRaip263q/A9OFwVw5tpzeOCuP MurSWABg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDZn-00000005tYp-1pN2; Tue, 07 Jan 2025 17:41:11 +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 1tVD76-00000005mVe-2HUu for linux-arm-kernel@bombadil.infradead.org; Tue, 07 Jan 2025 17:11:32 +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=SD8L+p94ij/cRbnTaS398W97mnn1eUsxlqmIjapeULU=; b=js/Zm1JKbPuHIJeuXYy1CJ18zo wRATGV1YUWdVlhF2dQJSHlmn/zKHcyiMfA3x/KvZxRI0m0uW0NyC92wP697gcayAsJ4zqP1B5+ZV6 JVhGUdWG5mhPXDcdClb9ZgFQ7uJGiIsd7LgJL8+oW6c3n51m7Gyf/IwRNyGLJ8nmXuPi+yqyemAWl QiiaoWmDKMp5Qpba/eLRvPIAtk6yU5ury+dRu/+DGczha14u2PZoHVK0wUL6eWTqsXy/fwcRbpVON YfZqKJaJvUaGyR03rRIfLo7YDdC3cSY+tXDEMqTsdmjwHCRwbkDZ1GHYii3I+w7JQVFshlLGcNnC4 JvqOJ7/A==; Received: from mail-bn8nam12on20607.outbound.protection.outlook.com ([2a01:111:f403:2418::607] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6n-00000009B2C-1UdC for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i/d6ffaomR7UJa698u+jR5mJcZ7fNiQgvAEMJr9eRq94zYpzGUBrVCT7kt24jtvg7QY1uirAGVkg+RXHzwZHSdC4A19bEwJv+vofulteM61eaq06RjxjKNbFDbq67PQ6WY79POdijDvcDz0yOic2uR8E8U9Nmkx96zsZKnDEU6ssNapztLklPsYrz7jP+qfgtOCMC6mnUyrwlYM1OK+VCsOom+EUq3gv0NJj9F2O1e1aAhbrwQIAOrntS0gK0lpu44sBQZIfTlNfpk62y1GyY9HiQyjTV/CnUQ09oI8QTuPIueq7FL18TUt79nbKBiz25pMjF3wkJMtyoYjM6zwkEA== 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=SD8L+p94ij/cRbnTaS398W97mnn1eUsxlqmIjapeULU=; b=es2q/AX1h9GpkiTXfCk7PA8WHsFPGwf9NwoTeFnp+STsSXkwEZtu/k5TdeY942zFgKW2inXcYM9NGa2YaKwMHd9cKyU56SIFDmCmimwI9+DxLBiGDz5MEFVVZX57tkZM+o6+WjPnaddrQEq1XiGmXoijyMjC9zP0m9jSzESGGMpgGa7Qu9CqRFv6xTSW4N+FzAPUS7AOWmqViq5hIXXUxF6SUZDNHLuq+eJfMOFztA5bs8hPVEMS3VNBg1WBVmlcNTfXqSsgIooMqANiN9jqu1iDW4FyR5U7toEiRrQJfKMVH/EARTkPuUIaJtkBn/gV+eqgmfNSz/il1FoEkOO9fA== 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=SD8L+p94ij/cRbnTaS398W97mnn1eUsxlqmIjapeULU=; b=C4OyfDcd9cSPN4TuQ/iYUXnfQl+Zmtxlk/VYsRR6xqyqgCE0774B/XH4ASPjfAxDw6RhY4dukZKs72PHhBw7EOKf0i5xtZLtHoa7J6n0jUFRaHBhNaKrTeBzasnKRyWODDQ3nCb3N/XjaD7Q+/gbc0J13abFb/uAcyb7daoCBCcJ8tEGJGxfy8nqLb9mNYFB7xJIOZVMJ9vw+pTl/vD79QzLThVMjenKFsI5/c6TcONazt5s2icrSN+TxE9yMV9UFSemucalwwYEJZFHe3FOCFnTm0nDnW7qpXP33/NskpekISN0CkcYget/gpi1PFL7zdDaljf0UGptQySIJ2/kKg== Received: from SA9PR13CA0123.namprd13.prod.outlook.com (2603:10b6:806:27::8) by PH7PR12MB6443.namprd12.prod.outlook.com (2603:10b6:510:1f9::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:10:59 +0000 Received: from SA2PEPF00003F68.namprd04.prod.outlook.com (2603:10b6:806:27:cafe::84) by SA9PR13CA0123.outlook.office365.com (2603:10b6:806:27::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:10:59 +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 SA2PEPF00003F68.mail.protection.outlook.com (10.167.248.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Tue, 7 Jan 2025 17:10:58 +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; Tue, 7 Jan 2025 09:10:42 -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; Tue, 7 Jan 2025 09:10:42 -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; Tue, 7 Jan 2025 09:10:39 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC Date: Tue, 7 Jan 2025 09:10:09 -0800 Message-ID: <86e78625c48d0c8fb815496dbc57708b98a46ec7.1736237481.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: SA2PEPF00003F68:EE_|PH7PR12MB6443:EE_ X-MS-Office365-Filtering-Correlation-Id: 365e6b84-5a7f-423e-694b-08dd2f3e4180 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: gYmXyEFC4JBly8RZeHijW4iB2cZeMGxjz1hQsFiG5hkwXcSMtIDwqttJ+8EVk4LRb5c34vdpWda5PAtG6vrK6d3D6zE44X1PvcQAK01fkjoQBMOpzspvsHUxpjmPFFYw0SDrCifj/u7y2pWVLB3Tp4hBC8/za637Y7bjngqEOw7nCYRIX45XS++Owgk/QNX3NzvvnoqNfaSIvpj2f8kc2nEwYeZ9p8WfFkg3pLoxQ++SdwwAJ1tWL2ikZ8DViW1YhZIi4SQ5ei4Xz77mIruLxyMKvfwo4gHGRULuMIDu2+LcHN0DMJ+2vBR02/G25qOMT/y8X0yLps8A6bDfN+9FqltqBvxyyiVca940NGH5C1+P2IZSlpJpsCLQ+Gdjvbxfj8OvTtTeTtFiaaXhHVETmJHDzETEnjtky2LmEH+0ngMdpSRrQbtMzvtPZUPWTtGhNjV5pVxS5XDPLi2xiQMGJpARSVcfWUCzYgkOiwYNMj9WtoxzZ49gkfpNiyDkvvPdgsqfTgq9v3ksklUptq4Qk5YTjGBNZWGdRzEJvo65KtiAaVLiLxQ0mBwUhgQ6MepMGMlMb5w5aNS4TpKGZM/AKRn/xJJYE6U580h/u57UPz7yp+SQ/UWZmlSs/Pe8SAmUMbjtl8GUnTFSa1oegbf5AadWQjB0Cer+bYqsExStpJXSBfHXqvkRCg0RbtzK/n/UrvdsE8LDr9dAh89irIO2EZJBfc3PtYodYMbyMXAMhjdbi7UcEafFQj4QUXAF2+UIttK56r7vuFTVfs286P5qMX9QiMuIU+RPt3xhcDpQJaZd7mO51dNDgC7pzgry22ARavQQmF7SA79l+bMU4lwRRAjp1muEe9OYP1AqZCKDZk8uHJqrF/UQAVR4uHI0klTkkvSuBmwUAI/otdlDUGPURBBhsg1UHEiBUatzyXjKqVhyCeCeLT9e6LGa3Wh8OpfbYNsDQ5qvkVHkjryK3ZGjpchjMn/w7L9OA/f4mXmomjIaDF4NWRt4rMfXpNLRFTiraOcLTACzbnbVChSp8T7rrZxiCaj7ZEPWaf/Px6KySzYTqTSeoYEatbGRHHYA6h9Rb7xFzHtMTrGQrRIMI4weKGkr3jv019zftzREJHBC+b88cKL45edpgYBBUgs1J0IfV3IaonYnHAXnoCTG4UV6nPEYliJWP4784ghQOyHLPJhsztDtS7YAKiWRXyvlT1b+QOXAK6qukS8uUU6K96zkkY5/xieaOr6CeGyep0Q9cT+gpjktTvVBQbycVXtDcHVg57KHEfft1ceG9e3v4da899MpJNNlirKGpuNkgN5TWgCBnMwUBWpvgLzyMlviWRmRQryb99MbyalFbMpCm6i092cGhj5dEeIJWOzWvrJQn/kpiFRIv8Jneq8SfKizVRNn18E//lZMlJWDbMZOWdIJAbFb7AmPcSP6vMTuCbegW/nN8EgFv0BcVSD6+38g5Os79Jse1nISiQSPx52Lo3gnE50bxQQ4tqX/PrKdlIUUndQ= 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)(36860700013)(7416014)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:58.8328 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 365e6b84-5a7f-423e-694b-08dd2f3e4180 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: SA2PEPF00003F68.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_171113_942127_ABDE8BAD X-CRM114-Status: GOOD ( 19.12 ) 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. And add a supports_veventq viommu op for drivers to help the core code validate the input vEVENTQ type. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 58 ++++++++++ include/linux/iommufd.h | 5 + include/uapi/linux/iommufd.h | 31 ++++++ drivers/iommu/iommufd/eventq.c | 134 ++++++++++++++++++++++++ drivers/iommu/iommufd/main.c | 7 ++ drivers/iommu/iommufd/viommu.c | 2 + 6 files changed, 237 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index dfbc5cfbd164..3c0374154a94 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..941f2ed29914 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; }; @@ -113,6 +116,7 @@ struct iommufd_viommu { * array->entry_num to report the number of handled requests. * The data structure of the array entry must be defined in * include/uapi/linux/iommufd.h + * @supports_veventq: Whether the vIOMMU supports a given vEVENTQ type */ struct iommufd_viommu_ops { void (*destroy)(struct iommufd_viommu *viommu); @@ -121,6 +125,7 @@ struct iommufd_viommu_ops { const struct iommu_user_data *user_data); int (*cache_invalidate)(struct iommufd_viommu *viommu, struct iommu_user_data_array *array); + bool (*supports_veventq)(unsigned int type); }; #if IS_ENABLED(CONFIG_IOMMUFD) 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..b5be629f38ed 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,70 @@ 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); + + if (!viommu->ops || !viommu->ops->supports_veventq || + !viommu->ops->supports_veventq(cmd->type)) + return -EOPNOTSUPP; + + 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 a11e9cfd790f..0d451601fb9a 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -308,6 +308,7 @@ union ucmd_buffer { struct iommu_ioas_unmap unmap; struct iommu_option option; struct iommu_vdevice_alloc vdev; + struct iommu_veventq_alloc veventq; struct iommu_vfio_ioas vfio_ioas; struct iommu_viommu_alloc viommu; #ifdef CONFIG_IOMMUFD_TEST @@ -363,6 +364,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { 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_VEVENTQ_ALLOC, iommufd_veventq_alloc, + struct iommu_veventq_alloc, out_veventq_fd), IOCTL_OP(IOMMU_VFIO_IOAS, iommufd_vfio_ioas, struct iommu_vfio_ioas, __reserved), IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, @@ -505,6 +508,10 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_VDEVICE] = { .destroy = iommufd_vdevice_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 Tue Jan 7 17:10:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929457 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 5CFF7E77199 for ; Tue, 7 Jan 2025 17:39:01 +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=ERSMdPLo8m0QzzQ6QnVP2SGUYvy/03JE9NWR4O6wxj0=; b=C/MS+nR4eCLafi9RDg1sNFRU50 cGzEFpzjz4N/10MRruMC68tkzGfYtIZs5CcuIVhOfBDg6vRBqinDXoQFUr6KbB9V65icU56caiid1 YaOqAw9FMZlkhnsI33cm5MkSDga3g4qkR8W/3ENwbfIIn/ETNoszdTkjh+sJr6CAJbWJlxErZbbSj o8aAR4b1wkP106dDU0P+t2gRV34ZMAzMgjSAIeReFSPOmwbAdWaVRgJDrACXx+sn8XQ/93fHVzr6y CaYwzPmBfNLdiQJqu3NQrJKQSHIshH1tqR/T2L3rDtbaxHaObZbGq98miAU39Ov55lA2rhek8n+Sm cFXqZT1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDXS-00000005t4S-0IYz; Tue, 07 Jan 2025 17:38:46 +0000 Received: from mail-bn7nam10on2061b.outbound.protection.outlook.com ([2a01:111:f403:2009::61b] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6j-00000005mHR-0k1R for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CqHtt7cZgnGAc9fHSZb2K/3ksyj6htH/VphnY2mM1a2+Vk89cywghCEoGfVPGbClZj+2Ynu32BvfCLl/hQl4hP36mthqrJexMwfY2Z2S+oIqjCm3eaKu+Lg2KGj8BESLrZMqnqr0iHpzC57BQczsU8aqtenC507yITMk45UWovjUGVRnoChCGaANrw+xVK4V3qYCiV1KEVjbwOUGuzvt2hKPWjATB0oGO0Bwki7Iu8uwTGcqJE2aJp9NWjAmkO4evTvPiDsrxH6r2rlFy/51wm6if5H5405Ic3YoJqHcgvahJ85Vye0xNbqCKxAoAeksgB0cLj1ZxXXBgB4G6lPA3A== 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=ERSMdPLo8m0QzzQ6QnVP2SGUYvy/03JE9NWR4O6wxj0=; b=HPCjawIwz9XnWXRKS1pP9fcciZK9LNlzL0u/l9d7IrPss6Amr6B9Jumrtyz8VKzS+cviCMLrqmMjSnSa4uvF5bigzR0Ul7pXeVL5QEByDUhG/w8qoLj+xECPM0nqehzmR7yKnNMuFtnGIpUjEnxZEtfuSPK8KQwszf8D4u6asi7KT85OSGF8+nuZgD9eXVC8/z9kW/PqO8G0WCgA6GkpwYhsZCWdj+scuoIMpRzunCmJ070FeseY7YoAjxFh05ayV/jWzY+GiaURqFuv9P49V2FAv9LhH7YjJ8rN/fg3Y7L2YhyQ9ZAr+PqSu1GFso1Z5Xjvfe1OPdadztwJyfqUoQ== 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=ERSMdPLo8m0QzzQ6QnVP2SGUYvy/03JE9NWR4O6wxj0=; b=Sm42v2VVY4ulR57dBTSo+Mp8WA0GkvD2FHxhx3q+8WuzbPF0xJbKKYYfrk8Dk9X/nQTd0fv7Yw8mQzGEXNQFUIMrhzF8L8Mk+9g4tzCGYeq1MF0CWocXnn02E2HEhMRKJ1sHgH+5q7bauPz1yLATNNpKuLXpXEqJ1pzm6rGm00UQAz6yoszV4dwiJ8XrXTAXWXr5R2gJxJjZm7DKcdhtzZV2FC8BbapUg+2f1yIqClj5lZb7VuCjJTi8oJKNwKb6ygCh+8LJKo73k6S5qF3Spk82eiwnlyMslb8yNmX+T21jHdAAtK1iLPlnTbkyDgcuNQFZH4hQtE0KlcHwOlropA== Received: from MN0PR02CA0020.namprd02.prod.outlook.com (2603:10b6:208:530::31) by CYYPR12MB8871.namprd12.prod.outlook.com (2603:10b6:930:c2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Tue, 7 Jan 2025 17:11:02 +0000 Received: from BN3PEPF0000B069.namprd21.prod.outlook.com (2603:10b6:208:530:cafe::f) by MN0PR02CA0020.outlook.office365.com (2603:10b6:208:530::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.18 via Frontend Transport; Tue, 7 Jan 2025 17:11:02 +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 BN3PEPF0000B069.mail.protection.outlook.com (10.167.243.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:02 +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; Tue, 7 Jan 2025 09:10:45 -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; Tue, 7 Jan 2025 09:10:45 -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; Tue, 7 Jan 2025 09:10:42 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper Date: Tue, 7 Jan 2025 09:10:10 -0800 Message-ID: <1dc30375464927950e12a5a52ed0433c3b01b8d6.1736237481.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: BN3PEPF0000B069:EE_|CYYPR12MB8871:EE_ X-MS-Office365-Filtering-Correlation-Id: 0acf61c5-feaf-4123-3337-08dd2f3e43a0 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: cUlKZvPFPPuc8M0/JNfV/6ypkHjUrL26W6pYVmBKzX/KE3qU0mqS2Vv8wbQDnkx7p6H1x936Ip5P3VkwMsio5zNCB3aEmbfWI1UO9vC3EQPOLnmmtLuqE7Ag+Ek7NQNKvr+5uLrQveJUM03xw3q43++437nCExdzkHweMWrPRd5HsyuWEq6DerjF1e02tARvjqh1wUBs3XATqbxcSPcWtreP62pflwqSDfmI6WhCa8Rx2PBP8DDcKvG94R/sCJd34jHJJ80Pw/Lcwb1TWzpF86fWrsyurK1D8/6b8f2ItZvwWimcZyZg3BYvCriiTFo+/zdXO+khws4Xr2FlFtqn/2IAi9kMphkGevZyyswtud6HwaQA/wsaF84XarJglYPkXkmR144dh6TqZ5MZowZLUOzyEr4t4z2YA7u6uerXVZtc9jQE/6JvC2H4b8p5n6ASSfwQOdOjj9WUTFr7Tap73rWDOqWc536VgsQ4ERx2I1DOkyBNtE1x+ubukvmEIhRgluTs3/4lOVuM5CpEatcdcds0tK+/F+a7tcubAwIFXMoaUil8s6GndPXT3SpBl0Izu10z12NiVteK7d2fASZG9g7ipE8MGPLPg9Zuz8mFrS8+Fh484vrMD5MAvwwY+Z78bv8WKJUs+H/vwAWJMtNKR9A+0+q4wH9/J4YiLcXJQIj5JaqQFkPZdv1ORSoGKQZo2csUu2c5HEvlDAC4aCbYGa50aQvXKT21wn3ImZHNlPdUnu+GeH60FwRAa3ZVkYUONC6/B/0t29NmvhUFfCZ5SaS7xjDhMVldDe20eZIRNeEhK7pdrKhzAT4uVWQt9w/OHdGxnEpMMZn5FMqN+zmSj+N077xx4wLZgHvWe8QI/gCG6O9jNxse1jlKwM5dZyGWEyL0fG3SPyM3liJ14ADmfMWBs3u4aVZ1cQP8OQTya6WaBW9ip+NFTELFoXyTw/R1B6Hy5u9GwZSgvaZeaTGOXvHYTKgz0Dcd2jaj2atKTsRNPjrpdwEPrWqwhfYq+wPPLUYeWbrSNfHOoB/5/izB6LTYzOdT2EVWfFpDDm69lMprxPPQy8arAaq4R/4OU/iHThjq2fL3Oa4a0fd+jYzlfFdOtvFQDMZdZ+WuCUaiNzzMFWucPb2hCDqoRp8LkLlkLbLs4MPQwoCl0JLsqzMFTg0Jrzrew6/uZwK3W8rhZmhvHyd1OgXTNOHZHsD/LGUYHKRONPUMutmUcPpr6zk7fR3VUse7be+uGjYj6OMfwjN7BbdZi1akXxmfu7TjEgoKoLecPypRjW0nDqUqWnFxflv6KeVhj4pL0GU8CPicyUg0qkhwAhYHHPhZRa/pPxA/otJBluBNgdrmMuT3P05QbLgRR/srrqoofme9CvXsnsZKPFDsFHu9pZ+66B6T6hDf7Mmw4Kk69RYCw7tJgeqTD8dFwrrSUgSzx/HnXjiQ1GQoNWP+LKZ5SWf9/OlIpkhpwAYLoZT7NSc6XtWriwHBtMTtIKlbnztdLCj2W1hSJb0= 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: 07 Jan 2025 17:11:02.3497 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0acf61c5-feaf-4123-3337-08dd2f3e43a0 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: BN3PEPF0000B069.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8871 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091109_210548_7D58329B X-CRM114-Status: GOOD ( 12.47 ) 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. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 941f2ed29914..a6dd9f8edcf3 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -192,6 +192,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, @@ -205,6 +207,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 Tue Jan 7 17:10:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929443 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 0259AE77197 for ; Tue, 7 Jan 2025 17:30:34 +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=3+s3Zq509Qux3LkEi5VFqIBrMZa2wNiJ+9xw+edgq9M=; b=ECVf9+FYHcCrJ0xLR+Rc0+E2wq rNi+tkEkCLzy/Ih5cOTaVA/QhMk9foiy+cLY8ZLXYi2ku8pUGhvBnycTk8u708PWf6v0sqMme32LU RX1XHqpSAvjqYCcKwupyEhDnp2lgZDhVYfrnVLGlEoAfixw3v5s40ucX73ILV+ofvr0cae/BNmTjq Ia1HHor8eySmhbpNz52Boadu7wM/L5MYDTURNFQ1HmQ5aj3WGW2mWbQtiV2Ygyp4OVmlRmTZM+V6+ bicJZ3bdVrgTN+viNZf2nC/mcO5P6+9IELaCT1prSHnewl/rps2qAXBayrlVXFyrMhJiYae85TUnh A8CX1rmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDPG-00000005roh-0LnG; Tue, 07 Jan 2025 17:30:18 +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 1tVD77-00000005mWH-3282 for linux-arm-kernel@bombadil.infradead.org; Tue, 07 Jan 2025 17:11:33 +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=3+s3Zq509Qux3LkEi5VFqIBrMZa2wNiJ+9xw+edgq9M=; b=bH65jSTCfzqu5cgdVYkhGkyUDU Y/Vay9oVtLvM/yHNNcposjcq89QSQhWAfAk8yC4h2AxMijv+9VxH/EIUNIkfUE7UO4gCHstaFOeyY Xw4Df9oDafaxZyG99E20zsTJRbp3sFZHnz4eXXKpOblYu2iSh+4fB+g74heFULFjeNt0KSoJF+UlP Qj60bzeTbHPfcP3DtT4emSAVAhD0eLS0UNl4zcRdrB+PtZTFVEkbtvqG4uUMb8iV/OyHeZ3JARVjk pwb1CIKfJ+fjNy4SCpp7fyvP7ilXClAyg+S/CLS+yL8WynnM2T7JY7bJ3nB0yrrTJiJbjCF4ZDYX5 W+j2juEg==; Received: from mail-dm6nam11on20602.outbound.protection.outlook.com ([2a01:111:f403:2415::602] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6u-00000009B2y-18pp for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RrjoSqLE7pB2FO4+wy6KyclEOdHqRYZLZbtB5iDgn+jpIZdYS7mvcaG25Wmz1su6OMfXAb1RwHLS9cduaVhk9fGSMVHMKpRZnKBwk3M6U/6FvBNDWXVwrU0hczy0rrRJsYGE5Xze28Rd0yL3pCTrdJNARlhOzGQR5Lrqhdg3oHkVACeWwCYzCV5ZKwSGMA3LqnkSnp3EjAoI+R+2hhAOMpAo26HT7vNiG/as0wOKAIAY+DXQ1DjZ3XmGknWs82pctbZvPtXOMLavDSk4fTvJZcWYNfpkIG4c9uQ0scFZyZnm8LhUEW3fYKJJWgLFrsTRKz71ggK61gLZbEpojtN11g== 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=3+s3Zq509Qux3LkEi5VFqIBrMZa2wNiJ+9xw+edgq9M=; b=QExkZv7hTGJEUSyxNurs8cKCTFhT+QDcX3qgYWE3SbUiXR0HvvCvYNeNC0gpgdfZJ4AL1PyyCN1hdQo+3cwFqpL8BhLPlUfNG/9ljUGW2FkzVveo3m8jgKhx8ljzBP3l9UwGCA4TG+20aq8YLUtUG+g10fITMq41HQdQ2OGygOpo2qy5morvC5qYYemu8VsLjNMsWD0fxatm+EX4PuzkcxCZnYxERY2phXZE7Z0GjFR9t7xUYgRB5/Kdr7Jhe6zylEz3MMQuH5b5osP/NQh6GmzoHUNPQZBmy6Qk1XkqtQbT/xha8OjaQZGXbgdNUya0q/PTVXDi7VT3yNSmTEMbAA== 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=3+s3Zq509Qux3LkEi5VFqIBrMZa2wNiJ+9xw+edgq9M=; b=ZBIMRPaEyh/1JRX0+4o9FCNhRT9gGoI3KipIM8e/ef+yeIrjLLtXoJV8tCUheiOMc8IU3tpWqc/4dtUcU+ts8ajfBCpDpfbcttBn+ZkLJFERY0C5LajjQoJkhHZmumFF5+mH/PFqbL/C7gwzw9dpqdCy0nGuW4zI540iK5aijUGCwWVC5SW6/qTYOKDCaLZRrKmczsLOQUlt8KNHAVeICWrPgrTc/JHxBCTOdGZhjyvHboWtXauGHLzvw46vUvZPKx8m/RJME2y/b4D40E1pOfbWNpH0qFuvLk2c/Zyh3sy6E7zU8DrUaYwswU6OOFK46u6ZYPxJhdEU6fLa5bHo3A== Received: from BL1P222CA0002.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::7) by LV8PR12MB9109.namprd12.prod.outlook.com (2603:10b6:408:18a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.16; Tue, 7 Jan 2025 17:11:07 +0000 Received: from BN3PEPF0000B070.namprd21.prod.outlook.com (2603:10b6:208:2c7:cafe::5c) by BL1P222CA0002.outlook.office365.com (2603:10b6:208:2c7::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:11:07 +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 BN3PEPF0000B070.mail.protection.outlook.com (10.167.243.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:07 +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; Tue, 7 Jan 2025 09:10:48 -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; Tue, 7 Jan 2025 09:10:47 -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; Tue, 7 Jan 2025 09:10:45 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper Date: Tue, 7 Jan 2025 09:10:11 -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: BN3PEPF0000B070:EE_|LV8PR12MB9109:EE_ X-MS-Office365-Filtering-Correlation-Id: 221cac00-e146-46c3-bb00-08dd2f3e4676 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: bUJ3EVVOhvX3IcCVlEdUwTCnGZQGFr/T2b7iB/dXYF3Wzt5zDn4WSqBUwymkjqL/gpXeiKUVXKBddMi/aREV8QGmMmslMJbH5bHURfqmkQeUidBZVEZVF/bjUjjSP4AZAH5TEOf0UTjuLQqlKOLNvd/F3ADiD1sT8xWqgA/MybTJGdq3AzcjwjHTsPDDiX14Ey3hpr0nBImUqtl2UZNWL/ulyQYyn6MB1xSfNqVBM11d2ZcS1UacsuAxxq8gYOPXN/ULBINcGuwnBrCYeLo32Unn/po5EepxhEGDosqxBj1ubo7PUlp2LljGkQn7q1gmKwa869ujP9/e1PF2VAWTQQvDwQOsdY3C0vTWzQrGodpAW9XcAtaP48ciGARe7TUoiqNaX92K0H1hcEzu8TrCsUy6MWl4F//ZvYDoA3hAJZEpsZz2Eaef+QbZdCXF4yJUGsMBAOYfyfGI4uwBhaIu9EnOJGJrvdbbe4ko/fwAfX0tIhg41NJVPhV2PTgXztyxlHN9dPt40yN8QIPbNSYZFuOu3mDy3tgJa8f9y2HZlV2TWKfe/gv5OT7NrFVWe6iRqts0HCo3CjRrgfTlfnIkeb0ig8ZPNfSL3Tn2HTZjtkRS5XZkIfTby3YlsNMtpzJFH6MCqQm1CkCMEyUW7+CIC4e8sncY6kf4LL3dzoc/brxUKit4+pelQ+9gi/DN77GghTjCL/+YutUv8lxM4G9BisGf0CWdvgCkivnt6Rok+wXDroqdzGX8I8wxUQhQhS5SshYSonnTayBWLDGI0f0e+x66PNykUp8MDkucrdWtcRnTWkusidvyD8fVKU2hwZHDU1S5jTdTd8uVvN38rh2Rjz2cm4gpP7R+sPI+kFBdkbURzSj8RKcWVxaoZyKBf/YEVvy3jvmPPi1FVpEaB65jhVTFvjC7mV7F1I6DzHuktBdxDbaxHwOcdNI5vSw6cYofqqAft7mTCaKBy1hy32pa1T2vpSNbtZ5srfqyl7dQtqhvdDDsXlgSqiWN5z2gBdlaoCIdwmsxtPK9xN8xmee/updmuA8w1iJQRFdokxn8rCVxZ+BAYtdnFpKjaopsHEdy8wxAbwXYZ04n6AQsMTp/FTTi2HgLUnA+CNQm31y/Jb1vNxthxtupL7G/0wzQeYnWLzQunWZihZ1hP+2yW9vaq6W1QTbVpPax19z+a8fOu1IFuotekDf1mIzu0W5r4/1r+F1nHiIZ1Q/KzVZ1xCAiWuckdVWKZ7urbUH7Jiqz/vpnUSQCRy8gDh99rHnxsoAnKiVtv/Xe6jJ2IOAydySOyrF2rjkrMPkoPoCHW8UeJP2leeYl67uC/xaaVK7oibP74uemQrxda4xl+3bR6bic9YWC7O1E0MNWzJNRep5y4UU2m/DlHbI2Om5yeoGQ5oF//qegURDGLFpRzIH/KeY4PyiUG/yIiqCidTxl1IGaNgp+UIbM5OdWXkysLsJnn3LpUrFl5dbYvlKWnPkTWh8fu+vvo1shWUmoORslpM+Epg4= 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)(376014)(7416014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:07.1111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 221cac00-e146-46c3-bb00-08dd2f3e4676 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: BN3PEPF0000B070.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9109 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_171122_690196_303B97EB X-CRM114-Status: GOOD ( 12.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 Similar to iommu_report_device_fault, this allows IOMMU drivers to report vIOMMU events from threaded IRQ handlers to user space hypervisors. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 11 +++++++++ drivers/iommu/iommufd/driver.c | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index a6dd9f8edcf3..55e71dca3664 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -11,6 +11,7 @@ #include #include #include +#include struct device; struct file; @@ -194,6 +195,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, @@ -213,6 +217,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..b03ceb016bee 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -69,5 +69,48 @@ 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(!viommu->ops || !viommu->ops->supports_veventq || + !viommu->ops->supports_veventq(type))) + return -EOPNOTSUPP; + 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 Tue Jan 7 17:10:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929458 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 EA160E77197 for ; Tue, 7 Jan 2025 17:40:15 +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=WV7vJIRdrY3baiyjoQvtJA6nPH uhyB75UDDEpXBRaXAHoMOV0ADJ8wdqACf5458RbNat7e7H6r8LN+CM5Gu0T7ncj0UIs4EjrnYmZzH oZgIo5SNSNdZUjWbAb8b3RqJjPNLwY1aWYDcgjhHdAXsfbVzF04v1/GlZrcl8ZMI9NdBSDCXnxUhy RDyuWIcZlDPzOzJOoBdOVqdfr20t87K1l5OI6bjNY4dyPY5Cy2whpdCqsvhymSMx8/W4ASv3MMl1e 9L2Fd2n+L0aWdEFN9IGCKbDGtlDmApgZKPdli8weOkjluBD7YwH+PEENDgQIT99Ix6G++or5rCfXD 8wYU12iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDYc-00000005tOL-3CW7; Tue, 07 Jan 2025 17:39:58 +0000 Received: from mail-dm6nam12on2060c.outbound.protection.outlook.com ([2a01:111:f403:2417::60c] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6v-00000005mP2-1UKr for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oInDzetp3+jfe9tf1/Yd591l5kIdEfK6glB+B1xs1JF89Jf3vhWfbAsksxXLx8Nv6fk8MWQ8MKFr4299piqBwfbROZJrD9Pc/1ryWb4sWnXuHAOHh5+4uMtrnm1Yb+4T7kPzq9F8eLdCd3dgsl0rQuGBzWie+bItA+h9VZLnwE78YEzJDNmPf1V0D1JzRATj6b8sO2lk9w9mAUDf+2Y4jbv7IBLMnApPhUwynGubRNbc4Kq1KDZY4z7BbvYeIOeZDa2iou7cjqOkRK7gsn5byfYlHb1hGTcPti3TrqsaDy2OVTQKYKkkqtW6MlYShKbhzTxT7ZMgO2z5GHmGGGTyIA== 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=lcjNQGITC8jyvSqOiwwSqwLfmrKk/nfiZMTmA4Z3mqdtSIDu0NfdTDr9IpAQUGWx1hDfNG9vryn1xyMJspwRH/c3BOkS6SbAB8QgkC89/7TwaUrO42bXANxYErlNKQr2ZKcvflAHiFw+cgMhUY2qO27nVrn8mIbSrjqoXDt9Gm5OFcZqH3PhXciXlwbi2cHek+jMa96xdR0v2lqC9yz27/6VLO5tkwXelwrPzAJN/STt5kifkB6fIsnLSmXp68PmnxrqKd3wwPU9Csr2r4cFZ3by8zwlCuSojxSn1/kYjGZZklD8mrDesVoWnStvXD69vyKgJAhmEyXR0+zaeBrLgA== 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=rS8glOESCY7MtGcKcpxCCp7pQ7TodetWuu5N4pB4Knc=; b=frcCm7zAA8l/QNv9tPqoUVBswJX6dq8tVFHTGudIe/r8WHPl8ybDFcpWI4ZZbcLRAse1FaZBWBLCQ9bNmh2edt7Mxe2sFfNtPanJPMD0qATYxcBpTTNSBQOoFUtoO1EKwt2y6ZIHfAumyxf9Ndm+Mb2zgcEGEPDEWjB6ZZ49QCXONx157k9tnedOK4HYhnT2SYvdfmkRwT9MCiekdgjGQTbHWPV4GzeGoMRN3s3WOXHg2cbhaVbDE9c4QUNdPY5Rd7Mjl6psENH5MzeTpnajet6pHMZ3Z1UyExEz5xYAd+jU0PViu2xCwk2lF6vq0CXUlI/7OoHCPdZcyLeb22ox+g== Received: from BN9PR03CA0326.namprd03.prod.outlook.com (2603:10b6:408:112::31) by BN5PR12MB9485.namprd12.prod.outlook.com (2603:10b6:408:2a8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.18; Tue, 7 Jan 2025 17:11:10 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:112:cafe::97) by BN9PR03CA0326.outlook.office365.com (2603:10b6:408:112::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:11:10 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:10 +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; Tue, 7 Jan 2025 09:10:50 -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; Tue, 7 Jan 2025 09:10:50 -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; Tue, 7 Jan 2025 09:10:48 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 09/14] iommufd/selftest: Require vdev_id when attaching to a nested domain Date: Tue, 7 Jan 2025 09:10:12 -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: BN3PEPF0000B06C:EE_|BN5PR12MB9485:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ea0dac0-75b3-4339-b523-08dd2f3e4849 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|7416014|82310400026; X-Microsoft-Antispam-Message-Info: tChq2wkNgue1G2talPEA29h7ELiPI8dnez6A3Wbz0jI902+K+7Zy054SQcPdF61VmGTbZ/0EBMP0vJQPZPotuVZLg0Y1eLkxm5KhtMqao4x8Fp3Dqs6BWGoDH+XXQBR8GQQg0q2z6w4WYvRUlYARCSKKp7u4SDOspI680eAKiHpyteP7ybbpn2lC6pduXT0y0hzkAiteZd0jaJm2Y4o2Qr2R2jnHmaXl1WGsts4j8Sr9yD0o12K8L5FL+6ww5naTiLxvmts5AblrjGy8ikLuEtx0tjciPaI6MewZoNLEb/uWL1VKhSFiPKJzG7WPGjpG8gPWF6bAtueA7lVN8JyT9LwUJvK28h1TmC9hNWbYKTZPCr1pSvI1hxExPkx/a/vAzVJno9fmZcdnz3o9dTV7N/pt5eJxGOoVB4r1fD5W6COGLgGovfF1d3DHW1uOfG/h8MZ1n51/5cmEMqwHvhvWfgwrZDH1B6cVcD49OiKsk8YEV0bFPCKOcxDbkMYiG4NznSOMjbV/LSgsHbohpiW7Dpl02GlGijiF1raTQiqT5HXuadc3S9E7WZ+cg+dghXNaV8xie+Vr0+KnAwSoQN7miP4tFY9rfbOcSzcWgEHR30J+iqtfTHoGxK/l4pbPVRYPSwvHR0jfgPzVa48kz5MFiRA4q++jqZ3f9PPgqFW13CUDDm55oiNhJDzUvKB1FUvwPTDVjR0x+v1m0b9JTH4Aoj//BEqq2iRhOpdOXwpeQTPF6tYr41yqz3YvA8yRjUY0osfo6ym/mxvwiNUKLhEPqo5oyKNS2E4mnL62OwBitSu7kgqGjH5kvAQw5NLuR8fADlRjWnLtJa/KJEYJI5F6WGM2ZV21AdlWC/HNVluMWi52FyvU78P81ZnntPVWJKRlTgCV2kBsmWAYbvoKa5/l8zUPpG2ukC7Pmztkl1Jz/agKA2KKIkVF314ACXnjZZfWDvMRKvohFnL3ahmz1A3veA+c+BnJ9H9SzT+3cjJbMhBZYZSffHMZlL3X9HmyjH1goZpBBlfe7LVvZttCfSHJis2McLrTHyBb0ts216DZdevB6Ew4vebeuM0zyX2j6Gv3hCz7IXmH/zKxI4EgBAncMYcCg9wu2D/U+9/2FQzZFuT9MNkdi4nMli+VoTUXLGaVD8j6hW5FcobTdsYgFY7LHLYGVEcCf+6P6cbfiA7tlKJms92GTAZuK8uTx8GshVuHCjgLvPjMZzJkP4qqwS7ZQ/x0WHAsUGhPrWXeSh2vtVgpzflXVyDuuLkSk8bfDj7zPX1NQHNLRtKRusL76e5k0xamV4DpNML4wxn9GwFQaoSYaY9r0nAhXSgj535YELWZyagPyotqDPUcSbgELhbTseWD6uK50kNp9TDhJBARZlo4qG26SfZPbbi66x6vrF0Eh17ztPzyOvyebKnXTVpWKoBh+catigjjlPoLrCEraSwiTb0G5f1b1C/QGndXlu3GPfEQSWrFsomnwMuu22OZhiHNdv/xDuaRjgT2etHgZ3A= 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)(36860700013)(1800799024)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:10.1558 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ea0dac0-75b3-4339-b523-08dd2f3e4849 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: BN5PR12MB9485 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091121_409781_25E362B2 X-CRM114-Status: GOOD ( 13.89 ) 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 Tue Jan 7 17:10:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929444 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 69EADE77197 for ; Tue, 7 Jan 2025 17:31:46 +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=AyhuQcvgvSblwQTMJNLyy33hbR n6NitdrHEwhNlYnjT37Rnql/spJtBuqMbWHD2sG0uusXU8O3iWfzlzGyxGJWFGXarGFYLrEm/YDr/ Pd5fGnEyqPfV8r8IIUf+IWUrS2/pdLlr33lxI3FgheiQDkgg8Lzb4n1P+1508tKGh5wbUbeFq7nmg EQn9VISOHHK3tNw17ALdbkYrpCetuFUCETP5zwsF6x5wMOCjPqr/Jn/dohHSHXgs9QDFG41QCKMXC A3dxstW8/GGKnFkixk3NHoMxacoRxR4DePNir4/rQtErSCBgBOC9sP1nb+mynUizfWEWZCBgu7VUY /cmcfrOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDQQ-00000005s23-2viS; Tue, 07 Jan 2025 17:31:30 +0000 Received: from mail-mw2nam12on20624.outbound.protection.outlook.com ([2a01:111:f403:200a::624] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6x-00000005mQ5-1ll2 for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DCvfc1QfB969HmWcD2AdhI+Igi4/kks2PRofiF8jhInbLVTLEreKLYjc0jQlgDiFh7klMun8eOymt85yCogBNoIVIbnDRH9EJBTZ3HDZ1btv23/JRByMi51O4bH8RgwQ7gZUMXlmowRy6esaMg7GUjFdKFsM7gug4vC70+0WHBFnvc1+6BlTrsR7ZtqVGH9NzUusoF9OUM3uFFE8L/xduI/eeSICwj2NyVyw9BRXGxUXasz9ecWSmtkqHIcH7LeHHv7tn2YefqAt7kvFmrde0ibmcI/mNAF+J1pNTqjx93AbxE8ceEV/YNEMLltseQNdnNO5q9Z2W6DKxrD7hLveow== 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=eyNYJm0v4FNT/iauIPJIO6Qj8mAz/bCUlNN5cJ8++JCJJAaztU1rkVhyGn+dDJJrHojS4GElmwjB27to7MxFRhsrl/HRDshmcLFgVDvwU3/OrZwEfOVhp02LBnTYqPXp9QUIFNq6FhflLdCk2CBvBOsNDwhStaGJgp748pxP0yXoXzhj33v7bQNUC4zcfqYmaG/836KlxEFj+0seTwj5uRBKs/96gzjuR7zG51WbAqf/3hmdCGuBifBZgAkg6OiTEd70VB1pzd4nt1aDfTNdRRXP2NwCcNzPMgIfvhUkswESpwIzknhO+seqztyTP9eYM4tKpVeFBcocsePrblI04w== 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=XUhykekp4FO5OF3mUhRfKopxfmzBM/fSHvQbzgphEKGLuala5Oqzm+1lA7R7quCjYwPzF5mYBtLjWs7ZCPNdV+yEqa+3MeguheDeE7g8tF0GzePIPNkQTcrB/SoFyEDwewaPLxfvHM5QT3/zsFbD8dfWv/0/0C6wVkkN83xWuJ8crhp4Ld6lyj2veO48ffOHqw7haXsKYBDgn2gsMmobN5V56desowDlgLWQYPD8JKk+OvJ8UCLGTeoZDZ4QCeAEuRaJhN7KvpHTxgMJyzcfb4uqYhRtZgnHLwd4gaMvkiD7nZZgDDkGOC19XBfIxNk5Vo2J0saO+Spmq+8CO2+erA== Received: from BN9PR03CA0322.namprd03.prod.outlook.com (2603:10b6:408:112::27) by SA1PR12MB6972.namprd12.prod.outlook.com (2603:10b6:806:24f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:11:12 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:112:cafe::ab) by BN9PR03CA0322.outlook.office365.com (2603:10b6:408:112::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:11:12 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:12 +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; Tue, 7 Jan 2025 09:10:53 -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; Tue, 7 Jan 2025 09:10:53 -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; Tue, 7 Jan 2025 09:10:50 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 10/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage Date: Tue, 7 Jan 2025 09:10:13 -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: BN3PEPF0000B06C:EE_|SA1PR12MB6972:EE_ X-MS-Office365-Filtering-Correlation-Id: 54d61a79-1eec-4d4d-44c6-08dd2f3e497d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024|7416014; X-Microsoft-Antispam-Message-Info: EQu2W5d21bBCp71xNvgVEnHpRZb8tXbRx+uBIoBeh9oV7yOlC7EIFC+yMGamR9BS03E5215NNfvzZHoKOckb5WEb+UQy4VqaK5xpEo1IS0Pb9qOKkz5Jb+BQq5PcfFYeGjXgI88q0YCnrPQd1xjfZynPPfCcl05sJmq0BM0npigMxU5K8j+5Z2dQvTJC4Mxde7h+/oQ/jpzG5owpRcBX0yuxAoZVZG0sg4rTrP5kat9YsD4Y47waTDB2RWM3/Nq27U/5MQnELU98IGE3HRBotnl42hzSMcIEzEoe1De5/fpC3RxGs75C7m8ccMiZiazQ01T+ymIwbv4yCqxMdfK6cEZ5dbnGFTaBKFkZikggoduxaUNro8REbnBoNRMZwf3rMIL8Fj/jQHCYpTkKS5vdfODdOsXj1Mxrx6jEgvQqm4JofJ75Ezf+BhzQI881S5NlS5jr2gqdjoJdFdEO7OTfxI1lv+msC40QKrYgnwpNsvbAEFpnE5oTu6N8ZOFi6NqI26JlBw3B0NTY7h6dkVFTaeWnJADtDpbPcOMyAS0HQbttDv+WcJLUT1l9Rs9mVQ68Yoi1Pb90FtZx4+Od5x7jbrLjNwhitZ9qbN5OioT6fBfkAakI2CKXJgB7bj+ssm0iXLg6/zPUlwgCNQMP4J6JtP2qCN5YXV8VyDIuyN7a9ug4Bt8JrSIkofyR1U2kMRU8fyrZ5UHI4rqPKh0ca6V31mP9AyO12klYlUpz9qETTP0sl2oY4E0DDTZStjzwYQf3yGTpAcgF5z06uginFq/EW7d2yaCflrzB4yAPWVL3t+X7vCn5WXf9+bGLsbfuCblL21fBLzWl4C7nMagtVXU9SgWl7uoiYcpYghzfKYJU++TbZU4yhAUUA9C0beocWSv7EvbjvtaUqQHr5KkToYKrcBY7EVRTkcf8BmzILcYWUkco/6HyAb0bUL7I4g0F+2YSSMlk887Ypzt6kQYKBqbzBYnTusQ0TWkgAWTFhbPFT+e3T/GrAAgWGiCdObO30yhr02LCSliseDwkgnVWBvee8l/yhE2zI0rT7LZCdV2rF8KJzyfn9uqmPNbYvKKJVAA3R8U6ZUqJcnMhSLfSFfEM+TkJQwqC61JpqFdInwmkXR6R3a0Mhw2lhkbpZd4joGNv+HqyIsA+yMFUNdbuRpCI3yGy32juEnBan/nDo8Yjr4wLkBU+uMNEZ6Z7ECrp/D7bJZZicDz3O4u2thy4J6CN6N9h4f8Z35ecSKCawA1CYDpP+0G5RVRm3eItP8Owgkb7aY2fSZrb9Z5QOTdHTca4Gt930SKt4nJfvr3WMBf7nmuIVkzgfbAvplryTPqq7szrPTsU9U0jqmwSSfVC63PLa7cCQdJvCM9G7S/IaHgM08GMmt24sM9DCznKA/LC9Jdkyf/7zm4pH8tRda/X54NZgGelSr3d7Zx9wHY4UiDQ38o0+U0jbvyTmPKjUmGY+0v1pUNMykY1WH863BPnz5WhuT8ha+VTt1UO4XNAyltaz2M= 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)(376014)(36860700013)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:12.1871 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54d61a79-1eec-4d4d-44c6-08dd2f3e497d 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: SA1PR12MB6972 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091123_456864_E7D8F29B X-CRM114-Status: GOOD ( 11.44 ) 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 Tue Jan 7 17:10:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929455 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 967EBE77199 for ; Tue, 7 Jan 2025 17:35:24 +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=DyzoIvMlCP094n87i359KYA/cD kh/5lkIXHqg4s0UpIEei/ELMEtFIj67BBrP6HUXu+LgrUXr3E3GmFPZGM9fAjUEG4QNqLDGwN+TC7 BW/K0O3L87owTdWcA9rcsfRCCplRjQTulPxF60nmBVgyo3kQ8p2G4AZsjmg6WueM4E0/ytaxu2ngV aI3QdMc9CyJB2nUUdZtUKJo1Dqgn62Gg22STUIT27KmiyQ3FoNu9m41g9NklBpNkTQmHGGrSia7Wu qSbtjJF2QBlRIrKFJ0ND/ytaoxiUwIy/FrDD0Bi0zT5F3z7/+XIdsLkRopNTIlYnSY+XHKn/wSyIn nL8Wea+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDTv-00000005sZz-3Yxy; Tue, 07 Jan 2025 17:35:07 +0000 Received: from mail-dm3nam02on20628.outbound.protection.outlook.com ([2a01:111:f403:2405::628] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD70-00000005mSJ-41iC for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TftiZTqtk4itukZRn26cH3JHTPjvZiSmuamyyC9dPvR9HDFcwoPXCVhtzW77P8BxBz3TruwL8orjjfq4OCSPwUrAXWqnUAVYMjOSk2NxcXN+Di8nVWdM4PgQPi17zHAzk+IX9vPQxD/cb35lW20xjxIPoxffLpnY4IMXruKlSQouRMQIV85+10tujpeZBbzn2PdCPq4ycIhpDXYvb35+kf9xQEHZS778IDLxHNtVEO8zmh4fqx29GeX+ZHcIAksH0Y+o67UFgAUIjR/O4ntZgBsDjHywF1K7MKT7FdLT+xW4CaK8KpidYEW/GUMC+BR/GzllVAIJtbOHNnQNSFSwHQ== 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=RVKsf9+VTWtCkxaJe7b0AdpWZ1us/JXAjeq8h/Yj9XR+0V5w6fRb82i8g+uj8j5FR5IEA/sxD79vLifK1qm7HLvhhGSgoXml8QCiyrGf69cxZPhgPnfBpGIA2cztnPTbzqzuKvc3eeKcp1FMDO7uYxe4XP0Vg8jmiyICzLxgHAY8LyoEWazZP6T9jrQp46QX0XuLMufNUgdRg1PYdyArKh+GBPZPwD7gM2pKHHU47k7vZ/AhAWxLM6jmNBMR1z7EIT+V1aStQlt6CVAwS0OPKYXkbf5nHjl99I1uWfyRY8vYNATE8HYwX2W8s2aMg1lLZyqtLHczN0bjtGWKAu5Zbw== 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=owksryRUWHVUTKc9EwdqafuNcbtKA7Z/YWtyFiy6EL4=; b=oBa/cgNBPDcV/ZZ+YT5XevfWDbqT7arw6bBa5xO0KiBPWn+zS7PPsKOJIXpoHExn9WibCvKQbjFwMaG3A8CG6ZWr+lZsPo6HY2yhkxyGAxpIkJOGEbTF6Kdb8QfjhCdx8kduU7jRXCWC6e4Q1bwee0FNoV/qktUBAxw2Z6TXus6728qbmI/K0y47Zm6jtcrBSDmhojgmbSw7sn5xLAlQW7OABtILVlNMETaARb/PgbvXrGO4l4Wnq5bUQUfTxOyl7cNhnMaBzcuYJc3HjwVoNMv6IviLbNpKZcr8qTq4ggmucYdVCKHdU+hu4XUVgNrBwMGh9Z1NZMIAuEed4Okphw== Received: from BN9PR03CA0306.namprd03.prod.outlook.com (2603:10b6:408:112::11) by PH8PR12MB7376.namprd12.prod.outlook.com (2603:10b6:510:214::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Tue, 7 Jan 2025 17:11:13 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:112:cafe::e5) by BN9PR03CA0306.outlook.office365.com (2603:10b6:408:112::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Tue, 7 Jan 2025 17:11:13 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:13 +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; Tue, 7 Jan 2025 09:10:56 -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; Tue, 7 Jan 2025 09:10:56 -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; Tue, 7 Jan 2025 09:10:53 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 11/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage Date: Tue, 7 Jan 2025 09:10:14 -0800 Message-ID: <293e82ce0591d541d35dda0043411a64b4f66a58.1736237481.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_|PH8PR12MB7376:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a5c2f10-2cd8-45fa-ecce-08dd2f3e4a47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024|7416014; X-Microsoft-Antispam-Message-Info: /KIKy1oBaddbXI5sBldAxNkpnMvPTNkOe65vqeqRZPArr+AlqW2vmlzm7y6I03JFPhgpXApQCrjuPYxx4NjrVissqQxKr/n/lWtTr4fEDPJhgSwNsBqEE6pksI6KKstBkOYWGeDLi6oSWdI75Z/ON/j1GKTl4UhhpkS9OWQ/2vEjZZcV16BHPTtCabF4WgIjV4DpQd9UPc7+yMT49ZxDdcncSwlnZ5u2qeunli/SB1bFcv8AABv2pT8C9m7LCwABOzDPQ0PfwNROqC/m23y/nSSixQ0ayM/d27US/wjtFem1Vrlciq9yP2fxHFPo6aosTvregV8YmiFSGDGSrkfsturR0AI0JJm0+6kmGcAusiLD8xHVnDkLFbL6/uxNL22Ydm1bPo6ERmBJMOOQlqsA7LQf/YlttZKPl9/NZoefDEm+HSqyYpnPyFW1hNlViyJj2utD1P/MDJvgRfZNLy2RyhrxEIrsMNmclG1qL24WtuOZjKDg1n2tLphYGQijPtKSyVv3HpAuGdsmJCFvjauSxhTMw5ehiGYts/PC2ZsBNSG8vOzvXXRowyeTfQvSdsrhYCo06RC+77iRD173mJEaBfHrp/g5TpJH2RB7RHMxq7jQdO/fyz3ZRRNFXFUhP7I0lmm8u/sHRTz2qAW/goXnkyp0UecHpf9Wta8z6QJ8fmBHoV5vIXDIbBycwEgh5oVJ7S1In1YxaHjifx/dM4IM41mdNyguQxLBR8RN1IYdvOfcbGm3RwOiV+88dl2uiICBtS1pQkjrU571HdcgMWTAton1MMafmiFAs2+OL/BQ1X2oOqhUJWw+HG6+y5av7Ok73hthevV9cFy7YmUGzNd1YFy4tjoWhP6SPOlwn+Y+FZY9ClwdGsJOc7F+AU/laBH/1DT5MG7az8nYays76hcZiiqE0RqfnL1QYhNBpDmVrttpgz/CsZUXmAIbGV13pXNDuZoRgmmbV6FU9+x1bwxPDfOOszZ8acqwKllO4ytn5PNjIxjbiujHH+XYEzWbSIRonin6vDAiSPiEzzUBlJHA1gTH8WAx+fb4SvYqS3ibxEMzi5nPVJF6tNpcxbfBS95zvwL81VkXiWUUpOIOw2tYh2NdcM6pX8IKLe2Lq7Dh1Qfbcj2hCGLIMHfrGG8y38JF2/HZNd8fm4SI/YihUFy1tZP5WQAihKn3rJfRMsFka7ZEd9Hf+Yk0sinQr6jMqFUKDdG4Ygc7Bie/kURhA6t3Ovw3hu8mmrbO0y6xxkGhVIIqGQVldIQRisds8fKthJSqtgollbUUulzZ/XbnB2TN/s/dvZlB2MmvO4cVuZB+mJuBcqGzjBf7+TOgy4hHtRx7aL7QiM3Dj7squsBvbFinVR9xdtCo3Empjnowf6uGCnXxhKWIxH2lUwH9WsqaEbnSGieJf3svmiA9QgrXLJ+19262ljeRq7RsoNEW382HJ5ZmPGBolQMRUjtEcxvyMQ+OTzRbed74lQOOsG2SIqIJJCylxBOhogYuizgadFbdKnI= 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)(376014)(36860700013)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:13.4996 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a5c2f10-2cd8-45fa-ecce-08dd2f3e4a47 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: PH8PR12MB7376 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091126_992495_831C0D13 X-CRM114-Status: GOOD ( 14.42 ) 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 Tue Jan 7 17:10:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929445 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 B916FE77197 for ; Tue, 7 Jan 2025 17:32: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=BfHoRj1WC5ljgSSUhvbNe904c/9I5exdjZ4GUcFUI8Y=; b=RI73BVCHDauWvh4c3fNj2augyi TewULJ8djMV4q7tyZXGD1BIMbKm4U1CPw1GOo3zHTuFlitQUSOtIWgTJa2mleaJAj6XE2fpdJPEKI ES+qlRnIDiTm+EJCHXfQ8vVD1sCeMzTaoTl0ekLtqIcRuR76Pv1d2Px/3FLdjaQ2NEUu4xEW8wdo3 l3MaBkeoGyt727XpTorK09Xugo4L3Q2kAIlWrj4211oATvDx/z6Go+BA+zSJId4CUyWSDJScpkN+r 3r/1C7IDTWkaojQx3akwwzXZ19xtTJyj5EwdoIC3i7FqVLkdU819T8j2OP/Uno+4o94+OTZdvJzeJ 2V58fHhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDRa-00000005sF3-25b4; Tue, 07 Jan 2025 17:32:42 +0000 Received: from mail-mw2nam04on2053.outbound.protection.outlook.com ([40.107.101.53] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD70-00000005mRm-1CNf for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D7srKtizauBGjgtjUHDNFpVrufuLD1GSU7ppB9GMo/HNtu2cW3oQJSuTBbcEAW1N7FHgTRJ26xuJkeYZjebUV/r4kw7BfM5DZDyEGm2ImBiDlDywHAUrN8r4GH9w/hnIjLH7XjWldXAMbm+0+lLF0RuBTDj7xE406ZYWxO8IxmS0Pp1lbV0Jsgv3ECX+/Fml+bWdpzTPdKiBm+UW8aFCVI0ew0UP+UrTvaNTiBVQzrCA6n/4Kadl4BmP+072uE3huz+TtbWPyuTXTI5lEFLPzHwFbHciTTWwk+fDOgt4xuBASooP6TQpVWZJ2yIHO9CPQjzVHRxjlLA0HXDhZgmSGA== 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=BfHoRj1WC5ljgSSUhvbNe904c/9I5exdjZ4GUcFUI8Y=; b=m5TYku6ekd5bfGcDGp2X2so/fHB5kIcCQS6vFDLS3NTU0ig2R70u4EaUvrDuFrjFOLK2aviEf2kQOVub/3j53EOg4SOTQcYyeFCQwXDaK4+4ONNG7kPhfrcRh0kOfny1gq3ghz0kb/f6SXWUCRJdwayl+T50Drf/iqWeJp1rdv0CHKvs+BCLEq3R2ffAE3O4IO6jNf5cJLmNWVVP58pL+1hDfUhy0iEwraU1uoDoRGsej2s3U0BMOsnP3FYEJwIyHIStVztX0GeJ/kXoM6mcaFpHJyKNbsk7pzePf7jRbfNq4DL7Bq7WFMm9qvsAAb/X1ki6Dp8/htBrzVzflgVv/w== 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=BfHoRj1WC5ljgSSUhvbNe904c/9I5exdjZ4GUcFUI8Y=; b=imSraK2mWZ/wAmq+AmYXzwLHIlpGctzcb73w1agaCUj6xfCLiFsyRfRU+noImwiwGwaqoTND1JtpGR1NlLGCW6CVXwyuYMUhd+dcKQX03lnVHYZRvgVJUXQ2HJpmWJN8OgRhoyfT0E64H6M32+B0D13dEV4yzKJnq5JTBX7OQb+JQhNAREGYzBJfl9OODBmfYazSxaI7umatQhNT1LcmD1FwBVsPN6bD9URTpnwp7x1zvBt5YqCQJpMjlNO75yY8bYxFDl6FYjoQ3MykGLPRB0sulgEaXqIAKJnnJF8o4smUA8m83I0lEFH4lO66FyTqX6SQgNoDdNJOIOYMVyZC2w== Received: from BL1PR13CA0003.namprd13.prod.outlook.com (2603:10b6:208:256::8) by PH8PR12MB7109.namprd12.prod.outlook.com (2603:10b6:510:22f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.19; Tue, 7 Jan 2025 17:11:15 +0000 Received: from BN3PEPF0000B06B.namprd21.prod.outlook.com (2603:10b6:208:256:cafe::ce) by BL1PR13CA0003.outlook.office365.com (2603:10b6:208:256::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.11 via Frontend Transport; Tue, 7 Jan 2025 17:11:15 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:15 +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; Tue, 7 Jan 2025 09:10:59 -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; Tue, 7 Jan 2025 09:10:58 -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; Tue, 7 Jan 2025 09:10:56 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 12/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ Date: Tue, 7 Jan 2025 09:10:15 -0800 Message-ID: <02e47317606d0e6f1220596a98152f61f422167f.1736237481.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_|PH8PR12MB7109:EE_ X-MS-Office365-Filtering-Correlation-Id: 9935aedc-a1b6-498c-ddec-08dd2f3e4b72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: HtrvDhB4MuqoYByCw4Vb5vLWcL+ERWthWldNGWu1492T1C7/vMYgNHDTnTByxHmT9kjrOuJEi1PSlFp5vNkX2bQAO9ZkhrNdUuIyjQys5oyQu26B2lOUWYFTRowfznll0rSqyoltx0nZrFUiIQPvxqGcpcrW0KapfhsI2wZP+Fq6nQIGjrZ7ZsPjfq44s5sBhijions6LcSRqi8USTdvl3c8olX3fpcG8igMg5jqsAn5mgc3qKE2n4Aj3Bnpfrk6Lo5GY9XGLDRnkLKhvagVEymxDKRcNkuqkGMs5swo6bK+xmGut3y72P95ELjBYsgLV2pgcXdMY7Pg/ee6J4bUEuVmOzMhwW/EHliw44hifN4gQauccUlP/7nzf4STMjrMcztMBPurdW3ldwPL4eZtajqDg4rz05Kznjb4g+sW2bjVjzGh/whRMjOrxrKC/PktffRtr9O1WcHwJgXnChvqvwl8PF6d3L5SLN+UXa85lWQN4sMgU8LPc94Swu6iomJP80RT2dy/05FW8qjhiwjNi9CCocGjzVOvxe7zC5EBAGumMHJ3Wl73IPNtlfIleE3rguXp5xjzvaHbriR6SIESZxCAOufKHsdXav0uKlwmJ/A4zH3tpVEUHxUxcGuS+Eh5c48a31AMTCZmHS/Ou5xMzEyQ3MuB+UpqPRlDsjVDtWT6Ld1MXMV4S+4EhshguijNY03Yy7hiLYW3CnBaxXeV5AZNaE/RGB+IZvYpikd0ItOR8udupYhcf4F4EZ85xVKZKzclk9MsTCLdtapsb7Pb1GBF/L2TgmhXRiJ4qGDbKA8mDeLJTzLxrmeEHpBxjpxoA2SmgKw2vBEle01wDPU77UV+7jWA3TAKpQcQoWS71lxIzGLLojJ0rR3m38GPchjdfaNyjTola25b2iBWbsmj/BoOVSJx28KhDkJ6D7uLAgMWTGNHPLYk7WDp1Ng0npvBiTfzAk7IU0sTmthTnUq6LIABuRPqbNI3pGeLDxqZtOn5NTHcdVQakltfDeQH1TNUzkM7LgxrBMaXF6utdSA6aJp+8+Yo9KrBVhI/DO1ZVdq6GeTzetBPxQH2yWEQ6pKhQ5LtdbPzY2Hy2LvorkR4MeVYT4LBBrVbbPhKQhhY9WsSBlazAQy5dPbnepZ+sYul7t6bV2zsmlr9ls4Rntx1ZBi0gdR42cNoJBQAY9agn/16ixlD8OHxU58rPMBT2noyukL/xoZKBL+UYDPRB4TfTj3JGOSBG6AJXmq1m87cIdWzTVewexir0acphRmOMSaFwatU5lyWYp1x8Th+yeAfW7msYJekYQ/AgFkOmyq1RaphxlMiUaoGVtHxawPuSDyNWR6byWPEoh43UfcjNuPGXKEYa0YZp7uPEmcmulaWG4AI2ovn0N2lnoAES+OaUv+Jpj2v7ZubJ47Y6Fg07xCLQ2088G1PWgOCr3J+zRdXSBRpi44Xk/mc+AZPFUevDczw1bB7+/ieeW11uF6xoIHAVcpsY4gYjZJDtDRELU2GtsA= 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)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:15.4744 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9935aedc-a1b6-498c-ddec-08dd2f3e4b72 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: PH8PR12MB7109 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091126_318953_9F293516 X-CRM114-Status: GOOD ( 15.17 ) 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. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- 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 Tue Jan 7 17:10:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929456 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 97CCBE77198 for ; Tue, 7 Jan 2025 17:36: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=tpay5frqqIixV8cU3KwdVDiKeW sCa8qe+jMHto4w2YtoSrrNHPGolkastBU8M8y2QuBU225OUmKn7LI43e2+aOfzxC/tWs0s+8WpYMu DTNJQ8vOgQ9p9MCoah779ayj1lFPTK9674N8tDcZ9nXfTipu7TdyADyi2xChLb2/hko0Gei5CPvv/ d4VvqF0MDSavnsnZsKVKXLJTnDGfmjEQXihy+WtTR+A5RJmwW2BiN0WuI2tzU2XMzpYMKDbgV6rRJ ksDs2db16krakZwygrhv3j8Z1Mqy3rb7U3n1xfVwZx8jjqCsmCpjLbS+RaYgEyZHiPHgkEDrJRnzy UByQkaQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDV6-00000005sk9-1wtG; Tue, 07 Jan 2025 17:36:20 +0000 Received: from mail-bn1nam02on2062d.outbound.protection.outlook.com ([2a01:111:f403:2407::62d] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD73-00000005mUG-3geS for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P1U7XtY5DQYbh+AFB+zhllGhoK9XCz7sPdP1XSYFxFvROY9paWER9xtPQmiV2XA9JfKf0GlcUzE5aFbVHCipd+9+LP3gusEBz3q4vojLnwVUPYE9TJtBGfX+T8mGZZyTLvDdgG0orHdrpZaLH2bOiMGLGhaEwbn5688sBk24F2FoOOzyUhajJMgV7d8eOFXZPOhjUiSH/tlMBE0q1nGegn3Ol8TtAyNZT9Ks2Q/uh0WEhg8v0eorILeEahJN0Ho2WlktL6OLPiQzWpWSPhB2U+9GENMqDoPQJTtYtEIg2l127SFRU9QeTlpUgTmct5qMT/mANT34nx8itVrxC+TUhg== 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=ejkGnI/5XlIJQjYGwaDnBJRHZY8LVs2b3JQaDQ1kXUjk0pcw3CFnDv2lxs0TBZRHBvW605UIg2NIJvrKoyzUpjNSisbmjJ3ogVvuttLhGqzmpPsk0/shpVqK3TTWj9VIbMD77xohirLa88ik3aEL3P5vE/cgIt+goNZBkFapGmpDmgo1CogrnwqQCPDzXycK3OqBj6FQSyWVUOaIHtohJzwJXPrIpxJAKmAO705Vdp93/Q9rx5iwSY3S83cIaZ5pOfuiCULJgfDe+2M9ygSHrekNSPEuTTZaEiA6Xd7IUKH4CTU9ild1mk1BxhAeLq5CPrOe/ukfoWVnjESF1IxJBA== 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=c/Be5FyriYV9O4cKY3PvsPx5/h93JMcKBft0eSjP1qpwqlQl91rxClX9XiVGEd+o58POg9FivQaXVJxlFZbsJEb9qDLMOKj9PujABkFsTwP54bLo+YIPqJ/Yd31KzA67n8qRhtqscAdJJt+ogT7fNETZmRIso4GKcP2TTd4ddbIbo1ocVpJgWS2IQoI08Psz8xF2/nIR+yCcpRgFuVyjo/VJBoxWmyKqV5iKqGdsAdxAF+UvLHx9eHjvCI4h3RsN+cnlsRuoczJbPIqJrTkTFCBv2ITC/pTEPWSi5ez38rjueQHL8babHfdMLxxXiFkCOVq+zvJ114Hy+eizqTor8A== Received: from BN9PR03CA0316.namprd03.prod.outlook.com (2603:10b6:408:112::21) by BL4PR12MB9507.namprd12.prod.outlook.com (2603:10b6:208:58d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.18; Tue, 7 Jan 2025 17:11:17 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:112:cafe::7b) by BN9PR03CA0316.outlook.office365.com (2603:10b6:408:112::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.18 via Frontend Transport; Tue, 7 Jan 2025 17:11:17 +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.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:11:17 +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; Tue, 7 Jan 2025 09:11:02 -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; Tue, 7 Jan 2025 09:11: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; Tue, 7 Jan 2025 09:10:59 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster Date: Tue, 7 Jan 2025 09:10:16 -0800 Message-ID: <115d6015219e5850ea49dc9f1247f9c3eb515770.1736237481.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_|BL4PR12MB9507:EE_ X-MS-Office365-Filtering-Correlation-Id: 234386dc-8652-43fd-a97a-08dd2f3e4cac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: mgxuxP8SdVEkLICi4zqEfPl3Gvc7xzVhBYjtSTHdlXRqZIAlIymId1RcUQ3yGdMtudbzZkgNCZYoUKfhQRkJSZGtaiE8GJTENhb3zzxGA916MKMExr138EOPHsO25N4OsUd15dzGsSP2mn1PND73yoRAdY2HR4FFWPsfBoaV4wMUuSe1dQG8+p+O0lLbYwotnwXzLqegrrSbBshri7Wq02lsj0T6ZL49Aht+HPhPymGGxGY9b4BU6RURrZfanMNC17C3nfyFqfQBfy5ddHaEQUhdP/E1wpWo7tBMN4OaOBCk2zPHK41mz8sE6M38YDbb2og3E011fqN1Zi4Jqnh/Qe6NHnpelSVulHZFivpmdRWnEKCw9K4GEainv6Ay4IQo/+/aUzU+iSr+fv0sjJbfqdjGx6fFILvIWkowUvNVoau3UWjb9bgCLiF7XZs3ho8DHpaMC2NbJO9f3JZccm9RwCqoU3sm7GUKBpSHeNDIou2Da4QyKP58xS7z6lA2NHvMpmuG4FdPSFytzRSVCIbGEd7aTdAnQuREh8GJ9+m4WuWrDMUf7gIoN8Rw9CRM0mOVvLAihMtXvIUt33nYP/XUx/bpKw3o69sB7TOEh/26QQyMZkbH/RlcmL+cR+xBmLy6aOXl2ad6zXBjyyb/qAUIGZIQzbErk4avu7H4dm3KuWlcFcAPczFeuu3SPIXru2OHpVAz/Jkr6YKIDiqa3iRqZHAzULIOmm/HJetN05X9/sr9yclVpziwiXq7S5PztkpAyR9VZiiNQ0uTWA5FxErjJYsmxZS1i81zfu0/bspRalBX28Z7dctvfGwwm5HH25dmfhgUHTbevrtjjU4eJUS+XEVdp4NyrXKfESMCepn8vJkAX8FzUlKW9hRm+R2ZI9ESWceJLSBBT9LwaN0yJxV7Q3Zt/Nm4SqXgkPGYN3hnt3nqTxVUmFxGrPon9NknFRAzb6tzxFzi3kjVKoo6iV0HoWAU7HQFp5MhZEvQq/9KV2gWhSwnK0BRCCDyOLwQmoiA7wssY1Fk8D0N7lbvFO5SzWc0RsTRn0C3PYLRu+3UXJviMhQkBNk65iGjtCidon2v6EISsEUx0NGhPgvoRt7R3KtfNY8572j3ElhHzJN9cb9U5P6gU+lp9sNVgcomQxOMzNyx3Hfsd7WYCLWOVttOaj+FAaRcrRbveUi6VEmVuPoe8Vhn+2ox7QTZNgfq5LhkKItIyIkOi3U3YOQb3L7qw/P2XllE643JtX4PiC6SCmD/c5XZWzTjMuj1yZj92fphp7Tsh+KLElPphKTXGsCZGUbAt0hvkz+cmz/+j3DEiPhbI5KZDO3VinvxVhVkiO2MdWnnj6KGEuUNl7JXh6VlJgIXSw3TnAKPfbIo6lchBYhioQA0rAGBQLbMaeKjHU/E/GnrKZmewDrdedyfZzuxO3xm+/suYlfHmA+9i+YQ+CJCqd2C9CTcjBUvjkAD9B+pZnrgGHPduucR8x9C+r0S5WYWnNupk1qFy0BxH4+4el8= 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)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:17.5308 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 234386dc-8652-43fd-a97a-08dd2f3e4cac 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: BL4PR12MB9507 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091129_986702_9B325B7E X-CRM114-Status: GOOD ( 22.49 ) 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 Tue Jan 7 17:10:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929446 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 31400E77197 for ; Tue, 7 Jan 2025 17:34:11 +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=2U5LYuqF/2RTpLwPXGEPwhWzWDJuS5pEs5qrvMXX+uM=; b=LCOPo9oE+B2zJkg/kwuT11fjMZ bSAarVm/dOW3LpYQpdgiFA+M/NfP83R9hg7MIJO0ESJriM8ibN6fcaMsEUsbt06PqgBb+mPrqQqVC XwKtRghgjCJzSOaq7XwpdlFiaCbDbWUJR6CgKHaUb7wcPsUjT3HaFHj0UNtlht6/lj/3EQmFe2HIO JKkWKyxm+9mF5x9pFNEN29ZiCy2NivDBPrwYVvPoPaXjuErPVaJpvjMiUJn9DvReMQJr75BaeDh7r c9qOo7r0A6MDzWWlyaMY5QTgkevueWTNCKrUfEdI9thjJB9cH/4XoZ/dISSJJ25FQCYmqlwBjuX8a IvyfTVwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDSm-00000005sPm-0xSj; Tue, 07 Jan 2025 17:33:56 +0000 Received: from mail-dm6nam10on2060e.outbound.protection.outlook.com ([2a01:111:f403:2413::60e] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6z-00000005mRW-33I4 for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:11:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I9Zzr7WLir031R8dB8xu1fGKgK9jQEQRO4f/LkEYnj8TmD6R9KfJMzIc4nOP/vF9NG3tvk+XcqJvrrjl5Madmelxj0yYhkxIi2v9n6J/Zlx1tewfdCM2iSB4unrhLxltRmdiNs3xZEoUOeQ8/K9CWbRxSVFsRTmASq7KK8XabgIyel1CY9fEEq5B7w4YDKjDAVekVfjU2PtBit6nDDnMv4LttYWHjs2ETh3A5zRhtTo7H28Oadtru/yUlRY1JM+rPF/gbDsh5N35d8Rpe9s4GGm2Kt53lCGMcPlinE3p6hOlHbIJ81cCWJKl61tnkjZg96CSp9BHyGohoU0xeGGFEg== 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=2U5LYuqF/2RTpLwPXGEPwhWzWDJuS5pEs5qrvMXX+uM=; b=h80bz/mMx7pZrlfdIQLABph2duhOzhAKdS6v/Q5IDHh6Hmolti8B6bQT9Rg+9c/1HZrpH1HH4C3pnfzQ9KuxiHl+NIS/rMD9F11FxzxagRQ6bbNutmpyWiLrNwvvARarPsftoAoBTy3ifUhg+n3thQR5HIf8h+U1Mn4ki5pAO15J4R0FLD44FZR4k5SOy3zGcEscmSl+o1WDS60Lx6bYuSCVEbAGPVKFiA5HLjkZNbQHMY+KrTvyIAb82az3t0Z5/gWCxG41cbukFjWS0016wc1Rgq7Gd+Q1MtYxYmDPeCqMZniTmh85CfQnPgxoRgy+dFp4/o7IbuVKyqw/Vm6MgA== 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=2U5LYuqF/2RTpLwPXGEPwhWzWDJuS5pEs5qrvMXX+uM=; b=ZcAMuiHxrNptoRpx5OsqgVWDjk//yJnCB2wWVQ0Jz9MYKdZYsf/IS0TRpebU5Xg+YWYDnPUUbIcn2W6OMiH2tGDpTYrv6Br+4+WW/0p6Q8jboCwvZVnyXKCpLbyGOxRJrIdMXwFkvc3XZpYEK8tx3Xw+LlMThyog/H3S8WTwn4U26rPxSdGvlzYMS73prbJVEkKiwy5mCrDnywb7ZaFXzOtjpsvBjCQpcN+rTGigvqJNm/apG4fJqnlVAWXzwS799nhg2BlvfQMx7U7hEZBJTl7nWsV5I/bmqj9p5YliK8FsgtxcQw0BLYyxcvwRgxSJSPd20agXKU3qn6NbuWMThw== Received: from SA0PR11CA0150.namprd11.prod.outlook.com (2603:10b6:806:131::35) by MN0PR12MB6367.namprd12.prod.outlook.com (2603:10b6:208:3d3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.16; Tue, 7 Jan 2025 17:11:19 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::2b) by SA0PR11CA0150.outlook.office365.com (2603:10b6:806:131::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.18 via Frontend Transport; Tue, 7 Jan 2025 17:11:19 +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 SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.7 via Frontend Transport; Tue, 7 Jan 2025 17:11:18 +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; Tue, 7 Jan 2025 09:11:05 -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; Tue, 7 Jan 2025 09:11: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; Tue, 7 Jan 2025 09:11:02 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU Date: Tue, 7 Jan 2025 09:10:17 -0800 Message-ID: <03c01be90e53f743a91b6c1376c408404b891867.1736237481.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: SA2PEPF00003F64:EE_|MN0PR12MB6367:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d5af8b8-3556-43ab-396c-08dd2f3e4d6c 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: jz/VwiI2hPfA3lFcdyLTlzXOCajJNAbcUnxtL6WwxWkJGuqnLkOBOfM4cP6/hDFvWZCnYJqUkprLHH8/fQpSw7IehcRoJnXqqvvYT2/gh0dj/DWliCYYrkTTey3/iEUrB9DbzOyM9wkudy+7GArbQa8rXrkZ7CL/Et2xOnenzvIXZSmpADR+fTt5zsgVM8Kp3OG3q+ZmuJ0Udmpix8zjZQRzWE98nbGAThfoQgwOk4GYOe/X56sugw+yCu0jgseDyw0VP4MSHyoX1LIHDtc2Cr40c+OoMyziOO7TOTW6hrTlvki5IoDNHWtTKOapVF/PEdOxfqyCBS5z04OS2GDAl0Gh/S4r5KRnvylagUPeorg+Nh4upo/VLqERoPg3QPjvrI/fBDls0l/nmFyHnYlnnfbRwQ7GIuuO8d5qzpGAcwd2Z8j3sQ1BywK4I9PUx/JPw2tLaLZFy4j0PXrJWpPOyQVnLvVSgEI3XSZb+YGqWv3InSW2LDK0KNStM5JkIyaAedSnc8aIMxLT9/D0XjUD6wJCK1u4B0AUtpW0dpKdwHA67R/C0c97c7D9XUFqIBkxf08VFZC+bHSRSBjvbTyh0JXIUShlSzjCDz5Tb1b/I1csVfbIehAfYnlWNC+lADY8Bb8jCoM9y59TkPOx/MMMruxrJcfPJObSoMxbuYt4+jSi3wKuEDya117xBFEfHVHPP3cbYDukgNfK0swJlP/59q5XRwM6z6E5CupW/2fKjFbF7HBv37WOl7GxUrKZmEgA/e0PfZD+O+wMBpTQiUYOtDNQZ47Q0dpp9hseek2jEuxbVPGCxYixQyYoti93hD34/7X2492q0KDNUgiMcMSI/9i9guakzPM7tm+pgTnmdtDKMagRSDSt7uPixXOEDVMxnYt6FOAJ8htlVF43rqPLadlzhp24MSOUJeyc04nQFv8D9KUylGU7UYBOyGgMMI+ZmuY660h0MmaU7PTJ9XixNE/rEz57lvOYAMWT3cRb6ZqraHZbJ0xCeZtIJx4lzo4G5/CFaUJcupBUFGITf1oYSZ10zl18kku2l0XSuRtVfFRR9ELdNmpslplU23D7mJQp47svcuYJ2VW1/FIHqXvwpBvZjZqG6xjSFZHWMcWsxLLfCxyy4xhEDilOr1nZGh5P/VrRLrQtdMgf54dwbudmWD2JDTSnpqjGAaJz9nBsURAo8M1qGCiNF+9cDzGx3wImteCZZlrNcYy9NIsCcS03UO0m1rsyBQvM5ha32Xhql5ikVxZmtjVnxsrhGkq1gzak36mfScWE4eRPx+bQ+q2cXTCYCi935quLP/n5Z1acza/MlKiM3wnAJ8LDkKf+jx7WNjuaSk9/pbP9EfH14QiSae2IV8Y2r6QozC5k6LyC4JfjQk/C8KU0CzlBMyaovt6txScm//GnfdtWSqrvFL9+rpooBV8IiqEOqXa26rAbPSdUnSR7lcKrseb0bAGizj00OcgaQkTbMCjI2toNOyz0biC0/GZyefBwSUGGr07TVzM= 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)(36860700013)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:11:18.8643 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d5af8b8-3556-43ab-396c-08dd2f3e4d6c 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: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6367 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091125_878632_107D1B3C X-CRM114-Status: GOOD ( 18.55 ) 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 | 22 +++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 58 +++++++++++-------- 4 files changed, 77 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..82b4513e56f3 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 @@ -389,9 +389,15 @@ static int arm_vsmmu_cache_invalidate(struct iommufd_viommu *viommu, return ret; } +static bool arm_vsmmu_supports_veventq(unsigned int type) +{ + return type == IOMMU_VEVENTQ_TYPE_ARM_SMMUV3; +} + static const struct iommufd_viommu_ops arm_vsmmu_ops = { .alloc_domain_nested = arm_vsmmu_alloc_domain_nested, .cache_invalidate = arm_vsmmu_cache_invalidate, + .supports_veventq = arm_vsmmu_supports_veventq, }; struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, @@ -447,4 +453,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);