From patchwork Tue Dec 3 22:10: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: 847143 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2077.outbound.protection.outlook.com [40.107.243.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39C051DF27E; Tue, 3 Dec 2024 22:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263861; cv=fail; b=GgWRjhjz9aMB86K1dbimmIas7V3os2wsjM5e2SdbOtUzDyZJdf2UoVrGqymTlP/JTBb7EXqvFzLobZ5eDx/JqzwaopEVIEU+v9GpEDn6KRcct1ALwoKK+iAaAD8EPRnnba2I7ePcGWTZKmIW7DCGxXg/NSJvXAR+cstDGZcTPWQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263861; c=relaxed/simple; bh=pMxFHTf0j2twpCDHDDsiqVu+FMmvpPSlFfLEovtqtv4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nio1uUyMmtwyuB8h+WsnYxqKEgxFRyNFjrLVy4304RNJGsxHt2uK+WfKsj0Lbb6MOFwqWpEc4Eq2d9dPN+hEOjlXprzosp5A20hRmVyKHPXkg3Ne+J/4SCmhGFLZEGC2HGVAsYV75k20GJrIFJEhmB2DgSPvWrZFoLB9k9a+lGI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=nMxAcnz2; arc=fail smtp.client-ip=40.107.243.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="nMxAcnz2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AEmBtV3i3NaVYNjrm/YYdFYJKXXO1HqMApdgT0nGJHMosVyI/fEse3I2Wt7NB02SfWzMb1dAVDXbuohNQrDUyVu51Rqf10J2Q4+Bj+raUYbRvLtJ86KnWezEvHczYnuX0qp6pmdp86xCuubUJTI2roIpwgLTgfMmXGneZl3dOFPS5nYlMpbu/jyxIVTx1HO8aM5tJucNbEmtmeWjBYxJSRcysoLikayAkW5h1rqaYrFnWD+wjNZ5QdvVephecCLFhi/yCEqJpz9IBCyYW7jzaSAya7uyIreA1wnTwMDY4oa2wQuPM3Hvy1Q92ctD+lAR9DEwW4SSAlm0TLPRh1mJYw== 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=ph+GJt+zDR7jitOy7Mc9T0fRmELWyhFVLN6UN79xO34=; b=MnmkW0NVIHOCW0RAdmypGm9eTCYZww6MLhQGrWrXbz1VkRC5uvbjnOFmhIFFOX155FWz8m9hkR11HV7itIndm4RT/IDFuliU3tMupG8fu71/jzX54eprI38dMRoNHrsn2word3lAsZpLiFQmZAbYFdixRK9No1496NmjasnX6BuvgHiNy3KRHFi8/McmOgak+D8KXwOEz2icEwiSVZXA8glGoylLaCfcWAKQxb3on7ski4FnjY3o2amgm16ezuTqKsSIs0Gph+ANnKTA6pYuEVcD8Dh0ndMFOa78sxQxpbC7qjnhAd6uaAR3yZ4v2o6hDTSrqbOQZZffOI26reRc+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=google.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=ph+GJt+zDR7jitOy7Mc9T0fRmELWyhFVLN6UN79xO34=; b=nMxAcnz2MDC2Dr0cL2gKuU8S0anbdKc1BMW+VxfhkpJ+gbee+UrSq9gv4d629Km+58msc8a/4a7woKSzbY8WprDzJOQciIGD28I7+LA7UslKqLoJlSegk/4e6pE/n7HxVAJQf/amtNWKnwyxOjl2TQmO/IseURBfNQA/SWMaIwTFG/Rfg6UVDAwDqyjVfCJ2wsGBdF8Xu0L/3yh0ia/hrrd2JgjUcvB7VwTZEoTv+aMQHDslKVJ+kYQh+mu96dzaVcZ8WuXYKUfmDyMQuDPJFAjlph+kwZebgh64v1k7O30sd/f7at2mKsuqn7BluCp5AF6OIwJNuTnMMLwrYVPahQ== Received: from BL1PR13CA0192.namprd13.prod.outlook.com (2603:10b6:208:2be::17) by CY5PR12MB6369.namprd12.prod.outlook.com (2603:10b6:930:21::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 3 Dec 2024 22:10:55 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::32) by BL1PR13CA0192.outlook.office365.com (2603:10b6:208:2be::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.8 via Frontend Transport; Tue, 3 Dec 2024 22:10:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:10:54 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:35 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:35 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:34 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 02/13] iommufd/fault: Move iommufd_fault_iopf_handler() to header Date: Tue, 3 Dec 2024 14:10:07 -0800 Message-ID: <137e3357f00b30a08c2b49c00b968a88af8cb5d1.1733263737.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|CY5PR12MB6369:EE_ X-MS-Office365-Filtering-Correlation-Id: bd23e13f-549a-4f2c-94ab-08dd13e75b53 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: A6bjSb9AgjXCF6UxTP0/rJSWArrQCx1Wvxyc0u9kgr4oZmhzMPTjZpT98Uqp7Rouf9n7WcDY2ShFeKP9iZfBHz7fGPSz6ODuAAXqhltUIDIPQyFh7o3f0NG3zjGuao4/ALDnuEKTS9EKZca0CmK+ep3WRoTOqMswDTmgHiXekBTr2uFLlk5HRQ5lXxyJOR5iFciPO0Nathp/Vz+GuxDhO6is8YmmLuI8hhhDctshNJJCDPPFWtVDWmmYtQf3TG202rlppO1w9vfdagiL5Q7VauhYjf6bl1r6VXR298YZ5cjBjdJwxmnyhxqckNe6ybKAeJ1RNgG+HBZptRfDPYC31iLIGRNXK7UUL4lCIqcSgxQ9wGoOhEYt+W0B8hdf36l/xc/mOe1tRBzbePw99gcfMMFub2LpVmXRmQOv9bTeTF0Y8BStOap2CoVXNp1sOuJrEqTpqoHRY5L4eFWjd/uF7uXHXrNtynekWDnHtop7qxcwGVQfSsc1MOuXQZOJIVdS3jXxKdtlHjgPji9//qmLGgIurbJQGXsQbPp7JvVsoArFJsYyzX+JEkgZoCZm2VBWMA7XZNunkKtqX/h7J/gb/VdGTPfs9lEsZB3ET5xOkuSq3HHJAEYucfKZkUWAK22XqkOqiZR0DHEbIfV4izdJW4KHxujR8ip/kGaaWNLj0QFKSjBDVPUJyvDRhnfRJUDEAYrx1UAdi6LZl5ygqrWok5RS1tkhpXNpFfAS/lsX5EqMc3J0i1RygfsYeno0h7tzXRPEn9JntpYdYtqCNgC35H5Zqdsuu6srerX/Md8aGyHbR9ChmlszuPOvyFzenvQLPbQ0gbgbWmvZWWyG+2phyJQg+11EJz3TLd7nS3rcPbEhSaeAdjF42WzOzu11vGrs/O0HngrF9ZNkiglwCpx0f7zWptbOJ0qAYaOR09ZiUXp0BZ1XW0TRSg/wv0qyhyMLMCFHvTUVw+h8xyVWtQFrmYKARDwhtwkaMw4Yf7pKlB9Pxldc9bv080JMJljT7ZiLH53eVgydziF6H1TYyALT1kgWBW6hINkuUgoPjnQFY6vi31g23uCqMhxF5RunZA0wMcoUaGMzFsWZ3WkE9MW75Ga7qt87vFbnW/iuenzNLW4Ab+qSft0E6eQX8hVYpQMsdH3fYrFK6NFbIfFmaeLvbUCHQKnKw7R/WD+NEqPg6JMVd9OX75q3eL/W4/RCveX87WGYdU7NC4dAu9+ymLm4GA7qTzA+VtKqV7q+zNFO5HzAy90DB8kCA1umQVYzPWIoO0618QxTUPrFi+wO457RZWsKqy7eg7PUiq7GKSRC8uMmmypx9/D4vDQMxnYTllYOtMTlEbypUFI8t4fqQTtWTqu9anmRbGKUixa/EQoNGM1yDvaIHDY3pQtHFk62lf/s4MAN81vovZc78l2qXMtVR2iJI1UVk8nCpkEM156y7l4xFuQfrv28HiUOiSnlk4GR X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(7416014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:10:54.5180 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd23e13f-549a-4f2c-94ab-08dd13e75b53 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6369 The new vIRQ object will need a similar function for drivers to report the vIOMMU related interrupts. Split the common part out to a smaller helper, and place it in the header so that CONFIG_IOMMUFD_DRIVER_CORE can include that in the driver.c file for drivers to use. Then keep iommufd_fault_iopf_handler() in the header too, since it's quite simple after all. Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/iommufd_private.h | 20 +++++++++++++++++++- drivers/iommu/iommufd/fault.c | 17 ----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index b6d706cf2c66..8b378705ee71 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -451,6 +451,17 @@ struct iommufd_fault { struct wait_queue_head wait_queue; }; +static inline int iommufd_fault_notify(struct iommufd_fault *fault, + struct list_head *new_fault) +{ + mutex_lock(&fault->mutex); + list_add_tail(new_fault, &fault->deliver); + mutex_unlock(&fault->mutex); + + wake_up_interruptible(&fault->wait_queue); + return 0; +} + struct iommufd_attach_handle { struct iommu_attach_handle handle; struct iommufd_device *idev; @@ -469,7 +480,14 @@ iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) int iommufd_fault_alloc(struct iommufd_ucmd *ucmd); void iommufd_fault_destroy(struct iommufd_object *obj); -int iommufd_fault_iopf_handler(struct iopf_group *group); + +static inline int iommufd_fault_iopf_handler(struct iopf_group *group) +{ + struct iommufd_hw_pagetable *hwpt = + group->attach_handle->domain->fault_data; + + return iommufd_fault_notify(hwpt->fault, &group->node); +} int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev); diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 87c811b9c0d0..5694b04a48bd 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -433,20 +433,3 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) return rc; } - -int iommufd_fault_iopf_handler(struct iopf_group *group) -{ - struct iommufd_hw_pagetable *hwpt; - struct iommufd_fault *fault; - - hwpt = group->attach_handle->domain->fault_data; - fault = hwpt->fault; - - mutex_lock(&fault->mutex); - list_add_tail(&group->node, &fault->deliver); - mutex_unlock(&fault->mutex); - - wake_up_interruptible(&fault->wait_queue); - - return 0; -} From patchwork Tue Dec 3 22:10: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: 847142 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2048.outbound.protection.outlook.com [40.107.236.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1351720A5D4; Tue, 3 Dec 2024 22:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263864; cv=fail; b=KaMUsq/YsDZ9NIhRwd0x//nCevN9xhl24W3cXmNsVntuw3tvBw5WCUDjKOONkRA4UFL9z6TKSljIvWQS5/N0bB7vY4RY8b63fmF1OyHpHVcGMUbmb8N5Va6bj/9YMRFj0DL+RzCcwpXTRgjHgDPa38z1Bi7/NemT2ZVY9UyGQrE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263864; c=relaxed/simple; bh=HCRB99QAkZ1K7y1148EjmSAEQoBd9W96RAMSUUboBFg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OoXrisobAYIBBGuHCnzgapenDpXy7AUbKy96rLvtp79AmItOx6yXPd03nevunB0kXJrXXBEwUVYdM2ka2AlnzxJUNK6UXSzm92RHQXALw7p2YoH+QsDwTKbgQGn4yqSfxcPcXEV1wwN1os1o/AGG2+FYLdhj4XUoBRqMuNZY9VI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gCR8vFH5; arc=fail smtp.client-ip=40.107.236.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gCR8vFH5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eOPWdwJmBencW9/CAsDxruxIo4ZqKRzqlB8opWP3VcugMhKDnHpmqKYweH5PpAPob6YRlLp6phM+v+3b7spiqjXqEJu4gm/OI73AUTaKa2qUMIFItc6m6Jjni/kePQmArk1voSctbhffKK05ZGVtLaxoj5UUQAmYpkpgAnpCGOIxGQVh9ObGKdayqezJ2S84akVP7ngBf02fantNijt2rn4Aa26CvnjBFwZ935KBSNN494KkvtkCKXcz6T0nmlVCieDrARQQmOVSTCiVdCQ1aRbLTt8KF//1txvBU6AF3S4EpDeZC26KYMAvHsE7Z5FiGLl2/Kast5RTS+ZYc0bqJQ== 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=fw2NtZj6iEimVhBoDkU0gUCqYdMiFNJwnKjemaTIpcc=; b=c3h14luBGym47H6rIkz/u0DyaLbK2x9M1ClI2z0WkJQNCihm3s57NOuxXth9tm0Ag/OBLtY2vMxV44n/a693uyauQiFom9941BA3LxL5ZTx7W+k0i2w36YihLfHken6uMkwXbmeDjwrx2D2jrhTBYudaJu5C8rrautfD4SLILfn5OtayCtsCM+YQJEeYgvBkNicj2Qb9KtDXwDLUtfjVdUOO5R48oq2nckRXCq8hUgwQGS2SubnIcGnC7IXq9RRxrQGB6GcAWVLzt/CGjMq8SqI3FXNMOzkIkCENoIv98JK83y5P6F7NvL0p4ZauUXgJt+G33T16jlJhKMDgIwsqsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=google.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=fw2NtZj6iEimVhBoDkU0gUCqYdMiFNJwnKjemaTIpcc=; b=gCR8vFH5bJ6UiCvLExxGUAxU8zrEpG/p0HEjLjq2T3UArJCzz5HjGd/VZoJFGz35in4lTDtOloMX8fgAL5D09QR66MYwyDavouNOjokC0Ggu9ddvaSufBIuavF1G6lLoWULU3WBqlkTdQv+bXdvGdG1kVdfjcK839cwqs49wA4IRddRDJR2g+VjNMMdR4Kht9f4H2bgyDdF9VNninef5Wh9p7W38FARkmj1O4OBxAWUfrV9Zta3MoMlyBHyLKk/Z46muxzHUilIrbpUT02DOQHnViLOcrW9qJ/OTNTf7h8HOd9UfrDUtj+1YbTzZTsP6zECPV5YukV8ZC18YcbtX2g== Received: from BL1PR13CA0187.namprd13.prod.outlook.com (2603:10b6:208:2be::12) by PH8PR12MB7181.namprd12.prod.outlook.com (2603:10b6:510:22a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.15; Tue, 3 Dec 2024 22:10:57 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::6f) by BL1PR13CA0187.outlook.office365.com (2603:10b6:208:2be::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.8 via Frontend Transport; Tue, 3 Dec 2024 22:10:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:10:57 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:40 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:39 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:38 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 05/13] iommufd: Add IOMMUFD_OBJ_EVENTQ_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC Date: Tue, 3 Dec 2024 14:10:10 -0800 Message-ID: <7f5f7adc2493c7bca7edf76ca15b377c8dc0d397.1733263737.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|PH8PR12MB7181:EE_ X-MS-Office365-Filtering-Correlation-Id: 82520c3a-470e-427b-ab18-08dd13e75ced 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: iFGgXg2xS+AVIV4XsUg/DCdDJuijDiGAU4Jv5M9YR1kyrcf6saZ4+C8XAd5XvAp105UGgl60yzjqk6gD+bhe0U4xge1SjPqqJatX97xeJJjWb5LDt5SkiR5Al6hCOfZgiLtIJ/V+BPL0YrOFY0fV10FtC1nW0PvP8hwtaZRVkiGwGBcFmZc8nYmGPBRkMT4Kk3w/OkrQuXf064Q2mA82Civ0onIyRO1yUFuX4lcqpN1MzrIT3tmiMazjJweWCSkaTgEYaCt1sbepUYTKnJPzh+YJaPhVedRCGbvKdO/hdDkl8cwnMPp7rxzXpcNpSm403YGSwRagZ7t9ZqCixU0hnLW+2kDHTVt3f5zIzdCIB3+ZZNi+taXSX2MxcPy97428W+zH8XAYbr1Wrtwqd01pMKUd257NOW46olNCwxKJwZcFcGkLItjpTgABU4heDpHwlWjG8+DDwQXlVPV0SaitZ7t9fx62PGHlQaXiSVDTH5oNou16e0O1NsNsfnmA4UCeGd0CnMzO+CCrEBFWhSqBWXBGFDFcgT92PqTcQhRxFC1TeHHVUk0mTwp567KMqY9Lhnu76L2ChhC+ZPOPOfYQibYSCPQf39y+PeBNMsvendafGbttmd6kD4uOqA0evCM6Z1gOiiSQCNrba3XbxjWztnhff2LNsTsAQxB1rAuvfeXMnUX8C0a/yf9A9Y48A8cgPGR7MdSbjnrZvNSBAaoUvR2KlVghRephgyx+fYeAr3CfOleGmB2Z7tS7lGzz4cppyi9kug5EA92AtkFZKUmVpyiFGUa3pcqQkepihWAzyQH9x3K2AXK95A/X00AdKM7lhJIpYb9OC0U+CxfwBdQMSVi4ZgQPiDZ/SJEPkJRDFJPdFIaTvf2maxh+v6bJiZ6MyLNCcmDJDLVwx++I3x4C1BDOirzHKu/DoHYOx3i7v7A+fc2iKuXD7wgHT59Y0ELjxtJI08HEM+FXc7heqbMYxLu6uuxJWCfjdje5GIqnbkBU8BxmT5dpXRnVTpewrQPuPaLyvU0RkporsQP6M+185WladaBBktrUnApcaFEhFmXsvly0B+D8Tps4rAbvbY/nv83V8ieS7k62gDCCze2bzo+eh+kGkLjyI6hVrny3mzZMIKPrNFglxWBA2bn3cg3WaNObNcUuMF6UyG4JjhDmmYzXN1F9HEJCK2PcDsTNP8UkGS1gGcGEalNHRNgau/RuGNrWyFIqxFHM4giPXl+wpoNaTohJDRWFreeRlBdFHEGeZZV4Ct4hjN9uJ8BXlMWx2Y6xg7RphxErm1HE7ICaFpQtgC7InpU4q4ON0XSR7b4lCTCtwmSdlxMphjEd9wIJdfT3EQvhbOF8q26X3lo5uzcvNS5/jQOhmquQdjkodFZedVw/hv5KLIAHeH+NQsvyn9jvCbMBpbcrXYYVkfcsGYVjWekwvQOVHk3voXUqEJuSk6XNob6dyyDp//giNPdO X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:10:57.2056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82520c3a-470e-427b-ab18-08dd13e75ced X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7181 Allow a vIOMMU object to allocate vIRQ Event Queues, with a condition that each vIOMMU can only have one single vIRQ event queue per type. Add iommufd_eventq_virq_alloc with an iommufd_eventq_virq_ops for this new ioctl. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 59 ++++++++++ include/linux/iommufd.h | 3 + include/uapi/linux/iommufd.h | 31 ++++++ drivers/iommu/iommufd/eventq.c | 138 ++++++++++++++++++++++++ drivers/iommu/iommufd/main.c | 6 ++ drivers/iommu/iommufd/viommu.c | 2 + 6 files changed, 239 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 1c9a101cc435..fd0b87707967 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -548,6 +548,51 @@ static inline int iommufd_hwpt_replace_device(struct iommufd_device *idev, return iommu_group_replace_domain(idev->igroup->group, hwpt->domain); } +/* + * An iommufd_eventq_virq object represents a queue to deliver vIOMMU interrupts + * to the user space. These objects are created/destroyed by the user space and + * associated with vIOMMU object(s) during the allocations. + */ +struct iommufd_eventq_virq { + struct iommufd_eventq common; + struct iommufd_viommu *viommu; + struct workqueue_struct *irq_wq; + struct list_head node; + + unsigned int type; +}; + +static inline struct iommufd_eventq_virq * +to_eventq_virq(struct iommufd_eventq *eventq) +{ + return container_of(eventq, struct iommufd_eventq_virq, common); +} + +static inline struct iommufd_eventq_virq * +iommufd_get_eventq_virq(struct iommufd_ucmd *ucmd, u32 id) +{ + return container_of(iommufd_get_object(ucmd->ictx, id, + IOMMUFD_OBJ_EVENTQ_VIRQ), + struct iommufd_eventq_virq, common.obj); +} + +int iommufd_eventq_virq_alloc(struct iommufd_ucmd *ucmd); +void iommufd_eventq_virq_destroy(struct iommufd_object *obj); +void iommufd_eventq_virq_abort(struct iommufd_object *obj); + +/* An iommufd_virq represents a vIOMMU interrupt in an eventq_virq queue */ +struct iommufd_virq { + struct iommufd_eventq_virq *eventq_virq; + struct list_head node; + ssize_t irq_len; + void *irq_data; +}; + +static inline int iommufd_eventq_virq_handler(struct iommufd_virq *virq) +{ + return iommufd_eventq_notify(&virq->eventq_virq->common, &virq->node); +} + static inline struct iommufd_viommu * iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) { @@ -556,6 +601,20 @@ iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) struct iommufd_viommu, obj); } +static inline struct iommufd_eventq_virq * +iommufd_viommu_find_eventq_virq(struct iommufd_viommu *viommu, u32 type) +{ + struct iommufd_eventq_virq *eventq_virq, *next; + + lockdep_assert_held(&viommu->virqs_rwsem); + + list_for_each_entry_safe(eventq_virq, next, &viommu->virqs, node) { + if (eventq_virq->type == type) + return eventq_virq; + } + return NULL; +} + int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); void iommufd_viommu_destroy(struct iommufd_object *obj); int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd); diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 7ad105ab8090..40cc9bbb1d24 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -32,6 +32,7 @@ enum iommufd_object_type { IOMMUFD_OBJ_IOAS, IOMMUFD_OBJ_ACCESS, IOMMUFD_OBJ_EVENTQ_IOPF, + IOMMUFD_OBJ_EVENTQ_VIRQ, IOMMUFD_OBJ_VIOMMU, IOMMUFD_OBJ_VDEVICE, #ifdef CONFIG_IOMMUFD_TEST @@ -93,6 +94,8 @@ struct iommufd_viommu { const struct iommufd_viommu_ops *ops; struct xarray vdevs; + struct list_head virqs; + struct rw_semaphore virqs_rwsem; unsigned int type; }; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 34810f6ae2b5..d9319f5b7c69 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -55,6 +55,7 @@ enum { IOMMUFD_CMD_VIOMMU_ALLOC = 0x90, IOMMUFD_CMD_VDEVICE_ALLOC = 0x91, IOMMUFD_CMD_IOAS_CHANGE_PROCESS = 0x92, + IOMMUFD_CMD_VIRQ_ALLOC = 0x93, }; /** @@ -1012,4 +1013,34 @@ struct iommu_ioas_change_process { #define IOMMU_IOAS_CHANGE_PROCESS \ _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_CHANGE_PROCESS) +/** + * enum iommu_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: virtual IOMMU 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 virtual IRQ + * @out_fault_fd: The fd of the new virtual IRQ. User space must close the + * successfully returned fd after using it + * + * Explicitly allocate a virtual IRQ handler for a vIOMMU. A vIOMMU can have + * multiple FDs for different @type, but is confined to 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 diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c index 3674961a45c2..cf07b3c21f1e 100644 --- a/drivers/iommu/iommufd/eventq.c +++ b/drivers/iommu/iommufd/eventq.c @@ -346,6 +346,75 @@ static const struct iommufd_eventq_ops iommufd_eventq_iopf_ops = { .write = &iommufd_eventq_iopf_fops_write, }; +/* IOMMUFD_OBJ_EVENTQ_VIRQ Functions */ + +void iommufd_eventq_virq_abort(struct iommufd_object *obj) +{ + struct iommufd_eventq *eventq = + container_of(obj, struct iommufd_eventq, obj); + struct iommufd_eventq_virq *eventq_virq = to_eventq_virq(eventq); + struct iommufd_viommu *viommu = eventq_virq->viommu; + struct iommufd_virq *virq, *next; + + lockdep_assert_held_write(&viommu->virqs_rwsem); + + list_for_each_entry_safe(virq, next, &eventq->deliver, node) { + list_del(&virq->node); + kfree(virq); + } + + if (eventq_virq->irq_wq) + destroy_workqueue(eventq_virq->irq_wq); + refcount_dec(&viommu->obj.users); + mutex_destroy(&eventq->mutex); + list_del(&eventq_virq->node); +} + +void iommufd_eventq_virq_destroy(struct iommufd_object *obj) +{ + struct iommufd_eventq_virq *eventq_virq = + to_eventq_virq(container_of(obj, struct iommufd_eventq, obj)); + + down_write(&eventq_virq->viommu->virqs_rwsem); + iommufd_eventq_virq_abort(obj); + up_write(&eventq_virq->viommu->virqs_rwsem); +} + +static ssize_t iommufd_eventq_virq_fops_read(struct iommufd_eventq *eventq, + char __user *buf, size_t count, + loff_t *ppos) +{ + size_t done = 0; + int rc = 0; + + if (*ppos) + return -ESPIPE; + + mutex_lock(&eventq->mutex); + while (!list_empty(&eventq->deliver) && count > done) { + struct iommufd_virq *virq = list_first_entry( + &eventq->deliver, struct iommufd_virq, node); + + if (virq->irq_len > count - done) + break; + + if (copy_to_user(buf + done, virq->irq_data, virq->irq_len)) { + rc = -EFAULT; + break; + } + done += virq->irq_len; + list_del(&virq->node); + kfree(virq); + } + mutex_unlock(&eventq->mutex); + + return done == 0 ? rc : done; +} + +static const struct iommufd_eventq_ops iommufd_eventq_virq_ops = { + .read = &iommufd_eventq_virq_fops_read, +}; + /* Common Event Queue Functions */ static ssize_t iommufd_eventq_fops_read(struct file *filep, char __user *buf, @@ -472,3 +541,72 @@ int iommufd_eventq_iopf_alloc(struct iommufd_ucmd *ucmd) return rc; } + +int iommufd_eventq_virq_alloc(struct iommufd_ucmd *ucmd) +{ + struct iommu_virq_alloc *cmd = ucmd->cmd; + struct iommufd_eventq_virq *eventq_virq; + struct iommufd_viommu *viommu; + int fdno; + int rc; + + if (cmd->flags || cmd->type == IOMMU_VIRQ_TYPE_NONE) + return -EOPNOTSUPP; + + 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_eventq_virq(viommu, cmd->type)) { + rc = -EEXIST; + goto out_unlock_virqs; + } + + eventq_virq = __iommufd_object_alloc( + ucmd->ictx, eventq_virq, IOMMUFD_OBJ_EVENTQ_VIRQ, common.obj); + if (IS_ERR(eventq_virq)) { + rc = PTR_ERR(eventq_virq); + goto out_unlock_virqs; + } + + eventq_virq->type = cmd->type; + eventq_virq->viommu = viommu; + refcount_inc(&viommu->obj.users); + list_add_tail(&eventq_virq->node, &viommu->virqs); + + fdno = iommufd_eventq_init(&eventq_virq->common, "[iommufd-viommu-irq]", + ucmd->ictx, &iommufd_eventq_virq_ops); + if (fdno < 0) { + rc = fdno; + goto out_abort; + } + + eventq_virq->irq_wq = alloc_workqueue("viommu_irq/%d", WQ_UNBOUND, 0, + eventq_virq->common.obj.id); + if (!eventq_virq->irq_wq) { + rc = -ENOMEM; + goto out_put_fdno; + } + + cmd->out_virq_id = eventq_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, &eventq_virq->common.obj); + fd_install(fdno, eventq_virq->common.filep); + goto out_unlock_virqs; + +out_put_fdno: + put_unused_fd(fdno); + fput(eventq_virq->common.filep); +out_abort: + iommufd_object_abort_and_destroy(ucmd->ictx, &eventq_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/main.c b/drivers/iommu/iommufd/main.c index 539c24ada6d0..89e8ac56f4ce 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -335,6 +335,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_eventq_iopf_alloc, struct iommu_fault_alloc, out_fault_fd), + IOCTL_OP(IOMMU_VIRQ_ALLOC, iommufd_eventq_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, @@ -504,6 +506,10 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_EVENTQ_IOPF] = { .destroy = iommufd_eventq_iopf_destroy, }, + [IOMMUFD_OBJ_EVENTQ_VIRQ] = { + .destroy = iommufd_eventq_virq_destroy, + .abort = iommufd_eventq_virq_abort, + }, [IOMMUFD_OBJ_VIOMMU] = { .destroy = iommufd_viommu_destroy, }, diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 69b88e8c7c26..075b6aed79bc 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -59,6 +59,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) viommu->ictx = ucmd->ictx; viommu->hwpt = hwpt_paging; refcount_inc(&viommu->hwpt->common.obj.users); + INIT_LIST_HEAD(&viommu->virqs); + init_rwsem(&viommu->virqs_rwsem); /* * It is the most likely case that a physical IOMMU is unpluggable. A * pluggable IOMMU instance (if exists) is responsible for refcounting From patchwork Tue Dec 3 22:10: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: 847141 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DFAE20A5F5; Tue, 3 Dec 2024 22:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263865; cv=fail; b=LVHnRZxdUCGgc7HNYkIyHu55SYsQ5IKsB8FORyDC1m6kw9G4LMZzS5FF+WYqYG5HzQwh0pdpEgB2pDqj3J+MPVWB1IYNd4sd1oQniifu9wbZ5670AXDSLvnJtqzlbpLJL6WRfTbuDWWsjoyjV7OL50ynTLOgRNmYUcnUbVJ7dRE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263865; c=relaxed/simple; bh=ykOM7BFYRYF5n4AjwPa6JiREWxFCCbhfppxUelq2kBY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j/DNDBf/GG1jVOvNQhZxdGl3HozTOIkvD2eY4zyBP3p7NgvxSvHSdJhJ3pr3IUD5CC7L8KtBYE49oeebr6jD9/hPX1B+m81GhL8DkhwRD/QLro0HGQCe5F9aYkJZdhBZkWEjT8cbzQgatUVHgHqCj/R98hxqHXI1r2lOp0KQXtE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gVFCGm6A; arc=fail smtp.client-ip=40.107.220.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gVFCGm6A" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HudT5q2r5ZiZ/PlOkG6gAq96BhkOXEAT+cDseBkA73yyPWfwVKHk97P88mscQ3NjfMwpyWd9wV6Vqv8ZBIlX7p666CweYZBabhOxnT3EsLkkMT4MoHoxKWtT3xGlOWlDkiVlksJ4uV2Y9sOXWUXusU+fQt3GOGpIuXPch3yxtMgCoRHCyO8rs1boKVBOt+WiKfr8M4RHfFpiVFP+BQ/VZTrj5LoFTRYwJy/co1+xv0/NXIjNCd+FmjlM+gsecL4WDUhs3Ndid88A9MimnSZzEO4xKHgDnY1OnGnCbt3aKmroTdVbaE/Udv2MzbWz7L4i6vMs2cyIWuC1Mc3IXg6TgA== 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=lzXk7UbAY3I4FC6TIIAdnFAX1qhMEmsh1l+dMSsHf/g=; b=rIJjiBQewO2M34IIFy4Pjo6+VsUrAqYFDi2F922390aY+XlRhOJKxcp9iIILYhr323UJlszQbJGEeNnHLCPPDNsBXuODXxdDGiY+roVTr/77n4Mo6PK07nDauAjbfkaBL019IktmnzcDPj56wtNAsAaiU3MGtevbRBlmqyA1VGEreF5unQ7zLNW8LVr0nTxLH/rErggACbHgELfsUVQEeqjXx+bstr1JniL3+7tPJPMRJWnhIAfESlQMXWaULdx/xQoBBet72rNvLqDmMQ9YgqvgqoyLtvm9ZF4CsY5to9r+5k7cpTR49OBZMrV0GL6elzXoUx2hgietxpATIgf3yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=google.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=lzXk7UbAY3I4FC6TIIAdnFAX1qhMEmsh1l+dMSsHf/g=; b=gVFCGm6AulVqpeQ1hLBwQhZtMA6xnq6aux4w6WYA1auWZAQKQAX6S0hP8Ku3F40ovTZnNOgbyNuTERd39H8ENTkEdMUG34ZF1MqvyxKTem7YqoAi5WrvbZmvwPx+igTW/RqMHCpeWV9uX3fQL+iwHYg5fzqMGif/zSV+FixyMz0AYQL387l11r2Wx/0loF3PxCEhuiRI+1xJtl4614JPmFPk/k00iFofvcsikmxn1mihyk5GboZlsE5Xw4NXzyxww4FvP51gal2U/G5AwrpIDu7+YddgSrmgMj9a2ihcpdRfk6uxFiIyOXtWqZmkbiFPeRoG1NjFltAwWkRpIZgtlw== Received: from BL1PR13CA0184.namprd13.prod.outlook.com (2603:10b6:208:2be::9) by IA0PR12MB7676.namprd12.prod.outlook.com (2603:10b6:208:432::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.19; Tue, 3 Dec 2024 22:10:58 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::ff) by BL1PR13CA0184.outlook.office365.com (2603:10b6:208:2be::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Tue, 3 Dec 2024 22:10:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:10:58 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:42 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:42 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:41 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 07/13] iommufd/viommu: Add iommufd_viommu_report_irq helper Date: Tue, 3 Dec 2024 14:10:12 -0800 Message-ID: <7e9842376e6235d9e3471356d035afe2bfe8f33b.1733263737.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|IA0PR12MB7676:EE_ X-MS-Office365-Filtering-Correlation-Id: 3debc2dd-aa90-4e77-4257-08dd13e75d86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: GEcJ0sQCWomq+fWJtM2R9RMO365cCjCAGyR9Ch48zIOSN3iO0C5hDF8AdhXgnw+BuZ9XrolXxXd/js3CRONn3A/cE7GaDWlTXB/gI2Z1xwhUwqPVbW0h7izjYI5T3neTQ6N8gxWHDwi8t6WvfqtKuAU9XlNXuYzQg4YjXnZ1ap+cIkrI+28joLr1YbG9nkmpycxbdWK3E+8i8yLGFvEsXNKv/CPnv3M00and5sXU/WW1uSNC4VIcKleXJRc5lZz1wXwuz3JnpIg6y+9HOOP+gYbadJOsVJm3RMoOnuWtgbgIoSPu/LW54lDAnM6Azf/esFhpRwHMuoUrUGcJv+u1+33Yy33xmb+fbrSqmUjci0VkaJZzwDwortSFUcz8Art9yBXcZtfiDRRhFJ9GT92qNSI8SgpWNS+ne989c/V1pmlUbHXGYSX9q2ZKcvtEhYAXvxD1KrsJnyGC5cVpEfNJiQLHsAZe4DHuRdErUTyZjLGClZEG/zsDnDUrkASDiX5d+p1QfB1Er0NFfMtJWUZuNlpDlPZ4kbHxQrHtdpvdoVcVfS9kQBEthoAtxyyeZBiipNZ3wOx4vibCcohqO5UljfaVoB0qrMlCe4HwzN/+Cr15yGotObkgB+jFWmySwTjqX5v+xTrB3qEHFOKZOqpSDmEBIyy2+y8SSCyrknU3wucGLndnCAEGLSvmkxl+leqFmaKR6wyrcIvs/HjZPAWR87qzz+Ucm2HLxHn+ZpSNq3GGgLcfXGOsUlEeNNDsLh/VYAs6PUJ9hrvJOfTdJk2L4/L1nuKqPzgYzeUh5f4q8ELr8h7WlE5CBAaNhxcn1yGtQ70xqyhSbzu5wLHM5j2wWE/Nl1BCoLNNM4GNLDsnzxXjHxTtJaeEDny5vneuPwPVAbwPX5xkULM/1exd6G3yo6N7rDg5p8Dj5vaZ2WWQHsfl7jPCYUjpzcNRoPRiWVhZjGho9PbxinRG3S0UyutckcZa+XFN8ARB/EF89oRIfHnRyVlhljOao+yIczeYfwzvnr4q5gMyeofAfBdEdHtANi5TRTsClhvglhzuVnZD6fVgSdWdzKgrhFmg6Gbh20hD9iqxCpz0sj3vhT5naQPsl1M8BVCW9h6tfs58JF9p504ddgS6nP+hQNOD3/EcyBBvr1S4f7c5/Je+WLMcZ43Ow992plSi/KdwK3H2zLyS7EMhqJUQBdEf8aRBKCzJswv4/dKWeDGqLyBdliffYSXaq0LH/vs6xoJ+ZQ+rtgjUZ6JvvXHqk0tC9ABEokYj/rqiMfxmeU+mMWz1bkEttqoPxTso+N/Sf7rWtYlFV3GxpZKkOk+fwC4YQ4inmMpnPAUFMK8szOYbCQt5GL4W+fWGE4ivChr/yZLhkOe+ZYn+VoMJd+eZ+xHo5Z8eNkp2jg+2aoNjcwti1wFMOlIU/F6LGB9kCwgJ012IRL2ckfmu4IsYTevVpMUSpBNBMgzzOLs2 X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:10:58.2525 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3debc2dd-aa90-4e77-4257-08dd13e75d86 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7676 Similar to iommu_report_device_fault, this allows IOMMU drivers to report, from threaded IRQ handlers to user space hypervisors, IRQs or events that belong to a vIOMMU. Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 9 ++++++++ drivers/iommu/iommufd/driver.c | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 1f5376476cfa..2ce78edec4e9 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -192,6 +192,8 @@ struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id); unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, struct device *dev); +int iommufd_viommu_report_irq(struct iommufd_viommu *viommu, unsigned int type, + void *irq_ptr, size_t irq_len); #else /* !CONFIG_IOMMUFD_DRIVER_CORE */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -211,6 +213,13 @@ iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, struct device *dev) { return 0; } + +static inline int iommufd_viommu_report_irq(struct iommufd_viommu *viommu, + unsigned int type, void *irq_ptr, + size_t irq_len) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_IOMMUFD_DRIVER_CORE */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index 817e430a11bc..339baa270d1e 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -67,5 +67,46 @@ unsigned long iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu, } EXPORT_SYMBOL_NS_GPL(iommufd_viommu_get_vdev_id, IOMMUFD); +/* Typically called in driver's threaded IRQ handler */ +int iommufd_viommu_report_irq(struct iommufd_viommu *viommu, unsigned int type, + void *irq_ptr, size_t irq_len) +{ + struct iommufd_eventq_virq *eventq_virq; + struct iommufd_virq *virq; + int rc = 0; + + might_sleep(); + + if (!viommu) + return -ENODEV; + if (WARN_ON_ONCE(!irq_len || !irq_ptr)) + return -EINVAL; + + down_read(&viommu->virqs_rwsem); + + eventq_virq = iommufd_viommu_find_eventq_virq(viommu, type); + if (!eventq_virq) { + rc = -EOPNOTSUPP; + goto out_unlock_vdev_ids; + } + + virq = kzalloc(sizeof(*virq) + irq_len, GFP_KERNEL); + if (!virq) { + rc = -ENOMEM; + goto out_unlock_vdev_ids; + } + virq->irq_data = (void *)virq + sizeof(*virq); + memcpy(virq->irq_data, irq_ptr, irq_len); + + virq->eventq_virq = eventq_virq; + virq->irq_len = irq_len; + + iommufd_eventq_virq_handler(virq); +out_unlock_vdev_ids: + up_read(&viommu->virqs_rwsem); + return rc; +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_report_irq, IOMMUFD); + MODULE_DESCRIPTION("iommufd code shared with builtin modules"); MODULE_LICENSE("GPL"); From patchwork Tue Dec 3 22:10:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 847140 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2057.outbound.protection.outlook.com [40.107.223.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50EDE20ADF4; Tue, 3 Dec 2024 22:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263867; cv=fail; b=rtRBLvVlQM5/WawQ1LcNO7a4d+ngWhz2eiZA7YG/vIDEs3bY7IxG+bnn9gIW+WW4X6nhN8ImeLAI+OPlgz9+QgFv/fDUqUJb+zH9+5c9pP74ZM5olLbhknAJVxIyVrWY/+U8GyTE4GhljY/VVba7lSXhQDvBALWNeYF4up/F2KA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263867; c=relaxed/simple; bh=9AC8Rf4fE3NRuwccz07xoV9B5wCWtCUENPR5gcbV8FI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a6R03Ng2VrBdcvrc9ivI0+F8svKLePMbSFaJBe94TQKYzLQRdSVaAOxHLh7EnkeKaCxne6Vx/8ckd9jQ39ymRnQqPv4mxT0QhM7TilVDCMOv6knMYFA27REBQZ0YXUH41krCQcWrg/poYP6gsWmRIuuAKChn/BZrRZEQovA1Pms= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=GSOKOy08; arc=fail smtp.client-ip=40.107.223.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="GSOKOy08" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EPPHqmqt/tWmLyaq0vHeuna9aulkP/8wjOtv2AsuZZO1Fr6Nxva+1rdqpunK0LahHu26fXLZTzRAa8vJz4DNnJDmE54VgVGB86lq9E+6vQkOHQMCRNK/bxbckQdfGahXJH7XFprw9A/I5fZ+xL+kmsHsd7lHCju/jS+bBxtrjtCgLhnTRjae/N7Pf4R84frnVDLjB3tNDGzx5tgBCBcwkpQEbVueTngQzFXdZjb8iTBAymqJDdQ2imGmyCUiXrPbdJYKOP3HjLYKPl2ySoihrL7o0lpsxyrz5ei+8M5yt02/cHW6kh6QPH60CYj4dHjqGT1UUtLjs7Ixvdja8xAFUg== 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=VLFWnsrYARGfxlSa8XyyJGyfIrvyXtFZaN3aeRVrNxA=; b=zA+M93+zV1rWXM/y3bsoYV9+sR9/plg4ztaAGUFkxIs9dF93xzPvGEr5m4PxXS/7OYdArZo6CGTKk8SQDrnbj6GJU5yF8LA1U3oVj5EYX6k+ICHlSU6rYuuoC6o3mhah8b6KQCdU5lWZ0vUMEaLhdaEjMwFTl0kUmMT+cZO7fDkoCaA+kYohgWD46YUJzxP8o7B3ZvQoOw2ZbgkNY1gsM/Tj4ktVadryZZEsgizrvvJMkcl9FnMC74ReLwTIw4BtEyIik3v1qDFwkFUsHV6Y7QjvwWQYxXbjon7fO1EmBMcBBbupdVyMGDHIe5zzIp0zuukaScnCps+6LSAJlBYANA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=google.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=VLFWnsrYARGfxlSa8XyyJGyfIrvyXtFZaN3aeRVrNxA=; b=GSOKOy08kITQtuNkdb4GsoHFxe53l1SeON+BkDodwy4ddMmgmybcHPx6PCmZY8H1ww96Rko3t6NNFUKh4MDIOqgoA3+ScJxGfXXllSdVBpm9gZtk3KO9zPBEAB7gmr5r+pWVP+xWmL8P5FsSN6nndrkbO0jt9li7PRh4gk3cooqdDbPIY1CqZupJogCbuI9n/Ott++72LmGL+sV7mVKuh9azsIs4sW0PWGWNaeCQ/X+FztypmYZZTjWFKi6CofpFnguNu5kGsZ1076+8nw2Jy1UpHFM6bqsXYMgrAd+N0Na3RJTnu5rpb+0PlDRjb+lx5zgIppoPsQVOpcjAoMeDvQ== Received: from MW4PR03CA0316.namprd03.prod.outlook.com (2603:10b6:303:dd::21) by PH8PR12MB7253.namprd12.prod.outlook.com (2603:10b6:510:226::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 22:11:00 +0000 Received: from SJ1PEPF00002327.namprd03.prod.outlook.com (2603:10b6:303:dd:cafe::c5) by MW4PR03CA0316.outlook.office365.com (2603:10b6:303:dd::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.19 via Frontend Transport; Tue, 3 Dec 2024 22:11:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ1PEPF00002327.mail.protection.outlook.com (10.167.242.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:11:00 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:44 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:43 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:42 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 08/13] iommufd/selftest: Require vdev_id when attaching to a nested domain Date: Tue, 3 Dec 2024 14:10:13 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002327:EE_|PH8PR12MB7253:EE_ X-MS-Office365-Filtering-Correlation-Id: 7fac7154-1e23-4275-7800-08dd13e75e80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: nMfysyHc6C4zBZm/GUEyo8TJTo3a8Q8/KBlrabBlunfKzxw06tk6YzZKXXUXgbVjjBEm/csBj/rXsdV1ybpzAMqyd7fJfV+bWOjOfnjtlidYwg5ISlOgv9XQ753Fxbzyp3vytICLGpY5FKxrzZ8PXyOyrjqgnNWAFLQyLokikOoFYaDFLJc0S+KGZtnR7Sv2bo+CBpia4oLZG6Xvv7wc6dTEhC5eGwtFF0iD8mpyJzQflucdDQ6ZB9Di02/AG9rnbFACro4KIBTrZXJi8erxrryDmy90UrD0g9YwapQIhnClJ/pqF4o7s/LqQgEjz01DMfnH298hLx7IJEKo13VV5rg6I+ARQaEykNwL8HxZpq/b/Z8/TQdn1AzPLrnKP2y1MDjHFrwn0iv2YpYKzJUbIQ8v9Z+gYAu6N5g/ZgMVUbIG1/PPXMOdqBzXuJFTIjNbW5pm1JYnjNR31aQQ867xXzN3ENBZ+yh4k8B00ZG6ULei10lQFNDm7rMIcoSnE6ASPFAiHCOKqnB5Cqfz3Su6s4TG70S/QW8UzDgZAAOEZzvw3hTX4LvFjgpbVx9KmUMf3hWyC4d2zkxWVNOKsb11jo865eihFxOP46JOerJM+CFTgjVylKG0lvkZInD74jlJi+ji4Z13gVScn0dum2veBJ7E6Y4MqOwJdUY03DbY6QAc1ictfQEY1SEvhIEjInHAlpW61mzvkWnfNGFFaliOpAWN9kIbyaLCjSpux+p/92iil9xxWqUOnDNKgpmfTOh1y/Xc1pNwXR2n5l+F3Dx2wiUIzeXcnAInfE4qQLdaQx+tk8qPsNrnV/2CvAO+vYO2b6ItAPgvmgTDsGR9qKl5jiEsMQg+IxPKzYHYG84awQ8Gw5dbOGfYQSYRdU79XYRZEHjDce1W7Pu2q8j499mSSC+J25HinwKacKDQNpHiPxkTLdDMShpT5vY85fb1450emR7ZwTNGcECh8wjahlaRsmAqKNbdAObn/Act8AtJBf8310dS+K/1wRDYExWxB3Gssi+sVdv8fGEDNc39qnaQIxjOciHItWa9v0poTX4H/PuFHFL6LymjIddlsIruDkXwUEqrpLShgigjTBBIE9ox4Yh5UI8Vladt3jWD3icDzJiFhwJa41hZslC9vW/4Jzoknc6SwGFsSpJ06PGd3adbEhMg0UZugzBugbwGcG9sh6kKmhCm4pSyfZqVbRtRmZ0L4mFS0iIUNC77RwOqg4g6UUJOPuHfg7K0zhkALMLGG/KE7o51cZCYwZ72YxQXPtqZXuN6lisoYXi+YEifryLhtHdTs+cHqixm9buvFlvfq/YDgPy/rG73sHTxZ2Ixd6cG9/HudOUBTneCSh+Iq/2JOkWvQoU0zgMavdjvjeFUrIpZSywauw+CHrHG/Ixq/k/ImxJzFlaZ1PNzOH5Vdo0cErECcPhT+Ysf2KYvcFArU74x+K9EaR8Zouh+nqLWJzCR X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014)(7416014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:11:00.0172 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fac7154-1e23-4275-7800-08dd13e75e80 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002327.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7253 When attaching a device to a vIOMMU-based nested domain, vdev_id must be present. Add a piece of code hard-requesting it, for vIRQ support in the following patch. Then, update the TEST_F. A HWPT-based nested domain will return a NULL new_viommu, thus no such a vDEVICE requirement. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c | 23 +++++++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index a0de6d6d4e68..d1438d81e664 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -161,7 +161,10 @@ enum selftest_obj_type { struct mock_dev { struct device dev; + struct mock_viommu *viommu; + struct rw_semaphore viommu_rwsem; unsigned long flags; + unsigned long vdev_id; int id; u32 cache[MOCK_DEV_CACHE_NUM]; }; @@ -193,10 +196,29 @@ static int mock_domain_nop_attach(struct iommu_domain *domain, struct device *dev) { struct mock_dev *mdev = to_mock_dev(dev); + struct mock_viommu *new_viommu = NULL; + unsigned long vdev_id = 0; if (domain->dirty_ops && (mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY)) return -EINVAL; + iommu_group_mutex_assert(dev); + if (domain->type == IOMMU_DOMAIN_NESTED) { + new_viommu = to_mock_nested(domain)->mock_viommu; + if (new_viommu) { + vdev_id = iommufd_viommu_get_vdev_id(&new_viommu->core, + dev); + if (!vdev_id) + return -ENOENT; + } + } + if (new_viommu != mdev->viommu) { + down_write(&mdev->viommu_rwsem); + mdev->viommu = new_viommu; + mdev->vdev_id = vdev_id; + up_write(&mdev->viommu_rwsem); + } + return 0; } @@ -861,6 +883,7 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) if (!mdev) return ERR_PTR(-ENOMEM); + init_rwsem(&mdev->viommu_rwsem); device_initialize(&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index a1b2b657999d..212e5d62e13d 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2736,6 +2736,7 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf) uint32_t iopf_hwpt_id; uint32_t fault_id; uint32_t fault_fd; + uint32_t vdev_id; if (self->device_id) { test_ioctl_fault_alloc(&fault_id, &fault_fd); @@ -2752,6 +2753,10 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf) &iopf_hwpt_id, IOMMU_HWPT_DATA_SELFTEST, &data, sizeof(data)); + /* Must allocate vdevice before attaching to a nested hwpt */ + test_err_mock_domain_replace(ENOENT, self->stdev_id, + iopf_hwpt_id); + test_cmd_vdevice_alloc(viommu_id, dev_id, 0x99, &vdev_id); test_cmd_mock_domain_replace(self->stdev_id, iopf_hwpt_id); EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, iopf_hwpt_id)); From patchwork Tue Dec 3 22:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 847139 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2065.outbound.protection.outlook.com [40.107.101.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 486B620B7E3; Tue, 3 Dec 2024 22:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263869; cv=fail; b=UogaQf+Hr7G/7DPijTqOzLJZmdyOs6gU0Oz9vwWKX3Gr91MCxdboWYQNcMwlQIPTxZiwOd1Ag1/pAozOvTYrKD0etqdsW38l2AFcZA/76Q9+W03drArd+Iyff5VRChEhR0FfThj+lFksCpvGgX4rmsQRNgCVYo8GPHoyyAu4bJA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263869; c=relaxed/simple; bh=1hlT0kSUhwJMKbMRzE23lybS5jktDbtEiCMbJFEdKhQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NpNM82VU1u2HBGWSmfIqi9a8MzEjit1yKnjFZMuUMQZwIc6YY3Po/Vuqnlg3sfN3wLw56pSPUsKLVoutEohS0QlZrr3VbyITgnVWuV00BMM//sAOke3qmLQOIRkriimUl+K800oSTWUmH27g5W/m24r7CenQPvRVAaN+ylFbl4Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=EPe9B0UM; arc=fail smtp.client-ip=40.107.101.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="EPe9B0UM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Lo3jqJwBufCZL6o0FE62TSfSkoT6E20LB9aGrdRHxxWnd2+MKxuWCywQ2z7d5OoXwQ2L3pf1x3zR8SW4mYmEsw00VMYYdFuHV+LlVTbqcjUk8yHkKuIdDd8dfP18jt0Uw5Meh4T1qNNH8/QYWkVZ1zRX8iu6GgxsL7HAvdomyFvpwCpEuJHVG7qFkAegFZs0cjqjEsuP1Ot31sBEBKboMw0iik0UxVMni1twbC2f+1wlyBU2OAvoyo/oadcnTj3fyi8zng414bcD89UA/y7bgfFB67aIfLEOvfZhaPmfNvnHdysmrwvURe6eP/1L8TTyKxVNcb1PPab1j4ftWOQ7Vg== 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=/NCGCZqr17sVj2upoM7Gwc0ihyUUa8f5uRYg1Aproo8=; b=v2QIXLTjco2/N6cyxeYlsinxh9ANfzuqyRQeQQFKxdm8FL1pYGU9hzdHZywaIj134uLViMsMaEwbJuEnhBxug9nto4w3/vyzBIm9IDuqkvm3D7AUxCCDN0OIeewLTKhQJ0vJj647VHw3noL5qrZBwvpUHKtAj8MZO0xJ+ocQyu0n8LSTuVIa9fURyXjl+rUdtSblVVoibog6Ro+SfAZu1nJN6YtO8/zP2s1kSwuKhGBjGPTgmH2VnvQVv1ZoOJP1gs53LdaXwM851RSlxFYLzKM+KZI8ML/7qnab0xPeuBkeVqf/MOtL+trnJZqQjgsJHO2RjbMlFNPQ/v+mDl9hgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=google.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=/NCGCZqr17sVj2upoM7Gwc0ihyUUa8f5uRYg1Aproo8=; b=EPe9B0UMCnqA/Cd3HNhV6cBQkFZZBrVUzJSSUTsDBPYkXUN9qiwKwnHYugxRxnVqqno2wE/nlypBApvpHpDMVIhY7J7r1Y653CiA43twclLRP44kuFzMO5vlT9q5Zy+jPBZ2kiiJI40Theyzhek0no1lUtpmXBVgtasOlWwQJyFgAtlf463tfvkrdZIYXUvC7qsYeLlHAvQ/WxnqyiecCushcM07eE6E7QuwTTTfanrv3xT1F6TchdKilfwmi+bPtw0SHJhbOZJIOebPcyoEj7mlKG/se8hwU/PZRcx+fDD6PXOJ/iEpx2mTnTLkCItH8ugR67qjMUcPsCgTwk6BeQ== Received: from SJ0PR13CA0044.namprd13.prod.outlook.com (2603:10b6:a03:2c2::19) by DM3PR12MB9286.namprd12.prod.outlook.com (2603:10b6:8:1ae::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 3 Dec 2024 22:11:03 +0000 Received: from SJ1PEPF00002324.namprd03.prod.outlook.com (2603:10b6:a03:2c2:cafe::5b) by SJ0PR13CA0044.outlook.office365.com (2603:10b6:a03:2c2::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.8 via Frontend Transport; Tue, 3 Dec 2024 22:11:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ1PEPF00002324.mail.protection.outlook.com (10.167.242.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:11:00 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:45 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:45 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:44 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 09/13] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VIRQ for vIRQ coverage Date: Tue, 3 Dec 2024 14:10:14 -0800 Message-ID: <7993411d7634d6bf5e7da4459ca4ee540f59188a.1733263737.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002324:EE_|DM3PR12MB9286:EE_ X-MS-Office365-Filtering-Correlation-Id: f6c6a2d5-dfa6-4e46-0ecf-08dd13e75ede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: +D23Hh75keIEiJHAMbFaw1W44unuDMPoRo9gE0o5BP/o8j/Nuy84yZ8pSWe3AsfKf5psCeVkH39lp/Rf9I/sa4n7tbIeovIIO6h6tfyP4Px3WwKfoQs8x+NRT4gXy8THUblFevOMkzokOxN2DDcRxN+pHySDhbZlUG+wd7NuxLy/DkmW35j4SxDZyFHzFy1V48otwtNyDElRLn1tVyJ3PmNWscB8jveNgR87O9/yhEgaOTcMr640C9uPo33yogoP+nxx0jGuzqFCayb6n2Klzayh4o0UkFwkECyHJKeFziJ0kSDOemTt4ojwg35FuNtdw8cmdYtoOi6bszVcR+c2AjefQTToqkoBQlyqqu2C39AaIzPWyr+6TlVNaXYdMXVi1ozd43zXBD8BBBoaD5UkV/7hCOZiofMPw8BKKeoubFi3cwwcfQIrV6E25gvdsbwiV7m8HzrShSLrj1533TUGNBjN24ULvdPrB1m5b+rRczgSIVI3UZ77RfXy6X+41bYZRQ3JK5kIU3ZOPuNb+13CoegL6SKbY90ZVkhmlH4ls9Zv8EejlZZYjhW7cmTDmHsEPlFdQ1CvtOeR1+HWpa7I8OUltaxuPYXYEAzGjaCmNLkn9V9aA4DvdhZY9ib0mSbUFQQYYR4t/ckSJzYCXVN8nFy2DzJ7t4rMehx4Jq03+eWQaBL8SHzjB+u64BtAHcuOzAApCC9tkdrUJvvAOJ47TEuvZZ7efc/cRG069HneplcQYu+i9lFhi+7Eivkf19TPCgF3Rk3wYSxjWQPjQ13AK25aAftvqs7A12+lA59nHQHvAjMxMLfCfEUcpbIuJQNpOYerxI7k9jR4hxQ7yAi87HDxGS7NujeMLqgspxbvstT8T9flnFkFLz+yvbGWiARl0gYEkcQ2o/g+UeLZd+7drfvnVzc/HwbP/PRTeQFODtRkwmE8wgb7bD/4OHVeij7KtSx2J8cXHACU4ocCj8jwmYHVs/ZVoK+7W0zS1ckXwjvGnic8uzu1Rj5UfEr+PEl86TegAWSSmBjRs7mc3GnIBGbwu6l/SvGIbup3evS6Tvzby/3Zn+fTjIQQsVO23Dv0tfSaqtRsXIV4GuFR7VpRrU9UmXfaKfq/p9F//cOQRnr34nMh2ztJXdbefHymlfQ4/B2cRpJjOaB0vbOsDDKc0k5ntGZhPJ4uMXHvyH/HtqOTaeLGEbis3pgOuhG29BmLd5s5gCOjWiRJDOhGRFgQoWvCZZja/NUcrnARVN7NUZexGGsb/zeEBjakLx212GTMK+vyUknPPNryNXExdCCq4nEN01/LUiPpFyEJFhkWTDpFJIYBprX4vBllzreQhNnbOzqyRIScLRdF6+lVFXYJIC33y8MK8usciQkNmXpdJgDdIF0II222/64EgqUF15twYlY+W6Xa5xwQ2JX3E89aAGhM+TOuH+vPXJ/9C0GZKAy+GGEAHn+0Fa5Q4mcWbL/4 X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:11:00.5993 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6c6a2d5-dfa6-4e46-0ecf-08dd13e75ede X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002324.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9286 The handler will get vDEVICE object from the given mdev and convert it to its per-vIOMMU virtual ID to mimic a real IOMMU driver. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 10 ++++++++++ drivers/iommu/iommufd/selftest.c | 30 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index a6b7a163f636..3037904f2e52 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; }; @@ -212,4 +216,10 @@ struct iommu_viommu_invalidate_selftest { __u32 cache_id; }; +#define IOMMU_VIRQ_TYPE_SELFTEST 0xbeefbeef + +struct iommu_viommu_irq_selftest { + __u32 virt_id; +}; + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index d1438d81e664..0785c9447102 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1631,6 +1631,34 @@ static int iommufd_test_trigger_iopf(struct iommufd_ucmd *ucmd, return 0; } +static int iommufd_test_trigger_virq(struct iommufd_ucmd *ucmd, + struct iommu_test_cmd *cmd) +{ + struct iommu_viommu_irq_selftest test = {}; + struct iommufd_device *idev; + struct mock_dev *mdev; + int rc = -ENOENT; + + idev = iommufd_get_device(ucmd, cmd->trigger_virq.dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = to_mock_dev(idev->dev); + + down_read(&mdev->viommu_rwsem); + if (!mdev->viommu || !mdev->vdev_id) + goto out_unlock; + + test.virt_id = mdev->vdev_id; + rc = iommufd_viommu_report_irq(&mdev->viommu->core, + IOMMU_VIRQ_TYPE_SELFTEST, &test, + sizeof(test)); +out_unlock: + up_read(&mdev->viommu_rwsem); + iommufd_put_object(ucmd->ictx, &idev->obj); + + return rc; +} + void iommufd_selftest_destroy(struct iommufd_object *obj) { struct selftest_obj *sobj = to_selftest_obj(obj); @@ -1712,6 +1740,8 @@ int iommufd_test(struct iommufd_ucmd *ucmd) cmd->dirty.flags); case IOMMU_TEST_OP_TRIGGER_IOPF: return iommufd_test_trigger_iopf(ucmd, cmd); + case IOMMU_TEST_OP_TRIGGER_VIRQ: + return iommufd_test_trigger_virq(ucmd, cmd); default: return -EOPNOTSUPP; } From patchwork Tue Dec 3 22:10:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 847138 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2056.outbound.protection.outlook.com [40.107.244.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D52BC20B808; Tue, 3 Dec 2024 22:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263870; cv=fail; b=MY3Al0b97elpSct6ZlCh+9M0R4+x67bzZrZ1oN/hVm9PB7UBQ46UokbE4qcI8OZq4JKtfhnKTeUlKbOQmGcUjAgZ2UuFt2oiOKdEGE1fAi6YdK7ea8EW5yVY3jalVVCjBzGs89PjzMcUaB0etEGqXbOrmhayTM7uH5OKwh69NPk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263870; c=relaxed/simple; bh=uSiEPC1hkjfTYDXYSXQgzHJ+fs+VLHYMKyvGm+Wkrgc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FxDa5SBJJULt6v5U2iJv2tSYINLy6YFXcbyhM+heGeXktXxnusn4bblTrkai2AY80kV6UG9nyN/Vt7z+kNU5rj0QX07OjJ/aU/7H06mXGeJE4R3KsJVt/y9pnY7b/gjBDrlpPjoPxcD81yDBK/lo2ynpFNBVHuZiRB5tjjQysVc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=WWImZl99; arc=fail smtp.client-ip=40.107.244.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="WWImZl99" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PUmM1FrQdtpfDejOWO1zwkqNmOqo36BeFOHsBGHVbxixuyCSS9+br/0gyIA306dAnz4Jka88tA16qCm9j7xm232z9GPYdHTft9xjesHL2P5ZUkNlFUFssThXGZTXoJ/u2kP2dvqKAvqYouNppR9pGO8i5pFFoAUdt6j80BQZ19NQpc2qva45FD5npcx4FKxn5uisS06QrLvKXM660W6V0C4FGhka5hcccMdJAJkyBEEkQ03BZbDYFFmnCZK7s8BiGLYy3ms1pKuMUuHf5XaBy90tLsCVbQm7o+am6FoqEpYP/RI5tGQznAyTJfQVrg48IoXkfGHZ3bi+CrT60q4TCQ== 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=eMVM3GEpN/ubnRSNFWvYwht1Bf3kSMJ6EqjcuzIeoCg=; b=EtzNBVpEqf+dAeuGeLeD7UDMM9Fdc+XOKQtquExY+IACqOtVvc8sCTWnE4GWu/bNgNCmt0IgchP7n0bmmaQna9SXxghC/UO1yadtVjN+bUVOKXEZ3zRDeW5onUw4aRIPPAl1hi7eTW6LpfEm67rFTDKpEKPfXgeIc11+LoLHE/9JN7HHA6qHsCP7x03oZ8SKf37lBO4eT+DqTnPrghYnLgL2PvC8XJAdf3VpHNB9ePdAm2C790Wd+kuW7bGjxDAg+xRPHxNCCUwFFjbzjY8P3lBMsWln6AvMmgtytkRGX5Gz6bNctEFtvU6uKGtKF52UDvbPggjpGU6WV7TcwXULlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=google.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=eMVM3GEpN/ubnRSNFWvYwht1Bf3kSMJ6EqjcuzIeoCg=; b=WWImZl99hpUr5UpsWu6x9HFa5KIPBnqkd+epfIChm7lZPL21Gq/j0bZdbbldKwSsyGaSiRh83TMQKTG75JO2U9rvUOFtP2FWm56G6F4wGgHDwK8350+wTupo9r0AGL9FBzecHsBwMprTy38OQBT3LpR+8yoF3tCzkat615R9KG61WLmcqFxpCh/qDNcncyWci9JlRjwR7XM8fR4gItWI2f3CsMIpW8UedGP0BDnUKlLD9y5MOFK/GCyBPrOSbK1yg6VISLRCwmEwOhsNO1ckSv8AlDwr8Yd/IAS1Z9sJgSZeMvTR3b65+qemM6mwyNSArVRwQg5lMJ/BTzZpehIK9A== Received: from BL0PR05CA0001.namprd05.prod.outlook.com (2603:10b6:208:91::11) by SJ0PR12MB7008.namprd12.prod.outlook.com (2603:10b6:a03:486::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 3 Dec 2024 22:11:01 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:208:91:cafe::8d) by BL0PR05CA0001.outlook.office365.com (2603:10b6:208:91::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.8 via Frontend Transport; Tue, 3 Dec 2024 22:11:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:11:00 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:48 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:47 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:47 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 11/13] Documentation: userspace-api: iommufd: Update EVENTQ_IOPF and EVENTQ_VIRQ Date: Tue, 3 Dec 2024 14:10:16 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|SJ0PR12MB7008:EE_ X-MS-Office365-Filtering-Correlation-Id: f05f9605-11b4-41e0-30f7-08dd13e75f22 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: QydaB9LXjYPbnst7IR+yyYqA+WLz/guQXeke5a+twiKsA0KtJxHmXENiHkz4I+ha14S3gkHbadbhFoS2jeAN4HSlraRt6TQYpyf9EgzLZRj9k6atxTjT0p6Hb47Ot/IAZGmOOkXUv7NfZ/Yucvf/ZT/g/ND8kus8oo+etHcY+rDYu1Zl2qEhxDl8YY/KMTIzXIbew6dwKFWa7Z2/upBGyJkheSUyW3OSCOubUdIaNfGKgyuZ0V1ME9YVKr4/WRgboWnGxZCbg0DCa2j5HFQu4bCqCQ871WtwZ5uv25YcHnW4zHn1mFvqrUFzSds7B0Vy5rCOjnL0jsDe2Lxm0A6RNZSrIcC0UtJnKXrJ81sxaby7DbT6i2JJBdZeyrvoRXEzQDg2uqQTQxXnjMJI++H7Xl3yBRanYPv7ShqmrfksKves51wViB9LYwqee+GhYA0NP+IZ1BIENZsm3Kkc54ubIY3dI9+pfJVZx7B+8cveGhbv76kIKnml02598vxoK19tyS4LvugufJX7MdwdGV+irWBRwlm2XD/7ziPL1RqNK5MurRJFLatSfVEES/G0wmeS1VW3yYqivsvTpdKfj9yp4xmIOqsIx2COAHQxteoiDoAVk7Px3EDSLA4XbNFbeuFk1lZCM/wUiv+ViAlmRSokoWY8Glw694FoMD2xfWKPJbB2lhCNbT46hRL8exVLerYNFTDws7arD07R4GVlL1cMXK9N79FlX1vEw6LiIEbJzqZOPshW7vXU+jSUz4hvpSkCRUATMJYL/xMIaHIEWlCmLd6s9oIqTe8WUNEURHRNpL2wRK43fVkHOA3Vd9Jay2jnmSlDyEGi9i/YLLcZ4u/kK2rnWyso/2jy+s/eHITx8U3Qp+U6uLPDZT02aesxsqlx5CuLGxS3P/8OykBDomEs5SN5zjudG2tYH/aS5xm1fDBIL8QzP8YoxIpEg4c5BhsuxVia4eiq3z3zcF9WEbdbN1UPa+501XVCHaJHV5d/KtxNIf6ZAdMsvZUCWQKz22k2Wgk437NGuZX5F5LQFPD5oGyr1w4pmPLrCaHU+y3mdLmPjgGm+BiI+YJzI+6+VL22h63ULnnnYWQYS1zRf4IdL2ECmjXlxJkr+OF7N5mJFvX/bw5gsFwcynVePf9DbmSbaJIAoxeaczWBRaiPQLXkwS8EwnhOybb400Ypb/zcbHern/NapoaF8FTIrakTlw5Hw+V5uIyB/xBu03UeFV1xP7rPUpE1vts2kygruOg4IQDXSIBfgr6AWNB2lCUV6p+3M/rB4RscYwUujGC7OE5QdLJtVckzgYxyUlTmW2tbfz99xlwh1aP9fcWAnse/L2Ln1sPpe1OB7Z8Kbmy1HDhm/teOEuK9nkX72OX40ylItVQBHZGcL8gmiXhF+XFBDBLakv/mnllGG6DxqKZg6M47Pgi/t9hRyTddodfhyYbMKxnuvDuSIEHHY1Lo9OeSKck5 X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:11:00.8896 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f05f9605-11b4-41e0-30f7-08dd13e75f22 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7008 With the introduction of the new objects, update the doc to reflect that. Signed-off-by: Nicolin Chen --- Documentation/userspace-api/iommufd.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/userspace-api/iommufd.rst b/Documentation/userspace-api/iommufd.rst index 70289d6815d2..798520d9344d 100644 --- a/Documentation/userspace-api/iommufd.rst +++ b/Documentation/userspace-api/iommufd.rst @@ -63,6 +63,14 @@ Following IOMMUFD objects are exposed to userspace: space usually has mappings from guest-level I/O virtual addresses to guest- level physical addresses. +- IOMMUFD_OBJ_EVENTQ_IOPF, representing a software queue for an HWPT_NESTED + reporting IO Page Fault using the IOMMU HW's PRI (Page Request Interface). + This queue object provides user space an FD to poll the page fault events + and also to respond to those events. An EVENTQ_IOPF object must be created + first to get a fault_id that could be then used to allocate an HWPT_NESTED + via the IOMMU_HWPT_ALLOC command setting IOMMU_HWPT_FAULT_ID_VALID set in + its flags field. + - IOMMUFD_OBJ_VIOMMU, representing a slice of the physical IOMMU instance, passed to or shared with a VM. It may be some HW-accelerated virtualization features and some SW resources used by the VM. For examples: @@ -109,6 +117,15 @@ Following IOMMUFD objects are exposed to userspace: vIOMMU, which is a separate ioctl call from attaching the same device to an HWPT_PAGING that the vIOMMU holds. +- IOMMUFD_OBJ_EVENTQ_VIRQ, representing a software queue for IOMMUFD_OBJ_VIOMMU + reporting its non-affiliated events, such as translation faults occurred to a + nested stage-1 and HW-specific events/irqs e.g. events to invalidation queues + that are assigned to VMs via vIOMMUs. This queue object provides user space an + FD to poll the vIOMMU events. A vIOMMU object must be created first to get its + viommu_id that could be then used to allocate an EVENTQ_VIRQ. Each vIOMMU can + support multiple types of EVENTQ_VIRQs, but is confined to one EVENTQ_VIRQ per + vIRQ type. + All user-visible objects are destroyed via the IOMMU_DESTROY uAPI. The diagrams below show relationships between user-visible objects and kernel @@ -251,8 +268,10 @@ User visible objects are backed by following datastructures: - iommufd_device for IOMMUFD_OBJ_DEVICE. - iommufd_hwpt_paging for IOMMUFD_OBJ_HWPT_PAGING. - iommufd_hwpt_nested for IOMMUFD_OBJ_HWPT_NESTED. +- iommufd_eventq_iopf for IOMMUFD_OBJ_EVENTQ_IOPF. - iommufd_viommu for IOMMUFD_OBJ_VIOMMU. - iommufd_vdevice for IOMMUFD_OBJ_VDEVICE. +- iommufd_eventq_virq for IOMMUFD_OBJ_EVENTQ_VIRQ. Several terminologies when looking at these datastructures: From patchwork Tue Dec 3 22:10:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 847137 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2049.outbound.protection.outlook.com [40.107.100.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5104220D4FD; Tue, 3 Dec 2024 22:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263876; cv=fail; b=Imc/eJpoHDUCteEo/YDyAdaR9XsBfAdoOCoXcvS+FCUh3i9bedJQNritmLEDkH3JkguSY4uDa+ZKODyjKIJm1OkE2zy5SFwuUXckOB9gEt/bWWTubf+9e0Lo3yWpWHJNevv7hHBiV42cSVA3W1HY0mf/c8Cv4Xe7bFCDzb2iWS8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263876; c=relaxed/simple; bh=dM/Oiuffb6SURuwzhkmcpnELT8Af3ANEFEL/zv9CI0c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IzqtyYK1eqDhv9Z+ndUwOTxHr2c85Dc17qxyTIBz2EBGvZNtJQ0eZKsx9iPbs8o6PQTqmS2yqrr3T5o2ebHVRXkglbasxHEqzh41hoJ8d0GvzOgv8QxZEYvG1gAYl6P6eFME39B04vKGKlu0ja6R3I7RSah3dCLGGIbFhxfdmdk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Tod0JHaR; arc=fail smtp.client-ip=40.107.100.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Tod0JHaR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QPmLxLuwntDQMZ54vt15eMcgm8SL9bsbeQWEDquAQ6QJahINz7NPoUqAgD2Soxw4JxkxVHI1rkmxM+JD6WZXJpmFOxxSTDyJkk3K+037kL/AEw6AIh0r4jp9BPJdj6TwS2ROjpqXVMN9jOmI45XnpRf0H35QAsH6CpzXr9FqKs+5349MSgiaUkclx/Tp7sWPmmq29p4/R/L5ckMO2btN5C1KYjfmldpnHPWgchNbCiXNoCQVn+qihgCCCE+bR7+WnTcYY0hGmcGuNBsuipTi0de0v2M0epog1pkk1QUchS1JTuGkQXC7BnViVOJ/z/YRQVaV3GRb8lAJB1KQ7f8EWg== 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=Sm1eAjZ3ZaNk6wZqnM9eK6VbYs3VE3XEVaXuWvdxwEs=; b=QdQ2k6rOHY5rCkNujOQfEN4ejNgfIkKBIavjQuU2Mwk/RFQUeZoRuFjc6wa7tL8/E1vNcsqRsfFGk6dEoz3ucLgGxu0FP86XOaMAQOsDEbk1KfdGeoq2q5eaOcqxGwPhdQ6bA31P/KuTZtImC1NkERKiQ34+KT92T0VyBUi9FNBel7lPr27vbO3MLMY3UliD83RTi3w1SdzpQuMp5I6GlIKjst39dxJZmor0SoXnvGrUkXsYyG9nxG0v2Oo40Bbd1Sz9/7tZPxLWom1FUGI1GEjZw9Q2v/tPblQyBj2Dqq3bYLTT+UzJLBLWCHxlI6rTw+lnSaHiQ9IzvVtMA9C4Bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=google.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=Sm1eAjZ3ZaNk6wZqnM9eK6VbYs3VE3XEVaXuWvdxwEs=; b=Tod0JHaRs6+elv3LnllHhMb4oP7nhXDIEC0SUfESjMJSTbEeuqIWsjFAUJoCtFOZG35nVEvKcv45xiuu81mantCWmP/52GOgP0qh7XNUO9rFWwXo6yyjAQrm2VwWRlyPW/++yHef+oCOF8BaflEJ8Uc3ieTKFGczdxXfD/5JKGB6xVKV+gHcsuj9dlKnb8hp5+GydGOPmipDY4Kre7nTfNykdAX4f0DqsW8tjf19YBilbZhB2cS6sQsdNGGeknUuLzICBDmOtnOKyR3BxfBPual/cCW0Nduw2mqJ4OFVQKtxwTAFuTc0xf1SZauw9aVkWIU6876dxgzCz2+/nxFy6w== Received: from MW4PR03CA0315.namprd03.prod.outlook.com (2603:10b6:303:dd::20) by MN0PR12MB6368.namprd12.prod.outlook.com (2603:10b6:208:3d2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 22:11:08 +0000 Received: from SJ1PEPF00002327.namprd03.prod.outlook.com (2603:10b6:303:dd:cafe::49) by MW4PR03CA0315.outlook.office365.com (2603:10b6:303:dd::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.18 via Frontend Transport; Tue, 3 Dec 2024 22:11:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ1PEPF00002327.mail.protection.outlook.com (10.167.242.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:11:07 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:50 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:50 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:49 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 13/13] iommu/arm-smmu-v3: Report IRQs that belong to devices attached to vIOMMU Date: Tue, 3 Dec 2024 14:10:18 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002327:EE_|MN0PR12MB6368:EE_ X-MS-Office365-Filtering-Correlation-Id: d65dd2f3-5871-48a6-b8db-08dd13e7632f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: DMYnNgn16M/Zj6hyLLqw5/z+WQTLnfFFnXAJopquRDTnGxHgE6VMgcGuZjJyag2q9lrNey7WFPglrw0FkgDkqfWOGU1dvKpKvpdrG2Wup1L7KcMYCnJG4utLNTnrXqv7lGpRezugXIMnlD55sv7FMfO2dMG2h/Pl1X9wIAXbOBcrmuxPXCS2dLeLQ9SriXdRIE00jfAM/WyNcs6yLUS8PWw7rSUpNue09QYkSpQ44vMjPj8JkPTVUjmbcydGRSwkOh2kTBSkShv2DadUsUMswHK11nuER0f1PxwVY1vg5/MfZ4iZ6aHh8Mj0DLKR+aChCKexEnrHawyedfCzIWq7rzglBznJHpqsqf4/XeGggGAk1dxPjB9STCOkihB9ODSu7dM+5MOCZyLPcLOto1ukRsUV9JMhYAbq4PU6AU3NQv1l093JrP/U5A8lrQGoHPewCO2s4ixMM64UfTE+YYY+3HBk5CchtB6Gq5rlW4CDOXvk9N/hl8QfMMK2RjtXPeEx9GVpHG/K9+GAZFJd/BofiwvSzSl32Jt0xKZftexhOPOmlLu346gr1HCf3sa7IeT/QPILLpT8/oxHKWzSxASKSUQ+6ErFyj/c8VIBaOphRWYgQiEupwItTKy9ByiTiZRSe/Q2o4cREPufGvapUZLa4LAswbfWI40SrRFcMq/8hw7eV0Bhe9ZfFa9onLThOTZvCYEBmUpnJ0gTR03l1M7nbTqEhaaJoXNwkrM89acaRalHpKyZ8QxhIj6w11a2CSSUjMcPkioDqa+dT4I2VBe44U9XtO4FUBocu/zhaWPb0+CEMBIzvK7PbTiFw5nqBro4BY7+OkDlajs0zreYuMbj7/Yx4OnFCaEYm2BalelZIuQtyn4ToBNF5akqPGpXd6jk01DNWUwVwP6COu7exWPEzGvnDETTS+YFawwzvAPD8syf400OkeRJY/MmG/Efhgh7PMBKW2W8zo8Zp6ysmFvCgVv7lGpx1Ogi27EKaFDtT2LAd7NwabibHcCgpQGmv/YCufucGVpeTWGG+8vGxxx4P2465WkdvXCfK0T8LOSgtY5IpVQ7iQM8/bUGnP3/MlIa9Vw6ddn0uZnP81LKWQo7aaPJQYIpHAkNl2oDXB6hBhiCOlu6VZ9GGgrJv324P5Gs796Hnpwa8VN68f/E3jXNE4wrrzEekO4CjjtfN3gZG65CjC8wdf3vCP1GH70PXSQF1klN6ZCeLuNu51cyoAl3bZA7mgpdY28SsbSTRMV05j53RyaCj5LAJR2a3dpjMs6ugs1AJAn30CZyQQBkI4495+q2uG6BSpt4woBIaa+U+iUClO4QrYCqxXIopYqx/vv66kjTfkgWXXq6bAW0AOz/OJTerrD0yEGuz1xb0R6o1DQ2Hd6b4wEgg1iYn1gtOqFuQkj54BaxFeWYYRlCjEWF2826fPITd1HO1Kh420tLW8txnqVk+BOZ0c7jhFFwucPQ X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 22:11:07.8610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d65dd2f3-5871-48a6-b8db-08dd13e7632f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002327.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6368 Aside from the IOPF framework, iommufd provides an additional pathway to report a hardware event or IRQ, via the vIRQ of vIOMMU infrastructure. Define an iommu_virq_arm_smmuv3 uAPI structure, and report stage-1 faults in the threaded IRQ handler. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++ include/uapi/linux/iommufd.h | 14 +++++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 16 +++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 62 ++++++++++--------- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index ec7cff33a0b1..05915f141eb8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1037,6 +1037,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, struct iommu_domain *domain); void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); +int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); #else #define arm_smmu_hw_info NULL #define arm_vsmmu_alloc NULL @@ -1052,6 +1053,12 @@ static inline void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state) { } + +static inline int +arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ #endif /* _ARM_SMMU_V3_H */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index d9319f5b7c69..164920d7f0ab 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -1016,9 +1016,23 @@ struct iommu_ioas_change_process { /** * 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, a vDEVICE must be allocated via IOMMU_VDEVICE_ALLOC. + */ +struct iommu_virq_arm_smmuv3 { + __aligned_le64 evt[4]; }; /** diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 3a77eca949e6..e3ef77e0bffd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -447,4 +447,20 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, return &vsmmu->core; } +int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt) +{ + struct iommu_virq_arm_smmuv3 virq_data = + *(struct iommu_virq_arm_smmuv3 *)evt; + + virq_data.evt[0] &= ~EVTQ_0_SID; + virq_data.evt[0] |= FIELD_PREP(EVTQ_0_SID, vmaster->vsid); + + virq_data.evt[0] = cpu_to_le64(virq_data.evt[0]); + virq_data.evt[1] = cpu_to_le64(virq_data.evt[1]); + + return iommufd_viommu_report_irq(&vmaster->vsmmu->core, + IOMMU_VIRQ_TYPE_ARM_SMMUV3, &virq_data, + sizeof(virq_data)); +} + MODULE_IMPORT_NS(IOMMUFD); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6a6113b36360..215c2d811eb7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1779,33 +1779,6 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) return -EOPNOTSUPP; } - 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) { @@ -1813,7 +1786,40 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) goto out_unlock; } - ret = iommu_report_device_fault(master->dev, &fault_evt); + down_read(&master->vmaster_rwsem); + 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]); + } + + ret = iommu_report_device_fault(master->dev, &fault_evt); + } else if (master->vmaster && !(evt[1] & EVTQ_1_S2)) { + ret = arm_vmaster_report_event(master->vmaster, evt); + } else { + /* Unhandled events should be pinned */ + ret = -EFAULT; + } + up_read(&master->vmaster_rwsem); out_unlock: mutex_unlock(&smmu->streams_mutex); return ret;