From patchwork Wed Aug 7 20:10:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756704 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 4BF91C3DA7F for ; Wed, 7 Aug 2024 20:14:11 +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=0HFa6QLMqlPOiy/eJ/OPp7DO2RpkYF0EwEmAbfXRoto=; b=cE7NMYRdatQMSEw2uiGmm8L05b itozND/ZiMswZ7JMACbXogkg2Zfwz20/2SLPK0HJnbpzhMqGI1rReDsaa3uwb+xRg+yN6ch/ekNxG Cye9v7hh7ZcHmd8vkunMPz9omYQ87NyM/Svs/AQi96JUGF511HLkht9RC3iL4ReeslAx+wACsnZ8+ 6/NHacM19Ho1Mhd2L/5wkSJoukojjn9c+GPjBpfuMbAXi5zkcHS4cgCKVAn49o1D8PixRcagh6sQQ pCDrTbrbl3KZ7QxZoUjbsVICK4lwyb8v/2b55LcLfhffmb6Y/riQjVpGJOUmCLGhZiY0o7P0qI3qC /sxXDS5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn2g-00000006A4Z-32zO; Wed, 07 Aug 2024 20:13:54 +0000 Received: from mail-bn7nam10on2061f.outbound.protection.outlook.com ([2a01:111:f403:2009::61f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0O-00000006988-1AFo for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r4PiXV3MW+qiOSSpxwRbQ4AVlEBsQ9ftqXaa6OSSRI9szzWucf6dixKF0gkjm/xTj8Nrn0y7k0IdvIZiP7KZSzqHTkEQutzeB4f9lePIHlVU+8aqRQZ+bXn2bMJ59VmEb1LzRetM4X1K1YWKDjafUc/DUQQODQrS3wHdyCr5K3jbZ0/ZBbDQ6NPJGeTrPyh0wwjr0hjtZ0vq9cTEQR7YNUWnxFrndsGRFnPy2sOMqlGCjup2Cu6ePRjEhBS0JowTltrdlRizDztpFfSKaKnndzxoBsGsG16P+LDSbSjtvuAmA4MRVDpR3TagyEf7SZpTXFmTi9PluutwajzFYfk2Yg== 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=0HFa6QLMqlPOiy/eJ/OPp7DO2RpkYF0EwEmAbfXRoto=; b=zARq1rzitZ/gXUaQhbuFCyprKj3P/2+FBZ5pXtvHNwaREjjQzMy29WCnK3jLdUki/IPQB/4+h9hA9K+DvXw7yrF4pPFob/pF9wspFNpKW8X4zxWH4hFpIhPeKbt+47heY9a/Gh1zXP1Jp+Ltp4H7A96kMQzFB9OzEW6Onvpfa759g5Gm8WlHO7wInDnxv3lavnuhcQV1BNDhXRASg212RP/LaodIth66bco6AD8Cj1LNIAVhaaaZWNSqmEhipwOQ3vhmVUQ1QjWrXvhm0DtnLTzQA6/DUAu7wwB/FI6uPPJ3pcMKpTonSE9bacdLGT3FLxBE6mBxp/x3txpj+c9R/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=0HFa6QLMqlPOiy/eJ/OPp7DO2RpkYF0EwEmAbfXRoto=; b=ajeUVhfJnZrsnrOHtZ6zySlqNU6uJD9/iXaQaZw0pEhVsY2l/vYy9h0OB1g+gWAGh0l4jFaZKIwSMJ+XLwnmW5CoA0c7sOMOV+mkJZRJuDDc0jcwfwDp4+F62qTXeGb0BRUkM1V/dwi8bTnJKaCMuemUH6hpTPreoBdI6AXy6lke3p2RJjQqp+Bm0g/3xBVeotaS02eImmUpglbaHSW2wZLQkreLMUQYaV3c/qTz3Qp9Vbp+p8gpW1rKVtNyFOZtaop+fx5V4KBqOVh6VnTYr2g2+2fR1oL9v+0Ue5ImOV6b5HFjZu67atxkX23kUejdLPwCnRaWbYBT/Rksq6sMlw== Received: from BN0PR03CA0004.namprd03.prod.outlook.com (2603:10b6:408:e6::9) by DM4PR12MB6256.namprd12.prod.outlook.com (2603:10b6:8:a3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Wed, 7 Aug 2024 20:11:24 +0000 Received: from BN2PEPF000055DF.namprd21.prod.outlook.com (2603:10b6:408:e6:cafe::f5) by BN0PR03CA0004.outlook.office365.com (2603:10b6:408:e6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.29 via Frontend Transport; Wed, 7 Aug 2024 20:11:24 +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 BN2PEPF000055DF.mail.protection.outlook.com (10.167.245.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:24 +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; Wed, 7 Aug 2024 13:11:07 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:06 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:05 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 01/16] iommufd/viommu: Add IOMMUFD_OBJ_VIOMMU and IOMMU_VIOMMU_ALLOC ioctl Date: Wed, 7 Aug 2024 13:10:42 -0700 Message-ID: <536c5e908af3847649d1f4b7050af17d77d8b524.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055DF:EE_|DM4PR12MB6256:EE_ X-MS-Office365-Filtering-Correlation-Id: ed7b691c-367f-494a-b116-08dcb71d1cd4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: 36VOfOefxPjmIgCZzs2BLv2V3sB78ae5ZFtT4agoecC1sDsOtIrg6vjAX3DCAmxt2hfwlibGcT4KlZuEY4Ud72BZVsjwK1fMXOBkEmkwCGPeQJR0nDHCK0ntgiHNkvThoHQIFIg5H+itkOr0Z0LWA2D5CANHORKYCpGRdOsN7x2Tz4WOSu2RVNjURHbBIS5X7gcaai4sgXktIih9cY+10UmQN0TD44rh7IN9jIeyv9bvDSgJ+ZLYMzrVSUQodQ4sXaqDCBXbD7RWLzdRT/Zqz6G5MQo4MVF/KtugNtiMQuAku+t18OzzEUZQ5oB1nyu0khmpaYH+jsgnsSdALgk3KJGamjMl0X1h+48ftkUwobeWuvVQukqV/PUZBoENbPjBirur62l1UDTOMPFvQjrlCBPSzhan+k82wONrggjOLO5hMOZR6q17ncFev2bNprtiajNPod7JllvIDP5x15eTfaFrL95dXUjSvwKgPpyM6ymZWzn0aU8XCFjzFVNpozIrcPp/AS1booM8JP6JQa/mWvNiSsvDA39zWTnFcf8a9D+9rdF2zPyM1Qs7AhZ8KlVygDzH2sKpshpuLU86HEz8lbjMRelSzTQLLUR3qDUOOv08KZD9B7rq6+fezajbothHNaQg8N900y3Vd1eIFGCPpEePRjkOJU93ry2t/bIUQUsj6E0rDfWoap86qzs1QDD4Isn7rj6nysWbeNIb2Kvt9lkKzpZWkasBHt22RFLJcd1nIEFLLchxdeFB8MBhL9hD2z7dOY4cCmYqzIwyjzXaGdlQEtTonb8bvxONTiD9REGGZvdpAvOqfsTn+5+nYIgPu5ABeDUSeKfYsbeQIIDTMj4ZXFPIC5q0/uSzSY40RCgnt5VyS0oLylDCbg67Q5/KaRDLwsFqbjqL4Um/KTZou5LlOIVOnetZGEPirPeOImVNMsvYot1F7eLNqkOCmXAsdRqmUibK9Z4nCVUqdVmzLJtbCNPUcTHgby2LT4RZf4PFwh6EvCsOzyFpbRZQuBARVU369kREpbHW9Pr6EVZr6p/xu8zfOFk2d5exhNXGVOW1gf1BQYvp+CN64S6wsChzc+DHo5uhj2fkvEoikiIKCSnOBq7y5m7mifN3swM2vIc8vd0SVQhy7a3xtiqGoFhikGZaETfvZv+rYkSfJXi0G2/jkqybFixMsq2E2Vr55WthgajXb0+2UQ2ATlGeg6Kgem/wZQ9Q3C1iqvHGBszMwlJ9skmx67zvg2cX2xCf1J41bsfE+Ta/WhqeLKvuVhoskTJcjae52P8/ut6Y/xItOFO12qVpycGFbsNDG7/wy8w9y7YQW7o3r0RoF5sL4r9IgSTpRo+KAopMaOvgR9sbEroluGmQPyKuM1Xm/ebiGYLl1eN+CwD6f+Ktzs1EsgSOUxJnzZQKdHrEovkhPIrXZmwIckpVXnsQHk6NJ021rfIARM+IpKASpC4iq9Cye/dH X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:24.3195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed7b691c-367f-494a-b116-08dcb71d1cd4 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: BN2PEPF000055DF.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6256 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131132_423830_7FFD63F6 X-CRM114-Status: GOOD ( 22.42 ) 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 Add a new IOMMUFD_OBJ_VIOMMU with an iommufd_viommu structure to represent a vIOMMU instance in the user space, backed by a physical IOMMU for its HW accelerated virtualization feature, such as nested translation support for a multi-viommu-instance VM, NVIDIA CMDQ-Virtualization extension for ARM SMMUv3, and AMD Hardware Accelerated Virtualized IOMMU (vIOMMU). Also, add a new ioctl for user space to do a viommu allocation. It must be based on a nested parent HWPT, so take its refcount. As an initial version, support a viommu of IOMMU_VIOMMU_TYPE_DEFAULT type. IOMMUFD core can use this viommu to store a virtual device ID lookup table in a following patch. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/Makefile | 3 +- drivers/iommu/iommufd/iommufd_private.h | 13 +++++ drivers/iommu/iommufd/main.c | 6 ++ drivers/iommu/iommufd/viommu.c | 75 +++++++++++++++++++++++++ include/uapi/linux/iommufd.h | 30 ++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/iommufd/viommu.c diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile index cf4605962bea..df490e836b30 100644 --- a/drivers/iommu/iommufd/Makefile +++ b/drivers/iommu/iommufd/Makefile @@ -7,7 +7,8 @@ iommufd-y := \ ioas.o \ main.o \ pages.o \ - vfio_compat.o + vfio_compat.o \ + viommu.o iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 5d3768d77099..0e3755408911 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -131,6 +131,7 @@ enum iommufd_object_type { IOMMUFD_OBJ_IOAS, IOMMUFD_OBJ_ACCESS, IOMMUFD_OBJ_FAULT, + IOMMUFD_OBJ_VIOMMU, #ifdef CONFIG_IOMMUFD_TEST IOMMUFD_OBJ_SELFTEST, #endif @@ -526,6 +527,18 @@ static inline int iommufd_hwpt_replace_device(struct iommufd_device *idev, return iommu_group_replace_domain(idev->igroup->group, hwpt->domain); } +struct iommufd_viommu { + struct iommufd_object obj; + struct iommufd_ctx *ictx; + struct iommu_device *iommu_dev; + struct iommufd_hwpt_paging *hwpt; + + unsigned int type; +}; + +int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); +void iommufd_viommu_destroy(struct iommufd_object *obj); + #ifdef CONFIG_IOMMUFD_TEST int iommufd_test(struct iommufd_ucmd *ucmd); void iommufd_selftest_destroy(struct iommufd_object *obj); diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index b5f5d27ee963..288ee51b6829 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -333,6 +333,7 @@ union ucmd_buffer { struct iommu_ioas_unmap unmap; struct iommu_option option; struct iommu_vfio_ioas vfio_ioas; + struct iommu_viommu_alloc viommu; #ifdef CONFIG_IOMMUFD_TEST struct iommu_test_cmd test; #endif @@ -384,6 +385,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { val64), IOCTL_OP(IOMMU_VFIO_IOAS, iommufd_vfio_ioas, struct iommu_vfio_ioas, __reserved), + IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, + struct iommu_viommu_alloc, out_viommu_id), #ifdef CONFIG_IOMMUFD_TEST IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last), #endif @@ -519,6 +522,9 @@ static const struct iommufd_object_ops iommufd_object_ops[] = { [IOMMUFD_OBJ_FAULT] = { .destroy = iommufd_fault_destroy, }, + [IOMMUFD_OBJ_VIOMMU] = { + .destroy = iommufd_viommu_destroy, + }, #ifdef CONFIG_IOMMUFD_TEST [IOMMUFD_OBJ_SELFTEST] = { .destroy = iommufd_selftest_destroy, diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c new file mode 100644 index 000000000000..35ad6a77c9c1 --- /dev/null +++ b/drivers/iommu/iommufd/viommu.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES + */ + +#include + +#include "iommufd_private.h" + +void iommufd_viommu_destroy(struct iommufd_object *obj) +{ + struct iommufd_viommu *viommu = + container_of(obj, struct iommufd_viommu, obj); + + refcount_dec(&viommu->hwpt->common.obj.users); +} + +int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) +{ + struct iommu_viommu_alloc *cmd = ucmd->cmd; + struct iommufd_hwpt_paging *hwpt_paging; + struct iommufd_viommu *viommu; + struct iommufd_device *idev; + int rc; + + if (cmd->flags) + return -EOPNOTSUPP; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + + hwpt_paging = iommufd_get_hwpt_paging(ucmd, cmd->hwpt_id); + if (IS_ERR(hwpt_paging)) { + rc = PTR_ERR(hwpt_paging); + goto out_put_idev; + } + + if (!hwpt_paging->nest_parent) { + rc = -EINVAL; + goto out_put_hwpt; + } + + if (cmd->type != IOMMU_VIOMMU_TYPE_DEFAULT) { + rc = -EOPNOTSUPP; + goto out_put_hwpt; + } + + viommu = iommufd_object_alloc(ucmd->ictx, viommu, IOMMUFD_OBJ_VIOMMU); + if (IS_ERR(viommu)) { + rc = PTR_ERR(viommu); + goto out_put_hwpt; + } + + viommu->type = cmd->type; + viommu->ictx = ucmd->ictx; + viommu->hwpt = hwpt_paging; + viommu->iommu_dev = idev->dev->iommu->iommu_dev; + + refcount_inc(&viommu->hwpt->common.obj.users); + + cmd->out_viommu_id = viommu->obj.id; + rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); + if (rc) + goto out_abort; + iommufd_object_finalize(ucmd->ictx, &viommu->obj); + goto out_put_hwpt; + +out_abort: + iommufd_object_abort_and_destroy(ucmd->ictx, &viommu->obj); +out_put_hwpt: + iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj); +out_put_idev: + iommufd_put_object(ucmd->ictx, &idev->obj); + return rc; +} diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index d42e0471156f..ed6cdc2e0be1 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -51,6 +51,7 @@ enum { IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP = 0x8c, IOMMUFD_CMD_HWPT_INVALIDATE = 0x8d, IOMMUFD_CMD_FAULT_QUEUE_ALLOC = 0x8e, + IOMMUFD_CMD_VIOMMU_ALLOC = 0x8f, }; /** @@ -876,4 +877,33 @@ struct iommu_fault_alloc { __u32 out_fault_fd; }; #define IOMMU_FAULT_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_FAULT_QUEUE_ALLOC) + +/** + * enum iommu_viommu_type - Virtual IOMMU Type + * @IOMMU_VIOMMU_TYPE_DEFAULT: Core-managed VIOMMU type + */ +enum iommu_viommu_type { + IOMMU_VIOMMU_TYPE_DEFAULT, +}; + +/** + * struct iommu_viommu_alloc - ioctl(IOMMU_VIOMMU_ALLOC) + * @size: sizeof(struct iommu_viommu_alloc) + * @flags: Must be 0 + * @type: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type + * @dev_id: The device to allocate this virtual IOMMU for + * @hwpt_id: ID of a nesting parent HWPT to associate to + * @out_viommu_id: Output virtual IOMMU ID for the allocated object + * + * Allocate a virtual IOMMU object that holds a (shared) nesting parent HWPT + */ +struct iommu_viommu_alloc { + __u32 size; + __u32 flags; + __u32 type; + __u32 dev_id; + __u32 hwpt_id; + __u32 out_viommu_id; +}; +#define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC) #endif From patchwork Wed Aug 7 20:10:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756707 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 DE7B1C52D6F for ; Wed, 7 Aug 2024 20:14:37 +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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=lNh1nBv5cTdPpLEB1tR6CXHr+X c2l/jA3fpeutJ+8S5ywPclt93OX/u1q5RJVxYPg2CzmgURUiItjdTWisPaO2XyEpMn17vyYdHpFsz blLN8hqTyzz1E0+RfUnNpmBoVuNoSF/sfR116ZwBiuWmMPzo3yFe6BrhPBy7L2hyLqNodcIsSkFbN ZhP/XHJlrhwzrQhDC5CMnykT3avs477LV8tBlyQZ3ROlDI2jr8x+U2xHrAnrC6F2SeC7NYqPNKiDZ uIO9iSJRSQmAjApxVGnUcoWqPyBz7wb4O7XlhsZbdnvvL1LVEuyDS0lvoLjWzeD8HUM6GHjClN971 3Clu0PAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn3D-00000006AFV-3I9Y; Wed, 07 Aug 2024 20:14:28 +0000 Received: from mail-mw2nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:200a::600] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0P-00000006997-2BRK for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eOQUbgTQaOs528/2A5Yv7QocgDmKWYb1maIYiPaCNWjvwIVpJeRRgTNq7VaCa7vpq8fUG+6ypXyFBb92Y3x/cCGtTHTmNtUAQlm7/c9DVmGhylaien8Bc8no2y5Bc6+t2rNkRkowUl1sHFHVAGO8jBYEBc3ZZdcl4MfU/vvNVBvksGwDE6pPZVV5P+GXVCLwLNorTp0LhOBVA1BB0i8jvnVmfQYGPRp1sJEMdxPwYTYKcu7csKULy6ebZa3ScfQ2x18S+5K9cW15/VsdiVt4TFxTdKnzm2ErTMt9egiNNZ5oHe0Spc1K/Qgh/IBgMp07b/JOeqWhA+yZW7Q+7uBhbg== 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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=xYm/2kji3B59Hc/kI0+Rb1qVAnCWmk8+FCkbjNo6b4lnROq5SRHBhf/c09aE5C4/e1BZe0RbI/auQskkLf5F8QpEFzV/OJ5x3E7h8gU426TSflzO8H3exFm8D5ne0McODz/JUpchLcmTz71NIwTjI/FzntZAchIqbZl5CBzJo5aws+iki+Gg1Wvm0NSJdIF6UL+QEPUcRdgWZrmphZh6+PEyu6zfoLHVnA9pF1ociUg2hv7dwe2yGWAx1QBmS1mrbKJ+NxUCvmWvRUDLlARbcVo7fF489l7hX3tNXy3FDfcDgkfpAqKP82aGcVQflHOdlv0pcYJhgkd2mr+7o4FXQA== 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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=hoyvg7AIEIkKOI4ibybwsq2IBzjwXYp3eIfVhXxpuZaPREdDoadMmNa/RC84thWb/21TRjplBjJg1+Vrtb1AAI6Zy/EcrgmORTp6dhlBOGS0e1e7Ub5lRAzCIT4T3oO7r5gAGurn3ts+rz1n9zLF30ACn3i7NZHHtlSU+CD7YZ6DUwMGbA3XdiM61a+EjGWF425rti+8mYooa8O5TNvl6e01Wt9cHNehanGz+7EmG0zfrK5jhuGB22gxPFHvs5UCa7Bq4NPgdWEjnaFbj/OA/vq5jDOCn1WQmnI5aVzvHG4QHE1LDWq3eANU1HWyAf1vRX9rDRsSkjVO6hsWWDmMeg== Received: from BN6PR17CA0041.namprd17.prod.outlook.com (2603:10b6:405:75::30) by SA3PR12MB9130.namprd12.prod.outlook.com (2603:10b6:806:37f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Wed, 7 Aug 2024 20:11:29 +0000 Received: from BN3PEPF0000B06A.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::80) by BN6PR17CA0041.outlook.office365.com (2603:10b6:405:75::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13 via Frontend Transport; Wed, 7 Aug 2024 20:11:29 +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 BN3PEPF0000B06A.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:29 +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; Wed, 7 Aug 2024 13:11:08 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:08 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:07 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 02/16] iommu: Pass in a viommu pointer to domain_alloc_user op Date: Wed, 7 Aug 2024 13:10:43 -0700 Message-ID: <41602c71a6b865734d34feac46cc596ff9fb7780.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06A:EE_|SA3PR12MB9130:EE_ X-MS-Office365-Filtering-Correlation-Id: 362532b7-2dac-4a64-b510-08dcb71d1fa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|7416014|82310400026; X-Microsoft-Antispam-Message-Info: MeWfrshpcbjzseiORYsT/fg8/n70DHBVvN9J9flRCk7pTTi3QsGkv6OOQdl+UcTVWdj4o7F67/MfDuFzjwdhKShibW5odZd0i+RNMcbJW1yLiE6ekLWGD2vTYbGHH5I9H/Se+wvLcz42uh4IKlYo702++iBFhgiGiw1kcK2DX0AT88GU/Xwtk2+rwPZH/z8FYJP+Yfv+IJ0BxW28l7LY0p672eJ27SAXYggLABf4iHVaBEVN1kJeaK4m0yfYMNo4s+b0UKxiZEWBCoTeojDu8BD2ysXf7uGoBRhRKyramYyTuEDJrir2VuU3o9yuqlmHCu1JgkEdk4T+aR+YxzB6diTGxER0N+BGJaTNh++ngJ8kYfL84xcRzqpjg+Dpte2d0Ke66XNaaXwLotzl3+UI/dq2TaTFZ1PCUKFW5hkBEFGhvkY/otxwQfUYyBzXPCocyqGrwXxFeyFY2Es7dj0pk3z3lX/YvIr0j1FTM8nRWVtXAhiSqNTAJh0lACgqiaH/9tgq3toGpWm4CGHb/r1Y6rWjOyQWV8BJ6RKjnCZ4ZsTRugx8Oved54RW7qMK4Y0Pnepyfqcrz2Rim+f0DE9qSo8+/fs0uq5CJdYNBYaFxzIbIarFcolMeMMERJk2pJT/giONwZDcX4fTEw830ftL/DQiJClew5jEyoGnr89D/aDBJOd+0aOM9c+9wgKiGMEB5g3LlkXcsj1cmxpk3u1ZhgZOdJqbZxknUcYK6afJTY+UrUi4LwMBM78KCqkTSP9JfqKzvmR+zplb/M+oVqHZFq5jYJj9pLkpv+luDmnThWKcqzOGGY+Ovo7MZ5m18ZgaJxp8SHg5W0Ngo8b5lt5sXTUPGozPsP6IMDmfczLMriEajFHz5RrvL12+BwcT6eS96lgbJuUyhQVOXNoQu8fQZKDQdx4vHRpqPNyYN167PmCTxKR4190lU+7uWgU9jjeLMeWvjVTYYXEPL5RpbMD3vsIydydKufkU5iRtgk6JuTQKd8vOw3wIa+uUXEXoQ7ooK1hsKwx5JeZt3MqqUkxtNcsxxF9VffQ5u+HcafOssGKwcBggytjoI6QLtOwyMRNf6eM+hdbtYJA4IFd7bwdwe7hiSQm/9eyQek1/eg6E72bWOau7Iu8uQjY96D/pe1usOfeb9grQ+Z5VCsu9ahK47Vq+NwS/AJLaTVwdzgXzuE/2hdP0hZK0CYg2i2q4AGQO72deaxbcaMK5jB5D0/DfpVUEbxDhb2XISJf/TEW803IRBj4o93sq2+3ZoKh/760i/iZSDsZixu081ppSgeF8QgNDeGFZ58F6VRSLFskS607bk/1K7lraw7/oEVdzKtOUwTQPd6O8YeOiYStpRPzNo/F7gK/54OZX7CclaCAwimB1gqaDgEu4xHTR+4kfJQxriCO64QWUnWINECMxj2yZDg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:29.0821 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 362532b7-2dac-4a64-b510-08dcb71d1fa8 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: BN3PEPF0000B06A.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9130 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131133_593857_6E0DE87D X-CRM114-Status: GOOD ( 14.02 ) 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 With a viommu object wrapping a potentially shareable S2 domain, a nested domain should be allocated by associating to a viommu instead. Driver can store this viommu pointer somewhere, so as to later use it calling viommu helpers for virtual device ID lookup and viommu invalidation. For drivers without a viommu support, keep the parent domain input, which should be just viommu->hwpt->common.domain otherwise. Signed-off-by: Nicolin Chen --- drivers/iommu/amd/iommu.c | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/intel/iommu.c | 1 + drivers/iommu/iommufd/hw_pagetable.c | 5 +++-- drivers/iommu/iommufd/selftest.c | 1 + include/linux/iommu.h | 2 ++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b19e8c0f48fa..e31f7a5fc650 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2432,6 +2432,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned int type) static struct iommu_domain * amd_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { 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 3962d5a55519..558cf3bb24e0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3403,6 +3403,7 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, static struct iommu_domain * arm_smmu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9ff8b83c19a3..0590528799d8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3703,6 +3703,7 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) static struct iommu_domain * intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct device_domain_info *info = dev_iommu_priv_get(dev); diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index aefde4443671..c21bb59c4022 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -137,7 +137,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, if (ops->domain_alloc_user) { hwpt->domain = ops->domain_alloc_user(idev->dev, flags, NULL, - user_data); + NULL, user_data); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; @@ -239,7 +239,8 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, hwpt->domain = ops->domain_alloc_user(idev->dev, flags & ~IOMMU_HWPT_FAULT_ID_VALID, - parent->common.domain, user_data); + parent->common.domain, + NULL, user_data); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 642ae135ada9..a165b162c88f 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -320,6 +320,7 @@ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent, static struct iommu_domain * mock_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct mock_iommu_domain *mock_parent; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 20a40fd6c4ba..0b71b2b24ede 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -42,6 +42,7 @@ struct notifier_block; struct iommu_sva; struct iommu_dma_cookie; struct iommu_fault_param; +struct iommufd_viommu; #define IOMMU_FAULT_PERM_READ (1 << 0) /* read */ #define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */ @@ -611,6 +612,7 @@ struct iommu_ops { struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); struct iommu_domain *(*domain_alloc_user)( struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data); struct iommu_domain *(*domain_alloc_paging)(struct device *dev); struct iommu_domain *(*domain_alloc_sva)(struct device *dev, From patchwork Wed Aug 7 20:10:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756703 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 531C2C3DA7F for ; Wed, 7 Aug 2024 20:13:31 +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=6aQWktePkOW4o78zFKMWXR88Zqd2sc4/zCRsO6x5eI8=; b=DKNbqld5mN6whCizTyHox6vgBd D5cFHE2ROmP7YMCbLW/x6vSfEQ7jrizpyXlOZC8CrD5R012A6Z+9bek+fN+TINT+jRMTpnXwmzOaZ oZiLyOmipue2Cjw6PcJt+TMIKzrLCo92LIx/NGxHI8D/AJDInlAnCcVY0h0ZVOozYEtZGWUcZa1W6 YzcGi5mY0kZxwTqju0Eltra2ZMvkuT6CkBSDZCEylYJ6Hx7Ag1X0qhj1UEUfyYdx5KyTELnw+WoOP XMMF8w1Unbi6UIz+P6e6tdXDHjMxmh+xJAuhe3vRxE6dnXbIDtiCT2FJvtjkCaIJbJi1/jzLrdaAc +D3CcZqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn28-000000069rp-3bh6; Wed, 07 Aug 2024 20:13:20 +0000 Received: from mail-bn8nam12on2061e.outbound.protection.outlook.com ([2a01:111:f403:2418::61e] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0O-00000006985-1O0H for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yHL+1+KUKUywUv9wX+qCLr50C7E00AYsDC4Psnh+Y9pXZgg9rdaUMHPoxcbITOzyfCnHViXvTfN7QqBIN729w3HBegrVx2zQYzgAk21gm3c14AYZqkV0APtH0CL0d/WaB72koOIzwoW2aStGw+F4uZ2cpRCyRJ5dkbAoXvYp3c2T2rDcDVL/0d1htSkJMU7LJ4do31QmWE44Odo7m6pFfWJ91CavON4OhezWsFLSWZ4hp418BZKuYI2/qUWFFLW77uFmOWhIsdNbqebrWhJx9lrxRtBHfZXLETkI38tY53thsRn/F6Rd8V3+0aGGsbES67jqLD2vvRpK9vUFUd6viQ== 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=6aQWktePkOW4o78zFKMWXR88Zqd2sc4/zCRsO6x5eI8=; b=dfNu8FekFL1DjiZljfM1nmH4Om8/QQS7zEJsWXhyKN4paxXwKNBrWaE7tc/gEckFG3ZXv7+pQuw/7rgJDeb/ukml+LpnvIQeC6iLLupO99a8kD6sDU8LugM6wUrDJ7NkN5VGoZBb7091PCuq+RxN9OOqLxZfV8iTCNS1shPqS761sMw9M6a59iUTMRvgC3QxEiTvi81vYJleJJLLpldzifikpKsNw687Bb4UU5rFS0kSjfzbJbvOUV/Dfm5mDuu77fDHcS3X8xOjyTQpKTnCI8Z6XLVUQKT7Nz2seySvVoVcMmZejUEkheXkdgVULJG5YPRzRduNILs8ldDNIHANeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=6aQWktePkOW4o78zFKMWXR88Zqd2sc4/zCRsO6x5eI8=; b=Ip4L2Ti2RkU4Ixfgp5AluWsZexyxbEpkpai9Xw/mH6zVSer14bEW3RB9IucBtok5PmJ6qg518eVWU4KbxSvCoeO94Vv3lw/2teA6B3k55BE/pqL6K/Wj0PKnKHD6Bs2A6/FnZATJV5qRkNxXg6vnK6qq9OGaeU8W1P1wHkrK9Ja6VMfHK+1mEuoEgHw1qab/liovq0ruhSycbMW0ibf3aXaYHz4JQmY4UEvNwvgoDCw7ZYY/qv+T0T2AFFIXC7pEsmuCe1dNrtTNBEUaAH9aF7drMMvwMKnDy8Tp8INYDEOs+3xcHaeduJU2SA/Lo59WO7spDlw/MyandGYGMISfXA== Received: from BN8PR15CA0054.namprd15.prod.outlook.com (2603:10b6:408:80::31) by MW4PR12MB7016.namprd12.prod.outlook.com (2603:10b6:303:218::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 7 Aug 2024 20:11:26 +0000 Received: from BN2PEPF000055E0.namprd21.prod.outlook.com (2603:10b6:408:80:cafe::cd) by BN8PR15CA0054.outlook.office365.com (2603:10b6:408:80::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:26 +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 BN2PEPF000055E0.mail.protection.outlook.com (10.167.245.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:26 +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; Wed, 7 Aug 2024 13:11:09 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:09 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:08 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 03/16] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC Date: Wed, 7 Aug 2024 13:10:44 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E0:EE_|MW4PR12MB7016:EE_ X-MS-Office365-Filtering-Correlation-Id: 75d80817-c339-457e-9b59-08dcb71d1de4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: nBlRCTFKKbPctNSvP3WXje2yh/UMMVadIIPYjsFDOPw7sSlOFjfXocvXOUzfQUNKUaCjWNOWnVp+vLMBmFXTd8rxtyC2lSmnxhTI6tVXxsRkjcbXSO7orWKndjjeW6K0+xkyOv9jftwDHua5vq7xfCDdpiAjfZKlbxJOYXQNh7AXRH83b5BwNkb1C5x7+I33hwyY23slhoDZ24YjNYMHWgp0KWDb9XTewg+7YLsB8BYhljrIrk7pRKTULcp3/TdQNZogKv1QncOpBPgDp4QZnl7Zfk3qm2U75bQuONsD/xt371FHjIu7yyuMKaQ/mmH3aBCZYNNyrzFXdChchTWNFAxI+Pk8qzq3ohQ27pYMQnlub4SMOe+Fv7WTSxBgyPcYeiKVfUAUIotxwRRhdsu23fAK2wnHX/dOUCoRLCFR3bJqEr/0o9ZE3bFRCM1MJaFLkLHCd5elsJGbRXFCI7uG3oT/acv2/s++mkmv+1Hp75eTocgOQjTamckXK9Ah4WOfSKsoniqgbJAhYTWcqMd95IuNTP+N3bdPwhicJnhA3wAdWEx/KjWG2C1k9cAcJoikK2ozVl6mkMdF/OE9AwjuZuIUcqGoULStQYW9cwAR0zYwD5TqFWcYEtBSHdRfzkr7FQ2yFMI5sflIjUA9R3yzHl3G06KAFMMQctn94DUwSAXMoZx/ex8C1M+pm57g4OppD+qlo/bO2YcD43z3xlFsBsQHf10SihERA42LMqnP1BxUGmGfLQxNilO5tcZ30UtJe3MHfywH9OJhGxENn2N5NjEW3NctBkjue0qO/vJdUNLOHlPwDrkBz3pXKT+Rxn/09U3+a+6BYqXeo8fAh14xv86H9Qy72+f34pBWRhr3xqEpgICvh1yBjcR2PDTOdTyWdv0QQZ2eNl/7+VWbqIqyXhf2nR6AOyTPG3uVK964Hj67iW89QLKu9RZ+QoBC69aKwDklHDIYQ832xmXqxDblgBA9sUTvIwav7btY6VQ9UXpTaQh/rWH9T9Ume3e/C2jfpreCRqBvD2+5Hxnweh4Q+34Hdohx7w1KHB3n9maajsqeO4EMMTJDtB01f2KbZ9V+9X4205a6BcvrIQoc0ymYh+9UBcF41rm299IbBhtTCwmzY0R6hCCXOBSz8SmJ2TtSujvS38owqQGBUPg2POY0srwsjCTBCh/p5LwRLyivPqswqZSyhIX1VdVb86HgJKHd861YVf1KW4wVNVH53H5TECXmwbvkI16VMq+nCcHNox3Nw6LCNKvj510LLr6AI4C0SX8FLYj9Y6MtP5TdTeYg/1FqSqPMjzB+jPYdw0jO8C58V9wjXhT4tewmQ1TRwX7oqkRhbsagRR+V4QJtSVKuVvLZjqnznCZcfN9MI/nWm6rk/klB5FKOW/fK1nkueLV0Uhih4BZkRl2eHBekjacE+JvSuBT5N4rQNojornAoTpq8rDsxMPxhK5aLb4IpmijO X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:26.1348 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75d80817-c339-457e-9b59-08dcb71d1de4 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: BN2PEPF000055E0.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7016 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131132_400575_7CE4FB95 X-CRM114-Status: GOOD ( 17.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now a VIOMMU can wrap a shareable nested parent HWPT. So, it can act like a nested parent HWPT to allocate a nested HWPT. Support that in the IOMMU_HWPT_ALLOC ioctl handler, and update its kdoc. Also, associate a viommu to an allocating nested HWPT. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/hw_pagetable.c | 24 ++++++++++++++++++++++-- drivers/iommu/iommufd/iommufd_private.h | 1 + include/uapi/linux/iommufd.h | 12 ++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index c21bb59c4022..06adbcc304bc 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -57,6 +57,9 @@ void iommufd_hwpt_nested_destroy(struct iommufd_object *obj) container_of(obj, struct iommufd_hwpt_nested, common.obj); __iommufd_hwpt_destroy(&hwpt_nested->common); + + if (hwpt_nested->viommu) + refcount_dec(&hwpt_nested->viommu->obj.users); refcount_dec(&hwpt_nested->parent->common.obj.users); } @@ -213,6 +216,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, */ static struct iommufd_hwpt_nested * iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, + struct iommufd_viommu *viommu, struct iommufd_hwpt_paging *parent, struct iommufd_device *idev, u32 flags, const struct iommu_user_data *user_data) @@ -234,13 +238,16 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, return ERR_CAST(hwpt_nested); hwpt = &hwpt_nested->common; + if (viommu) + refcount_inc(&viommu->obj.users); + hwpt_nested->viommu = viommu; refcount_inc(&parent->common.obj.users); hwpt_nested->parent = parent; hwpt->domain = ops->domain_alloc_user(idev->dev, flags & ~IOMMU_HWPT_FAULT_ID_VALID, parent->common.domain, - NULL, user_data); + viommu, user_data); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; @@ -307,7 +314,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) struct iommufd_hwpt_nested *hwpt_nested; hwpt_nested = iommufd_hwpt_nested_alloc( - ucmd->ictx, + ucmd->ictx, NULL, container_of(pt_obj, struct iommufd_hwpt_paging, common.obj), idev, cmd->flags, &user_data); @@ -316,6 +323,19 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) goto out_unlock; } hwpt = &hwpt_nested->common; + } else if (pt_obj->type == IOMMUFD_OBJ_VIOMMU) { + struct iommufd_hwpt_nested *hwpt_nested; + struct iommufd_viommu *viommu; + + viommu = container_of(pt_obj, struct iommufd_viommu, obj); + hwpt_nested = iommufd_hwpt_nested_alloc( + ucmd->ictx, viommu, viommu->hwpt, idev, + cmd->flags, &user_data); + if (IS_ERR(hwpt_nested)) { + rc = PTR_ERR(hwpt_nested); + goto out_unlock; + } + hwpt = &hwpt_nested->common; } else { rc = -EINVAL; goto out_put_pt; diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 0e3755408911..443575fd3dd4 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -313,6 +313,7 @@ struct iommufd_hwpt_paging { struct iommufd_hwpt_nested { struct iommufd_hw_pagetable common; struct iommufd_hwpt_paging *parent; + struct iommufd_viommu *viommu; }; static inline bool hwpt_is_paging(struct iommufd_hw_pagetable *hwpt) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index ed6cdc2e0be1..0e384331a9c8 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -430,7 +430,7 @@ enum iommu_hwpt_data_type { * @size: sizeof(struct iommu_hwpt_alloc) * @flags: Combination of enum iommufd_hwpt_alloc_flags * @dev_id: The device to allocate this HWPT for - * @pt_id: The IOAS or HWPT to connect this HWPT to + * @pt_id: The IOAS or HWPT or VIOMMU to connect this HWPT to * @out_hwpt_id: The ID of the new HWPT * @__reserved: Must be 0 * @data_type: One of enum iommu_hwpt_data_type @@ -449,11 +449,11 @@ enum iommu_hwpt_data_type { * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags. * - * A user-managed nested HWPT will be created from a given parent HWPT via - * @pt_id, in which the parent HWPT must be allocated previously via the - * same ioctl from a given IOAS (@pt_id). In this case, the @data_type - * must be set to a pre-defined type corresponding to an I/O page table - * type supported by the underlying IOMMU hardware. + * A user-managed nested HWPT will be created from a given VIOMMU (wrapping a + * parent HWPT) or a parent HWPT via @pt_id, in which the parent HWPT must be + * allocated previously via the same ioctl from a given IOAS (@pt_id). In this + * case, the @data_type must be set to a pre-defined type corresponding to an + * I/O page table type supported by the underlying IOMMU hardware. * * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr From patchwork Wed Aug 7 20:10:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756702 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 22C45C3DA7F for ; Wed, 7 Aug 2024 20:12:59 +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=ztlI29zpHxKZeb82NIMRhiRfkuDoLAKoSoT28lOiyBs=; b=epgke6I7K7RqRvEVrULnC7Tp4k ZEG4J9YPxgbsax1/4mjvockJkWQwtBSCoaafyX3GZ5eMY0/klwvBcvDfPz0v3W6MRdLkeWdR9L/tQ nsaUGP97taxi6c9O+aLsktdASxY+LKgzy46vHk6J5Y/t1Z39EUULCWvdvK0CqMiMsfICR3+7v5lyO DKW2D2QRbrdSYUjBTdiB4ZYeAqc+ceXjTWz1gXhpZ32ifFrZAM3KBGnnT+ejwmHIUTKWKhQu7+b3C JTYkAnZln2CHm/MJSEqexzM4hQUEemXIeB3WC/QoL+FAVpqBE9XfO+C1ssa7aNHIagzo+zsWlKRng 2DW+vO3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn1b-000000069fb-1XG5; Wed, 07 Aug 2024 20:12:47 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0O-0000000698C-1BiX for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cW0ahweNLGWb6vwCLbkRHMunii5oMOpmeEyu4nuSaAYzeqEXRIkP9Fup3nKnM8BNPsKJkMTZlJVISD2FPQ7eqS4BqL1MYRlBlj16nwCQkxVGJD0a8z21jPKzf507FuLErtFC1Nd/AMEU6hV93LvZDBZbTZJvZKIdMidL18QXFRiUw7+U1ziJNYXSQHRuZvkKXxzmM9RqZSJTs2I+ogPIUdT9XkQcLFDit5tr+JMoi4YeY3AFgr5aS37JMmhITkY/UTjfPBe+YSAIJcXyGcMP910otGDA9B60EW983/8FUKYmuUftqJudH2X6RkZ3gjJWCjUIryhF7eNR7dLJPc1qYQ== 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=ztlI29zpHxKZeb82NIMRhiRfkuDoLAKoSoT28lOiyBs=; b=PSSrNo9jSVm30KJ1QBSkDb+8JUD+ZtAat7OtHfNVGnTeLkp4xoAHYgJbWSVZ9kTvrsc+HIBWgMct1s+Mfqo57MLjE/BNdVTeAULJhObAjx19f4U43UQH7oPrpvc9JizWDAgmfMyTiggjjK/co/ASdX5ICEVGSQtC4CQuVNUTxaptMEMTGq4MCVnQ5m2x7992WVYWuJ9uRQnHdxqKLAmzP89lFOjtZrXrpaMFs2n6m/10FdTG3aTw6V26Fq9VgSQBIeIZSdlmO0XC0DvjF1Zm44QuVxpttwollrXJEHqilUB4/b31d+OZP66374lw5yh9QkINPEvTf3MPVO7j20ByCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=ztlI29zpHxKZeb82NIMRhiRfkuDoLAKoSoT28lOiyBs=; b=AEKX/NdKDDXlP7ttWYxlQyGtPAQhQLn8ilR3YQVHJ9YjNGNE2MBUzwIz8ltxbG86FH5pvA+yd5K8TyB9We0wrw9ZRaCioWUVj8doh/deZpVu5v+iMewde9rTYM7eWTBJAvSdhv2TND8j+q6WiJbfILc7S+wXalslNKJCB4REUIHxHaCWuTraeNRFf3uoLqg4I+TG25XavDvyzYL6GFrypZ5Q7wmraAM4MYQUmynhF3UcuWIyHBs933OC8WdQajj2LQNw8vFZoasBK5+3cadgIF2GhWO+QK8zIfCmMsQQg+Su2mgDQaMSCrQz6a4fXSNPp8ZXdar6heeyXmsi48D30w== Received: from BN0PR03CA0024.namprd03.prod.outlook.com (2603:10b6:408:e6::29) by MW4PR12MB7287.namprd12.prod.outlook.com (2603:10b6:303:22c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Wed, 7 Aug 2024 20:11:27 +0000 Received: from BN2PEPF000055DF.namprd21.prod.outlook.com (2603:10b6:408:e6:cafe::2) by BN0PR03CA0024.outlook.office365.com (2603:10b6:408:e6::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26 via Frontend Transport; Wed, 7 Aug 2024 20:11:27 +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 BN2PEPF000055DF.mail.protection.outlook.com (10.167.245.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:26 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:11 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:10 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:09 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 04/16] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage Date: Wed, 7 Aug 2024 13:10:45 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055DF:EE_|MW4PR12MB7287:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b0b893c-4e5f-4c01-5121-08dcb71d1e48 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: awWw7lDXuN26WLfACyYwFuM5IrFvr/RPBhdQzfIT5SOVXlHsi1/6zU4UIEdc4fJjfQVdfJA9CYd0uXGFld5SnvalykA3g9tUr1G/dekp4sR4xJMn1ObRBt9rJXFDHBYf2K4pnnBE/8yjmLMCH3At6gqVA/Cy44guG8iJDoDGp5eSVrNCoaEWwA/CqoXBUzbqUUzwN8J5ngicqD/VvtKkYqFha8H/YqC0ILYz62uIdNutK1kuBSXGFni6qt/PDCHMfyXy+5guV717jVe7QlrtaObv8Ny2x9zecoRPrrYi/ESnK3SdGCfJ8lLmezpvUCFSOJoRmMDA5TlJsVqXRuYe8v/MNMNe0xcMAQihfDNN0v74btBP8Q4SJXGUuKreF8zkdYuCAaZp1RMNHEBT5kswcHpPG3Ej4+4AJ3YNC2nArhGrJ98iYBD5pAHIV3Q6Jtl5yQopcyViViNdh1XjOCKymvUluJQqONeeYMhqYIfB6ZR04sjbMdHROlcQ+75wNuVg8T5OG4dt6X4YoZMxOKj5Yz4zTet/yVcWwSj826xiabiytXq5pG0soQfp/nYIV3KtzCLxaaXoUkq2ZE5qx0mBksi4/3nHW44pt0paRkYEpPkixOTOY9yA5Ab4L0wucgYTge7xw+y/+dhEwEz3NceGlW98jKoVGNxdu6D28z3fBO2VNxgdwJZZ9FW6le2+/62zfd56dU2RYjRIbBQXimfs7PZCyAX9afLgXj9ReFHhftZJ1VP28+KG+9+7MpuwXVmmpcj+2q1jl173hO5qDmmgY3pDINJBwk+p36zX4FBRzDEiVIuJ4hyF1U7skDPHRdV3gAMNFm/RCmOrpejD04KHdptalImrtDrkVA+yu5jHDif+stSNHDhMja/lRAT/gO9ePQwmnKtnCr0tWrWnqaaEcI3LrW7RJvH7LlytB2mUZ06z/k/PxQWbJwfi9svnUIIbHv+GoxWCljfluSUV4eZLBVJgdXZeACNIo57sCK8TbIjFkPi/SST5051+c5Vg1H0PlqFaDZZWAeTT7Q3xWpI4Zg5v9iaJcC/HxODqf5k4e3X5z++qyr2TGo/ZVNaLIcX6q9s8FTajHIU33d/j7hrAe2wdfPow6w5BzPzZOfe/iKwFc7kwEgeucH4v6R8LBMYGiS2XF1jkQ3cVhZJjOVNWd1O3QwpgitEF/5vyEchyPaELlLNmXm3HLR+yXBnPTrdEpvmVp+PIjDiQUw5KIK4A1qGrU+Jp/L9bBGVGdfuSRCFECYDwuyELh4Bp4UY6RkEXwEJVZDmt9fCLHREsEYoBZgERgVnswIJCv7tcVLVWQlhvXBKkpWFz6DoNZXqWmSyt2om/Gn67ytvbfVlWlEmuVYdKY+eEZLMG8lFIQcCrinfwmn/7SCE68KHz4+l7xtMou+3vC/8scZnv4Wns5/ZjDc4sCe5noPuO8oEEAWwIOsSCO5ZUix+p8eVAGD+V0r6i 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)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:26.7726 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b0b893c-4e5f-4c01-5121-08dcb71d1e48 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: BN2PEPF000055DF.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7287 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131132_348364_84CDB8FA X-CRM114-Status: GOOD ( 13.60 ) 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 Use IOMMU_VIOMMU_TYPE_DEFAULT to cover the new IOMMU_VIOMMU_ALLOC ioctl. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 35 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd_utils.h | 28 +++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 6343f4053bd4..5c770e94f299 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -554,6 +554,41 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested) } } +TEST_F(iommufd_ioas, viommu_default) +{ + uint32_t dev_id = self->device_id; + uint32_t viommu_id = 0; + uint32_t hwpt_id = 0; + + if (dev_id) { + /* Negative test -- invalid hwpt */ + test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, + IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + + /* Negative test -- not a nested parent hwpt */ + test_cmd_hwpt_alloc(dev_id, self->ioas_id, 0, &hwpt_id); + test_err_viommu_alloc(EINVAL, dev_id, hwpt_id, + IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + test_ioctl_destroy(hwpt_id); + + /* Allocate a nested parent HWP */ + test_cmd_hwpt_alloc(dev_id, self->ioas_id, + IOMMU_HWPT_ALLOC_NEST_PARENT, + &hwpt_id); + /* Negative test -- unsupported viommu type */ + test_err_viommu_alloc(EOPNOTSUPP, dev_id, hwpt_id, + 0xdead, &viommu_id); + /* Allocate a default type of viommu */ + test_cmd_viommu_alloc(dev_id, hwpt_id, + IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + test_ioctl_destroy(viommu_id); + test_ioctl_destroy(hwpt_id); + } else { + test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, + IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + } +} + TEST_F(iommufd_ioas, hwpt_attach) { /* Create a device attached directly to a hwpt */ diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index bc4556a48d82..810783d31ca5 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -771,3 +771,31 @@ static int _test_cmd_trigger_iopf(int fd, __u32 device_id, __u32 fault_fd) #define test_cmd_trigger_iopf(device_id, fault_fd) \ ASSERT_EQ(0, _test_cmd_trigger_iopf(self->fd, device_id, fault_fd)) + +static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, + __u32 type, __u32 flags, __u32 *viommu_id) +{ + struct iommu_viommu_alloc cmd = { + .size = sizeof(cmd), + .flags = flags, + .type = type, + .dev_id = device_id, + .hwpt_id = hwpt_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_VIOMMU_ALLOC, &cmd); + if (ret) + return ret; + if (viommu_id) + *viommu_id = cmd.out_viommu_id; + return 0; +} + +#define test_cmd_viommu_alloc(device_id, hwpt_id, type, viommu_id) \ + ASSERT_EQ(0, _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, \ + type, 0, viommu_id)) +#define test_err_viommu_alloc(_errno, device_id, hwpt_id, type, viommu_id) \ + EXPECT_ERRNO(_errno, _test_cmd_viommu_alloc(self->fd, device_id, \ + hwpt_id, type, 0, \ + viommu_id)) From patchwork Wed Aug 7 20:10: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: 13756708 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 93A7FC52D6F for ; Wed, 7 Aug 2024 20:15:13 +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=zTp8oEpJJZI+rcs6AILGCBaCefNRwcbwWthdXWw2cOY=; b=BWV5PqzWkbcIWxlg/Ll2HYFHh/ d+05EgTQ4PBOkydy38t7NlRLtveSppwjkA/Zs+7wUqlyKNd0Ad+g2vdHIf9PGmHmkgRpHxCfz1nx/ k3JLwWVoCdF6nBa1GEPImQisyGCB0mUcvZKuPu6IzS/aingLGr/FRhdU877iyE90C0YN05bBp8YjM gX4Io9dCdSoF7bIl+Imqdg+00zOWjFGjMf4xFonrJ6ywE+0E+EChDJ2Jg+cGxwBTLz6GcojOO3+vH zJkItcbka6R1gGpY9beA34Vn35gtFyS65o0gKsEsRo2pmLX83mG3+tuUgNpRDgvdzSJwTrRWm0jBG NL23OmRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn3k-00000006ARD-49Cm; Wed, 07 Aug 2024 20:15:00 +0000 Received: from mail-dm6nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e88::62f] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0Q-00000006998-0xFM for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bBRExV8fhwR3dOHP7uwoNuA8soDcj00wQjhPpHWvOccULe96eJoAlWMoZUO91DowCJrvc9kXmf3/VWMFZie0jwGQ0CAMoH6uNoaQG4KhVv6JiZ10h9sEWDm1u33aoEgi67suYRxOGAerhMpKwqOMqxKYfPRNVsE67ezHV1tDNTAmLugu5/zIY6x6TZihwPa0amVcSpUUS4eOeYRC4i0VblZbuPZfdtX1ZPDb2eQ9Casytfnp/JQYqSCcihdgrtmh6EkNiiCuqwYmXR0OLo8Ifd9tDWMdq0s0cqJzYI00WVgmkoXN286wPlEh+c5/d84JWlkYfnRDS64MOwGZLEOccg== 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=zTp8oEpJJZI+rcs6AILGCBaCefNRwcbwWthdXWw2cOY=; b=zVLsmhiMP5GuBh2651fTYyHmRrws/fg+24SG5YJxYm35V4hCgtHH3F1tatZb2kVACqg6okRy/N+OdomjukF4maZTfjm7dpwtFxa2+C/x0XwZLBSs9tH/TE0DSyYrqAOl64C9gibsA7caG5UlvRgWnR3RMWkaUqbHvRVldu5HyOkhNUmlKaPHf9Zi59C4fa7lkPRO03NhHs1inX86eWJndROg6QuRxMlpzs7AxRqjBBzz+y2C187pk42KzjOevxmpSPDVclw0weRBSpkRFx14xtDkc6v54vV1sPuOQ3B2ntMoLKzMzYI6y/F0USWCnvLNidGAO0pXY1i77F85MLC7nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=zTp8oEpJJZI+rcs6AILGCBaCefNRwcbwWthdXWw2cOY=; b=ggINxS2EVAry6AxFkSPTbO1q0IklLVvePLB/puFtN2955wQE1JcCws+5tIImTVYnNKca6iz+NsrKP7wWBGn1k8k0lGr9ygRl/Y+FwMu270tUVDWZPhgrLPvuD9FIepV6YHMv58BBqa3m6rNnJjYACGVQyo3we5tt9GU+VVfDvyZWHYzOorXMSTkRS/eHY2iWI8KtcqzWOzN8yJ0DIIu5MJJhSIcXhE1i8ux2zYj+zCT+wO45EHA4EW0KZzqhBNG+uKsckgibNsIAAscloc8vYasYY7OyGWmLOuH6SSKeANczOk/JxqGC/S1Q99pktZljO+tiBSvsMq6+YamZ29vnog== Received: from BL1PR13CA0069.namprd13.prod.outlook.com (2603:10b6:208:2b8::14) by SN7PR12MB6689.namprd12.prod.outlook.com (2603:10b6:806:273::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Wed, 7 Aug 2024 20:11:29 +0000 Received: from BN2PEPF000055DB.namprd21.prod.outlook.com (2603:10b6:208:2b8:cafe::6d) by BL1PR13CA0069.outlook.office365.com (2603:10b6:208:2b8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13 via Frontend Transport; Wed, 7 Aug 2024 20:11:29 +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 BN2PEPF000055DB.mail.protection.outlook.com (10.167.245.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:28 +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; Wed, 7 Aug 2024 13:11:12 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:12 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:11 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 05/16] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl Date: Wed, 7 Aug 2024 13:10:46 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055DB:EE_|SN7PR12MB6689:EE_ X-MS-Office365-Filtering-Correlation-Id: 3cd15d10-65c3-41e4-63c0-08dcb71d1f78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: Fo89YhO36k3L2O8SIn+es08Ati5guUHiGiK/4Ei+zqheuKAGtXWsD7JxUzOoPSPXkMB56Q1aphnPhd6k+I7gg1jP5rqnYBiuozCnwE4V2YhkhWYSodxPxHT5IlAnBsItmJzDTG/wD+mYW0znjaG9F/9WuqYnUd55evrmNzlTefzH1d8goRMfzSa/0wbkrzAS0IK7lPB/1J5HzjcxvUXyPpU00sWoiRWP6fwU8VWeCq/lGbEFaS6cjFdwL6n7H6wm75yfSL8B4ooNMtud4qzByeXzyJoFplmHv/zCZ9CTHOGJSppP9yUPdF9VWHLwsPqrLQ/QVU4AYNJ+GO55Jg+UCBGEmGsiBROhdhpqmIcuKn3jK3ULDU4R1mtihhTFyKZSDy6Yk5g0NTHJPXgqDxnB6IpW+a8O647cFOWo/ciTys5k/meoSRsEfuwx6hW0fsO9eSzqI7y1ruiX8HQp5pX9HkLn+NLV040ZPLa1DFvhlOFNpgdXSE/LbXqKCC+x5oqhxxou/haYmgtAvgd/Df5pGryGIzVcPOFoJmIdiNPVaYhHf1chyQV2gQRa8Jl6A82Npq9Uoy6UUzyuYA0jSCmBd0SaxZOQ1teU8bqElbZzHEJ6nUSkQnpCuRDV0BIs7bWiDAUCNT+VSMDboUMW7rTm0PXgr33PI4V2AEc7IEqakHxWtPGWBgVSSsmtnMk8/D3YXz/jUwLEF8jW08rErMHJ0s7KL2D1+exqQiqw16XQJ5llsl2VFZmbSa/aaLlzoFngbed16kaT4i6ff5tiGQHrVfB7pqeeArlegc3/AdMS13yHVIyPoLHaPk4zj56tO6X+ZLSnc4rGDiWiUBkAOsRhkWDQCugGHQtyoDosfsO2yG/dDCL7UOhdOnT87XeuseSlbYZJZhpldvYzh2ThqzGO8A/5TNAGrJgXtNK07Y+KgemANbBcp+04LkyRkPFpWr0j+b/KcikQ8Gt7U5O5LhFdYiSfgGnS25Ukiat2jcgNOqx2nQ3EJqWg7iKkBwwLXOzQDg9VqpgyT6eWuqe/BaGI331/gVcSivfilQ+uM8cV3aPW6kjGzfJwmczxleNeUv5YMi+1m3z5Z1kDNC0Bn83dPKoxuF0v1nstGYiovUFVBJiIfffI9JDuE9/8zwAB9h6J4ZNs1kCXQBiVTnYr8eFiWXm5NoFOBwMo4u6/v96R9Ob1lJIE4MP7Yv05iBab7yRCVH19HgI3qjeve4nh8I69eVFILWauy/pqpGdeieTChW1pQpFVPZ1CmbY2MXK8UTHU20wSuEBaYgYuihPTdSdfrhTmS2pxoabesD3Ty8kBlp6DAEJXOwnUtfk84vMmL2lrfRmxSgUbrPXhnzzR0jIfjJi6O6VyW34f9D8WGECfgFkD6IZlX1W8Ztlb1AgSVq4V97oC/NYl09e4Ugo6ICLbJA== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:28.7654 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd15d10-65c3-41e4-63c0-08dcb71d1f78 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: BN2PEPF000055DB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6689 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131134_452602_90240324 X-CRM114-Status: GOOD ( 18.49 ) 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 Introduce a pair of new ioctls to set/unset a per-viommu virtual device id that should be linked to a physical device id via a struct device pointer. Continue the support IOMMU_VIOMMU_TYPE_DEFAULT for a core-managed viommu. Provide a lookup function for drivers to load device pointer by a virtual device id. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 9 ++ drivers/iommu/iommufd/iommufd_private.h | 20 ++++ drivers/iommu/iommufd/main.c | 6 ++ drivers/iommu/iommufd/viommu.c | 118 ++++++++++++++++++++++++ include/uapi/linux/iommufd.h | 40 ++++++++ 5 files changed, 193 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 5fd3dd420290..ed29bc606f5e 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -135,7 +135,14 @@ void iommufd_device_destroy(struct iommufd_object *obj) { struct iommufd_device *idev = container_of(obj, struct iommufd_device, obj); + struct iommufd_vdev_id *vdev_id, *curr; + list_for_each_entry(vdev_id, &idev->vdev_id_list, idev_item) { + curr = xa_cmpxchg(&vdev_id->viommu->vdev_ids, vdev_id->vdev_id, + vdev_id, NULL, GFP_KERNEL); + WARN_ON(curr != vdev_id); + kfree(vdev_id); + } iommu_device_release_dma_owner(idev->dev); iommufd_put_group(idev->igroup); if (!iommufd_selftest_is_mock_dev(idev->dev)) @@ -217,6 +224,8 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, idev->igroup = igroup; mutex_init(&idev->iopf_lock); + INIT_LIST_HEAD(&idev->vdev_id_list); + /* * If the caller fails after this success it must call * iommufd_unbind_device() which is safe since we hold this refcount. diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 443575fd3dd4..10c63972b9ab 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -417,6 +417,7 @@ struct iommufd_device { struct iommufd_ctx *ictx; struct iommufd_group *igroup; struct list_head group_item; + struct list_head vdev_id_list; /* always the physical device */ struct device *dev; bool enforce_cache_coherency; @@ -533,12 +534,31 @@ struct iommufd_viommu { struct iommufd_ctx *ictx; struct iommu_device *iommu_dev; struct iommufd_hwpt_paging *hwpt; + struct xarray vdev_ids; unsigned int type; }; +struct iommufd_vdev_id { + struct iommufd_viommu *viommu; + struct device *dev; + u64 vdev_id; + + struct list_head idev_item; +}; + +static inline struct iommufd_viommu * +iommufd_get_viommu(struct iommufd_ucmd *ucmd, u32 id) +{ + return container_of(iommufd_get_object(ucmd->ictx, id, + IOMMUFD_OBJ_VIOMMU), + struct iommufd_viommu, obj); +} + int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); void iommufd_viommu_destroy(struct iommufd_object *obj); +int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd); +int iommufd_viommu_unset_vdev_id(struct iommufd_ucmd *ucmd); #ifdef CONFIG_IOMMUFD_TEST int iommufd_test(struct iommufd_ucmd *ucmd); diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 288ee51b6829..199ad90fa36b 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -334,6 +334,8 @@ union ucmd_buffer { struct iommu_option option; struct iommu_vfio_ioas vfio_ioas; struct iommu_viommu_alloc viommu; + struct iommu_viommu_set_vdev_id set_vdev_id; + struct iommu_viommu_unset_vdev_id unset_vdev_id; #ifdef CONFIG_IOMMUFD_TEST struct iommu_test_cmd test; #endif @@ -387,6 +389,10 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { __reserved), IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, struct iommu_viommu_alloc, out_viommu_id), + IOCTL_OP(IOMMU_VIOMMU_SET_VDEV_ID, iommufd_viommu_set_vdev_id, + struct iommu_viommu_set_vdev_id, vdev_id), + IOCTL_OP(IOMMU_VIOMMU_UNSET_VDEV_ID, iommufd_viommu_unset_vdev_id, + struct iommu_viommu_unset_vdev_id, vdev_id), #ifdef CONFIG_IOMMUFD_TEST IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last), #endif diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 35ad6a77c9c1..05a688a471db 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -10,7 +10,14 @@ void iommufd_viommu_destroy(struct iommufd_object *obj) { struct iommufd_viommu *viommu = container_of(obj, struct iommufd_viommu, obj); + struct iommufd_vdev_id *vdev_id; + unsigned long index; + xa_for_each(&viommu->vdev_ids, index, vdev_id) { + list_del(&vdev_id->idev_item); + kfree(vdev_id); + } + xa_destroy(&viommu->vdev_ids); refcount_dec(&viommu->hwpt->common.obj.users); } @@ -73,3 +80,114 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) iommufd_put_object(ucmd->ictx, &idev->obj); return rc; } + +int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd) +{ + struct iommu_viommu_set_vdev_id *cmd = ucmd->cmd; + struct iommufd_hwpt_nested *hwpt_nested; + struct iommufd_vdev_id *vdev_id, *curr; + struct iommufd_hw_pagetable *hwpt; + struct iommufd_viommu *viommu; + struct iommufd_device *idev; + int rc = 0; + + if (cmd->vdev_id > ULONG_MAX) + return -EINVAL; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + hwpt = idev->igroup->hwpt; + + if (hwpt == NULL || hwpt->obj.type != IOMMUFD_OBJ_HWPT_NESTED) { + rc = -EINVAL; + goto out_put_idev; + } + hwpt_nested = container_of(hwpt, struct iommufd_hwpt_nested, common); + + viommu = iommufd_get_viommu(ucmd, cmd->viommu_id); + if (IS_ERR(viommu)) { + rc = PTR_ERR(viommu); + goto out_put_idev; + } + + if (hwpt_nested->viommu != viommu) { + rc = -EINVAL; + goto out_put_viommu; + } + + vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); + if (IS_ERR(vdev_id)) { + rc = PTR_ERR(vdev_id); + goto out_put_viommu; + } + + vdev_id->viommu = viommu; + vdev_id->dev = idev->dev; + vdev_id->vdev_id = cmd->vdev_id; + + curr = xa_cmpxchg(&viommu->vdev_ids, cmd->vdev_id, + NULL, vdev_id, GFP_KERNEL); + if (curr) { + rc = xa_err(curr) ? : -EBUSY; + goto out_free_vdev_id; + } + + list_add_tail(&vdev_id->idev_item, &idev->vdev_id_list); + goto out_put_viommu; + +out_free_vdev_id: + kfree(vdev_id); +out_put_viommu: + iommufd_put_object(ucmd->ictx, &viommu->obj); +out_put_idev: + iommufd_put_object(ucmd->ictx, &idev->obj); + return rc; +} + +static struct device * +iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id) +{ + struct iommufd_vdev_id *vdev_id; + + xa_lock(&viommu->vdev_ids); + vdev_id = xa_load(&viommu->vdev_ids, (unsigned long)id); + xa_unlock(&viommu->vdev_ids); + if (!vdev_id || vdev_id->vdev_id != id) + return NULL; + return vdev_id->dev; +} + +int iommufd_viommu_unset_vdev_id(struct iommufd_ucmd *ucmd) +{ + struct iommu_viommu_unset_vdev_id *cmd = ucmd->cmd; + struct iommufd_vdev_id *vdev_id; + struct iommufd_viommu *viommu; + struct iommufd_device *idev; + int rc = 0; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + + viommu = iommufd_get_viommu(ucmd, cmd->viommu_id); + if (IS_ERR(viommu)) { + rc = PTR_ERR(viommu); + goto out_put_idev; + } + + if (idev->dev != iommufd_viommu_find_device(viommu, cmd->vdev_id)) { + rc = -EINVAL; + goto out_put_viommu; + } + + vdev_id = xa_erase(&viommu->vdev_ids, cmd->vdev_id); + list_del(&vdev_id->idev_item); + kfree(vdev_id); + +out_put_viommu: + iommufd_put_object(ucmd->ictx, &viommu->obj); +out_put_idev: + iommufd_put_object(ucmd->ictx, &idev->obj); + return rc; +} diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 0e384331a9c8..d5e72682ba57 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -52,6 +52,8 @@ enum { IOMMUFD_CMD_HWPT_INVALIDATE = 0x8d, IOMMUFD_CMD_FAULT_QUEUE_ALLOC = 0x8e, IOMMUFD_CMD_VIOMMU_ALLOC = 0x8f, + IOMMUFD_CMD_VIOMMU_SET_VDEV_ID = 0x90, + IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID = 0x91, }; /** @@ -906,4 +908,42 @@ struct iommu_viommu_alloc { __u32 out_viommu_id; }; #define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC) + +/** + * struct iommu_viommu_set_vdev_id - ioctl(IOMMU_VIOMMU_SET_VDEV_ID) + * @size: sizeof(struct iommu_viommu_set_vdev_id) + * @viommu_id: viommu ID to associate with the device to store its virtual ID + * @dev_id: device ID to set its virtual ID + * @__reserved: Must be 0 + * @vdev_id: Virtual device ID + * + * Set a viommu-specific virtual ID of a device + */ +struct iommu_viommu_set_vdev_id { + __u32 size; + __u32 viommu_id; + __u32 dev_id; + __u32 __reserved; + __aligned_u64 vdev_id; +}; +#define IOMMU_VIOMMU_SET_VDEV_ID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_SET_VDEV_ID) + +/** + * struct iommu_viommu_unset_vdev_id - ioctl(IOMMU_VIOMMU_UNSET_VDEV_ID) + * @size: sizeof(struct iommu_viommu_unset_vdev_id) + * @viommu_id: viommu ID associated with the device to delete its virtual ID + * @dev_id: device ID to unset its virtual ID + * @__reserved: Must be 0 + * @vdev_id: Virtual device ID (for verification) + * + * Unset a viommu-specific virtual ID of a device + */ +struct iommu_viommu_unset_vdev_id { + __u32 size; + __u32 viommu_id; + __u32 dev_id; + __u32 __reserved; + __aligned_u64 vdev_id; +}; +#define IOMMU_VIOMMU_UNSET_VDEV_ID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID) #endif From patchwork Wed Aug 7 20:10: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: 13756709 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 CC2C9C3DA7F for ; Wed, 7 Aug 2024 20:15:45 +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=e65jdJJhhANst2moupxW83W9dVMktWBZ9575fT6Mh1I=; b=q3af2DNX0JlnLPH0om7EMTkbzZ 04kQ8/f26cQy9qmENQAjVV/cys+IVT6AJXcEFwBvfSlZMalC1poEh+JS13qrRxvk/zuE9S8aSXFns LmpEQSV1lUOcT92kw2mEWSzX9bSxQ+vgnai4QMZtYxIx13CE9WKEd7Jkj+MfeD7JeL+pW4LCWieX/ yTHu7pYPXM78t8XNb0bYtiNLRy6EKyxu8/dwJCJQQ4Gh0CpkthIofrfCHhE7mk8iEQHkVgqY4O5uj IYM/lC1RwP+M+Obry3nmX684CWEXQ96FcCwp/yObvR1N7NPu5IVS4vKqd0Dj77Jon4J3PLo3pE5Ro Eu6xxOiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn4I-00000006AcO-3clG; Wed, 07 Aug 2024 20:15:34 +0000 Received: from mail-mw2nam10on2061d.outbound.protection.outlook.com ([2a01:111:f403:2412::61d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0S-000000069BH-2eSy for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rnKKgSqGkfO3C5upxt74X82SdAhuT5NZVz6GVT4RtgOT3TGePDBZeYR5t7hULeluY4JYI5+/Z20Db3oWDzODtickG8VRnmk4X2LgwIC3cgHSxkHiGGKHwsWug2wEsBZ/44TBMTBXkLssUKKmuaHXJ+b2YfxBRH0KcS3BN91ars2KyxR4IxbAj9XxRUge89AYPNVyWzoHxpKNEpLeHSeHW1O9MXISe2s1xKhZ6wo++2Wpgpsmim5OmbtpSBaDT5eW6uRSy2AlqPyETMy8UxDFq6R40RFmTsIFiKgn80CC36S0cWLGa+/q/8ZD6JwCi5C6OMVbKMGRHf+zrJUQs8JLOQ== 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=e65jdJJhhANst2moupxW83W9dVMktWBZ9575fT6Mh1I=; b=ILF6tyPPtgnQCEcR7Xr339KaP+e5KPHuckjeIly5NEEMY8qMb4P89GPqrtuFqnSxMjzogYRDGa69bSx86CZuSIBySinfXKOXz1FIgagGiNFS+lGko6xAdYiK+3cNcx3dWuQlAg59DWz/0axb/x/znvao5L/llDRuYu0WuUX6WyIgviYQXeJpDh/T3jyN0SxiZcu7p2gnZjaK7rdyV4Go0yEDNIm/CbQnHLwaUmgCUICikGWDG+fIxZiCBeNoqDyTP3h8w9OtKOvB91oNX7Ic9/x/bzPplWfBdtL9eGY/gnAVGnnXJ9yRKa6NF1afaxOawPa6WrYV/SVUcCVBufcsCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=e65jdJJhhANst2moupxW83W9dVMktWBZ9575fT6Mh1I=; b=YFp2WAi2Qq4tApfwTzxN8vGh8YjiM258/7pZpzBuGYMJskQlEy8pwaOPGyour1JK5+NqkyZSgwa45qVRxB0p6/1xfWRpk7CgyhS/Y8GfOqOt4nhGjWgLSgyizGlE9OOMQHMz+kLxIISYQK2EbbVY6uKM/XBBKfVWN3KkY6AtBSkBqdsNl79ilrRNrpMgESYddK2XMrFSDcUmUPPoSwysOBPRqbc1NUkANI6CwhelFFCW24GU1w3tO7BJmbwWgINqOzZ/N3CLK32uUDtlUXTu+/ffigrOD58ZBcjWg1KwqDwX+Gpx8R3ry6Xf28nK/YKdFGECgFuWyHzsfQBxdeyq8w== Received: from BL0PR02CA0132.namprd02.prod.outlook.com (2603:10b6:208:35::37) by SN7PR12MB6909.namprd12.prod.outlook.com (2603:10b6:806:263::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Wed, 7 Aug 2024 20:11:30 +0000 Received: from BN2PEPF000055E1.namprd21.prod.outlook.com (2603:10b6:208:35:cafe::55) by BL0PR02CA0132.outlook.office365.com (2603:10b6:208:35::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27 via Frontend Transport; Wed, 7 Aug 2024 20:11:30 +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 BN2PEPF000055E1.mail.protection.outlook.com (10.167.245.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:30 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Wed, 7 Aug 2024 13:11:14 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:13 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:12 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 06/16] iommufd/selftest: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID test coverage Date: Wed, 7 Aug 2024 13:10:47 -0700 Message-ID: <4e7303c6dc2cd585c3855be9cf9d032f23c66b9e.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E1:EE_|SN7PR12MB6909:EE_ X-MS-Office365-Filtering-Correlation-Id: 3673dbe2-88ef-48a0-0484-08dcb71d205b 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: SYoj9I5aXLpPTNna8cLGYRpB+PUenBe3Oh3BhTqKBkMF/NZVo9q7Ww+5ngeZfA0iuA45oYPr3Fi/VMoL5O4oX8Soku6wwIIol9PJEPAzEkvu5AHiQTe4H2nVzvtBjggXje5q+EbQ5gglO9YaPGcvZ3b3MOYZhgn16wPAtD4CraTWTXPy1qOtROBDDzw4C3PNfICgdsfFf6OEG0M6T8Hu1z5wUE1Od+LL8JMWyysPNsP5GskmdC4DV1V7AK3iW/zJV0FEsYfkRQCzMhvHrPK02IbcZqwYgMBWvn5Ii0twGbT0kjvcdFIdHQbvk4VeSiRo39FAFWoqhfaAn2/E7e97mPC61OCQkAUFlyDv385Dh2KVB6Mbb/nlx1554NEe6nyyeWcwJVeXFkC7l3vKjHeitBQsJ/kKc2C1imVDqu2rDC8umFHSuEtaKgODWLi98cCzXeEBs42aMoOPvWAOA+cg39WXaqD+9qrMw0dqaJFzSbY35Uj20l7BOv70TMsNbNUXkyKpG0tEqATjG7RhbrBaCb/vEx6ocvLgOucJv157eQBIIIPCcZDxtv8Hoube4gOmJ+kLeBUdLanS2yzGovKcCNLSOcd650yQ3vsGnZ8OtsadBFXCvejcqVJznvy7HUbLrb9VCLk+N01l9ouCOo1nQvvg0NU2hZrCj/LPYpYkVGzaz0gzzv6NAwAmwhXQJ50xiSZ+1vJohz7HtpHCVaU6ilGWfrXdOSN9eXBsU8NAipEEvagMK+APonm/DWX8bZxykdmy9pdSIQL58OjEYpQAHCBIT+N99744gYHM0XdXLqa1rxSffQibiJwXrTfDaVo93ZF3Y4v3TrB2mgQztwYh7ZIfK4fTt33Jfwg96axSDuNsQyW+LLPDgTAZ73ScHQK+X76d63g+SDJl4eff2zhTSDDncHx0o2byZWYMA+hiWDlCzeBPY+U6po6kvFJNae3s+MtzlChkBlE579jHgSFQDDdN7UExgeqvoBvmLDDfeXKp50MmlteOrXb8NlC1suVyKdAPldOlm9XvpN9hK91W42FffBQAIIVV8J3LMt4/XX67NgiR6NTmZnfCt5sI4/ZaEQ4MVgeeH2y0aM+TMfOxeJ+823kSp5wbPw3uqe2ZNkxh8miYwwcIKiOHlsK/VsBWdNVakHJxFcd0a6jiUxy+jNG00O9fhBOyXaMO6rkZvlbbY7ppkdmPuSUzOpeYFSpbWtylJrD/7W7jOrGukxA1bEWROKlzqlMa4UifDNaAzrRY3N7r369rmMIOQKmDCHO9K8oyM15jXzE4d3Tv+yY1zU/NJlC56/lBLePIDxz0nRCPGVt7ZKNcbVvob3CKxZs+dQxCZ7y/YVmQ4IQycwxEM6wMQhnEAa67hZbYFRCFeepsAVei++drI3MT6NC38CBlHto+fWI7PtC7dDCMgSolIq+m+ue7F86VVLfkdJOuI97QGfNwexN6gyqHY8wSBNXj X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:30.2506 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3673dbe2-88ef-48a0-0484-08dcb71d205b 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: BN2PEPF000055E1.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131136_786405_B1ACFF28 X-CRM114-Status: GOOD ( 15.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A core-managed VIOMMU maintains an xarray to store a list of virtual ids to mock_devs. Add test cases to cover the new IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctls. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 35 +++++++++++++++- tools/testing/selftests/iommu/iommufd_utils.h | 42 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 5c770e94f299..2c11525ae754 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -556,9 +556,15 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested) TEST_F(iommufd_ioas, viommu_default) { + struct iommu_hwpt_selftest data = { + .iotlb = IOMMU_TEST_IOTLB_DEFAULT, + }; + uint32_t nested_hwpt_id = 0, hwpt_id = 0; uint32_t dev_id = self->device_id; uint32_t viommu_id = 0; - uint32_t hwpt_id = 0; + uint32_t device2; + uint32_t stdev2; + uint32_t hwpt2; if (dev_id) { /* Negative test -- invalid hwpt */ @@ -575,17 +581,42 @@ TEST_F(iommufd_ioas, viommu_default) test_cmd_hwpt_alloc(dev_id, self->ioas_id, IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id); + test_cmd_mock_domain_replace(self->stdev_id, hwpt_id); + /* Negative test -- unsupported viommu type */ test_err_viommu_alloc(EOPNOTSUPP, dev_id, hwpt_id, 0xdead, &viommu_id); - /* Allocate a default type of viommu */ + + /* Allocate a default type of viommu and a nested hwpt on top */ test_cmd_viommu_alloc(dev_id, hwpt_id, IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + test_cmd_hwpt_alloc_nested(self->device_id, viommu_id, 0, + &nested_hwpt_id, + IOMMU_HWPT_DATA_SELFTEST, &data, + sizeof(data)); + test_cmd_mock_domain_replace(self->stdev_id, nested_hwpt_id); + + /* Set vdev_id to 0x99, unset it, and set to 0x88 */ + test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x99); + test_err_viommu_set_vdev_id(EBUSY, viommu_id, dev_id, 0x99); + test_err_viommu_unset_vdev_id(EINVAL, viommu_id, dev_id, 0x88); + test_cmd_viommu_unset_vdev_id(viommu_id, dev_id, 0x99); + test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x88); + + /* Negative test -- a device attached to a different HWPT */ + test_cmd_mock_domain(self->ioas_id, &stdev2, &hwpt2, &device2); + test_err_viommu_set_vdev_id(EINVAL, viommu_id, device2, 0xaa); + test_ioctl_destroy(stdev2); + + test_cmd_mock_domain_replace(self->stdev_id, hwpt_id); + test_ioctl_destroy(nested_hwpt_id); + test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); test_ioctl_destroy(viommu_id); test_ioctl_destroy(hwpt_id); } else { test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + test_err_viommu_set_vdev_id(ENOENT, viommu_id, dev_id, 0x99); } } diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 810783d31ca5..1b494752a87f 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -799,3 +799,45 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, EXPECT_ERRNO(_errno, _test_cmd_viommu_alloc(self->fd, device_id, \ hwpt_id, type, 0, \ viommu_id)) + +static int _test_cmd_viommu_set_vdev_id(int fd, __u32 viommu_id, + __u32 idev_id, __u64 vdev_id) +{ + struct iommu_viommu_set_vdev_id cmd = { + .size = sizeof(cmd), + .dev_id = idev_id, + .viommu_id = viommu_id, + .vdev_id = vdev_id, + }; + + return ioctl(fd, IOMMU_VIOMMU_SET_VDEV_ID, &cmd); +} + +#define test_cmd_viommu_set_vdev_id(viommu_id, idev_id, vdev_id) \ + ASSERT_EQ(0, _test_cmd_viommu_set_vdev_id(self->fd, viommu_id, \ + idev_id, vdev_id)) +#define test_err_viommu_set_vdev_id(_errno, viommu_id, idev_id, vdev_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_viommu_set_vdev_id(self->fd, viommu_id, \ + idev_id, vdev_id)) + +static int _test_cmd_viommu_unset_vdev_id(int fd, __u32 viommu_id, + __u32 idev_id, __u64 vdev_id) +{ + struct iommu_viommu_unset_vdev_id cmd = { + .size = sizeof(cmd), + .dev_id = idev_id, + .viommu_id = viommu_id, + .vdev_id = vdev_id, + }; + + return ioctl(fd, IOMMU_VIOMMU_UNSET_VDEV_ID, &cmd); +} + +#define test_cmd_viommu_unset_vdev_id(viommu_id, idev_id, vdev_id) \ + ASSERT_EQ(0, _test_cmd_viommu_unset_vdev_id(self->fd, viommu_id, \ + idev_id, vdev_id)) +#define test_err_viommu_unset_vdev_id(_errno, viommu_id, idev_id, vdev_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_viommu_unset_vdev_id(self->fd, viommu_id, \ + idev_id, vdev_id)) From patchwork Wed Aug 7 20:10: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: 13756710 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 312F1C52D7B for ; Wed, 7 Aug 2024 20:16:23 +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=5JYkKwU3A8mqt4Tl1OfDIeLhlon28+Jp/qcEf71GYtA=; b=UlNzVei6Prtc7HC9HDXK71rBei upLidAuGHjVzM99T/69mRXp+VCQJNbMxH/THSh4Jto2sgVY0RQfPPlBsqDiXsFa0EvebkiA8ReX5t drDfcMYXGyw22jnMcK5Gb71F5xxBy9I9zWVYbSoDU1lVbXVPmhZ+GPJtktEncFyHILZ3/gEkEk9ww z8seRs92+aXt2SLcDrdSZj6MsVc66t9O+guKj6Zvh7VYQxb7ffKs+rZ3pTQwwt3s6meWa1mVJ10iU ElOVE2MSb/SYpLEIXsKEM4hjOges6hmTJDdE/nmP1V3sPFi8BH5tEvHH1pgG9rIcCpXgfDZZuQS7x OwbT9/TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn4s-00000006AqK-424R; Wed, 07 Aug 2024 20:16:10 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0U-000000069D6-1FR7 for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lJFzI9PKUI/0WxHRRz2my+4HHruh4IczrCCJghed944XS7+6FwFSbLUamlK9VabWqwafTsiSazqDEQ6F7xUDtVYYm3VblUmbwG/tkN+F8SQcQyTG//rHXwJLAkoVGDeVkvxcRnAuTS6iGPV3OkXQSFIG3/3K53LxSHrZw5tjuzib03s1wJHDSX/JmbrdxutNfIr3r/aVGsu+ROCay6qEwYq2XRoq3hPtauWBW7FqIdnqjrP5TRO6Hebbb6RrZEieAH/g1cQQlbemez97L9tKsxOAlNWP5d18FE3QHDqSS/F/eQzxyZZnTLpDeTajO287/5td3rKefTIBlA7hVBZtfQ== 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=5JYkKwU3A8mqt4Tl1OfDIeLhlon28+Jp/qcEf71GYtA=; b=w+m1s7bCFkTnv7O+ngQewuYjY2RHEZA0eTaxZlxUwFiOZzjUHr5JKRwSNxEOl4XhqucXivh8E/RE57WHMykgVim9D2fdYkT+IZ2yhvhGUvA08HFYwAzUVOO1z2ZUeqfZGCbnrGG6CCsFjIk5uZcgFvBlNlKbUtLmxbrnmZPN/1wX5zHS4rhsIIM4pP16PfRWipyqvS6a0/eckRCFmfeLLAeOIbMSYTcj2riV1l2yBNpj2HhQBwevkLVTY5yffKq532WWLDdEwTSzlBpscrERbjADeHWhhyqLV57wAU1G1hZFi57P2bAyWG0r/hxpBVxZPEbYKj2ms4Kzw4QNsSrsIg== 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=5JYkKwU3A8mqt4Tl1OfDIeLhlon28+Jp/qcEf71GYtA=; b=XyR5ehBkio8SMIjvjHigIHt43oT+SXZeCsQUydl9STAQ1RCih9/AmzbYXEvf/+LI4LoiWle7yJhuj4cNBLe0AXHK0jlqII0e9UfpJ85tqpdRZ2NQPY3Gk8ksmKM9EJ/SeDQiIxcKWXK7KHzK1D8QmZDMavXo7YTTD/jPX+Amn1M2yF94QAm8BMflHQdiELImIRnShwYwRqug68R7ITRDKWCTvrRqisuf9xWo0KbzTcYPuI5Ua8Wwa3SyiGv3pzlxZyV8KJKXqyGq7V0Ps1cbdYYKzlTOJ6Hx/eikepejImRNEaPweU9avt8He5FzEdM08PF3pEMzwVo/HDP79lrASQ== Received: from BN6PR17CA0043.namprd17.prod.outlook.com (2603:10b6:405:75::32) by CH2PR12MB4216.namprd12.prod.outlook.com (2603:10b6:610:a8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Wed, 7 Aug 2024 20:11:33 +0000 Received: from BN3PEPF0000B06A.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::16) by BN6PR17CA0043.outlook.office365.com (2603:10b6:405:75::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27 via Frontend Transport; Wed, 7 Aug 2024 20:11:33 +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 BN3PEPF0000B06A.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:15 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:15 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:14 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 07/16] iommufd/viommu: Add cache_invalidate for IOMMU_VIOMMU_TYPE_DEFAULT Date: Wed, 7 Aug 2024 13:10:48 -0700 Message-ID: <00cd7da4abfcaa700064327a5087df8e7661116b.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06A:EE_|CH2PR12MB4216:EE_ X-MS-Office365-Filtering-Correlation-Id: d91216c9-140f-4d05-1065-08dcb71d220b 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: j4Z1XPhyzFoNNEQhI2srTnWzqIUaLNDdpH3LmSPBUsYpP8Y0S2MPkJ3oiB5lyIhNRchIWT/M1akkCD6+pUKI8QZuFpcaPZ53e4QcV0RGY/nHqWZEQXMbrcR79742qggEfIXHxoeoEmpAVzeOtxmgiz9kSQlJEkQWzJjBQ6kIQ49uSfsgTkHnGPNG9OV+LfJuGEBWZvFpv64feE8yJT0YJcK/SA8fb6hbo8aBagMcwu2eN79ztoCq26K1mhKqIpqNaDAPGVkJmCcz84ps0pU3T5N33664XteUBvvzisLNCZjZPklSbXk5kgv2/r/oLPslBHYH2sH/m4tnIzjRmU64VLSH+Cswc4o6wL4h/1jYGSh0b+9WZ2CM54aA7QRV6lu5UZEDUDQm/Dia5pVMTAFaJF4YKPZnKQFBsY6VN3yXgodODNHb95v6L9R4llNNfb7ROUHiQjssFlgav5QsamuG9yGAtlD8oVaYCNXNPuWxhc5UU3ZWOEHxMA0967qyQjmb0AclgtvW1Gc99aQ9l748/Qq+ltaZpBStrdeL1dhJwN0xLmDj2urCCAcQJiSKuW2qdHPpPC1KiBQaxWT9sLCgBupf4Nb6MW7SbV7Gr9XDN/+F2w3vytzDkrw0qrUj2WGhkEMctoJHyNiAJzBMCn/KQcMGQ8RKlF/1GBP2242GtPxcMVSc3XuadIBfed6j900YcGT2MwHWaXvHF0DQE16qsOtL8HZ4kmy7Ox1GIJ0YOSGs0jXP4v1k7jKN/4lu/hEAA6p0RdDSvb4JykUWeqO7yq+jd1cz+fBOsiaoWp70OGFYWNesWHYTqJ+gMfsxGc3/1filGSURyWypOLmmepeJ5ymOuP+PUDyx+B+yS81GtgtlaoP1bW66n3hJFt+gDFsJYYhVlTEqIGBIrik34Hn0JPOEhkO+BZOVIlYJ5wYD1CcOjmwIcu65uEsH7FmldrWOatxrQSmKXt1OPjleVWhxhC+g8BB333f/9MBEkG5c0+ka8p/h2D6uCZmgXTied/+JmBLPoffiAXrJccCwTR/s+jsdFMcZ9P3qiEmrKZzDRVxlTk17YpQ4wLiLr5m/uTWFfl170ejkHrg2bV0PoS0kL6D1TZI253USrfejR20obpPKvEl1UNF7378PT733fVpeK32X8S4Nphpz8T2gZQnIoKMXvuFRilAvro329rlDqwSLeQb6bscvD0TUxGQD3xhOCsAwts+G9dsCTuy44IJ3urj0h3woExnGQkIMLDNUvPBW1EmCqxdS7ADSaJ3glq891UnCcpBKmuqm/x7uOErMnvf058/yGOMc9mnZzvW46PXJJz8au13vtZhyqHpcMJYB5Yrc+szatqeTONnhw6giDm0DrQ8Vdi1YWc1oo7fveufA40YwZx3MgHGAakub6CTpWZC2hCrwpk9ZConJfc4Bzg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:33.0821 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d91216c9-140f-4d05-1065-08dcb71d220b 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: BN3PEPF0000B06A.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4216 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131138_545624_7C7C8247 X-CRM114-Status: GOOD ( 18.14 ) 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 Add a default_viommu_ops with a new op for cache invaldiation, similar to the cache_invalidate_user op in structure iommu_domain_ops, but wider. An IOMMU driver that allocated a nested domain with a core-managed viommu is able to use the same viommu pointer for this cache invalidation API. ARM SMMUv3 for example supports IOTLB and ATC device cache invaldiations. The IOTLB invalidation is per-VMID, held currently by a parent S2 domain. The ATC invalidation is per device (Stream ID) that should be tranlsated by a virtual device ID lookup table. Either case fits the viommu context. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2 ++ drivers/iommu/iommufd/viommu.c | 3 +++ include/linux/iommu.h | 4 ++++ include/linux/iommufd.h | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 10c63972b9ab..65023211db47 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -536,6 +536,8 @@ struct iommufd_viommu { struct iommufd_hwpt_paging *hwpt; struct xarray vdev_ids; + const struct iommufd_viommu_ops *ops; + unsigned int type; }; diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 05a688a471db..209d419fe5cd 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -27,6 +27,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) struct iommufd_hwpt_paging *hwpt_paging; struct iommufd_viommu *viommu; struct iommufd_device *idev; + struct iommu_domain *domain; int rc; if (cmd->flags) @@ -46,6 +47,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) rc = -EINVAL; goto out_put_hwpt; } + domain = hwpt_paging->common.domain; if (cmd->type != IOMMU_VIOMMU_TYPE_DEFAULT) { rc = -EOPNOTSUPP; @@ -61,6 +63,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) viommu->type = cmd->type; viommu->ictx = ucmd->ictx; viommu->hwpt = hwpt_paging; + viommu->ops = domain->ops->default_viommu_ops; viommu->iommu_dev = idev->dev->iommu->iommu_dev; refcount_inc(&viommu->hwpt->common.obj.users); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0b71b2b24ede..c884b2b9f8ea 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -680,6 +680,8 @@ struct iommu_ops { * array->entry_num to report the number of handled * invalidation requests. The driver data structure * must be defined in include/uapi/linux/iommufd.h + * @default_viommu_ops: Driver can choose to use a default core-allocated core- + * managed viommu object by providing a default viommu ops. * @iova_to_phys: translate iova to physical address * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE, * including no-snoop TLPs on PCIe or other platform @@ -712,6 +714,8 @@ struct iommu_domain_ops { phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); + const struct iommufd_viommu_ops *default_viommu_ops; + bool (*enforce_cache_coherency)(struct iommu_domain *domain); int (*set_pgtable_quirks)(struct iommu_domain *domain, unsigned long quirks); diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index c2f2f6b9148e..7da5140fa1b0 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -17,6 +17,25 @@ struct iommufd_ctx; struct iommufd_access; struct file; struct iommu_group; +struct iommufd_viommu; +struct iommu_user_data_array; + +/** + * struct iommufd_viommu_ops - viommu specific operations + * @cache_invalidate: Flush hardware cache used by a viommu. It can be used for + * any IOMMU hardware specific cache as long as a viommu has + * enough information to identify it: for example, a VMID or + * a vdev_id lookup table. + * The @array passes in the cache invalidation requests, in + * form of a driver data structure. A driver must update the + * array->entry_num to report the number of handled requests. + * The data structure of the array entry must be defined in + * include/uapi/linux/iommufd.h + */ +struct iommufd_viommu_ops { + int (*cache_invalidate)(struct iommufd_viommu *viommu, + struct iommu_user_data_array *array); +}; struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, struct device *dev, u32 *id); From patchwork Wed Aug 7 20:10:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756719 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 6823CC52D6F for ; Wed, 7 Aug 2024 20:20:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=os7gZ54YSo6aStBmNuIepdODOB+OiN1a5hqWeP9if0U=; b=GYKk/yQQvZKZuD4+dlPSraudIo YZU66eq+8f+/I9UrpB9BRYne6SbG5uTZJsUtPuXCSgB1ebKT7zqghyVHojwjK09A5VTcSxLcd9OR1 pJKKQA+kQ+sDaxSlWwAlGFoR+d3ma3ZP8UFBfh8ab0fxUw3h+KL4f+hoRPlqr6E+y6gB1qqjFGQ0i wOEFqGgyJ9iOR2uJFI+7BR+YgP2qQfVRFFByFlcrxCgyTiQEBXqy2Vsyhic8dEewthv1UNcL+g0Qs WxGRaGhvCpwAiTqvs3n0wYw16190rRmOIlCRoSFPYily7Ih7xfr48lvIPVPpjrsJnp+TXK/tYiEqc fluK33jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn94-00000006Bq3-0SaB; Wed, 07 Aug 2024 20:20:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0p-000000069PI-15th for linux-arm-kernel@bombadil.infradead.org; Wed, 07 Aug 2024 20:11:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=os7gZ54YSo6aStBmNuIepdODOB+OiN1a5hqWeP9if0U=; b=cF6RYndTSs1M3DZNcRsRHPby+4 sNCTWPbRVmHLFkUZ4r0M+YoHG0uPFDuwgAcNMArRO0DqI3zJTHlBjKDV6eUNoCehFGctpYwuIF3fI s/ztjpDo0CtPN81yy+wwG8v6GSzE5j/zrGlFxsc5II0ZbgiZSKGO6RvcUtXJx+uQj1BtprxACnUVi XTb8x2bZPDyyWZtaNlSm5hMXBA1HSAuvLeLjZ0/4cSdk3+HnX9SSnB8HzWK/fnw16gIqcZ6WsW+xK r8GDrYJPxSHkBq8SsSpcJ7M59XpbDfU83x81K5hxtiJ6siQbYousQgp71iUONo3C22xpbaUa2dX4I UcjS6+sw==; Received: from mail-mw2nam10on20605.outbound.protection.outlook.com ([2a01:111:f403:2412::605] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0g-00000006giC-2T0F for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PyT5n/qIegXoGRsXq9MA2byIYuLgZB4ymh8Mfd7mkFQLT1jN82E4OtJJ79t5odK5MKacOSjGrOVaFQfNquUzsk/j/j0c+RO8c5Md+tR+dTLl4ivdQTFgHUABIem4O15KhgafflVfTytuuvKmD/W2TeGpkhrDdQhpatsHVO+8c78pOrhXahO5AaQu8MQkfTO5W+o2SH19mJzDWqmpm3/Eti+AlUINOe0Bz8Cwpxh3hfzkrkVAVPrthZSpST3gyHPhcRUfXD7/i/mokcZAx8onVWPI1mYBPxBMhq8Rb05erASp5/uPJDNvMIBguSk9fE2EF8a4oiRZLYVcMlyDusTeWQ== 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=os7gZ54YSo6aStBmNuIepdODOB+OiN1a5hqWeP9if0U=; b=gevAAx5BAGsqPnh3UBw75s9RMsp4pHP8oIJMn550Y9GCpaVkIQOliYvKC+IyMNSOyfnR/pPg9E6ao+RVxsmSmYaYFl3HykWZ+VNhcvtjJRNj/mFzw6Eca/hb/9XSl11CdgtxJi8aXD9yfWvNTFq0Mchj1RkHQoF6S2cyuvy+tbhDBd4iBAjLdB/HpsAa7aARmnJ/hX3OWEPYOTVTod/n9osFOrGdKJDTsnU2C5cUwhgOYvZI9k3Ne0kjUAIF1Q+/C5XYtDpJX2upVOKoJQ9dzuMfy1mOJH1KBuRNMjfwHOz/x0zk6swmIzymA68X9Kdcep6ejnWGoL1bZsfUvskOfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=os7gZ54YSo6aStBmNuIepdODOB+OiN1a5hqWeP9if0U=; b=CTjWHABe5LkV6yRRozGfo3zQZfJ5cy9zZqwD1wofPGlQUn6CprzI2gnq8GBOXlYibWkbUKTOuZOZ5YcMGnw7smmX1LYu8ozoWHeWuwiZ3aaYyd/tQvKYfWajKB53Pfe5q979GzmjeFyNmnNVXVxJs4FlrGKtmoqXckX/DY2oeZC5hlgSMxB1tOsPD8X5wR6fauv1fGyw/yairHeqro32mxlV4m/uIipIDpym0lHNeCtvS+NyxKocpetvkUNn/T9tP6bEwzik+6wHTc31+Yrdc0eCFe74hURu93Jdd/MWozk8qsl2+CW834aThZb31ZZBgu50RYpqioQ9/qopKupOdQ== Received: from BL0PR02CA0132.namprd02.prod.outlook.com (2603:10b6:208:35::37) by MW6PR12MB8706.namprd12.prod.outlook.com (2603:10b6:303:249::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.24; Wed, 7 Aug 2024 20:11:33 +0000 Received: from BN2PEPF000055E1.namprd21.prod.outlook.com (2603:10b6:208:35:cafe::53) by BL0PR02CA0132.outlook.office365.com (2603:10b6:208:35::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27 via Frontend Transport; Wed, 7 Aug 2024 20:11:33 +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 BN2PEPF000055E1.mail.protection.outlook.com (10.167.245.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:33 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Wed, 7 Aug 2024 13:11:16 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:15 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 08/16] iommufd/viommu: Add IOMMU_VIOMMU_INVALIDATE ioctl Date: Wed, 7 Aug 2024 13:10:49 -0700 Message-ID: <59ad8c075bfa9de7098fd79a30b51d1f53d61a94.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E1:EE_|MW6PR12MB8706:EE_ X-MS-Office365-Filtering-Correlation-Id: f532e0e0-df37-4afb-2a37-08dcb71d2227 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: ER9rIOvXWCqAn7hIk8oelCDmi1pxY9B9iDlHbeFE2rVNHzNczSZzAjqWU3qiuh4J8kbccOTTuYx1WMDlniDxI68HMzBm9nZmEpSUh3I4gYLRS8GPa7NfQqN+QGXZ7yUcPLaz8T233VNxWULfcovQwgOmdNjHFGzzJvom+CH+qCosZnwbDJFGbTOYChIt760eWtaI7gVpaK6EVgHyUJMme0oIAVDl+IOrBxKmKgIw0LSsrWZV0ydVjiNx34AGa+72Yg1G+Noc24VDzikgmytEJVwTKKQw2+jZIfoU3larCp3WAHWgONG7jrQbYQQpBGuEJPb+OtTSwrxH8qu1F/dhdm2NDFWaOChkO5QDC/7MHlFsMWYj17QqLl52Tvi+Xftl53nvNiHB+Gq2175vf+Mev9vF8TM7pujj5/B+b4cI5iP8QnTap5i/eiLn1GH90HxiijIJ7sZOBoofKgTLwkGfNhFyWc30k/VXSNsd2Xs+fFBkkxHfP9tCuRDCCMTCJZ0GxSDYj4j/oSVL/3qv0I4ACiQW9ZiNe5pzc+GX4M2z47f5CMZ10lKXJBy8R/QojM+jLHdmfnVAubLJvj/rRDIiN5PfmEq2Ne9OnOriAy4YG1sBVXU1ckaNhEoK9v9LsYPGI+6QaXEgPb6Z2TJID/r3d5E5Jq5vdx0VIsxt+iNdw1k5SQcHq4O9Gbj9Al/PjVlOvXuaFo2+xjV7uchuDlX8sf56fBN8lz7ifSOddmBQHtEFDeXoLPsOizn9aXfNzCs/h74PAQhidrQKhKwArxg8wWZwF5brANN9Pt41zKWgia3cvtOMOaW+0ETANNm0M/t2zJ5/oSkPlO+S6BzfZIDHIU1WPLXEb6h2z8z/V7ZG65FgoMDgkDnrdOwKZGXVtLfDsiMlMQi8fH5o/DQx9rrcB96DXzHc7H3W9HqbY54ExbyhYSlah5aU0sSgr21SIWQsaJZLVOE/cCi3lujNygkDD1QTaV6Oyjw7U+Hb4D+zFI98v6sdVL3NhfqYFAb10GOEp2GeB8dJbEk7rfKF2za2yXvF06hLXPP2qIoTDSNfyM9TW0V6w5L+l8xu+0zBMAgNsPckyZzgqQjBgfr0IFU3M9vAuFJgqXKFZwEjSZLqgamyfIBw1bIbx6AcJgRVMrtgDSP8+LWNuyE2V7cNyEOD+Ng1qW6Obb0qFQ+3HSmGi3Tgvm0wDeQKDFflcTkQCqD38osEe+HZs5Hqn3YZQXZlZCjKGpk7VhwiYmdcDp4s+n3g04GfCnjE6dYF/YT35FYnQlty69KyaGya8KRoijM2Yw4M4z58lXP6G67fuZ4jzcRLZQnbwUVs0ZGApc9FHeB7jZNHxnVwSfguDUTBtHOQzHllt4/pgsA1hVEAOK4mIR2ubmGC5e6lzwOtJVs6R0I6KEhrqd1tnTE2KbFyfMZsPUcCAPW+/WEN7aBJBIMfZbsciNI+YX3YpFIhYx5jlYk8 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:33.2663 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f532e0e0-df37-4afb-2a37-08dcb71d2227 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: BN2PEPF000055E1.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8706 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_211152_525577_9087FAAB X-CRM114-Status: GOOD ( 19.50 ) 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 Add a new IOMMU_VIOMMU_INVALIDATE ioctl, similar to IOMMU_HWPT_INVALIDATE. This is used by the user space to flush any IOMMU specific cache that can be directed using a viommu object. Add IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 as the initial data type whose support is in the one of the following patches. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 1 + drivers/iommu/iommufd/main.c | 3 ++ drivers/iommu/iommufd/viommu.c | 45 +++++++++++++++++++++++++ include/uapi/linux/iommufd.h | 37 ++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 65023211db47..57c4045f3788 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -561,6 +561,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); void iommufd_viommu_destroy(struct iommufd_object *obj); int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd); int iommufd_viommu_unset_vdev_id(struct iommufd_ucmd *ucmd); +int iommufd_viommu_invalidate(struct iommufd_ucmd *ucmd); #ifdef CONFIG_IOMMUFD_TEST int iommufd_test(struct iommufd_ucmd *ucmd); diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 199ad90fa36b..85d4d01f9ef6 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -334,6 +334,7 @@ union ucmd_buffer { struct iommu_option option; struct iommu_vfio_ioas vfio_ioas; struct iommu_viommu_alloc viommu; + struct iommu_viommu_invalidate viommu_cache; struct iommu_viommu_set_vdev_id set_vdev_id; struct iommu_viommu_unset_vdev_id unset_vdev_id; #ifdef CONFIG_IOMMUFD_TEST @@ -389,6 +390,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { __reserved), IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl, struct iommu_viommu_alloc, out_viommu_id), + IOCTL_OP(IOMMU_VIOMMU_INVALIDATE, iommufd_viommu_invalidate, + struct iommu_viommu_invalidate, entry_num), IOCTL_OP(IOMMU_VIOMMU_SET_VDEV_ID, iommufd_viommu_set_vdev_id, struct iommu_viommu_set_vdev_id, vdev_id), IOCTL_OP(IOMMU_VIOMMU_UNSET_VDEV_ID, iommufd_viommu_unset_vdev_id, diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 209d419fe5cd..ada9f968b9f6 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -194,3 +194,48 @@ int iommufd_viommu_unset_vdev_id(struct iommufd_ucmd *ucmd) iommufd_put_object(ucmd->ictx, &idev->obj); return rc; } + +int iommufd_viommu_invalidate(struct iommufd_ucmd *ucmd) +{ + struct iommu_viommu_invalidate *cmd = ucmd->cmd; + struct iommu_user_data_array data_array = { + .type = cmd->data_type, + .uptr = u64_to_user_ptr(cmd->data_uptr), + .entry_len = cmd->entry_len, + .entry_num = cmd->entry_num, + }; + struct iommufd_viommu *viommu; + u32 done_num = 0; + int rc; + + if (cmd->__reserved) { + rc = -EOPNOTSUPP; + goto out; + } + + if (cmd->entry_num && (!cmd->data_uptr || !cmd->entry_len)) { + rc = -EINVAL; + goto out; + } + + viommu = iommufd_get_viommu(ucmd, cmd->viommu_id); + if (IS_ERR(viommu)) + return PTR_ERR(viommu); + + if (!viommu->ops || !viommu->ops->cache_invalidate) { + rc = -EOPNOTSUPP; + goto out_put_viommu; + } + + rc = viommu->ops->cache_invalidate(viommu, &data_array); + + done_num = data_array.entry_num; + +out_put_viommu: + iommufd_put_object(ucmd->ictx, &viommu->obj); +out: + cmd->entry_num = done_num; + if (iommufd_ucmd_respond(ucmd, sizeof(*cmd))) + return -EFAULT; + return rc; +} diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index d5e72682ba57..998b3f2cd2b5 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -54,6 +54,7 @@ enum { IOMMUFD_CMD_VIOMMU_ALLOC = 0x8f, IOMMUFD_CMD_VIOMMU_SET_VDEV_ID = 0x90, IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID = 0x91, + IOMMUFD_CMD_VIOMMU_INVALIDATE = 0x92, }; /** @@ -946,4 +947,40 @@ struct iommu_viommu_unset_vdev_id { __aligned_u64 vdev_id; }; #define IOMMU_VIOMMU_UNSET_VDEV_ID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_UNSET_VDEV_ID) + +/** + * enum iommu_viommu_invalidate_data_type - VIOMMU Cache Invalidate Data Type + * @IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3: Invalidation data for ARM SMMUv3 + */ +enum iommu_viommu_invalidate_data_type { + IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3, +}; + +/** + * struct iommu_viommu_invalidate - ioctl(IOMMU_VIOMMU_INVALIDATE) + * @size: sizeof(struct iommu_viommu_invalidate) + * @viommu_id: viommu ID for cache invalidation + * @data_uptr: User pointer to an array of driver-specific viommu cache + * invalidation data + * @data_type: One of enum iommu_viommu_invalidate_data_type, defining the data + * type of all the entries in the invalidation request array. + * @entry_len: Length (in bytes) of a request entry in the request array + * @entry_num: Input the number of cache invalidation requests in the array. + * Output the number of requests successfully handled by kernel. + * @__reserved: Must be 0 + * + * Invalidate an iommu HW cache used by a viommu in the user space. + * Each ioctl can support one or more cache invalidation requests in the array + * that has a total size of @entry_len * @entry_num. + */ +struct iommu_viommu_invalidate { + __u32 size; + __u32 viommu_id; + __aligned_u64 data_uptr; + __u32 data_type; + __u32 entry_len; + __u32 entry_num; + __u32 __reserved; +}; +#define IOMMU_VIOMMU_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_INVALIDATE) #endif From patchwork Wed Aug 7 20:10:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756711 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 56345C52D6F for ; Wed, 7 Aug 2024 20:16:55 +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=TLRuaC84Ka4PZPe9pc/TLQKq1Vc4xsd2IGKYVfwh890=; b=Jd+aInKtnS/HaMZT485sAZTBmY JqBmnoGT/YdN5wUvmii5ZRwtqrbSvvUVAQGDTu2uWX6nKVkkkl65jvHGQ8MJCYUE/9nOwqnxyIium fjT8k8viiPZ+I/VyYmUkuLmZUIqP6SB+FTlyuLa3Nszfk8vXCId9y+l5bhBM1XLfKxcDAZwlxS1s0 lPUWhBfosRgLSy5EYH21AhY5bwbNApkVhOH2uJBvdUvqIGArm0Hm7HLW4zx8exR+w/4hc3oKosn33 tzeX8Og2LUDVv+NRNrCz/DJ9NuRmbFPxMvA6xkgrXKeuLhydaW/nHPhMBbB2EfniiyWBev4LjWE/w 0kEqmdMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn5R-00000006B1d-0QmF; Wed, 07 Aug 2024 20:16:45 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0W-000000069Es-2aYG for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZTZQ+fSrteauweUHoWhHb8HgD0W2VSAb3GPiiBq4rab7gGI5CPF97FNH5BcMDNPKI86B5qFADWncwr5mRxRbLKcvRip5yPR+mAhB0M6xdZ//2B5cE1EiN9pisD0OMdKigrRT01n0vs5x2LKUm1gca8XTQzEw17N0jwBzjgUu+SVNsxbZM0v/5KAt/zpL9obd2LeQMGtZfrvnkwSupkObqhX7cDuBTaIieJhmy5m9cHE6eki21pkJcgD09aDDXS783u7wQgaMuqZZ/tJWNvSg9appQxwFI6lNuNJdz6axZm0ZTE0FH8OndXnInnGLRzogSOgtWj0TNxN2k3/XwWQzmw== 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=TLRuaC84Ka4PZPe9pc/TLQKq1Vc4xsd2IGKYVfwh890=; b=kxUyLkflVva6xDSxd/7hfdskOTLyW3di/EPeIs8a1JQ+CMl4d/NzUvXMzHL7gDKwfdELNTYbkjDSl25LGulQS8zBJChePXO9Ld9qG3mbSztPM6lHnd/+znwfsPxrMDxGUxYQZhUKkw/uosigJbL5cOKh+AtLi0g7ueKGSChmIZEX2D/GBYrTC8Grv8pM2jJovi/WIONTYBKQbxPa7Ts75OZWY+szFHN/cIEVdgaibmTwVQJ2lGYdwYXJZXObigdXNTMQZNwcoT7nCRgIvQLNOxc7sz6eQiWhNzHFy1MntirO+g7ol1AYZOO1s4JZJUN6+lccyCzm01Y3VGeGl0fh4Q== 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=TLRuaC84Ka4PZPe9pc/TLQKq1Vc4xsd2IGKYVfwh890=; b=maYo0tmRU2jRbKA4Shey5aTsovZwOGnICa3KUZ8WIH2VrA3yaI7Cj4rgxkxDZggRMM9f5svJ1Ld73zCJF5NLLmwH/7kq9P8iHohrPVeVgO1xbQUslvj9tWkKab9mS47DR+kV8E20WV9/9dF3RLZousShsOV7zhsMubnB7bmReIU/rcZnBYcHQbkP0sm02PjohErKtcT1RzYaFkSCZZs88Fp8AIwyQ2tBeZw/4Vby0kI6rkC1evdbDjgLr/C7lh8eqpaEr0arJvnaOO7GawoimvHyNbkMjCf1vAOVW0EQw14GCb95hITrA48ydy91qiyzB/4gmdpVfncEzT6f3CH5ow== Received: from CH5P223CA0010.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::11) by CY8PR12MB7731.namprd12.prod.outlook.com (2603:10b6:930:86::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Wed, 7 Aug 2024 20:11:35 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::ff) by CH5P223CA0010.outlook.office365.com (2603:10b6:610:1f3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:34 +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 CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:18 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:17 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:16 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 09/16] iommufd/viommu: Make iommufd_viommu_find_device a public API Date: Wed, 7 Aug 2024 13:10:50 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|CY8PR12MB7731:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c8d0108-e3f3-4da5-ac27-08dcb71d22d0 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: 4VcmKDVCswUZFBFqX8+RMqE5Sl22XDjaZmhxW4XuzDZBPwkTRh7QM5EyG9iA6Rd2XeCNWU/wm18e7rhIRZZcCtFf83YD2ngeYSHRkHI19Wotd6lc9GRNbYTh4LO2iPR+2PZ+r1IF/lXfhJvFhLcBqqiaqeSN3R6I49XzGJvmVrVn/kf4go4LYhk9UwgbX1u7rBTmdkC2tQjWj8WRfFszeDdj4NeOtIoDL7zN6gdJZ77qjmEUm/Fqx7cwIjULtELDoKJWxpI07Q4iwc/hmdN5uq68vgo6aKv4YxvKLudCo2AJ4nBX36NwPmLdogNNgRrx9tCV0sFQz5jrxSoVplLpDASAi9Wbl/LEGqBTxNu1DnXUL2seiLzJ4Gzav+9DVQNz/LzK6JUgpIeRM4D97EkbYURvhI/yV/l0Bddx7U9xBtaDOvhs5CnxMpS68cgNdT2eVSrkUtfJnahkjAgdPIaJmjhvkosiIPIIARWRkNRfIgqr6M7dIOtt+sjYZSP0SvMHJVcUhD4sG9dtINzr1Ym6ME+EYlsmr/z+i5eRjgN4qLd7Wt+tVkmDlIS2lEN6lM5RoWOBsU7ZugB1X33auiswXnHhTL1BSbgInES+MCRTq8vZiJIJbH/NGMzFvFwqz0qO51NI7FAfJgu/jBNI8lbC1Ynbb1lWRlzfzPdYT1lAkuDAhZ/5Y4L+aQtUzWI8zAu9HjPcftFVFyWmoXuR+FjE+DvlEjORjyI+bSMot38JQEAjudp/GRUIygv9VkkTuhvaYeNt93jTrnes4DUq5J6Gr64gGN4GBahRHSZ2mos9jReBmkQ29Ica5gkp+QZdCd/xZjgEyOdMjSRjoW3mft/fWvrHY3/3EkXoabfVkVukAx1Ja/ocVx6dsi6BRAIy7B8sbM/p9lG+FJFa0lJvCvrPIqOgUfqYhBQRq68IxSd+pZ5ec1SzAo9v4olqvaA/7LQ5lqubI02J5QX5WZCeY41eWTN8WH+tcB4f4Wkbt1O3p6MyAEp7f5p9ZkfN5PyQUQ39SouHxSrJErtAw6DkG0kDOkqgTswcLGog3fSY4BcfGltOL+SqoXTQhHnlD49+vRes7vBbG5Q5X8bM366AFTAixZc8AvytJEB6+rj7mD03/SBzV+yDThsnD2dM4ZsDgfuLnOKOEd1+wAaRYbGhP8xhhfFM1rjHKHk5H12vCUrTIhcNL4AjBdX3GN0x4jlgD8VsUdJ5zYh4EnJUTEVaFEdIlES2saFkToP1rk78/Caw5qi4+FhIDd+wNfpno7pWpQuJ37z2cw/Q8HlNyW7uKOhe7Mr43J+cgvMDjnlnuy1qygAPrx3KHCAMUDyY5xpCNhA/m3qDVbvDei4sXdNN5zT/32MHCYC21AOqvYP8TV6aYo7DrHHNoLxjnMfq/TyLcTIGBEeJvOLXtpTnyUPnJME3eVrmbV4NgRRNk3QwS2S6RdhagmT9T8ZYRbI1/LVDyNJR X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:34.4240 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c8d0108-e3f3-4da5-ac27-08dcb71d22d0 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: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7731 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131140_829182_85BC24F3 X-CRM114-Status: GOOD ( 14.24 ) 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 Now, an IOMMU driver can use viommu to invalidate a device cache via the viommu_cache_invalidate op. Very likely, this would require the driver to lookup a virtual device ID for a physical device (or just its ID). Since the core already has a helper, make it public. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/viommu.c | 2 +- include/linux/iommufd.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index ada9f968b9f6..2304f199b033 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -148,7 +148,7 @@ int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd) return rc; } -static struct device * +struct device * iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id) { struct iommufd_vdev_id *vdev_id; diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 7da5140fa1b0..e0d7a53acbd5 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -89,6 +89,8 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id); int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx); int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx); +struct device * +iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id); #else /* !CONFIG_IOMMUFD */ static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file) { @@ -129,5 +131,11 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) { return -EOPNOTSUPP; } + +static inline struct device * +iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id) +{ + return NULL; +} #endif /* CONFIG_IOMMUFD */ #endif From patchwork Wed Aug 7 20:10:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756720 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 67107C52D6F for ; Wed, 7 Aug 2024 20:21:11 +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=KV/Q6SMkExA2HoQBd7r5qaLfNJF1CD8r+wXPjbVzOZo=; b=5BNgW2ccfK+DOJ8RNCnGwu7ClP dS5ej+LT/WBVs3kpY4BLqkrAdZ4DAZqLLyBFsfqphnjMXiL14gAP6IDOgEH3cZmJeENxMEAvajzgp 29oa6YZeVUcuHOdvsEj2Q1uSu4awh4xLrt0npvVj3ambrVDH4lM1kMsXqmnyRjphhmOiC8prleSg5 s+n0z/mLidyGmVKjHFy/1P579q15xsyQWs99Pfi2pLZh5Z2hkIZ8OXeIP25hhgaqaUxU7ImKf3rQh NFq1UhJRNbgK4R24Grh8cQROHxgfQBWd38EUCEwJmpYL9WpaRIf6rTJuBn+XDhBaHPUqie3PA96Vj Xy5Srwzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn9Z-00000006Bvh-2aIN; Wed, 07 Aug 2024 20:21:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0p-000000069PH-1lPF for linux-arm-kernel@bombadil.infradead.org; Wed, 07 Aug 2024 20:11:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=KV/Q6SMkExA2HoQBd7r5qaLfNJF1CD8r+wXPjbVzOZo=; b=qjoWNe38yRRIhGZyF+MxfNZZhr 9fnRe3ZQnotF2cKU+J+FLZlj0k8UYuMjys0VWVfyp/YwPE7IelIEt5TNqhr+I1fvduDSGwlFGE+JX MRP4ZIJYfm8Y8JqN/T48nSHLoKpnmkXstSvOIha7Bx3EjdJaqJAccXgMYsqiidyoO7sSAm5hGJe8T MlogSZOJfGePlCtG6f6k1wMCway39nLHIIwPwpEGYELyxs4N62du43gEQLkQwgS0ZZjb63OV3k/Rd qB05VzVBzK4TiBbUvO/bQaebjuwrROattBGmhIlvbU8eWcA4i6DXQX3Ul6HnG8gAm7volptYTCdpU 4CCE8kog==; Received: from mail-co1nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2416::600] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0g-00000006giF-16ef for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D0FjQnA6bc3qKMZsr86msfbJ9SrFJlymKpcLen1Gk8HgwAfZMk6rbpZueNVo2r2QjANWjpC3qRiPlZub5Zmi72Zx3xlZQIN5MNxMLdxekOe9Kn3zdsp51uwa7P991nNfDC6Pt2ebwAHHML8xtoQ94fyrsz/cTtR6nldM4SMfhS44QSFCACAxm7m31MO4GHmwa/7a+qj5JchWw3gP44bCnUDeds8byFxg3DGohjV0NiUB9eRFV+DMNh/74OTQZfdFgi2nbeD9q/qBqD9RmD/yZvn5a1+j106SmIsdFQZis4FjIkOaAvuNZm0GPWZ7KY19YXZaYNo/GF1GNV5drD7KcQ== 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=KV/Q6SMkExA2HoQBd7r5qaLfNJF1CD8r+wXPjbVzOZo=; b=ydZWePNZhcajbzmUXIRfE+etkYryUqKnwSczlcF6yVxaiRdXn440RS7jsnxt30WBOP1pBfprfgNEA+M4BM2pQK4pVlDvqEU+flOzk+BIQII/R59qJ5ym/Dm0v448UPxw8pKNKMnw783wQgPGtDkxRAyX+UyuxJ7Emgbky1wPCYETJJQgvHZKhm0SwA2BpCyJfeFXvIUe41mqgVyWnGbI8110G8NX8pbsg/NWNsywvlzZ1nmC9iIp8IYiLAxaVX3yfJ3yr8zLDhuOD1WC2ch3Qf/YyfkSZ2gj5o6cmGvdIz3Bp6JqK449lxGrIglDZUQQN5gaakfosCul6i62aGxdXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=KV/Q6SMkExA2HoQBd7r5qaLfNJF1CD8r+wXPjbVzOZo=; b=Xt4PHJlydFkhjj4yKKumpHg9vJreHxqqAVRyAXv7xyqtmVnPIivhsPuIdMtSzYxjsgFjS8F+Ec/5gxGbs+PhmqtjpWEr0tyUqqsbZyA9zZIyi/ftiGssPuh2xA8ykyqapDOTNdy+LA6inUAYhF8HzAKb4Y3HWKrmZLb7IYNLhJEAQH4kS6lboNbMY7D1ymHOe/+4SuR1FzwosLUMxBvyi3OaLtw7XUj/k8i3+OVcugIWTJ97UfYGDwVC7FscpU5BKXhMlcp1J02GqaOVxt2/JwR+4o8fGNRX2e4xKIFbgmG3hP4Tg2YFdlzBmWtS4ypTCEeTO5Z6MYD3SHYATKfL7A== Received: from BL0PR02CA0111.namprd02.prod.outlook.com (2603:10b6:208:35::16) by CY8PR12MB8268.namprd12.prod.outlook.com (2603:10b6:930:6c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Wed, 7 Aug 2024 20:11:35 +0000 Received: from BN2PEPF000055E1.namprd21.prod.outlook.com (2603:10b6:208:35:cafe::5b) by BL0PR02CA0111.outlook.office365.com (2603:10b6:208:35::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13 via Frontend Transport; Wed, 7 Aug 2024 20:11:35 +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 BN2PEPF000055E1.mail.protection.outlook.com (10.167.245.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:35 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Wed, 7 Aug 2024 13:11:19 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:19 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:18 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 10/16] iommufd/selftest: Add mock_viommu_invalidate_user op Date: Wed, 7 Aug 2024 13:10:51 -0700 Message-ID: <3242ded32a55b4d5f95c06b9b2dfb6809a0b1b9c.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E1:EE_|CY8PR12MB8268:EE_ X-MS-Office365-Filtering-Correlation-Id: 59e0e7a4-c3c7-4278-a6cf-08dcb71d2347 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: WGwbw+Hb6cssShANUFJqj38lGMjg90rXFUEnCWtlDSElHsfInygWfkD2p8eoQFcdeEn/DOZpg9Uhtqb4yVGYwBRjW1uYY4d+Z6FmdJziiYlMmWS5Z+Jt00lCqHJpVO8Ajf31/2vsFat1WQavIWAHVi+bVB4OqNZ4gTbQosvVl1OBFR6lyoqquwNMKajrRgaNT3t880VD+nA8ouhlfqsaLz5OI9TPTCBiZ2lP8k7CFzEreNweADsdC74jZhQZIYIvyitixlwCZZ0EQwiaEj/7ntAvlPBWmnFmTgoS4q9LpzK4HvtRJ+LsIkVxyvv08iMXGOsxVQNpd1ICsqI/HjeNFK9sozTPW7u9Z+xlujVUvytczM1HavCPLlsRYIMrqkNIUY8M5UJtfJR/Hb8zXbl4Z8w9fasNs4AE+/t7LC/LnNzct+mYEyPiDR6UXtn2QgDKq2y3Mi5yh1448A8wQzRYON140cUrrMsAzxVTd80QbaSqvRuOZH8I8WIIPY+O0rznHXHq0msecOA2bUprtkDzy2IqxTkY/94DV6X04mk7/uo5/aHp1bCuPMJb1j2hLzB0PpBU2oUzhIUikilJhBTXd/fxTpfxkwFO13Yze49tdl5pestaOKMcLWCF7MBt8eoEG49BbZUzbNwflYTG8bryanY3mhsKcHZkhT8q6KX+o2829kiJiCXbEkw0Ky59SfCPCLpikfB/qqxwpOLcE8YnyNDGIRMwrzriWTC3iHtDspBT/qmvPcVK44r2zNzhxiumar78GvqYovdoiNSTZM658aAqv+eiWrO8jIrZ2McQc2Cwkge+E36IcaSwlIejg/4toWJ1pvLWZPwGdLFBlg8wKpdr1CTZNionMYbFDcPZN1gn+NmKQITutmj6rIJe/85U1NqNiJMJuIgsQJHru0DEuFehOFCFWdSF/k4CiTmm+n3jlmbyEzlnX0dn0hLwvbc8LL59Kp95dLS4XTPzKs2MjSj2M27x0eSo6WFRaK9SJbY+kq2pz1JVTqsyq77VvdS5aaVcjF+VxMXALJI7LSUhO086mpmszykV7p1fZ8Dnstd5+L5VCp45dYgG45RgvjRdY7Sg0oz5fUTWHB+SJS3+sqPQpoV79XZFui9mrvM9Ug2xgRLKaFR/rx/VAwhOZvVb71/hE/TyFVXOPBzWL4nd/p7HAAU5N0iigWJK39iwTIfeOW+Ly6eP6/oc1zXvhmv4WynasOO8z329pjcUc8ag3U+1OjBF7Ypn/J7FRmMHrv+uKeH85h5/p8LrCJmFE6pqb7ZkMmFgE/d8Y0CFPfeVpj/FPnI2/0u7tiquzaeuzsQOLTbNFCS0y8os7NfvS/tAcwBAjxCQaxwitDizsn/ynqD3GKjTS7/RULEx94i1oKpqGV8AlOMykMjL3R26sUekHh+Wuieci3w9/FyNLu1jCTRmxolNu/XrjPmW/9xOQrGsLB8gEN86SLIzBUoK0TmT 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)(7416014)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:35.1725 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59e0e7a4-c3c7-4278-a6cf-08dcb71d2347 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: BN2PEPF000055E1.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8268 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_211152_526720_A42DFA71 X-CRM114-Status: GOOD ( 20.09 ) 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 coverage of cache_invalidate_user for iotlb invalidation, add a device cache and an invalidation op to test IOMMU_VIOMMU_INVALIDATE ioctl. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 25 +++++++++++ drivers/iommu/iommufd/selftest.c | 63 +++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 0bb30275a92f..da824b58927f 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -55,6 +55,11 @@ enum { MOCK_NESTED_DOMAIN_IOTLB_NUM = 4, }; +enum { + MOCK_DEV_CACHE_ID_MAX = 3, + MOCK_DEV_CACHE_NUM = 4, +}; + struct iommu_test_cmd { __u32 size; __u32 op; @@ -156,6 +161,7 @@ struct iommu_test_hw_info { /* Should not be equal to any defined value in enum iommu_hwpt_data_type */ #define IOMMU_HWPT_DATA_SELFTEST 0xdead #define IOMMU_TEST_IOTLB_DEFAULT 0xbadbeef +#define IOMMU_TEST_DEV_CACHE_DEFAULT 0xbaddad /** * struct iommu_hwpt_selftest @@ -184,4 +190,23 @@ struct iommu_hwpt_invalidate_selftest { __u32 iotlb_id; }; +/* Should not be equal to any defined value in enum iommu_viommu_invalidate_data_type */ +#define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST 0xdeadbeef +#define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef + +/** + * struct iommu_viommu_invalidate_selftest - Invalidation data for Mock VIOMMU + * (IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST) + * @flags: Invalidate flags + * @cache_id: Invalidate cache entry index + * + * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @cache_id will be ignored + */ +struct iommu_viommu_invalidate_selftest { +#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0) + __u32 flags; + __u32 vdev_id; + __u32 cache_id; +}; + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index a165b162c88f..4858c74c67be 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -141,6 +141,7 @@ struct mock_dev { struct device dev; unsigned long flags; int id; + u32 cache[MOCK_DEV_CACHE_NUM]; }; struct selftest_obj { @@ -560,6 +561,61 @@ static void mock_dev_get_resv_regions(struct device *dev, iommu_dma_get_resv_regions(dev, head); } +static int mock_viommu_cache_invalidate(struct iommufd_viommu *viommu, + struct iommu_user_data_array *array) +{ + struct iommu_viommu_invalidate_selftest inv; + u32 processed = 0; + int i = 0, j; + int rc = 0; + + if (array->type != IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST) { + rc = -EINVAL; + goto out; + } + + for ( ; i < array->entry_num; i++) { + struct mock_dev *mdev; + struct device *dev; + + rc = iommu_copy_struct_from_user_array(&inv, array, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, i, cache_id); + if (rc) + break; + + if (inv.flags & ~IOMMU_TEST_INVALIDATE_FLAG_ALL) { + rc = -EOPNOTSUPP; + break; + } + + if (inv.cache_id > MOCK_DEV_CACHE_ID_MAX) { + rc = -EINVAL; + break; + } + + dev = iommufd_viommu_find_device(viommu, inv.vdev_id); + if (!dev) { + rc = -EINVAL; + break; + } + mdev = container_of(dev, struct mock_dev, dev); + + if (inv.flags & IOMMU_TEST_INVALIDATE_FLAG_ALL) { + /* Invalidate all cache entries and ignore cache_id */ + for (j = 0; j < MOCK_DEV_CACHE_NUM; j++) + mdev->cache[j] = 0; + } else { + mdev->cache[inv.cache_id] = 0; + } + + processed++; + } + +out: + array->entry_num = processed; + return rc; +} + static const struct iommu_ops mock_ops = { /* * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() @@ -587,6 +643,9 @@ static const struct iommu_ops mock_ops = { .map_pages = mock_domain_map_pages, .unmap_pages = mock_domain_unmap_pages, .iova_to_phys = mock_domain_iova_to_phys, + .default_viommu_ops = &(struct iommufd_viommu_ops){ + .cache_invalidate = mock_viommu_cache_invalidate, + }, }, }; @@ -722,7 +781,7 @@ static void mock_dev_release(struct device *dev) static struct mock_dev *mock_dev_create(unsigned long dev_flags) { struct mock_dev *mdev; - int rc; + int rc, i; if (dev_flags & ~(MOCK_FLAGS_DEVICE_NO_DIRTY | MOCK_FLAGS_DEVICE_HUGE_IOVA)) @@ -737,6 +796,8 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; mdev->dev.bus = &iommufd_mock_bus_type.bus; + for (i = 0; i < MOCK_DEV_CACHE_NUM; i++) + mdev->cache[i] = IOMMU_TEST_DEV_CACHE_DEFAULT; rc = ida_alloc(&mock_dev_ida, GFP_KERNEL); if (rc < 0) From patchwork Wed Aug 7 20:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756712 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 304F7C3DA7F for ; Wed, 7 Aug 2024 20:17:31 +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=TC9SNW7IN7fFhJQHD5YDKVE2lhSn6XQdyrDWCjDgKqY=; b=JIfjd9vXMEsM+L5te5t08HXyiE k6nH8TFxCy3ai6iZUOVmTKSrBrtQf3qJYrg3J/QfysqX19xFf91HiDwikPSVC8WrL7PO8y7eDphLQ sDXTdsli+7NN9xDgPvUb0W+5IG6FXauqFTf3XJJnoUL4l63EdFspFt3RXGFxm9WGP1qzdttaDJ5jA ZuU5uCxI6M2YfNZs5I4ukLVVahLzcm8urKG9Eb9pDz1Ty4qVflP6Pj0hWFq+M4hS0sZ5eNcyNvT1l Y3EKetZQlo30TRd4vzGHkgvnXycGEEruCoZpurNrvccY0JiMU6rMomTRegyUOpJkZWaEvicEEDqSJ 5iCOEqXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn5x-00000006B8V-00la; Wed, 07 Aug 2024 20:17:17 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0X-000000069Fo-07ba for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qoutBs9Jb+VLP+QPwYDObhawMGmttQfFq+aH5S294HCqPGJM+IRycgp+/sLjyixS17YOqjZQwqWx3iSEdrLgUaOfKd2cW+YFR0bljnaBdg0YT6+E0KPkvxyxVwy9WojxPaOuW9H8RBhK35ESbxLd38hdNlhVmQbgrh47AaE+37JPFBCzTrJK5hR8Qwx1Yn4Hk4dDkvKpmwpFz3JU7kCUe/nLoF/sY6oXvM79HJaL0uDGQUyjDK9FIcoHn5UN9xfmPwn1PwFCDlhKelNxHbEuot/mUPtFuByDAEUqf8pRmYohE1k91H6IYsx+RmYTqk57BYkyJlo2HwWsmNnZ8BJQNQ== 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=TC9SNW7IN7fFhJQHD5YDKVE2lhSn6XQdyrDWCjDgKqY=; b=Tn532meVyExfsO+eOqgktqLdmWtVL3YhhUGNjnomZTBqz0F/pS7bSXzzuc5Srqh4xewhvbBcPaWo6bzEU7qDdQ7uHeiy5zXZpcjvt5cibLaFsggcUbxX1s9xrCu04iSk8ZZTyd155qV4Y4bk545H0/kFvV0W2VZZriCYmk3nosdc2fjbNmE6HanGUYGGxFIAdKX1eXevmY0wHoXkhykeo6xf501YZWLE+1ba5FEb8OHRCIQsLnSV4CWUnOyKTaYh4y87MuGxOn0MmLXBjkaQSL85Wet3E/yj3xcIf8+J++VCfgbtgnrGvbsPR52M+3rPP4itnbZHDmHRefK1P9p/+A== 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=TC9SNW7IN7fFhJQHD5YDKVE2lhSn6XQdyrDWCjDgKqY=; b=fAadpBYRSFxcVTp17radY/bLzYE0o1Undp4nfRSVx8r2CpwTqjCIyGkpfUGlfrRZy9T3SxXFjeFSBuJTM13u0r74VDvr9pJ0SJ2IPZmcZaEVUg3DUZ74UoYNMKbkSGegKiviqMfHwi3j9hciS4VBS/L//XLP4oQ91NB+Q9EK5K4Oh2ZLr0Mcb95H48KsI47q/uUidgsk4WmIts8u0nAAGe5TMqIIkvmiUTsRik5dgtymdG9oJ3Sq/+o5TL5ehOA03w8mxRnml7UKZ9T6HuH/ZMzDo00dvK+TmOzd7gwSHknvHlpqwoA6ybyNMo8nUYY7YQdp80l1IQw9PVtRGq63Ew== Received: from CH2PR11CA0002.namprd11.prod.outlook.com (2603:10b6:610:54::12) by DS0PR12MB7778.namprd12.prod.outlook.com (2603:10b6:8:151::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Wed, 7 Aug 2024 20:11:37 +0000 Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:610:54:cafe::48) by CH2PR11CA0002.outlook.office365.com (2603:10b6:610:54::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.29 via Frontend Transport; Wed, 7 Aug 2024 20:11:37 +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 CH2PEPF00000099.mail.protection.outlook.com (10.167.244.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:21 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:19 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 11/16] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command Date: Wed, 7 Aug 2024 13:10:52 -0700 Message-ID: <8fb4b729182b39165e9594f71eb756fc9679b97d.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|DS0PR12MB7778:EE_ X-MS-Office365-Filtering-Correlation-Id: 14078cfc-e4e0-4bd2-f8ad-08dcb71d248a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 34flCrzNvKr19Kdf+yapPYGaNVH8ifp4qyESDdnkdQKMX1bn5o74GUy/9SWrCGTtWmpFfay4rKXMY54/yQDLTt4u2nM/O4u3NBMX5MKIylp+Vi54AM6TUl9zG4bLRPAwqxkmz9Pwz2uqvNbioeHKL62Bnrp0K71zbA/Wb8sQ4dJ1cH4lsvFCblunAe6Jh3w6+0mbkcRngEhcn4EwwKvRuSALnXqJCxC6nmaKJdxzCrn4XLl34V0PGAmDOSpPFCuS3eb4FQ1CPpODlaxBPkUpCo7xJUQPgL9S4ECfzdm/Lj6n66Zl/kZDUvzJBf76Qb6ywktnP2yII0EliXjDsv/9pXN6PdV1q8pCcaJE81sNt7Zf581RrW6fLd8hxgyVO6QCNKsfuvMGALNYK8Kv6ZEvQFSGVcSEPAcD5eULNEr/RoLnONiNF3o+ol6tpEmZBnVB2ZiWdzoLCH7h4YJ7EmjU8FI+FQ9cJHatF8xsmA+aoiiu7tbPfEqEXbjWuz3afmA+K3DEs67n0Zkujj+9nDJFZN4/wIHxh1RHTKg0fGZSiGDXb9vhM+CvTfC+qJYpiT+Dl1nxs+32c1x2iZcvlrJneZVloI89w2JvgOb98ck223E69RwJd8MtDSyFRS5usuuDdpxyT7lPTn/+almhRiuzUXfL6VGrsv7LNTkfRjQkBPZateHA9JLHgHJSsIjkWNVJO+2bFlRNcXLWkVxmuRwk2j6LleHdzDx7vfw0RZeodkD7+QXCpkTfp9/9ij2ESa6MCodCAn2i28IhyatzgP/VcX+joqig4uO054TZP/ZezbMALE8Vp7P63OZQacU40VmeW+Jav3zlD3VJ9WlO8JQYlKNmvYqrQSYvaVvBaX3+ynLAU/KlQu3qn99XQLO0oh99EXO7rXgNcGVaV4vUaR9w7kzuwRLiZESfNUxh7UW2fFgy3/Qcv5iCS6Kc6NwS7pH8PSJ9MGzDnLUfUGkJ/WAArRzUCswwqncEzJRS4UTG3qpyuvUIJELq+QYYBohunAmDzvjXE7Qz2BBpWwvSKEvlpjJNl01VkdMFDZwT7/42KbaXjkGp3JhQlWTRDhmTy7pDvGOuNwGT2c9tFXzxvraSUtFluprAAXOIgIEnSFU4SW+oVmUwrwWEriR63JOU2Cr5JWoYvIfaOw1eIykpruDuNH2Y8C+WhjzXk5VgQbTlEyRQEpiLiZ7PD6zm0aB7FOiYamTI4xtQspoDFtobVysz7ONXxlICzclSmuo7G6LghVHnpVQzRfWGHkqNRsQCNakPfo/2ARiyu7JsvfWGcUmuFPXfrViMcMUKaPYxbLkPOG/qqPsXcJPCdJMDo2JhwBJof2tsVZrTz5AseTN164o42ns4qT7vesVLEnQVH7pLGcXs6j7bzS58qIfN6CXd1d1SVv2UfGg42JL0zrnlVEH1W93VL3LiENNptRgraLIbdNGH8K+l09sMUMZOpaiERkDM X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:37.3383 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14078cfc-e4e0-4bd2-f8ad-08dcb71d248a 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: CH2PEPF00000099.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131141_225570_3E417526 X-CRM114-Status: GOOD ( 16.36 ) 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 IOMMU_TEST_OP_MD_CHECK_IOTLB verifying a mock_domain's iotlb, IOMMU_TEST_OP_DEV_CHECK_CACHE will be used to verify a mock_dev's cache. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 5 ++++ drivers/iommu/iommufd/selftest.c | 24 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 7 +++++- tools/testing/selftests/iommu/iommufd_utils.h | 24 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index da824b58927f..8c21c37a41cb 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_MD_CHECK_SW_MSI, + IOMMU_TEST_OP_DEV_CHECK_CACHE, }; enum { @@ -144,6 +145,10 @@ struct iommu_test_cmd { struct { __u32 stdev_id; } check_sw_msi; + struct { + __u32 id; + __u32 cache; + } check_dev_cache; }; __u32 last; }; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 4858c74c67be..a79584fe8331 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1103,6 +1103,26 @@ static int iommufd_test_md_check_sw_msi(struct iommufd_ucmd *ucmd, return rc; } +static int iommufd_test_dev_check_cache(struct iommufd_ucmd *ucmd, + u32 idev_id, unsigned int cache_id, + u32 cache) +{ + struct iommufd_device *idev; + struct mock_dev *mdev; + int rc = 0; + + idev = iommufd_get_device(ucmd, idev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = container_of(idev->dev, struct mock_dev, dev); + + if (cache_id > MOCK_DEV_CACHE_ID_MAX || + mdev->cache[cache_id] != cache) + rc = -EINVAL; + iommufd_put_object(ucmd->ictx, &idev->obj); + return rc; +} + struct selftest_access { struct iommufd_access *access; struct file *file; @@ -1616,6 +1636,10 @@ int iommufd_test(struct iommufd_ucmd *ucmd) 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_DEV_CHECK_CACHE: + return iommufd_test_dev_check_cache(ucmd, cmd->id, + cmd->check_dev_cache.id, + cmd->check_dev_cache.cache); 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.c b/tools/testing/selftests/iommu/iommufd.c index 2c11525ae754..ce2e8c9ede9e 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -220,6 +220,8 @@ FIXTURE_SETUP(iommufd_ioas) for (i = 0; i != variant->mock_domains; i++) { test_cmd_mock_domain(self->ioas_id, &self->stdev_id, &self->hwpt_id, &self->device_id); + test_cmd_dev_check_cache_all(self->device_id, + IOMMU_TEST_DEV_CACHE_DEFAULT); self->base_iova = MOCK_APERTURE_START; } } @@ -1450,9 +1452,12 @@ FIXTURE_SETUP(iommufd_mock_domain) ASSERT_GE(ARRAY_SIZE(self->hwpt_ids), variant->mock_domains); - for (i = 0; i != variant->mock_domains; i++) + for (i = 0; i != variant->mock_domains; i++) { test_cmd_mock_domain(self->ioas_id, &self->stdev_ids[i], &self->hwpt_ids[i], &self->idev_ids[i]); + test_cmd_dev_check_cache_all(self->idev_ids[0], + IOMMU_TEST_DEV_CACHE_DEFAULT); + } self->hwpt_id = self->hwpt_ids[0]; self->mmap_flags = MAP_SHARED | MAP_ANONYMOUS; diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 1b494752a87f..a2b9a6bbcfcc 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -243,6 +243,30 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, __u32 ft_i test_cmd_hwpt_check_iotlb(hwpt_id, i, expected); \ }) +#define test_cmd_dev_check_cache(device_id, cache_id, expected) \ + ({ \ + struct iommu_test_cmd test_cmd = { \ + .size = sizeof(test_cmd), \ + .op = IOMMU_TEST_OP_DEV_CHECK_CACHE, \ + .id = device_id, \ + .check_dev_cache = { \ + .id = cache_id, \ + .cache = expected, \ + }, \ + }; \ + ASSERT_EQ(0, \ + ioctl(self->fd, \ + _IOMMU_TEST_CMD(IOMMU_TEST_OP_DEV_CHECK_CACHE),\ + &test_cmd)); \ + }) + +#define test_cmd_dev_check_cache_all(device_id, expected) \ + ({ \ + int c; \ + for (c = 0; c < MOCK_DEV_CACHE_NUM; c++) \ + test_cmd_dev_check_cache(device_id, c, expected); \ + }) + static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs, uint32_t data_type, uint32_t lreq, uint32_t *nreqs) From patchwork Wed Aug 7 20:10:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756713 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 6CD6AC3DA7F for ; Wed, 7 Aug 2024 20:17:59 +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=idQMeIUexF32BsXmRN6jzWro30nXOs8dLCnokv5Ijkw=; b=M/GPu3unnPp6gNkXS2fefXiNWU us3s1MjdjnV4y8aJbnSJdckLxknjcbtsU84zacbe2GKLUptj89R+j2aYn/LerKoWzZ1QtXsKM7YKS fPdBu+nh2J+LhJ7giyB5deAsQY1ymi3FvK2eH/r5+GWrcjrvB1QNGtuSX6c2IpkYrknIzOHAHXcAR B+KoUSVUOEyzAE0VLZ8NSN9WNYtFcGZe4aGa2r5Y+dzKfSAuq8GgIhXz4x1u0ZcqFwjFK2XByYb99 /4sa0IKWsMs5DPX2AYStlUG3bxZAjCGkMQNB1SNawOQOnADPsD1XZRbTUA7V2K7B+PGnXFYQgTBN4 YW6WTqnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn6S-00000006BFB-2TpC; Wed, 07 Aug 2024 20:17:48 +0000 Received: from mail-dm6nam10on20624.outbound.protection.outlook.com ([2a01:111:f400:7e88::624] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0a-000000069Hf-1iy7 for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kChEWfB9nSJP9UoYC7ERGCZ4nJ34ln7+0FCcEw1s5d3kGgBt22NcUIrKcAULFeeYBhuHZ6q/dWN4ImtggKdorbvdYf1CGv1JXdosfnmhAQtCdrwsYYrsIvYcGxL161isR1A27strHhtAoHu5GbbY8Mm2goJr+2I5isJbn5m9EtocYFafhijE3Qr5yBRAr4ea8HHGf6TvcgOlwh7hNgHxIMvB+j3etOV01vUpZv6juJnpFjFcbjzS7rsgp/JbuFlRyd4hrUoIy8sDQLyBc87w/mgBDRQLETV0AP3OZJ6kNvUrfzQumC5CjEIJiZOMj/HNVj7Llkllwkkjkmgi+DrEPQ== 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=idQMeIUexF32BsXmRN6jzWro30nXOs8dLCnokv5Ijkw=; b=VJkAuBMqoLpk/ycWkjdHYNOCnpPFaSux6FuuJSOdihq1QTxblSUgyIsZXLBGidEsbKvh1/Nouq9iPhIPufVnUiQsqH0yixCRzHo+7bECNF22bb2sl3T+0NlUJTKOMBvPwAh74VgYnR1SV8a587agV8KphhA4cCmDU1FbditIzt5Leej5g/1so+rudfLvRfZQDiEuBJXKn7XY1FN+0IN6CEGJ2HsvStoYCDfBBXk7N8LGcH7AMcD9DHw03KauC+qz4tk3/LZaqyFEZ9yl4v8NpuCObZFR8mHqDRgDDsgvdWpQ/7wrjRiAH8+k6ej1/vlAmHOtM6SGuwk5RSICBf8uDw== 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=idQMeIUexF32BsXmRN6jzWro30nXOs8dLCnokv5Ijkw=; b=nU4mHu1gDkoLBDxbYhB8zQEmTMLzkHuBP2pOXiDl9Jl7S7MAUhjWSobZPyNcung+K/7IhrCUK76qtyO3V0c6XafwSTGku9853M+gEzULI/sXtCT3mlfkrYhWaQ+6XTlStCq/tEKOHzpiqKpqExxmxMRshweLrtGN8OJtHc6y2mGHAZhW2/FAZmXWNz6mj8Gqmpdn3Zd11Z9dYwq9fZ0/v0WbkMMwMGFpJ3dyCbPFD2oBGJhaO3PXfDWTmR7mBiLEWHnRzWRoPJS0EAZ7kdOCi5/agh7BpNed6ztYgApnoa2hpd4FVCuhk6jeEHGyRrSZCh6kBJONLL++EjkhgEtL1g== Received: from CH5P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::27) by BL3PR12MB6426.namprd12.prod.outlook.com (2603:10b6:208:3b5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.12; Wed, 7 Aug 2024 20:11:39 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::76) by CH5P223CA0001.outlook.office365.com (2603:10b6:610:1f3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:39 +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 CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:39 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:22 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:22 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:21 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 12/16] iommufd/selftest: Add coverage for IOMMU_VIOMMU_INVALIDATE ioctl Date: Wed, 7 Aug 2024 13:10:53 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|BL3PR12MB6426:EE_ X-MS-Office365-Filtering-Correlation-Id: f7f5e987-542c-4198-3b7f-08dcb71d25aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: AK5cpAJRaydcBQzhvYTRd1J6TK8LZKuzdihk1WlwP1qKgD0Cqvq0JI6x2yIHlHQLncSX8joqUbOviEoIGXNyUgGRatGkRRXEdXzID1dxNv4hblsBDBXvIkfYlEYQ8NKmk2JpmBLw40nadzuckM0eBOGsuThTfBQwW9amk+iiRSG3cKxBJMrcl4xMgqrufQMT7b3Pk3iqWNcXQ7AUvInD7OupM8mYYv89WX0hPRSxDtaAsQeSFFJ52MM5QxPv49rlJNKoulSDR14GAcWi+sI+FewMDopXq8K5ojtk2+ZzEg4ZkmQVQ0jzDrAtk9/iej+s1bqf79AhT/rMjC8vtlSO60HVJs5NrKgS6Bd8A9ZekwrzZth4tffW3UAKUbYVmDCogdL7V0tn9fMlHltJPNLPXsTGfCiRJV6ni74CFFnnzTpJX5YdJSN9OXb6pKYKdKyj/WZ3PSbT8wFplmd/zuiDQjrQ/w1v7NxXKAuc6FwI3/Nut/VbDiS5t14eAf/TdZ22cW0+sLM6DQusdpSMiH/r23++pKG7uq5GqRcZ+B+vuas3ipKCurWTPM3egvQlgqNn/4vwSfZV1AINj6dDktJfu/qCzT6X6/kj4T2EWrYZcZ0EVWCKl11pwLb2XRLYS3w+evp4bd21HAQo0Ae5aUx7kF0UV/VVkAzoH2xbYUjfmWRVe/EWQcNioZTEqJhRm1v/Orw6RVJzirulTjPX3bg1ovuMX0y/O0MXPoghSsm8DZOnn2lCH5PqKw/W4K8Oj7nmgs8KST0MooLleHyY7hyYfEPqSGbZUJ3HKeRFnEHFvHy6TuxaiuDzgig8T0Uv/GmKuE4tfvQO+aOtYwnfchIgXbgpC0Gzt91lMkpm0fNFbrQKGMiVQTY3r9UkJeyWaEyneWxZro3RZgH8P+gaeM1DfnxmkrEp8GckQzJ21KA+LVqgsb1hN7ipKOdvhoG7CPP6Zrka6eJ3l412mTjvoQRdrlzIGDPJ9X5WO9dBDcT2zVFIoSvu/VbAfey20MCM+bCQcF5NBd6D7uNwIoWaxrNz+IgySN0KDbEo6rGffAeZvPPWWc3gqHgGdlFlVvyzW2nQ2TYzI1kq1M1bpKpm3cRw35caUa00tTRmfxViL9hwJ+nJ1t4vBRQuriJ27PYIRtRAklslF/IOj1M5K+wxrlwNh7iDdhVtAK912ibBknd7xTGDdS2gdDyqHlk8lIiUJPJYhWgEArJ6b+tpDFIhh5GAwYkaEMRVH06Ga5rxBFmWuuNHusbeOIZc+3VQcD8bCIunl3+4mE1na0aI9ARCh9Pe8NphYDeqFx1kuIxaNT0IZ6dvRyvyI/Nk5em72cfVq/GuNDU2DCepjiN0+EcX76DKtKWAQw8Mr6aRjPiA0XjoQcm6M7QnV8dynJgDKTgyDcgLLf15Q4Abuorn+ekyyX7piaIPoBSTkXYSVN5DUzz/FL9leJAjLVFDgh8jbbKc3xIJ X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:39.2053 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7f5e987-542c-4198-3b7f-08dcb71d25aa 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: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6426 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131144_645920_237D5932 X-CRM114-Status: GOOD ( 16.35 ) 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 Add a viommu_cache test function to cover the new IOMMU_VIOMMU_INVALIDATE ioctl with similar postive and negative cases to the existing iotlb ones. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 190 ++++++++++++++++++ tools/testing/selftests/iommu/iommufd_utils.h | 32 +++ 2 files changed, 222 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index ce2e8c9ede9e..b8f20eeddd5b 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -622,6 +622,196 @@ TEST_F(iommufd_ioas, viommu_default) } } +TEST_F(iommufd_ioas, viommu_dev_cache) +{ + struct iommu_viommu_invalidate_selftest inv_reqs[2] = {}; + struct iommu_hwpt_selftest data = { + .iotlb = IOMMU_TEST_IOTLB_DEFAULT, + }; + uint32_t nested_hwpt_id = 0, hwpt_id = 0; + uint32_t dev_id = self->device_id; + uint32_t viommu_id = 0; + uint32_t num_inv; + + if (dev_id) { + test_cmd_hwpt_alloc(dev_id, self->ioas_id, + IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id); + test_cmd_viommu_alloc(dev_id, hwpt_id, + IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id); + test_cmd_hwpt_alloc_nested(self->device_id, viommu_id, 0, + &nested_hwpt_id, + IOMMU_HWPT_DATA_SELFTEST, &data, + sizeof(data)); + test_cmd_mock_domain_replace(self->stdev_id, nested_hwpt_id); + test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x99); + + test_cmd_dev_check_cache_all(dev_id, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Check data_type by passing zero-length array */ + num_inv = 0; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: Invalid data_type */ + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: structure size sanity */ + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs) + 1, &num_inv); + assert(!num_inv); + + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + 1, &num_inv); + assert(!num_inv); + + /* Negative test: invalid flag is passed */ + num_inv = 1; + inv_reqs[0].flags = 0xffffffff; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid data_uptr when array is not empty */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EINVAL, viommu_id, NULL, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid entry_len when array is not empty */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + 0, &num_inv); + assert(!num_inv); + + /* Negative test: invalid cache_id */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = MOCK_DEV_CACHE_ID_MAX + 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid vdev_id */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x9; + inv_reqs[0].cache_id = 0; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* + * Invalidate the 1st cache entry but fail the 2nd request + * due to invalid flags configuration in the 2nd request. + */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 0; + inv_reqs[1].flags = 0xffffffff; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = 1; + test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* + * Invalidate the 1st cache entry but fail the 2nd request + * due to invalid cache_id configuration in the 2nd request. + */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 0; + inv_reqs[1].flags = 0; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = MOCK_DEV_CACHE_ID_MAX + 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Invalidate the 2nd cache entry and verify */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 1; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, 0); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Invalidate the 3rd and 4th cache entries and verify */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 2; + inv_reqs[1].flags = 0; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = 3; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 2); + test_cmd_dev_check_cache_all(dev_id, 0); + + /* Invalidate all cache entries for nested_dev_id[1] and verify */ + num_inv = 1; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].flags = IOMMU_TEST_INVALIDATE_FLAG_ALL; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache_all(dev_id, 0); + + test_cmd_mock_domain_replace(self->stdev_id, hwpt_id); + test_ioctl_destroy(nested_hwpt_id); + test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); + test_ioctl_destroy(viommu_id); + test_ioctl_destroy(hwpt_id); + } +} + TEST_F(iommufd_ioas, hwpt_attach) { /* Create a device attached directly to a hwpt */ diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index a2b9a6bbcfcc..69c51151238a 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -298,6 +298,38 @@ static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs, data_type, lreq, nreqs)); \ }) +static int _test_cmd_viommu_invalidate(int fd, __u32 viommu_id, void *reqs, + uint32_t data_type, uint32_t lreq, + uint32_t *nreqs) +{ + struct iommu_viommu_invalidate cmd = { + .size = sizeof(cmd), + .viommu_id = viommu_id, + .data_type = data_type, + .data_uptr = (uint64_t)reqs, + .entry_len = lreq, + .entry_num = *nreqs, + }; + int rc = ioctl(fd, IOMMU_VIOMMU_INVALIDATE, &cmd); + *nreqs = cmd.entry_num; + return rc; +} + +#define test_cmd_viommu_invalidate(viommu, reqs, lreq, nreqs) \ + ({ \ + ASSERT_EQ(0, \ + _test_cmd_viommu_invalidate(self->fd, viommu, reqs, \ + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, \ + lreq, nreqs)); \ + }) +#define test_err_viommu_invalidate(_errno, viommu_id, reqs, data_type, lreq, \ + nreqs) \ + ({ \ + EXPECT_ERRNO(_errno, _test_cmd_viommu_invalidate( \ + self->fd, viommu_id, reqs, \ + data_type, lreq, nreqs)); \ + }) + static int _test_cmd_access_replace_ioas(int fd, __u32 access_id, unsigned int ioas_id) { From patchwork Wed Aug 7 20:10:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756714 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 10104C52D6F for ; Wed, 7 Aug 2024 20:18:33 +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=xEagwWkHigxjr0995SwXhtPFsE/vSIE4k1B48AEqbRg=; b=SXgdGmkRtaU2Kpxti4zoPDy35m hBej6AxPzQT2wT20SaaWmhnM8TQlfOGenU7M+UC8ZDoi3lujdQ2Tz8QlMsyzJUXsHSrjjtNAJB75j twDGNS35jyh3B8r7t5bf+RSgc64V7RIcPlepZoKkhLyszfvbXcUm/dH6Nz0ssAYJf4hNQLT5yPsak IU+Y4N3aY92ijqT04EQaAXfjIZ2aVXaOwXqNJqeGIEvMdLlL0t3N8C3ZMCBNzAmxDNiCifMAa8UDF LtflfMVlbC6LqKnLRRjC9ray4nVaWhcCPl+j7nxl/1okOk3wbOnF5tklwXbpGDzMwQ8cwT6sCh3h9 N0i6ah9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn6z-00000006BO5-1RUv; Wed, 07 Aug 2024 20:18:21 +0000 Received: from mail-mw2nam12on20603.outbound.protection.outlook.com ([2a01:111:f403:200a::603] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0e-000000069K1-08Mw for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iSCX8JIjDmtQ6FUq0W7cm/gfYkY9XgSoiQfDwGhtpr5XJDAZMPj2TxFqiDJCXe+iSG5ltKw+961pXmEXveC8tpnIcioDSc8nUblGfweXCI5In46LMDi3W9c5nueMNeOnX19nJAHyj8UP2r3LBDgqQRzOjFZqVkqxtUMUME+1fq98k8vRgPHJbYQE6cwt++Ad4MFlR4cYowQNhcPCWcDkpO1DrKHQpo8DZJe6u3no3dtXzWjCFqs4RL9GGWVCt95E5w16MOhIoYQG09asztA/8UibdlTxGAtGR5SwzHfGxqdBf6llcT16xLYjKL+O3sdJK0XxvPtvrL9v9QS7z1t6Hw== 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=xEagwWkHigxjr0995SwXhtPFsE/vSIE4k1B48AEqbRg=; b=gxW3WrNVPDM2+o8Lda/Ws2hI0mp+qx+i+znFR412kuqKSJC+ZD7ERWRHumREhkFxZNsJ769oNjvxhSJ/0CHWHyuyrv5g1eg+JUT3jLiLDrAu4QXlREAu0mOck8v4IZdXmnuhV3x8YyO8r4QNw22o5OBlrX2qQWgu5+F0Awa1x9eaYJNNE3He5QaXY5CGBt1ZmVfPzgnCcy9moIh3MfkUh+Mtu12GivcCYU8dY6AjfYBnzqQrHohnrFBy12avB36OAkxDpoSI0awV0pWjn57VbMG5FygAq/jRMHRkdo26FPy3bGlVijozEj/G5CzjKCczfp+KujvZO54tNCX1wX2GXA== 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=xEagwWkHigxjr0995SwXhtPFsE/vSIE4k1B48AEqbRg=; b=It+PJfaofea+Jd1eWkQO2VLzKduMUidJdhEBzXja0fm4xX2/iTzlYVd4S106wwtc9kyWlQh3kybXK0JPVxWQPc/Yl1hwx7K4xGVxiPSjlKPMrleK0/4HMnFlm+E1Kd5bY4JNWKYi8CBsAqNtCPV+czZJFKc3piM+V4Fzo0WNIWqFd/johxfIEot3zAw0WiieuhjP7Y45Esu6iq/ytY8hDyMZ8usBdF5qbJkXHLo/V2+0mzmEUq6o7yi4nSpaN3LJm/NijfcrL5VcHBP3eP/Y94DqQj4bggUU3aO8zZPymrJPXNfxmA/1P/QBm7K3NzGP86bVNBnytVrO10SdE+quYg== Received: from CH5P223CA0018.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::25) by DM4PR12MB7742.namprd12.prod.outlook.com (2603:10b6:8:102::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Wed, 7 Aug 2024 20:11:41 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::96) by CH5P223CA0018.outlook.office365.com (2603:10b6:610:1f3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:24 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:23 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:22 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 13/16] iommufd/viommu: Add iommufd_viommu_to_parent_domain helper Date: Wed, 7 Aug 2024 13:10:54 -0700 Message-ID: <3d61830fe978e1b5024ce1f36442dcd5ecc03362.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|DM4PR12MB7742:EE_ X-MS-Office365-Filtering-Correlation-Id: 0597e5f2-0e1f-4cbb-cc48-08dcb71d26be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: iYnKRwJ4wRbXPnbqvQoytg5rn6yeD5uzNZxj8qOqJDRJy9NCda08dy892jXKPTSeZ2b860ZhFCI85WdJ3Xu3ckkLJWofwsVAJop4eQVwp4COaKx8uTWnaYh0SdTLaYl+B7As9eQa7Sp+schlrM0tBBpFy+6F4rRLu7p3GKvRuRdplMsCCD7VOvPuln2JxsVcOv4kWAA1+1xLcHmF/7dtYfTHt1Tw7LNKbwnRYpQPy4rPUdiBEAgNB5rPGWpfmFHQu5rsoEJM9ypFRaZu/LX4b7p8GaJQnYmlZaf9+UwD/jlKERyJrwyRN/JaNTtcHXJ2di6Hr3pgMIayqUac2t2EAGvhtV0aU/YM/LSNJGTUppXSN7qe887/Nxa2OqaiplTDJNE23LN+V863702kZ/zhbRFHbS3Ox+H80Vsqkorm4iHsxFwYdrwp2l2/AIn0rzVxnovxexvN2F/7OeVKhzEIz1hZkeJHEfS5VN8Ddv7QPac1qZ4m1fk2wM0yZdPEQwgegC6MZ9qp7xFnZR3bnlLSKAtsXbZ0aSzhqMRBf/DH9+gunZCi+9ADQQGkNYd47WdyzJJravuAEayFmAAmFM7yrOnzKGxsAo+Br9JhQ2sJuGZc3RrTg27V1cFr+kTpnKcF1P/vYPK1YT0F4/h8oZRyHjgBuI2neq3bV/N+alM+4W3LcSFnT/9wDWiJVWY2z08j/uqLMNpIqvZi24MZPZ9bug44R5hwVooLN7YKkzysxl+U4zpbHBMh5QaglyUl/QP4D/qbucPA9MOdLN8Ji1mzxDSXwHg6PCiihZBDW9XSzrlwna0ZrcJpDcooF49uhq8pdzTGRZggEEabO7VZRRW6DCZyKGeXvIjSu34/3n2hRPNpmv/ZD3l0JoZbPX9CKQBWOt5q6GDM0B4s6um9d1R34v1yyU5WslqN55vRvB7w7GxoOyzUZrlDfy6JlOBIXs4XlyOsTXGyqjKqUYHY3D2rtUnb9oSi5oejARjbgkfVAwWGmZx9TnAZv0SgmuifjdtgFrSYlOzQiNgg0teWWwrSjepFbYKFkXqIzOBYplNUsVWw+VyWO86ZdjnLmfQrUMkBPY8zMe1OWg/JhQ1RVtehwqkVPumKlT6lOYkaXdOLk5AOTfT9IKkULvC73mx5xLoE1Q8jTmlu2/xn8xSp6mNf1agrYTekHVKBUCOFCfhmqGPAl/mAAfgv817dYDXIPafMduHRFutRhbLVJvh1tvod8VSg3mom35zSukVCXVvnpyHRumjNqYr9tiMMY20HBnZ9wmXVkEaAetPFzYjTfD2ypnfa/t8ABlKE5Fnzv2dMpuuRiosw5L0QMJMLnJyJ08N9eDtbXJLJqHyspQfIwPwc0ZoXRlYHCB+KvVqs+p67kNyvFS7za3bvOoCiGSCzCdHPuzUhu7NGMi5QnhaKHfZxl+lPT32gZXT05gzg7INOhWz7TfTJkoK7ViEnaLrPv80C X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:41.0178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0597e5f2-0e1f-4cbb-cc48-08dcb71d26be 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: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7742 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131148_121146_3DE9B237 X-CRM114-Status: GOOD ( 10.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allow an IOMMU driver to convert a core-managed viommu to a nested parent domain for the info that the domain holds. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/viommu.c | 8 ++++++++ include/linux/iommufd.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index 2304f199b033..39a7c04c4132 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -239,3 +239,11 @@ int iommufd_viommu_invalidate(struct iommufd_ucmd *ucmd) return -EFAULT; return rc; } + +struct iommu_domain * +iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu) +{ + if (!viommu || !viommu->hwpt) + return NULL; + return viommu->hwpt->common.domain; +} diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index e0d7a53acbd5..c0ce12cb1374 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -91,6 +91,8 @@ int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx); int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx); struct device * iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id); +struct iommu_domain * +iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu); #else /* !CONFIG_IOMMUFD */ static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file) { @@ -137,5 +139,11 @@ iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id) { return NULL; } + +static inline struct iommu_domain * +iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu) +{ + return NULL; +} #endif /* CONFIG_IOMMUFD */ #endif From patchwork Wed Aug 7 20:10:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756718 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 96A44C3DA7F for ; Wed, 7 Aug 2024 20:20:07 +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=TZrvfVns3n+wE19BdpBxEW0UC6D8M1vjafDg+cBNr3Y=; b=10mC4u92Tjk7jqaDlqr/a7UtjZ euR7jLyL62tXqHltBYDDZ+h8rWNAqhZwGfESGNcvmseK0pBHEqaEcsjxtUtQCHs2+VtW118e0N2S4 ygMkecA9hGlXGLjul5yc4i/VApyn53aLLXBSwDpSmti8jomAxWa3m7DnRLzMsqlAq1DNDYuoli+/f DE1daJbu6/G9J9KM3ezvL+RgIKfjg0qcl8qNEj2puZXMj51PqqaY0CyJv6gWtBZClS23ftV+9Z6cB G4OzGbgRaZU8ckJSMwu3q2MkDNyI5PCCgnY9sSNmJ1UxDxDBQ7vdPWj57mwzHGtJBGqM+w3QyBw5K 73Sm1Ecg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn8Y-00000006BiP-0V81; Wed, 07 Aug 2024 20:19:58 +0000 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0j-000000069NS-2y7a for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=o+8aj+e570Ux3syfMi5glUypvm7+D+V0tflm3kKZ2lzDZHV3gF/w7QDsoWeQE2kGqC9amzZv30b4zUeWd9lfsScwAvOg2UIBRHVZkpyM46bvn2KHCirJ2HTMm0WZwZPOiipyuv1KNGzta2/Z0e3DyKRNveYS5lFUpdRKXtIKnWCejJmBumMG/WG9Mqc3s+g9k9nVxCoZ84kqcOOWlBk1q9IkiOG/dl1XOZyRoeKGbNj7RoNHYedTUcCyG77WyQTGou+tLXQptJ+D6bowoOZ954yj13rDwp8i/9JeyY7K7ZHELr1khnmBJ7dKA6yfIApOiIPI4qLNCg5g6ZquCQFxJQ== 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=TZrvfVns3n+wE19BdpBxEW0UC6D8M1vjafDg+cBNr3Y=; b=t0y/R9TmNJzWyyMiS4WcROmC/XGjPyXPSIyoHbHks+Txw2V+WAhAP/qjceKlpmWgwQ9zINMn9PZPfZXf4+O5Etd48oVSHrb/TF4Wjs6ztzNasM0genL9y1Y8D5DqeP+0H6EaMk/j7bLxUEy1q/w+3UNc7oACG6+nTbhJ7gHtfihXFe7fWb8Rtj8oIJsiDY+5BFHnN0Lks/dTOGffpShyLZe+PqK5Oezhg1jRACIw55qjFv+Ijy+7mh+YToRd1PsyP6ihq9Uzi9s6CJj/jCzZ9y7Zu2+37Qg3sTMqoRg4cRj1vjbP9VK+tfO3fI7jR1HP+lbE87P3fB8iDYG9e+DocA== 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=TZrvfVns3n+wE19BdpBxEW0UC6D8M1vjafDg+cBNr3Y=; b=BQwEgn6K4lAosxLyX0nMiyUoV0KbyjKEHtaSQtHFr1u+An9hXgyX7ZIyI/Nlsb5waN3AJvsYrJ6qCLFZ8k6rLFLPXp5BC2e3O7jUddVyMqQaApD+gobZTMrXbuFdGIPsc3KjqagoaRBQR/NPfdH8ttuLUvf00okVbm4f3a/uXSbx4KEvt/CCf4G67MFmtkMnVPGmbXrBADm4HgEBC5aeHkOiOTHQ+paTwcvFmSITKjHdSGp3F7dyI9AggakOYZF4AephPkcvdxBkAr5H71coWKwB+zywpDVZfjukBfpn1YiUT3ih6MXHtvjNVUmgbTw3sCvBadw38ARRckePQshjLA== Received: from CH5P223CA0013.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::8) by SJ0PR12MB7036.namprd12.prod.outlook.com (2603:10b6:a03:483::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Wed, 7 Aug 2024 20:11:42 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::98) by CH5P223CA0013.outlook.office365.com (2603:10b6:610:1f3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:25 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:25 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:24 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 14/16] iommu/arm-smmu-v3: Extract an __arm_smmu_cache_invalidate_user helper Date: Wed, 7 Aug 2024 13:10:55 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|SJ0PR12MB7036:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b1aad55-d505-4642-ef22-08dcb71d2722 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: /cQrJXafNOFvPVC0IrT1IE5C9HsVjjDZY8SURwcHI4ANp+b8EFZCEX4ft/mG7KJ1SAhA92rpVwdgzemKwAXh8b2drqGh8KZMgRtskd8oAut9lV3biW1ViIEb+ddmyAIyrkisnzR0GM+Mcz4qB1rTDVTh1yosSLheCzqAzqfoap+jHwYETnG6maQb+KUM+H1hMD+bAu/wETpN0Lzih58p3G6H9cK8LRZGR55B98xjTArO0ArcP9hCMD4wAVCOneVD4wC+zZwIWvmu7x+7rpL5XDrBLBFh9cAp6AH/1kb75INfnQvUBdanNcntdj1xUJgfbrqvWAr14DcEdb54SdwEQEVgehOq/xifOxp2onwenbFYslu+8NETICgui3UPWbRO2KSr3PE7tAdmcdxSBv6vEYuzSMJV5h1IHPaqx9znrgICi62KqbPDVNLWEywsxA7HxVC1nu0Nq9RBZT18HknxMadMWmXFMmE8f7I0p5OtAQIC1OuTBbEDxhotpLmLfqGOlKDO7OE6l0YwS56myqrXGxjtCLXutVxSRXaVkbllL0ey/y2e0RUI+9P4iuihKQgn3c7aKK53df21gna+EP/DFT4uHNUSPBsdvSfvKTGBv82AwpSDV0SBK0RlOUmbDlXwsQ1snFxqarFBeRV/IWdfojfpXWcxdcFuVhaLD0Kpz66Jq7mCEnVF2Rh2AyfY4PhzGZgV5Z9ues87nzqopxXn+FB2pSJgsEImQ3oSFXwKjn++xGG6K9r7pl4LXj/1Vz+oAdXfKecdYndJ9fVAmKL69e6iYIfI1Dc5dBb5dxv8zBf2m5oMVhrR0qrDZ8anLavaWsyx2n9AhoNsjrIsIbJYQkFfTxnRXsan+Xoa16E7nSqxbH1LEBQRfZru2luiuJ7GgFlEInCBFePShW2RDOF9s9ridgjWaW+00rmoqniIit8VRapXnigTQK0DRDPUZ6Q9RB35CCkKvCxKffwwWvHQChsUiT29i1ky3pjcp85mjA0q5FNwWK+BdYL0iqRqaZrZB91Zd2s9XtiB2q2pPg64IXqfjgGg39Z1/SmUwXPWNj0nVzs+kd/JQltNsXUerIh0TNCnUGXfrQyLlp3KmDKw7zIMVdUb2xYYnD062wA6IM3dOMZ1kIBF0i8EYepoNqIFvENMMX3/kRgCPlMU9Qwq6caYc+LMMrS9skGlcfi4XB3AggsXh7tYBJE6F4RhAs36Xx2Kr41TOpRDxrlwMMVJD8jYlcSY1wZKeKrsvoN8hBbxvneOKYZrudaSZYTi7TZZx+kyg4RhCsCfUE5KYYm6CzPMeEz2qjFeWyaorG7L6AD9sHu0H2fnkVWmbtthyWf6hTh0Q+S/DDqC1Wbd1zi9KtaDkvMohZeEzQ6qSUdqYjREg/DcB+YO/jhOlL/8EgL+WcbDxPnehyyD7ZqS7gtLh+fmi+X/EvnEWyWCJTKv496eSW71A3sHug1HUMTlKumQ X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:41.6897 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b1aad55-d505-4642-ef22-08dcb71d2722 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: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7036 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131153_782231_F52DD0E1 X-CRM114-Status: GOOD ( 12.67 ) 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 Extract a helper accepting an s2_parent input directly so the following patch can take advantage of it for viommu's cache invalidate callback, which doesn't have a nested domain but a viommu object linked to an S2 parent domain. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 558cf3bb24e0..ec76377d505c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3227,10 +3227,10 @@ static void arm_smmu_domain_nested_free(struct iommu_domain *domain) * Enforce the VMID on the command. */ static int -arm_smmu_convert_user_cmd(struct arm_smmu_nested_domain *nested_domain, +arm_smmu_convert_user_cmd(struct arm_smmu_domain *s2_parent, struct iommu_hwpt_arm_smmuv3_invalidate *cmd) { - u16 vmid = nested_domain->s2_parent->s2_cfg.vmid; + u16 vmid = s2_parent->s2_cfg.vmid; cmd->cmd[0] = le64_to_cpu(cmd->cmd[0]); cmd->cmd[1] = le64_to_cpu(cmd->cmd[1]); @@ -3255,12 +3255,10 @@ arm_smmu_convert_user_cmd(struct arm_smmu_nested_domain *nested_domain, return 0; } -static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, - struct iommu_user_data_array *array) +static int __arm_smmu_cache_invalidate_user(struct arm_smmu_domain *s2_parent, + struct iommu_user_data_array *array) { - struct arm_smmu_nested_domain *nested_domain = - container_of(domain, struct arm_smmu_nested_domain, domain); - struct arm_smmu_device *smmu = nested_domain->s2_parent->smmu; + struct arm_smmu_device *smmu = s2_parent->smmu; struct iommu_hwpt_arm_smmuv3_invalidate *last_batch; struct iommu_hwpt_arm_smmuv3_invalidate *cmds; struct iommu_hwpt_arm_smmuv3_invalidate *cur; @@ -3282,7 +3280,7 @@ static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, last_batch = cmds; while (cur != end) { - ret = arm_smmu_convert_user_cmd(nested_domain, cur); + ret = arm_smmu_convert_user_cmd(s2_parent, cur); if (ret) goto out; @@ -3305,6 +3303,16 @@ static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, return ret; } +static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, + struct iommu_user_data_array *array) +{ + struct arm_smmu_nested_domain *nested_domain = + container_of(domain, struct arm_smmu_nested_domain, domain); + + return __arm_smmu_cache_invalidate_user( + nested_domain->s2_parent, array); +} + static struct iommu_domain * arm_smmu_get_msi_mapping_domain(struct iommu_domain *domain) { From patchwork Wed Aug 7 20:10:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756717 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 983EDC3DA7F for ; Wed, 7 Aug 2024 20:19:38 +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=H+ua6Q4EfhYRYs9OsVqGyVK82T6xIpPjP8Sk3Payhy8=; b=YHyNFih+10P6ZaUd+hRTfePbaa KGkkbJZM6dJmCuEhucTuau2/hgZxtDqDeQAREP4bn+GRCTDwKfIGBJ4saWyIEz21NscD7NMCUEpXM jJh3eJNSoBG4HZSV9ZDjKaAzbniAZYckk/hLHEeLRzsV3kmKHz64/YXuaQM/Geu3aq02bZREw5kal MMc7A6kAKgYSNztZEENmyFjx7keU1q4Mt3wkCHEa8ltf1dFHUcUCkiZFFrhQQiHtVq3b5QvojaC5c Ew5AuJOo2KlzCd3pdzQ5AR+4xfFzCts7TFwOp4hh13MepHUOuCAhwjJ+R0CV+jzSfq4jSlP2RwTNd tbtPgM9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn82-00000006Bbo-1RNQ; Wed, 07 Aug 2024 20:19:26 +0000 Received: from mail-mw2nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:200a::600] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0e-000000069LE-47mu for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XdzxAQbLMpYLq7pqbFr6A5RqL6q2MviqjFRj8dUtgx75uOIrEHUbm3CsP8tgAhT6xvRnRBJb4OUK00dyojAK+NLi9RYpoKy6JQfT1DKnbYx1WlnWRmp3o3dKqgOrAqtX9RDciwazGLmKX5+EYJ33mMgeAXxSl/Oww2Lf0EzFNkMMQXDdYtvTZWwgXE+eXLjz26AkR2E5ZFkKAsfmSsiysBPYB9Rps1JFOCpTPv4/QJyAvGFq5sxxfcrNjB7axQGii7B2JEH+F/bQ3G07ioVy8WiJyA3aO+qkLiducgIITTCL/B1SIaVGZh3FD3iEhmFwiP3cz9DePL7z1MxzTMTIKg== 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=H+ua6Q4EfhYRYs9OsVqGyVK82T6xIpPjP8Sk3Payhy8=; b=tRi8oXxqzZ6rr9bOCm+OUpdm6ZdO4np3NOnnmOzSv1e6ymuihBgsTQ9rflzRoatXXdNG8cEJjE4zxgoKJZW0TuMAojkqBJX/QXw4+06JgeGdVveRmJHFDkYmHh9x3zIurkZxFuwSndx3hayOvajZtfuCbuOzC9pGfb2qt5SM6I7FLIvTTYm5AXMmEsi1MMp5PxE3eZy2rxmU2+fpBzjJbHNxWS38oHJ5cckGGVVm9CD5rcHOWBByII9dReHTbeoxb69SnOjWbcDyF7Yg40TV/4vS3EmPR28kTXmdZBZYIS4iFqM+e9+QCgycMbTwn2RBIbOvUtIWpJBGPVM3q+BQlw== 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=H+ua6Q4EfhYRYs9OsVqGyVK82T6xIpPjP8Sk3Payhy8=; b=VMEU5SVRnPOMrWmYGOwX72qT7yYljxxbj/aKvulJHA/+kyiZgx7uPhjlZabyaeBVZEkzsG+UuZOxdK6aoI9JRkeM+A8T4yZ/E0cneMm/69qcSu6yk6SrFyDsz6PXffuggZCShpCxLIeHj2mrQRvmZMV/x0W6fELN9gfiadXpeB6dQx3t3zzLKL52RTtNi2X0VNpxnuuI2aInc2dHaNweB/u9mTf0WNiW0Z6R7HSVGB2x87gsYVnAChppSdHx/7U/qo+vOlVrw2b2YnH6oIjGQVkRxSEV5BXM3OlI2BmVb7meHH6JA51EswsZQ+NsFeGhTYRsk3ILqrNm65JsPdovTw== Received: from CH2PR11CA0030.namprd11.prod.outlook.com (2603:10b6:610:54::40) by MW6PR12MB8899.namprd12.prod.outlook.com (2603:10b6:303:248::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Wed, 7 Aug 2024 20:11:43 +0000 Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:610:54:cafe::ad) by CH2PR11CA0030.outlook.office365.com (2603:10b6:610:54::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.30 via Frontend Transport; Wed, 7 Aug 2024 20:11:42 +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 CH2PEPF00000099.mail.protection.outlook.com (10.167.244.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:42 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:26 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:26 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:25 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 15/16] iommu/arm-smmu-v3: Add viommu cache invalidation support Date: Wed, 7 Aug 2024 13:10:56 -0700 Message-ID: <729dfd0808f85d88fd3ef8bcea0168cc1d2c0d59.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|MW6PR12MB8899:EE_ X-MS-Office365-Filtering-Correlation-Id: c7221624-5538-41c0-485c-08dcb71d27c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: 8Eq4r0vO6XRN8qxzVWpimOCAe7fcxEPEgPke7v+VRLx8AVuDbQmvP6DJgFbTJ4Es42tPKy7JAS5dvhnIqo0eobGa571KKS71Qp/TGvuNr/sZH8eRsA7tghCG+oMVVQauAE7yqDcUZgTMM+Bo6cQtKJiJbywwCHbVPpem5MwZ0YVo2y/1wJPv3LvkXFu3GDlfBVfWYJ+A1UZkrkGh01xkOTSBkUU1FZndWM1lxF8jKvS+DDuhvgbCuQRlDmmsVR1hSalqenCZFb2hlZY4mMlkc0oXOGAyupjUretIIFd5egNYJzja22o496QvYrc8BBFgFwFVlaGZgIvtynCV5y0XjcdCYRh46+LBnC53oGPGrzRMyUGNFN9QGr3OtcbPtZUOdonSudqro/htqBfbgzz7J0J5+S0z+E2dikd0U8A0dhbFK5Yq2OeDw3L0JQq1szhS1Y3T6c/qAaFzAtJPO8gpgyLdsZhQ+OQ3iyntPUBe51/65HXLHSqCr+cPbDlW6qFTP/mKPiJNS1/Wh0++vv3FdtpqpOZQgTWzCSIPOR1utPCV48k7zu8AsSPRSbe7QfN0SH9byeDlI+3C4PFIXR/uLFFqZlEX3WxaVsHPg8GUDFTCSBOqK+fyhAIdMzCptrfch1e0qzGilSxcsFfFgBWaVvJtCRnLuMIhPrG5UGgsOvz7C91S2s30MhrVF8swVVfuVqLd64dkn8K1K5Y8Yzc/Ths0bT61arOpcmObm1xEG4b+EfbtASKGdQsmPsEbZHxE81fzaCXIWkBWtIOEl6EQz8IYOWVbaFgUlPvrBUFyoht2qpvpGDiUOcTsET+tqt9x8REndtKKsSBCjGrD11eaAsWSplnh+RyW8e3cEeSDXZhraf0rAcvKbETKwqqD+49H1tlZkSVjSVtJe0aJAUVV8sao8wZahbAg6wu2yQtDRhznLtSbpY/gLLWSRqY4RyTj3+A8cqw5LwEDlsobHiOL5PreT6vNvAIBeTLVgg0JpYOwSRnqgLRcoaGA7w+p1lKZ3+f/X5HQoPwo9MnonfmuOccG5Fj7Js0NRzZLWTwXyg1aDcMP9LlpWVnDiauMtwmAuDcyjEELsfhlX2zPF5Cx+IpBECnl3sbzbW/eg7be16ozUW+LV75hnwvFs4l+Ck1+c/a1fTWJD6SPK3GJ+bqhAAlwlCtB9Kr5OpXze3sR3B25R2njy68vYtBEQtRabTJ/lGYs1Vi4U5iJ/b4lnwi3qGGvq5WuHvvfVSiB2JG5GNaQLmB4vWwqrFtz9z3JBjjB5nZup1K9O5QzElh2Ez4EtRu0a/Nr6LSx2u7CO/JRvLTjXspQlMuGQYytQ3fdgpSJqCs04YeEt7y4LHOqRdeJoNYh6OShdm8c24gP8xwnmzAehToFJPjRvdoQmiplJnZQHwsimvquT1s5mRi2eVAvxfe5IzTHiAA16BPAwIpztgzO91NsoVyn5Gcgtu8nwvHU X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:42.7289 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7221624-5538-41c0-485c-08dcb71d27c6 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: CH2PEPF00000099.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8899 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131149_105080_A7B3CFCF X-CRM114-Status: GOOD ( 20.77 ) 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 Add an arm_smmu_viommu_cache_invalidate() function for user space to issue cache invalidation commands via viommu. The viommu invalidation takes the same native format of a 128-bit command, as the hwpt invalidation. Thus, reuse the same driver data structure, but make it wider to accept CMDQ_OP_ATC_INV and CMDQ_OP_CFGI_CD{_ALL}. Scan the commands against the supported ist and fix the VMIDs and SIDs. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 54 +++++++++++++++++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + include/uapi/linux/iommufd.h | 20 ++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index ec76377d505c..be4f849f1a48 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3219,15 +3219,32 @@ static void arm_smmu_domain_nested_free(struct iommu_domain *domain) kfree(container_of(domain, struct arm_smmu_nested_domain, domain)); } +static int arm_smmu_convert_viommu_vdev_id(struct iommufd_viommu *viommu, + u32 vdev_id, u32 *sid) +{ + struct arm_smmu_master *master; + struct device *dev; + + dev = iommufd_viommu_find_device(viommu, vdev_id); + if (!dev) + return -EIO; + master = dev_iommu_priv_get(dev); + + if (sid) + *sid = master->streams[0].id; + return 0; +} + /* * Convert, in place, the raw invalidation command into an internal format that * can be passed to arm_smmu_cmdq_issue_cmdlist(). Internally commands are * stored in CPU endian. * - * Enforce the VMID on the command. + * Enforce the VMID or the SID on the command. */ static int arm_smmu_convert_user_cmd(struct arm_smmu_domain *s2_parent, + struct iommufd_viommu *viommu, struct iommu_hwpt_arm_smmuv3_invalidate *cmd) { u16 vmid = s2_parent->s2_cfg.vmid; @@ -3249,6 +3266,19 @@ arm_smmu_convert_user_cmd(struct arm_smmu_domain *s2_parent, cmd->cmd[0] &= ~CMDQ_TLBI_0_VMID; cmd->cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, vmid); break; + case CMDQ_OP_ATC_INV: + case CMDQ_OP_CFGI_CD: + case CMDQ_OP_CFGI_CD_ALL: + if (viommu) { + u32 sid, vsid = FIELD_GET(CMDQ_CFGI_0_SID, cmd->cmd[0]); + + if (arm_smmu_convert_viommu_vdev_id(viommu, vsid, &sid)) + return -EIO; + cmd->cmd[0] &= ~CMDQ_CFGI_0_SID; + cmd->cmd[0] |= FIELD_PREP(CMDQ_CFGI_0_SID, sid); + break; + } + fallthrough; default: return -EIO; } @@ -3256,8 +3286,11 @@ arm_smmu_convert_user_cmd(struct arm_smmu_domain *s2_parent, } static int __arm_smmu_cache_invalidate_user(struct arm_smmu_domain *s2_parent, + struct iommufd_viommu *viommu, struct iommu_user_data_array *array) { + unsigned int type = viommu ? IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 : + IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3; struct arm_smmu_device *smmu = s2_parent->smmu; struct iommu_hwpt_arm_smmuv3_invalidate *last_batch; struct iommu_hwpt_arm_smmuv3_invalidate *cmds; @@ -3273,14 +3306,13 @@ static int __arm_smmu_cache_invalidate_user(struct arm_smmu_domain *s2_parent, static_assert(sizeof(*cmds) == 2 * sizeof(u64)); ret = iommu_copy_struct_from_full_user_array( - cmds, sizeof(*cmds), array, - IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3); + cmds, sizeof(*cmds), array, type); if (ret) goto out; last_batch = cmds; while (cur != end) { - ret = arm_smmu_convert_user_cmd(s2_parent, cur); + ret = arm_smmu_convert_user_cmd(s2_parent, viommu, cur); if (ret) goto out; @@ -3310,7 +3342,7 @@ static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, container_of(domain, struct arm_smmu_nested_domain, domain); return __arm_smmu_cache_invalidate_user( - nested_domain->s2_parent, array); + nested_domain->s2_parent, NULL, array); } static struct iommu_domain * @@ -3812,6 +3844,15 @@ static int arm_smmu_def_domain_type(struct device *dev) return 0; } +static int arm_smmu_viommu_cache_invalidate(struct iommufd_viommu *viommu, + struct iommu_user_data_array *array) +{ + struct iommu_domain *domain = iommufd_viommu_to_parent_domain(viommu); + + return __arm_smmu_cache_invalidate_user( + to_smmu_domain(domain), viommu, array); +} + static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, @@ -3842,6 +3883,9 @@ static struct iommu_ops arm_smmu_ops = { .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .free = arm_smmu_domain_free_paging, + .default_viommu_ops = &(const struct iommufd_viommu_ops) { + .cache_invalidate = arm_smmu_viommu_cache_invalidate, + } } }; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 3f7442f0167e..a3fb08e0a195 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 998b3f2cd2b5..416b9a18e6bb 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -956,6 +956,26 @@ enum iommu_viommu_invalidate_data_type { IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3, }; +/** + * struct iommu_viommu_arm_smmuv3_invalidate - ARM SMMUv3 cahce invalidation + * (IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3) + * @cmd: 128-bit cache invalidation command that runs in SMMU CMDQ. + * Must be little-endian. + * + * Supported command list: + * CMDQ_OP_TLBI_NSNH_ALL + * CMDQ_OP_TLBI_NH_VA + * CMDQ_OP_TLBI_NH_VAA + * CMDQ_OP_TLBI_NH_ALL + * CMDQ_OP_TLBI_NH_ASID + * CMDQ_OP_ATC_INV + * CMDQ_OP_CFGI_CD + * CMDQ_OP_CFGI_CD_ALL + * + * -EIO will be returned if the command is not supported. + */ +#define iommu_viommu_arm_smmuv3_invalidate iommu_hwpt_arm_smmuv3_invalidate + /** * struct iommu_viommu_invalidate - ioctl(IOMMU_VIOMMU_INVALIDATE) * @size: sizeof(struct iommu_viommu_invalidate) From patchwork Wed Aug 7 20:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756715 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 F0400C52D6F for ; Wed, 7 Aug 2024 20:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IAMVu4DFsuu/fqBPno6W61KUtQwiq8UyhtoUcscWChk=; b=s5QnjZl9bYxj+/Tp55eL8wfidi vTKgkUw/zQfxUh20iR5adiSMvOjr1Bev070qOS+12EvpHthJSPEvgFosLkHCTSWxKRHmFsvxPOuu6 zqGSnP8r+v09II2xbD/Mp0sBgtmna+CQ11t4R7gStX0yzofC2P7LL3sDvDk7p2WQlIo2aeMKh0J8D JLevJTkdgF1paNTBaM1ZiD5FCGkmXb9qrL1FUfiO1AqsiqCj7bS4KP5HxlbHN5OJf1hrUwOgeWFZ9 joph9IK2Pbj0nqHCWqlI1zNn0R/uxLPE2uEVDRVmvjVP52bviM0bLZiworu+mOUybKyoO/ehNcTM0 h9O34A1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn7W-00000006BVw-23kw; Wed, 07 Aug 2024 20:18:54 +0000 Received: from mail-dm6nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2415::600] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0e-000000069KF-30yp for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ao1Smp2Y2MhFTLluuO8GwLT1pr0NwOL4YbPgpvdiKE7pX1NGVFkRqkLCjOlnksixBYwUMsgQp+jDYvHabUY5GuzsP3fTG124PJivXjp+1QpjYJ9JA86zvP8nw5gmr8YxkwktYGbUu9EeQobMZvxJE5oQDJZNzBWFeWQ5EInoFG5EPIxRBC1SkoFX+U4zQgeDeDyFLVBCNQJSIrGU1leuF3ejkeGtQE0oNhR9m+CnGT1dypwQuxsWVVVKan+/OoekRdhrNRXrh7nHh3FyN9vAhODcpYznDoC+iB4NW9LKYMZXdzmWWsdfN/wSkIZ4wZMuX7OvjLugOy9/vdhLGI3DgA== 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=IAMVu4DFsuu/fqBPno6W61KUtQwiq8UyhtoUcscWChk=; b=uidfEiinAidcJSRhohLcyEycNza9cTRhMicttFCCT/bBamYrVLnMgvnDVp+YTPB98ve1xzZcQKSoWz8dlp4TO65DihsKMA4T04GYWXlkxgg4mlSHVqi5eiarSVqjfyIEKWJpvio3wwJyscPPbrc7oVvbmpZoW6VB0oqsPH9kRPjqjxYZ6aqqsY2j0NQP15MiIcshqKfukXXAt/Yzmk7LP52Uz1moz5ps06rHGF7+sYaYxbzDhpjaJngC/GZu1vtJwqdFdf/JMceuaiDYG0t5WPaQPX4teqNPheQvzUevzQXIfwtVncGbPs3FlI7nHJ/SWc7Q80r7UQ59mQ3p3lRphw== 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=IAMVu4DFsuu/fqBPno6W61KUtQwiq8UyhtoUcscWChk=; b=ByPIq/rnC6e0AB4bqMf9aww5VIqc/QOEXnRzxztC0InC9Zxp0tbiJ8d/z54HRC09B0EBNzRZLJvwdeCd+I0sCeTfWq2qK0AWBr0BR0sFZwa850pxFvpvSnfmTmpHjlhHztluUvVWeOKXRvOphWZdeTjWWSowdVR+BuiN/NdQAuoldgnjq9bDLPbeM0tiqrrFXnOUZXk8KGVmxdNpAcFJjjfjeXzol65ywfPTdSyNAAp//WrEz8q3d3j95Wi2xV2S13fZlFYOuhXI+iK7wpE2CA8ATUtbUTCGqGhT647tcwmMHcxVRnmlueyF+JVzC5m5pqksnOaLuOr3Zypkiubqbw== Received: from CH2PR02CA0026.namprd02.prod.outlook.com (2603:10b6:610:4e::36) by IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 7 Aug 2024 20:11:44 +0000 Received: from CH2PEPF000000A0.namprd02.prod.outlook.com (2603:10b6:610:4e:cafe::4a) by CH2PR02CA0026.outlook.office365.com (2603:10b6:610:4e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Wed, 7 Aug 2024 20:11:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF000000A0.mail.protection.outlook.com (10.167.244.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Wed, 7 Aug 2024 20:11:43 +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; Wed, 7 Aug 2024 13:11:28 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Aug 2024 13:11:27 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:26 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 16/16] iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Date: Wed, 7 Aug 2024 13:10:57 -0700 Message-ID: <442b3d5d2b15182f5cc100346183f8c710b7e909.1723061378.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF000000A0:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: f6351630-0dae-4498-5ae5-08dcb71d2871 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: a0lBqDPwfbuVGhoNWwBklzZOK/GRb1n4WsDDDlUqObC4lbm+d+/i7nTkV7rC41g5fM4ghvgyLxSvonlp6KEMNnrEb7o1dyP287TjiBpfOkxiBbEinO6EcAMCSGoWSoTEJmVQBYhxz6zkau0aEWqlJgklos+q70t/g5VBl3xlSbHXpx6GGcdgcA5tEun4ucBG7cSntbPoXW0sTQwT4B2lGlaS/fefIN6KNSRPiWDZLvadEfb0EgbgEfbp6BNp5SjpQcQujAgf7e/74afgSnF475TwhKvqqnfkaTrMc0LAqCse5MP8ejHPRGkMEEGxf+C72klE6pYLCGpRl1ZXn4haGVO0S8YLi1dppjgRacagEtz2XjTufma/lrOihLP2VU2XJJ3S5AIrIA2s33yhNZXtMjFuhWk5/8/xgRiGqv+soUQJC1xWo3xgMpzMvd2nAznOgg5Zfy5Ps/YxB0kuVbk5TYH2dgoy+8yx9xKsyQxcy9N4RZjy9N3zN6C/w4U4rESCB/d30TpzlX7V07z4A92M3aY//PTL11t2DLt5SOOCgmXP6BW9LnRX+Ka1gRUSX7lJwNyX9vTRc/yZ/pyOwfc5pzcg962f6FKeKYUG3BldIsfH9SEiT8mod1/Ch9IJo/OQTZdMSOMdK+S+RqCflAAsa8SNm/AlKY+xfoUsch0oARA+cDxGezJ3pNP5RWjiujaee3E9Du6qZCN299xK5SkaYhLbWmiBQSq4hD7+etDV/xNnIqfvOQSyqcBWIiF/DkWEslgyj2YAqTUzZBk/t49rAERS3Q9aONYmrEILwMRb5B8ZmZZl2MR91kDu10/7reCC96wwqb2xRJwlkPJBu7DOeSs/I9wj/dAN887NHcZ8393deI1mFsW+iMxyELI86YBehS859W58cKP2bpuXAhfZjOg/E1cMyJJfY5yXbXQulUGWscnwarcDWXpKeVS/sAsqxAYvTAh2xF9Z2TTkKW0LRCdCffu2GHmzNW3d5L3LHjxw5oiKdZhXg+7XOUGCNJrK7E7jYCsbj4+P0tVaSjoznMcK/On7MILpIEU+jN7bD+lyKPbckGzeJ1GYGeliPyiIrFlab/NHNkZH2fdcphyO3KGgHMDcsw+nmDlQ99oOmEBdwXZWQZDfnFoVXXT1cLqrIbj4UiPUtv+ZqleWqlObZ+UkRdKZUeqSBeIxMDOnDI/yDTPEqJ3wlZsp8OhWpYRB7W/fF4W6SItalOrseAtK/n9TIMl7TF6YGmAbHNQleS+CmTry2smY+OSZGh1Vp5QCqQeezK0sK8ymNGTOusNnFOizNhjqEsF2RTqLE4RaOtk1pskXUSYdlT8vNs7r5e2sJ8TWq9l+TcHQX4k2vUFknuHIfUwwzmjgKx6NbjbuFEImUw5UjTYg+iVZ/VR1TOdzU5vy72DiEwb4w33CPmJ7RpheYufGNLjBN0qUnhq/zIE3MfsWa/RG1QP25NHaX7kw X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:43.8657 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6351630-0dae-4498-5ae5-08dcb71d2871 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: CH2PEPF000000A0.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131148_955399_2DF97291 X-CRM114-Status: GOOD ( 16.14 ) 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 From: Jason Gunthorpe Now, ATC invalidation can be done with the VIOMMU invalidation op. A guest owned IOMMU_DOMAIN_NESTED can do an ATS too. Allow it to pass in the EATS field via the vSTE words. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 ++++++++++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index be4f849f1a48..ce84f0c04022 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3189,8 +3189,6 @@ static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, .master = master, .old_domain = iommu_get_domain_for_dev(dev), .ssid = IOMMU_NO_PASID, - /* Currently invalidation of ATC is not supported */ - .disable_ats = true, }; struct arm_smmu_ste ste; int ret; @@ -3200,6 +3198,15 @@ static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, return -EINVAL; mutex_lock(&arm_smmu_asid_lock); + /* + * The VM has to control the actual ATS state at the PCI device because + * we forward the invalidations directly from the VM. If the VM doesn't + * think ATS is on it will not generate ATC flushes and the ATC will + * become incoherent. Since we can't access the actual virtual PCI ATS + * config bit here base this off the EATS value in the STE. If the EATS + * is set then the VM must generate ATC flushes. + */ + state.disable_ats = !nested_domain->enable_ats; ret = arm_smmu_attach_prepare(&state, domain); if (ret) { mutex_unlock(&arm_smmu_asid_lock); @@ -3420,8 +3427,9 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, cfg != STRTAB_STE_0_CFG_S1_TRANS) return ERR_PTR(-EIO); + /* Only Full ATS or ATS UR is supported */ eats = FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(arg.ste[1])); - if (eats != STRTAB_STE_1_EATS_ABT) + if (eats != STRTAB_STE_1_EATS_ABT && eats != STRTAB_STE_1_EATS_TRANS) return ERR_PTR(-EIO); if (cfg != STRTAB_STE_0_CFG_S1_TRANS) @@ -3434,6 +3442,7 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, nested_domain->domain.type = IOMMU_DOMAIN_NESTED; nested_domain->domain.ops = &arm_smmu_nested_ops; nested_domain->s2_parent = smmu_parent; + nested_domain->enable_ats = eats == STRTAB_STE_1_EATS_TRANS; nested_domain->ste[0] = arg.ste[0]; nested_domain->ste[1] = arg.ste[1] & ~cpu_to_le64(STRTAB_STE_1_EATS); 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 a3fb08e0a195..65f90b00e16d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -811,6 +811,7 @@ struct arm_smmu_domain { struct arm_smmu_nested_domain { struct iommu_domain domain; struct arm_smmu_domain *s2_parent; + u8 enable_ats : 1; __le64 ste[2]; };