From patchwork Wed Sep 11 15:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Coster X-Patchwork-Id: 13800854 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 CA6ADEE49BC for ; Wed, 11 Sep 2024 15:43:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 49C0710E19E; Wed, 11 Sep 2024 15:43:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=imgtec.com header.i=@imgtec.com header.b="aV3CDMDl"; dkim=pass (1024-bit key; unprotected) header.d=IMGTecCRM.onmicrosoft.com header.i=@IMGTecCRM.onmicrosoft.com header.b="LHAkusia"; dkim-atps=neutral Received: from mx08-00376f01.pphosted.com (mx08-00376f01.pphosted.com [91.207.212.86]) by gabe.freedesktop.org (Postfix) with ESMTPS id 89FD410E19E for ; Wed, 11 Sep 2024 15:43:15 +0000 (UTC) Received: from pps.filterd (m0168888.ppops.net [127.0.0.1]) by mx08-00376f01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48BE97iF025570; Wed, 11 Sep 2024 16:42:55 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imgtec.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=dk201812; bh=JMcVxzyx60Q2pBUVTJQoB9HgY FD7XVyQC21fhc6uRCY=; b=aV3CDMDlIggYC5qQyRdWZEqLOA7OgkiUhfmzgXT6Z 6jxbnqs2K9gcpxR8kBeICL/c9QTVCgCgxGGysFntPM/d9hRx3JMgddsa1Bq1nLjs ghxoFmPR4iQh3SMDUzCoRaD9GVRe2Gi8SN/dIVE/R4RoIfkru9ncsi1mfw+vpsv5 1k2ErzCLDKtQTo3Vna5d2vQbUYFP7jtPqZI0avFzjjibkgPaiO++xfRRJs/mYJ4N ELpBVD1hvxFw4FEl3YVoAs1oSNyVZo8vxjqLwU2oTO6nLejuITviPx1/2/Qnpc4e emG8KFOtOTaOh0vGwZZKDh8R/qMXfkofaGK+CfNpkrd7g== Received: from hhmail05.hh.imgtec.org ([217.156.249.195]) by mx08-00376f01.pphosted.com (PPS) with ESMTPS id 41gd3rayps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 11 Sep 2024 16:42:54 +0100 (BST) Received: from HHMAIL04.hh.imgtec.org (10.100.10.119) by HHMAIL05.hh.imgtec.org (10.100.10.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Wed, 11 Sep 2024 16:42:53 +0100 Received: from CWXP265CU008.outbound.protection.outlook.com (40.93.68.3) by email.imgtec.com (10.100.10.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37 via Frontend Transport; Wed, 11 Sep 2024 16:42:53 +0100 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XS/n2/+E7C6E45K5LeGI8g2Cn/KLtyQT1EvN8CiysVZYdxMsspY2hKlLDD31vUWEvHFEk5ym/baF+9d2hLYXiSBDxk9KanwnnPeACaRA+wGoHDq0DAWuODuevxLfGWQ7m4DholhWcDpymeZnJfuKXBlsfCUO9uSkvETLkqEOOXZGpjApiN7Zr6kJreOyhgZ+pm6dQBStbuM1+KTsXF6Qj2Xjswa6Miov54cJYkGVgnozWO7oo+4HMI0006gOzm7b0dwJrJTMqCa7ZMpE4elHSikh3HLNq0UuTT71nt2iOzaUkMBDNSndGEnuiydTeUegCTNY5QIc30YoxE6NVhDs0w== 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=JMcVxzyx60Q2pBUVTJQoB9HgYFD7XVyQC21fhc6uRCY=; b=Lu7O7yWtI8QzTZdGD/AKrWmu1jve2DG8w8XD+OfSOSjbxBO2khM+e9twEtJaPXr6HBWklIUjcIwQotoPRb8KhOFf81mu+ZgZ029iEbRu+kHimthgEoh9fOBqFgRKHDIGSvOZwsNOsuH4YaTOe/8WAqZuHfyv0Qi3G0E95RtIpcgjmfP1pXYSH9mDP/bHcel8hh4DUI1OSMOTJngx8vlZS2BbjiabIZZkzErKj6Jr25wKvN2zqctTr4wsEyssM7Dmb6juGNlKBjTZFwMxOvhmuqIvUUE+QjNT1dqiGeWv/JN5PNxKqAK5BAXgMQY21NZmsKIuG4MzGU7fXm4hWfAvSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=imgtec.com; dmarc=pass action=none header.from=imgtec.com; dkim=pass header.d=imgtec.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=IMGTecCRM.onmicrosoft.com; s=selector2-IMGTecCRM-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JMcVxzyx60Q2pBUVTJQoB9HgYFD7XVyQC21fhc6uRCY=; b=LHAkusiaVQAW3Gds28Y6mcdx8nIh/m9WmUhAbObedsO/9WbccmMAFBCbtYoiVtctlKi5Lo1xyEWnWo3yW/DJcc5JnR+FLIQG47NrmvHSP7L0QUFkC/aSvwQO4BJCItg1vQnQGL7u7AomFPKI0Ru3s4tkhzYncwqJVA93gOXz6aU= Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:e7::8) by CWLP265MB6740.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Wed, 11 Sep 2024 15:42:50 +0000 Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15]) by CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15%3]) with mapi id 15.20.7962.016; Wed, 11 Sep 2024 15:42:48 +0000 From: Matt Coster To: "dri-devel@lists.freedesktop.org" CC: Brendan King , Frank Binns , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , "linux-kernel@vger.kernel.org" Subject: [PATCH 1/2] drm/imagination: Add a per-file PVR context list Thread-Topic: [PATCH 1/2] drm/imagination: Add a per-file PVR context list Thread-Index: AQHbBGFAoIxYip2DjkenFFxtsnCiZQ== Date: Wed, 11 Sep 2024 15:42:48 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CWXP265MB3397:EE_|CWLP265MB6740:EE_ x-ms-office365-filtering-correlation-id: 69641342-4363-4da0-0932-08dcd2786363 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|366016|376014|1800799024|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?1RPO921JlEU4ToQTTlCpmSFGnI1oE4t?= =?utf-8?q?DSrrVXfH3gUdPItJi6j1XH/wfvud5Ur99/YCjxKKYgDKOEXJVcG+3lHWNj3H3t7iU?= =?utf-8?q?60gbE1Pn02oHwhzxEmRDd28Ud/cOH8DfyhNuikZMhtu0AYLaHv742eaVWE1D5LV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E7Y7fB?= =?utf-8?q?5T6CILcRnRDCN74BBNDLwqBTVKdrh5liTNuzyPVCPto8zZmsfOEOl7XnDDV3JDR2u?= =?utf-8?q?CYdC+/13Np4EQNVNhBSD/O4mdyaYIxBU3Xx4C1DSrXO/Gm0+8U9dAeg6Ua5xuctOf?= =?utf-8?q?WMy3AdMJm+UlavG0TNL2dnpBK3BfTdWsgL7dmNKyTZJqUoAaQfc8ZkIpQpjwtE35r?= =?utf-8?q?bzI0tsTnZGl/0uBj/15v3FsNA7EtfTn2lM82YLkm/qkZOyRjGg3ftQT+RxOaWZULN?= =?utf-8?q?dHx3bzuSKW6y3UZR0t0UgrLtkEc4ff/Cw3AQE+nIHxNs9Jgvwwvxy5KMtnmygRMxF?= =?utf-8?q?sNGWbHQnXCWavZ7TDYD5VFo8W5u5klFGLA=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?SLCH+me02VF87nBqaV5try4il1RR?= =?utf-8?q?iPbZM5appOZwxTgsIrSaqoGzEnV1RRfqJUNh/wjXnUVaGUGht4/yqDUefQ0r7vXt4?= =?utf-8?q?v+18gU4M6+dNLysWfTRF7JHIUnZ+o1MLiKAI4ObVbJgsbfExH8y22CrTNxie4NI3E?= =?utf-8?q?jorHSiYOTsTqmBjbCDxOTuy2x3UU0W5X8a2NB9J8VW/n+0AvTuFOxeqxbCe4/O6AW?= =?utf-8?q?e5nTK0FlLVNiEvnXYn+xJwSey3MWUZ1Z+s12YTrLwx7QRcZ99txqAWXjf9PLD6Cr7?= =?utf-8?q?/m4ulKOyrjIHkcwDmD0Mt08RhDMfofBdVqkM6yArrdsWefLXQE8PP8+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KDBAtKrE?= =?utf-8?q?HPKstUl8laMgGzHXCvCfVUob+CA0Ub+u75UocBICAfHPUWsGlsGv+hrGL6AQLiYrf?= =?utf-8?q?o10SRqdmqfQ1FleQzIN6iHgFla6qioK8oEuHZWRTJ+o9CoZyn53CHlkE0JQGgH7B4?= =?utf-8?q?NoC38ieup8ksUihi6UJ8VzUK35rw0UHXYb9/AuquqYQ24WrWsL3HO2kwRRpOI4d5Z?= =?utf-8?q?sJLhnWhz3t3wG6UuD9uhwSJk6QExXT7g0gRJIexrOVvS3zbaVH1KeBWfPv8pYCGF2?= =?utf-8?q?Zn5rHwgvqsU3Jtz6gNjxqDXOiyqLTBCsOs/JpEBTChlCfONirT8z5oqra1fC8z0sj?= =?utf-8?q?Y41rnDXxctmaqBfF3AUxWbqbGhMM43r+UQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 69641342-4363-4da0-0932-08dcd2786363 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2024 15:42:48.5088 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0d5fd8bb-e8c2-4e0a-8dd5-2c264f7140fe X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: gjMES48MerUYJpcYj/g47PnXLwIxR0EiTsuHpzl79sZiU3yhOd7ejvurwrHffCacdJm1IqHmu5WLZSrr4daTXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB6740 X-OriginatorOrg: imgtec.com X-EXCLAIMER-MD-CONFIG: 15a78312-3e47-46eb-9010-2e54d84a9631 X-Proofpoint-GUID: fCGDCMMu6LB7_1lAOPeeVmOzUx_y-37s X-Proofpoint-ORIG-GUID: fCGDCMMu6LB7_1lAOPeeVmOzUx_y-37s X-Authority-Analysis: v=2.4 cv=GIVaEfNK c=1 sm=1 tr=0 ts=66e1ba7f cx=c_pps a=6IdplsTJodF3+aqeaEJcqA==:117 a=6IdplsTJodF3+aqeaEJcqA==:17 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=EaEq8P2WXUwA:10 a=WnR_qW7rlZcA:10 a=NgoYpvdbvlAA:10 a=r_1tXGB3AAAA:8 a=VwQbUJbxAAAA:8 a=zfBPz-HDHTuPlw-aen4A:9 a=QEXdDO2ut3YA:10 a=L3WQYlS-Qr307JIZeJIA:9 a=FfaGCDsud1wA:10 a=t8nPyN_e6usw4ciXM-Pk:22 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Brendan King This is in preparation for the next commit, which makes use of the list. Signed-off-by: Brendan King Signed-off-by: Matt Coster Cc: stable@vger.kernel.org --- drivers/gpu/drm/imagination/pvr_context.c | 14 ++++++++++++++ drivers/gpu/drm/imagination/pvr_context.h | 3 +++ drivers/gpu/drm/imagination/pvr_device.h | 10 ++++++++++ drivers/gpu/drm/imagination/pvr_drv.c | 3 +++ 4 files changed, 30 insertions(+) diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/imagination/pvr_context.c index eded5e955cc0..255c93582734 100644 --- a/drivers/gpu/drm/imagination/pvr_context.c +++ b/drivers/gpu/drm/imagination/pvr_context.c @@ -17,10 +17,14 @@ #include #include + +#include #include #include +#include #include #include +#include #include #include #include @@ -354,6 +358,10 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co return err; } + spin_lock(&pvr_dev->ctx_list_lock); + list_add_tail(&ctx->file_link, &pvr_file->contexts); + spin_unlock(&pvr_dev->ctx_list_lock); + return 0; err_destroy_fw_obj: @@ -380,6 +388,11 @@ pvr_context_release(struct kref *ref_count) container_of(ref_count, struct pvr_context, ref_count); struct pvr_device *pvr_dev = ctx->pvr_dev; + WARN_ON(in_interrupt()); + spin_lock(&pvr_dev->ctx_list_lock); + list_del(&ctx->file_link); + spin_unlock(&pvr_dev->ctx_list_lock); + xa_erase(&pvr_dev->ctx_ids, ctx->ctx_id); pvr_context_destroy_queues(ctx); pvr_fw_object_destroy(ctx->fw_obj); @@ -451,6 +464,7 @@ void pvr_destroy_contexts_for_file(struct pvr_file *pvr_file) void pvr_context_device_init(struct pvr_device *pvr_dev) { xa_init_flags(&pvr_dev->ctx_ids, XA_FLAGS_ALLOC1); + spin_lock_init(&pvr_dev->ctx_list_lock); } /** diff --git a/drivers/gpu/drm/imagination/pvr_context.h b/drivers/gpu/drm/imagination/pvr_context.h index 0c7b97dfa6ba..a5b0a82a54a1 100644 --- a/drivers/gpu/drm/imagination/pvr_context.h +++ b/drivers/gpu/drm/imagination/pvr_context.h @@ -85,6 +85,9 @@ struct pvr_context { /** @compute: Transfer queue. */ struct pvr_queue *transfer; } queues; + + /** @file_link: pvr_file PVR context list link. */ + struct list_head file_link; }; static __always_inline struct pvr_queue * diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h index ecdd5767d8ef..b1fbf9ccf19f 100644 --- a/drivers/gpu/drm/imagination/pvr_device.h +++ b/drivers/gpu/drm/imagination/pvr_device.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -293,6 +294,12 @@ struct pvr_device { /** @sched_wq: Workqueue for schedulers. */ struct workqueue_struct *sched_wq; + + /** + * @ctx_list_lock: Lock to be held when accessing the context list in + * struct pvr_file. + */ + spinlock_t ctx_list_lock; }; /** @@ -344,6 +351,9 @@ struct pvr_file { * This array is used to allocate handles returned to userspace. */ struct xarray vm_ctx_handles; + + /** @contexts: PVR context list. */ + struct list_head contexts; }; /** diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c index 1a0cb7aa9cea..fb17196e05f4 100644 --- a/drivers/gpu/drm/imagination/pvr_drv.c +++ b/drivers/gpu/drm/imagination/pvr_drv.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1326,6 +1327,8 @@ pvr_drm_driver_open(struct drm_device *drm_dev, struct drm_file *file) */ pvr_file->pvr_dev = pvr_dev; + INIT_LIST_HEAD(&pvr_file->contexts); + xa_init_flags(&pvr_file->ctx_handles, XA_FLAGS_ALLOC1); xa_init_flags(&pvr_file->free_list_handles, XA_FLAGS_ALLOC1); xa_init_flags(&pvr_file->hwrt_handles, XA_FLAGS_ALLOC1); From patchwork Wed Sep 11 15:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Coster X-Patchwork-Id: 13800855 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 3F735EE0213 for ; Wed, 11 Sep 2024 15:43:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 13FCC10E1A8; Wed, 11 Sep 2024 15:43:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=imgtec.com header.i=@imgtec.com header.b="cksUcuux"; dkim=pass (1024-bit key; unprotected) header.d=IMGTecCRM.onmicrosoft.com header.i=@IMGTecCRM.onmicrosoft.com header.b="Mh9w2275"; dkim-atps=neutral Received: from mx07-00376f01.pphosted.com (mx07-00376f01.pphosted.com [185.132.180.163]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9599910E1A8 for ; Wed, 11 Sep 2024 15:43:29 +0000 (UTC) Received: from pps.filterd (m0168889.ppops.net [127.0.0.1]) by mx07-00376f01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48B5vdIB026099; Wed, 11 Sep 2024 16:43:20 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imgtec.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=dk201812; bh=Fof4O4ujJ9SP6Bf+NZe0VyWf6 plDVydYFKJvJWcnXpY=; b=cksUcuux7hKiWQz1/omShjpe1gvQOwR0fO1PKyzKl fn0OuCVdZBNLAx0ndF5lHpKAhAkJ0bRSl3u3qcNtvTIt1gL2cnSFf9RWQortAEF+ Ea9tNRR05V3deK/9zORZodah++p4QjrSHNgAml2KIvgeDjMKfb3XDX7bVgnWHMin KDKYQ7bnGoxy+NvH1syJfCywWgMWduOOXkhmXeKJVbuhZGIUAsTxZZAGYlVIkIU3 zvt58O9vNP51JXyiU3RNL1Q33euwiTF7SNkMigmLyAM80vGmC9SPVRsBdnr2h2il jF67V5oO2jKIt5n2zkg3nLP5K5dHvkTzzMFNcgarRT6+g== Received: from hhmail04.hh.imgtec.org ([217.156.249.195]) by mx07-00376f01.pphosted.com (PPS) with ESMTPS id 41gewwbcbt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 11 Sep 2024 16:43:19 +0100 (BST) Received: from HHMAIL04.hh.imgtec.org (10.100.10.119) by HHMAIL04.hh.imgtec.org (10.100.10.119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Wed, 11 Sep 2024 16:43:18 +0100 Received: from CWXP265CU008.outbound.protection.outlook.com (40.93.68.7) by email.imgtec.com (10.100.10.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37 via Frontend Transport; Wed, 11 Sep 2024 16:43:18 +0100 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RUX5MVQE8Rx6SQG3TgPABFitJc5hvtADv/6ox5nBdomu9KoSTZmDYN6EfpMMwpz+BKr5ZnB6sg8Cldi/DL1l72yZ6MyGdDpOnoDg7su6CXHHhYjHMGp/EmjxhhBCeRLV0gfPngE2sewH3rSc2N3fPfNXLoc5VLAjBVwWn8xwvVwh1Ql53vQdGXi24z+Vkw7MHYvaM1EQQz27HEv/DQ/vUxduG79EVZAU59ltpGqRLI0P+bWG60ALuurwHGRzsfV3Neqnza9iKlFugZo0h68/9NzTycFxECVkjJyb77NJIOpl88sZ15tXAwGD0bnXB5s43PFb9Fy3PpBb0qHrLXR2hw== 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=Fof4O4ujJ9SP6Bf+NZe0VyWf6plDVydYFKJvJWcnXpY=; b=cmEUUXrQo1gwfP/Ibfhfni/b63dpEf5tz4/kXb6JvRXEpu9TMdgB/o60cC8n3FgrVwYrqME4amHeGS3PsYb+PIYD/j9BbozwGa1OMRzv5WqzfK+knXzEtCUV/w0vzsfxbzdJP7L3FeQ9HzxjH7mtn5IYSD4ys1UHVNsJClheuo3A9hcoMwcDybEsbm+zjeH6M10VK6hrnSVEngI79qFnkU+ugyx1baSYsiFB5/nrcQA3ErAMEnTyXHvCu7jH5Yoj8SC+FUaQfjQqERj3uu9xltBy8s89YavpNt/Ype2I1AYpGM3rttBYpuQnkRsuOeVsgkzBi+p3kut/fP/+cXuCUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=imgtec.com; dmarc=pass action=none header.from=imgtec.com; dkim=pass header.d=imgtec.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=IMGTecCRM.onmicrosoft.com; s=selector2-IMGTecCRM-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fof4O4ujJ9SP6Bf+NZe0VyWf6plDVydYFKJvJWcnXpY=; b=Mh9w2275SBDIMbdPYy7/4xzdK4ONRXwwwQoJDzninT2dsttW+AxBR4yw2G4B1+Vbh/TvdM9G8B1ctuLjUiKY6wRiRTcjxd2QVDKjFloV4aGpdRYCv6BH+ChKzd091cnVzjX9jTvvhH6YxIXmrQFagvuNWziQNDFJYZlazYZEqGo= Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:e7::8) by CWLP265MB6740.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Wed, 11 Sep 2024 15:43:16 +0000 Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15]) by CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15%3]) with mapi id 15.20.7962.016; Wed, 11 Sep 2024 15:43:15 +0000 From: Matt Coster To: "dri-devel@lists.freedesktop.org" CC: Brendan King , Frank Binns , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , "linux-kernel@vger.kernel.org" Subject: [PATCH 2/2] drm/imagination: Break an object reference loop Thread-Topic: [PATCH 2/2] drm/imagination: Break an object reference loop Thread-Index: AQHbBGFRZTaZEBXqvEqglnFzLz8enQ== Date: Wed, 11 Sep 2024 15:43:15 +0000 Message-ID: <6c283532-e39f-4bb0-b0a1-d654632478a0@imgtec.com> References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CWXP265MB3397:EE_|CWLP265MB6740:EE_ x-ms-office365-filtering-correlation-id: c50d992f-e5c9-4087-d0a3-08dcd27873bd x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|366016|376014|1800799024|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?XpPB5iPp3sFIzRmKt1tbMvhwUmRI0FB?= =?utf-8?q?ilQaaZyCZ7J04IkagEsVmHhcGrUnQiGxbnBZ5DlkxM7F6Oky+no1F7D+12FaYRnzj?= =?utf-8?q?ocggnJ3HSHP6x+OpyS0toKJPH94yurDZxBQkyBdrYinx4GR5DeRMcaAwva10ZBNHt?= =?utf-8?q?t+Nrio98Q5jR62tMf7PeZS1XTqsrz7ZO4bMit5pMi7apgizReJRWYmvIORMqIhz9Y?= =?utf-8?q?dJPmrhs4gsqvVtyiqiIIa3WfVZdnDsbg3+J3OaQ75mdoLUwp2roBpInoDf6e9Av7j?= =?utf-8?q?9LAsgMVWP3xrv0w+hLZVPkjFHDFStK+yxcsZ8Le/Zw+aofRAimBorMXZeTBhZKhed?= =?utf-8?q?jn1OJgjtdBzhOaeHM9wzJW035cfzZTTZgslliGzlC8t7HTXPJ5Zr8oZDc8emnviA1?= =?utf-8?q?tGssCWluh9WP1CnqxGRlK7ofv2OmJFKiLLqPBv8candzY9rTpn+mvwPKUl/a01L0o?= =?utf-8?q?W7NB+o7rTXWJFKgWjWhATWcd8I64iggddsWuqbDgfGgYtamV2ALBTPIo3OmEeLxXu?= =?utf-8?q?VS1RlRpWSlPEQfgBYK2KqSYGu8tnnfsrIAcWToo5P92fjsCcNctg1jNBDU3WISeDy?= =?utf-8?q?xWNMsz4Q0h/7nzTa3/IiyE4M32EroIBLjz651WAD/F3MeUSNIuNxc8mJZiKdQr51a?= =?utf-8?q?DTMU40sPYllAGOQO9bTarEpHIFF6uWJKU4ZOwTWEJYY/IlP2NGaSjawEsc0avsyT4?= =?utf-8?q?3oBM1K1qInyitjgp1jAeg75wiukedZxBA3O96h6iZ6LVwSxj7VvSi5af/F4RQsAgl?= =?utf-8?q?AbJXBIa4YZQ4HfimN5Z7kvRNcJ3OgJtTfBtszkzz/AXedAwfRgMQOTCfANm+C+gCV?= =?utf-8?q?K1yCXxlI1w6yXxAHFAKxbhXQTYZjFLvATzNsVg7SWEwyfCWDJernIbKBG44yt/k4f?= =?utf-8?q?YZix6Z8DMTKQ5azSpTvhP/pvMcgh8iZpwIMtXJkC282z1pSt+h9ThAIz5nO29EZTY?= =?utf-8?q?6FbmAGO2ZAAoson3JyXOGQQDJtBkaxTgl3MbdWf0+jNiEwtqG89HSC8ehbs0dxFLc?= =?utf-8?q?jxFuT8PL7aMZBJ764mhL5cc4AX0v6j4K3YFItd8LRyr1svtyXGUz6p1vwt8viC7OU?= =?utf-8?q?BqOE8aS0H9bZDcFq8A/eyNjaZMbH5Tn1S71hK9ICkR9o7PCJ9a6v4cuB3TFdsQr/x?= =?utf-8?q?C86URfcys/sGK8OY271m8mFLRPyotVEh9W9cxYjgiIUBxRjQ3cuaLlNXa1AXyoxyY?= =?utf-8?q?O70JZaTk/RmlJAQ7Q4m7ZaKsZ+1w3d2RICEkYm7CstlbQ8RDOqIIWfg034ts3tDsL?= =?utf-8?q?p2ouT41d6uGQz1lac9XQdhDRPaEveVDhCimUDVUg2pQAy4+NsDtpgRbajDEBSQIUg?= =?utf-8?q?D6IguUmZ5JvPElLCO9ru2aBhXxr6fODCHA=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?Lb3F7oz31qHH95uxev3zHSJf1wzN?= =?ut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NEk?= =?utf-8?q?KKhmUV67IHAHRQ6IyFn70Aw3XLctgjTsHrKBiVuC/xgCbzvInX06Gf2XLXhC52TRM?= =?utf-8?q?yInpe041Qfyhxq5UUD/C2Bl7EQi8I3zpnMcdUo64yR/WfqykVFKbiNsnq6LQsXeu8?= =?utf-8?q?rRcAMFKHLZ/i4PMdtPwObP42c/TB4i//VmCXz+FyqSNCSd7Mk7mkCgoyRqK9s7l3j?= =?utf-8?q?AGAVxZyMS9RIxZRtbhPPG+s81XKNDjPZxmg5belmdtgxLdcmsW5yMsVRsH3J70Kpd?= =?utf-8?q?i5pYhWRRorQ+oJ4Z6yhUoVLx7lrAw6liUN/GOURqstnvWGKBbXV+pUuJCjmDwC69O?= =?utf-8?q?HAv4OAT0c3F9KArofAbZxYU4VMTzDV6e1vxfVNM0uzYG66joHrW6VbB/ffQb3JLgu?= =?utf-8?q?YEYM4pfGGcXYJ7vKDBjze/Yp261MEHicDuEnIKrb/3qlKZbnnWwhYxAqbpgqWPfMX?= =?utf-8?q?UfoR6pg52U3fA9FbNb6ytTvaqZxadllLrcQ+y6BPZWmp13ZvdgJYh+KxVonKTVfix?= =?utf-8?q?UtsFMilS5F1HBnJAnp1IPAR/liaoWl38ShZb89ce/uL561hphDg4uuQuyWUOhEzut?= =?utf-8?q?G2W54I3rNc4d8rIg4H2ddESZcApl0LJ0bDDZ0CvvNJn7ykkQRoD8jNrz6KgGrWI/r?= =?utf-8?q?IHL2xh8k0tfHSbClGTkTaHZqmeo6z1pdDA=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: c50d992f-e5c9-4087-d0a3-08dcd27873bd X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2024 15:43:15.8953 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0d5fd8bb-e8c2-4e0a-8dd5-2c264f7140fe X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BjUrKJrciI2ZluLLVCQiyVWBWEuB369016XhxpBGSn5Z/JqeYO0v3HeMUtjgrnipHcwQC3zCKPtOjq1VX13TqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB6740 X-OriginatorOrg: imgtec.com X-EXCLAIMER-MD-CONFIG: 15a78312-3e47-46eb-9010-2e54d84a9631 X-Authority-Analysis: v=2.4 cv=V7Ev0vni c=1 sm=1 tr=0 ts=66e1ba98 cx=c_pps a=6IdplsTJodF3+aqeaEJcqA==:117 a=6IdplsTJodF3+aqeaEJcqA==:17 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=EaEq8P2WXUwA:10 a=WnR_qW7rlZcA:10 a=NgoYpvdbvlAA:10 a=r_1tXGB3AAAA:8 a=VwQbUJbxAAAA:8 a=wHEVHdBimyBemZvaBQYA:9 a=QEXdDO2ut3YA:10 a=Krd9fsHnkUVr2O1wAC8A:9 a=FfaGCDsud1wA:10 a=t8nPyN_e6usw4ciXM-Pk:22 X-Proofpoint-ORIG-GUID: YNDsddm2Jg_kOglUUDXjTEZkTmUZjFzJ X-Proofpoint-GUID: YNDsddm2Jg_kOglUUDXjTEZkTmUZjFzJ X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Brendan King When remaining resources are being cleaned up on driver close, outstanding VM mappings may result in resources being leaked, due to an object reference loop, as shown below, with each object (or set of objects) referencing the object below it: PVR GEM Object GPU scheduler "finished" fence GPU scheduler “scheduled” fence PVR driver “done” fence PVR Context PVR VM Context PVR VM Mappings PVR GEM Object The reference that the PVR VM Context has on the VM mappings is a soft one, in the sense that the freeing of outstanding VM mappings is done as part of VM context destruction; no reference counts are involved, as is the case for all the other references in the loop. To break the reference loop during cleanup, free the outstanding VM mappings before destroying the PVR Context associated with the VM context. Signed-off-by: Brendan King Signed-off-by: Matt Coster Cc: stable@vger.kernel.org --- drivers/gpu/drm/imagination/pvr_context.c | 19 +++++++++++++++++++ drivers/gpu/drm/imagination/pvr_context.h | 18 ++++++++++++++++++ drivers/gpu/drm/imagination/pvr_vm.c | 22 ++++++++++++++++++---- drivers/gpu/drm/imagination/pvr_vm.h | 1 + 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/imagination/pvr_context.c index 255c93582734..4cb3494c0bb2 100644 --- a/drivers/gpu/drm/imagination/pvr_context.c +++ b/drivers/gpu/drm/imagination/pvr_context.c @@ -450,11 +450,30 @@ pvr_context_destroy(struct pvr_file *pvr_file, u32 handle) */ void pvr_destroy_contexts_for_file(struct pvr_file *pvr_file) { + struct pvr_device *pvr_dev = pvr_file->pvr_dev; struct pvr_context *ctx; unsigned long handle; xa_for_each(&pvr_file->ctx_handles, handle, ctx) pvr_context_destroy(pvr_file, handle); + + spin_lock(&pvr_dev->ctx_list_lock); + ctx = list_first_entry(&pvr_file->contexts, struct pvr_context, file_link); + + while (!list_entry_is_head(ctx, &pvr_file->contexts, file_link)) { + list_del_init(&ctx->file_link); + + if (pvr_context_get_if_referenced(ctx)) { + spin_unlock(&pvr_dev->ctx_list_lock); + + pvr_vm_unmap_all(ctx->vm_ctx); + + pvr_context_put(ctx); + spin_lock(&pvr_dev->ctx_list_lock); + } + ctx = list_first_entry(&pvr_file->contexts, struct pvr_context, file_link); + } + spin_unlock(&pvr_dev->ctx_list_lock); } /** diff --git a/drivers/gpu/drm/imagination/pvr_context.h b/drivers/gpu/drm/imagination/pvr_context.h index a5b0a82a54a1..07afa179cdf4 100644 --- a/drivers/gpu/drm/imagination/pvr_context.h +++ b/drivers/gpu/drm/imagination/pvr_context.h @@ -126,6 +126,24 @@ pvr_context_get(struct pvr_context *ctx) return ctx; } +/** + * pvr_context_get_if_referenced() - Take an additional reference on a still + * referenced context. + * @ctx: Context pointer. + * + * Call pvr_context_put() to release. + * + * Returns: + * * True on success, or + * * false if no context pointer passed, or the context wasn't still + * * referenced. + */ +static __always_inline bool +pvr_context_get_if_referenced(struct pvr_context *ctx) +{ + return ctx != NULL && kref_get_unless_zero(&ctx->ref_count) != 0; +} + /** * pvr_context_lookup() - Lookup context pointer from handle and file. * @pvr_file: Pointer to pvr_file structure. diff --git a/drivers/gpu/drm/imagination/pvr_vm.c b/drivers/gpu/drm/imagination/pvr_vm.c index 97c0f772ed65..7bd6ba4c6e8a 100644 --- a/drivers/gpu/drm/imagination/pvr_vm.c +++ b/drivers/gpu/drm/imagination/pvr_vm.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -597,12 +598,26 @@ pvr_vm_create_context(struct pvr_device *pvr_dev, bool is_userspace_context) } /** - * pvr_vm_context_release() - Teardown a VM context. - * @ref_count: Pointer to reference counter of the VM context. + * pvr_vm_unmap_all() - Unmap all mappings associated with a VM context. + * @vm_ctx: Target VM context. * * This function ensures that no mappings are left dangling by unmapping them * all in order of ascending device-virtual address. */ +void +pvr_vm_unmap_all(struct pvr_vm_context *vm_ctx) +{ + WARN_ON(pvr_vm_unmap(vm_ctx, vm_ctx->gpuvm_mgr.mm_start, + vm_ctx->gpuvm_mgr.mm_range)); +} + +/** + * pvr_vm_context_release() - Teardown a VM context. + * @ref_count: Pointer to reference counter of the VM context. + * + * This function also ensures that no mappings are left dangling by calling + * pvr_vm_unmap_all. + */ static void pvr_vm_context_release(struct kref *ref_count) { @@ -612,8 +627,7 @@ pvr_vm_context_release(struct kref *ref_count) if (vm_ctx->fw_mem_ctx_obj) pvr_fw_object_destroy(vm_ctx->fw_mem_ctx_obj); - WARN_ON(pvr_vm_unmap(vm_ctx, vm_ctx->gpuvm_mgr.mm_start, - vm_ctx->gpuvm_mgr.mm_range)); + pvr_vm_unmap_all(vm_ctx); pvr_mmu_context_destroy(vm_ctx->mmu_ctx); drm_gem_private_object_fini(&vm_ctx->dummy_gem); diff --git a/drivers/gpu/drm/imagination/pvr_vm.h b/drivers/gpu/drm/imagination/pvr_vm.h index f2a6463f2b05..79406243617c 100644 --- a/drivers/gpu/drm/imagination/pvr_vm.h +++ b/drivers/gpu/drm/imagination/pvr_vm.h @@ -39,6 +39,7 @@ int pvr_vm_map(struct pvr_vm_context *vm_ctx, struct pvr_gem_object *pvr_obj, u64 pvr_obj_offset, u64 device_addr, u64 size); int pvr_vm_unmap(struct pvr_vm_context *vm_ctx, u64 device_addr, u64 size); +void pvr_vm_unmap_all(struct pvr_vm_context *vm_ctx); dma_addr_t pvr_vm_get_page_table_root_addr(struct pvr_vm_context *vm_ctx); struct dma_resv *pvr_vm_get_dma_resv(struct pvr_vm_context *vm_ctx);