From patchwork Tue Oct 22 00:20:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13844937 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 93D0CD1714E for ; Tue, 22 Oct 2024 00:49:39 +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=GmoYv5BXmCe+AYwmJbXz6MBwe1Btk5MIZJr1HGNZ+QM=; b=ACYZVWYHUK+NAbDSdJeX0XuKV7 Xuq1Nz91uk1mGUwsRt6QmfIiOrVlAymFmsKogZ5pXNeOdYXqcY9Tb9pj4NSA4RtLc6LQFpcnz7kXw YV/6pKEyeCDirBhx2FWB601XHkLjZZLAy8V140c3/QVcVxLB2/jS+gA7i21kfxzIXDHAERbD+MDMH CKvI18XvKdi8RPva8thasS7LVM7KXYjWS8yDGlzO2ksZN99ET0R780zp23A6GratU0ssRA+/yP93b jnWHApqruiRI5GEQbkkxKeBVbr/ectWkUe/USAzb49JzH21riyf15dluZXwBwIvN8ZTDD1lkjNk+o NQrme0AQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t335W-000000097Sl-0WJb; Tue, 22 Oct 2024 00:49:30 +0000 Received: from mail-dm6nam10on20605.outbound.protection.outlook.com ([2a01:111:f403:2413::605] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t32dt-000000092SY-0XCc for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 00:21:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X7W9SCmD/8aW4zWta4sr3o+LPxPAA+PweKkfBwGpBOCx4MviBviDn9ivcWUnh9l7HHZ6UYiml+seZPsmk3n5lwXaDCmeDG/En3e8OHF9mErRy8613vajZQLJyD7EDHq9M7udwRAZRFvkHDOMqA4UxPuDZjJAlnKyrkLjAi6+2sOlYsZMP774Hqz4M+XGQrgv9nosQ6UidtmQtmhle4lA4G9DfuSMeBs7xNmZLGcygcq7CoVqmg9KEqG+OWf8r8Okyktv4Iw2yxLN5yqbHY8GacxulsbvYXyDDRp04jL6MQjokXrqylP1vr56/Z/Dp8unEXLcfUivs6ve/bgEUcb8eQ== 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=GmoYv5BXmCe+AYwmJbXz6MBwe1Btk5MIZJr1HGNZ+QM=; b=j2M1onr9sXrw+we/+qN+6GH7AS9bL3ClHvnZQd0D5km4kXtIojPdc5mztBWbOBfLUrA7MemQ45REHCLMS0IKA10Jq6HqegSRv5n8N1YIUV5yezSl04qwtq4o9tf5/ter2zDTizXixv8Vp8whbcv4zJ5UcW4hynYI/H1ko9nCJIacxVoVxvrcJybDyKcvSNvmMVpGsM2YI6Zi+Hlhp1h2+VZAS5gPYszVyZ56cCOtC9oS6CXBLkugLs4WV2pVKmI1ZMbgBw2uHxCGNW7TNhsN68TiwwUl28r4fJ+QIJIGPpf8qi5opNiUFNxxKz8/JAxapZr4V6W/KYXh5GIUDPk5ZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=amd.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GmoYv5BXmCe+AYwmJbXz6MBwe1Btk5MIZJr1HGNZ+QM=; b=C0RamxVS8akGoIyCSAv7kFyX/Eimhw7V3wd8zl+TJnJfc3PxUT5NMNcPskmfEeW2LsSIdZM6hTgy6dA44TVUlO8CIj8hOpPczeyRddOS/pdCpXILv2KVLMDcqyR+kYXpzsVl7FwBLPQ6B6y9bnQ6eIOpsfEZhdFJutS/afTdesD1MDSiIgFo6T9kD3AZf7jzJ0sYu7VWHYhCfiaQK67xdSZk6Ym3mPQjLPgfo+rnhKZdK8/oJdo4VgPnWaKnvOWQ9BBZPkmvk7uKT3AyoE74XFsV3BGDV8MgryZXbttASu+vvGfR/Q3GAY/PbHIfpH8RKwK3TpYjdFf08O8zP8FsGA== Received: from CH0PR03CA0006.namprd03.prod.outlook.com (2603:10b6:610:b0::11) by MW4PR12MB7359.namprd12.prod.outlook.com (2603:10b6:303:222::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 00:20:46 +0000 Received: from CH2PEPF00000149.namprd02.prod.outlook.com (2603:10b6:610:b0:cafe::af) by CH0PR03CA0006.outlook.office365.com (2603:10b6:610:b0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Tue, 22 Oct 2024 00:20:46 +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 CH2PEPF00000149.mail.protection.outlook.com (10.167.244.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Tue, 22 Oct 2024 00:20:46 +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; Mon, 21 Oct 2024 17:20:32 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Mon, 21 Oct 2024 17:20:32 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 21 Oct 2024 17:20:30 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 03/14] iommufd/selftest: Add IOMMU_VDEVICE_ALLOC test coverage Date: Mon, 21 Oct 2024 17:20:12 -0700 Message-ID: <80162ab41c302ac7f624161cc78a5bf1524f60e2.1729555967.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: CH2PEPF00000149:EE_|MW4PR12MB7359:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d22fe15-e77c-4e58-6ba4-08dcf22f5fa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: n+KjiEZ7JGg+h0WTVNkH9K9/Iy1n3Ly13uJFQgk4obh4JPBMIlVteJlnUg6ggiZUSsgshb4uESNAYRx7El6jeakYiWJEL1iC3dIs/pkcwsRHsCTo5c4XDbtkIfrpYGTLpS1OU+yVDsNAKp7jbeTnoZCzqtYBRN5ZZdTgjzu2MDjX8RQRGGboJ/S+LZRd2rILCNa3w4HXAHCUt/ZaxNE4PxHJKqOauARicHQd+UHHR/XIBY20roMNmlhWjYGgkNoK9hSB9WODOlzg86Z76WdzYj40wonpNLLclB8nmFwWeJpWU+PZkwOBYywB2286kADify0Czwu1QJmFNc6Lb0c7fv6KfP0/vgdN9apD0+jU9V7rDDHPCKFgtPadvbNYuVh1qe+nAevaXQGvO6oAhg7ZUv4yiphNqZ5BxAACx8SgevLmQ9Q7T5vdXJl7/foGeP6/er1mIchqCFoEV5UG/RZ7DPHA/WK9w8zIeixzGtxWfU+F12eN92/1P8y3IAJsqvcKP6meyY1b63NmVnnDyTEty8iz8QMtD8qEavNT6XDwMfbEzwomMwW0tE8am9+hISptLvPSStk/ag2wZIJj955rE3ylKIP0a32Wui/RDaK7LRMAhipuh96UZliyvBKw++nEi7GjZfzydX6jBh60eQp4kQaiCcA/gOTecQgh9uz3tL+g+GmCqmgaxNLTXV9MWDT/Fs1O07FQP9c+2Xc7xw1SqOMY7b17q12d4A6Pgysh2bYEukWKtDsDSpgBScxDs11nsRDkYofj9vFekqnNByoA5QJXFbOcdPRxmaPFPWzEArjEllMCHh6dFn/ObjpZTVV8wLssmeCU+OOZVdjKZvXCJsXlNEVeXuT8wnC3+VqDB4c9jZOUaNtR0rDRA0LP6E8JDNQ6FRS5b8K6DKsTJYzouwImGYbj2zcgwFC9nZxl3XVbT5rgIdtArioHiaoaBR2GixwVPhAjXKEweWxHBJekS/XGKlAK4OM60321Ox6HJSp4qzKurhRo5lyO17doXKUM1I80AVNzI6Hwfff6dxayDy9GdujgJ2HO3T42OS2bFc7z95q5nqJ5Lg/UF06QffFJnwIxOU7c5iOV+EsJ/fU/jpOrD6vZfppzcloI00PLGkwmg9Vzw3IROBdJFQJwMsgsOFdolHD/cyx4f0Lcugp2L7H3qSFvTe583wIvaq6F5wrko19mdRlltHWGS7BQo1QHnTcCm+VSPBdd6+wcSxlsYrrj+XOp/GeVSnyoq+G0tjpNI9kxrblijlN31WCfR8ZaUt7+L1Kr8x8piVvP+IZ1Xn89eQHQI//yJUINMTQ5XMqCPHzK/GetfpFhsowYDlg0k77zwEjmILY6801IGDkJlpsPLbwIxoy7lO87U19Z4bMlCxMyZGzxG5P4YXPvo4kfr0lcTbnT+egL+i2WAAitPA== 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)(376014)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 00:20:46.0004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d22fe15-e77c-4e58-6ba4-08dcf22f5fa1 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: CH2PEPF00000149.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7359 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_172057_279115_E649E140 X-CRM114-Status: GOOD ( 15.85 ) 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 vdevice_alloc op to the viommu mock_viommu_ops for the coverage of IOMMU_VIOMMU_TYPE_SELFTEST allocations. Then, add a vdevice_alloc TEST_F to cover the IOMMU_VDEVICE_ALLOC ioctl. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 27 +++++++++++++++++++ drivers/iommu/iommufd/selftest.c | 17 ++++++++++++ tools/testing/selftests/iommu/iommufd.c | 20 ++++++++++++++ .../selftests/iommu/iommufd_fail_nth.c | 4 +++ 4 files changed, 68 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index ca09308dad6a..5b17d7b2ac5c 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -790,3 +790,30 @@ 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_vdevice_alloc(int fd, __u32 viommu_id, __u32 idev_id, + __u64 virt_id, __u32 *vdev_id) +{ + struct iommu_vdevice_alloc cmd = { + .size = sizeof(cmd), + .dev_id = idev_id, + .viommu_id = viommu_id, + .virt_id = virt_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_VDEVICE_ALLOC, &cmd); + if (ret) + return ret; + if (vdev_id) + *vdev_id = cmd.out_vdevice_id; + return 0; +} + +#define test_cmd_vdevice_alloc(viommu_id, idev_id, virt_id, vdev_id) \ + ASSERT_EQ(0, _test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, \ + virt_id, vdev_id)) +#define test_err_vdevice_alloc(_errno, viommu_id, idev_id, virt_id, vdev_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, \ + virt_id, vdev_id)) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 04dd95fe24ca..f401c565143f 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -136,6 +136,10 @@ struct mock_viommu { struct iommufd_viommu core; }; +struct mock_vdevice { + struct iommufd_vdevice core; +}; + enum selftest_obj_type { TYPE_IDEV, }; @@ -558,8 +562,21 @@ static void mock_viommu_free(struct iommufd_viommu *viommu) /* iommufd core frees mock_viommu and viommu */ } +static struct iommufd_vdevice *mock_vdevice_alloc(struct iommufd_viommu *viommu, + struct device *dev, u64 id) +{ + struct mock_vdevice *mock_vdev; + + mock_vdev = iommufd_vdevice_alloc(viommu->ictx, mock_vdevice, core); + if (IS_ERR(mock_vdev)) + return ERR_CAST(mock_vdev); + + return &mock_vdev->core; +} + static struct iommufd_viommu_ops mock_viommu_ops = { .free = mock_viommu_free, + .vdevice_alloc = mock_vdevice_alloc, }; static struct iommufd_viommu *mock_viommu_alloc(struct device *dev, diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 49ac144cf5a4..a8c6bdf64825 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -129,6 +129,7 @@ TEST_F(iommufd, cmd_length) TEST_LENGTH(iommu_option, IOMMU_OPTION, val64); TEST_LENGTH(iommu_vfio_ioas, IOMMU_VFIO_IOAS, __reserved); TEST_LENGTH(iommu_viommu_alloc, IOMMU_VIOMMU_ALLOC, out_viommu_id); + TEST_LENGTH(iommu_vdevice_alloc, IOMMU_VDEVICE_ALLOC, __reserved2); #undef TEST_LENGTH } @@ -2464,4 +2465,23 @@ TEST_F(iommufd_viommu, viommu_auto_destroy) { } +TEST_F(iommufd_viommu, vdevice_alloc) +{ + uint32_t viommu_id = self->viommu_id; + uint32_t dev_id = self->device_id; + uint32_t vdev_id = 0; + + if (dev_id) { + /* Set vdev_id to 0x99, unset it, and set to 0x88 */ + test_cmd_vdevice_alloc(viommu_id, dev_id, 0x99, &vdev_id); + test_err_vdevice_alloc(EEXIST, + viommu_id, dev_id, 0x99, &vdev_id); + test_ioctl_destroy(vdev_id); + test_cmd_vdevice_alloc(viommu_id, dev_id, 0x88, &vdev_id); + test_ioctl_destroy(vdev_id); + } else { + test_err_vdevice_alloc(ENOENT, viommu_id, dev_id, 0x99, NULL); + } +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index e9a980b7729b..28f11b26f836 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -583,6 +583,7 @@ TEST_FAIL_NTH(basic_fail_nth, device) uint32_t idev_id; uint32_t hwpt_id; uint32_t viommu_id; + uint32_t vdev_id; __u64 iova; self->fd = open("/dev/iommu", O_RDWR); @@ -635,6 +636,9 @@ TEST_FAIL_NTH(basic_fail_nth, device) IOMMU_VIOMMU_TYPE_SELFTEST, 0, &viommu_id)) return -1; + if (_test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, 0, &vdev_id)) + return -1; + return 0; }