From patchwork Tue Jan 7 17:10:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13929433 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 3F8DEE77197 for ; Tue, 7 Jan 2025 17:22:39 +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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=vnlSYQ+JVV0+IrYmbVeqIVDz0m dRqopGB6VnPAK2D1M77bBmzaud56+1EtPVQ6y7So4XQyYcauiQHfKrF8VrdZvent+107ZnafaQRNW YkonzHY1mwJvEbo8NsWKaS+Jfb0GvYWxPG0b37r1OkEa+4r3UtZQ9+Yy85fceH9MAPYwoDGVROwFF wdlIBIye4F+FbGolszOfeoUTu7A7aoJQuJ7T3a9HrT/xwy4Xf13dJr0mJd4Uak8JkCutvvi/OCjRn pbnLI9XSmAH5vCDuRCEZp6Skq6oeyxpsNoxwp9YZ7xdgfrmwUOUpswPgjoeGPhsxO50g4oZaJTca0 4ttcCNSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tVDHd-00000005qD5-0JWg; Tue, 07 Jan 2025 17:22:25 +0000 Received: from mail-dm3nam02on2062f.outbound.protection.outlook.com ([2a01:111:f403:2405::62f] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tVD6U-00000005mA6-2Got for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 17:10:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sI5q97Nw6d/9qHx5AjWwM3CWxyahrRxIS3iKzhhP1tAEjUCKdF3F+hEu9BeuB8uqFJgohE47R76tstB6Cef9l4R9W8kCdSa83d/pu+rnPXWjABbQbhFskRKddp3o9pdEoQee78yUimFwlDDrZCaNkpbDRUtLgJLQ9lbj7xV19+fOwbMz2z7pXw7oHRQ4WfoPSDmALxAf2+sUSPmYdkLgn3YwYoSvUd2oyNbH7saZfHtWiXNdLikGWRC7yuDLtxiqqawxnIZVv3WEypuJWTb3zEIB12olTlC465LTvCM8WQf5ebUlEicoDzt8GuHcioJjxBacPhrbnSn6OfY381R4Zg== 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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=CEC1aDYCv0q+spq+ifS+vCRy8tCAusIJtxMsGI9Dgu3v2wh8pJNSF2oPwlnt88yVqRdNisNXCbpor0hujHzWY4q4/Wy31a+HVNIEQNiA0HKBeuR6lIE9H8Cv4jEM6Vy18vU7Zvoo2w6IOX/zD6U/koCxRa0vJDnqXKQhN5vZBqEh/nE/vl3Ko3kCfGFj4LkP5aDdgWeUOiVUv1V3wfd3MYowkhLgxfL1VudWPPMq1BEAAzb9R8xfL5ungSC4s1AWRQ3zImolDJthUjjrIOM6R32/10Cs2xXfYN+yx5QAT8mjgTI/5wOoA5140OSQQOvHtIc7UBNh0ruaBKEEBYLrMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=p7fQGoJKB6gpiw7+BSeR17Aoc3kvyXkMjqb2HwDDjOQ=; b=fW1K0DuwOnwx6cZJ9CmM3aWu3wVUkBq65Ako0cHeNsHPJ50sx2P9op/IJpSXZoUXw7WZ9SQBwijG8c5S1NLbTsvRL/XIlRv1drkbDdZvC+Op0xm0Zr7/Ku3gRtA2RTzZp+oU8ZR7TTHD2jk0QGjm4WlZUiRJ4DopER/Mm1jArX0b82KSBxBi7tgXIJoYpC9LcLShCbMNiDsdjHZ8MftDnTnxnZttAi3wHhHmFe1m+lG/RgD7cwKZdN8DdL71G1HbnWY8bGh294F8hsb4nlVK1n1THoUyNCwR3+IrtV9WsPUH4xEypWHZSKMkLeqGIMG5k8xQFg0d4eocL7xJuMofDA== Received: from BN9PR03CA0418.namprd03.prod.outlook.com (2603:10b6:408:111::33) by CY8PR12MB8410.namprd12.prod.outlook.com (2603:10b6:930:6d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.18; Tue, 7 Jan 2025 17:10:48 +0000 Received: from BN3PEPF0000B06F.namprd21.prod.outlook.com (2603:10b6:408:111:cafe::a7) by BN9PR03CA0418.outlook.office365.com (2603:10b6:408:111::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.18 via Frontend Transport; Tue, 7 Jan 2025 17:10:48 +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 BN3PEPF0000B06F.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.0 via Frontend Transport; Tue, 7 Jan 2025 17:10:48 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Tue, 7 Jan 2025 09:10:31 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 7 Jan 2025 09:10:31 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 7 Jan 2025 09:10:28 -0800 From: Nicolin Chen To: , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 02/14] iommufd/fault: Add an iommufd_fault_init() helper Date: Tue, 7 Jan 2025 09:10:05 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06F:EE_|CY8PR12MB8410:EE_ X-MS-Office365-Filtering-Correlation-Id: fe4dea3b-5bde-4398-e0ac-08dd2f3e3b14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: DmBnyKL3ipYDBapsBXyQDOX6tbg7nbqyLJIR45A1GMYky10l4I1j4/11cyR3XDbOhtUWAMPFiTlwcO0Q+YdcwuDJVpHXsLkYONCHNxeQ6SLB7nwd5WQ2NPgK0fANZsaGvBIUzGtMF6vbya03HGlfcqHD7mpmVwsvZFyvmMwCBqZGAu7hWyWziFYIDB8jIjWGQGO90/UD00NifMXxVbEmWVfxYf3pHoVE8BoVrZKkGDd+g2d6Sy0Q679JfOee4HbWYmv0SDYOk0ZmK2NAUGbDvpsBhubU3qq6JQ1it7DoxvyXe4xmWBD2rORLRSo9qbKSf5IyF3CO8YLkQn8pKFQdILk0UIHyQE3FNMjpuDkEpkN4GmQ0H1Bqt+m7egtZPPSrqA/zJqEG79noWi8vvBpGysTHz+/ea3SAqRWLzlm2kl7Uh7n+OSa5xd3GprYCEw3iu5lIviw/vF6qL1JoENQLrQjZWqMC7yl1mprl1yu/ueavTBFUROkD3g0gncZ8g2PGwVARewOITU+AR2ZXTKfH2iOZHoazuP3VIz5hOzOqqgJtq5eCadUb2SkdkgGRBKhAUM978EIYovOTYKrDiAkKcP9Ej9X55FGP60TkWep+4zmbVRoEKvLSuoE+2lZqaxtIyZXuejerPkdCMlcZuBOz9zzotiVzluwHI/g3uTF4JBprb5CBuBQXvKpLY5aojlCQ/1b4ZST+Zi/9EgwzWTAkF+xICpjIpM+JURmMLy4khb8fw9p9xv9y0tovlBNiMnHmXVfxUXvbSfCXbwRUmfuxQ21MgLYrKu89ifYxSZEQzOWjfwNS9vIXBxI8i3WoSQXXCCY7tJSueXBvTyGCH/1vHHtbvgI45eXf1A5j6+qsNvLXVawP4Pq0KzDdTIxyVpJiPq4OOrYF3YxITHQlb2j9BXZ+lCoc2K+v+fSfogbug19q+3oKLVQUd3M73S/oeecJ7W0CaCfpUKiUiM+7kw4G/m9shSqHhnakferzu80RtJnD+WyPt3p9V20TSZavRuKH6hmzeAhUEtbrDi9HX0qHKeFEf9KVN+Xy6xYRA7w/zNnKxZwL+cG3isxVFz8acBfwnS4bZIOfMUlJyXgumVxa/ft1NxvyBLZ6CwUvBSkJHqjqoKho6LVAEcanLigdM/oLq+9ulSg+4pBeOTaI2/ZfcrWGIKwjTwVwqO4bKSyZaqxA4alxeMtJuzUqWA5r9k9AnoD4JaY0yKodR+eYr2US9rieRFlIgs6QT+xrbYcbOHoUndNROg2JKhl4p+pvqBDaCvXzdImnX8irscqQw9XYjaORQxmZG2GCkmKcgC3zOLHSUrhQHYWHbLuD09qttO5ryLizrs7ARt2T6FURcGDuVR8zbZePS1xnQG1FJ3O+3eN6v5Fytq07HvUBH8aRgcA16afMpcNG4gqMW2wfvIA2fh+z733bK8PzSrUOZfTasyBZ/OG17c1XTKGVahJyjbldvjnnDUeMT8GOpfMbCMlN+HNsQzjRUZQvsUxBAr04U4w= 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)(36860700013)(376014)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 17:10:48.0148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe4dea3b-5bde-4398-e0ac-08dd2f3e3b14 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: BN3PEPF0000B06F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8410 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_091054_582036_E5BC69AD X-CRM114-Status: GOOD ( 15.38 ) 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 The infrastructure of a fault object will be shared with a new vEVENTQ object in a following change. Add a helper for a vEVENTQ allocator to call it too. Reorder the iommufd_ctx_get and refcount_inc, to keep them symmetrical with the iommufd_fault_fops_release(). Since the new vEVENTQ doesn't need "response", leave the xa_init_flags in its original location. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/fault.c | 48 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 1fe804e28a86..1d1095fc8224 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -367,11 +367,35 @@ static const struct file_operations iommufd_fault_fops = { .release = iommufd_fault_fops_release, }; +static int iommufd_fault_init(struct iommufd_fault *fault, char *name, + struct iommufd_ctx *ictx) +{ + struct file *filep; + int fdno; + + mutex_init(&fault->mutex); + INIT_LIST_HEAD(&fault->deliver); + init_waitqueue_head(&fault->wait_queue); + + filep = anon_inode_getfile(name, &iommufd_fault_fops, fault, O_RDWR); + if (IS_ERR(filep)) + return PTR_ERR(filep); + + fault->ictx = ictx; + iommufd_ctx_get(fault->ictx); + fault->filep = filep; + refcount_inc(&fault->obj.users); + + fdno = get_unused_fd_flags(O_CLOEXEC); + if (fdno < 0) + fput(filep); + return fdno; +} + int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) { struct iommu_fault_alloc *cmd = ucmd->cmd; struct iommufd_fault *fault; - struct file *filep; int fdno; int rc; @@ -382,27 +406,12 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) if (IS_ERR(fault)) return PTR_ERR(fault); - fault->ictx = ucmd->ictx; - INIT_LIST_HEAD(&fault->deliver); xa_init_flags(&fault->response, XA_FLAGS_ALLOC1); - mutex_init(&fault->mutex); - init_waitqueue_head(&fault->wait_queue); - - filep = anon_inode_getfile("[iommufd-pgfault]", &iommufd_fault_fops, - fault, O_RDWR); - if (IS_ERR(filep)) { - rc = PTR_ERR(filep); - goto out_abort; - } - refcount_inc(&fault->obj.users); - iommufd_ctx_get(fault->ictx); - fault->filep = filep; - - fdno = get_unused_fd_flags(O_CLOEXEC); + fdno = iommufd_fault_init(fault, "[iommufd-pgfault]", ucmd->ictx); if (fdno < 0) { rc = fdno; - goto out_fput; + goto out_abort; } cmd->out_fault_id = fault->obj.id; @@ -418,8 +427,7 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) return 0; out_put_fdno: put_unused_fd(fdno); -out_fput: - fput(filep); + fput(fault->filep); out_abort: iommufd_object_abort_and_destroy(ucmd->ictx, &fault->obj);