Skip to content

Commit

Permalink
device_cgroup: Export devcgroup_check_permission
Browse files Browse the repository at this point in the history
For AMD compute (amdkfd) driver.

All AMD compute devices are exported via single device node /dev/kfd. As
a result devices cannot be controlled individually using device cgroup.

AMD compute devices will rely on its graphics counterpart that exposes
/dev/dri/renderN node for each device. For each task (based on its
cgroup), KFD driver will check if /dev/dri/renderN node is accessible
before exposing it.

Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
hkasivis authored and alexdeucher committed Oct 7, 2019
1 parent a3e520a commit 4b7d4d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
19 changes: 4 additions & 15 deletions include/linux/device_cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,15 @@
#define DEVCG_DEV_ALL 4 /* this represents all devices */

#ifdef CONFIG_CGROUP_DEVICE
extern int __devcgroup_check_permission(short type, u32 major, u32 minor,
short access);
int devcgroup_check_permission(short type, u32 major, u32 minor,
short access);
#else
static inline int __devcgroup_check_permission(short type, u32 major, u32 minor,
short access)
static inline int devcgroup_check_permission(short type, u32 major, u32 minor,
short access)
{ return 0; }
#endif

#if defined(CONFIG_CGROUP_DEVICE) || defined(CONFIG_CGROUP_BPF)
static inline int devcgroup_check_permission(short type, u32 major, u32 minor,
short access)
{
int rc = BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type, major, minor, access);

if (rc)
return -EPERM;

return __devcgroup_check_permission(type, major, minor, access);
}

static inline int devcgroup_inode_permission(struct inode *inode, int mask)
{
short type, access = 0;
Expand Down
15 changes: 13 additions & 2 deletions security/device_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ struct cgroup_subsys devices_cgrp_subsys = {
*
* returns 0 on success, -EPERM case the operation is not permitted
*/
int __devcgroup_check_permission(short type, u32 major, u32 minor,
short access)
static int __devcgroup_check_permission(short type, u32 major, u32 minor,
short access)
{
struct dev_cgroup *dev_cgroup;
bool rc;
Expand All @@ -824,3 +824,14 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,

return 0;
}

int devcgroup_check_permission(short type, u32 major, u32 minor, short access)
{
int rc = BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type, major, minor, access);

if (rc)
return -EPERM;

return __devcgroup_check_permission(type, major, minor, access);
}
EXPORT_SYMBOL(devcgroup_check_permission);

0 comments on commit 4b7d4d4

Please sign in to comment.