From patchwork Tue Oct 22 00:19:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13844925 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 1532DD1714F for ; Tue, 22 Oct 2024 00:37:36 +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=ppccpeyy1L2Rk3cWFAMsyZahdwqz/tSFTOoVMVOcQpI=; b=mP3GRYF36d8iHyjHXIri2OELdY M8pTFzzQr+TlTdinP4AFGTKmkQcVYsji5Hc/pGz9dbPD8w9DPc0v/30twdGHmdlVCGoK4XtLv6y4t Da1VGAwU71sdxKiKq4cTbKfbVVOxX3poOCzI3tDqqoe3f8M+plIRKeWahodTSOOQ9VPCEUFTOP4N/ uWJ4p38Ao1t/GuJ3IF9HVvIdKN1rOM5+PPi9YtkA4U7pvhoMQrroSYyt3Mq4xRKHAQUfqd6yLSYJt XMdQ0bzXzRis8i4//MIE8cfi7ihxvL6VvotZpVqRphPzsCG5eRptfpmk8RJD6WynEKR057eLFEkRv 4rktyeUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t32tq-000000095qv-1UNM; Tue, 22 Oct 2024 00:37:26 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t32dY-000000092Hj-3kQk for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 00:20:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EvaEpxUGyqivCzfRqHTEj6evwE+u1IY4F+woT0HvwwFYavumRAig6LM4R5RbIMZOuUFcawq36fnSIQcTsMmLqRcAYQbb1bhkPoOkwAJyxFqakqW/6NZuD4SqBFSdaXEibmT4TOfrS1b7mDgQTUQtKx58KckM/+aPXyP9PuV/HJVT6PZdkzAy2SkpMkwVf6rEvGD81alSCj+UmBOyuhMGJnyofpMRIKj+Jzi6WLGKYBjAm3Uze7Y9w6l4GoBRk1veREyP6qfCNBXx0TVRA28HZ1B7f0AMaiTD/AmdSlpPyc7nUY2Zxl3MvsnFLB19C6Gat6SZjC8F+mSBjcJ2BDxSgQ== 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=ppccpeyy1L2Rk3cWFAMsyZahdwqz/tSFTOoVMVOcQpI=; b=ot/5/DIiC5T2gg9w8YYubvwvEcjgDLcCRK7Svo2VwZDNU8ItFanG4PjXsQ2EhcNZ9vpwsb4OXyHwmE+ZMSO9Hes3/MbsEXXJ40QZQpc1nMWq+oDKzwG+/UKxpcomOiMxPV5lbHeYp33F9X+oJEwDnvGvybSJsv8N9VOjJELhWoXn1axuGZWM9Rlk08urVNm2N91qC0Ert4WlZIunbijcLCmqW4DJ03R4tUzLK2Jh/cLDJwlPwEtuBPPjYpvNAlcE4InaLiYKMAg9m7pPKlQi1gkZR/kp65aXGQ4K9cx6N/qpQ6AEwpISTOj4/BpQsd5YVFJqxRXDb6Tm5wd6Uar0hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=ppccpeyy1L2Rk3cWFAMsyZahdwqz/tSFTOoVMVOcQpI=; b=TUQ7ttPM3JNVX1sHLfBM20kpeENvTsjPpDAD2Uray30YVlZ+/leB1+AgyQHkJ95VBrlePvboOKobnHL7CCtbK210ogCrwat4yekDTT75GLQC93rKlTpMUoOSpK2gvC9GyUSTzSAbiFn0a34TYB7omor/ZM1nzjKqg8+iZ8du4CkVYhNx2E6vBXFY+BCbCsoEts+mgYBPsLj/Cd63J0FgTc9FrWIxfwYlo1zgNgzikG6ukwNLuGZ2xZ0RRpWQtY9HJNpeI0ugFtuKFDj6MLBZMwPQQhCzz573K6aFJeL2G61H7dJNy60SURXErAcHK1KZa999rmO6NUkA6sxPca5+4Q== Received: from BL1P222CA0002.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::7) by IA0PR12MB8713.namprd12.prod.outlook.com (2603:10b6:208:48e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Tue, 22 Oct 2024 00:20:30 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:2c7:cafe::58) by BL1P222CA0002.outlook.office365.com (2603:10b6:208:2c7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Tue, 22 Oct 2024 00:20:30 +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 BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) 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:29 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Mon, 21 Oct 2024 17:20:11 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Mon, 21 Oct 2024 17:20:11 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 21 Oct 2024 17:20:10 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 08/11] iommufd/selftest: Add IOMMU_VIOMMU_TYPE_SELFTEST Date: Mon, 21 Oct 2024 17:19:30 -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: BL02EPF0001A101:EE_|IA0PR12MB8713:EE_ X-MS-Office365-Filtering-Correlation-Id: b4b90187-1ce9-4e88-92ea-08dcf22f560c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|7416014|82310400026; X-Microsoft-Antispam-Message-Info: P/QA11pKMOGDu9e5cOekM7XMbFc2f9tVJSj3MnTDwjJdIeJf6UpIfrJX3Syv1DUS/2gLd2Cox0Vahka4xXEqpu0lI/Laqi6sEC+0S0B/i2pd+bfNVJNfL9JlRbJTHu/NRcNUKTPMBlLAIsZqL3C3XaI2A4Or77XdzzKXjvpMUV+0JHNis+1zhsUgpItS5jIXVeF4pBvlKygCdmYVnYJlgLjuHJAM0IaskH1qOaXtjnKqc7siftKbsU56Xz20s0YPdI/Y81eK3fOzepuBfqxmwkrI1cLQF31qW9spPxQR71mBygl+AXl9USBU5nsUp2ZB7Py3AaH+hr7RMGqHdQz3JrPm5MWxQA03JwrXZmCBDRAoXc+OyZZkYnNCq3kztkA/sOFQEOIObWEkecH7D4laTqa8pGY56YEh9HP9Mi8gosMbX+rlQ5l/mK0ZZFgpwtYGtcGify4XhFpf8dko0pZ0V3Sf1jNGrmNO3IKsyfqW3S2aZPx8dGegPDNPJ5v1qBwab/yvmaQSdefUyokHoLCp4Wd4+fF61+0TZ4258pzFBBsGVfqToApAKJjvC1CHi0dvxqGD+7WU3XRlYcWQQJ/lgSjwmpn5sZw9qSqFB3wsPwpiz40sPZISF5H4Ac9rDgI6bsiM8nIt3tSI1jamvTQ9pcIrWGf4mzRb6wek2Ci/p9LPA/ZWEXmcf4dcpz7LYIjEcnD/GGkKny0NxFmQkRpgrDsTT67MzllsEHoWPtVERm+w/Ifb7rrezJ5vHKTuAHrJcJuW1CMk5Yn7TBdlxeronRuK98IGDMqk1Nza5kE2F7ihfXi8LyEqFb71GNwGPxN6DAZmIBqiVpCY0qQSm8EsoVL7J6XDhEtaqPCKinrSaUSJb22Y+LJQviQVWAvrowze+W5juOcvaEli6+rataEMk9gBcmflSylEZO6uCp/Vn/K1mwI3MpYHavGaf+0Oz1jTIhZohW0pQKxdum/snSTTfnWWRCyqAZzZcIQym4m7zSGtgbIvkvXZdZIWRd0irdKLp2ZmqsdNnwsNrvmzSn+mEru176m2ZjBxe2qGRkY1NuZ6OJ3tUc4BPBznIqifZKedbaNrWEq0TFXnIiJUcBQAlff0mMUwBHTumrl6wknUlQavLe9FSmV0O1XHsH06/MdcftxYyk938O4UGPUefO0lWBNHiZaD/CiUiiQUAg5vspg+UUTLzEJmqQP97nL7lvtKwkkX9oRaZkVhQ8S0wtejfpLIEtkiD15C6eermIVrlFZjwIiBv2W0nm1TzHuV0NNvZPdBSiLNiqBxOFf43LZIPk9Ohs2gwsV39fY2TZPciMG6c4lGi1ETX4GeAfkyx8G/HtOhmLYGFrcqXPLZedFPIGSLVoVt/nMdaL2nxBFA4MgdoTS5U30vimKjlpvQYBYNn9Pfm4OCEI4enEFyOVlAoQ== 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)(376014)(36860700013)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 00:20:29.8629 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4b90187-1ce9-4e88-92ea-08dcf22f560c 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8713 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_172037_089948_56940B4C X-CRM114-Status: GOOD ( 12.57 ) 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 | 41 ++++++++++++++++++++++++++++ 2 files changed, 43 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 dbd2a78c1074..04dd95fe24ca 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, }; @@ -543,6 +547,42 @@ 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)) + complete(&mock_iommu->complete); + + /* 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 device *dev, + struct iommu_domain *domain, + struct iommufd_ctx *ictx, + unsigned int viommu_type) +{ + struct mock_iommu_device *mock_iommu = + iommu_get_iommu_dev(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); + + refcount_inc(&mock_iommu->users); + return &mock_viommu->core; +} + static const struct iommu_ops mock_ops = { /* * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() @@ -562,6 +602,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,