From patchwork Tue Oct 22 00:19:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13844914 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 DC398D1714C for ; Tue, 22 Oct 2024 00:27:00 +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=PCiiwbPRF3tMxjrTpTPyUaddxelaA0bQsArIpIV1apE=; b=C2G9l3r+9oKMpwi0qVWZIPgpkH dzexyL+bJoZo9DDdHFmj5mJVtlJxoG+vWtY3GytxbxJud74KwDb6yfV260j6BCnmM8eSODhCAP6a7 BYUIWSoqV/2idVxUykGgJfagF8A7nmnhTvheMl93tw0hVNs4nOtLs7E1qWZ4fkn+QYpyfvZ8BV7m6 I/gC6d13/BY99kv/TK3av9HEUR+L3Q4WXlqyshLmtri1d8HkDX77HrQMf19WCVOqcCOhH6Z8KxWCd oDe12hsnJOFMS374QFwPlksg6xAld9iILnMS5S5llQoiGculpL/890YSZuk8Ob4G2QUqo/cVyq7qK wTx+W8zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t32jZ-000000093xS-3FKh; Tue, 22 Oct 2024 00:26:49 +0000 Received: from mail-mw2nam12on20607.outbound.protection.outlook.com ([2a01:111:f403:200a::607] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t32dQ-000000092CG-2txO for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 00:20:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q4kKEg5Tun4Xm3BYB+spsAE47xku5UWF2I7pXJe+h48UURVIdlBuiU+kjzKxkMwYiLv+ohgMxCFfDjGz6hA//p0YgdjIy2BBcvRbzMslYYjteb9/zD+09CH7sl644RXEqtVGtx9+gUqt4WUkN3EsK05fAu3R0pHumGi9I9yJQzx6IqDlfqla3Att3Z2jcmTdbIpBDNIKB9YERRzv+KTdnv6SYUbqG/uxj3I2jqu90cBekb5u52qO80l4nCVLdpSuIF012buBmvQ6z1OllBkEaP1orsdDBVLVEWzRCEQESQNOX3QHoPvPYiMzpqHXy6HDlIPf61mOzEtS1VsA/uZiLw== 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=PCiiwbPRF3tMxjrTpTPyUaddxelaA0bQsArIpIV1apE=; b=H7ke4q8GEj6bEW2w2djdXNipXLKXWF31y4aJmaDiE4p5mKJnFe4GtMcYM7kyXwNhZt4pmIpkapyNfi4I30EYJpDd7OU7nPJqmZeVcvRpA4gj7JmjxONnAR1V4+4RzhivT711bn/w+2gHBefcR5LRVoqUr1lC/EBHu2nny6wCgyRZsj+3KmvgPFoCUKRYiEKsMx3SHvDOCfg6hXejKk+u/OD14jcKXHNTnba/gqUbcP9vwLM089r8ly7tK8EgbI94BWDSpV1vWQZUtH6lRutV0brZdHYMm+BRq/WX167ea4a34GAaEggMPGW+WXruDSURtzZhy82bQGC2Ib710fRx4w== 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=PCiiwbPRF3tMxjrTpTPyUaddxelaA0bQsArIpIV1apE=; b=Uzd/XGtH/nQAbenKntjv2ymsZxQCj7sxrjw0Ly4cDmBzXMLZiH6P7vucQC8leT4rbYEJWf3dkm2RniFbrbzQtm8s3nE8GQpgmu45On2DjHTExtsjJr+mPwAyShhVESCzIn8RTYpQhC+zDSgCQRpLS1wRHSh8p++ZiK96XZSRgV5LBaZtpUeyTAFq56NZIhfx1hl0HAfT6GS6N0RpVjzQc4NI8zQY2wTR/DszHqYFWnGvryLKgdR8dVf/ek0k1c6loP63/sVlgzjHHsYOEQuFyBxoJwdFPCxBeL8/0BbfX9ZpEjgttc7f89XYXKuvpKnqdbeXeqIgN64HLudy6VGKHg== Received: from BN0PR08CA0020.namprd08.prod.outlook.com (2603:10b6:408:142::8) by IA1PR12MB8262.namprd12.prod.outlook.com (2603:10b6:208:3f6::14) 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:21 +0000 Received: from BN1PEPF00005FFC.namprd05.prod.outlook.com (2603:10b6:408:142:cafe::50) by BN0PR08CA0020.outlook.office365.com (2603:10b6:408:142::8) 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:21 +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 BN1PEPF00005FFC.mail.protection.outlook.com (10.167.243.228) 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:21 +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; Mon, 21 Oct 2024 17:20:04 -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:04 -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:03 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 03/11] iommufd: Add iommufd_verify_unfinalized_object Date: Mon, 21 Oct 2024 17:19:25 -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: BN1PEPF00005FFC:EE_|IA1PR12MB8262:EE_ X-MS-Office365-Filtering-Correlation-Id: 66f47bef-1b55-49b3-6579-08dcf22f50db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014; X-Microsoft-Antispam-Message-Info: Law1FOcW+UEbGewWY7M++AYEvwXP4NO19sJoXoSJDM80kygPi8y7k14j3ckkN0las2JcBl/jSQZtn+OhwrnqzRn206PJ0oNAwUv+FxG9rAxraGxZAWyUEYpsB/3cE9G5OCwN+fBUJHLiWsNIx5n3DsxVT+TxEXu0mvQdsxhUdD+wLTahGuZhLtcXUjA5gP8apzr8EbTeVhzz0LUYsWcf1JxRJVZeCIlvEEgcuNk3U8DD/hN2RZEBS3ZxN018vY6HcifKZCsyoFIdMbxhpyR/iCzKHbySy/eZ+r+/WLmKbC0LBjtmsVtaTVr4Ul3WQGrfX0NOP3gd4m0FoOlUbGcCVNKduwFxN9xVOMsrStSp4S1drLjpvkeOBrOlLS67+cFDCx/hQ4obJHdQsDzWGqx9u8CrBDv+Dz4CQGPalcAhDkqAQ+QbELyK8BgFQw//1rfm/Asuk5HArX0GW1qKlGUbMyMG3Abl65082kEgZwhe7/XNqM7QyyDAS2iIO4IpC8Tb2Ginjydn87VO6iwJ5F2tZmSE3m0nYe8A5jmbovE6nkckk9ebXhTtkq/OA+UJsJufXzV/AXb41rUE27YqO2s9qzFybVqkuRz0+fRUdNOF6xflVcLSbzCBDGRh2f69/VeH4mwCei9R2WKrlkT0wv8k/44jHcktP2cyxwXYrMpmF9T0WTHwx7fP0Erx2rKXttEIGGCno/pF1l/MS/ab2egZ/3m1HfgRVFTAs8cnLrQB3mLW535wcJyYl0nlibbcEjs7/trDnZ61hndvZg5FZOLraF0x75s5i4LvbC0HyYyk3JzbBXp1lu02ebxGpf5G+2HPx286aPr6Bs5uSn7d8NT5R6pzQ0TNw9CFeXzIpKdxVHmQq2XbaREsvkUNUrmZ72lFWVF2v7N1VGZZo0bw6lIZ2NVxpNKYCkYYtLbFd0NfIOrvB27/+WGd0olSYWyn3c5SfuUpGGNaHq8J8VFXzp8g5Fj1zq7mmYGcU2um6F+C6H2megjNgsdf6GMjY1TTN9+w+McMSR8nWsIrBZULcqTNJuUDp4WFRk+aNt5afwTl1gEO7rJHo/pYPZQtBFCM7qIXZ7dj72Mh39+a6b+N6fNIdtOiowot4Olo31U/aEXFJoIiV0ps9e4vmp6DskMcCS8/7O04ukHLqpqaikYPGJiRlUzgA23SQCIPLch9S6BAfO04KTRnYfglw2WOXnaomsHafvvVTSmvBi+YRl7ncpIzuHZ2iTMXDo/YgvPJbVJbEsK0v1hNwkdCfq98glxOuIVH/VWetyVQKKVsVwD6aPXQDmVZc5nQK/tGDdTUYgEa0j3tahPXIy95jlUJXx2mDCa8REJT+gxOY+XYSiwjTGPAwcUrPjIY8v9ruFVAn4xdPmbXteojo6A6bB5OGQcRKOG9hiGeOsKC5uSdPhhDcpln4w== 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)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 00:20:21.1676 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66f47bef-1b55-49b3-6579-08dcf22f50db 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: BN1PEPF00005FFC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8262 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_172028_751819_EE677CA4 X-CRM114-Status: GOOD ( 12.69 ) 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 To support driver-allocated vIOMMU objects, it's suggested to call the allocator helper in IOMMU dirvers. However, there is no guarantee that drivers will all use it and allocate objects properly. Add a helper for iommufd core to verify if an unfinalized object is at least reserved in the ictx. Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/iommufd_private.h | 3 +++ drivers/iommu/iommufd/main.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 5bd41257f2ef..d53c1ca75532 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -152,6 +152,9 @@ static inline void iommufd_put_object(struct iommufd_ctx *ictx, wake_up_interruptible_all(&ictx->destroy_wait); } +int iommufd_verify_unfinalized_object(struct iommufd_ctx *ictx, + struct iommufd_object *to_verify); + void iommufd_object_abort(struct iommufd_ctx *ictx, struct iommufd_object *obj); void iommufd_object_abort_and_destroy(struct iommufd_ctx *ictx, struct iommufd_object *obj); diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 92bd075108e5..e244fed1b7ab 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -89,6 +89,26 @@ struct iommufd_object *iommufd_get_object(struct iommufd_ctx *ictx, u32 id, return obj; } +int iommufd_verify_unfinalized_object(struct iommufd_ctx *ictx, + struct iommufd_object *to_verify) +{ + XA_STATE(xas, &ictx->objects, 0); + struct iommufd_object *obj; + int rc = 0; + + if (!to_verify || !to_verify->id) + return -EINVAL; + xas.xa_index = to_verify->id; + + xa_lock(&ictx->objects); + obj = xas_load(&xas); + /* Being an unfinalized object, the loaded obj is a reserved space */ + if (obj != XA_ZERO_ENTRY) + rc = -ENOENT; + xa_unlock(&ictx->objects); + return rc; +} + static int iommufd_object_dec_wait_shortterm(struct iommufd_ctx *ictx, struct iommufd_object *to_destroy) {