From patchwork Tue Aug 27 17:02:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779883 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 46DB3C5472F for ; Tue, 27 Aug 2024 17:22:27 +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=6R5S4Ae2wJoBk0qVZvDuyvm4tQyhiwaQ+mUvlc4Nh7g=; b=JvmbCKPYofi2KUKpRUl72A9FWQ 0M99cGirQ7DUTiYYvwGYhM6WNDlnkK0Jnpj55Khc2kA5PwXBtjubaWncDL/6JjS3RyV2UjLJGk3wH VkMKmwpFizrud8YSK91sESqC5ZCmA7ceHkQGz/sIeIG6xi5w48EIhgG1qP5P8L4rcmHC6NrB4G+FA xjZ/WdQ6eTIa/OBDUkvCul26ms8eCHZEhoODGftoeYKJGR8qDzg9+sTO/Gm95sI3Lz3W4o6gJQquO H7z0TqJIPWiRgB6W+Jz6agVUCkPaQGWXAy7oCSH9BWa8f/VclXiFQy77TPeIRXyHuv2lQbFuUMuv6 Jp2FYReg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siztZ-0000000CGrN-1uNr; Tue, 27 Aug 2024 17:22:17 +0000 Received: from mail-mw2nam10on2060d.outbound.protection.outlook.com ([2a01:111:f403:2412::60d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizah-0000000CCAB-1OxZ for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y9yjb6Kv+b3T23S9+h2Q0hlM+qCqImNQ5OUb+2c81b5PXfD1g2b8pw49OckzLxqrh7DkVFpeWFV/XZf9UwUIYbCBkRn1pe9fTEEpBbBQUMUkQ+mzaCWb3yzxarYDROD2M/NwLWFMz4CYQ85W1aSTGiSsd0/nciOSpUWQKZ2LK4zgblX7yMMG1ZuyU2i5bxUoQENDBanjVQX43FsXBdZJLPjFIx9gzbjFFAeA9/ScM6WuyOI2BLf9gjLF3EWNd82nFVftG3gG2RNGJTk88eOTPxj2269qt+qFKBxRJphT1j0ZRIMnVJGjD4IromyCpIqF1FQHYe3v7FHXF3t866hezg== 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=6R5S4Ae2wJoBk0qVZvDuyvm4tQyhiwaQ+mUvlc4Nh7g=; b=k2jDb9amIho6mOgXJoDcwlVE3pad5JcmMazOTbktEzu5Ifp62O8t6q717HfgFDg3L+1DhJvtB6iMWOPFjcvggYx8US+HbAkZ4blne5Y2/c2ngHiKFvUy83yixDAnqjK3Laf5RWd70Cy63BNp3GQEOJ0eFuiFLdK75gFlmVnUB03Pab27MD1HcbUCYbFflg7m7vouChL+8C5xlI36qMs9cn4L2m9x+XkWkTD/HO+Ogzb9dkpTRy7wCo4+a+LaKlcE6PW4pOsImjWpV249/HeQWq5QExtMJoCuboo5qswYyM4OYlacQjxuGmISDD7eEMK9Dhb9sJGmtRe3/rdNO/zaMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=6R5S4Ae2wJoBk0qVZvDuyvm4tQyhiwaQ+mUvlc4Nh7g=; b=K1SxQe2MmYBBanrqfFxD7cEOWmcxhlUQ5zPRXHpXwSasmpI7RUAZArEGwhtqHd+fSbSMMCfvK4g/+54ejoV5mL84zYjQU7/2A6uNoUblenjAHJ9BKbz1SC77MOAW6nlTzyi7+BWziMwGO8k54psjCtOHUUnG1JV1RMsAAkE8sRFHlyhB/1On3xbuMT8gBuNrzrRptS4cgj0shZmbXSCiVea9UraM6nWwUe45UpctgAKum0M5kMHSNj9Httr8CKcVPVrgjAZWzKLfgQR/Gfns/kmH2y3pzJbMyFz63VlUK3q0Z5AFQF4MEKJDsEySTu/IR7ACn5/QpicC9ATpx1GeHg== Received: from PH7PR02CA0004.namprd02.prod.outlook.com (2603:10b6:510:33d::7) by CH2PR12MB4101.namprd12.prod.outlook.com (2603:10b6:610:a8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 17:02:40 +0000 Received: from CH2PEPF0000013D.namprd02.prod.outlook.com (2603:10b6:510:33d:cafe::fd) by PH7PR02CA0004.outlook.office365.com (2603:10b6:510:33d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26 via Frontend Transport; Tue, 27 Aug 2024 17:02:37 +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 CH2PEPF0000013D.mail.protection.outlook.com (10.167.244.69) 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:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:22 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:22 -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:21 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 01/10] iommufd: Rename IOMMUFD_OBJ_FAULT to IOMMUFD_OBJ_EVENT_IOPF Date: Tue, 27 Aug 2024 10:02:03 -0700 Message-ID: <546f9750aed1787fa2f39efbb13e47779a34963f.1724777091.git.nicolinc@nvidia.com> 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: CH2PEPF0000013D:EE_|CH2PR12MB4101:EE_ X-MS-Office365-Filtering-Correlation-Id: 637430da-b1fe-4b93-bada-08dcc6ba0d82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: CiaKp9k36vGGdnmK0D7H4paoCpXZyt7rGOk5I1qVN5lexdCC/KECA+Fu/ePHWCyReuaOMl+Vs2AbSoi4PHe+LIR6ok7yHx3L9AHYBQ5zN5dL12v7hYlW/SSLfOapkiGXslkXRjIvpjRVAYt4aNp4Fox2s4YSFvVvig3IABv0JCLEoaF4E77rpL/VaSo7STmunQ0YYd3Sp8/ZNBTMe/14ynxG/MFaUKMNpL4c5WjhzuqN4TT+DDnw/u42shog1IpthuUrRHWCOnPWL++6bWAg9UV4AANqkdsLfDwvzfCFmPDrqCLcuS8rMvXCFnA2gwYiqF3RpmN5Cl005wAguQJ2UmtbKcK0+Vv40ZNps86hDL2eREZRnHJQkf3lZAtwj+jitjozVTqYNNdw53NVhYvPAsHhyv+5yVLlPFvO4tTSkdb/hA/BH5dSKjIr5rOZ7oR9tew9c88d01IlJxxfo/Yjts8YER0hp5+phtgvBX5WKSPI2FHrSLv8G1yPXDEEPklIP99phdu68oGAlq7Uy1Z6o68vQeKky+AAtdl8jdoY68xF3BwFWziIrg0zHrnD0d8vIBGAAm9ZzvjQ+usQfVB2KpxG5QO5eJORhcBDAYb9/D6KeRBbLoENQQVapyMjQpfoEMZMxMSj5sO58FXxDEKZllTjUBTSHpg8lp8uESyqsi0iTON8OrDoog0tuMIo7xj1VcwH33AwVhzhzoPLQ0LWFuz1hZtHFTL1pi1CjSLthzFGMJqI3gmsKlfscdpD2jXmfnPplH0WVBQP8p9pKJQ+3rD8f3czHLlaTHVi1l/f0FlOJRrTgoSysdO5kKgLwWkkR47OfPmgL2+08Ogoy5n+J2fSb2s22o3c2djRazlP/rHNmZAhlZ1xF/hrenS+PJSlTRk8OTHnw/JCiQEmLFHWsI/1Fla2oixvDdkJWVLah0jt99o7d0LKDwEuLs0D87stOYX3zwZatOlwDp3w6ST9P+/jX8Y6098Eyav+dvk6Ui5gBGchiMhd8rDhx2BWWW3icacOVE9e/CjIMtr3Yj6V1Yur3a/3viP9k7zL0j3BRadKlbG1tsgL6h9862igB/+/VrW5ZrwhybvPBd2O3igm+JmhG3/iLRx6+bcuwtlcRQxiq0jDi1nRSjIdQEUh3kURcJzrg+8ZXYQzcspNiwr9thyjVtoQNK0p9GY3KVeNrxLUqKSppP4nKtccrc3l9CEnyQx0ECNOKuSmDtUQeC1I7E0TC3POsihx8I2vTZi2KVDcY3UFUMnQPmCdAj+5R7UihAmQJiTDs2X2FPgZIX/fZzFmtUMvZc3NBZNQ/xGJ07Rm5BGaPF1zOQ2ZSg+pLT8NOKE5VKsOYyrXRJNqfjYHrYyptGhpxZ7+hbFc5aHlLmdApHRjey2SsIpC3/jSIqp+gT3mnOaAosGJE2EltdPTBv38VAUXIJf4Fl3tF3FsfpipVGJCM6I7vQ8rX5zHkNBQ 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)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:37.1093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 637430da-b1fe-4b93-bada-08dcc6ba0d82 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: CH2PEPF0000013D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4101 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100247_582029_FF8C3DC7 X-CRM114-Status: GOOD ( 18.56 ) 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 A fault object was designed exclusively for hwpt's IO page faults. But the implementation of the object could actually be used for other purposes too such as hardware IRQ and event. Define a common event structure. Embed it into another iommufd_event_iopf, similar to hwpt_paging holding a common hwpt. Roll out a minimal level of renamings and abstractions. Add a common event ops to prepare for IOMMUFD_OBJ_EVENT_VIRQ. Also move event handlers to the header, which will be called by a viommu_api module for IOMMUFD_DRIVER. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/fault.c | 270 +++++++++++++----------- drivers/iommu/iommufd/hw_pagetable.c | 12 +- drivers/iommu/iommufd/iommufd_private.h | 87 +++++--- drivers/iommu/iommufd/main.c | 8 +- 4 files changed, 224 insertions(+), 153 deletions(-) diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index df03411c8728..8fea142e1ac2 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -16,7 +16,9 @@ #include "../iommu-priv.h" #include "iommufd_private.h" -static int iommufd_fault_iopf_enable(struct iommufd_device *idev) +/* IOMMUFD_OBJ_EVENT_IOPF Functions */ + +static int iommufd_event_iopf_enable(struct iommufd_device *idev) { struct device *dev = idev->dev; int ret; @@ -45,7 +47,7 @@ static int iommufd_fault_iopf_enable(struct iommufd_device *idev) return ret; } -static void iommufd_fault_iopf_disable(struct iommufd_device *idev) +static void iommufd_event_iopf_disable(struct iommufd_device *idev) { mutex_lock(&idev->iopf_lock); if (!WARN_ON(idev->iopf_enabled == 0)) { @@ -55,8 +57,8 @@ static void iommufd_fault_iopf_disable(struct iommufd_device *idev) mutex_unlock(&idev->iopf_lock); } -static int __fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, - struct iommufd_device *idev) +static int __event_iopf_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev) { struct iommufd_attach_handle *handle; int ret; @@ -74,37 +76,37 @@ static int __fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, return ret; } -int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, - struct iommufd_device *idev) +int iommufd_event_iopf_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev) { int ret; if (!hwpt->fault) return -EINVAL; - ret = iommufd_fault_iopf_enable(idev); + ret = iommufd_event_iopf_enable(idev); if (ret) return ret; - ret = __fault_domain_attach_dev(hwpt, idev); + ret = __event_iopf_domain_attach_dev(hwpt, idev); if (ret) - iommufd_fault_iopf_disable(idev); + iommufd_event_iopf_disable(idev); return ret; } -static void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, - struct iommufd_attach_handle *handle) +static void iommufd_event_iopf_auto_response(struct iommufd_hw_pagetable *hwpt, + struct iommufd_attach_handle *handle) { - struct iommufd_fault *fault = hwpt->fault; + struct iommufd_event_iopf *fault = hwpt->fault; struct iopf_group *group, *next; unsigned long index; 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); @@ -119,7 +121,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 * @@ -134,21 +136,21 @@ iommufd_device_get_attach_handle(struct iommufd_device *idev) return to_iommufd_handle(handle); } -void iommufd_fault_domain_detach_dev(struct iommufd_hw_pagetable *hwpt, - struct iommufd_device *idev) +void iommufd_event_iopf_domain_detach_dev(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev) { struct iommufd_attach_handle *handle; handle = iommufd_device_get_attach_handle(idev); iommu_detach_group_handle(hwpt->domain, idev->igroup->group); - iommufd_auto_response_faults(hwpt, handle); - iommufd_fault_iopf_disable(idev); + iommufd_event_iopf_auto_response(hwpt, handle); + iommufd_event_iopf_disable(idev); kfree(handle); } -static int __fault_domain_replace_dev(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - struct iommufd_hw_pagetable *old) +static int __event_iopf_domain_replace_dev(struct iommufd_device *idev, + struct iommufd_hw_pagetable *hwpt, + struct iommufd_hw_pagetable *old) { struct iommufd_attach_handle *handle, *curr = NULL; int ret; @@ -171,43 +173,44 @@ static int __fault_domain_replace_dev(struct iommufd_device *idev, } if (!ret && curr) { - iommufd_auto_response_faults(old, curr); + iommufd_event_iopf_auto_response(old, curr); kfree(curr); } return ret; } -int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - struct iommufd_hw_pagetable *old) +int iommufd_event_iopf_domain_replace_dev(struct iommufd_device *idev, + struct iommufd_hw_pagetable *hwpt, + struct iommufd_hw_pagetable *old) { bool iopf_off = !hwpt->fault && old->fault; bool iopf_on = hwpt->fault && !old->fault; int ret; if (iopf_on) { - ret = iommufd_fault_iopf_enable(idev); + ret = iommufd_event_iopf_enable(idev); if (ret) return ret; } - ret = __fault_domain_replace_dev(idev, hwpt, old); + ret = __event_iopf_domain_replace_dev(idev, hwpt, old); if (ret) { if (iopf_on) - iommufd_fault_iopf_disable(idev); + iommufd_event_iopf_disable(idev); return ret; } if (iopf_off) - iommufd_fault_iopf_disable(idev); + iommufd_event_iopf_disable(idev); return 0; } -void iommufd_fault_destroy(struct iommufd_object *obj) +void iommufd_event_iopf_destroy(struct iommufd_object *obj) { - struct iommufd_fault *fault = container_of(obj, struct iommufd_fault, obj); + struct iommufd_event *event = + container_of(obj, struct iommufd_event, obj); struct iopf_group *group, *next; /* @@ -216,17 +219,17 @@ 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, &event->deliver, node) { list_del(&group->node); iopf_group_response(group, IOMMU_PAGE_RESP_INVALID); iopf_free_group(group); } } -static void iommufd_compose_fault_message(struct iommu_fault *fault, - struct iommu_hwpt_pgfault *hwpt_fault, - struct iommufd_device *idev, - u32 cookie) +static void iommufd_compose_iopf_message(struct iommu_fault *fault, + struct iommu_hwpt_pgfault *hwpt_fault, + struct iommufd_device *idev, + u32 cookie) { hwpt_fault->flags = fault->prm.flags; hwpt_fault->dev_id = idev->obj.id; @@ -238,11 +241,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_event_iopf_fops_read(struct iommufd_event *event, + char __user *buf, size_t count, + loff_t *ppos) { + struct iommufd_event_iopf *fault = to_event_iopf(event); size_t fault_size = sizeof(struct iommu_hwpt_pgfault); - struct iommufd_fault *fault = filep->private_data; struct iommu_hwpt_pgfault data; struct iommufd_device *idev; struct iopf_group *group; @@ -253,9 +257,9 @@ 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, + mutex_lock(&event->mutex); + while (!list_empty(&event->deliver) && count > done) { + group = list_first_entry(&event->deliver, struct iopf_group, node); if (group->fault_count * fault_size > count - done) @@ -268,9 +272,8 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, idev = to_iommufd_handle(group->attach_handle)->idev; list_for_each_entry(iopf, &group->faults, list) { - iommufd_compose_fault_message(&iopf->fault, - &data, idev, - group->cookie); + iommufd_compose_iopf_message(&iopf->fault, &data, + idev, group->cookie); if (copy_to_user(buf + done, &data, fault_size)) { xa_erase(&fault->response, group->cookie); rc = -EFAULT; @@ -281,16 +284,17 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, list_del(&group->node); } - mutex_unlock(&fault->mutex); + mutex_unlock(&event->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_event_iopf_fops_write(struct iommufd_event *event, + 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_event_iopf *fault = to_event_iopf(event); struct iommu_hwpt_page_response response; struct iopf_group *group; size_t done = 0; @@ -299,7 +303,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(&event->mutex); while (count > done) { rc = copy_from_user(&response, buf + done, response_size); if (rc) @@ -325,119 +329,149 @@ 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(&event->mutex); return done == 0 ? rc : done; } -static __poll_t iommufd_fault_fops_poll(struct file *filep, +static const struct iommufd_event_ops iommufd_event_iopf_ops = { + .read = &iommufd_event_iopf_fops_read, + .write = &iommufd_event_iopf_fops_write, +}; + +/* Common Event Functions */ + +static ssize_t iommufd_event_fops_read(struct file *filep, char __user *buf, + size_t count, loff_t *ppos) +{ + struct iommufd_event *event = filep->private_data; + + if (!event->ops || !event->ops->read) + return -EOPNOTSUPP; + return event->ops->read(event, buf, count, ppos); +} + +static ssize_t iommufd_event_fops_write(struct file *filep, + const char __user *buf, + size_t count, loff_t *ppos) +{ + struct iommufd_event *event = filep->private_data; + + if (!event->ops || !event->ops->write) + return -EOPNOTSUPP; + return event->ops->write(event, buf, count, ppos); +} + +static __poll_t iommufd_event_fops_poll(struct file *filep, struct poll_table_struct *wait) { - struct iommufd_fault *fault = filep->private_data; + struct iommufd_event *event = 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, &event->wait_queue, wait); + mutex_lock(&event->mutex); + if (!list_empty(&event->deliver)) pollflags |= EPOLLIN | EPOLLRDNORM; - mutex_unlock(&fault->mutex); + mutex_unlock(&event->mutex); return pollflags; } -static int iommufd_fault_fops_release(struct inode *inode, struct file *filep) +static void iommufd_event_deinit(struct iommufd_event *event) { - struct iommufd_fault *fault = filep->private_data; + refcount_dec(&event->obj.users); + iommufd_ctx_put(event->ictx); + mutex_destroy(&event->mutex); +} - refcount_dec(&fault->obj.users); - iommufd_ctx_put(fault->ictx); +static int iommufd_event_fops_release(struct inode *inode, struct file *filep) +{ + iommufd_event_deinit((struct iommufd_event *)filep->private_data); return 0; } -static const struct file_operations iommufd_fault_fops = { +static const struct file_operations iommufd_event_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_event_fops_read, + .write = iommufd_event_fops_write, + .poll = iommufd_event_fops_poll, + .release = iommufd_event_fops_release, .llseek = no_llseek, }; -int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) +static int iommufd_event_init(struct iommufd_event *event, char *name, + struct iommufd_ctx *ictx, int *out_fdno, + const struct iommufd_event_ops *ops) { - struct iommu_fault_alloc *cmd = ucmd->cmd; - struct iommufd_fault *fault; struct file *filep; int fdno; + + event->ops = ops; + event->ictx = ictx; + INIT_LIST_HEAD(&event->deliver); + mutex_init(&event->mutex); + init_waitqueue_head(&event->wait_queue); + + filep = anon_inode_getfile(name, &iommufd_event_fops, + event, O_RDWR); + if (IS_ERR(filep)) + return PTR_ERR(filep); + + refcount_inc(&event->obj.users); + iommufd_ctx_get(event->ictx); + event->filep = filep; + + fdno = get_unused_fd_flags(O_CLOEXEC); + if (fdno < 0) { + fput(filep); + iommufd_event_deinit(event); + return fdno; + } + if (out_fdno) + *out_fdno = fdno; + return 0; +} + +int iommufd_event_iopf_alloc(struct iommufd_ucmd *ucmd) +{ + struct iommu_fault_alloc *cmd = ucmd->cmd; + struct iommufd_event_iopf *event_iopf; + int fdno; int rc; if (cmd->flags) return -EOPNOTSUPP; - fault = iommufd_object_alloc(ucmd->ictx, fault, IOMMUFD_OBJ_FAULT); - if (IS_ERR(fault)) - return PTR_ERR(fault); + event_iopf = __iommufd_object_alloc(ucmd->ictx, event_iopf, + IOMMUFD_OBJ_EVENT_IOPF, common.obj); + if (IS_ERR(event_iopf)) + return PTR_ERR(event_iopf); - 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); + xa_init_flags(&event_iopf->response, XA_FLAGS_ALLOC1); - filep = anon_inode_getfile("[iommufd-pgfault]", &iommufd_fault_fops, - fault, O_RDWR); - if (IS_ERR(filep)) { - rc = PTR_ERR(filep); + rc = iommufd_event_init(&event_iopf->common, "[iommufd-pgfault]", + ucmd->ictx, &fdno, &iommufd_event_iopf_ops); + if (rc) goto out_abort; - } - - refcount_inc(&fault->obj.users); - iommufd_ctx_get(fault->ictx); - fault->filep = filep; - fdno = get_unused_fd_flags(O_CLOEXEC); - if (fdno < 0) { - rc = fdno; - goto out_fput; - } - - cmd->out_fault_id = fault->obj.id; + cmd->out_fault_id = event_iopf->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, &event_iopf->common.obj); - fd_install(fdno, fault->filep); + fd_install(fdno, event_iopf->common.filep); return 0; out_put_fdno: put_unused_fd(fdno); -out_fput: - fput(filep); - refcount_dec(&fault->obj.users); - iommufd_ctx_put(fault->ictx); + fput(event_iopf->common.filep); + iommufd_event_deinit(&event_iopf->common); out_abort: - iommufd_object_abort_and_destroy(ucmd->ictx, &fault->obj); + iommufd_object_abort_and_destroy(ucmd->ictx, &event_iopf->common.obj); 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; -} diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 6aaec1b32abc..ca5c003a02da 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) @@ -342,18 +342,18 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) } if (cmd->flags & IOMMU_HWPT_FAULT_ID_VALID) { - struct iommufd_fault *fault; + struct iommufd_event_iopf *fault; - fault = iommufd_get_fault(ucmd, cmd->fault_id); + fault = iommufd_get_event_iopf(ucmd, cmd->fault_id); if (IS_ERR(fault)) { rc = PTR_ERR(fault); goto out_hwpt; } hwpt->fault = fault; - hwpt->domain->iopf_handler = iommufd_fault_iopf_handler; + hwpt->domain->iopf_handler = iommufd_event_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; diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 7831b0ca6528..c22d72c981c7 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -19,6 +19,7 @@ struct iommu_domain; struct iommu_group; struct iommu_option; struct iommufd_device; +struct iommufd_event; struct iommufd_ctx { struct file *file; @@ -131,7 +132,7 @@ enum iommufd_object_type { IOMMUFD_OBJ_HWPT_NESTED, IOMMUFD_OBJ_IOAS, IOMMUFD_OBJ_ACCESS, - IOMMUFD_OBJ_FAULT, + IOMMUFD_OBJ_EVENT_IOPF, IOMMUFD_OBJ_VIOMMU, #ifdef CONFIG_IOMMUFD_TEST IOMMUFD_OBJ_SELFTEST, @@ -297,7 +298,7 @@ int iommufd_check_iova_range(struct io_pagetable *iopt, struct iommufd_hw_pagetable { struct iommufd_object obj; struct iommu_domain *domain; - struct iommufd_fault *fault; + struct iommufd_event_iopf *fault; }; struct iommufd_hwpt_paging { @@ -456,24 +457,42 @@ void iopt_remove_access(struct io_pagetable *iopt, u32 iopt_access_list_id); void iommufd_access_destroy_object(struct iommufd_object *obj); +struct iommufd_event_ops { + ssize_t (*read)(struct iommufd_event *event, char __user *buf, + size_t count, loff_t *ppos); + ssize_t (*write)(struct iommufd_event *event, const char __user *buf, + size_t count, loff_t *ppos); +}; + /* - * 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. + * An iommufd_event object represents an interface to deliver IOMMU events + * to the user space. These objects are created/destroyed by the user space. */ -struct iommufd_fault { +struct iommufd_event { struct iommufd_object obj; struct iommufd_ctx *ictx; struct file *filep; - /* The lists of outstanding faults protected by below mutex. */ + const struct iommufd_event_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_event_notify(struct iommufd_event *event, + struct list_head *node) +{ + mutex_lock(&event->mutex); + list_add_tail(node, &event->deliver); + mutex_unlock(&event->mutex); + + wake_up_interruptible(&event->wait_queue); + return 0; +} + struct iommufd_attach_handle { struct iommu_attach_handle handle; struct iommufd_device *idev; @@ -482,31 +501,49 @@ 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) -static inline struct iommufd_fault * -iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) +struct iommufd_event_iopf { + struct iommufd_event common; + struct xarray response; +}; + +static inline struct iommufd_event_iopf * +to_event_iopf(struct iommufd_event *event) +{ + return container_of(event, struct iommufd_event_iopf, common); +} + +static inline struct iommufd_event_iopf * +iommufd_get_event_iopf(struct iommufd_ucmd *ucmd, u32 id) { return container_of(iommufd_get_object(ucmd->ictx, id, - IOMMUFD_OBJ_FAULT), - struct iommufd_fault, obj); + IOMMUFD_OBJ_EVENT_IOPF), + struct iommufd_event_iopf, common.obj); } -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); +int iommufd_event_iopf_alloc(struct iommufd_ucmd *ucmd); +void iommufd_event_iopf_destroy(struct iommufd_object *obj); + +static inline int iommufd_event_iopf_handler(struct iopf_group *group) +{ + struct iommufd_hw_pagetable *hwpt = + group->attach_handle->domain->fault_data; + + return iommufd_event_notify(&hwpt->fault->common, &group->node); +} -int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, - struct iommufd_device *idev); -void iommufd_fault_domain_detach_dev(struct iommufd_hw_pagetable *hwpt, - struct iommufd_device *idev); -int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - struct iommufd_hw_pagetable *old); +int iommufd_event_iopf_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev); +void iommufd_event_iopf_domain_detach_dev(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev); +int iommufd_event_iopf_domain_replace_dev(struct iommufd_device *idev, + struct iommufd_hw_pagetable *hwpt, + struct iommufd_hw_pagetable *old); static inline int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { if (hwpt->fault) - return iommufd_fault_domain_attach_dev(hwpt, idev); + return iommufd_event_iopf_domain_attach_dev(hwpt, idev); return iommu_attach_group(hwpt->domain, idev->igroup->group); } @@ -515,7 +552,7 @@ static inline void iommufd_hwpt_detach_device(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { if (hwpt->fault) - iommufd_fault_domain_detach_dev(hwpt, idev); + iommufd_event_iopf_domain_detach_dev(hwpt, idev); iommu_detach_group(hwpt->domain, idev->igroup->group); } @@ -525,7 +562,7 @@ static inline int iommufd_hwpt_replace_device(struct iommufd_device *idev, struct iommufd_hw_pagetable *old) { if (old->fault || hwpt->fault) - return iommufd_fault_domain_replace_dev(idev, hwpt, old); + return iommufd_event_iopf_domain_replace_dev(idev, hwpt, old); return iommu_group_replace_domain(idev->igroup->group, hwpt->domain); } diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 199ad90fa36b..015f492afab1 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -359,8 +359,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_event_iopf_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, @@ -525,8 +525,8 @@ 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_EVENT_IOPF] = { + .destroy = iommufd_event_iopf_destroy, }, [IOMMUFD_OBJ_VIOMMU] = { .destroy = iommufd_viommu_destroy, From patchwork Tue Aug 27 17:02:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779885 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 C4689C54731 for ; Tue, 27 Aug 2024 17:23:16 +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=/aF/ljdpojKR5leSVeKttvQG1lVuwPWEwGdFW9et8EY=; b=V9pgFk4tqDFLSysA7GBdenaGZ5 7RexeQhWM0agl+6cputD1pdrtH6iaLabmltDSgd5OAi3hBuodnjG46hoHyG8TMVBO+X1xuc/0qLdI s75xp7fNppA4DPLozWLY4crwcePl8Y0zJVZBbnIOtL/4xYKYKDSQioU4NzfIY2hQrwkZUFDKjxalb mHwvnwP95j1scwBbqqoellVEH5uVFXaUvRyNLWbVbr9+ow0EyC+UWIL1yGQbyZI4y0i9M/qMw8X7I 9dvccq3JXErguKPTBTKuqWIZ3lTScUdCk4be0H4nfn1mH1FFrxLXwzr28Ltmh1W+G2iF1GS8kx2w2 KfRUlCgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizuL-0000000CGwN-0vZL; Tue, 27 Aug 2024 17:23:05 +0000 Received: from mail-bn8nam12on2061d.outbound.protection.outlook.com ([2a01:111:f403:2418::61d] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizaj-0000000CCCK-3V2e for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JG6gUCLsfXABb1Hat6fJOAuvcHXltuvbglX3dYr86NDUgefuzH+nQjR7v599ZM7IKrpAKdgYY9wZqgF9HjyEclgjGycp2HrKa2BukevbAFeG5+1lCupGbi6ETJXbtnwDhBtZOs+6fRFoRGvacpGXwKcyRofH4AtKVI70szDuRQQC2pKchbQ0LUv5m0+FANemZ5Dz0JxApoGBERwET9v0xbqMVxv9aYoabOjQb1hr9oK17p1p6qKU1EyDi3B7WoIfWR0YHkP7mCv8z5pZuRzMf5Cr6tYsllzMooXksxBeKz584Vb0NgbhFK4SvhZytpGnHtq7weZ3OEKpvZNt7PwDeA== 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=/aF/ljdpojKR5leSVeKttvQG1lVuwPWEwGdFW9et8EY=; b=J57Ct1DwT4QHzU6YdtJ3QWfUyhghMh7dOOk+JAGJ11NACmHQiWtNgDIw7Jz7P5FfbjarKuGkN5QxTti12IW1SBzQVpqXAcmcYZF/NKwvvoVq5nHEeypEa8gt9CPfKoms03CakyluG9n4yaQdqrs07k/vHBLw4negnGgfuzH0LbWjsToMagBan8R6S7xL9tdJMnGLIUawLn6UGVz3efLHzbBIdPleX9xuIbDrJkDBM70YuLDbasEd1FEqpuHy2WK23r+nnGMUm13F2LL42+VZQc09GaoWb0phKFyTZE/IiakiJmrZD2ZeHy0lAlRsgjI7NfhM7m50mb7k017SuZgNcA== 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=/aF/ljdpojKR5leSVeKttvQG1lVuwPWEwGdFW9et8EY=; b=eAZQ3GLEdXLN0X27Dof6CCluoJBBN0qeQ4lKm2tUjKt3+geCKOPjPQeCsBN0HsePiXtnTdxhlHfCAskcuVXVrhWo7ohb3mPj40Lzqj0/JzTEyQrapLa02WKMtrgfEB146HzfNcNJ/PcIIunrXEE67RtYDplLGrtAmzWa8oHhvjBZM1COjSDNdki8rCHGE20fy5B4C7o5toy4S/iSVoRA/2VwmhVD8ww/4bj8MNvowc9SGgS1lUq2vFLijmX1EkTxs+RwAL6pfdorbrC1Ud/2q5JJBbiWW6paIobHd/C8UfoAiZ6UNc9DdlHvk44ma5v8G8j128OoZfojzJ6QwiVC9w== Received: from CH2PR05CA0063.namprd05.prod.outlook.com (2603:10b6:610:38::40) by PH0PR12MB7958.namprd12.prod.outlook.com (2603:10b6:510:285::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 17:02:42 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:610:38:cafe::ac) by CH2PR05CA0063.outlook.office365.com (2603:10b6:610:38::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.16 via Frontend Transport; Tue, 27 Aug 2024 17:02:41 +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 DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) 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:41 +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:24 -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:24 -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:22 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 02/10] iommufd: Rename fault.c to event.c Date: Tue, 27 Aug 2024 10:02:04 -0700 Message-ID: <2c9a3339e9aa633993428d4ad41ed2f0d268dbbc.1724777091.git.nicolinc@nvidia.com> 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: DS3PEPF000099D5:EE_|PH0PR12MB7958:EE_ X-MS-Office365-Filtering-Correlation-Id: f36e27fb-2170-4892-23d7-08dcc6ba0ff1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: MYX2jriCnQQEK8QtOEMi9nhLDwUkbKm24tlvxIkzPHwEN05Hd6SUvPBlkVTenVzzL1AFCPMd7XZ1TmwkS4W4aoaKv++hV4X1lzu9IiOY0sj+WZPzAtBG6hilP/MavsKrEZHJC/hphHqCCtShqVOA9aRvYD0w1ZwGFzFTsVN/a4OuN8pr0qwiM9PhmpqkjAL++rj2rBf+Tg3euaSBcnk6MCzEVAVKYGXMxMAlGsgl4rWX/F5P0cm1/CsZVGRJsrG0cb8Daf4VVCg2ssoAaZ+H4l8OLyTpDGZWW5rsTL2gyDvJThtp94AWR4+CkQPiRw/hGx4nLglIlrKIs3V5exgaO33Suv6pcLSigyKTStHx+NvlKAvA4gmdBT2GwqjKx785ywiIhM/0tQVM8AX34uYayzmliHRogdFhffoS+CcPoJCYSqBsDc49V3T4NdiJCUJF1TLffCCmc8jxhN67kIlx+slfUCqAHVqo31A8MQSFEHJ2zDc/XYEItmd+2g5DwVtfrBg1U4aCKzwVk+JY3MCAiXT8D7kBda4+RmgjWtFwO9fBR2H9WgQkyeUAM/sLcKX7b9sMXq0zIwxkSE9hOl8NVvo2e3du6EWH8RroGyHne11lG/3BCJnctmEMqaClhNcDhpZxfKkLHwjuj3bVl61bKaWOt1cCupbJOEZ8T38d3y+pHhaFRuoUVjX/igZw9Ddm9jyOIoLdOeBDhYV5vB4SpLlLGP9XCWjgiV16M3CjGqGfIcfODTWe9XQFdHGIvRfPmCJUQsyxfdbO3opaNWwR+0XqexdwMk8dqq4tZ9rs7nqcrCdXzlRu0tZZN22/hoBX89+xwF14w9FytnYjsIddvi4o2ksANLxGxVnYs6s3iw27niNNBvpxxC5wFV00+9jcRBcpDnqe/ZpR7/IwwahTKe+ggo38SHOeU+NFc29QxiHkTO9sV/NFvaeuXQvtTCoqb/ixm335b/IO9yJVodRNz97e3w0Ofmmdf+vLT2nycCG7qmkL/cI+TxdY2oe+7wQWWzD8Aflc7XwH9GKFb0cHTRJoJcbfM3F+7pH6In9/faQquyzro1VWrf/TbC2zcMI0VJf+nh1FMpzwRCE4ZhtLLLZNcGiSowhL+5vkqg0K+lDDJiIqiZyyJagCCs5XbvGTaDezOpBRSLU+Nk4kvBEGqXKT1fwAEkyYn4HEoQ4f3OCuuFFx/Hiudbo13Q81UJN+14GgD/00fW55OdVpO2dkqoum+GerBz+mU0oIDaAxrJNPJxrHWUKhcPPRby6peAdovf6COgzUv1VrAFP8VCwebtuzrXc/xI13wQQmbuSfEW+HyDzaEk7OIVO35BtC1di7iRjhVlj6Rfvn451EyGPpcWDU7th0m6xrTNVeeD6cr2gaWMnXrOFlmI8dvG/06KHSbXEvNkyCdiYCS2bhT5hKSJpSEmn4QegX17QDjMgUA4GjgN9DS40qm31dFjxGK4uB 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)(36860700013)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:41.1883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f36e27fb-2170-4892-23d7-08dcc6ba0ff1 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: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7958 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100250_014829_ADD85FE9 X-CRM114-Status: UNSURE ( 9.05 ) 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 event object. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/Makefile | 2 +- drivers/iommu/iommufd/{fault.c => event.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/iommu/iommufd/{fault.c => event.c} (100%) diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile index 288ef3e895e3..baabb714b56c 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 \ + event.o \ hw_pagetable.o \ io_pagetable.o \ ioas.o \ diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/event.c similarity index 100% rename from drivers/iommu/iommufd/fault.c rename to drivers/iommu/iommufd/event.c From patchwork Tue Aug 27 17:02:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779887 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 555DEC5472F for ; Tue, 27 Aug 2024 17:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=02OaAJNXTmBe3J9SJNEhtuFoRPRVInbsx8Sh8Tc6Tk8=; b=xzhP2C3L4hkdzuNCAyipivbY49 u0q+64SGVE97rSZySdLCN4jaxIZrwjn6ChVRdp4jukT9hHhKaMfincSV40I9AmcU5rWAGV8SRuYec +rWEEa7Ty1JUh2Ylo9/t0iOpldPOz9tbcjzDmq3OuiywmnhFkdR8iUo6XAXwjyXCGgaTFfqPci0VC NTR/BDIH5qQL2IE99TXIqkS96kdVCvqg7rzfCd3FVokxnHJu/yYcJ8d1oG4y0TqDxRm/GVsdcT/t6 D1EEDxq41YukKky8XGyp3dtSOKREte5wqSfnwpC836bKs7tjcgpxyo5c8VuwOyDrnpHaenQQD1ezj /1hBbDyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizvu-0000000CHHQ-1W0v; Tue, 27 Aug 2024 17:24:42 +0000 Received: from mail-bn7nam10on20628.outbound.protection.outlook.com ([2a01:111:f403:2009::628] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizal-0000000CCDO-1dVg for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BbULXPWoQQHrpru0qkYq17J6lsc2Nae419Jo1CrDCAp56p7/CsSqU+tyrR/FohtRDCA5n/X8j0UEYUrtztdhObhekvqRc9kOf9rR6EcInEVjUpV5uvTxg3dljQIPPSUENE0XyTY+WC/1VqTVHPyXB5aQxqDf/LemKZIIxVJLISwbrVLJ3VmDrIe839+wNdzjAUMBhcyEg0Jh88rZKN01qsdeeVEGnRato+bLlw7kpZblhOnl5uZKh4cC/Mbj3iEcNk12TwEkv/dR1VAu88S701rI1nHsHSPqQEXSV5XZfXQWpJY2RBxsx7KeyLXNsHmQPZ1N9L7HWY2UvmuPYt/eBg== 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=02OaAJNXTmBe3J9SJNEhtuFoRPRVInbsx8Sh8Tc6Tk8=; b=QaoWyz3xXv24RdE3EixtqH239liaIxZ0s/qW92//JjgowvKeOOQbWtbchv6zTAYTNyrNrRqD1j4DMCnGcM27z0mde9JPIBOvS+qQ/meRmHGuMHqvlTCwO8kLh0VrlqSRBiFycdioZNK2bLx6ujup05IwS1gfabwCWd7bm2dIhlXwsKNu98m4m/Rco7BjkGhrOEbcsfETf3jJwCr7S6uLM+VzPUXsPU/2Bxqm2gdO2DGSzXy3WuSZrhwvgejgs36EbvDapSW/ReH2hs/sjk/EGWdV9xfI34vkwJW+Hcd9oUV6/u1x4ZHC00+3vFORmzc1CQ7X5sWzGILfZ9KUsbW+qQ== 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=02OaAJNXTmBe3J9SJNEhtuFoRPRVInbsx8Sh8Tc6Tk8=; b=si8LOEgXGfrQdJ6K4w6vV1lDXOpzF5u+mUP2fnmqjP7bwSRoF3fgDGGpObqbkn3ZimNjFAfM+14r9U00fuiV/3elxrGWFgANRaSzbRJxW/ctMVoLuhAcc0Rhx5bwYujS5u7LlEV67SqJ2a1Mf+YFozVRfkHjKEHDWjinrdNj+oxg5rpmoyPphwqlSbjTCWz8dLfKVJAjzmcY0xlxrDFo/7WKFOImOD4P+F2TAaXvau0UQ/5GrSnvUJGUI1SR6KzqcSnpI1JD9ZEIVlD06eZkx7y+4mbHaYxwDy16fTDAmsAz52tg4qJK9Km6AwTMrcHwcUYzO/1+1RPVD6C5gr7vBw== Received: from DS7PR05CA0080.namprd05.prod.outlook.com (2603:10b6:8:57::18) by DS0PR12MB9348.namprd12.prod.outlook.com (2603:10b6:8:1a0::18) 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:44 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:8:57:cafe::8e) by DS7PR05CA0080.outlook.office365.com (2603:10b6:8:57::18) 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:44 +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:43 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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:26 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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, 27 Aug 2024 10:02:25 -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:24 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 03/10] iommufd: Add IOMMUFD_OBJ_EVENT_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC Date: Tue, 27 Aug 2024 10:02:05 -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_|DS0PR12MB9348:EE_ X-MS-Office365-Filtering-Correlation-Id: 264d9098-a355-485d-1136-08dcc6ba112b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: d/mszNF4xyI5WOQFnoCoDZeYvwJrbe/2W19JkYcnvukFWkGiQ6dkV4E3m9O6ulESVYCgaF6bB6XPrIqkWo6sK72xFEC7kh9+x0+xe94SsY7xthFkBHLItEoSYytzMQWP220f/LgMif5Xq4qcjT9caLKbrTtQxIQUjKAkFtCAazk0nLR5UuHYmcWkwmHZPl2buP30vs6QCMGrL/ng5VQltfx0djnx+eqmKyC7laosgZdv8dXSd4Z9SwGLlcPL81vasKMW2tpp++cRh/hGWJaY3N08iOQVj9QcOABp5fLRDhCgOvMUqhShX0eV+/dG7Wl4aM6SuS7I5p7/zsIubkLWwNK2Wjg2EyuC9iS2xZqG7t9euIJhLOUXJZaw9E/oVOAvFxKXqcBCK6lKwwpZZfCGIIlWSoknZqf6Z1kPh5bZgfOKANKsVx1RTGfIzbKp3X89g3MBgpYVsaSl3VdwfSTwzXkjowa15DZnoagfHJEklGkAomeY1U5h1deuozSHP5xF6vF6Wk9G62FW+3hlqGHW4ro7AQxBzM+IWWmdCUCmFuBbUtt8AB0vmmTF0VxgXLNK5zryuNae6jeUKVowEsLZct1N0EwT6qvFDbmQBZgV787G2Qg0AuSuZ6Mc/WAZG0amKZTvYKHM0434IRM/v01hXdf5r3SUWCIDYPPomNhNnRKjRnIyEnDDlsoc8m+npZZRarO8xRxtMYgiI8mvPnTmsB0AotoN4hA7RruvuCDOpzDRFmIp3C0BAiNSNugikEGRyX+R8dfpIdYNKUYgOnxF7uR7nwg065S5RSUlnqmwfcAnAvftZU+ZpkJORFwZCiMlqUTYEkIdu7dpA/pWxgmGJFXAe86rCOOm8JTd1DXWyOtom+w7Zwcyhpmmk2j1/MQHCSqbpUwvKYkGOOD4qWiZmMH32uTFr78jLG/prHNKZUur7PEdfoE1k1aDlg0RDmQc7kRR3Z4J2SIVSWkztJi4MdM2gdEKevF18/tb6dFyCwIc3/ojCeGU7rXvUd4oXJt20eX0mvUJfrIWJeDk/RKuye5lxsJUYaHT6AAzgk80VecSwIvorPo6YpFEVvS7dMO6QW6nDyxGbn3KvfiZQ0K2mERl4oM5I73+9rrzzwwUGvuWgfdYRLdNvezHQVBh9GlB5yj7rbcK3NjzoK+VP9V3Do3YldWvellne4VAJbvnMCri/QNX2fdB+TjBtIADALGy7r3nU1B8b4eIOdSiI+ejM0qLSScQyhhVFfHROlOTNghmEbspknk3/XBTmg/cAqB4DlhMUfNUXt5Fm2clIc5LzVe2TOjDnOkYsi/HUvNUNYvmImkBa26SEgSjxuxlFFsaVFcWQEja4atxoqJ75u5rSpMfzAwlmsOzUZ895ZFGahpk2YG1J9tRREFCCS/EFprPpv18p0IQ2tVQh8P3sdkpP649GDHZAlmDpJLdrQApAke3CzC7LVCpctUUg/Hwa15E 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)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:43.2613 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 264d9098-a355-485d-1136-08dcc6ba112b 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: DS0PR12MB9348 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100251_626631_5514BFDA X-CRM114-Status: GOOD ( 17.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 Allow a VIOMMU object to allocate VIRQ events. Each VIOMMU is allowed to have multiple VIRQ events but they must not have a duplicated type. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/event.c | 136 ++++++++++++++++++++++++ drivers/iommu/iommufd/iommufd_private.h | 54 ++++++++++ drivers/iommu/iommufd/main.c | 5 + drivers/iommu/iommufd/viommu.c | 2 + include/uapi/linux/iommufd.h | 32 ++++++ 5 files changed, 229 insertions(+) diff --git a/drivers/iommu/iommufd/event.c b/drivers/iommu/iommufd/event.c index 8fea142e1ac2..f10827ce9cbd 100644 --- a/drivers/iommu/iommufd/event.c +++ b/drivers/iommu/iommufd/event.c @@ -339,6 +339,67 @@ static const struct iommufd_event_ops iommufd_event_iopf_ops = { .write = &iommufd_event_iopf_fops_write, }; +/* IOMMUFD_OBJ_EVENT_VIRQ Functions */ + +void iommufd_event_virq_destroy(struct iommufd_object *obj) +{ + struct iommufd_event *event = + container_of(obj, struct iommufd_event, obj); + struct iommufd_event_virq *event_virq = to_event_virq(event); + struct iommufd_viommu_irq *virq, *next; + + /* + * The iommufd object's reference count is zero at this point. + * We can be confident that no other threads are currently + * accessing this pointer. Therefore, acquiring the mutex here + * is unnecessary. + */ + list_for_each_entry_safe(virq, next, &event->deliver, node) { + list_del(&virq->node); + kfree(virq); + } + destroy_workqueue(event_virq->irq_wq); + list_del(&event_virq->node); + refcount_dec(&event_virq->viommu->obj.users); +} + +static ssize_t +iommufd_event_virq_fops_read(struct iommufd_event *event, + char __user *buf, size_t count, loff_t *ppos) +{ + size_t done = 0; + int rc = 0; + + if (*ppos) + return -ESPIPE; + + mutex_lock(&event->mutex); + while (!list_empty(&event->deliver) && count > done) { + struct iommufd_viommu_irq *virq = + list_first_entry(&event->deliver, + struct iommufd_viommu_irq, node); + void *virq_data = (void *)virq + sizeof(*virq); + + if (virq->irq_len > count - done) + break; + + if (copy_to_user(buf + done, virq_data, virq->irq_len)) { + rc = -EFAULT; + break; + } + done += virq->irq_len; + list_del(&virq->node); + kfree(virq); + } + mutex_unlock(&event->mutex); + + return done == 0 ? rc : done; +} + +static const struct iommufd_event_ops iommufd_event_virq_ops = { + .read = &iommufd_event_virq_fops_read, +}; + /* Common Event Functions */ static ssize_t iommufd_event_fops_read(struct file *filep, char __user *buf, @@ -475,3 +536,78 @@ int iommufd_event_iopf_alloc(struct iommufd_ucmd *ucmd) return rc; } + +int iommufd_event_virq_alloc(struct iommufd_ucmd *ucmd) +{ + struct iommu_virq_alloc *cmd = ucmd->cmd; + struct iommufd_event_virq *event_virq; + struct workqueue_struct *irq_wq; + struct iommufd_viommu *viommu; + int fdno; + int rc; + + if (cmd->flags) + return -EOPNOTSUPP; + if (cmd->type == IOMMU_VIRQ_TYPE_NONE) + return -EINVAL; + + viommu = iommufd_get_viommu(ucmd, cmd->viommu_id); + if (IS_ERR(viommu)) + return PTR_ERR(viommu); + down_write(&viommu->virqs_rwsem); + + if (iommufd_viommu_find_event_virq(viommu, cmd->type)) { + rc = -EEXIST; + goto out_unlock_virqs; + } + + event_virq = __iommufd_object_alloc(ucmd->ictx, event_virq, + IOMMUFD_OBJ_EVENT_VIRQ, common.obj); + if (IS_ERR(event_virq)) { + rc = PTR_ERR(event_virq); + goto out_unlock_virqs; + } + + irq_wq = alloc_workqueue("viommu_irq/%d", WQ_UNBOUND, 0, + event_virq->common.obj.id); + if (!irq_wq) { + rc = -ENOMEM; + goto out_abort; + } + + rc = iommufd_event_init(&event_virq->common, "[iommufd-viommu-irq]", + ucmd->ictx, &fdno, &iommufd_event_virq_ops); + if (rc) + goto out_irq_wq; + + event_virq->irq_wq = irq_wq; + event_virq->viommu = viommu; + event_virq->type = cmd->type; + cmd->out_virq_id = event_virq->common.obj.id; + cmd->out_virq_fd = fdno; + + rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); + if (rc) + goto out_put_fdno; + iommufd_object_finalize(ucmd->ictx, &event_virq->common.obj); + + fd_install(fdno, event_virq->common.filep); + + list_add_tail(&event_virq->node, &viommu->virqs); + refcount_inc(&viommu->obj.users); + + goto out_unlock_virqs; +out_put_fdno: + put_unused_fd(fdno); + fput(event_virq->common.filep); + iommufd_event_deinit(&event_virq->common); +out_irq_wq: + destroy_workqueue(irq_wq); +out_abort: + iommufd_object_abort_and_destroy(ucmd->ictx, &event_virq->common.obj); +out_unlock_virqs: + up_write(&viommu->virqs_rwsem); + iommufd_put_object(ucmd->ictx, &viommu->obj); + + return rc; +} diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index c22d72c981c7..be1f1813672e 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -133,6 +133,7 @@ enum iommufd_object_type { IOMMUFD_OBJ_IOAS, IOMMUFD_OBJ_ACCESS, IOMMUFD_OBJ_EVENT_IOPF, + IOMMUFD_OBJ_EVENT_VIRQ, IOMMUFD_OBJ_VIOMMU, #ifdef CONFIG_IOMMUFD_TEST IOMMUFD_OBJ_SELFTEST, @@ -567,6 +568,43 @@ static inline int iommufd_hwpt_replace_device(struct iommufd_device *idev, return iommu_group_replace_domain(idev->igroup->group, hwpt->domain); } +struct iommufd_event_virq { + struct iommufd_event common; + struct iommufd_viommu *viommu; + struct workqueue_struct *irq_wq; + struct list_head node; + + unsigned int type; +}; + +static inline struct iommufd_event_virq * +to_event_virq(struct iommufd_event *event) +{ + return container_of(event, struct iommufd_event_virq, common); +} + +static inline struct iommufd_event_virq * +iommufd_get_event_virq(struct iommufd_ucmd *ucmd, u32 id) +{ + return container_of(iommufd_get_object(ucmd->ictx, id, + IOMMUFD_OBJ_EVENT_VIRQ), + struct iommufd_event_virq, common.obj); +} + +int iommufd_event_virq_alloc(struct iommufd_ucmd *ucmd); +void iommufd_event_virq_destroy(struct iommufd_object *obj); + +struct iommufd_viommu_irq { + struct iommufd_event_virq *event_virq; + struct list_head node; + ssize_t irq_len; +}; + +static inline int iommufd_event_virq_handler(struct iommufd_viommu_irq *virq) +{ + return iommufd_event_notify(&virq->event_virq->common, &virq->node); +} + struct iommufd_viommu { struct iommufd_object obj; struct iommufd_ctx *ictx; @@ -575,6 +613,8 @@ struct iommufd_viommu { /* The locking order is vdev_ids_rwsem -> igroup::lock */ struct rw_semaphore vdev_ids_rwsem; struct xarray vdev_ids; + struct rw_semaphore virqs_rwsem; + struct list_head virqs; const struct iommufd_viommu_ops *ops; @@ -595,6 +635,20 @@ iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) struct iommufd_viommu, obj); } +static inline struct iommufd_event_virq * +iommufd_viommu_find_event_virq(struct iommufd_viommu *viommu, u32 type) +{ + struct iommufd_event_virq *event_virq, *next; + + lockdep_assert_held(&viommu->virqs_rwsem); + + list_for_each_entry_safe(event_virq, next, &viommu->virqs, node) { + if (event_virq->type == type) + return event_virq; + } + return NULL; +} + int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); void iommufd_viommu_destroy(struct iommufd_object *obj); int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd); diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 015f492afab1..22381ba031b5 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -361,6 +361,8 @@ 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_event_iopf_alloc, struct iommu_fault_alloc, out_fault_fd), + IOCTL_OP(IOMMU_VIRQ_ALLOC, iommufd_event_virq_alloc, + struct iommu_virq_alloc, out_virq_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, @@ -528,6 +530,9 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_EVENT_IOPF] = { .destroy = iommufd_event_iopf_destroy, }, + [IOMMUFD_OBJ_EVENT_VIRQ] = { + .destroy = iommufd_event_virq_destroy, + }, [IOMMUFD_OBJ_VIOMMU] = { .destroy = iommufd_viommu_destroy, }, diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index a4ba8bff4a26..9adc9c62ada9 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -67,6 +67,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) xa_init(&viommu->vdev_ids); init_rwsem(&viommu->vdev_ids_rwsem); + INIT_LIST_HEAD(&viommu->virqs); + init_rwsem(&viommu->virqs_rwsem); refcount_inc(&viommu->hwpt->common.obj.users); diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 0d973486b604..f9ec07efed8d 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -54,6 +54,7 @@ enum { IOMMUFD_CMD_VIOMMU_ALLOC = 0x8f, IOMMUFD_CMD_VIOMMU_SET_VDEV_ID = 0x90, IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID = 0x91, + IOMMUFD_CMD_VIRQ_ALLOC = 0x92, }; /** @@ -951,4 +952,35 @@ struct iommu_viommu_unset_vdev_id { __aligned_u64 vdev_id; }; #define IOMMU_VIOMMU_UNSET_VDEV_ID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID) + +/** + * enum iommu_virq_type - Virtual IRQ Type + * @IOMMU_VIRQ_TYPE_NONE: INVALID type + */ +enum iommu_virq_type { + IOMMU_VIRQ_TYPE_NONE = 0, +}; + +/** + * struct iommu_virq_alloc - ioctl(IOMMU_VIRQ_ALLOC) + * @size: sizeof(struct iommu_virq_alloc) + * @flags: Must be 0 + * @viommu: viommu ID to associate the virtual IRQ with + * @type: Type of the virtual IRQ. Must be defined in enum iommu_virq_type + * @out_virq_id: The ID of the new VIRQ + * @out_fault_fd: The fd of the new VIRQ + * + * Explicitly allocate a virtual IRQ handler for a VIOMMU. A VIOMMU can have + * multiple FDs for different @type, but is confined to have only one FD per + * @type. + */ +struct iommu_virq_alloc { + __u32 size; + __u32 flags; + __u32 viommu_id; + __u32 type; + __u32 out_virq_id; + __u32 out_virq_fd; +}; +#define IOMMU_VIRQ_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIRQ_ALLOC) #endif From patchwork Tue Aug 27 17:02:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779889 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 AE5F5C54731 for ; Tue, 27 Aug 2024 17:26:29 +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=r4dsKNnuk6CqIH0N6k5Osr46RlFdbBtzX+OpDl0TX4E=; b=QppjcW8fqkNsERJ6dlIGhvsQjB P6Ftf0koneNtu6emGU6znmmmHJ0YWesIpPTikv2awPSOdVLTrt9d1Uov+Z6g8rUAjU08JKhCYKTKA kkYF0Zl/ap/m3M8soCm03m9tLoHl/h4WkX55LUHEfLdvQ1CjMjctSws22IGkEwhlZ1D7fpGdB67Br xGh63dOXZWl7eMRZJ9BEOaFvlBi/AdygfPeMdRfrEMfyW2ujS+TcsD0PEhNo5BdjS2LWZUjMoSSY9 H7IhZ50Z4HOTn5+d8i7s/kC0mYzBuOqTpvPqtwRAe7BMzqc9YF09VPwTruuIjN7OJMENgJr/psYi9 iEqpYLNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizxS-0000000CHbl-1wYb; Tue, 27 Aug 2024 17:26:18 +0000 Received: from mail-co1nam11on2062a.outbound.protection.outlook.com ([2a01:111:f403:2416::62a] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizap-0000000CCHk-2kdD for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p/vB5olj1Of/G6BGeTqZURggacHUTmkGFpvtj8Uju4RTdi4vBzz99LxNFKUlZ+L3TrdYDUuDHsmQ0L1g2KFyAFQn+e9UeuCTFqjXZeRnQsZdSFYqMpNU93cNIFuYuH98qxF3Tj8/4bcVGQM1mvtGHXva0/F0b9cvd4BV4JaDCeedkVoelRR+HuHuBgHFbMJNHECrAusWCZOzdrQRaGkdCftFdOrcV+pbrOAz9MASFbxod8Lg7ZbK0TRZK8MaDRBngmFOq/ilaoIIOYYXHJkLAvibdhw48xG6MGtcAAfDwvNkQr9jfTXUqi/PQfCLWV0oBhTmovQervmcBNisYWS70A== 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=r4dsKNnuk6CqIH0N6k5Osr46RlFdbBtzX+OpDl0TX4E=; b=nW6kYJHpSrHauj3ScRyzlZR0fMUr1sc7KKLt4WeG279H6aaUjHG7UqtAFeufKT4XPSnhhJgxk7S4MwLLnccvF/pxS47FvuH5RGG73oNrT5pBJFR1PAApmIcsXszruRBM4/VoRCoubzZslmJQ3urKSRDyKNqU7yApxBqv1dVj7+ipVQ1dTq9mZeNt/2X4gNfiXOujXQ+UKykl71OfWjuKseeeWW5ZTcnO6UrCxhFL7C1QgabhN8ZFoopqXMc+x9gMHYu9gOs5v8Y2hVpqO9Wl3Ps6Puc4x24BojXNbJk+PnH+9OWzg8J7q0PJYJl5KmJI6quAzpjzn8Anm1U3mgcmGw== 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=r4dsKNnuk6CqIH0N6k5Osr46RlFdbBtzX+OpDl0TX4E=; b=ZmKo/f2AnOy0M6IuI3srG6IK7gSqSM7yh6/y9KnUk6AjZBaH4bThE953xLTE3aMd0Fkm9AdoTaqexNAS3DLX3SSBtk3CR4Intef/UaxCXtwt/Ft8TQm/YbTNHhelSe4RT7qF+r78T0djYDJzdmwBTlBDAkMRNHCtj0cKLSJEizZlj++kYmrsY4+Ix9mQFT5Mb7bnnbFJaVB2DDJNN92p21Y/gdQU/MzboFvBiV6V8XGWap1Qnxpmcs9Z3jPiSfSh81LWF00iDT/dtM45vBNBNJusSDPkbxxpGq/BgxwJbFPzMXOw21X+crXJUYbvMGUddxRITaC8wmT9eX4n4clauA== Received: from CH2PR05CA0058.namprd05.prod.outlook.com (2603:10b6:610:38::35) by PH0PR12MB5606.namprd12.prod.outlook.com (2603:10b6:510:141::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.24; Tue, 27 Aug 2024 17:02:45 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:610:38:cafe::22) by CH2PR05CA0058.outlook.office365.com (2603:10b6:610:38::35) 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:44 +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 DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) 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:44 +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:28 -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:27 -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:26 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 04/10] iommufd/viommu: Allow drivers to control vdev_id lifecycle Date: Tue, 27 Aug 2024 10:02:06 -0700 Message-ID: <3ab48d4978318938911d91833654b296947668ad.1724777091.git.nicolinc@nvidia.com> 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: DS3PEPF000099D5:EE_|PH0PR12MB5606:EE_ X-MS-Office365-Filtering-Correlation-Id: b2f22e4f-e1b0-4631-bcad-08dcc6ba1210 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: 3DT1ktkjJ5BHCUUbufscsayewbPC6AUzfDrYPenJLPTtOBiI84vQifG/0onAODaNlEPCM7hslmuHM6pZEjn0VyfNjTqWbU473DO+ILsRiTKKYm0eM8t66u1LRSqUKUv5jS0QY1sUTMDAAbwQL691ZGkmHiK9dthSHASu1fSNzBzTyWOit9HohKta/otcoN/f/N+BgZWc9RzQg2KMGPBCaZ2cZ/dZM44KnSuujSdpV2/L1Sn9r1HqBkN8nvb6wiNfaKQNa9/F0Nh4rQrFn32D68YjE5lskZqmGi2QzhXku6vQyv6sewzhzSyAr58UNcxVs//ZFPjdwbtnMTHKQGprXbQil5KWiuRatEGycgPo+mukvoGtBSbg8Zz9PScUSIV6L96K0BiK8EaYjko3s3qJgnm0+KP2rpXB4ttlYcJebdyqXLsBeLdwkFCSpDjMzPy3szarm+Gj/wqLgo2pdnd+w5aDse9iMU4qXK5f2Dn+VvDFu30dtcdkwfHkPeZZ094j1Mdwo4R5qkkt3rtZlrfs8iCOV4GEcLPxW0w1fK0BavzkzdtYJvBlvXUZFDS4UB3NLpTDEKKlie6qhmvcW/Lai646TzPvVXl+47M5iX/wYfxHhNleJaG3wOiXwB+gLRPhqk2StXyLLyOzo66mahkBFrz8IZrljI+TLfpek9LW4OLgOVKu3fhzqXEEMsP4APly4nUfsumJeEPPqM3lirDtHK2tTsdT26fujBQ8G465rz4Xw0VbIQIJ1Tk/AHs4+PXJdilZzfIXDHqHUwW9mQMspZ+rPl7LlG7KuwapAy+/rkwGre5GcUrSZTt1seQq8zWRHd+HUg/93t9x6y1YakI6qASx1cDnZY9xnzlEU8gtd0gsxDJPmi8qDBqi3SPrak5RSDUhpJM0oGCEAHk7T9HI6KGzN6fJGxuKkAOkfGgfKFbIWFDNlyUzWwlV203coSnmodsCc3tTcxXFnj2Uw4mkYxrdURtpNIfH1FK45FNZf50wFp50FYI6QhtncICxBG9ehYJQ9hBJHv+u2hz57n9omadqchEDg8m2QPHxKtfzQXvgGnOJlSonVFNACayZYO3D6rAM0JDzepdh7TER3/i1l62YCi3zaJrsYcMKpAB2JXRJUGPv+oWiPHyPvMkdN+Q3OKS8MI4WKABSbQMAJmR84wHyY56Mv3ERyRO/FMLcTaDgp93SvYP/6aeuyoyOF7cSZ/DaBziN11qLnXqJMcsVJE0hamZCQ+POnwY0YzokOH5cDQfJI9sK+/Gpsq5q/Q28cGlCDxfqQukJGP0PTLK4MAb9AGR8jfE/sYbtX7onHnoRS1QnYq4HVUCxySi/bUv1gdcoD5erj0OHoxEddN0+fHSar1zT3n0iLTsvTcIJ4MAF7sFrYQcFJKpHr93f6QNDEa+p9SCmmrUQPYSq1vqGUJk4q6ilvN3mSZORs4AX0Nmsno+aEf0NBbJPYTbEYzje X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:44.7508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2f22e4f-e1b0-4631-bcad-08dcc6ba1210 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: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5606 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100255_867741_C328BE22 X-CRM114-Status: GOOD ( 18.59 ) 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 iommufd core provides a lookup helper for an IOMMU driver to find a device pointer by device's per-viommu virtual ID. Yet a driver may need an inverted lookup to find a device's per-viommu virtual ID by a device pointer, e.g. when reporting virtual IRQs/events back to the user space. In this case, it'd be unsafe for iommufd core to do an inverted lookup, as the driver can't track the lifecycle of a viommu object or a vdev_id object. Meanwhile, some HW can even support virtual device ID lookup by its HW- accelerated virtualization feature. E.g. Tegra241 CMDQV HW supports to execute vanilla guest-issued SMMU commands containing virtual Stream ID but requires software to configure a link between virtual Stream ID and physical Stream ID via HW registers. So not only the iommufd core needs a vdev_id lookup table, drivers will want one too. Given the two justifications above, it's the best practice to provide a a pair of set_vdev_id/unset_vdev_id ops in the viommu ops, so a driver can implement them to control a vdev_id's lifecycle, and configure the HW properly if required. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 2 ++ drivers/iommu/iommufd/iommufd_private.h | 6 ------ drivers/iommu/iommufd/viommu.c | 23 +++++++++++++++++++---- include/linux/iommufd.h | 13 +++++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 3ad759971b32..01bb5c9f415b 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -145,6 +145,8 @@ void iommufd_device_destroy(struct iommufd_object *obj) old = xa_cmpxchg(&viommu->vdev_ids, vdev_id->id, vdev_id, NULL, GFP_KERNEL); WARN_ON(old != vdev_id); + if (vdev_id->viommu->ops && vdev_id->viommu->ops->unset_vdev_id) + vdev_id->viommu->ops->unset_vdev_id(vdev_id); kfree(vdev_id); idev->vdev_id = NULL; } diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index be1f1813672e..4cb1555991b8 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -621,12 +621,6 @@ struct iommufd_viommu { unsigned int type; }; -struct iommufd_vdev_id { - struct iommufd_viommu *viommu; - struct iommufd_device *idev; - u64 id; -}; - static inline struct iommufd_viommu * iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) { diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 9adc9c62ada9..b1eb900b7fbf 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -13,6 +13,8 @@ void iommufd_viommu_destroy(struct iommufd_object *obj) xa_for_each(&viommu->vdev_ids, index, vdev_id) { /* Unlocked since there should be no race in a destroy() */ + if (viommu->ops && viommu->ops->unset_vdev_id) + viommu->ops->unset_vdev_id(vdev_id); vdev_id->idev->vdev_id = NULL; kfree(vdev_id); } @@ -116,10 +118,18 @@ int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd) goto out_unlock_igroup; } - vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); - if (!vdev_id) { - rc = -ENOMEM; - goto out_unlock_igroup; + if (viommu->ops && viommu->ops->set_vdev_id) { + vdev_id = viommu->ops->set_vdev_id(viommu, idev->dev, cmd->vdev_id); + if (IS_ERR(vdev_id)) { + rc = PTR_ERR(vdev_id); + goto out_unlock_igroup; + } + } else { + vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); + if (!vdev_id) { + rc = -ENOMEM; + goto out_unlock_igroup; + } } vdev_id->idev = idev; @@ -137,6 +147,8 @@ int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd) goto out_unlock_igroup; out_free: + if (viommu->ops && viommu->ops->unset_vdev_id) + viommu->ops->unset_vdev_id(vdev_id); kfree(vdev_id); out_unlock_igroup: mutex_unlock(&idev->igroup->lock); @@ -185,6 +197,9 @@ int iommufd_viommu_unset_vdev_id(struct iommufd_ucmd *ucmd) rc = xa_err(old); goto out_unlock_igroup; } + + if (viommu->ops && viommu->ops->unset_vdev_id) + viommu->ops->unset_vdev_id(old); kfree(old); idev->vdev_id = NULL; diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index f7c265c6de7c..c89583c7c792 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -56,8 +56,18 @@ void iommufd_access_detach(struct iommufd_access *access); void iommufd_ctx_get(struct iommufd_ctx *ictx); +struct iommufd_vdev_id { + struct iommufd_viommu *viommu; + struct iommufd_device *idev; + u64 id; +}; + /** * struct iommufd_viommu_ops - viommu specific operations + * @set_vdev_id: Set a virtual device id for a device assigned to a viommu. + * Driver allocates an iommufd_vdev_id and return its pointer. + * @unset_vdev_id: Unset a virtual device id for a device assigned to a viommu. + * iommufd core frees the memory pointed by an iommufd_vdev_id. * @cache_invalidate: Flush hardware cache used by a viommu. It can be used for * any IOMMU hardware specific cache as long as a viommu has * enough information to identify it: for example, a VMID or @@ -69,6 +79,9 @@ void iommufd_ctx_get(struct iommufd_ctx *ictx); * include/uapi/linux/iommufd.h */ struct iommufd_viommu_ops { + struct iommufd_vdev_id *(*set_vdev_id)(struct iommufd_viommu *viommu, + struct device *dev, u64 id); + void (*unset_vdev_id)(struct iommufd_vdev_id *vdev_id); int (*cache_invalidate)(struct iommufd_viommu *viommu, struct iommu_user_data_array *array); }; From patchwork Tue Aug 27 17:02:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779886 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 E0C8CC5472F for ; Tue, 27 Aug 2024 17:24:02 +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=S7uJzBWU3ug9HE5spQDfc2A+knb9ed9B5xzddhVFhvw=; b=1mMuTA0LBk+sdy6na0K6E0gfqq qvXqN+Dgi4hzrBe/+uxsCIdO+CbsLl18krQelFUrSVjXh344NQJELiY+n/wzFdaeNuLJgGgWP6aDF Uz64KiujxxaSMQv+aCIpZE0FOLV3wL5wReKIFqh5YuJVIPnrdEwmzXGU8ZsHIsSe/JLojf3Fj1mzn 810Gd7sOjFBUSJjprrfUeN+MlRZJH5Q5DrrdlrRWteAc7DYnSuQA17gK5icuKdt00x5LwEEz3tSIp ReNrQk04ZU5j3kLIf7GJLZYFceqfke1dbxS6bLc4tZ33txnO4DvwohclzROPJmL0Lypadhq7pe1iw RVQjumhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizv8-0000000CHB7-1EBf; Tue, 27 Aug 2024 17:23:54 +0000 Received: from mail-dm6nam11on2062e.outbound.protection.outlook.com ([2a01:111:f403:2415::62e] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizal-0000000CCE1-2oLv for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Jlk/AaLW33cWx8MwaKJSvcdYr8nz4rJ4qWIT2AlcIw3quU/aXbXU+dt8BLNzxsDWns4wL0Fu9WOB5j/GBPBxjQxnI8SplgMASNT2F6IP5NK8kAN2YtiM+NYuqomyL4k/0cCGsWsOkOA2YxW+1mViHRUcNs6MoI1CwEA4HHYlw/9Ub+2zuGVtkHkrJC6BtUgZZXyyj9fq+FzvsTEwp/J2TYRMVedtiuLH3A/QjV/ube/hWoyimmmTaMki0vY/VHrHpcyZykQh+iZfEvqjR/DJ6exVm3dL+F/ga4Y/sd3r9U+lgDP31l+yQuTy/ZeVtJcldJmB+bA+s5vLscDzSvILHw== 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=S7uJzBWU3ug9HE5spQDfc2A+knb9ed9B5xzddhVFhvw=; b=JxRp6h8mvZmVU3RUBV+iPe1bdzgD1DIVfM651pI2aBYfABS33Q5xIffbKb+mg3VqW1LENhR5mafqlkpAzHdcjDu8KDtkSkIE1cZW8txwJFb4ptlErGVtr21TzImz7+PJgNKnDmj6cLYbN+ETT8jQmYFiiq4tBZ0x8BRQ6VLG+9JD5FS8VZrJrMflJfdk6Q5JHZxzEREa4r5IBfysICI3BDHrHS5bk9xncIQ1eRNs0KarFmaJAXf9SWePvGL9kWzNymAJ5rKEkYLdi4npVXk4trfuvqq9yYpplGzB+Zqtgi863KT5GsmRxw49jVWpJ8I8fGpkrzvImQwXxtN0mo0s7A== 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=S7uJzBWU3ug9HE5spQDfc2A+knb9ed9B5xzddhVFhvw=; b=VOTxo1T8553etDr7d1k/LjNrvSThdNbcXuMHySpqW1ycfT7iG1rJqcrnKZrpNueO2doC8ZFJwoj2GG8dF+YJWabWkrbVvyBylFgJBqgTpEZq6kHMrrA7AI6L5CGhc6q8ygr3YAgaeTPR5mgIdzlGM2nUnRcPXuhkWUGceVFjsdUXO+wksw7scJVzvM/hZb52f9cSfMCa21yzikknIB9fVLmudxdqWZ7QzGrkYr5Dm+MjdRhavA5sZ2sJsy6WyzIdV3ocOChrJzfmH6cR48UcZuklwB5nmKtY7aCsedSWJBczL7ktsr0Jdf2UqqRmp6jZ8pdtpm+nutBeSEK5W1LwFg== Received: from DS7PR05CA0072.namprd05.prod.outlook.com (2603:10b6:8:57::7) by IA1PR12MB6387.namprd12.prod.outlook.com (2603:10b6:208:389::7) 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:47 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:8:57:cafe::a3) by DS7PR05CA0072.outlook.office365.com (2603:10b6:8:57::7) 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:46 +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:46 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:29 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:29 -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:27 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 05/10] iommufd/viommu: Add iommufd_vdev_id_to_dev helper Date: Tue, 27 Aug 2024 10:02:07 -0700 Message-ID: <0079015047db9981c111f09414a863b644c038ef.1724777091.git.nicolinc@nvidia.com> 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_|IA1PR12MB6387:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c1c7aa8-3382-4c97-35b9-08dcc6ba1335 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: e7QiIVEhn2lsOKpdwRxa97VcN46YjMOgZFoKR5ON6V+/gAucKWs8oMw64oFLHZdPX2Ilp9lPpvB4Uf4WC6hKzw7JhP4LkVErtpAW/gBlI0DruFpbY5WpLhUBGpGKwArV/BApHJUcibfD2fTgFO0pzm4agmIlwIoB9ZGIBzh05838i2CebyQvSvGz1SC16TUlKjoWA6LOg8H+0i+NfSSJY5yJ9P8O+CCX4Y+zknNQrRl5FXgN8Qy65jH66iKkAitzUbP2kLBhSEtijOHH0PeGXPNq+/swl9sPGGfg9wmBwW1S7bBR+jVJPUrrWsTFpp3LKDy8/x8xuy5RW+7s2vo4hVT8lOgc78ginix4vXtsqrV6FbZM9ipiJ0UU7TI+haKHObiHLtcZ4aiXVIHUQJ+yBOKn9KiQuzPGXHC9TruYUeyde6vxx17g2dqHW+qiV2ENLMEd9N0FfY5ghqAirjf3oeD4FmosOdXb8XzQJdD2Hqlpt+Irh7kS1gt93MKbciy2qzZdxkBry0DCAUJc/8tmGSs8bi0/sF/hODAU7iOU/QPA53+ShVDVk2p545tltcMUdSBsldaqkwqTkq5l2G/dF5JB20ao6l/9NEc0ugQpX96xPGJUp76mde502bRPVjPQadHSMopbimWiqa6ujGp6jEFvnr9Y+N/ZcR8c/18YiNdPYW1q7h2A8lZ2LSLytGOx93K7+178bKtLbcqkPd3/s2u9NMji335zRMChNdeXHs6ZbY/HT7sp9wLDAb5EUbmjAxB3fWYGGLQnMLt0UQHemJ4wtbfI13Rs+++YdDIh5bTdXRVxiDeGmkdRz31MfxAtJ1M6VRzPvPznrIVcBJWh14C29WFadN/GFT4ohrX0UhrE9jD14lgcVe9Zo3om2jGZt9J0snmhw1J70hNLcWvZ2viIYVni1ogfHMoUAK2JTeCLmTTw/vXh4NhPZpUKEpD31bRLNxUfWQxLv7C+u0KhAMmaRmXwzQdlJQCiTOYTk839L9rJPHQI/Sdom8H+BcaLzR9HK3MmwsUGsL03Gwfq8AEOQPRlvARpw0hgBnYuCEt731T85zcna6KJr4+Ws6EA5VZwekIujVcp68SJ3H2wH+KfWaz33YBsz8Jv1FkvQ5U4tYtAJ2viIgohBQQjZvdblD2rX7PoB96V+Qk7PjTRvpbyXAGnEN9GfAxT8xQH08jiOguPtit2X6yiThKOJYjH9pe1JOEc7RjV0Ffke0H9du7KObjQg5C204oJ2mR/OUtVZ3yO+jGwEo6TOPNSoqAY1Xk8/gyQy2m5016f9WWTRlGzi2dsxIVL3D1R3FWmzeR1iqZizdCp+aNEg39Mdbx0ueLTgTuUSnHpOQxfM2nnXEK/1yxM612xwjauJLf61wwh9yi1rT5PI3S2AD4FbaWdJlnKuQnaaAB8lyW3nV5yP/ZYhDofLJVJ2tpym1iTJRY= 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)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:46.6519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c1c7aa8-3382-4c97-35b9-08dcc6ba1335 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: IA1PR12MB6387 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100251_887639_D0B68525 X-CRM114-Status: GOOD ( 10.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This helps drivers to get the dev pointer held by the vdev_id structure. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/viommu_api.c | 14 ++++++++++++++ include/linux/iommufd.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/iommu/iommufd/viommu_api.c b/drivers/iommu/iommufd/viommu_api.c index 3772a5892a6c..82eb33e047cf 100644 --- a/drivers/iommu/iommufd/viommu_api.c +++ b/drivers/iommu/iommufd/viommu_api.c @@ -51,3 +51,17 @@ iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu) return viommu->hwpt->common.domain; } EXPORT_SYMBOL_NS_GPL(iommufd_viommu_to_parent_domain, IOMMUFD); + +/* + * Fetch the dev pointer in the vdev_id structure. Caller must make ensure the + * lifecycle of the vdev_id structure, likely by adding a driver-level lock to + * protect the passed-in vdev_id for any race against a potential unset_vdev_id + * callback. + */ +struct device *iommufd_vdev_id_to_dev(struct iommufd_vdev_id *vdev_id) +{ + if (!vdev_id || !vdev_id->viommu) + return NULL; + return vdev_id->idev->dev; +} +EXPORT_SYMBOL_NS_GPL(iommufd_vdev_id_to_dev, IOMMUFD); diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index c89583c7c792..88d6586a424f 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -99,6 +99,7 @@ void iommufd_access_unpin_pages(struct iommufd_access *access, unsigned long iova, unsigned long length); int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, void *data, size_t len, unsigned int flags); +struct device *iommufd_vdev_id_to_dev(struct iommufd_vdev_id *vdev_id); int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id); int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx); int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx); @@ -138,6 +139,12 @@ static inline int iommufd_access_rw(struct iommufd_access *access, unsigned long return -EOPNOTSUPP; } +static inline struct device * +iommufd_vdev_id_to_dev(struct iommufd_vdev_id *vdev_id) +{ + return NULL; +} + static inline int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx) { return -EOPNOTSUPP; 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 From patchwork Tue Aug 27 17:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779888 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 54BECC5472F for ; Tue, 27 Aug 2024 17:25: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: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=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=NJRqyWftLKMClQWnGGsldQM6RS ZOavOm5CdAvzQjx21lemdp9GKPGl7afCb8JXLwIEdNEBMlzi8A5Q0j0iRsagJYWxi/EfFScsIADqi nos8uRmRWisxopbaTtQCN5QIc+/DX32i6J40rv9NoLcbSGsU3Mkv3FuLgdkvmgtCEGKpeiGFNN04g e92qkH2y/Eh3WDIUGACIAurZ02vJKeqVJtLFp8UQL7uhzZjk/gdwtnGKbub5/2TMbpwjTUGiVHe5P BN8gpQbDVt/8Lee7mNs3hnRPHLs991rWm02QrXHOFImIJer2CEUW0trOdsHNpqsVWrpck5M1G7GQ9 8/4Rg1eA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizwg-0000000CHP0-1X1D; Tue, 27 Aug 2024 17:25:30 +0000 Received: from mail-mw2nam10on20617.outbound.protection.outlook.com ([2a01:111:f403:2412::617] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizao-0000000CCGh-10sQ for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=isqcK1v073uqW2Cg7/dVZ/lqHEEX3cSiiBdOB72xW4ZOp/SM9eBA6B+EtaiN3XFZUCKiIj589koPdxNutblBEhrR+5nqUIyJWxzKDYR75HWET3+QAOVaCLh59ffsJ+qrqRIBT+LHEypijV3QyzEqNCJrKeqnMvrSmF0bzfIJbXZXtthpgFnxjyyNfPPMv3UymvwrU10uAkLCX+P5uqwxeqKI4WloEw4BT7VEIwFzdvF+UIsU9Ahe+9HhOyisz9hgz94EKxfKpTQmntogjGJCRqDVuV/8fopwww9FAqlJ+w2C9mJznICNB70qcAOKExJpIzA7TdsdVxu8XaGCgfAD7A== 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=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=JnMGPWtPStgUh6bAWFcsOCeXxkFYiF/4vVxZ5XIZYHH2FItW7uWd+d4UbM40VLxe5QyXvMEF0SoqTdpebUPMoDe+PMLAJDdnhl0yzLgMJz4etHx5CZrXGRjMYP5t37O9LnBvf+yhX1OuzVJyPiNgWkCB4vudyhKEDdg111R3rIj1hhLDMXe4mhMYSDZJGQOM3OqxUgb70CA5qKNm+TdaFBgIKZ+o4wVKd6508jPMflOVA1Hl1GFttVI33xmpilss6oEvR56NbBxgg3SGEZqzYhSeSFhky5je+k9wmUEsg6eqzAbnDqMkRmpmRZ5WCG8X2lxxmC8sxk1XsZIoggKl7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=mtLP0IVCJbxKV+h8jKTHo0+kYizW/a42eZmztDImQUNAyXUw/sJQZPMv87Uu4dlwgw24XtqwPEXM0xy9Og4A61nDjBQfagO6f8nNLKEhRrlPQ6BC+O27mFDUXi+CjPORU3mo/FMyqBbgyttqrXbEJrp/klzCgMXe4admb+T+HdQJKXawLp48hb+wBo/8kYE38ji9SD8SWqw6ixqZRkAywkRNHrGw1w2ZnXPTF7HldolvvLFmwAFPH/C99C5C6KyxmsO4Kkfk5HtkhCuKEDlSVWkcHv2Q6BwpUEa4EY+Z5594K5IsvYUrRw3WdcmSZZxaIVdRKz9zWes6cNmbxevDtw== Received: from CH0PR03CA0417.namprd03.prod.outlook.com (2603:10b6:610:11b::6) by LV3PR12MB9404.namprd12.prod.outlook.com (2603:10b6:408:219::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 17:02:49 +0000 Received: from CH2PEPF00000142.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::5c) by CH0PR03CA0417.outlook.office365.com (2603:10b6:610:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26 via Frontend Transport; Tue, 27 Aug 2024 17:02:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000142.mail.protection.outlook.com (10.167.244.75) 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:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:33 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:33 -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:31 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 07/10] iommufd/selftest: Implement mock_viommu_set/unset_vdev_id Date: Tue, 27 Aug 2024 10:02:09 -0700 Message-ID: <383bb9fabff0051bee9c0fbb5d32163f1e0cf87d.1724777091.git.nicolinc@nvidia.com> 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: CH2PEPF00000142:EE_|LV3PR12MB9404:EE_ X-MS-Office365-Filtering-Correlation-Id: 8effce88-3043-48a3-1ed0-08dcc6ba1425 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: z0n1FM38GPuF25sZ722gtCjAOCnr3wacsyQfmBGpN7b5w1oXiQudOcx1Lxcc/fON4pFDS4TM9WeMiKeMz42ZlK/EbxD6furI02oyWfVdACiDR1YE08o55l+2PO4VPF+JdCByuMyMs0YAAH4ga276ZCPu6v1Rp5pd5ceDb0FjrovWqd9K9KU8tbP33cl4b9nbSijY16WeLqeEXy2MDUq2dgfD1jTN5aFlea8DZ3ShdBrTu9ljPsvatyeBsCXatGi6/WEpfhYerCALdUaDd1H2IMIMmlQtYL7wPn6pTKHEkeKqhKL+9PpvmgjQPg5xGSrDsLuGWJsc6pmM/9Qmixp4V3nM+Ux9xy+aw1bmD9tBgih3IlF2ihYZ0w/qoDIb4pTXKPd9/11/wi21DVu2us5TSNNRElWHSLIeLJbB/osWarHi2J7L0jycxAkzywU8T/4PYfqCSiq4y5bKyWqjXA9lOLQ9HPUyHUSQgQy7eMGZIZCY+zyrDhmKbDPzPSE8S7t9wLEKssCZPavp8hgwgjHpiRK66/MCThqnuIZb5ofoA6+igesP/vSqp9FpBv6zcXcuoZi01yygIRahCvHwuTMUrRaRd4I1iKRO8SWhlFAPidjJgEfdOB2IBePzHxBpvVTabzB18wkUaR4fEIwt9OFaXDefTYSyYYdw4pq4LTJgGfUlOhsQBuv3KVVtFCbzuMmf5Kdq00wBvbWiivFfKW7p/dfLYql0fk1DhcK+4hFsJgsU9A1dIbJiUTIby/Sy+7j6YY9Os8+6sh46tAqXjN6xppti3gGFNSdQ2ajevUVTFNPxCgUrNqJ7FeeCctvGoB/cuxi3O1Jc3uRz3X8yBOdZ+cAYa/C8MsBAL+XHoUbQ/4uE9XgxuvNqlRfDFjcrLEIKRUn3S1/f2JP6UOgpKjr+iy7BbEAeU199n/gTY2LXpP9AlJ8cYBsnYfBEqMSeFJrllc6NUE5LOI/bDDOnLfOdKComB5PLWGhDAFblP9Q+mplRrIt4bRS6vLR3R60P9TLF8v/VJil0/22vJ5EozWbGF1bUmYwA2xz3OYOCnqQPIgPYYAuzTbTmf8zp5PFmeKkfO5S7bcb0mtvcKJPbuUH0gKiYs1PUEJv2Fa0y3/poCCN4Yo57IntzvPX7xHSVLJHedek+eEQWP80u2qmy6yJo1T7l2bxoUC+33lWFNk+kt2CtQKRxBRtT4Ok+lVloCIl2Hpzc0n5Y5+vkt0huvzazBHLvjfGV11mhLGQIl0rFhuhTCIdFbXbIt4fdfRig+KV759eHUkrWwV8zU9aTTQ6LZ/gMDZd92RiSh/M0LoLrghczwXZBd0BIJlyOQEYfcAZcEbyVUiYJj5zk7oYBaCER+F3cwFDzL8GJpqBmRvQKB4FrcZFThv05IQAvea3eJhn750+QgoWPiX3J93X73b4sL6/QkihkHLJfGk62eWfk4NuWsglCU9XX0CZwrnoM5Gtw 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)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:48.2242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8effce88-3043-48a3-1ed0-08dcc6ba1425 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: CH2PEPF00000142.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9404 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100254_459926_B94C38A2 X-CRM114-Status: GOOD ( 15.32 ) 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 So that the driver can take the control of vdev_id's lifecycle. This will be used by the VIRQ feature in the following patches. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index f512874105ac..ea2861d34b4a 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -137,6 +137,8 @@ enum selftest_obj_type { struct mock_dev { struct device dev; + struct mutex lock; + struct iommufd_vdev_id *vdev_id; unsigned long flags; int id; u32 cache[MOCK_DEV_CACHE_NUM]; @@ -541,6 +543,36 @@ static int mock_dev_disable_feat(struct device *dev, enum iommu_dev_features fea return 0; } +static struct iommufd_vdev_id * +mock_viommu_set_vdev_id(struct iommufd_viommu *viommu, struct device *dev, + u64 id) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + struct iommufd_vdev_id *vdev_id; + + vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); + if (!vdev_id) + return ERR_PTR(-ENOMEM); + + mutex_lock(&mdev->lock); + mdev->vdev_id = vdev_id; + mutex_unlock(&mdev->lock); + + return vdev_id; +} + +static void mock_viommu_unset_vdev_id(struct iommufd_vdev_id *vdev_id) +{ + struct device *dev = iommufd_vdev_id_to_dev(vdev_id); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + mutex_lock(&mdev->lock); + mdev->vdev_id = NULL; + mutex_unlock(&mdev->lock); + + /* IOMMUFD core frees the memory of vdev_id */ +} + static int mock_viommu_cache_invalidate(struct iommufd_viommu *viommu, struct iommu_user_data_array *array) { @@ -636,6 +668,8 @@ static const struct iommu_ops mock_ops = { .unmap_pages = mock_domain_unmap_pages, .iova_to_phys = mock_domain_iova_to_phys, .default_viommu_ops = &(struct iommufd_viommu_ops){ + .set_vdev_id = mock_viommu_set_vdev_id, + .unset_vdev_id = mock_viommu_unset_vdev_id, .cache_invalidate = mock_viommu_cache_invalidate, }, }, @@ -757,6 +791,7 @@ static void mock_dev_release(struct device *dev) struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); ida_free(&mock_dev_ida, mdev->id); + mutex_destroy(&mdev->lock); kfree(mdev); } @@ -773,6 +808,7 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) if (!mdev) return ERR_PTR(-ENOMEM); + mutex_init(&mdev->lock); device_initialize(&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; From patchwork Tue Aug 27 17:02:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779894 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 8C6B4C5472F for ; Tue, 27 Aug 2024 17:28:05 +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=ss4/aUGPOPzQOkDGeHhXTGW2kLfTHKop8PrV2z2scPg=; b=a0biO8hVpszuEdeh+b0Q/woa7g /T1iJXqAf6B+T7pImD25JWhsIdQyXwsT37RfW3u/QKB4I/M21yRYgX67VSYxdmZNA2OQH8rgBk//D k/E1geAZrnh/QlYi/2z8EdWf2d5NH6A8kyf2+tIUzictoy8D+JNuJEHkzWlvc+F9WfDzcCgTmelI/ BTmflfnpeQBljjQBcfFVmBgqU40BmGxsMTKusRfapq3Jig0ZxixGVD4xG4s0RywI1ReBRLFNGFjJA 8Ostp16pUBw5k+n5p+km6Pjh3TPE9eCFw6UGg/+6zlI8wDQ+9eoAJ9+2i15BP7jxl1Mi+QnnSWXcI WLmidKEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizz0-0000000CHqD-1N6s; Tue, 27 Aug 2024 17:27:54 +0000 Received: from mail-dm6nam11on20630.outbound.protection.outlook.com ([2a01:111:f403:2415::630] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizau-0000000CCLt-4APf for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:03:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CR3MNT27+VOUwI2VdFBWqWGVCOEBxp9i/G4zjtizaLMXaO696Xzg1D3lVtFWBBCN9mgqiDZMt1xkzExpdKYWKdc5ScbQKGo91xPTYwPbwgZu7QJaj+xUozLDQzCrwYfNCAsH4XxpKAf99qecBGrjVWqRb4GiQO7zB5H+tfSUNx27ncxF8EtxBkzvfVgHDaJxHbFaBMjug2RJwRsgsiBFMIvFK7m6+28vBa8S59qkiIEsRA7iP4X73lgaARje+CBi/BTk/xiVqxawIR4bHG4kUFA3OZv46AXnZedWpr36HSv++Aa4pzZHxvmJHDRJNBcZnVGVdO+g5roMlk/Xooxi+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ss4/aUGPOPzQOkDGeHhXTGW2kLfTHKop8PrV2z2scPg=; b=ehzrLTktvl+ByLtSavg0vmLD9ZgR1B9vl5dYeGGx0aX+PNy97zocpbqqmTFl5XptNcLi0deAJs/Ap7/uXErEdsxifuoJB3eevdzrnogcSK3xGRQtpxD8+Aakmf2Zkw2ybrvCjYsMc/CRPc4DcFuseN5yk4tSXiTAwcqhL87v1yUTf9bnxxQeY6JeZvoMwURHz/R0hjGk23cciKnPLCJJX9rPxkt2oh6j6gHatsqVDeeYvjf6Ck8xzNVywkoIu/4sJUBihUf/JxTebztVDoqu5a+yiuz0BwvJJHsJ7tUY7nMPURSnqntsqHWL2DouwmS1t9/SFefgVXLp1FIFLWggBw== 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=ss4/aUGPOPzQOkDGeHhXTGW2kLfTHKop8PrV2z2scPg=; b=evfuLyW747HKBK/tZcGSNT2P+qQVl8Rp4gkJE/zi1NTdXCz7KfrXMUm0xHf7Kc85i8JngZM2KhyFUx5eHGcbXJwXB8UmUWMNsVpw9IvWul6t0GRcAqMEI78plv6v/XU9KdNYa2SJYKjEEWr0q10/i1oyCb8D7UDT/F4xf47JQ3ryBPVWSy/ZN2qHs5DIybOXPftv66611dLYownt84PXa1d6b9Zboo8geBEnvMM3tlAJ8wTFJ5doZPJA9TRqJTXP3ODzT8UCKNCUxKLp5IomkJdBa7throIzPLUB7H/qfQSWxpP/4Q1DIAJrm4xBPL0EL3fSnkqLkzrq0b/XFBEPFg== Received: from CH2PR14CA0022.namprd14.prod.outlook.com (2603:10b6:610:60::32) by PH7PR12MB9075.namprd12.prod.outlook.com (2603:10b6:510:2f0::20) 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:54 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:610:60:cafe::30) by CH2PR14CA0022.outlook.office365.com (2603:10b6:610:60::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26 via Frontend Transport; Tue, 27 Aug 2024 17:02:53 +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 DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) 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:52 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:35 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:34 -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:33 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 08/10] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VIRQ for VIRQ coverage Date: Tue, 27 Aug 2024 10:02:10 -0700 Message-ID: <6fd58376ee0b04d42cc62e233a65d26127f8f921.1724777091.git.nicolinc@nvidia.com> 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: DS3PEPF000099D4:EE_|PH7PR12MB9075:EE_ X-MS-Office365-Filtering-Correlation-Id: ed12725b-0cd5-40c1-aaa8-08dcc6ba16b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: BHXC0P6fGRKmW3mG++uDSnpNqpuBv/fYin+X7/7OkqBwnugtP8bbVNTETwEaH4ze2DdmP231hx/nPWwcrizBucfIsg40HIBi2l1BsoJmf4HTNdGXFDTxAQHVQmeSxocC7FSPslfo09T8C/9od3DtF0uNDoQ3v4kxxg3CfHxGQL9asRfxI9FCU/vj73+tIfI+uJ7OYYC7aJBDPo41466fo3ZRNuEvOe7azRCHvUhR7K7Eq1YbrqSUgUL1WXA4/Abev9CrcAL/V7iluRgUY1iwib00SS00KriKryBM/l1VzWTgzS3MhEG73u8FfBS306WM2Ex4GyuJ+0NVzl+mNStd8LIqiV7dBYo1jwk0C3TTuoS+o3IgpHVsm11cs9r9I2CpNn3qK4bSbThlOj1rzJODnNbkHjGxw6CDMlY9ShWnzWjluSnWvi/y0SReGJGiyEOZQ86lvFkzYZ3uJr4+uzy4bZW3478Z27NkMQXy1WeayOktix0ny5fSmb4bzpxrp1ZNDsTXj5R8Ertrwl48vEoGXkSBMGj2PD88reWYhv2RfVAwzrlrFK89m0COvdL3mliynW1afWKrXw/OKYbbD+PtKJ1HAxqK+/XuSXzlXDCfZqg1k1q38xOgxz+Yu8qRhuP8nNjPb49OZYMAwQCEUGs0VPPvDpb3z5k3EVBOZZM+6rykLdLrjvBSxXPsrxckq59+fCjXBvChjPZRJTjymAf006MyeKOWqi184145/dQZZzIaEz7NKQ6ZwUJEe7wXREGZ1WLMQp4FhDYTmh2stiIqvCjmJtPd1/ldlPxAZd4lGSwYijR1VFf1ZdmpBcfHYYQKnrNpAYMXGxW/PazD1uq6ZnWK8+xNSjPz71kPocWbTP4e+H+061JGb5lmH3X39Eyd/AI7sRKMQic4ZmJtOcdsONPg28U0zvhaaWUg8QsLBJU4ORwKCGov/mD7wCCsGhHtJY4TQDttLv6SMuV0zJ4Kuda0UPWn8JNs+eXpirCiumCJSt1OFDM9YEVnDxrhEZwl5u7e1aAJjKSjX6ckqb23/71KcvteDudlFQa3Vx7Icy2jWQv4c9cRKH5Eg4VJwcGMQWi7jqhJP8hoLgXk1WiSAx9ROB0QlyO3Yp3vr7lIgo4pOpBS5dO5HVp1wRh9FmHBWbABWKJnZywhFj4s8MTBVdpCLJH8en9OYlrdvhXybAwLAF9RHExZsgNS7QdqV9UH7jaALRvi5NhCFCKALAmuH4IZKxiqSKws7HcpvyMQBmEFGydXIlfiFGPEwZAYb9edDUZR9nwtKjchZokz10KdogvydWmYvXX4D8ufxJywlkCSh9CU2vKI8IS62tVfVmOASSrJ5SCwt3uDg+jC1/mrncujC9JYd1+tKfTl/Sd0M692lu4djhT1ZGNEqF1jU7unR1WA2ZbOuor5oUkbkYbOK1Xy0XLzuzVc8oPOMGLKnlVjobHK1L5yp4gWGG3u3qSF 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)(1800799024)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:52.5451 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed12725b-0cd5-40c1-aaa8-08dcc6ba16b3 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: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9075 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100301_058982_963E6914 X-CRM114-Status: GOOD ( 12.33 ) 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 vdev_id structure from the given mdev and convert it to its per-viommu virtual device 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 56bade6146ff..736ae5f8152e 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_VIRQ, }; enum { @@ -145,6 +146,9 @@ struct iommu_test_cmd { __u32 id; __u32 cache; } check_dev_cache; + struct { + __u32 dev_id; + } trigger_virq; }; __u32 last; }; @@ -210,4 +214,10 @@ struct iommu_viommu_invalidate_selftest { __u32 cache_id; }; +#define IOMMU_VIRQ_TYPE_SELFTEST 0xbeefbeef + +struct iommu_viommu_irq_selftest { + __u32 vdev_id; +}; + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index ea2861d34b4a..75fccd466018 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1560,6 +1560,34 @@ static int iommufd_test_trigger_iopf(struct iommufd_ucmd *ucmd, return 0; } +static int iommufd_test_trigger_virq(struct iommufd_ucmd *ucmd, + struct iommu_test_cmd *cmd) +{ + struct iommufd_device *idev; + struct mock_dev *mdev; + + idev = iommufd_get_device(ucmd, cmd->trigger_virq.dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = container_of(idev->dev, struct mock_dev, dev); + + mutex_lock(&mdev->lock); + if (mdev->vdev_id) { + struct iommu_viommu_irq_selftest test = { + .vdev_id = mdev->vdev_id->id, + }; + + iommufd_viommu_report_irq(mdev->vdev_id->viommu, + IOMMU_VIRQ_TYPE_SELFTEST, + &test, sizeof(test)); + } + mutex_unlock(&mdev->lock); + + iommufd_put_object(ucmd->ictx, &idev->obj); + + return 0; +} + void iommufd_selftest_destroy(struct iommufd_object *obj) { struct selftest_obj *sobj = container_of(obj, struct selftest_obj, obj); @@ -1641,6 +1669,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_VIRQ: + return iommufd_test_trigger_virq(ucmd, cmd); default: return -EOPNOTSUPP; } From patchwork Tue Aug 27 17:02:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779895 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 E5903C54731 for ; Tue, 27 Aug 2024 17:28:51 +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=djhiKFapha2IGC376NNMAO6nQe96ek7Qii9YLPHngBw=; b=AX4j5B38XLo6iMALONU/9+6lGv SZXKz0x3eporFo3ynE8iAVyokQzOX4DQV6LQaTHx+R1xdYKzM/31ek2M3UZMSPHi1ajPEVqcRrISd Yql+AZD/PdvzVyZnjN11n0hDa9Zt4w7Pj6q7wc0JWFOrNKFoXWIJ5cunAUoiYUDnt5QFnRKtc2GzT Mdv3xD70R0u21m/EE3MLoN0AHci/fjdOfD2L7Jg0VRqWplX8d6SbKd3vRxtZsTPW+aLeiEw4txQRR zP4gHkW3GXbkR7K/3wIoSXi5IKfvv+CWWHEb2nDgSPUdgJ9+FxtQnDo4dWP0uc4CnbKQN/4Hx6zyc nJ1UaFuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizzm-0000000CHyu-17sp; Tue, 27 Aug 2024 17:28:42 +0000 Received: from mail-mw2nam10on2060c.outbound.protection.outlook.com ([2a01:111:f403:2412::60c] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizay-0000000CCNK-1YTN for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:03:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pOuQEKkAwRbJz1kOrgEXATEcSeKAHgP+wTf2g8sJ9Mhp+JeWPT9MgMVFcCHMd2flqbpVKqnaubA5wmOJK/yAoaw85SgYDYxHS+KVZDNbJDNKOrP7kZeXr+VLFyHGfHiGj0L2s6+06E/FCJvppyy3ig5uZDRbOibwZaUvufHX2w2x9kAgGNkWU92p+pYBigcRnyo0A06qr/luCAw7Ewjclcjz7tCpfTMJW5GTzqyv4SqUvdYLaPPKgyHGLmHu7FRF2MK50DbtpLn1B3Oug5lv9FlqKY9p/bNL5lXH9vwg8I+SLz4HW7TnxR+tRv3u1+tbINslksn1mTW004U9vJUITw== 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=djhiKFapha2IGC376NNMAO6nQe96ek7Qii9YLPHngBw=; b=HN1wjnwvcgBYdJ8BJ1vkkgCHC9MtT7Qc6t231v73dardQMdIBvDGLIOT2TASCAVPBnVyJ60q8vSGfHxn7lyCWjMaMVFt8NSC14/DO/slWE7G1ITfGScZdiOiMeMkf5mSnuSwDWKtulUCF9vzLHLu195RDL7zBvuiO8SMWWQlWcVubC2Wx2Hj6zoxpAVKj2sCN5aNsFP2YoPQS3a7YgaFJGv2Xf1A4JB4ajileDisqBF6h7BpR7UgUYNgKO8HVqwIymMDx25ddbk/6cxZX1nliocwZerzyCEkmNJDYuGVJcoOas3P+Lkfd6grK9p3p27mZ3G3WJkLic6nY/ss4WXeog== 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=djhiKFapha2IGC376NNMAO6nQe96ek7Qii9YLPHngBw=; b=eAGYtIT3//qW6R4YJhpzbXDScmyPskKL+p/NUpVQRqa+mt4k/h/26W7aliP8ygv7N0mDfe9BXvjXCMwJGJotAnKvbXt8VnMYoHofw/y6jvCWscb7MFi/eYvOWMlMnCRhhsMrU0/oKIeIHv7O4hGSbbc8l0jxmTIoX9HlewcOdcelJNeczoEBSyaYfDwM8ZZC+UlCGsHxU3gyjV7A55qO1MeD9fvxe74ifDtlRuqAnrPyTZmAVPeJfae2EbW0eu7GW0q/DUjkgUKwVqI/QtGhoTAJapHg4msKBESUFZ6ZfaAZcani64kjBbFrEJNDl6XVCZ5+hma0XlWrOT3fNm0DAw== Received: from CH2PR05CA0054.namprd05.prod.outlook.com (2603:10b6:610:38::31) by CYYPR12MB8989.namprd12.prod.outlook.com (2603:10b6:930:c2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 17:02:56 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:610:38:cafe::8b) by CH2PR05CA0054.outlook.office365.com (2603:10b6:610:38::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.16 via Frontend Transport; Tue, 27 Aug 2024 17:02: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 DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) 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:55 +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:36 -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:36 -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:35 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 09/10] iommufd/selftest: Add EVENT_VIRQ test coverage Date: Tue, 27 Aug 2024 10:02:11 -0700 Message-ID: <0320b797787b8c314171b915660e6366d92da3bf.1724777091.git.nicolinc@nvidia.com> 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: DS3PEPF000099D5:EE_|CYYPR12MB8989:EE_ X-MS-Office365-Filtering-Correlation-Id: 61852039-ad32-494a-faf2-08dcc6ba18a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|7416014|376014; X-Microsoft-Antispam-Message-Info: M+0+Dn+T7/DD1x8hOL7GhbLNSjOj4c4H5mtsO25a6TFYgsH2pZ4QzfGXpHyPkMYUyJnE2HM8GJ3e9ifsFzjbm8g97xUKUBi2jjN5d15Hw1c2UBV7qav+PVF9ZFAKbmQv7J+QZWkzJDL1RVASo4HE3rToxvhCtebmJ1EbOGedpMkUB6YO0/Yh0rXPbfLEQsYbeKhHOBumf57nVteoSZbk8eU4yN7CjvaWPVeJtQVEPvIdoTSU6eQkbsEuIBKh7MUMVElMbGMxZPJdh1jQiITMyJcrEPd4X5gvW7efF3O+DHD9r6kMtBYwKQ3c4/MIfT14H8OIdYWvXd2G09oi7BxyveAvrf4vPzsYArPV0OXQEGgkQfqacXCYX1vKGtywMi6RGeam8QmyLy2O9NIBjwYrTWYL5AUnGUgaL6G6khS8Ntg8rY5ytt9ltTWtioFqSn0E19IGexJFOUvILC8VDravGLm/qP+JNIzWf/jDqeZWQSLJ8oxrDTEsmHjyL6HthuCF2oFflZDNFLaHUThUoCfH2/1Nm270AqsSwzU2ZxC/yGcRyhICSTiVemB4i4j3UV328paEWicpuerZUkdDm9vW+JuNZqpm/6VvR/3d0t902ZXcBO+klhy1uo/0Y6AtD2+efBFUiyQ1OKcrYVQmVdgY4R3muVzy2c6c5PmqJRaGBd2Tsenvr9TZ+CftVYWUeZfOc/BF2zRMYHyV+MPrjrJaF5VWWI/Oa3kvdrMkUfnVC4DgA+fiuNkMdAsmALrJQ2Z4Lu4gI8EOTEX5li5FTEWKSEiEXsyJE0ccOGUeHliRBXbYfp0fd95vSB+lcpsHSllGYBfVifOT3VbjFqS9WZ+K+dyj07+bd/ezDz2wBkzIvyFbTyUzP9KbjwXRpf6tEMA/ZKM48hYC1nYlxc1bsNd7fwMT9HhsFY4RILJpPMzJCi2UeyUPxl6Si6a5yT8rnrirsELYwhtvSw945M7sQEks5s6TWvAaSbqVUNqAG025L/rkPoDlS8MWVYb4x9X6QualtzHZFc4tuwDHRTAgXuLD8x7tz6ieb7pmszgCxQ9CU7+0DQ0n/kBzWyl6UaSeDifjl48Pn+reib04upw0Ry69hnGSb5iFfu5gY84POMINvnWRPpcUhBhC0B4cEQetj4sDSOtO8cYYPHs2eciPJ+D+OpttJcAMWA1IdtxLEHoxQt7gdDC8IkMcuKuwJSAX7ltf56DjhzHb6/XxglKXZnd6Ng+ltJOpdccU8nA+BccIbCIPkW+Uc7Xzj0r5FhLVz0B6ce9k4e67Mnyb0QpzeKYupsc3nlEPOGyJj3AReKsYIxHJmSe+VFU0xxQ758hlogbvMMogFENruOOVQQI49g5bGGMDwKwvPioQt8P0mhqoyX3TlXfH4K3L9qjQuz+tNkwJb/yBogj7JDzQAOJFSsZvNmTgcf+IM85WoG/VUOCiLeiRi29d/RxToVithrE1mQLO 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)(36860700013)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:55.7821 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61852039-ad32-494a-faf2-08dcc6ba18a3 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: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8989 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100304_445432_C27B74F9 X-CRM114-Status: GOOD ( 14.32 ) 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 an IRQ giving an idev ID, to test the loopback whether receiving or not the vdev_id that was set to the idev by the line above. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 11 ++++ tools/testing/selftests/iommu/iommufd_utils.h | 64 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 6f1014cc208b..11208f53fdce 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -564,6 +564,8 @@ TEST_F(iommufd_ioas, viommu_default) uint32_t nested_hwpt_id = 0, hwpt_id = 0; uint32_t dev_id = self->device_id; uint32_t viommu_id = 0; + uint32_t virq_id; + uint32_t virq_fd; if (dev_id) { /* Negative test -- invalid hwpt */ @@ -595,16 +597,25 @@ TEST_F(iommufd_ioas, viommu_default) sizeof(data)); test_cmd_mock_domain_replace(self->stdev_id, nested_hwpt_id); + test_cmd_virq_alloc(viommu_id, IOMMU_VIRQ_TYPE_SELFTEST, + &virq_id, &virq_fd); + test_err_virq_alloc(EEXIST, viommu_id, IOMMU_VIRQ_TYPE_SELFTEST, + &virq_id, &virq_fd); + /* Set vdev_id to 0x99, unset it, and set to 0x88 */ test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x99); + test_cmd_trigger_virq(dev_id, virq_fd, 0x99); test_err_viommu_set_vdev_id(EEXIST, viommu_id, dev_id, 0x99); test_err_viommu_unset_vdev_id(EINVAL, viommu_id, dev_id, 0x88); test_cmd_viommu_unset_vdev_id(viommu_id, dev_id, 0x99); test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x88); + test_cmd_trigger_virq(dev_id, virq_fd, 0x88); + close(virq_fd); test_cmd_mock_domain_replace(self->stdev_id, hwpt_id); test_ioctl_destroy(nested_hwpt_id); test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); + test_ioctl_destroy(virq_id); test_ioctl_destroy(viommu_id); test_ioctl_destroy(hwpt_id); } else { diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 0a81827b903f..9fec38f45e0e 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" @@ -888,3 +889,66 @@ static int _test_cmd_viommu_unset_vdev_id(int fd, __u32 viommu_id, EXPECT_ERRNO(_errno, \ _test_cmd_viommu_unset_vdev_id(self->fd, viommu_id, \ idev_id, vdev_id)) + +static int _test_ioctl_virq_alloc(int fd, __u32 viommu_id, __u32 type, + __u32 *virq_id, __u32 *virq_fd) +{ + struct iommu_virq_alloc cmd = { + .size = sizeof(cmd), + .type = type, + .viommu_id = viommu_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_VIRQ_ALLOC, &cmd); + if (ret) + return ret; + if (virq_id) + *virq_id = cmd.out_virq_id; + if (virq_fd) + *virq_fd = cmd.out_virq_fd; + return 0; +} + +#define test_cmd_virq_alloc(viommu_id, type, virq_id, virq_fd) \ + ASSERT_EQ(0, _test_ioctl_virq_alloc(self->fd, viommu_id, type, \ + virq_id, virq_fd)) +#define test_err_virq_alloc(_errno, viommu_id, type, virq_id, virq_fd) \ + EXPECT_ERRNO(_errno, \ + _test_ioctl_virq_alloc(self->fd, viommu_id, type, \ + virq_id, virq_fd)) + +static int _test_cmd_trigger_virq(int fd, __u32 dev_id, + __u32 event_fd, __u32 vdev_id) +{ + struct iommu_test_cmd trigger_virq_cmd = { + .size = sizeof(trigger_virq_cmd), + .op = IOMMU_TEST_OP_TRIGGER_VIRQ, + .trigger_virq = { + .dev_id = dev_id, + }, + }; + struct pollfd pollfd = { .fd = event_fd, .events = POLLIN }; + struct iommu_viommu_irq_selftest irq; + ssize_t bytes; + int ret; + + ret = ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VIRQ), + &trigger_virq_cmd); + if (ret) + return ret; + + ret = poll(&pollfd, 1, 1000); + if (ret < 0) + return ret; + + bytes = read(event_fd, &irq, sizeof(irq)); + if (bytes <= 0) + return -EIO; + + return irq.vdev_id == vdev_id ? 0 : -EINVAL; +} + +#define test_cmd_trigger_virq(dev_id, event_fd, vdev_id) \ + ASSERT_EQ(0, _test_cmd_trigger_virq(self->fd, dev_id, \ + event_fd, vdev_id)) From patchwork Tue Aug 27 17:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779896 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 96AE6C5472F for ; Tue, 27 Aug 2024 17:29:43 +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=SwmixdpYdExmjE4reTF8pmlfMGjG5l7D+jesZo8PH8w=; b=ogGnXQNwGp/UJXQnXzkbzdr//q cdiOIUVuvYW7qidE+vzKEY0hHZOffktXxFC/3PZwJ+bRDRngL0je0e97q8zuJxdkhkgVpL2lRVWdP HTyzUkUanQYk9XqgHaxUyoUML+wooTSBDho+ZyVaJcUZKh5NYcy0jvQOgqTjIwIcmaWHwsKQD4yQq OHjm8Qovn7XIFtiHXDVAC3qpcc8Hti44V+s8ZonuZig9uWl0fpKy/fULojTx/fB4051IlXnPhe6Oz uOMR8eiQfo22GT1nKzI39j9eAX62jOAmNzb/z+8S/Us5UZ5T9usyB+171UVaz3J9VqKLoDMlTE53G pWm3vP7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sj00Z-0000000CIGA-16to; Tue, 27 Aug 2024 17:29:31 +0000 Received: from mail-bn7nam10on20624.outbound.protection.outlook.com ([2a01:111:f403:2009::624] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizb4-0000000CCPX-0ltC for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:03:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P2YqaXJ1uZiP8vb2WZbVSV9xqU1gUdlW/9wRO5PrrdFGU4G0y6MgNropBkeUS4ppqfIAor2s4uVtaFoUWR5BWYMdh0R2pX6+c4oxeqc1oF0IhW7mEV9lE74BR0icUJvBZCS6uxLquHMi+V999Cj9rd9p/dKWYcHbf1acrHtwEgbPgAzyKR9YzP99vlaKwNkB8AEeLfRfJRTca7vHS4KUPogX4S0TJLabeMawCjrNOIHnHAQJUzQJfWkRRYuovl0clYZFONBM0CY1xn14nn7zJg+EpaWpDBj2Dui/D88ikq0QQ0YLuug3/tfZoLSNb1jKszpANsCc6GozlAwVu3EtAg== 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=SwmixdpYdExmjE4reTF8pmlfMGjG5l7D+jesZo8PH8w=; b=hfDdk9dO33AkpjeNmSucAwka9CZOtDLo+CZA6HVjw8bk+gs5N2WEjyqrMMZadFuL4KB2CpgXKj7Q6a+amOcf38NlRGz9bWgl5N046A1tC4BateOPiLVajkX7xY3KUBbhuRq9OtSnCLCj2d6ApV9Sk6zvvbrTM1yhwbuVHYGGL82E/rmb/PWrzwTCxt4LVSWmQaTZttprxQmlGobR+VZUIKRh9AXP/8SLv0oLYLtYgCaqMUQkzEHDHT3zfBbMJqEIcmxLhd1nsxI2JLf1XTmvu+l2fe865LZheJKMFOAo5lHWzEEEtvS0VSCn4MYwIZ4sh8fHRRs93mWLgJaGn7U1mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=SwmixdpYdExmjE4reTF8pmlfMGjG5l7D+jesZo8PH8w=; b=h9b4BuvPN2EGD220cDA0icw34Xo6UvnyU+UnLPwhgOQeVWMfW+8Gngt+oV0epZHQbCUwY2bjziZBZ6CgnjysufYtJQGBYmNwHwWElo2OohmI4ELUUkBFfZ9/Q5tM2MCXLTA5ZIDl6jF/vJW5PuHOKrc+RNhCAG0ANm+GV7KLBsdMZql/XtJ+KXKJ0e0NI8/EM+DLrHLzDAKd5auWUpqODs5HSEYPwAwynKWHMZYgkIzzUpslLFtgl+5GcFI8ejmuetEDvEItfNnIf5hGD/eSyo8iUzVdhSfA2k9spAuy8RagXN4WHiZksOoMhXE1COsqdtkcZAzQ8nOvR1gO0dXGoA== Received: from CY5PR13CA0093.namprd13.prod.outlook.com (2603:10b6:930:a::28) by DS0PR12MB7702.namprd12.prod.outlook.com (2603:10b6:8:130::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.24; Tue, 27 Aug 2024 17:02:56 +0000 Received: from CH2PEPF00000140.namprd02.prod.outlook.com (2603:10b6:930:a:cafe::56) by CY5PR13CA0093.outlook.office365.com (2603:10b6:930:a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.16 via Frontend Transport; Tue, 27 Aug 2024 17:02:55 +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 CH2PEPF00000140.mail.protection.outlook.com (10.167.244.72) 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:54 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:38 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:38 -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:36 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 10/10] iommu/arm-smmu-v3: Report virtual IRQ for device in user space Date: Tue, 27 Aug 2024 10:02:12 -0700 Message-ID: <8b93be1d913f9e227748de2d07e8540ddc2372ab.1724777091.git.nicolinc@nvidia.com> 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: CH2PEPF00000140:EE_|DS0PR12MB7702:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d8924ef-8abe-41cf-fc93-08dcc6ba180c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: zgqYggyaapJTIVH/PLDs6eYu41EAbuhBXNnyWrOpOopT151OtyUYxzbi9SG5MO6KRhkSQdKh3kv7VLR1ojGmJLP/0NaP8exojuOBWVDmyvSKHaAzwowfMtGthvJi9YX5GKTd1XorVfui0T/hx5ZPI8jcIF9/2UWuaY107/QjQjKjNexSTS5eMFwHfFyleygomqkxOfRX2MLixgWcUjQSbT2Ibq3Pyu3LJU7ks/ZwhsXTHWXz8putblmoZ/z0xhF/PI8JtBqobtEekBdym/3YZeonX1yX/iIsA9G8jHpgG0JI1rTMzas0T9Ge46TOot2RreFDB/O5dbQ2z6UI6GSeG+ceZrmxeSGJpndgZXC9bpp0hzuDTYQCXIPQ1a89B+4s7/Cuihti2dPET8JLKeM5nMhqewB4MhEFlyL/YQHfy0km1l7oWSc0taE6lxAr9yzle8L505aFzOL4c0WvtyfCICDQpD866ynuTgi3f8YrODMEgH2Ut25fC9C0upTEKb7r9FfYuyoUOrO8Tswdhfs1zle9jyeo673ddB3BBXRH+Yhg9CRy/RRlwYxEv2qBC6sArxvGXIGDySo4TT42lBIDaF+g0SQzzFDYM1dAbK4C8dfZR2S1E4R3Fo1sEH15WX9Hc+8esLi4gcEirdES0YR5TiDld+uv5apAVkT7lTmlAiwLnsr6MyMHcbPmsyDMSfUMUTN/lDUC8gaMr9//gDOSkxYeN9qi1NPO3f5qQmCYKhM4OsCpY67E+A3FApfN7dDMaZtWoYEYBzjTELUwTBe4LEntgRnsyfV7Xp2Ksojk4+UJyumNS9QOkYjnOXavzPO+7r4C9RD7Tokg9nn4bvc25kJ6ufudp8/lz9axEP4M4eO5P8l6WRaigCqPADdCOFeyOLzCUY/WZ+iBj6H3yaL4UUDYmW61znvPyyZbKVnPOe9GuQcv+IY1eDDynVFJ7qark6fUwqKEOzNUnbDN8KMS3/syIAM1OJz0CZldgKtfNaUSZKT1DNM7pK7BgRspjhXGWRXsKcueIU8on4VbJaJoJnppm6JlFpiJFoG8wDxviswW16OmxTJJHPpL4MXws+i4SlW3+7kFHTb3e3D4goiE00avfCcAHxhkW5cvABnXNHoklZnxAS/wkfwYCk149XG4+uy2JGbhHqIf+/wH30lFAbL3aDx4W0xj/70cTplZqO4viD98bqJCham23ZI9wZZdC5jwbfnGGqtaVNzbDy9eLeNvhFfaoPO/EgsDek9rJVuf4xyA6pokaDn9tLTQ4lTg2MrLh6qIb1z+FeINX/uHpd/zOkVweORSbz8Be3r3eWz5xDIkEACp0UxgcreXLDogNevuFuOItTO/GZqaB4ek9ay44KuA/U/h6B2dFhDOlJJf43oobUf1fsSp4jHr6tws+xRNcsLhYO7wqvzPQ2RpR9lG9jnIhLEFQWVIh5ZyOLJzZaAmg/lJGSyGDHepo7fU X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:54.8238 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d8924ef-8abe-41cf-fc93-08dcc6ba180c 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: CH2PEPF00000140.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7702 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100310_330687_1B872565 X-CRM114-Status: GOOD ( 20.91 ) 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 a hardware event or IRQ, via the VIRQ of VIOMMU infrastructure. Implement the set/unset_vdev_id viommu ops, to take control of vdev_id's lifecycle. Lock it properly so the threaded IRQ handler can read out the viommu pointer and the virtual SID, to call iommufd_viommu_report_irq(). Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 109 +++++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + include/uapi/linux/iommufd.h | 14 +++ 3 files changed, 97 insertions(+), 28 deletions(-) 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 ad43351145d0..28daa0b253c6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1810,6 +1810,7 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) { int ret = 0; u32 perm = 0; + struct iommu_domain *domain; struct arm_smmu_master *master; bool ssid_valid = evt[0] & EVTQ_0_SSV; u32 sid = FIELD_GET(EVTQ_0_SID, evt[0]); @@ -1830,41 +1831,59 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) if (evt[1] & EVTQ_1_S2) return -EFAULT; - if (!(evt[1] & EVTQ_1_STALL)) - return -EOPNOTSUPP; - - if (evt[1] & EVTQ_1_RnW) - perm |= IOMMU_FAULT_PERM_READ; - else - perm |= IOMMU_FAULT_PERM_WRITE; - - if (evt[1] & EVTQ_1_InD) - perm |= IOMMU_FAULT_PERM_EXEC; - - if (evt[1] & EVTQ_1_PnU) - 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 = FIELD_GET(EVTQ_1_STAG, evt[1]), - .perm = perm, - .addr = FIELD_GET(EVTQ_2_ADDR, evt[2]), - }; - - if (ssid_valid) { - flt->prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; - flt->prm.pasid = FIELD_GET(EVTQ_0_SSID, evt[0]); - } - mutex_lock(&smmu->streams_mutex); master = arm_smmu_find_master(smmu, sid); if (!master) { ret = -EINVAL; goto out_unlock; } + domain = iommu_get_domain_for_dev(master->dev); + + if (evt[1] & EVTQ_1_STALL) { + if (evt[1] & EVTQ_1_RnW) + perm |= IOMMU_FAULT_PERM_READ; + else + perm |= IOMMU_FAULT_PERM_WRITE; + + if (evt[1] & EVTQ_1_InD) + perm |= IOMMU_FAULT_PERM_EXEC; + + if (evt[1] & EVTQ_1_PnU) + 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 = FIELD_GET(EVTQ_1_STAG, evt[1]), + .perm = perm, + .addr = FIELD_GET(EVTQ_2_ADDR, evt[2]), + }; + + if (ssid_valid) { + flt->prm.flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; + flt->prm.pasid = FIELD_GET(EVTQ_0_SSID, evt[0]); + } + + iommu_report_device_fault(master->dev, &fault_evt); + } else if (domain && domain->type == IOMMU_DOMAIN_NESTED) { + mutex_lock(&master->lock); + if (master->vdev_id) { + struct iommu_virq_arm_smmuv3 virq_data = + *(struct iommu_virq_arm_smmuv3 *)evt; - iommu_report_device_fault(master->dev, &fault_evt); + virq_data.evt[0] &= ~EVTQ_0_SID; + virq_data.evt[0] |= + FIELD_PREP(EVTQ_0_SID, master->vdev_id->id); + + iommufd_viommu_report_irq(master->vdev_id->viommu, + IOMMU_VIRQ_TYPE_ARM_SMMUV3, + &virq_data, sizeof(virq_data)); + } + mutex_unlock(&master->lock); + } else { + /* Unhandled events should be pinned */ + ret = -EFAULT; + } out_unlock: mutex_unlock(&smmu->streams_mutex); return ret; @@ -3750,6 +3769,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; + mutex_init(&master->lock); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); @@ -3802,6 +3822,7 @@ static void arm_smmu_release_device(struct device *dev) arm_smmu_remove_master(master); if (arm_smmu_cdtab_allocated(&master->cd_table)) arm_smmu_free_cd_tables(master); + mutex_destroy(&master->lock); kfree(master); } @@ -3937,6 +3958,36 @@ static int arm_smmu_def_domain_type(struct device *dev) return 0; } +static struct iommufd_vdev_id * +arm_smmu_viommu_set_vdev_id(struct iommufd_viommu *viommu, struct device *dev, + u64 id) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct iommufd_vdev_id *vdev_id; + + vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); + if (!vdev_id) + return ERR_PTR(-ENOMEM); + + mutex_lock(&master->lock); + master->vdev_id = vdev_id; + mutex_unlock(&master->lock); + + return vdev_id; +} + +static void arm_smmu_viommu_unset_vdev_id(struct iommufd_vdev_id *vdev_id) +{ + struct device *dev = iommufd_vdev_id_to_dev(vdev_id); + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + + mutex_lock(&master->lock); + master->vdev_id = NULL; + mutex_unlock(&master->lock); + + /* IOMMUFD core frees the memory of vdev_id */ +} + static int arm_smmu_viommu_cache_invalidate(struct iommufd_viommu *viommu, struct iommu_user_data_array *array) { @@ -3977,6 +4028,8 @@ static struct iommu_ops arm_smmu_ops = { .iova_to_phys = arm_smmu_iova_to_phys, .free = arm_smmu_domain_free_paging, .default_viommu_ops = &(const struct iommufd_viommu_ops) { + .set_vdev_id = arm_smmu_viommu_set_vdev_id, + .unset_vdev_id = arm_smmu_viommu_unset_vdev_id, .cache_invalidate = arm_smmu_viommu_cache_invalidate, } } 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 6930810b85cb..5d20a67683e6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -788,6 +788,8 @@ struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; struct arm_smmu_stream *streams; + struct mutex lock; + struct iommufd_vdev_id *vdev_id; /* Locked by the iommu core using the group mutex */ struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index f9ec07efed8d..1dc2c0b05af7 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -956,9 +956,23 @@ struct iommu_viommu_unset_vdev_id { /** * enum iommu_virq_type - Virtual IRQ Type * @IOMMU_VIRQ_TYPE_NONE: INVALID type + * @IOMMU_VIRQ_TYPE_ARM_SMMUV3: ARM SMMUv3 Virtual Event */ enum iommu_virq_type { IOMMU_VIRQ_TYPE_NONE = 0, + IOMMU_VIRQ_TYPE_ARM_SMMUV3 = 1, +}; + +/** + * struct iommu_virq_arm_smmuv3 - ARM SMMUv3 Virtual IRQ + * (IOMMU_VIRQ_TYPE_ARM_SMMUV3) + * @evt: 256-bit ARM SMMUv3 Event record, little-endian. + * + * StreamID field reports a virtual device ID. To receive a virtual IRQ for a + * device, it must set its virtual device ID via IOMMU_VIOMMU_SET_VDEV_ID. + */ +struct iommu_virq_arm_smmuv3 { + __aligned_u64 evt[4]; }; /**