Skip to content

Commit

Permalink
Support non-root gdev with render nodes
Browse files Browse the repository at this point in the history
Close #30

Leveraging newly added DRM *render nodes* architecture,
DRM can restrict the priviledges to render nodes with file based permission.
So, by opening splitted `/dev/dri/renderD%d` device file, if the user have
permission to this file, the user can execute GPGPU applications without root
permission.
Currently, typically, `video` group is allowed to access this device file.
So by adding the user to `video` group, the non-root user can use gdev.

[1]: http://dvdhrm.wordpress.com/2013/05/29/drm-render-and-modeset-nodes/
  • Loading branch information
Constellation committed Oct 22, 2014
1 parent 473fc27 commit ee09b74
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lib/user/nouveau/nouveau_gdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,17 @@ int gdev_raw_query(struct gdev_device *gdev, uint32_t type, uint64_t *result)
return -EINVAL;
}

static int __gdev_open_by_minor(const char* name, int minor)
#define GDEV_DRM_LEGACY_DEV_NAME DRM_DEV_NAME
#define GDEV_DRM_RENDER_DEV_NAME "%s/renderD%d"

static int __gdev_open_by_minor(const char* template, const char* name, int minor)
{
int fd;
int matched;
char buf[64];
drmVersionPtr version;

sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
sprintf(buf, template, DRM_DIR_NAME, minor);
if ((fd = open(buf, O_RDWR, 0)) < 0) {
return -errno;
}
Expand All @@ -170,13 +173,35 @@ static int __gdev_open_by_minor(const char* name, int minor)
return -ENODEV;
}

static int __gdev_open_legacy_by_minor(const char* name, int minor)
{
return __gdev_open_by_minor(GDEV_DRM_LEGACY_DEV_NAME, name, minor);
}

static int __gdev_open_render_by_minor(const char* name, int minor)
{
return __gdev_open_by_minor(GDEV_DRM_RENDER_DEV_NAME, name, minor);
}

static int __gdev_open_by_ordinal(const char* name, int ordinal)
{
int count = 0;
int i;
/* Opening render nodes renderD%d dev */
for (i = 64 * 2; i < (64 * 3); ++i) {
int fd = 0;
if ((fd = __gdev_open_render_by_minor(name, i)) >= 0) {
if (count++ == ordinal) {
return fd;
}
close(fd);
}
}

/* Opening legacy card%d dev */
for (i = 0; i < DRM_MAX_MINOR; ++i) {
int fd = 0;
if ((fd = __gdev_open_by_minor(name, i)) >= 0) {
if ((fd = __gdev_open_legacy_by_minor(name, i)) >= 0) {
if (count++ == ordinal) {
return fd;
}
Expand Down

0 comments on commit ee09b74

Please sign in to comment.