From patchwork Fri Oct 25 23:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13851983 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 21488D149F8 for ; Sat, 26 Oct 2024 00:22:31 +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=lvlBSYEvWCG0hAnIUYc10bbXD8NGghhkWHcflXNXcto=; b=SIddBsUrtmHwoiwYcUfbzyWTgg pOxqLxCW0AHDhjc61AXnx89MPD2sf1lrctu61fQhXCiFpTBCqg5GEzYVSymU6REK9pK/EqLeh9YV2 atYRVtiAcs3AiTCOzPk0/jGOcci4mFkifPONdXFx1od2yEqCcsr/eAhT27rQNx6xkMdLmb9/HAORj 6NTu4ssLghnVmOJgrMvAHTOaf+Gud2x6eLPFfM9Xu/RHhdJzj3w3/qpSNqszR2iCUPXIFYPgQm73T Jay67QuwUu1SPTQFk9WbzMnww78TsWt5ReCis872Ayl1e3DyBhOSMoN36u9Ckr2JLoAcu463S7dcj 5xnd1YAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4UZR-00000005djA-2hhi; Sat, 26 Oct 2024 00:22:21 +0000 Received: from mail-bn8nam11on20610.outbound.protection.outlook.com ([2a01:111:f403:2414::610] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4U5G-00000005Z7n-3MDC for linux-arm-kernel@lists.infradead.org; Fri, 25 Oct 2024 23:51:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EP/MbRAMz5EG4tc5IRYiyITbZlDEaDLjwSAhsFChlvxWr28GLVOGwFMghztZLfMBJcqfohgJdvRVPFhog9hYwE6b/SlUzQEnXNoywZFiamiff7xH2PXI0Gl/5BEWSgzIeKy13Kw9I6wun2F8HUHthq83GEsfz2kcgebRduFnfjQpxsiMkMtKw3eu+4XZLCqEJRqMpffT6XgXuSpmFQU11tljeeQMQtfuhW/B4qEuaW7aRjSDkcK7441PKm+bCgnly9DNznyonjIfiajqd0Ok57wk/RP5kbnW2mDtbdybREPiUS43M8NsbU4WoxgyTXR8/kC2IZa6QOih2a6bJUPAcA== 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=lvlBSYEvWCG0hAnIUYc10bbXD8NGghhkWHcflXNXcto=; b=QH+nWpHH6b9GImCh9EUE68IJ/Q7lxGG4J1GlB5CpubKbntdAjG80RWOdD4ntAx1vaqzopU9NeJGCI8nrqyelj5fp1nMD6XlQuG1/yHgW70KPAs5RjCh2zN3MOKuWkcKUbUK4Wzq+1wCs4QcU0srtj9PtVPJGBTB/5Seiv2RqYyDNI9FJzuBMTNlRBVbHTVkVTAvBMIAV3b5ODZGIE2CEcuHRrQTVqi5EBAv5TFgL7bwbXVLylteijcuWWEnaf/ZkzmvDqs+0ml7Cdtn3kn0IBQ0METKazbe1nZiuymAY2c32mfvDn6ji+B1iy7WANyhp+G44iLOJdupCcfX/NGfipQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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=lvlBSYEvWCG0hAnIUYc10bbXD8NGghhkWHcflXNXcto=; b=E4eUZsv51JungpLM2GZZztmIb9hCivFZwCdp+iK/9SSPSNjA3gSUiraLNsi/532FieYehYOTGO+DeYdHJwcuyuveLEGHLlMwJhlbkGL6Jxu3LjDRmm7+nqKYUBgQVeqBLoqDAADEbz5sbW5vjT9NeLLLK3P5eV4R6467gMYwKZ4VRF14y3Mg19ZAaV7UkZMGnYQKjn1dI8FqKW1LtkxM0qygDP+/XNPAbvNvwlNPfN5xfEIQwfk3TB0g6AoYkntFSA/MYYkwrjyW5OvUwMSlF0BBMhIywoG3RwC/N0JWm8/ebpJZpxu+lUsZ1vVCf6YOOebGBeeftzDCHLMIRGUzdg== Received: from BYAPR05CA0100.namprd05.prod.outlook.com (2603:10b6:a03:e0::41) by CY8PR12MB7731.namprd12.prod.outlook.com (2603:10b6:930:86::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.19; Fri, 25 Oct 2024 23:51:05 +0000 Received: from SJ1PEPF000023CF.namprd02.prod.outlook.com (2603:10b6:a03:e0:cafe::38) by BYAPR05CA0100.outlook.office365.com (2603:10b6:a03:e0::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.8 via Frontend Transport; Fri, 25 Oct 2024 23:51:05 +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 SJ1PEPF000023CF.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Fri, 25 Oct 2024 23:51:05 +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; Fri, 25 Oct 2024 16:50:57 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) 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; Fri, 25 Oct 2024 16:50:57 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 25 Oct 2024 16:50:56 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 07/13] iommufd/viommu: Add iommufd_viommu_find_dev helper Date: Fri, 25 Oct 2024 16:50:36 -0700 Message-ID: <384f7b4333a1f75da09e390902b8f82be21a0dd3.1729897278.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: SJ1PEPF000023CF:EE_|CY8PR12MB7731:EE_ X-MS-Office365-Filtering-Correlation-Id: 006ed9b0-b188-461b-0c50-08dcf54fe412 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: PzRHX/1AQIgXyKxvdKk4NPzmvDwk5JqMazn8tAaXnNEgTY9tikJf80s4bo4XVC1m6BeNJQkFmV+AZRu0RTZZGoX9l9WWAc3/5pE9iCBH1Xpkv+3rJePaVybo3nRNayvkn1FwIZxgEqpqlkK5iJDKpTqfA4501bm47pxQnQqSYoleaDSaVa16WzNaN+m0geQmpppJHVOqvXHTnau0mMoJjs74scbRqsczYl7P6uvzf6GFAYN/dWNqfxO5DDod2yqxFXhREYmZcu+PADeKw3eA+Nn2DdzXurobcyeGbjs+0QKxmDNlB5cjo2d5ZjD+3f/byUfHlkKxNVO+ymaoQSZIoxN7n1JeVp3CKEnaVGCdb451Adkfc56X50EoeSvio7019fi7iZeujB8XnH3l0tUQSNzD3qY/cwtuo9PsPLt0FsrDHuR6/PnyWv1EQQQcKvfTuU4S63unQyH8UpqQyAnFTS8cNfbyrIbf6ep0sGX2pWc7bSIB5nUNMsX5td3Nw3XkGhCFXxkrJxLyJSMXurG5wTLePJ75emskMWBrb6XwrnwW1+vMMZBhC0F4B9Enn1pwa3vf93pT36WK9yyGvh9H6ciRf6/iaIOUE8RBteQTlUQfRWC3UDS7RatPM5uS9Rr5M0qrqMlPgBp/fstU+x38XGyDnd1qNysHe8JVfL7xOnEI9dFb00poTnRenoxkAWFD/BZJ7gCEqF5d42DJQvH8ju2jIgdGNp28m6BE3WZggYWD+vm1R7qW+DrqBsEJjUv6tTzvvjS3XrDknPubuUdTxaWtTbTiHteU5EvG21cY43jYDm9XSWiFlGCbD4kSyKUh+14P2p8AAOWTb2bD+W9zxC4Q8hBLCuvckj120vzJqaUX1jJ+Vk5hodt2++KbYMmASjwYWbWkkU9WA1P8sp2uHp3Hyo5d5BJAdZfC+s/k9NNC9khTLIl5LxDYVdoXvQdCw2Qsbt2micKNa6C3ET5FScRwSaHxvV04/Uc+M3HmqtgVUJqnEnGb5Ak3AaTG8Tah73dLgOF/aG121a9Xr4K1bM+2Lxf/kZ8mAPcKOKh/+hfvRuEwYm8PO53mAdJSc0nGzhh/WRh8cm2BKXIhroaPMJL9TPrxPfTQLLI81hFbmF3+Qnn41wQ4wEx9Krss9XOcmOUba08PXXTUOIlr7c2PLqxiqyOkBAN/cqRGxRmLaq55NCBOojOWFsOjsqHkLyHVs9HmsJ8tzShkxkUaR7V+SzYKTmbSzQ+1JWNmFw33G6ND+YKleJUBrFdgKyKeB0ZNpkEHYhu6t5NaHBzgfI8qEvvWZvfVHTCmMZPVDdeJIWhRfpgKiraQ8u0vM9QjUfTbDx9oh4dYOTNevALzqS/CVCBoNLvtwTIejr4kr+KDYQJdHRFQsWEPOi2KdxCg1nluRjcgMsPyI7P7vF8EL5hUdw== 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)(36860700013)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 23:51:05.7064 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 006ed9b0-b188-461b-0c50-08dcf54fe412 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: SJ1PEPF000023CF.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7731 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_165110_850104_E9F2962A X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. 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 This avoids a bigger trouble of exposing struct iommufd_device and struct iommufd_vdevice in the public header. Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- include/linux/iommufd.h | 8 ++++++++ drivers/iommu/iommufd/driver.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 0287a6d00192..dc174d02132b 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -184,6 +184,8 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, enum iommufd_object_type type); +struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, + unsigned long vdev_id); #else /* !CONFIG_IOMMUFD_DRIVER */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -191,6 +193,12 @@ _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device * +iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id) +{ + return NULL; +} #endif /* CONFIG_IOMMUFD_DRIVER */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index c0876d3f91c7..3604443f82a1 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -36,3 +36,16 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, return ERR_PTR(rc); } EXPORT_SYMBOL_NS_GPL(_iommufd_object_alloc, IOMMUFD); + +/* Caller should xa_lock(&viommu->vdevs) to protect the return value */ +struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, + unsigned long vdev_id) +{ + struct iommufd_vdevice *vdev; + + lockdep_is_held(&viommu->vdevs.xa_lock); + + vdev = xa_load(&viommu->vdevs, vdev_id); + return vdev ? vdev->idev->dev : NULL; +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_find_dev, IOMMUFD);