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+OpyS0toKJPH94yurDZxB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qG89HSC8ehbs0dxFLc?= =?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?= =?utf-8?q?qyumrxig7cCdbY2aJBh7Srvnw9iMl919si0E7Tap+PTqhXg9v7hGoZxtHOppjXR5U?= =?utf-8?q?SV8a1zc/KD0G/7ynfJqL9d86CCIAoZ5W8zLBmB4yLaRUxqCcVY/FGZ8Hqo8XjrDZc?= =?utf-8?q?VrRL3Ot29g8YXjFvSMgcJsRxwBPVC5ux+Pg3VxmRfRSz81mIn/mVuDsizveyzsSLu?= =?utf-8?q?k9PDfD1ILwLb/CsQhFkOWFKhcZh1lg0ufblWvx8CkrvNeTjbAfspx9xpfD9fay+m+?= =?utf-8?q?mbecvbKGeGQqmjm7ZSvKRP/Flb9vdXZQKE8XWk0QpE4N9U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stnvWGKBbXV+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);