From patchwork Tue Aug 27 17:02:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779890 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 61EFDC54731 for ; Tue, 27 Aug 2024 17:27: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=bqNoTNQDmPlpgS4R12z/JOVoGPAsGQcRbzQLY45kVFI=; b=2Hn1A3LuNpSbFBpNThw5wl9KZf x+BQiMqpys2NsbZ3oTv0fGJ3exuQ/PZWluGCG1j9W8esPKDRGjHFe43l7sKdSmGigKPjmYO7s/KNG /wNMdL+eIjFE09k3jJhpD+zMksxlQUsubXOujvpc4xnPaVUj0r00wuyCt6c23p3zX83cvRTb+wNjT 2L+cGmq2TcVGgSQLAtk7dqFzDH2pg16jfEvJI5J9Nfl4FsdJhLQMbhUVsFxqWIjd8yhg4+PVOH9Q1 V7CODeaAbaP/Vl0Vqj/sq6S2b9qsSjq8WzgvfkZtJwYgz1IZgn1kYUdjL7h3uRrZe7mUqd9ibevjb e3sgxFmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizyE-0000000CHjQ-1yLe; Tue, 27 Aug 2024 17:27:06 +0000 Received: from mail-dm6nam11on2061f.outbound.protection.outlook.com ([2a01:111:f403:2415::61f] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizaq-0000000CCIs-2ZWT for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oWv215DdRpuqTGMl12cHUvIC4B9vum1S28AN3vQMyON1DgiDhTJLA9GZh/lU6Qra0xs6kZ6ipzlS/9b51gAN8NvbOlJ9lHXn0uvK4If5VcmxyW48PXVeBpE94ySIIWgz7qtj5YYhc6qe97l6Ng4CXL8eG1RdB++3xR0qDhoCtzC4bys1CA42g8hwgOg/d6/52y1l9ODJG7i2sbZG0T2BxD7Ia/cM3Lnh62RyYD+hJvWpgfKImJGP1aSWFW6KZAMManoEq4Get6uTOH1+4hfhzxEjFP+68T6TyhDe8OAP7Zkqm7f9ABYLaEc3gF/wtL2gR1c6yS+M4KYA5t8kJczRyg== 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=bqNoTNQDmPlpgS4R12z/JOVoGPAsGQcRbzQLY45kVFI=; b=J0aaF0tvPmzvguiLOduqL2ozJ90OGnbJ3U6VSiM9tkIJL5Dl/ng3CrI+9smr2lbuJx+LslEKeXf0LPmn2lpR3h7lx7Y9izjOD7zRosbtwKqoKd8jwcB4ihXYnDsr8IuAD/MgTsB0z4ESyWn7sucZFmQb0zFHj0wu4kv0liGoLi0oONwwponC8IunUxQAh68OntMDKd7oWVKq6+2pIKLIGbwh/i4Af3U35YZuLXzLdJ1AiPSoSzuwrWmpm0KQ6W5VF+36Wz36/JKssQ/tuGqIjKSXx6UAvAQwYdwGWJidpw+ZfoJeXf03Fsr+RpFd6bJHQuxonn2PfIkiOkaVzVGV0g== 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=bqNoTNQDmPlpgS4R12z/JOVoGPAsGQcRbzQLY45kVFI=; b=L2kcGZBAkG9h9IxVkO/lViTr8s4/rOvnYtq9a08NIy6QXQzdOvN+X4M50Qyxwx0nj7i2tWF4m0BOcN5Ql7GJNrFvb705LjTNXj2B0P3yz2f+BJqH31FIof4rZvo2Z6sOLWNpvje+YkEOnnwLAwsDkXEZRJYbmloAidsMp7eVlbpvFvEJ3fwjuSSscghBYcoRptVHFdecVFyQjeYmMwceGPAaaTBQwe9RBzBN0SzWZWCExSq4OiVhNPdfH5kZGGZK1iWQoHh+h55C+oORXKq0r000ww1iMyMZB7NFpmpaO5CnSZULrT7hOPuppT98B8Rz3kHGDQiOhWnZMCQCl1c8Fg== Received: from DS7PR05CA0083.namprd05.prod.outlook.com (2603:10b6:8:57::29) by DS0PR12MB9321.namprd12.prod.outlook.com (2603:10b6:8:1b8::13) 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:50 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:8:57:cafe::c) by DS7PR05CA0083.outlook.office365.com (2603:10b6:8:57::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.14 via Frontend Transport; Tue, 27 Aug 2024 17:02:50 +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 DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) 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:50 +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:31 -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:31 -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:29 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 06/10] iommufd/viommu: Add iommufd_viommu_report_irq helper Date: Tue, 27 Aug 2024 10:02:08 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D6:EE_|DS0PR12MB9321:EE_ X-MS-Office365-Filtering-Correlation-Id: 22aeff60-07be-4c56-6cf1-08dcc6ba1552 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: 4FueWfNkpaLTT3oZRfgsg/jb2QAltrWqXkZGeix4+fsZH5qP/hiJDZaTrnIV9L2/ewB9HxreIdu9RQEH+aQy0TapYX8rdP3T92aYL4RxA6xm9nL96ESKhKtNsKc32w6PD03rSrWGi57jBXvYY0NYvmaoDY4SNsj9kkehr/x50oSC9n/1vSbbj0glWAP5oZS2wxJuMQNLRmOFkRPTUOoW0g5Wy7nAOQTpbi1uybflQlG0bmzAEOZq8BVPpc3fTugG21xQRyzf+c7r6fxT+SMXxx61CvOUr584xT1/UhpbOOO9cJWYXj2gFozA+WAP0bqoaD2zwNYFwDdYEFLNSHfXlw1MpZVcWLuABm+wox1/eWRGBsTbxXm0SkoBFXjr6mT0hMsf4gH47sb4pQmM/EYxnf03RfjLfqk+kNmpfglzOHu4/YNJxXNDl0P/9dVo6XIrQ+wB9ER1zN8NddNzRmJveuMDI29sdUsddHA+lu4KpF/OhNNinpMzViP77w7oAHe74zhmdcxY+fiJ+TVy2Rijc2PI3WHEuNbMr+xzOpechkLI/8SA4/TMU57OBlkG46106+hQPqfr8NM6H1rnysbsXWTkWJjW0xplQ7FBxgiiUcnsD0sEhnskyXIKp9DPLjfAtP/FKj4B24zQl5usNHButaRXKhdWnXZgEnSSzq3t6jziptAMquxb/jfO7z3wRItBuWKjDbNaxkN+TBTlGfES+HhZbs6oRzm4JPn09iv0nLT+G8em8wNlYZ9rK17mtQWN44CoEYAElu7pA1Lb0AjyhdXtmfBcVnTyc+jg8Ay2YpjquBIS6QJyfyft3+7HWOKIfhs8+8afzEu6McDBEOvY18+gUx2+A3XlFrIYnb8WDKcmzDUv0Gb2i8M1CnFcTm7UHChjXwg9y3K95PRbXW5ZqLI7VjpNenAJs3m6YP1Orn1Qoow6fElbMe9uzTLhH80U47zBrrZ+wVMIz0ZOV/niwul5R6M3NyzA70NdT4VLspdye7UG/7Rrciv/oRxws5cpXw/iHRnAHbBahf6FTPQDxSWEB45yf2Uw+nT5TE6obRaZCsDOU/Kz2QRZvo35FI5mYWoQcnS7tHuT8bCsH/V5RekyKMDcqTkQLrQpN+nlt0cnt10btv7JYRCN6qXPXxMf16K5kXaPDONQZKGuMzy6+h2LxcYUqruUG2Jbppqiaf7beirj2zP+JZPXJHEqK1zS6KnlFISUtC0kpKghY1qXexBo2QvzasUJv/lfVr5z1enUV1aRHl9I1Wb9Q7fsRmkMaofNTXB9BbqD8dZyS8xRNvd4wFuZDixj5eubEhHh6eZO/u6BK1uE6/T0GK6SqKRHZWy4Z4k58CvQL8mmQwGnA7rjVbbD30EJl0gvwHmcIjcqN2JlJW0cLYAQd6Szt1HWdHK4CW7MrAIToaedLhUqrZUFYChxkyEwV94z2Bk3/sSRJfkoIXWOa07bd0eybr+y 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)(7416014)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:50.2301 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22aeff60-07be-4c56-6cf1-08dcc6ba1552 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: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9321 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100256_752277_CC12223F X-CRM114-Status: GOOD ( 11.82 ) 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 allows IOMMU drivers to report to user space hypervisors IRQs/events that belong to a viommu. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/viommu_api.c | 40 ++++++++++++++++++++++++++++++ include/linux/iommufd.h | 8 ++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/iommu/iommufd/viommu_api.c b/drivers/iommu/iommufd/viommu_api.c index 82eb33e047cf..d075727a1b38 100644 --- a/drivers/iommu/iommufd/viommu_api.c +++ b/drivers/iommu/iommufd/viommu_api.c @@ -65,3 +65,43 @@ struct device *iommufd_vdev_id_to_dev(struct iommufd_vdev_id *vdev_id) return vdev_id->idev->dev; } EXPORT_SYMBOL_NS_GPL(iommufd_vdev_id_to_dev, IOMMUFD); + +/** + * IOMMU drivers can call this helper to report a per-VIOMMU virtual IRQ. Caller + * must ensure the lifecycle of the viommu object, likely by passing it from a + * vdev_id structure that was set via a set_vdev_id callback and by holding the + * same driver-level lock to protect the passed-in vdev_id from any race against + * a potential unset_vdev_id callback. + */ +void iommufd_viommu_report_irq(struct iommufd_viommu *viommu, unsigned int type, + void *irq_ptr, size_t irq_len) +{ + struct iommufd_event_virq *event_virq; + struct iommufd_viommu_irq *virq; + void *irq_data; + + might_sleep(); + + if (!viommu) + return; + + down_read(&viommu->virqs_rwsem); + + event_virq = iommufd_viommu_find_event_virq(viommu, type); + if (!event_virq) + goto out_unlock_vdev_ids; + + virq = kzalloc(sizeof(*virq) + irq_len, GFP_KERNEL); + if (!virq) + goto out_unlock_vdev_ids; + irq_data = (void *)virq + sizeof(*virq); + memcpy(irq_data, irq_ptr, irq_len); + + virq->event_virq = event_virq; + virq->irq_len = irq_len; + + iommufd_event_virq_handler(virq); +out_unlock_vdev_ids: + up_read(&viommu->virqs_rwsem); +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_report_irq, IOMMUFD); diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 88d6586a424f..346a6257ed0c 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -108,6 +108,8 @@ void iommufd_viommu_unlock_vdev_id(struct iommufd_viommu *viommu); struct device *iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id); struct iommu_domain * iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu); +void iommufd_viommu_report_irq(struct iommufd_viommu *viommu, unsigned int type, + void *irq_ptr, size_t irq_len); #else /* !CONFIG_IOMMUFD */ static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file) { @@ -173,5 +175,11 @@ iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu) { return NULL; } + +static inline void +iommufd_viommu_report_irq(struct iommufd_viommu *viommu, unsigned int type, + void *irq_ptr, size_t irq_len) +{ +} #endif /* CONFIG_IOMMUFD */ #endif