From patchwork Tue Aug 27 17:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13779888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54BECC5472F for ; Tue, 27 Aug 2024 17:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=NJRqyWftLKMClQWnGGsldQM6RS ZOavOm5CdAvzQjx21lemdp9GKPGl7afCb8JXLwIEdNEBMlzi8A5Q0j0iRsagJYWxi/EfFScsIADqi nos8uRmRWisxopbaTtQCN5QIc+/DX32i6J40rv9NoLcbSGsU3Mkv3FuLgdkvmgtCEGKpeiGFNN04g e92qkH2y/Eh3WDIUGACIAurZ02vJKeqVJtLFp8UQL7uhzZjk/gdwtnGKbub5/2TMbpwjTUGiVHe5P BN8gpQbDVt/8Lee7mNs3hnRPHLs991rWm02QrXHOFImIJer2CEUW0trOdsHNpqsVWrpck5M1G7GQ9 8/4Rg1eA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizwg-0000000CHP0-1X1D; Tue, 27 Aug 2024 17:25:30 +0000 Received: from mail-mw2nam10on20617.outbound.protection.outlook.com ([2a01:111:f403:2412::617] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizao-0000000CCGh-10sQ for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:02:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=isqcK1v073uqW2Cg7/dVZ/lqHEEX3cSiiBdOB72xW4ZOp/SM9eBA6B+EtaiN3XFZUCKiIj589koPdxNutblBEhrR+5nqUIyJWxzKDYR75HWET3+QAOVaCLh59ffsJ+qrqRIBT+LHEypijV3QyzEqNCJrKeqnMvrSmF0bzfIJbXZXtthpgFnxjyyNfPPMv3UymvwrU10uAkLCX+P5uqwxeqKI4WloEw4BT7VEIwFzdvF+UIsU9Ahe+9HhOyisz9hgz94EKxfKpTQmntogjGJCRqDVuV/8fopwww9FAqlJ+w2C9mJznICNB70qcAOKExJpIzA7TdsdVxu8XaGCgfAD7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=JnMGPWtPStgUh6bAWFcsOCeXxkFYiF/4vVxZ5XIZYHH2FItW7uWd+d4UbM40VLxe5QyXvMEF0SoqTdpebUPMoDe+PMLAJDdnhl0yzLgMJz4etHx5CZrXGRjMYP5t37O9LnBvf+yhX1OuzVJyPiNgWkCB4vudyhKEDdg111R3rIj1hhLDMXe4mhMYSDZJGQOM3OqxUgb70CA5qKNm+TdaFBgIKZ+o4wVKd6508jPMflOVA1Hl1GFttVI33xmpilss6oEvR56NbBxgg3SGEZqzYhSeSFhky5je+k9wmUEsg6eqzAbnDqMkRmpmRZ5WCG8X2lxxmC8sxk1XsZIoggKl7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PjHK0Mmz06BlScrMGlT/QFUlxKbZ8+hHetw9oZzo2R8=; b=mtLP0IVCJbxKV+h8jKTHo0+kYizW/a42eZmztDImQUNAyXUw/sJQZPMv87Uu4dlwgw24XtqwPEXM0xy9Og4A61nDjBQfagO6f8nNLKEhRrlPQ6BC+O27mFDUXi+CjPORU3mo/FMyqBbgyttqrXbEJrp/klzCgMXe4admb+T+HdQJKXawLp48hb+wBo/8kYE38ji9SD8SWqw6ixqZRkAywkRNHrGw1w2ZnXPTF7HldolvvLFmwAFPH/C99C5C6KyxmsO4Kkfk5HtkhCuKEDlSVWkcHv2Q6BwpUEa4EY+Z5594K5IsvYUrRw3WdcmSZZxaIVdRKz9zWes6cNmbxevDtw== Received: from CH0PR03CA0417.namprd03.prod.outlook.com (2603:10b6:610:11b::6) by LV3PR12MB9404.namprd12.prod.outlook.com (2603:10b6:408:219::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 17:02:49 +0000 Received: from CH2PEPF00000142.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::5c) by CH0PR03CA0417.outlook.office365.com (2603:10b6:610:11b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26 via Frontend Transport; Tue, 27 Aug 2024 17:02:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF00000142.mail.protection.outlook.com (10.167.244.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 27 Aug 2024 17:02:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:33 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 27 Aug 2024 10:02:33 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 27 Aug 2024 10:02:31 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v1 07/10] iommufd/selftest: Implement mock_viommu_set/unset_vdev_id Date: Tue, 27 Aug 2024 10:02:09 -0700 Message-ID: <383bb9fabff0051bee9c0fbb5d32163f1e0cf87d.1724777091.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000142:EE_|LV3PR12MB9404:EE_ X-MS-Office365-Filtering-Correlation-Id: 8effce88-3043-48a3-1ed0-08dcc6ba1425 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: z0n1FM38GPuF25sZ722gtCjAOCnr3wacsyQfmBGpN7b5w1oXiQudOcx1Lxcc/fON4pFDS4TM9WeMiKeMz42ZlK/EbxD6furI02oyWfVdACiDR1YE08o55l+2PO4VPF+JdCByuMyMs0YAAH4ga276ZCPu6v1Rp5pd5ceDb0FjrovWqd9K9KU8tbP33cl4b9nbSijY16WeLqeEXy2MDUq2dgfD1jTN5aFlea8DZ3ShdBrTu9ljPsvatyeBsCXatGi6/WEpfhYerCALdUaDd1H2IMIMmlQtYL7wPn6pTKHEkeKqhKL+9PpvmgjQPg5xGSrDsLuGWJsc6pmM/9Qmixp4V3nM+Ux9xy+aw1bmD9tBgih3IlF2ihYZ0w/qoDIb4pTXKPd9/11/wi21DVu2us5TSNNRElWHSLIeLJbB/osWarHi2J7L0jycxAkzywU8T/4PYfqCSiq4y5bKyWqjXA9lOLQ9HPUyHUSQgQy7eMGZIZCY+zyrDhmKbDPzPSE8S7t9wLEKssCZPavp8hgwgjHpiRK66/MCThqnuIZb5ofoA6+igesP/vSqp9FpBv6zcXcuoZi01yygIRahCvHwuTMUrRaRd4I1iKRO8SWhlFAPidjJgEfdOB2IBePzHxBpvVTabzB18wkUaR4fEIwt9OFaXDefTYSyYYdw4pq4LTJgGfUlOhsQBuv3KVVtFCbzuMmf5Kdq00wBvbWiivFfKW7p/dfLYql0fk1DhcK+4hFsJgsU9A1dIbJiUTIby/Sy+7j6YY9Os8+6sh46tAqXjN6xppti3gGFNSdQ2ajevUVTFNPxCgUrNqJ7FeeCctvGoB/cuxi3O1Jc3uRz3X8yBOdZ+cAYa/C8MsBAL+XHoUbQ/4uE9XgxuvNqlRfDFjcrLEIKRUn3S1/f2JP6UOgpKjr+iy7BbEAeU199n/gTY2LXpP9AlJ8cYBsnYfBEqMSeFJrllc6NUE5LOI/bDDOnLfOdKComB5PLWGhDAFblP9Q+mplRrIt4bRS6vLR3R60P9TLF8v/VJil0/22vJ5EozWbGF1bUmYwA2xz3OYOCnqQPIgPYYAuzTbTmf8zp5PFmeKkfO5S7bcb0mtvcKJPbuUH0gKiYs1PUEJv2Fa0y3/poCCN4Yo57IntzvPX7xHSVLJHedek+eEQWP80u2qmy6yJo1T7l2bxoUC+33lWFNk+kt2CtQKRxBRtT4Ok+lVloCIl2Hpzc0n5Y5+vkt0huvzazBHLvjfGV11mhLGQIl0rFhuhTCIdFbXbIt4fdfRig+KV759eHUkrWwV8zU9aTTQ6LZ/gMDZd92RiSh/M0LoLrghczwXZBd0BIJlyOQEYfcAZcEbyVUiYJj5zk7oYBaCER+F3cwFDzL8GJpqBmRvQKB4FrcZFThv05IQAvea3eJhn750+QgoWPiX3J93X73b4sL6/QkihkHLJfGk62eWfk4NuWsglCU9XX0CZwrnoM5Gtw X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 17:02:48.2242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8effce88-3043-48a3-1ed0-08dcc6ba1425 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000142.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9404 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_100254_459926_B94C38A2 X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org So that the driver can take the control of vdev_id's lifecycle. This will be used by the VIRQ feature in the following patches. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index f512874105ac..ea2861d34b4a 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -137,6 +137,8 @@ enum selftest_obj_type { struct mock_dev { struct device dev; + struct mutex lock; + struct iommufd_vdev_id *vdev_id; unsigned long flags; int id; u32 cache[MOCK_DEV_CACHE_NUM]; @@ -541,6 +543,36 @@ static int mock_dev_disable_feat(struct device *dev, enum iommu_dev_features fea return 0; } +static struct iommufd_vdev_id * +mock_viommu_set_vdev_id(struct iommufd_viommu *viommu, struct device *dev, + u64 id) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + struct iommufd_vdev_id *vdev_id; + + vdev_id = kzalloc(sizeof(*vdev_id), GFP_KERNEL); + if (!vdev_id) + return ERR_PTR(-ENOMEM); + + mutex_lock(&mdev->lock); + mdev->vdev_id = vdev_id; + mutex_unlock(&mdev->lock); + + return vdev_id; +} + +static void mock_viommu_unset_vdev_id(struct iommufd_vdev_id *vdev_id) +{ + struct device *dev = iommufd_vdev_id_to_dev(vdev_id); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + mutex_lock(&mdev->lock); + mdev->vdev_id = NULL; + mutex_unlock(&mdev->lock); + + /* IOMMUFD core frees the memory of vdev_id */ +} + static int mock_viommu_cache_invalidate(struct iommufd_viommu *viommu, struct iommu_user_data_array *array) { @@ -636,6 +668,8 @@ static const struct iommu_ops mock_ops = { .unmap_pages = mock_domain_unmap_pages, .iova_to_phys = mock_domain_iova_to_phys, .default_viommu_ops = &(struct iommufd_viommu_ops){ + .set_vdev_id = mock_viommu_set_vdev_id, + .unset_vdev_id = mock_viommu_unset_vdev_id, .cache_invalidate = mock_viommu_cache_invalidate, }, }, @@ -757,6 +791,7 @@ static void mock_dev_release(struct device *dev) struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); ida_free(&mock_dev_ida, mdev->id); + mutex_destroy(&mdev->lock); kfree(mdev); } @@ -773,6 +808,7 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) if (!mdev) return ERR_PTR(-ENOMEM); + mutex_init(&mdev->lock); device_initialize(&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release;