From patchwork Wed Oct 9 16:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13828826 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 58756CEE330 for ; Wed, 9 Oct 2024 17:00:52 +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=0mGsrTnbsmY4X85s6BenaoLrJrpAH3MtQiiwHnt+EI4=; b=AEvyJKWkK/xi0miDCVb6YJehMW fmWacQlA6HrCqvO0G3JElacde74KOPIdldDvxtZs8GSo1/EHyKgu51bCeJBO+rjBb6veC4rLPUGtr w9Um1fFiMqoP6VfNtSn88dXszQi+ATZt3Wle4Zurm4GCSesxBumhADz+gad0qXKk39VzrUx4GcDE7 pLDydpWnkOpmQ7ugAg6pY83Eju9YcOwzJOp9NtVP6mAQy8k4Tm6BMpDcoai1WL3pQxEsva5THKCYN D5dWSagaaJSo6W0GNHEqDb1W97xDfXUsCndtAkRuOtEaHaURMNZN6mLlOx2c5Cd0/2JSD5SaissZ+ KZnL3blg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sya36-0000000A5zK-1bGH; Wed, 09 Oct 2024 17:00:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZiR-0000000A0UO-26Kf for linux-arm-kernel@bombadil.infradead.org; Wed, 09 Oct 2024 16:39:11 +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=0mGsrTnbsmY4X85s6BenaoLrJrpAH3MtQiiwHnt+EI4=; b=dPO71jYYhdgf3d37GyT/TvLfKR WHE2npGx+or2UbQs7SoF5oKasJgZuBrFEatvkWnJIEFtaA/2ZC8VhzW91Id8wl2oilulVXOCjtCrq MF3Wfn+AMum47sqvfryifmrBog1US3Pt2qmq2Tgc/rKKPIOalhmFKKjgeQjmW93VAgl8+6PVljbdz NCsHBuxxKIFbrVC0DXDJpX8T6o0CBrnPeKjM0IZHf64XOUCjPQwaZZIjOp1qVr622Qcq4IGsV4vT4 kOnA2Z0WBXDYFPfuBy33qmvwFj2p2OGCY3s/KXoXliRymf0LlfHuvAvnWweX3HlCOqytWNpB8WDDC If925CUg==; Received: from mail-dm6nam10on20600.outbound.protection.outlook.com ([2a01:111:f403:2413::600] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZiN-000000052e4-2YPR for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:39:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F6eyTYRLwPSP6vJoOTLSSiMhM9eGd2/CmwbO9HgtmWC0gkiXzFJ3eAQflvFh7Rp5e043SjGpX/0LwTeia/drDoA6As53I23v3v9mFQfq+UDN/en+H/balyrkKE8aZIO3MZrcXuy7FLBMZvHD/bqFA7OGeO71UBGTNyy8ABW6GLwX/GPAtsYENDXX5gY9kGKCKOLnwRHk5zkYuzd2KZwDukx37XKiBpO/Y6ncGLzRUpn5i5cbPAhSyw9RqU6PcsYuOFaQpIg7oJJuslpsUEihFgJGL3h7qItiin+a2QdXmdicbh+cUQP9v4Y2BwsJ98PCnxFlWwsMPwUAFlmN4MTcJA== 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=0mGsrTnbsmY4X85s6BenaoLrJrpAH3MtQiiwHnt+EI4=; b=SF7Q2OhpcSi6cib8jq3aYHzCAcOl7608uycMKMrWjr82CFj02HWiiKNxk4P+hoJUVIgwmve1qTL+6qNII24CajKR/pun+9+5ktPde14KoyzSX/0M3s4KZ+Anr0tHWtzV/OLDoRYSR5XhXT152xcOqs4IurpOGdXe21YmdT+sJ/VSaSyQTmBkOO7DA/tPpVWrohOoT74/WmszcheeCg8hGk9wlkX4crwhf5KQ/Ao4jE2hDiiAYQayrZvjgXAJq+tLAraPbSgVQsV0zw363cFC+BuRmr12a1IAFqhq1GHcC+iPIuRTexFm0pGMRPU1z0qnL7p1w4IFPIOZrSOW8E7jOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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=0mGsrTnbsmY4X85s6BenaoLrJrpAH3MtQiiwHnt+EI4=; b=s6lTxhEB1Amw3UoAZ3by/oEovgfyoRydiOKWc29GsqqaGfZkDKorqQ3vap7AN2gnq1cArcgqbhjYH82BR2ecKKgv4odsRdZe2C5nSEr1SB4aiY1rKBC6Y91+L6pj3limwxc5qBV7nYj2/ZUrXpYJEhjfk1NAxU9XynKUKiwzjum9+wD+ZXBMKmKfySjf+nRrhQ31Xt7/HBYh0f6JMukbAZxrlmbTSXSgMLZSOy5/eF5o5hgdX4K4WNJnf2kPhtttaa8qqjH2cIi8ppUX+g1D475rxHZ60IYfIHhovB5hu2CvmBsHbVoxKVmrRawOk/q2PanSRyDBdUyb2AfXGdFi0w== Received: from SN6PR2101CA0021.namprd21.prod.outlook.com (2603:10b6:805:106::31) by DM6PR12MB4249.namprd12.prod.outlook.com (2603:10b6:5:223::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:38:57 +0000 Received: from SA2PEPF00003F62.namprd04.prod.outlook.com (2603:10b6:805:106:cafe::98) by SN6PR2101CA0021.outlook.office365.com (2603:10b6:805:106::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.6 via Frontend Transport; Wed, 9 Oct 2024 16:38:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SA2PEPF00003F62.mail.protection.outlook.com (10.167.248.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 16:38:56 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:50 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:50 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 9 Oct 2024 09:38:49 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 08/11] iommufd/selftest: Add IOMMU_VIOMMU_TYPE_SELFTEST Date: Wed, 9 Oct 2024 09:38:08 -0700 Message-ID: <240dbfe0bec59b39e759d610485ff062054c370f.1728491453.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: SA2PEPF00003F62:EE_|DM6PR12MB4249:EE_ X-MS-Office365-Filtering-Correlation-Id: dce43afd-9f1b-4a72-3192-08dce880dead X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: EdRk2ErIyQOQKWUvbucQJpaiYbNtkVqmVKwNorwRBMSPfwdMt7SBeCWHD3VVffhK4bBb7pkV/OCtP9+wyvxavyg0fES0/uTccZ9AMhzooJVZIb5paDp6I+i3oNSD/5SMfdEG8Z/RneDkztm8U2Rj2X5alDbog5dcOe9MXYYnYz4WZmMEIwGeslOW7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ATf8vPTiaT6uv+L5jxWuq2EhADpOe+Bz6pUGBncp3LKlIy1JS5TuR0XNKYYyG3drBzFPNaHHv7vRZnz1mKTnsmL7VLuFfe7IV74zJfeW8tc5O5Y4sUsmzDl2Q5d2NJCesi11khiJgUi X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:38:56.7711 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dce43afd-9f1b-4a72-3192-08dce880dead X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4249 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_173907_743219_DC222429 X-CRM114-Status: GOOD ( 13.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 Implement the viommu alloc/free functions to increase/reduce refcount of its dependent mock iommu device. User space can verify this loop via the IOMMU_VIOMMU_TYPE_SELFTEST. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 2 ++ drivers/iommu/iommufd/selftest.c | 45 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index f4bc23a92f9a..edced4ac7cd3 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -180,4 +180,6 @@ struct iommu_hwpt_invalidate_selftest { __u32 iotlb_id; }; +#define IOMMU_VIOMMU_TYPE_SELFTEST 0xdeadbeef + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index a89a865617db..4fcf475facb1 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -132,6 +132,10 @@ struct mock_iommu_domain_nested { u32 iotlb[MOCK_NESTED_DOMAIN_IOTLB_NUM]; }; +struct mock_viommu { + struct iommufd_viommu core; +}; + enum selftest_obj_type { TYPE_IDEV, }; @@ -544,6 +548,46 @@ static int mock_dev_disable_feat(struct device *dev, enum iommu_dev_features fea return 0; } +static void mock_viommu_free(struct iommufd_viommu *viommu) +{ + struct mock_iommu_device *mock_iommu = + container_of(viommu->iommu_dev, struct mock_iommu_device, + iommu_dev); + + if (refcount_dec_and_test(&mock_iommu->users)) + wake_up_interruptible_all(&mock_iommu->wait); + + /* iommufd core frees mock_viommu and viommu */ +} + +static struct iommufd_viommu_ops mock_viommu_ops = { + .free = mock_viommu_free, +}; + +static struct iommufd_viommu * +mock_viommu_alloc(struct iommu_device *iommu_dev, struct iommu_domain *domain, + struct iommufd_ctx *ictx, unsigned int viommu_type) +{ + struct mock_iommu_device *mock_iommu = + container_of(iommu_dev, struct mock_iommu_device, iommu_dev); + struct mock_viommu *mock_viommu; + + if (viommu_type != IOMMU_VIOMMU_TYPE_SELFTEST) + return ERR_PTR(-EOPNOTSUPP); + + mock_viommu = iommufd_viommu_alloc(ictx, mock_viommu, core, + &mock_viommu_ops); + if (IS_ERR(mock_viommu)) + return ERR_CAST(mock_viommu); + + if (!refcount_inc_not_zero(&mock_iommu->users)) { + kfree(mock_viommu); + return ERR_PTR(-ENXIO); + } + + return &mock_viommu->core; +} + static const struct iommu_ops mock_ops = { /* * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() @@ -563,6 +607,7 @@ static const struct iommu_ops mock_ops = { .dev_enable_feat = mock_dev_enable_feat, .dev_disable_feat = mock_dev_disable_feat, .user_pasid_table = true, + .viommu_alloc = mock_viommu_alloc, .default_domain_ops = &(struct iommu_domain_ops){ .free = mock_domain_free,