From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86DBCC71141 for ; Sat, 14 Jun 2025 07:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UyToRfTFW9rmOaY+RN8l8tu0oh4F/0yijMIbuQNZFdI=; b=TNMz0zdlev/wS3x0JCBvN0J49q AdBp+wVG5cGg0Ri029LMObXQ0+y7Rkmmwm0I0+qXc5lFZ6FcwqA3uspwCzCLWpfkoGLBVDPYOjRvA v7AiCM/8JVL6ygLTDc65vfVYp9JNXpHdLOsaDO8CYSXeH7SFj7EGGXdFULHQ4QsVGhfm+/lR/ZCxu Yi6HMi/BkBNNS/EumIqb6zFNk0FUy+KiwLcfB5iKdcCNj8QHeEkoiwATjc7BvjLvoMNSLze5p4k1y sS5UBq3/nCUksPMqSSv84HoX/kPjk9C1ShHTaLeNEIa5M7voq535QbE6D5Go5qyHGY8Z0iLNRegyK HNsNbNnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQLBI-00000000sgd-3wxR; Sat, 14 Jun 2025 07:20:00 +0000 Received: from mail-dm6nam10on20621.outbound.protection.outlook.com ([2a01:111:f403:2413::621] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQL6l-00000000rCP-1FB5 for linux-arm-kernel@lists.infradead.org; Sat, 14 Jun 2025 07:15:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F2ShUNOx4HQj2QVFc0ZHZbhZkU2nmxGT/UfU66j4aatMXKQFu57t0Sj7ocT5SbeT/OEev8sRs3RPYQkE7b3z26ar8vePEUu7u/z0a/0tPmkSblCJYW1FNbKT66dAq7E/SYoduq1OCqYQIBunYUP53M2rCGbtdg+O4dq+Wo7o76kVcLd9uh262j00sF1HWipThiarEgrK9iWGJxU/8nn8pobJD/s7YlHgPN5egK5ihFV6tSVMXQCT7/V6T4OXC+rmEOLdT90YZckG4wRtglz3bvEfQjAzck6ZfnUlVecRw8/rtZ+CW+tl/mWnHn5htuWDk4WxeLV73xtfpo4xaZkNig== 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=UyToRfTFW9rmOaY+RN8l8tu0oh4F/0yijMIbuQNZFdI=; b=bIQ3FYmrhYD/E9/A5aHQo75C1snjKASoWe9+Z3sZAOnn8ZlTld35Bed+KofZPl/Ye9ad0aIwDeK+BxQz1qQMJJlxtbaCPa5l2xA1rB/T2z1wEoaH37tZRpAAJ0Dud7mm1Yw9k9tJRF2EZlt23aonpxiGv7r9IflUrn7ShVf9G0sQLCxETpJCBu7ZZ6y9dG37gD0fTSsB9t3dhv9X1n9MQoXDu1EZ4wKrUgCQrjSL3isdoO+ogrbLs9gVH+86kXlVfbFUH+k/5CVnMLbDpOQzMDHqVxqLsOogadEjWE4xegJXJPKdkkKous3YAmK/9MHtD8RRG6kX9HzccqMnwb66ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=amd.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=UyToRfTFW9rmOaY+RN8l8tu0oh4F/0yijMIbuQNZFdI=; b=oz9/57Y77wvaHNH3nxTuEzdYNAUOYTYmXJnj4v19YDVQx0bdPkWYWVhfC0HEvfzfON0asrykuCvpDbMlqzT9RSrv3JmPcnaIhB33VMqZLzbs9UYKpD1PUgtO9rOhRZR8QAxbUuSqFIspaBdurND/A4VAARI8fmuWxxr9eBCeUrqDYRmHB2B3uIuwiHzd2t2RSDsbfYgNiinjyPSYicLeWeuNQ9gIPt26VKG6JA5GwYNNQhQMhdba2EKX3aCz+J5tVFdV8L5i0OUqKyeXxHBDE5HEc+8EV+4Lls7LddrUrSInq2PCcrueUFI8OKZVUmKNtClIr+sZd3QD2X42/3vzWw== Received: from SJ0PR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:33b::18) by CY5PR12MB6478.namprd12.prod.outlook.com (2603:10b6:930:35::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.18; Sat, 14 Jun 2025 07:15:08 +0000 Received: from CO1PEPF000042AA.namprd03.prod.outlook.com (2603:10b6:a03:33b:cafe::37) by SJ0PR05CA0013.outlook.office365.com (2603:10b6:a03:33b::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.16 via Frontend Transport; Sat, 14 Jun 2025 07:15:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF000042AA.mail.protection.outlook.com (10.167.243.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.15 via Frontend Transport; Sat, 14 Jun 2025 07:15:07 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sat, 14 Jun 2025 00:14:57 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.14; Sat, 14 Jun 2025 00:14:56 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Sat, 14 Jun 2025 00:14:55 -0700 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 01/25] iommu: Add iommu_copy_struct_to_user helper Date: Sat, 14 Jun 2025 00:14:26 -0700 Message-ID: <7428b583d360eec09e4fd11029638426bbcd98f1.1749884998.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AA:EE_|CY5PR12MB6478:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ed6fccd-6309-4bd2-59e6-08ddab13315e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Q39Ke7AwlA0F5To3T/hjTMbrKsCL8XVPT6F+EhN/HuARPDDWP59rs1KMTevC?= =?us-ascii?Q?HrCD0EhHpzIB282swyX0tAn/b+ZhyWyE2v3353KZcJF0468fhJQo4if6x6sE?= =?us-ascii?Q?0L5Tn0RnjSqwkCVpH/Nm1LpF3ericVRM8zqSiWyNy6crZAgV9ZZ7vhAKxN3U?= =?us-ascii?Q?PlJouI5uFgSHQaKGbF88URSxfdmVdChV8s9c9jp1jtnLrVR3At1RaF6aU3U8?= =?us-ascii?Q?tkDDEhSOirwEBfook1LYMdRNPHOTXQLVdsoaUADWan8l5tQLjlFZPyYyKyvK?= =?us-ascii?Q?bcPePb0V/PIvVGWCs0UGejpn0UkuCsZsv7f6WHA+Az5Bn6DvSIPszgqqv505?= =?us-ascii?Q?U1k9V/xCoK9FjIyYQQQC8XUYH1YJr0zFBYubxnUa4SWd2RDQM2STX76fj0me?= =?us-ascii?Q?x25lwgqnVAkmNwJxd3OgfXIJ95L/QNF2y8IbopQRv+GhjaRqQWwgKwTy6fRF?= =?us-ascii?Q?CODxa+59l+3Iuinnor+vbsxHwWmnbG7xoSQlJgtEAc4l9jhEL2KklKfomwAS?= =?us-ascii?Q?K2OEWreTR9cI4ajXeNhVVXj6KcCGkhikVBuQrRGgSpw0nfUfvCQKmrVSUdz1?= =?us-ascii?Q?ejsy+nVGP9N+R3go4toJyyRIZAgTYpibHu9VdPYrLXTxeKOjttK6rYbm45CK?= =?us-ascii?Q?o2pM9hqkVgkDUDbFE6/PjGOQutHnz+A2KfaTF5faMCX9WBOyHXw0I+9Iw5Xq?= =?us-ascii?Q?b7gsjqA1gLcHrYHoplwx6nP4gzMY2vxI19udTICC8Papvo+7pSSKRGl9wUK+?= =?us-ascii?Q?7szhK6WFnDO3TmP4yUrD526tQkpGemvryr+XXf6c/N0DdyyI9J0ZYmnhrn+a?= =?us-ascii?Q?At50Zv94YAzUzvZtPFaegebGY04Iy7mNBBv7uXIrD/x1uR6yuPKkRwdPxdfi?= =?us-ascii?Q?u0PLt1MuVrI6N1cRTKA5LFi6ExcnPsSiFyZ2nW4WkY0eifmlwYKhzP3C6j/O?= =?us-ascii?Q?l/pyic1j6EVjxBRDB9YHSHrUyPd8QYKHn0ad225MKMgS8n8AFJW3IlRL5FLw?= =?us-ascii?Q?4MOaosVAfUamDdRqjjJ7ayWdkqCiGYXUDSRaOBGRr/uK0xTcu8h9OOmPCPxb?= =?us-ascii?Q?EsGnaORQ7sHCfTN7glC0OOgSQJ1X+JrQpimdvjMSEThoo8XodXVsExz1PH42?= =?us-ascii?Q?5H56oLPfvx5OKgB4EsKwjmqVcoAw0I+0zOXxmcG0/fkumrEoSZ7F4FlPy7MK?= =?us-ascii?Q?C8i0QbtiEIbjlh3buDUCnf1Q/MD6Z05F5jGR/KAQkYHpSWWNtu0vp8V80Mgh?= =?us-ascii?Q?4GL8a94ipFj6aPntRWLQPOA80gS56RWc+50EmysuSCSmUDhmhInbFF3e4PX3?= =?us-ascii?Q?zJCMQhHQwgGAZdC3k09xXmmuti3B8rE/9+m3BX/2DLwXtTKJLz3JHJWQWk7y?= =?us-ascii?Q?SCgi19M6vP5btAB9UBwQtP8YZCqfLhvCBnWSA5S02TizGiHQNRJxmSp3NLeF?= =?us-ascii?Q?GRxrAwQzqclJaiA7OmXI+zJN3BkxMBMDKk8lYrCTQo4k1g7Eigjm3xgVyT9t?= =?us-ascii?Q?KW5iZI0sqpjEzadQMnQ4Sa43e1z8RQvan/pX?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2025 07:15:07.6506 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ed6fccd-6309-4bd2-59e6-08ddab13315e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000042AA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6478 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250614_001519_331429_DBB03D93 X-CRM114-Status: GOOD ( 12.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Similar to the iommu_copy_struct_from_user helper receiving data from the user space, add an iommu_copy_struct_to_user helper to report output data back to the user space data pointer. Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu Reviewed-by: Pranjal Shrivastava Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 04548b18df28..36a43c6d8fdc 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -558,6 +558,46 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size, return 0; } +/** + * __iommu_copy_struct_to_user - Report iommu driver specific user space data + * @dst_data: Pointer to a struct iommu_user_data for user space data location + * @src_data: Pointer to an iommu driver specific user data that is defined in + * include/uapi/linux/iommufd.h + * @data_type: The data type of the @src_data. Must match with @dst_data.type + * @data_len: Length of current user data structure, i.e. sizeof(struct _src) + * @min_len: Initial length of user data structure for backward compatibility. + * This should be offsetofend using the last member in the user data + * struct that was initially added to include/uapi/linux/iommufd.h + */ +static inline int +__iommu_copy_struct_to_user(const struct iommu_user_data *dst_data, + void *src_data, unsigned int data_type, + size_t data_len, size_t min_len) +{ + if (WARN_ON(!dst_data || !src_data)) + return -EINVAL; + if (dst_data->type != data_type) + return -EINVAL; + if (dst_data->len < min_len || data_len < dst_data->len) + return -EINVAL; + return copy_struct_to_user(dst_data->uptr, dst_data->len, src_data, + data_len, NULL); +} + +/** + * iommu_copy_struct_to_user - Report iommu driver specific user space data + * @user_data: Pointer to a struct iommu_user_data for user space data location + * @ksrc: Pointer to an iommu driver specific user data that is defined in + * include/uapi/linux/iommufd.h + * @data_type: The data type of the @ksrc. Must match with @user_data->type + * @min_last: The last member of the data structure @ksrc points in the initial + * version. + * Return 0 for success, otherwise -error. + */ +#define iommu_copy_struct_to_user(user_data, ksrc, data_type, min_last) \ + __iommu_copy_struct_to_user(user_data, ksrc, data_type, sizeof(*ksrc), \ + offsetofend(typeof(*ksrc), min_last)) + /** * struct iommu_ops - iommu ops and capabilities * @capable: check capability -- 2.43.0