From patchwork Fri Aug 2 21:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13752005 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2083.outbound.protection.outlook.com [40.107.236.83]) (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 B356474040; Fri, 2 Aug 2024 21:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633860; cv=fail; b=KnZPzOiPAv4iQItBR96Z0J5i8pPvrypMOboJv0DV4ZdAHfVNkuYxhx7kX+SvVDFv7ZnLZm0zLaM883KhW9XUHqFbi2RSD0CQ9vIaOKCgYIaOcPCQl3LV3NXjrUk/rVrG/xknZtH3jArRoFGiYVzUs8XmwnQ1eRK4XX+pKKlV+Vk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633860; c=relaxed/simple; bh=NxeLTY+idNAHCbsBCAzriak3VvVxd215Egs8fzM2tQ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dEifjPxP/Uw2Vp4m8NcHQgjg4dDHH65pj2bM0SA/2vqJrkVzeqjaY16uokIaVsuIQ0ysmJLsknkzB9nd5FCesgnAR89lSH35Dum9oOFrmI3Tj8JQeFcS+2uzQ17GS7ePQMrZeDbjW+m9idgT20PaDg7e1aQ/5KVgAf9gbZVMCYM= 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=Gy5ssTyW; arc=fail smtp.client-ip=40.107.236.83 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="Gy5ssTyW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Eb0nXkd57kwr8v+pRHTnLuDV3EDnfSZNLLn5F+gULv+rslS/iPfBRPZ6qo6aPH6uDNnO4kU5BohmpMQIkrKa0ft6KbMJ8LE2XK0ok5Xi9GzmuygJQ6TCSYcRdlzz+3OO0pQYzsNDpecmsEX0ls4LrEipcE6HM1VMmk7x89sa5o+RmJBzJHCLsWFq8aaHD6uVSUJc5VDn4/9XAjW7+GGZo4MBARHHv7jdlVF7zruW0g2DLSg4EgSvkH01ETlW8Pz/u8KoRfMnnc40yW4t1oXnGMLdWlWCkd+i2KWyLTuLykTAzVsgmz8HrLMXsEwPFQWvnWZV6y7KDmGE4tp4GiAp7g== 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=MPNloh2bQ77p615itoyosI8JbhB/G0bhaNWiEafCAMg=; b=J/2PPYK1PTXsLSd7sumVDkKt4PT3DxbW7RKeLeQLQoXVmBT91hqfQfqUj88O9wus7DXCdstVnvS29YEk4nf53MmFCtwimr+3RpO/K3SbcVVgf8X71qxT063UAvTYYPxPNofOHzMa9i85j970Vz887FwP2wza2gOur877n6YJfDQwSnzghZLHWbKbxadwPRMYroCtIZVb0I/VigozcmkbINsZXp5UnHtYyV1XGLZquGDy42FOVw2cYaDmbTJJcelOMs2Jy9X5gQrmG9UTmtrxbwZuCvAeM1lqldCRV7u9WSdqJiurep+l7jA9SgfbuvX7UCp9TgjLZjkkFq45zbCUwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=intel.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=MPNloh2bQ77p615itoyosI8JbhB/G0bhaNWiEafCAMg=; b=Gy5ssTyW7DlTdApL1H4VJXG/xG6Jm2ufg3O2b2USEj1dazSD09KfUojtLPyCg6Kg1LMilq64z0boi5AfKx0Q35LlesNVbOVhDo0cx/G7Rba4fGYcYYFNGCPsUs7DzkXPkRDxFfJ0bhzcM2umwg+p/BGV86nU5EHMCRSd2sRV2SJjpak+K5i5QOfvxQrwDqWu6E8PSvPBJeC4N2mLU+bZEjnXL/N4cccKi7zlvX6Gkm8o6hAD6Okkx66iVebeuEVgVvu+3FRaMUpJMHekzq4ipWQ6tv0pmgplqFHSzhqQvWyHEdc4P5+4bjEOZ+0IIbJTHqlP3wDinPp3iNc+0wNDSw== Received: from MW4PR04CA0057.namprd04.prod.outlook.com (2603:10b6:303:6a::32) by IA1PR12MB7758.namprd12.prod.outlook.com (2603:10b6:208:421::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Fri, 2 Aug 2024 21:24:13 +0000 Received: from MWH0EPF000989E7.namprd02.prod.outlook.com (2603:10b6:303:6a:cafe::a2) by MW4PR04CA0057.outlook.office365.com (2603:10b6:303:6a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21 via Frontend Transport; Fri, 2 Aug 2024 21:24:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000989E7.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Fri, 2 Aug 2024 21:24:12 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:02 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:02 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 2 Aug 2024 14:24:01 -0700 From: Nicolin Chen To: , CC: , , , , , , Subject: [PATCH 1/3] iommufd: Reorder include files Date: Fri, 2 Aug 2024 14:23:46 -0700 Message-ID: <7524b037cc05afe19db3c18f863253e1d1554fa2.1722633199.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: MWH0EPF000989E7:EE_|IA1PR12MB7758:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e9a498e-6751-4b7e-3a22-08dcb339742c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: 9N7IBdz9jvS4kp2CAaV/942CQL3ywXbZJkn9J6+hSLFf1plwHKJ+RFT48pdItGSLAfcD87q7Du5vfnnFceHNLEKC/jc8i2NPMnsZ65/yNkira/xQPc17PAN4LwVxboAMrszp5U6Me3j4N8J0NWzrHNZ93sjHMCCphkVCboN10uvQ1OQO4deB54y4lCxizxvJhKqt174fnbYTlw8oB1Hpu3yaj2EDZe6o4mWhQLibIdsLbIiyMcTTcLLswY/s29uwgCs9EQIXqtYpxcVFOmu7ChR0GDZfGLlHmAG5jI4zenKT3hCGEVxLjJnXUixh0EgLmoVx7dXDjXYfYyxlwHls3IigTL8mxbhnyOWKotaLHkZzF9sr211oD87K1SrWJ2FNXAtQRzWFMOwfUZNSn2f7jgWullziablM4rVhDN6Tsxv+2goKz7CwrU2phgnol7RRNBnSX7O5h68GZLOwUtAtcDo9htokTL+sDrHxHMYnkqbz//oe6NpZY/h8jNFiZj7zB8qx0pzFdgfd47rti/n8zI8P2R3CdPTY1gzY+bqtXIoMQDsFHk7lHYf2B1htrbEOMgtwG3Zc2R2zFtUXO3kw8DhjDfc89aOW+hFHgTv7C6tqPaYKNhEKUg+Bt4218q88X6/YWejyqQQPXlT7NpwgYT4ePWemXGl1cnucFWkJndWWIN+DUlYYB/C6FgEMwKJlZsKGe6B18xlQvHkyKTscCcZTN7lki1uacWmZ2ohgRaTApmNR0F6BC4xYSHwySnCByRPuhvgH7QolN0sr6cgIGYv5+Qzw019e2a8rvmqsVsRZUhg2RyzEm5Cw1LPfdtFS+uRFKZHEA+13z1nThaig8gHY1Vz7gCuEqxdWpHk1RTqJnnWkItJsa3bqDJcP0HL/moM73isF/k6ELkxIb6177Z/XlITiaeQGIqNm7hYNni/lbKKIGoI7l1lIqkM+hbc3ceQzRZvUXpiC/HH+lN25rS0h2OiN4bpyHFYcrUf2lTw60TgOMkcT88yhiiUwE8a+LhahF1LmripA1AfPHZBPzU/eGqTDXXLKWXEDZ9lQb/QSFvwbaG1TM0+77JcazAQP9nW9Z4pJ8IzXD0A4GlTfRw/z0NrcDUAl4mlIt6vZ5LpsfGOOidxK0uasrdFZcffV2CZLZP96HFK3uZiX0G1TH40iITbj0iKr3tFzRW/ILm8euyIRdtCcx0Oe8/fOzKoPSsRo7MBlXaOHObO9u1ILVoekTb7znsuXd9XgBZkPne6k+LPouz5DxasCdZArJqGRZT0jz+1qfJ3Nv9oVdUEhKWZG10kvR2Ek5HDB7NTR73qOzol9AB/GxnW7+G/xHYMyfQfxr3BgYizVbl3T707nHwphmdIWRVwhYnQUPLPz07L2wJq+X4O9/cmQYYVzdN0IbFlxo/iDel0BgL4s7547zUUPnr1kYR3P6xgi86hHfMTEG6MK5jPGeosPZn5bQJbJ X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2024 21:24:12.1924 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e9a498e-6751-4b7e-3a22-08dcb339742c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7758 Reorder include files to alphabetic order to simplify maintenance, and separate local headers and global headers with a blank line. No functional change intended. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 4 ++-- drivers/iommu/iommufd/fault.c | 4 ++-- drivers/iommu/iommufd/io_pagetable.c | 8 ++++---- drivers/iommu/iommufd/io_pagetable.h | 2 +- drivers/iommu/iommufd/ioas.c | 2 +- drivers/iommu/iommufd/iommufd_private.h | 9 +++++---- drivers/iommu/iommufd/iommufd_test.h | 2 +- drivers/iommu/iommufd/iova_bitmap.c | 2 +- drivers/iommu/iommufd/main.c | 8 ++++---- drivers/iommu/iommufd/pages.c | 10 +++++----- drivers/iommu/iommufd/selftest.c | 8 ++++---- include/linux/iommufd.h | 4 ++-- include/uapi/linux/iommufd.h | 2 +- 13 files changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 2ac26a948987e..eaa1fdf71bb0e 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES */ +#include #include #include -#include #include -#include "../iommu-priv.h" +#include "../iommu-priv.h" #include "io_pagetable.h" #include "iommufd_private.h" diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index a643d5c7c535f..df03411c87289 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -3,14 +3,14 @@ */ #define pr_fmt(fmt) "iommufd: " fmt +#include #include #include +#include #include #include -#include #include #include -#include #include #include "../iommu-priv.h" diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c index 05fd9d3abf1b8..bbbc8a044bcf7 100644 --- a/drivers/iommu/iommufd/io_pagetable.c +++ b/drivers/iommu/iommufd/io_pagetable.c @@ -8,17 +8,17 @@ * The datastructure uses the iopt_pages to optimize the storage of the PFNs * between the domains and xarray. */ +#include +#include +#include #include #include -#include #include -#include #include -#include #include -#include "io_pagetable.h" #include "double_span.h" +#include "io_pagetable.h" struct iopt_pages_list { struct iopt_pages *pages; diff --git a/drivers/iommu/iommufd/io_pagetable.h b/drivers/iommu/iommufd/io_pagetable.h index 0ec3509b7e339..c61d74471684e 100644 --- a/drivers/iommu/iommufd/io_pagetable.h +++ b/drivers/iommu/iommufd/io_pagetable.h @@ -6,8 +6,8 @@ #define __IO_PAGETABLE_H #include -#include #include +#include #include #include "iommufd_private.h" diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c index 7422482765481..82428e44a837c 100644 --- a/drivers/iommu/iommufd/ioas.c +++ b/drivers/iommu/iommufd/ioas.c @@ -3,8 +3,8 @@ * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES */ #include -#include #include +#include #include #include "io_pagetable.h" diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 4a23c675ddfda..3f4ba3181fe91 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -4,13 +4,14 @@ #ifndef __IOMMUFD_PRIVATE_H #define __IOMMUFD_PRIVATE_H -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include + #include "../iommu-priv.h" struct iommu_domain; diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index acbbba1c66716..f4bc23a92f9a2 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -4,8 +4,8 @@ #ifndef _UAPI_IOMMUFD_TEST_H #define _UAPI_IOMMUFD_TEST_H -#include #include +#include enum { IOMMU_TEST_OP_ADD_RESERVED = 1, diff --git a/drivers/iommu/iommufd/iova_bitmap.c b/drivers/iommu/iommufd/iova_bitmap.c index b9e964b1ad5cc..d90b9e253412f 100644 --- a/drivers/iommu/iommufd/iova_bitmap.c +++ b/drivers/iommu/iommufd/iova_bitmap.c @@ -3,10 +3,10 @@ * Copyright (c) 2022, Oracle and/or its affiliates. * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved */ +#include #include #include #include -#include #define BITS_PER_PAGE (PAGE_SIZE * BITS_PER_BYTE) diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 83bbd7c5d1608..b5f5d27ee9634 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -8,15 +8,15 @@ */ #define pr_fmt(fmt) "iommufd: " fmt +#include #include #include -#include -#include +#include #include +#include #include -#include +#include #include -#include #include "io_pagetable.h" #include "iommufd_private.h" diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c index 117f644a0c5b7..93d806c9c0731 100644 --- a/drivers/iommu/iommufd/pages.c +++ b/drivers/iommu/iommufd/pages.c @@ -45,16 +45,16 @@ * last_iova + 1 can overflow. An iopt_pages index will always be much less than * ULONG_MAX so last_index + 1 cannot overflow. */ +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include -#include "io_pagetable.h" #include "double_span.h" +#include "io_pagetable.h" #ifndef CONFIG_IOMMUFD_TEST #define TEMP_MEMORY_LIMIT 65536 diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index f95e32e291333..b60687f57bef3 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -3,13 +3,13 @@ * * Kernel side components to support tools/testing/selftests/iommu */ -#include -#include -#include -#include #include #include +#include +#include #include +#include +#include #include #include "../iommu-priv.h" diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index ffc3a949f8374..c2f2f6b9148e2 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -6,9 +6,9 @@ #ifndef __LINUX_IOMMUFD_H #define __LINUX_IOMMUFD_H -#include -#include #include +#include +#include struct device; struct iommufd_device; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 4dde745cfb7e2..72010f71c5e47 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -4,8 +4,8 @@ #ifndef _UAPI_IOMMUFD_H #define _UAPI_IOMMUFD_H -#include #include +#include #define IOMMUFD_TYPE (';') From patchwork Fri Aug 2 21:23:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13752006 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2073.outbound.protection.outlook.com [40.107.243.73]) (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 94CE91304BA; Fri, 2 Aug 2024 21:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633864; cv=fail; b=nzagPcAPK35kJdGjhfJ66Z6wnhqjR0ZkjD0ivCXSMJXQT5prCsJUCpDc7wOBQPUXi74BVaj5hMMe8lBpcY2H5m0AMLEl6TuyYKOeJpjaxcYBZkSPVnMyleqUnTwMdueAqfP7pZ0URAYLIa7JmvOI0N28qdzeSRrrn0LNT9TYuj0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633864; c=relaxed/simple; bh=6uA00BK2lf+Z1ga6tKxs2EdKKCLkYre2/i5yDGFhhw8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UoAAy1SdZpmseLiDdMTaMFhmHUVAhhL/s6EikIKNWBmjpkMNjxgFi1k5EA/dN1EWUl1q9YFw8JOdZrfZnlg3m2bpWXGCQjndBTLHILOR6mQFC+jYGFDXKe0PpelGNZIhNaJmYd6f/QzWowA62ol6RFtefffT3bGA1cAGwzAwc2o= 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=KbY2VhOp; arc=fail smtp.client-ip=40.107.243.73 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="KbY2VhOp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yK7LDstZAJG9xFQUlyK/XkS4a+Nsb6t8NDH0srQOea8HASZZOkjjvk684iJQoTmRQip8TVdLouYHdZyjLn9HTopDT21VONyljyWcs+WNYShyMLSJuuoN9NPh3lZMZYQAs3d7TxzUH/dxnuilhnJk1flrCgNglHSw0gIwbq2haKlCCxmEp15lIpH/L7e6ZXQEZL7aaBMYSozqDHHbExSDLtK//8+EMpSWERR/c8R7Z3xxJ/+8jPopw6bCt9htPnfpc1yxOSkW2Kado+hEbXkfzkYu3qmJyn+0Afo+f1N982uptEhDrH7wEbzircV/TCCVZmYFb6DPm1sD2Q9l6BiZyw== 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=D20G2M+aQVUdKCMe81xyHdP4RUwPObZi/qMHmlpzZLI=; b=ZC2Quot1ErymglTInZLKke48wui9MyPG1BalBQTSvmwqfb9vgQ3ICPF+u0t0mcpIKt8Fd4MN8LeHZowEfER9/QhGxcQZqnLzzNHECrJT84GYTbjXuN1uWM73O8VRnzpsK2bF7EbbjiI/pC37seerG14tH7lnAt0Y4wR8OHLsA731v+U1sHoTnIWP9/LDj+L1f9uhNmrrx+mvO45B6a1aice9CSDCj9I51KFlE+7UWyGOHx19ZlKbQr3+r5MhlQLEbF425CoMmb7HhW6dUhL4DCpEymAYwnohJyIxxMMsB2zzUm/MYsiHnc7IlZGGr8ZC4EK2Qcv2ib5so29blXFX0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=intel.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=D20G2M+aQVUdKCMe81xyHdP4RUwPObZi/qMHmlpzZLI=; b=KbY2VhOpk0sPtwvb8Q0E68eB3kkUzaoYeVsSys1pnOuEFFKegKwqCgD0d1KyVjguo3CXtmrdNukmXjGgxBCZR0LoGk691wY7aL9tUxfjbtNiyRPW/wWgwBdF1s/2PT/yX88YH4Duj6csP6bgdfX2V2ZIHxpNrRqubFGvCuXXvSPH9CzIKK3bfM6w32MAjFVZHL1FNl9uVAcYIBzpoIM76PysQxRCnTzOFGdMd3qjW59z1t0KN+aC0fbpgNJ/v+igl35fTMDOGpX4YngZiK4YsPhJed1FnixS22KiLuaT6kX53N76iiDrcXFqvRQib0VkinKyr1cJulhGpoYQ/tseLQ== Received: from SJ0PR03CA0170.namprd03.prod.outlook.com (2603:10b6:a03:338::25) by DS7PR12MB5910.namprd12.prod.outlook.com (2603:10b6:8:7b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Fri, 2 Aug 2024 21:24:18 +0000 Received: from MWH0EPF000989E8.namprd02.prod.outlook.com (2603:10b6:a03:338:cafe::e1) by SJ0PR03CA0170.outlook.office365.com (2603:10b6:a03:338::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Fri, 2 Aug 2024 21:24:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000989E8.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Fri, 2 Aug 2024 21:24:17 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:04 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:03 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 2 Aug 2024 14:24:02 -0700 From: Nicolin Chen To: , CC: , , , , , , Subject: [PATCH 2/3] iommu/dma: Support MSIs through nested domains Date: Fri, 2 Aug 2024 14:23:47 -0700 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: MWH0EPF000989E8:EE_|DS7PR12MB5910:EE_ X-MS-Office365-Filtering-Correlation-Id: aa4f4f54-2082-423e-8790-08dcb3397737 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: H2/VEkasjSedopH/eBbEQ7qMsMBWPBisH+AdLhUzWTqMOkrnVKfFRWLKLyYTp7SVFX3Urwsnj9+/1fPSgbU6e2/qdj1HeqHtZdCNfGINgRirJdgjqpv/oP6GbKD6Kv5DZIvwIrONMGT1wH0OMcffe1La7dwFpKsDjXro9pJSLLQtyobR47yIAzdEl4buFkDd09UGYTvTGKRZxUZNFNPDG78dyvdSUyzM1Cyd7PK7IGNVcjM7T5DaxhcCK7xyPP4yX4Gs21cN5Zgh+Fy9DsvqxNsz0xNokpBLCT4LbkSUUmVRm2nf8IMZanxl9ETEGiIj2HaQV4ItVmvKX1Pv2jCP1DcT36sPfc7RAbIo3qFeXCsu17OqtC59eKbGNQCfaY4fugu3i1Lk0O5zc7RkWGhuDybRxriaM002D3M6Iuo7tzWyD3vUtFIaKF54Eq+zx3KogC+ZX2Xf0WtrcSOsAI8difb5H83Etb02HyYjN7QBH4idb3lRQrb6dS9FVVTMP8K3x+3k2X2PsDATowLh/sAxkQhExfanZOoB2QowFgtFhGc27KeK/3ZyqWta6V0ATaqYFTOsSDnXqr2WoDsfqAfdD+aVRCCjn9LhIil6NpzCayw0QPylDNDKzBNDBcDwEKF74XonsiEsJZynkPqxpalNrr+t5nbRnCkJXK+p5+NwpIMU3kJhHVXIQXxP/Qj0pHLcoPrrBH7lmSiGWo6zaGDc3z36A3s7D1hNxb7vMIRPS2UJIPFxrNFYVdH8T+auUqq7hpNxUhOxfggSfwPpAc1xDBJiBH7hBVpDCK3sdINvylsnJW7EKhWHYgWqLU+OoYIHSV+NQA6Pd8ftqeXuh7D7WnFcxtjJL7I/zas9UVkCOacECkIiPhMSxxGOb37PN6T46fsTFLFg6x7b0JtiWK6M0+nqIXMtnekVEEvxHZy5tGEQioO0yuuVFU0yvAPgdZzcgBykSwzyhrwAzZ8KG+jVrL/koEff5JOTJd50WqRMm25DnuXPORBbBfMT6IZ5cPvmQKobOlGhG7CAR0Cpl9VbMQV4yYhfIjTy02KXz7PZIKLovwsdEJ9ptJWG8bBVg93wqUHrsh6KHHThNyflPdq41ZlpaB7geitikTT60DFrN9k1re4zkpIxWoiUN5SeXVPaFYXkHyhdlMLlhoAUtIwZsYXqSZOP3aqIbcsWIgLHND0aQruvt9DmcoccRWlKQjNZzDN5vw8Zgg1P5SX5iGDWr0rFl2iylrvJ7CF23IhMev2JcMM5piavqbE7IG8/tbMkFRs8UlWeqaqi3xKO5CPZDzAE5WGsvfrg68ZoHIPDrr1ffrIWxr4j3th8M3E4BWxrnVlW9ouAoLuWHAUKR/CfyOYfhpF+dQxCwLiIjnvUB3kKwW/CNHTKCQ2JGTXtGDW/GYSB+gd6ellrLvoXqrKs1PZnhURqfys3uJqBfnE8dEb1kDCJLFyaPJeQ1pYm5oYw X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2024 21:24:17.2840 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa4f4f54-2082-423e-8790-08dcb3397737 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5910 From: Robin Murphy Currently, iommu-dma is the only place outside of IOMMUFD and drivers which might need to be aware of the stage 2 domain encapsulated within a nested domain. This would be in the legacy-VFIO-style case where we're using host-managed MSIs with an identity mapping at stage 1, where it is the underlying stage 2 domain which owns an MSI cookie and holds the corresponding dynamic mappings. Hook up the new op to resolve what we need from a nested domain. Signed-off-by: Robin Murphy Signed-off-by: Nicolin Chen --- drivers/iommu/dma-iommu.c | 18 ++++++++++++++++-- include/linux/iommu.h | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7b1dfa0665df6..05e04934a5f81 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1799,6 +1799,20 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, return NULL; } +/* + * Nested domains may not have an MSI cookie or accept mappings, but they may + * be related to a domain which does, so we let them tell us what they need. + */ +static struct iommu_domain *iommu_dma_get_msi_mapping_domain(struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + + if (domain && domain->type == IOMMU_DOMAIN_NESTED && + domain->ops->get_msi_mapping_domain) + domain = domain->ops->get_msi_mapping_domain(domain); + return domain; +} + /** * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU domain * @desc: MSI descriptor, will store the MSI page @@ -1809,7 +1823,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) { struct device *dev = msi_desc_to_dev(desc); - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct iommu_domain *domain = iommu_dma_get_msi_mapping_domain(dev); struct iommu_dma_msi_page *msi_page; static DEFINE_MUTEX(msi_prepare_lock); /* see below */ @@ -1842,7 +1856,7 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr) void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg) { struct device *dev = msi_desc_to_dev(desc); - const struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + const struct iommu_domain *domain = iommu_dma_get_msi_mapping_domain(dev); const struct iommu_dma_msi_page *msi_page; msi_page = msi_desc_get_iommu_cookie(desc); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 4d47f2c333118..69ed76f9c3ec4 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -638,6 +638,8 @@ struct iommu_ops { * @enable_nesting: Enable nesting * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) * @free: Release the domain after use. + * @get_msi_mapping_domain: Return the related iommu_domain that should hold the + * MSI cookie and accept mapping(s). */ struct iommu_domain_ops { int (*attach_dev)(struct iommu_domain *domain, struct device *dev); @@ -668,6 +670,8 @@ struct iommu_domain_ops { unsigned long quirks); void (*free)(struct iommu_domain *domain); + struct iommu_domain * + (*get_msi_mapping_domain)(struct iommu_domain *domain); }; /** From patchwork Fri Aug 2 21:23:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13752007 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2088.outbound.protection.outlook.com [40.107.92.88]) (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 0AFF5130A7C; Fri, 2 Aug 2024 21:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633865; cv=fail; b=eqgEH0GYXk53xKq09SL0cSWQkhE148aBvoUpQx+lS4GSXMXsO3zN7JRk7YJqyILjySw2IP5lhCWeYNBGENMxf9230y6KAWSNT4dt6+P2d7nAokq046FnzzTQ8MVU2N7UCqBZVvn+5gqkC9+Jys4FSke43MOp52GXbFDC7+O0nS4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722633865; c=relaxed/simple; bh=d8FzJLWfmZr7crqDkuXTNYPepxZkVYCDvmqTXq2I0sg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p4TjHSmN7tkPQ76b/5TF19WIFYhLM0zDHw+FI2GXvBvaYJki18UitUwnudxvBPINQ+G2o7Q9Y5EhBD/KgvtYQIridIcczgbKeAwjWMWScUD6uN7vRS0E/qtZZI94B/WNUXNRtWqUcVVN/cKkYEss+N7OO42toe9lWM6v5nmMcrk= 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=ryyDANbx; arc=fail smtp.client-ip=40.107.92.88 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="ryyDANbx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HIa54EIaJvtKVCsa47IVuffxYYNFOMt5uRBM7q9vTeq5IM4BhQz4EDq3hoymY2oeWnyoDU7b40u/7znMgthZBUPuK4vWMr5VFYBRBufIY4bnIawd7ciWCjuSTSJrs7QtEqdSoP8EUm9Oepqsm45YhAfZ2Gz7/GEGFw9KWzZWo072kg9wE5tiwUcAmUjIUlJuTDpfiwqY/5sRzcKYa3x0LjoZF+jV/l7dzCY+u1I/VHhMjZrXo8wmSMBBJgM+TqdiciL69P4Hpuz7LakEVH2AdB81L3+N7Jf2bFHbu4iYdqRuuyOmJMrEc6KjiblfAyHu0+0C6zHkVEbZm8GJR+4wag== 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=bLD1uSGDj5q41eX1MX6FQnqUcRtuaIH9gQWuG36ffVs=; b=l7mosx8oXyeNcLEPAGjZ1zz/+xD9W8I1GaxSp5H7hOuke+fOxjZk3ChRe0pVOqGoMWahlEanXDN7xNfWBWci/U04U3VA+B/vazle4cRcR/D6CWI3bMaZx9px9dSdxFLYx+WPrsAKcoP4XVcRiU7wD0g1pfuxPVZ3bNmWl3C09kSCf4dESuMkcmfwacBK3CaTNFVXv8LIdmjKpb2MQaRZkSIY3w+Txfa0I9d4V/4TCYabLMG8qfa3P5c5lgGMD57j03TIaKLNOqZUCeZXWvlt6jPdLVh9Iycv3fuCRBpU2Fs0FCyza2NyXfFoSmOgFmITbiuteZzYgaHJax8NL7VDkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=intel.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=bLD1uSGDj5q41eX1MX6FQnqUcRtuaIH9gQWuG36ffVs=; b=ryyDANbxhppPbOTkEfAxGNRYzbnixDKbhhDgvexJ3P18cHLhE6r/FJyoiF9zNqYlsc/QRomBwiTn5yCIEyEFHIQm+GZeyzbicFvFy8FH3jvsSFBIvQ9vFY3tDfKp0klkgfbbh+UKYKSjXJMaIH639HKNmxX6rX6nrJ1eCYCqHWwUfOnYZ2vGWwh1AxrCzt9GjLtgqenoduVbN0owK57OTBoWMZ+fzKJCQyThTky/8WWQz/57D/euNR11oS0fkv6f3it7tBMQq/UDx/fKfyWiE8fqJ2kafgjAvR1h3rTDQeOvA/w0R45URtQ4Xav0GEhld6MoMgC1szvrgyt28sw26g== Received: from SJ0PR03CA0154.namprd03.prod.outlook.com (2603:10b6:a03:338::9) by MN2PR12MB4288.namprd12.prod.outlook.com (2603:10b6:208:1d2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Fri, 2 Aug 2024 21:24:20 +0000 Received: from MWH0EPF000989E8.namprd02.prod.outlook.com (2603:10b6:a03:338:cafe::91) by SJ0PR03CA0154.outlook.office365.com (2603:10b6:a03:338::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Fri, 2 Aug 2024 21:24:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000989E8.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Fri, 2 Aug 2024 21:24:19 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:05 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 2 Aug 2024 14:24:04 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 2 Aug 2024 14:24:04 -0700 From: Nicolin Chen To: , CC: , , , , , , Subject: [PATCH 3/3] iommufd/selftest: Add coverage for reserved IOVAs Date: Fri, 2 Aug 2024 14:23:48 -0700 Message-ID: <68e3341f9e993b2a248d96f7fee5104d485d4a03.1722633199.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: MWH0EPF000989E8:EE_|MN2PR12MB4288:EE_ X-MS-Office365-Filtering-Correlation-Id: c2372a5f-00b4-41f8-3e9f-08dcb3397872 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: 5EJUABCraL801MHRwxZ8OP/0SHyn0GkHpj7An/Jx3mUiDw8dn1o+ML6lqzzF3ILZHYKJ5fIlBagIc6fsIt/kDoUJ0D5looOR+HHvtnfjzxxYl/VXMIvp9x7K/k0vTq+8LDk3OzKTtz5JJ2WMV/+rLB7sviZDrdoTMhmivuZez1xOOsUjOfx7VcEUrNaDD2c29fHGgASezNsiuEgk2mFOAelHjeCblmFqV7NYW+kG9TYEebkKutpCyYsj4UwBaVySEkbB2YFWgS4uaRH6X5UsHlEv5jP5osQU6Ey9obwf8npo414Lz087XeCFealPJwMP4PJwE/klGp2vekeOwBeyaHkMTtoMDoizCoJpCQRJBWJAJzHzpuxk0LAwtV045jzmBbkWfg9yzblmkky4CVizuFTDXHnqObq1VdFrvmG8ukI7Xe+WemMwumHq4Gq0rlMN6AwOHBelpTYII1aiyDaWDgi85uuA/38CHloIHtSFPHU7ZehtSJuEBtfLbRV6t7cZVxwpJ9Xjxiw9weO4LBpa1IaVgBuk9wWRIq3xM64VBOBeJda130+8CK7/DbjOgW6jl5/mBQDh9DJjToBjBc1zD4FL4YBokEPmvN/7zeD3GNYP1jW2nD6Xw/5f/3IJIDU1MTipZxi3KA+0/A2B100g3EOXjI49wK7W5w+FH4u29EaNZPUsRbjyJLNSzkzUlC208XxiGsvpSwgTRyssLYnkzUPWVxGJRzkVXIpJBKE5PfcaK3SLPd0NgQLiookwiGVAlidJKsCBLnMUI6QWpDJwM3C919h9uDm6X8z52MwfMxsTTSNMdrkejz1lBov6tNhWe2CkyjyUxxn7YUoiWGGZa2ZkB4qiIIUjYDyTotiYnEpKyfl0v/6BmvCpar2gvyluHVegTIEZu1c5VS7V2mo95svoa0LKzoaYTqekWD1DkO3FZd1+R87EtQWDB20BAdO7IN2u/kPlt75OsF0ZJFyoNd5zY4xfPvuZyrLk0QixomTiBTaj0UoqSvn+I6urJXHPcXhSpPcqSLMj+s2f1Xb1oGgrJc1AUoQLXdIBAy5PTXROHa/fAhP40OW0qQUqcWv4jh826eIYhwc0zC/PaTG58Z3QwZ9kA9P0hay8Cti6zTzbMMaFi0fNfu07MmvZ+G0PZBQAuDJOprH2VVWo4H0iC52LKHo/aJjlPvPyU98a+NjgeBJHTeRbx3sC/GDvLndCRjzxiiurA8PH5lgGXw1EfTqJ0hOWrYKgi6LrRSC3iMC/RbI376ecJpLUwbeBkwHAdo7H6bKJmQ+q40+JwbVD6YDqOMRUv49ERZXPIXjuHOKY2/0yVOAB4Jc6LgtHqwOGdTWUjaUM4Z+PCBPc97Lpo6cCxQncgN7Dz/x94llfd+5y6KzCDZWoxJ4NRGixUrnyDGCY88WgwkUlkjNt6gJEWYRrogx4QktX8oE6cr/4Rl8LBRdCZ5UhN4OGQmIu5cnh X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2024 21:24:19.3466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2372a5f-00b4-41f8-3e9f-08dcb3397872 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4288 Define an IOMMU_RESV_SW_MSI region (within the mock aperture) as the ARM SMMU drivers do. Implement the get_msi_mapping_domain nested domain op to allow dma-iommu to find the correct paging domain. Add a new IOMMU_TEST_OP_MD_CHECK_SW_MSI to loopback test the MSI mapping using public dma-iommu and iommu helpers. Note that iommu_fwspec_init is a must for iommu_dma_get_resv_regions(). Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 4 + drivers/iommu/iommufd/selftest.c | 78 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd_utils.h | 9 +++ 3 files changed, 91 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index f4bc23a92f9a2..0bb30275a92f7 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -23,6 +23,7 @@ enum { IOMMU_TEST_OP_DIRTY, IOMMU_TEST_OP_MD_CHECK_IOTLB, IOMMU_TEST_OP_TRIGGER_IOPF, + IOMMU_TEST_OP_MD_CHECK_SW_MSI, }; enum { @@ -135,6 +136,9 @@ struct iommu_test_cmd { __u32 perm; __u64 addr; } trigger_iopf; + struct { + __u32 stdev_id; + } check_sw_msi; }; __u32 last; }; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index b60687f57bef3..5fa8d204bb098 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -7,11 +7,13 @@ #include #include #include +#include #include #include #include #include +#include "../dma-iommu.h" #include "../iommu-priv.h" #include "io_pagetable.h" #include "iommufd_private.h" @@ -539,6 +541,24 @@ static int mock_dev_disable_feat(struct device *dev, enum iommu_dev_features fea return 0; } +#define MSI_IOVA_BASE 0x80000000 +#define MSI_IOVA_LENGTH 0x100000 + +static void mock_dev_get_resv_regions(struct device *dev, + struct list_head *head) +{ + int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + struct iommu_resv_region *region; + + region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH, + prot, IOMMU_RESV_SW_MSI, GFP_KERNEL); + if (!region) + return; + + list_add_tail(®ion->list, head); + iommu_dma_get_resv_regions(dev, head); +} + static const struct iommu_ops mock_ops = { /* * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() @@ -557,6 +577,7 @@ static const struct iommu_ops mock_ops = { .page_response = mock_domain_page_response, .dev_enable_feat = mock_dev_enable_feat, .dev_disable_feat = mock_dev_disable_feat, + .get_resv_regions = mock_dev_get_resv_regions, .user_pasid_table = true, .default_domain_ops = &(struct iommu_domain_ops){ @@ -625,10 +646,20 @@ mock_domain_cache_invalidate_user(struct iommu_domain *domain, return rc; } +static struct iommu_domain * +mock_domain_get_msi_mapping_domain(struct iommu_domain *domain) +{ + struct mock_iommu_domain_nested *mock_nested = + container_of(domain, struct mock_iommu_domain_nested, domain); + + return &mock_nested->parent->domain; +} + static struct iommu_domain_ops domain_nested_ops = { .free = mock_domain_free_nested, .attach_dev = mock_domain_nop_attach, .cache_invalidate_user = mock_domain_cache_invalidate_user, + .get_msi_mapping_domain = mock_domain_get_msi_mapping_domain, }; static inline struct iommufd_hw_pagetable * @@ -701,6 +732,7 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) return ERR_PTR(-ENOMEM); device_initialize(&mdev->dev); + iommu_fwspec_init(&mdev->dev, NULL); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; mdev->dev.bus = &iommufd_mock_bus_type.bus; @@ -960,6 +992,49 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd, return rc; } +#define MOCK_MSI_PAGE 0xbeeeeeef +static int iommufd_test_md_check_sw_msi(struct iommufd_ucmd *ucmd, + u32 mockpt_id, u32 device_id) +{ + struct iommufd_hw_pagetable *hwpt; + struct mock_iommu_domain *mock; + struct iommufd_object *dev_obj; + struct selftest_obj *sobj; + struct msi_desc desc = {}; + int rc = 0; + + hwpt = get_md_pagetable(ucmd, mockpt_id, &mock); + if (IS_ERR(hwpt)) + return PTR_ERR(hwpt); + + dev_obj = + iommufd_get_object(ucmd->ictx, device_id, IOMMUFD_OBJ_SELFTEST); + if (IS_ERR(dev_obj)) { + rc = PTR_ERR(dev_obj); + goto out_put_hwpt; + } + + sobj = container_of(dev_obj, struct selftest_obj, obj); + if (sobj->type != TYPE_IDEV) { + rc = -EINVAL; + goto out_dev_obj; + } + + desc.dev = sobj->idev.idev->dev; + rc = iommu_dma_prepare_msi(&desc, MOCK_MSI_PAGE); + if (rc) + goto out_dev_obj; + + if (iommu_iova_to_phys(hwpt->domain, MSI_IOVA_BASE) != MOCK_MSI_PAGE) + rc = -EINVAL; + +out_dev_obj: + iommufd_put_object(ucmd->ictx, dev_obj); +out_put_hwpt: + iommufd_put_object(ucmd->ictx, &hwpt->obj); + return rc; +} + struct selftest_access { struct iommufd_access *access; struct file *file; @@ -1470,6 +1545,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd) return iommufd_test_md_check_iotlb(ucmd, cmd->id, cmd->check_iotlb.id, cmd->check_iotlb.iotlb); + case IOMMU_TEST_OP_MD_CHECK_SW_MSI: + return iommufd_test_md_check_sw_msi(ucmd, cmd->id, + cmd->check_sw_msi.stdev_id); case IOMMU_TEST_OP_CREATE_ACCESS: return iommufd_test_create_access(ucmd, cmd->id, cmd->create_access.flags); diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 40f6f14ce136f..ab9fa5ea48915 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -130,6 +130,14 @@ static int _test_cmd_mock_domain_flags(int fd, unsigned int ioas_id, static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id, __u32 *hwpt_id) { + struct iommu_test_cmd sw_msi = { + .size = sizeof(sw_msi), + .op = IOMMU_TEST_OP_MD_CHECK_SW_MSI, + .id = hwpt_id, + .check_sw_msi = { + .stdev_id = stdev_id, + }, + }; struct iommu_test_cmd cmd = { .size = sizeof(cmd), .op = IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE, @@ -145,6 +153,7 @@ static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id, return ret; if (hwpt_id) *hwpt_id = cmd.mock_domain_replace.pt_id; + ASSERT_EQ(0, ioctl(fd, IOMMU_TEST_CMD, &sw_msi)); return 0; }