Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drm/panthor: Restrict high priorities on group_create #260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions drivers/gpu/drm/panthor/panthor_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>

#include <drm/drm_auth.h>
#include <drm/drm_drv.h>
#include <drm/drm_exec.h>
#include <drm/drm_ioctl.h>
Expand Down Expand Up @@ -995,6 +996,24 @@ static int panthor_ioctl_group_destroy(struct drm_device *ddev, void *data,
return panthor_group_destroy(pfile, args->group_handle);
}

static int group_priority_permit(struct drm_file *file,
u8 priority)
{
/* Ensure that priority is valid */
if (priority > PANTHOR_GROUP_PRIORITY_HIGH)
return -EINVAL;

/* Medium priority and below are always allowed */
if (priority <= PANTHOR_GROUP_PRIORITY_MEDIUM)
return 0;

/* Higher priorities require CAP_SYS_NICE or DRM_MASTER */
if (capable(CAP_SYS_NICE) || drm_is_current_master(file))
return 0;

return -EACCES;
}

static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
struct drm_file *file)
{
Expand All @@ -1010,6 +1029,10 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
if (ret)
return ret;

ret = group_priority_permit(file, args->priority);
if (ret)
return ret;

ret = panthor_group_create(pfile, args, queue_args);
if (ret >= 0) {
args->group_handle = ret;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/panthor/panthor_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,7 @@ int panthor_group_create(struct panthor_file *pfile,
if (group_args->pad)
return -EINVAL;

if (group_args->priority > PANTHOR_CSG_PRIORITY_HIGH)
if (group_args->priority >= PANTHOR_CSG_PRIORITY_COUNT)
return -EINVAL;

if ((group_args->compute_core_mask & ~ptdev->gpu_info.shader_present) ||
Expand Down
6 changes: 5 additions & 1 deletion include/uapi/drm/panthor_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,11 @@ enum drm_panthor_group_priority {
/** @PANTHOR_GROUP_PRIORITY_MEDIUM: Medium priority group. */
PANTHOR_GROUP_PRIORITY_MEDIUM,

/** @PANTHOR_GROUP_PRIORITY_HIGH: High priority group. */
/**
* @PANTHOR_GROUP_PRIORITY_HIGH: High priority group.
*
* Requires CAP_SYS_NICE or DRM_MASTER.
*/
PANTHOR_GROUP_PRIORITY_HIGH,
};

Expand Down