From patchwork Fri Oct 18 15:41:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Coster X-Patchwork-Id: 13841988 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 B7524D30019 for ; Fri, 18 Oct 2024 15:42:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 297AD10E19A; Fri, 18 Oct 2024 15:42:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=imgtec.com header.i=@imgtec.com header.b="Er5wgY1j"; dkim=pass (1024-bit key; unprotected) header.d=IMGTecCRM.onmicrosoft.com header.i=@IMGTecCRM.onmicrosoft.com header.b="D4muzv0i"; 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 DDA7B10E19A for ; Fri, 18 Oct 2024 15:41:58 +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 49IBSmvl018297; Fri, 18 Oct 2024 16:41:39 +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=BZKcoAYwqQov8ijGzTVVKFXh1 9Hql2U8WjaG+HOgDjI=; b=Er5wgY1jKZ8XRAe/Nx+FPA+B5c5NSHkXU1QL/rWKp Qup1B8ux0ldGCkvhDytKmJ/wfhfhwDC/31LWMaSN42Qs1cSK6lgDwzFi6ArpLLLT N8IEn7QAqB18ZrAclrxnz6kI5tWrpuCW8+Vtk9Da97yTG5vWwl+cYhZsg5Vl7i+N o7qoycgHaYLopO8ZUT2xbmHAwIAuheQgmsVbm2fUmdhWMwBg6qJRaj+iuNWlhk/t FpGeN6TcjF5cKYCVgYukLuhMgBav00xY+wusGQQ9x5H2SYvSNDibIT2EvWPHJmWW 631UnpudrQPtO8omndsV7BcjIliglN1UzwtsPVmknGpgQ== Received: from cwxp265cu008.outbound.protection.outlook.com (mail-ukwestazlp17010003.outbound.protection.outlook.com [40.93.68.3]) by mx08-00376f01.pphosted.com (PPS) with ESMTPS id 42a3ac2nwm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 16:41:38 +0100 (BST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d2fj0pUwQRAXVAu6IUM/8MM2sr33/52J35XVXJZXeg7etEU26dK2HDz/zF+RgUglLgYsX24r0ahHzyaw5KKJQaIYE3ShKuOH7/Rjop5dBT2kysSLt7A9Ya1dCkEPkVwCrWjjetf/IcfmijjNVMEBg2lNzWgAfaVP4T2cBFMUk9lfz1PdDE2CeB0omJTJNxhwpONrz8On53t7hxvZx7KvBBuGGW9byhme0baIRtKJ8Xf2d1RffS/Z6SRrdOS5IzVyBN8pdw+4EP2xpigcSxY7/vzyiIezpadL2+mezS/yPCItLwN2YhFSheQr3q5ghrb3py2E8v+BuXL+vC7eW/T2dg== 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=BZKcoAYwqQov8ijGzTVVKFXh19Hql2U8WjaG+HOgDjI=; b=J0WjVGUWeKAUN+ilT6/xt5/mmz41Hr9hpIGnrU+b2lm2QyjddWVZonw9cMP0V1hGDQMTBeZTzezaHLSyB3geRrYWTlQL05mOVCKdXdwUiNNnrMjPyuAc2ZwJjCeuBscbWDxFZ6eYZyeLKcUEyiZvvzbOrxYjE4ZAWBC8Kase30Qr2v9KuIe31qcCmiKdSvpbfMZRmFE9Dt5bUNrLovYOvJ/EMvXUb/7f/76d7KLgXeeA3JFBcofFSJnIzwWsAJwH17NkPEWKdaHZETa5fFQM9J3ih2lMFLVrqPm7qTcYllOofoLf7TlVJzxl+A3+d/WgkKLD7CJL6cOKRuLH7hf4Zg== 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=BZKcoAYwqQov8ijGzTVVKFXh19Hql2U8WjaG+HOgDjI=; b=D4muzv0iEl/ctaN1KgXxMT7yUgdvxQWJwK52k/xg9H+yxQy3X7ilCge5MGLwwfbASvBmS4RWFoIBu++a8kNfcbxMsIw7iWn6kUJntHQ8yQex6MsStSlUn/F4K8uPvSeICx0763N0WdXflgY9lQ4hrtjy16n/xK04GAsL8+vgNKw= Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:e7::8) by CWLP265MB2259.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:6b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Fri, 18 Oct 2024 15:41:36 +0000 Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15]) by CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15%6]) with mapi id 15.20.8069.020; Fri, 18 Oct 2024 15:41:36 +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 v3 1/2] drm/imagination: Add a per-file PVR context list Thread-Topic: [PATCH v3 1/2] drm/imagination: Add a per-file PVR context list Thread-Index: AQHbIXQ3By0tkWHfnE+2c5pxM7UKeQ== Date: Fri, 18 Oct 2024 15:41:36 +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_|CWLP265MB2259:EE_ x-ms-office365-filtering-correlation-id: 4a5b3e7f-0f72-4954-3b17-08dcef8b5995 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|366016|376014|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?aYHn1n9YW71nbzW3rr5ZEOlZEdx5MIf?= =?utf-8?q?Njj5kCW8GxAb4Q5CA1AUMk2mmN6veNjGdhQC+Gu3UEKHGvC6STZ/55YfRsmfWLsS0?= =?utf-8?q?/s6GF/QZPs5z89Ewq6EylNT+uHqRFWI+Hx30Z7gdboQg/Cj8isSlEOmCyTw1tKV0Y?= =?utf-8?q?kybInKzfAp7Wp6IU8yy77c3Or99bxrkP8txtGguAeSwnTAEdWQrWsviniKXjRjkyM?= =?utf-8?q?rhASl10JucKgtooq8fFP+ZLVgFvcECTXxB3BK6dL3Mu3uZBNCE1F6hM75bp0wu76O?= =?utf-8?q?JCaTEqsHCaKfknFp+zETCK0+KqN1va4V8iIJizeVlE6R/HedxX3BHU2OZWbrpKmE1?= =?utf-8?q?IaOeCIVsGs505cvnQhnDhzXpCSlxAhROy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SZ0XbBWWD15R/oUBCEPjH1wmjDVpqsGjuQPkO/Gw?= =?utf-8?q?ZfGiUnuwcMOfLy/w1GTc66SIXxYmhTsC33SJakz/YitiO4i8atp69/DcJzajJgXik?= =?utf-8?q?6olX1sIY3FQ3?= 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)(1800799024)(366016)(376014)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?pt/OQHPIUF2T+GZ8dao8iXYLBiYo?= =?utf-8?q?DaDlSSSf5PvQNl8nBFF4qx5pDxAPQaNR8Z+vE2ZeCXVTfxPu2PTffVV4hAY4xO/t2?= =?utf-8?q?r6RCBNloskzwyx7AT2p/fRZl6lXYCH1+/1lvoOOmxPvrdH+mvTzkC27YNJcGimr72?= =?utf-8?q?i3WoPXvISc5EHsTEH+JSplNhEXhhUbLf8264SidkvCbBYOED9CBsNL0ggcEZ/cmlB?= =?utf-8?q?+PlMJQNtoS+4elE/gAn0uhDs7yvCtwumhd81gevrPdlIeeXX7VYcddn/Ra5Q2bcWM?= =?utf-8?q?WY/XBfjPh/zBP48JcRc9pYAMy1b7sTFpXM+qQNG6W9MXWQi/TwV80JfvROFw0LjNM?= =?utf-8?q?DVEW56LU+DOz0bnrfAqrzal9wJmTrBMmoh026qL5DxhXYeT95lSqqVL/2x8SGk2dn?= =?utf-8?q?vQdi28/WFmz5ygH4911rMLnLqbsU7hsrME2lg6kqOyXnL+2oTcxHJs/puVrG8fe5H?= =?utf-8?q?Z7jdxIaRB23KphslEJAlvPdWk3f+nZm4a3TW5MYXKEVHl44rxxEOK01DBc4MLWc5I?= =?utf-8?q?9PrBSSIXuNM7o72JRbgdf53CkXRweJlctCeQJJbiGHvCD7G/258UaxFQTuF2SI8B8?=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=?utf-8?q?TYorEfHpnS0uceKOBROjLOBN8nV0+9EveWxVctUfU4ioJC3vl6PaC/fjEI5zj/AK8?= =?utf-8?q?eZU+KMMnLuVZuw+Jt+1nooF4Fer2dmtQCg=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: imgtec.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 4a5b3e7f-0f72-4954-3b17-08dcef8b5995 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2024 15:41:36.1641 (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: VOK57d2WcCabwPD4onX3hJlJjOJFZmXJwh8fG5t6ymbIe8S+VkCo1aGuTFnOeHGm90EiV2XCl6zsl/neVRDJ/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB2259 X-Authority-Analysis: v=2.4 cv=AcbjHGXG c=1 sm=1 tr=0 ts=671281b3 cx=c_pps a=Du42DVBbjaS4S3NNO6dabQ==:117 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=DAUX931o1VcA:10 a=WnR_qW7rlZcA:10 a=NgoYpvdbvlAA:10 a=r_1tXGB3AAAA:8 a=VwQbUJbxAAAA:8 a=ve1ODSZ0aD4dUIyBzsEA:9 a=QEXdDO2ut3YA:10 a=8WOXGegX6ja1v6kmIbUA:9 a=FfaGCDsud1wA:10 a=t8nPyN_e6usw4ciXM-Pk:22 X-Proofpoint-ORIG-GUID: ciBiJjBNHKyQ5E9F18mak3vZ0RkbKmas X-Proofpoint-GUID: ciBiJjBNHKyQ5E9F18mak3vZ0RkbKmas 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 adds a linked list of VM contexts which is needed for the next patch to be able to correctly track VM contexts for destruction on file close. It is only safe for VM contexts to be removed from the list and destroyed when not in interrupt context. Signed-off-by: Brendan King Signed-off-by: Matt Coster Reviewed-by: Frank Binns Cc: stable@vger.kernel.org --- Changes in v1 -> v2: - Add justification to the commit message so it stands on its own (e.g. during bisect) Changes in v2 -> v3: - Add Frank's Rb [1] - Add Cc: stable tag [1]: https://lore.kernel.org/dri-devel/1a206b08485a1ebea0aeff5306c0f5b6eb7c315d.camel@imgtec.com/ --- 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 b574e23d484b..6d0dfacb677b 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 Fri Oct 18 15:41:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Coster X-Patchwork-Id: 13841989 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 BC327D30019 for ; Fri, 18 Oct 2024 15:42:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F63F10E1D0; Fri, 18 Oct 2024 15:42:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=imgtec.com header.i=@imgtec.com header.b="jZTjkjtu"; dkim=pass (1024-bit key; unprotected) header.d=IMGTecCRM.onmicrosoft.com header.i=@IMGTecCRM.onmicrosoft.com header.b="prSYL7Pv"; 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 2D29E10E1D0 for ; Fri, 18 Oct 2024 15:42:01 +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 49ICP2Fx008181; Fri, 18 Oct 2024 16:41:42 +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=qHHwH7bI/YMEclJZwyZP4/j8V tKd3sP5jx62wQm9xJU=; b=jZTjkjtuEDzdjkOUjWntofDlAjiH7xQoUf0CdbZZa ki0BF1VRmJ845LxBwdVEHsG5pGACeENlojtjZlSacPI3Vx40qjhsJ3A92EY/geGf hBPkx0u6ZZygq3XiyYtfWNHAn/RdQS9DceS/SVNdt0Ky3o2YFcqH6YO5vhuVN0g+ 7GtKDVQG1bBxorzlGePDXR4CZo5VxxZRquYye09xNS+NHLBnGAGc+zwDueVBM3xA ua+xkaeh9q9ie8LF0ozdlqj4WwNDO6gmKrYwTTPNa9aYCNBwGGixuYOtG6LWBNo+ G8PhKiHRu9zC7yrGvqS0g8sA6FFxNYLSnRAvPGgwRHlkQ== Received: from cwxp265cu008.outbound.protection.outlook.com (mail-ukwestazlp17010004.outbound.protection.outlook.com [40.93.68.4]) by mx08-00376f01.pphosted.com (PPS) with ESMTPS id 42a3ac2nwq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 16:41:41 +0100 (BST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t6BdCNbEem42cYPg5/b89wczlVWEIl4p1GFDWt0uvBXZdSLvboLyC283mNPnjVjD1YlqRvjDoajDcpVgfymFNyNfSKOkDhLn5j4pCcFdNROSQcgEhwlGrQOluL4vNEfoX4nt5u0hTU3To4BLQnvWRsoeJAPn30nVBThFBBmvVFJx3oahEeMzWOg3D5s8lIOLWRdGNb31wt7xQVl0F5p04euzU9hqcFjmEW/Vw0jjWROs/F2mKSs9EqOk7KvDY4XIS/GxOUDNKCR2QOmlWCAYc0GCGqi5Pn5FMBx5tlvdglg+6cTeDjN/Cs+Fvsdck3aOwq8431I+lvZR2hVvTXcqPQ== 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=qHHwH7bI/YMEclJZwyZP4/j8VtKd3sP5jx62wQm9xJU=; b=kYrcFXXUYXWIyRH4m7c0oPGvwSI/70KgHzvoN7F/704R4VBgKTi2FCHZEWCX45MPW/8n4am/cMPmaEGu7hZzoq6qoI616OQ5jDArV9bjeqX5mJdrYY1NtoF6DYbQSyoW9eElpk6ltl8n1D12Seakp7n8P7nlE9IId+dJyrfAh6uvgkDLaxwgmJdRmw9+Ir6oV6yysPndAIav3lC3b6kxVQlDHPvF3QMDN6yx8CO+s3qUnOk7+WAP/yE5F0QyePXOzsRVspr5wxu8+V6fuYzfIPDgyP5oChD59VNB8xAKECKBBUD1akp76VbWqmO5hiqgnQV98P1WtY3J8uOUY+X1oA== 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=qHHwH7bI/YMEclJZwyZP4/j8VtKd3sP5jx62wQm9xJU=; b=prSYL7Pv8KaGwGUMZMxhbQnuYEdQq+Vony4lkuMald+Ao/MrAGw7lSCVu06WuIWIgBKevScUz7bMQNh+KQrvC+nmaWU0hRMoOq/Coy3e7uY3SUzCHKWjYR4TmMgZtzsbqUtw3ek+vIbGZUwwc25UQQ+mqZnlPw8+xbb9JEXCbzA= Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:e7::8) by CWLP265MB2259.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:6b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Fri, 18 Oct 2024 15:41:40 +0000 Received: from CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15]) by CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM ([fe80::8e9d:6b2f:9881:1e15%6]) with mapi id 15.20.8069.020; Fri, 18 Oct 2024 15:41:40 +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 v3 2/2] drm/imagination: Break an object reference loop Thread-Topic: [PATCH v3 2/2] drm/imagination: Break an object reference loop Thread-Index: AQHbIXQ5O6skwcFhHUq9t8DEiam/vw== Date: Fri, 18 Oct 2024 15:41:40 +0000 Message-ID: <8a25924f-1bb7-4d9a-a346-58e871dfb1d1@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_|CWLP265MB2259:EE_ x-ms-office365-filtering-correlation-id: 6ea76559-c70e-4b1c-8ee1-08dcef8b5be4 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|366016|376014|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?85KmgvL6FIYODbKqMJUbaVxuErHgt3y?= =?utf-8?q?Ns/e/wtiDePoBBXmHxs3pQEC96SoM+/XYYPqqi5ylIyuHcqLVT80jOaDVHhD+OUbb?= =?utf-8?q?OrGXe5UNAiA5+xCh4TEFx908BUIGcpbx6/RzUW4G9iDFgA6HOj/l4TM4DDlq7Qmq0?= =?utf-8?q?Bgu/3xtXiaaytkUiNrNDhELCTZ8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agvmI3zAjiQPP91fxUcCeWWj+8VpH22eJ4/?= =?utf-8?q?xYqc3jkW98dGLwHPcsVfTceoP+6DJ1jzWQH/L6DrCMqn16os30qZ50O4tUqEpX/qw?= =?utf-8?q?sdnLRDiIktgx4YoY5uM1bL6jGGHVYBHrSrIHh2qwTWCa2/aNb3tV4igruQanCtzkF?= =?utf-8?q?sNHMP76KiHeQ8klf9A2Kg8HgureNNTZJmzRv8ddPGOrxpFp5cYX9HWZ/zmyD9NT6b?= =?utf-8?q?GKEwofy+OsKjvnMFUqe+jlozWqsSMuhPhsOLe2ISTBktGPpoS6J+BAV2odSCv/fVr?= =?utf-8?q?ZzOMBeRYjLql?= 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)(1800799024)(366016)(376014)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?Olp2uq+7tPFKNi3euF0WrS5VB8Nh?= =?utf-8?q?MZ7Z2e6ElYba8PV1SEu/+irdhmFrH5HFmrf3IIVqy0SO0LUihDZ/ABmT38tPRZ5aq?= =?utf-8?q?/cwl2QNJ9BMXcNiJwpmwkNyvoH31Fke5tsuKsuC8woTSRrRlcGbOpSn6Hi5/HJPuj?= =?utf-8?q?hGU1RSEx1VTHZt8zMOxh0EcS3ZWXDkVbEntBiJQVV8FNwwO5mOPG0CLrJu26YQu6t?= =?utf-8?q?s3eEqGLdtSYmX8337QyLUTv1RnTUGO7ay7LlA5Yk209NyevzWNXKyN+UshSI6mZi8?= =?utf-8?q?BzcmHHlJ7wPhCVBFVRuZEHf2AhmvL+U0R4bpm8q9VK8e8xFZgBNJdMwAwTX9Vvu75?= =?utf-8?q?v4v8mC8iV+gO6lmx/rfs3tApU6JRmYn8X61J4dh4lpSutm3J46SMw4x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utf-8?q?PCGCzi5ZEAujPJrce31f8oKQvbIGZWciqZZlsOtgako25En4qz3F9BRJAaMnbJgFr?= =?utf-8?q?hNKuE2svVeZrQsL34PCXQGbNLHfRkib6wi2T9u+t0yAfNegMdQwetbUqKqz78nTg/?= =?utf-8?q?CP+XLKAR6v9Ccn8Q3XzzWvGeCJVkkesHtS0EsfN5G405B71zOPEXrukq4rdgB4URw?= =?utf-8?q?hPlu26tul3kumKUziEmIdFgI/wbzfW9d3qS/iCeyrFpf/a48QB18cAgK1UCXIFNYf?= =?utf-8?q?I3m+jfwQBrnjQEBJ194zB2FbXGaMllg79Q=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: imgtec.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB3397.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 6ea76559-c70e-4b1c-8ee1-08dcef8b5be4 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2024 15:41:40.0837 (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: YK09arh/dBhVX0VFfeGQpqQYa41vv+tHMz1W66ZfhuYDQuv7URdp1xd6tK256UwlY7WeDngQLCJKFEOPQL5W0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB2259 X-Authority-Analysis: v=2.4 cv=AcbjHGXG c=1 sm=1 tr=0 ts=671281b6 cx=c_pps a=tbUAc5YXJZE2aXMCunvlBA==:117 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=DAUX931o1VcA:10 a=WnR_qW7rlZcA:10 a=NgoYpvdbvlAA:10 a=r_1tXGB3AAAA:8 a=VwQbUJbxAAAA:8 a=2vpGiOW3mguWqdhXNEEA:9 a=QEXdDO2ut3YA:10 a=FQAv6l16WG0gR8wUSMMA:9 a=FfaGCDsud1wA:10 a=t8nPyN_e6usw4ciXM-Pk:22 X-Proofpoint-ORIG-GUID: oXZFUJlsOVUzBZYpeOXfONpDufMa_C5d X-Proofpoint-GUID: oXZFUJlsOVUzBZYpeOXfONpDufMa_C5d 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 Reviewed-by: Frank Binns Cc: stable@vger.kernel.org --- Changes in v1 -> v2: - None Changes in v2 -> v3: - Add Frank's Rb [1] - Add Cc: stable tag [1]: https://lore.kernel.org/dri-devel/b75e658cc5ce9ac24df2c31c1a6fd798a5f3a87f.camel@imgtec.com/ --- 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);