Skip to content

Commit

Permalink
fix/gpu: memory leak when launch weston
Browse files Browse the repository at this point in the history
sync framework will call PVRSRVDeviceSyncOpen to allocate psConnection
and hOsPrivateData which has no chance to release these kernel buffer.

Change-Id: Ibcb8c255f5c5de9861b22ef7cb560f585f2daf66
  • Loading branch information
dengbo authored and kevin-zhm committed Dec 7, 2024
1 parent ee8d944 commit 766bb65
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion drivers/gpu/drm/img-rogue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ pvrsrvkm-y += \
spacemit/sysconfig.o \
spacemit/spacemit_init.o \
server_rgxkicksync_bridge.o \
rgxkicksync.o
rgxkicksync.o \
pvr_sync_ioctl_common.o \
pvr_sync_ioctl_drm.o
pvrsrvkm-$(CONFIG_ARM) += osfunc_arm.o
pvrsrvkm-$(CONFIG_ARM64) += osfunc_arm64.o
pvrsrvkm-$(CONFIG_EVENT_TRACING) += trace_events.o pvr_gputrace.o
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/img-rogue/connection_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ PVRSRV_ERROR PVRSRVCommonConnectionConnect(void **ppvPrivData, void *pvOSData)
/* Allocate connection data area, no stats since process not registered yet */
psConnection = OSAllocZMemNoStats(sizeof(*psConnection));
PVR_LOG_RETURN_IF_NOMEM(psConnection, "psConnection");
psConnection->bSyncConnection = IMG_FALSE;

/* Allocate process statistics as early as possible to catch all allocs */
#if defined(PVRSRV_ENABLE_PROCESS_STATS) && !defined(PVRSRV_DEBUG_LINUX_MEMORY_STATS)
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/img-rogue/connection_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef struct _CONNECTION_DATA_
/* List navigation for deferred freeing of connection data */
struct _CONNECTION_DATA_ **ppsThis;
struct _CONNECTION_DATA_ *psNext;
IMG_BOOL bSyncConnection;
} CONNECTION_DATA;

#include "osconnection_server.h"
Expand Down
14 changes: 13 additions & 1 deletion drivers/gpu/drm/img-rogue/module_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ static int PVRSRVDeviceSyncOpen(PVRSRV_DEVICE_NODE *psDeviceNode,
iErr = -ENOMEM;
goto fail_alloc_connection;
}
psConnection->bSyncConnection = IMG_TRUE;
#if (PVRSRV_DEVICE_INIT_MODE == PVRSRV_LINUX_DEV_INIT_ON_CONNECT)
psConnectionPriv->pvConnectionData = (void*)psConnection;
#else
Expand Down Expand Up @@ -686,6 +687,7 @@ static int PVRSRVDeviceSyncOpen(PVRSRV_DEVICE_NODE *psDeviceNode,
void PVRSRVDeviceRelease(PVRSRV_DEVICE_NODE *psDeviceNode,
struct drm_file *psDRMFile)
{
CONNECTION_DATA *psConnection = NULL;
PVR_UNREFERENCED_PARAMETER(psDeviceNode);

if (psDRMFile->driver_priv)
Expand Down Expand Up @@ -717,8 +719,18 @@ void PVRSRVDeviceRelease(PVRSRV_DEVICE_NODE *psDeviceNode,
pvr_sync_close(psConnectionPriv->pvSyncConnectionData);
#endif
#endif
psConnection = psConnectionPriv->pvConnectionData;
if (psConnection->bSyncConnection == IMG_TRUE)
{
if (psConnection->hOsPrivateData != NULL)
{
OSConnectionPrivateDataDeInit(psConnection->hOsPrivateData);
psConnection->hOsPrivateData = NULL;
}
kfree(psConnection);
psConnection = NULL;
}
}

kfree(psDRMFile->driver_priv);
psDRMFile->driver_priv = NULL;
}
Expand Down

0 comments on commit 766bb65

Please sign in to comment.