From 48e383a1b9a3eb260128caa4aa83b7e2d65f5e73 Mon Sep 17 00:00:00 2001 From: Mikko Perttunen Date: Wed, 15 Jan 2025 07:24:36 +0000 Subject: [PATCH] drm/tegra: Add option for explicit syncpoint free Add kernel module parameter to enable a mode where syncpoints must be freed explicitly (using the free IOCTL) or they will be left dangling. This ensures that, for particularly locked down configurations, a syncpoint will be forever left in an expected state even if the process owning it dies -- for example another process will not be able to allocate it. Change-Id: I2f350c710775a296c70910df21e95737a36c6a45 Signed-off-by: Mikko Perttunen Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3284405 GVS: buildbot_gerritrpt Reviewed-by: Santosh BS --- .../tegra/include/uapi/drm/tegra_drm_next.h | 2 +- drivers/gpu/drm/tegra/uapi.c | 18 +++++++++++++++--- drivers/gpu/drm/tegra/uapi.h | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/tegra/include/uapi/drm/tegra_drm_next.h b/drivers/gpu/drm/tegra/include/uapi/drm/tegra_drm_next.h index e2637765..3ef63a59 100644 --- a/drivers/gpu/drm/tegra/include/uapi/drm/tegra_drm_next.h +++ b/drivers/gpu/drm/tegra/include/uapi/drm/tegra_drm_next.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: MIT */ -/* Copyright (c) 2012-2020 NVIDIA Corporation */ +/* Copyright (c) 2012-2025 NVIDIA Corporation */ #ifndef _UAPI_TEGRA_DRM_H_ #define _UAPI_TEGRA_DRM_H_ diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c index 70de9bd3..b7cdbde0 100644 --- a/drivers/gpu/drm/tegra/uapi.c +++ b/drivers/gpu/drm/tegra/uapi.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2020 NVIDIA Corporation */ +/* Copyright (c) 2020-2025 NVIDIA Corporation */ #include #include @@ -13,6 +13,10 @@ #include "drm.h" #include "uapi.h" +static bool explicit_syncpt_free; +module_param(explicit_syncpt_free, bool, 0644); +MODULE_PARM_DESC(explicit_syncpt_free, "If enabled, syncpoints need to be explicitly freed via IOCTL or they will be left dangling when the fd is closed"); + static void tegra_drm_mapping_release(struct kref *ref) { struct tegra_drm_mapping *mapping = @@ -60,8 +64,16 @@ void tegra_drm_uapi_close_file(struct tegra_drm_file *file) xa_for_each(&file->contexts, id, context) tegra_drm_channel_context_close(context); - xa_for_each(&file->syncpoints, id, sp) - host1x_syncpt_put(sp); + /* + * If explicit_syncpt_free is enabled, users must free syncpoints + * explicitly or they will be left dangling. This prevents syncpoints + * from getting in an unexpected state if e.g. the application crashes. + * Obviously only usable on particularly locked down configurations. + */ + if (!explicit_syncpt_free) { + xa_for_each(&file->syncpoints, id, sp) + host1x_syncpt_put(sp); + } xa_destroy(&file->contexts); xa_destroy(&file->syncpoints); diff --git a/drivers/gpu/drm/tegra/uapi.h b/drivers/gpu/drm/tegra/uapi.h index 3c8b24ae..5f9c82c7 100644 --- a/drivers/gpu/drm/tegra/uapi.h +++ b/drivers/gpu/drm/tegra/uapi.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -/* Copyright (c) 2020 NVIDIA Corporation */ +/* Copyright (c) 2020-2025 NVIDIA Corporation */ #ifndef _TEGRA_DRM_UAPI_H #define _TEGRA_DRM_UAPI_H