From patchwork Tue Aug 27 17:02:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779882 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 B3352C5472F for ; Tue, 27 Aug 2024 17:21:40 +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: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:In-Reply-To:References:List-Owner; bh=9K1UNFhxs53UztpWWuS6R9k3rRi74RBo2NE9m1fH74M=; b=gX38vSyNEYs7sSvQOj9xv+bcuH /fpYy/g0KWvZTQmZItb+Qh5pcMdkWor0bRO6cAo0P/SYA0KSNzutVMi8E4il+0zlQSpgyMiKgRJ6w ggSvuclfKqugI36jHcsscQZYomCsXpoYU7/w6mW6RQWEvmIL5R/5xMqTmxYGls/yAK+JBMkwC4T07 d0VWRLWJSbZYHLO66DaknWnDVe+ESiaJmHZUani8xp2YgFi7JVvAoT3GClxqbef/AIlzDutQVHqpR joRmto2RhZ8TY6Hz2QGxR6uPC+9QiQRZB2NXvTw7J5WsDCIfC3F/EMvtY5dsQeg/maoxJDbWWM5fE U+O6xILw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizsn-0000000CGjn-1uo9; Tue, 27 Aug 2024 17:21:29 +0000 Received: from mail-mw2nam12on2061a.outbound.protection.outlook.com ([2a01:111:f403:200a::61a] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizaf-0000000CC8x-1Rn4 for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y8qXS6WTVKjCQ9ucvQ+3iHtt+la5tkUNChJ6GgTn+A37VC9u0HVIkW0UK8XpRM8TT695D6cCqacNbnCdSCm13O60e3AOZhVC6uFTfRXTk9v4uOVr1dw/+Kf54skBBZit/9RdiBKTSnyAx38SgLN0YBWwR7H/kzAXCAIvNPQqDIbuAzJMVzJUs9Hwi8QYtJlsXPdF4Zkb3CX6jaIEZpTEQD/uoiC1vrpCfqLqICGxboP3vBRLWVBF55LMciMxAz5qbVz+h7ULjPYHV7FTu2XeGNb2SCV2Fee82iyspL8EJFbstzwsUTkNjcsKdKuldJK2le3hxKIsr+6vQjRJS/U8ow== 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=9K1UNFhxs53UztpWWuS6R9k3rRi74RBo2NE9m1fH74M=; b=yOMKiHPxS1+CifWqVYVAIgXxocvZD6bULPukKVTH391EjrfbfWp9KY18eeEk6CkWUzAXQRjJB1T1+heptEbhkfmeZtOI4PKnlJ0jn4Sfr+R1IhjptP3FiCZvRGIkrs5t/BmcMxd43wJ+6zuBUStfMmJzrdmeEAnfzvEj5CHg1m9DFj6wMkE9vH34HiDp2vKKgwAB/RLlCWhQZHd0vYpOx3umkQ/qJMGSjio0l46ooWxnkI+BVbSwTu7eC7tYrCcYg1oDua3AgfWV5h2bfEpjcfTTiSmY3vl8iZ2w8layXj/wmcn5RMi8lvngPRi/TE7Bnz+Rlz+0zHmv21B5zItsJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=huawei.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=9K1UNFhxs53UztpWWuS6R9k3rRi74RBo2NE9m1fH74M=; b=ICsFCj0rI7ivwEWn7L1A2umz9YczqAIHoZSS2VfsV5OPbSUntEBwSDDnKiGTNvKcsaoIx9+r0fxMxD6vEmu3LqziY0Lj7kL7TruTYlQ540qY90Wl8MItgZQIR6Kim29goNu96/Nhsx4h0Bp1D9BtyqVjzBi0oLzycoaTDWysghCP3oxdgLffdTioowA2pojn9YLtvDmyGX3syUyMTvGxykxvn1VZ7SU68/+ugnGiLrYs7W+6ARvlA3fv26w2mekK18l9mJOahzazZ+R6oEbHK234AOJ8Dpaafe+K15YifvRGP//yRdhCrOPMl1tnLxf0DBFXXAogSkxn4BQIOAHpKg== Received: from DM6PR13CA0003.namprd13.prod.outlook.com (2603:10b6:5:bc::16) by BY5PR12MB4241.namprd12.prod.outlook.com (2603:10b6:a03:20c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.25; Tue, 27 Aug 2024 17:02:37 +0000 Received: from DS3PEPF000099D3.namprd04.prod.outlook.com (2603:10b6:5:bc:cafe::49) by DM6PR13CA0003.outlook.office365.com (2603:10b6:5:bc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.20 via Frontend Transport; Tue, 27 Aug 2024 17:02:37 +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 DS3PEPF000099D3.mail.protection.outlook.com (10.167.17.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 27 Aug 2024 17:02:36 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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, 27 Aug 2024 10:02:21 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 27 Aug 2024 10:02:19 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 00/10] iommufd: Add VIOMMU infrastructure (Part-2 VIRQ) Date: Tue, 27 Aug 2024 10:02:02 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D3:EE_|BY5PR12MB4241:EE_ X-MS-Office365-Filtering-Correlation-Id: 4078a907-a454-489f-3e55-08dcc6ba0d28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: 0w8gemh2XrW8460yzo/Sl1ctH7iuiUFZz2RfDSssxrTpe/xmNMS6sg5m4IepPUEUW+wH4qjMUikKKiP315kLATZkDI+K9zDnUpWO/OXfwJXb2dTP5bXyoaoG1qxVVuRw9rDOm4m5PsZ/64MQKhbcvPnP/UHukXXK9HBwy16ZWtT8gZSz3a/kvXAwh7TI2/2Rh3CZqwFVvwWsw6mrYUsc/07yVOBUyt4OZpIVqJcsSg0HflovjFiMRmUk2S/JSemVxLFf8JoPQGyzGvX56lq8dK9kGIcX6m0GpERrEu3kWQ9MGz/6I9kF2t9TDAqTHunv8BdjCWQye84lkdTd88f8ACRrsPPWxp1KANjM+MgfKOcba64yBpngE8xlM/KhLGdWC+2nnkqcqDdryz1UszA+xjYiprEbA4bMPvDtuy3gsahrWoshgQIagEFfv9xYl10Jro4MrkdPu4W6hn+ILml9sTQnV2S6Ovm4CntngfSLq30+N8jtfW0wdL4RUL3ZIUv8LaGclSF6KB5Mjy03/Caro9CBCIeLM7OIcWPaB+wxkq6kMDMQDHtpOdny98FWU7l/S90+SG7/UeW0z4zl13nd57+MSSx9HFOnrJ3NkMCSue2fRPuKnUaA66h0zU9Ln9AdwAky682faq/mB1L0ls1KunGExq86r4pPk+uKpByq/p9AkNeToi0S1PVnn+1KHNRTQUWg31SxL53Tlh4mCe++WjEdYDuklqH+HsgzBBfBgE8pISxPtjc/K0zdM3ig0aquef+FvLSdyzXJBRxTiZmt/kkGlx9etbFBnXdWE67JhxRbemGVq+b160WYWlGtWJ/Uvu/iMSk7Fx23JmBahhtJQBkGUlD+vt0PiTKTOYlxrKkFt3LCGx63Tss7BXc5Ts9FBTDaFAY67VTrDPBfXhVBTh10Pc3g3UjvznoFQiUt/+iqA7LQCD3JqSY7Pu613tmQbLzfzs1TnY/wRoMoZeApRbEKkteYGaS7zowGbjRXK29ognvZYHwcwcVLIGn0a/K/tXfSN1yg9XcF63vb89gpC1vo5s9Er4bncyq4Lqygqckv1fd9CJOksv+N4Z5izA3XR921vlZzUiiGvhdl5fLBrfowqpMtOgKeY/ybGsp301/uatXcCcHH7n/YHPH3CG5nybXLJYB659DdYUJQATWF0JL5kxHiLb2+o0oiSG2cvsPrwEZnAaMetqOisYsfdMKGGAmtgew/3ExQrTIv7cFxgdB2lQIgAJuf1H21drYiwOKuoP++x0TtZa46ESCFxbOcZg/uY+ff3l6dlJ0f6Y2ss6X2qj6AjN3iqjDgt4LTmqVsPJnf9NauMey5ZAfzr9BKWeJ3l1PTDMF66KvlD+ixJVAMefgaPqaYLsAmq8p4VIXi44nW97lnTg3bj856/1gDWGTRx8J7SL7u8Jy3APd5cUqTCCVXIP7agO/dbczK+OhcHaHWGrwYmpBrS0JeeKYI240TIZ1vcI+c7DZOwUcE9w== 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)(82310400026)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:36.5475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4078a907-a454-489f-3e55-08dcc6ba0d28 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: DS3PEPF000099D3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4241 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100245_412960_056EC638 X-CRM114-Status: GOOD ( 15.98 ) 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 As the part-2 of the VIOMMU infrastructure, this series introduces a VIRQ object after repurposing the existing FAULT object, which provides a nice notification pathway to the user space already. So, the first thing to do is reworking the FAULT object. Mimicing the HWPT structures, add a common EVENT structure to support its derivatives: EVENT_IOPF (the prior FAULT object) and EVENT_VIRQ (new one). IOMMUFD_CMD_VIRQ_ALLOC is introduced to allocate EVENT_VIRQ for a VIOMMU. One VIOMMU can have multiple VIRQs in different types but can not support multiple VIRQs with the same types. Drivers might need the VIOMMU's vdev_id list or the exact vdev_id link of the passthrough device's to forward IRQs/events via the VIOMMU framework. Thus, extend the set/unset_vdev_id ioctls down to the driver using VIOMMU ops. This allows drivers to take the control of a vdev_id's lifecycle. The forwarding part is fairly simple but might need to replace a physical device ID with a virtual device ID. So, there comes with some helpers for drivers to use. As usual, this series comes with the selftest coverage for this new VIRQ, and with a real world use case in the ARM SMMUv3 driver. This must be based on the VIOMMU Part-1 series. It's on Github: https://github.com/nicolinc/iommufd/commits/iommufd_virq-v1 Paring QEMU branch for testing: https://github.com/nicolinc/qemu/commits/wip/for_iommufd_virq-v1 Thanks! Nicolin Nicolin Chen (10): iommufd: Rename IOMMUFD_OBJ_FAULT to IOMMUFD_OBJ_EVENT_IOPF iommufd: Rename fault.c to event.c iommufd: Add IOMMUFD_OBJ_EVENT_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC iommufd/viommu: Allow drivers to control vdev_id lifecycle iommufd/viommu: Add iommufd_vdev_id_to_dev helper iommufd/viommu: Add iommufd_viommu_report_irq helper iommufd/selftest: Implement mock_viommu_set/unset_vdev_id iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VIRQ for VIRQ coverage iommufd/selftest: Add EVENT_VIRQ test coverage iommu/arm-smmu-v3: Report virtual IRQ for device in user space drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 109 +++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + drivers/iommu/iommufd/Makefile | 2 +- drivers/iommu/iommufd/device.c | 2 + drivers/iommu/iommufd/event.c | 613 ++++++++++++++++++ drivers/iommu/iommufd/fault.c | 443 ------------- drivers/iommu/iommufd/hw_pagetable.c | 12 +- drivers/iommu/iommufd/iommufd_private.h | 147 ++++- drivers/iommu/iommufd/iommufd_test.h | 10 + drivers/iommu/iommufd/main.c | 13 +- drivers/iommu/iommufd/selftest.c | 66 ++ drivers/iommu/iommufd/viommu.c | 25 +- drivers/iommu/iommufd/viommu_api.c | 54 ++ include/linux/iommufd.h | 28 + include/uapi/linux/iommufd.h | 46 ++ tools/testing/selftests/iommu/iommufd.c | 11 + tools/testing/selftests/iommu/iommufd_utils.h | 64 ++ 17 files changed, 1130 insertions(+), 517 deletions(-) create mode 100644 drivers/iommu/iommufd/event.c delete mode 100644 drivers/iommu/iommufd/fault.c