diff mbox series

[RFC,3/4] uapi: Add RLIMIT_GPUPRIO

Message ID 20230403194058.25958-4-joshua@froggi.es (mailing list archive)
State New, archived
Headers show
Series uapi, drm: Add and implement RLIMIT_GPUPRIO | expand

Commit Message

Joshua Ashton April 3, 2023, 7:40 p.m. UTC
Introduce a new RLIMIT that allows the user to set a runtime limit on
the GPU scheduler priority for tasks.

This avoids the need for leased compositors such as SteamVR's
vrcompositor to be launched via a setcap'ed executable with
CAP_SYS_NICE.

This is required for SteamVR as it doesn't run as a DRM master, but
rather on a DRM lease using the HMD's connector.

The current situation is bad for a few reasons, one being that in order
to setcap the executable, typically one must run as root which involves
a pretty high privelage escalation in order to achieve one
small feat, a realtime async compute queue queue for VR or a compositor.
The executable cannot be setcap'ed inside a
container nor can the setcap'ed executable be run in a container with
NO_NEW_PRIVS.

Even in cases where one may think the DRM master check to be useful,
such as Gamescope where it is the DRM master, the part of the compositor
that runs as the DRM master is entirely separate to the Vulkan device
with it's own DRM device fd doing the GPU work that demands the
realtime priority queue. Additionally, Gamescope can also run nested
in a traditional compositor where there is no DRM master, but having a
realtime queue is still advantageous.

With adding RLIMIT_GPUPRIO, a process outside of a container or
eg. rtkit could call `prlimit` on the process inside to allow it to make
a realtime queue and solve these problems.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
---
 fs/proc/base.c                      | 1 +
 include/asm-generic/resource.h      | 3 ++-
 include/uapi/asm-generic/resource.h | 3 ++-
 3 files changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 5e0e0ccd47aa..a5c9a9f23f08 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -589,6 +589,7 @@  static const struct limit_names lnames[RLIM_NLIMITS] = {
 	[RLIMIT_NICE] = {"Max nice priority", NULL},
 	[RLIMIT_RTPRIO] = {"Max realtime priority", NULL},
 	[RLIMIT_RTTIME] = {"Max realtime timeout", "us"},
+	[RLIMIT_GPUPRIO] = {"Max DRM GPU priority", NULL},
 };
 
 /* Display limits for a process */
diff --git a/include/asm-generic/resource.h b/include/asm-generic/resource.h
index 8874f681b056..cefee1a8d9db 100644
--- a/include/asm-generic/resource.h
+++ b/include/asm-generic/resource.h
@@ -3,7 +3,7 @@ 
 #define _ASM_GENERIC_RESOURCE_H
 
 #include <uapi/asm-generic/resource.h>
-
+#include <drm/drm_sched_priority.h>
 
 /*
  * boot-time rlimit defaults for the init task:
@@ -26,6 +26,7 @@ 
 	[RLIMIT_NICE]		= { 0, 0 },				\
 	[RLIMIT_RTPRIO]		= { 0, 0 },				\
 	[RLIMIT_RTTIME]		= {  RLIM_INFINITY,  RLIM_INFINITY },	\
+	[RLIMIT_GPUPRIO]	= { DRM_SCHED_PRIORITY_NORMAL, DRM_SCHED_PRIORITY_NORMAL },		\
 }
 
 #endif
diff --git a/include/uapi/asm-generic/resource.h b/include/uapi/asm-generic/resource.h
index f12db7a0da64..85027b07a420 100644
--- a/include/uapi/asm-generic/resource.h
+++ b/include/uapi/asm-generic/resource.h
@@ -46,7 +46,8 @@ 
 					   0-39 for nice level 19 .. -20 */
 #define RLIMIT_RTPRIO		14	/* maximum realtime priority */
 #define RLIMIT_RTTIME		15	/* timeout for RT tasks in us */
-#define RLIM_NLIMITS		16
+#define RLIMIT_GPUPRIO		16	/* maximum GPU priority */
+#define RLIM_NLIMITS		17
 
 /*
  * SuS says limits have to be unsigned.