From patchwork Tue Dec 3 22:10:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13893035 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 ECDF1E74AFF for ; Tue, 3 Dec 2024 22:13:25 +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=Dz+PkQd0y9lcDfj6LfaI68k2iko+rUkTXwu93/VdqjE=; b=cQGyPVXPLp/t0A0U8YlFriAN7v qfv2Kqi4TRD7NMHytrC+qTI/1L8GOBbdFVDb1Um3+YxHFXfWVSxPPT4Rv7IMmvfymhu0CeIt7RGDN cRs6N+V5ylPGRjiZUo+8gS5QFD4vgMBXOkOaG0JJFKllcaVtHeUBG6xCXM/2oyCFdHXcFSaWMNs2i WWlPeFwXDc1gJ9TwJ6or1LofzmbulcXVMXG5xMmtJnh7/QnzmSj9t0b8CizcdFLKhLGLwuvpQxe6Z FmhwQx+i1NAGRZkXRPvnjcVzjQu1GY1LbMaw/xqsarA4Rd9WzNmSNDBCvUlQSHR4rROZ+Bcw1ZIfD SMe5cvyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIb8q-0000000AsTS-2OLj; Tue, 03 Dec 2024 22:13:12 +0000 Received: from mail-dm6nam04on20614.outbound.protection.outlook.com ([2a01:111:f403:2409::614] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIb6n-0000000ArpW-3vZW for linux-arm-kernel@lists.infradead.org; Tue, 03 Dec 2024 22:11:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vADHkl/sHsIxsZ62wD3JFsOk/zh3TiCO/1T9gkllYG3es7501btt4D1d6scoh4A2+ugdKdtOfMtSQvF+jibtPvke58XTDng87YDfkREVRS7WHh0Ou/UDUSkIRT/4oywPixfmzWzWCVhSSn43nk+wbnjrAkb2aJ/q5mOF95NYtWtZm+UrOPbrfsbGxjZ1+xzFsRFPREzHQu7sklbRetlCkolIFp7/n3LnwM4UOOwc2Gt/YlHpj3p7yas/QYKRtdgSgjZWFCx2i5slxgYYpf4r0WV6mclNWnwQrjAPHpsHsXaXX3Ob5JMR13yCyS9+eFSA5DpPFZ7cn6kRzVSJXuXaDg== 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=Dz+PkQd0y9lcDfj6LfaI68k2iko+rUkTXwu93/VdqjE=; b=Po8YjdTUUa0C3CHJoaAB7JLRfy0jSpGm5bXdU7sn/158imjsxvtYcbA/lpaa8yO24BM2Z2wwhewjyI2G00kT9OG3dct4aTMAnytFGqdRyLmupmN9ptkWqhRywhWkXrMg6VjHhRJtw8EbTTPYgebbUMjOia/gySwxDtT03aClZSF42ctDbTRLy5bC/Dc8BeAkjzpzY/NkTJhoNEhWPh5aherO2bXcDjA/LDFsltuqQ8PYZ8GdufEMZ7j7c2xiX3TrCq/13g98G4BflQYIvA5516yPSMiibBwEtaQFyS9hMVSlypqss3AMKme0eDacRJSR/8VnG8P1gYL8cAoknDaZrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=google.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=Dz+PkQd0y9lcDfj6LfaI68k2iko+rUkTXwu93/VdqjE=; b=i/NDcl9zuZ3wHv7UB43gXYQPCKyZjQIIQ0AkqV5DHTrOLkd5h7snr9dVoo7bLkgnEvbFWjMjRWCY2pTKVmc0moGbC51UA0I9oBbjXMT+tQdNzLa3uRodFC+WkXQwaGmHZpuVKpTNonxczyztdqEHGvj2lWl1WDxPN7CB6FWjzN5WZPR/8BM2UoBnSf9bns8Q8XnLPjFom3Ne3s5OyYLuTpoYWe6egyodxaSTVuoBGF0ZuYCsbYlKCF1NhqNdc3aaCbS0atjDiV3RtoDtOFN1Uv80UgRDLk+pNbl52/K73equL1ivSwg21Q5lBUUk9JjGQGbk1Iem2yMXoe/O/sU5lw== Received: from BL1PR13CA0197.namprd13.prod.outlook.com (2603:10b6:208:2be::22) by SJ2PR12MB9162.namprd12.prod.outlook.com (2603:10b6:a03:555::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 3 Dec 2024 22:10:54 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::4b) by BL1PR13CA0197.outlook.office365.com (2603:10b6:208:2be::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.8 via Frontend Transport; Tue, 3 Dec 2024 22:10:53 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.7 via Frontend Transport; Tue, 3 Dec 2024 22:10:53 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) 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; Tue, 3 Dec 2024 14:10:34 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 3 Dec 2024 14:10:34 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 3 Dec 2024 14:10:33 -0800 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 01/13] iommufd/fault: Add an iommufd_fault_init() helper Date: Tue, 3 Dec 2024 14:10:06 -0800 Message-ID: <3bc49512a42b88130cf447a7ac10acf5c02e056c.1733263737.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: MN1PEPF0000F0E2:EE_|SJ2PR12MB9162:EE_ X-MS-Office365-Filtering-Correlation-Id: 35fa567a-d783-4cc8-ffe9-08dd13e75a7c 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: UH6/CUOozmiDphQsdTLndBxowY9OFaTOTYHzCElgpCPQ9BDXXI5McrTa3NFfdiCeAsSr3nzpqCIGUvmyn2HmZLVG36rwilEegxdtNYlnpzeuvBtGEnTgh+7iNkb7ElwXnSnZoGp65w/66KwBugVQV11V1tYkknorvGFey9oOwOxXd3hyX2LYbZWOTSPNwN2Y9mwMsQl/mwhU7hpvums5/avyFI2EYJJJcGfGX4YxeCdFNqrQnVfrhfnsCU92DEkOIrK9w1qmXhyDlYmKwjmUWcMjpii4m8G4aBsWvFaBAKiZ4nh4mij5rozLNZMsSDlLRT6gZxK713Frrm4zUf/czV3OgwuZEKrE9la7kOQ8PrQUbArPw7ifDm17rhQwZPxbH4BCi1YPVuZK5gNJo1uMtoG3YkT+1FKyqh5KVpFKPz4WwgL//JXQ8urDlDMcBZGAAPhqavxlyNFzwfqjpJpjXKi/H/rIHoLYpKidgioN2d/0sS0wS+xWBD9Kw6h72A5NTqbimtWvdVdWHBVqodt1iKeF/4Cxb57jkkpjsnqJFtHZVgs6o3SG33K9Ed3XoVRsq7msKGdhImv7USWOaNAnW7oR2UDvb+iwi98jwei+JHiBr27CRK/dxJe3XXxTk7JGXQlbKe8F+04CMXNjGciv2J2cIih8V4YtPPOiXLdLJ/LOrcU/aSyANxyHyVNZ9GK63s5+4YkmYCiarAaU4MQjQHoxLSclC74VKCK+vqNTKTLxSd98eijyxgbopoQ5/upu6DpzBMK7FwsQmEKofXmQijRAMBCC4oPR4I0ScfZVbnC3RsYRLQ8nZRnL/8C7g5emtqy4MqnV41N0gIVeGs44fK5l66/1AwZHPLkrhFwg9H6BStPN7tQM1X14Nbc3hZOcEV1NkzzX4+8NZ9wBMEHqg836L65V0yTkHjEk1v+Rj4ZwfCqR/+p1Z7bMUJEwe/kr5okrKKYkjCMTZD4etaVul0BrJsP00UEXA2DQYppcGvo85oqNrNTKZKSP70FWXmGkY8+zgSjuacQ1Pz9IBunvmNAsK7Wb2vg+4QMFcIHDZn4ufIAw2Bwcl6II59OKEhDnn7oEGPLRJQ+j6xDfhM8u50v3VkOUTvUx8l5r4WJZhqVaLb8//LyP78Qv5/dpXBr7snsL0gTv0wJns1xjlid+yJzm4gzP5ijJlG89yjjFvyLEOoNI46kmv/uKWy0HY1KZBleER+N+xZkhxvIZ08k3KAs6SBly/FTooRjWKTK2RADSw9YzEqZLSPNVajtJkJjVoSloiwiuQKxUiMxbNOVcEgiHo6pl5Kx0/htfx9QLIyKaJdidDNkYIw5poMnvhLLYdNhxDxh+ygzvslqOU6fQvux+iA2tIZNup48Q37iMTiwYd/Nq4TMZu+Z9spHB5RfsMMUGyg/sIbEFVXB6SuLxrrAGn6s5eZiw+W4c7KgIl1ySlUsnqMtvJr7eSpiPeeVZ 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: 03 Dec 2024 22:10:53.1117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35fa567a-d783-4cc8-ffe9-08dd13e75a7c 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9162 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241203_141105_972212_2EDBCAD6 X-CRM114-Status: GOOD ( 15.07 ) 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 A fault object will be renamed and shared with a new vIRQ object in one of the following changes. Add a helper for the new 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 vIRQ object doesn't need "response", leave the xa_init_flags in its original location. 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..87c811b9c0d0 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; + + fault->ictx = ictx; + 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->filep = filep; + iommufd_ctx_get(fault->ictx); + 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);