From patchwork Tue Oct 22 00:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13844939 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 5D4E5D1714E for ; Tue, 22 Oct 2024 00:52:42 +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=ZbsA2m98T3pNucsZDzhx6Qsfim74k5Um+RCGSXdg/cQ=; b=CHyogcv8rU6KAHZYqm4DC/UPud aEB/Q5IiGYsxYXGT1XAfQn16gtZ5VnGhRhFNAecYodGYjXfY2YSEnZv78SHSPQsl2usNETkLzR52/ p4UdXIFgJmC74d82O+oZFicufmHaLC67LIDPbwxxXLbldYWQ28ovIPuJndmVDBgoJvobRQSKLWlID 2fv3Jfuu3dQR6x1F96/76bxRkClrYASJlz/sfBREpk1LQtU0KWtzuWix+E/71E8z0H9tElU96qaL7 j9bGcblKTmF56xBn17ZLUhCLAl9/+u0D3W7LalqVhRrsQlaF4h7NWLnCltTZJK4ArCrU51T63P8Rl YC43h9cQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t338R-000000097my-2ZJN; Tue, 22 Oct 2024 00:52:31 +0000 Received: from mail-bn1nam02on2061f.outbound.protection.outlook.com ([2a01:111:f403:2407::61f] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t32dv-000000092VE-1vtQ for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 00:21:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ew5IJxsXy/xIRB2k/m7KoUgq5bYSoapoG5DCmN2Z+oj8Acl86ExZjhI1IIanULxPh6owuHlGLbtecsAR/vYN5ZJDlqw966M0KqW+MZW6Ll1GY8ec5+7c9GqEAkmYv+07tklOJ2I9jWpd+iPRTaBddSS16AR2MhE6l4asuH7rjULX09TVzNHj3QAWw/fjvHhoyNivTG6thDbp84+nRTkGvmc2TcUell43c2cmyPVkP4vQy0z5hsZa9BqVaAuTQea6109g0e8MLm5r5QTFo3Ecp2YrurQSRlHVvbqt4fR5dA63FC4KPIto7sP+yBs+oehl5huRlM6Q3WV7IWlKSqH54w== 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=ZbsA2m98T3pNucsZDzhx6Qsfim74k5Um+RCGSXdg/cQ=; b=GNUqqBK8luiSoJgfFdD62Kr9gJBnXtSd91BERfPVWIUWarqPHOyYbXL/haBFrSRXzoylEpKePMyJPdkSNJ+mNgeZEKWa7QsJR3A2pUlPBN9BNfVViOs3rnq5h3hoMblTuRyfzSnrrFdcyPHgWavK23wCRSCeqp+Y79lK/wZtoX6kDXcqapWG0HCKgL+kv4ydT9+Glum3tD3WUi1DmUgJJZexKxRgN8q9CZTwHFee9wENBblRQzep/Afz1s/l3HhoYbJHO0r79/vnJ8K2EXH9f+1O6zuUCC/fQixqVnCt+Se0LZmBs6hFqJE6mdK19mW0DUZIGr+aXayulnWexW/Ntw== 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=ZbsA2m98T3pNucsZDzhx6Qsfim74k5Um+RCGSXdg/cQ=; b=jKEVBxopD0O8KEUbd7kHyYUI1NFe2TqH+f31+4iKqkKtq1zmqItDZZdcFKIt3AZ6MqFSvLaIRzC/IC+cRLEpIN79L6HEv3piLocQwEBObzwk6NmMb6ANO+9eP6ca1x+WYsMg36wt3ueHSmCN9xXpwSBaxjfeCTvq7xc/fJ+k/oAOLVa6p86byWj0KOqCtbc9Zns66VblMVNTRdR1pP1hgx97cjQlenwOtMr3vj7gy8MCvhY1omq0mNLtTnyZVWlj6z9p3YaaWKPHCEh72wPcOEn0lWaJRO6UKTi6LMUcfvITxvNE/dL6VITHMhQTYrccZbnK+4D2cbnQtK6oMcPBlg== Received: from CH2PR18CA0040.namprd18.prod.outlook.com (2603:10b6:610:55::20) by CH3PR12MB7740.namprd12.prod.outlook.com (2603:10b6:610:145::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.24; Tue, 22 Oct 2024 00:20:53 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:55:cafe::61) by CH2PR18CA0040.outlook.office365.com (2603:10b6:610:55::20) 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:53 +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 CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) 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:53 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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:39 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) 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:39 -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:38 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 08/14] iommufd/viommu: Add vdev_to_dev helper Date: Mon, 21 Oct 2024 17:20:17 -0700 Message-ID: <3eae567a6d674cae144c5fd36cc8eafe84d6a24d.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: CH2PEPF0000014A:EE_|CH3PR12MB7740:EE_ X-MS-Office365-Filtering-Correlation-Id: 86111bc4-b556-4e0b-dd70-08dcf22f6400 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: Ezx8r/gorELYJmsmQeX6UKtWrmceCZzGOXScV2OR5K/HkEn1ecd/Hh9w1Z+VOG845tkftr7PKIZiP+fIVRVKU3k1SsiSa+9ApfYgg/j3Thndo9msk7N5A5uhLdKkEk+rUNmkzQN5fCkT1dKqGkb49jO5WuUmhb9cVkTOuoynfP7AwoYClx7dtJYlwQ4i34BgullHbiA7boNzQi3fEvN41R4wPxUNlc+7WDd4bkvhWDd7i09P5FNxOGQM+Ue/gFJcBqR3/qoiXiuCKRmiedkmr33jZzm6lAT3h5QIOWrFD7eXdnjf0AViYFIdolCXh66nlIyYIveulB/BlenN5T46CB4XKdi/2N3JEbtwO8rflif1uV64d+NWPDpEJxnfgZrOU4W2n2/dFPoKNTTwxAiKUBLXAokTbKg37sKw0izLa+rrBfKMXoGybi9qFQaL/epWr3oNbkPsMJe9AjlbAXrvWoc6rCdmUSVVCk+GPqlwMTOo9TqjLPjd8uPTRcThrTv+JEiU45HDkVFljJ8ktqTajM3PzSi8RiSQzsxKomComQ0Q+yiw7/pCCoZrm3tKODPCaZskg3J2rJHxXEvUC6A16bI/Nj7InJrXF5AvUg/wqWOFHHAcPh7Tmno0um+CybXSpuijKdBjjOfCKTY64B4VSy9oH1IyqRcxlO3V8vK6VjEi9N9LtiDph6N2prughwuCRN1lnrWd+epPmdwyC8d8sNZqc9q+gr6GvLhJqXar1zJanaYY85D21PHgCaMjxeIWXAXJS2goLGYEjzzkJfhrcbv0quHMqj5Xh2G050V42/KI/CCQafLyEo1a35QPA2ETyGscBsX53fuQTHoq/YQ0mCChhTIPRzPTwmvjvOyh6HdptoRuByE82S8/6/0CkjRL0ormX/uMML8fMKOJBtNetPNyVl+9zxqUPID7xRXJLPov6ucrypTGfvPV9twYZ338074ldj6FuoaRqd2zdbunNFDRbh+RbLwq39bZhJKSaBNspnUoZyzotomqyEc/78I0tUNqahHKZ3c1StO50ql5tDxYZNtXzNSCqcf7rKpFqGdQlP8cM5prYmREw6x86FzOShKemnNVGHLie+gul4VSMgKpcOF0H1ZwhNXopIJeMY95IwkvJxurJ1A8M3Tnnd1uOVe7RgTSu1Sh8WzXpLJM2fZPJjd1+O16ZP5Qze2FG4ySEgsTalqA4KDBElNcAq5TB4Hqms85FUWBdhhwcM/7okujn7jsopAMqhMU8AnVRtMmxhx20mtuF0jmIklzH5yl7mzpWtv/RFpznLVcwOGNqqe9UhgOLOYIn25Y3PihujNtTQ4bS2BI7CPfs2h7blw4qRwLEkPSdx5AhEqlhnXsIt3c8xgazvoxB0dPb+k5wMDyjYqrFasSTKK0HbKHjoC5lja/anWMyN0HTe63XJ0cqw== 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)(376014)(7416014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 00:20:53.3368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86111bc4-b556-4e0b-dd70-08dcf22f6400 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: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7740 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_172059_746969_7AAFB4AD X-CRM114-Status: UNSURE ( 8.62 ) 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 moving the struct iommufd_device to the public header. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 6 ++++++ drivers/iommu/iommufd/driver.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 559f274a26ea..2f4ec6e6df21 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -204,6 +204,7 @@ 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 *vdev_to_dev(struct iommufd_vdevice *vdev); #else /* !CONFIG_IOMMUFD_DRIVER */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -211,6 +212,11 @@ _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device *vdev_to_dev(struct iommufd_vdevice *vdev) +{ + return NULL; +} #endif /* CONFIG_IOMMUFD_DRIVER */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index c0876d3f91c7..a5d750d2cfaa 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -36,3 +36,10 @@ 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 *vdev_to_dev(struct iommufd_vdevice *vdev) +{ + return vdev ? vdev->idev->dev : NULL; +} +EXPORT_SYMBOL_NS_GPL(vdev_to_dev, IOMMUFD);