Skip to content

Commit ed8b670

Browse files
arndbairlied
authored andcommitted
drm: convert drm_ioctl to unlocked_ioctl
drm_ioctl is called with the Big Kernel Lock held, which shows up very high in statistics on vfs_ioctl. Moving the lock into the drm_ioctl function itself makes sure we blame the right subsystem and it gets us one step closer to eliminating the locked version of fops->ioctl. Since drm_ioctl does not require the lock itself, we only need to hold it while calling the specific handler. The 32 bit conversion handlers do not interact with any other code, so they don't need the BKL here either and can just call drm_ioctl. As a bonus, this cleans up all the other users of drm_ioctl which now no longer have to find the inode or call lock_kernel. [airlied: squashed the non-driver bits of the second patch in here, this provides the flag for drivers to use to select unlocked ioctls - but doesn't modify any drivers]. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: David Airlie <airlied@linux.ie> Cc: dri-devel@lists.sourceforge.net Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent dcd6dfc commit ed8b670

21 files changed

Lines changed: 89 additions & 140 deletions

File tree

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,19 @@ static int drm_version(struct drm_device *dev, void *data,
434434
* Looks up the ioctl function in the ::ioctls table, checking for root
435435
* previleges if so required, and dispatches to the respective function.
436436
*/
437-
int drm_ioctl(struct inode *inode, struct file *filp,
437+
long drm_ioctl(struct file *filp,
438438
unsigned int cmd, unsigned long arg)
439439
{
440440
struct drm_file *file_priv = filp->private_data;
441-
struct drm_device *dev = file_priv->minor->dev;
441+
struct drm_device *dev;
442442
struct drm_ioctl_desc *ioctl;
443443
drm_ioctl_t *func;
444444
unsigned int nr = DRM_IOCTL_NR(cmd);
445445
int retcode = -EINVAL;
446446
char stack_kdata[128];
447447
char *kdata = NULL;
448448

449+
dev = file_priv->minor->dev;
449450
atomic_inc(&dev->ioctl_count);
450451
atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
451452
++file_priv->ioctl_count;
@@ -501,7 +502,13 @@ int drm_ioctl(struct inode *inode, struct file *filp,
501502
goto err_i1;
502503
}
503504
}
504-
retcode = func(dev, kdata, file_priv);
505+
if (ioctl->flags & DRM_UNLOCKED)
506+
retcode = func(dev, kdata, file_priv);
507+
else {
508+
lock_kernel();
509+
retcode = func(dev, kdata, file_priv);
510+
unlock_kernel();
511+
}
505512

506513
if (cmd & IOC_OUT) {
507514
if (copy_to_user((void __user *)arg, kdata,

‎drivers/gpu/drm/drm_ioc32.c‎

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
104104
&version->desc))
105105
return -EFAULT;
106106

107-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
107+
err = drm_ioctl(file,
108108
DRM_IOCTL_VERSION, (unsigned long)version);
109109
if (err)
110110
return err;
@@ -145,8 +145,7 @@ static int compat_drm_getunique(struct file *file, unsigned int cmd,
145145
&u->unique))
146146
return -EFAULT;
147147

148-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
149-
DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
148+
err = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
150149
if (err)
151150
return err;
152151

@@ -174,8 +173,7 @@ static int compat_drm_setunique(struct file *file, unsigned int cmd,
174173
&u->unique))
175174
return -EFAULT;
176175

177-
return drm_ioctl(file->f_path.dentry->d_inode, file,
178-
DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
176+
return drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
179177
}
180178

181179
typedef struct drm_map32 {
@@ -205,8 +203,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
205203
if (__put_user(idx, &map->offset))
206204
return -EFAULT;
207205

208-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
209-
DRM_IOCTL_GET_MAP, (unsigned long)map);
206+
err = drm_ioctl(file, DRM_IOCTL_GET_MAP, (unsigned long)map);
210207
if (err)
211208
return err;
212209

@@ -246,8 +243,7 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
246243
|| __put_user(m32.flags, &map->flags))
247244
return -EFAULT;
248245

249-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
250-
DRM_IOCTL_ADD_MAP, (unsigned long)map);
246+
err = drm_ioctl(file, DRM_IOCTL_ADD_MAP, (unsigned long)map);
251247
if (err)
252248
return err;
253249

@@ -284,8 +280,7 @@ static int compat_drm_rmmap(struct file *file, unsigned int cmd,
284280
if (__put_user((void *)(unsigned long)handle, &map->handle))
285281
return -EFAULT;
286282

287-
return drm_ioctl(file->f_path.dentry->d_inode, file,
288-
DRM_IOCTL_RM_MAP, (unsigned long)map);
283+
return drm_ioctl(file, DRM_IOCTL_RM_MAP, (unsigned long)map);
289284
}
290285

291286
typedef struct drm_client32 {
@@ -314,8 +309,7 @@ static int compat_drm_getclient(struct file *file, unsigned int cmd,
314309
if (__put_user(idx, &client->idx))
315310
return -EFAULT;
316311

317-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
318-
DRM_IOCTL_GET_CLIENT, (unsigned long)client);
312+
err = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, (unsigned long)client);
319313
if (err)
320314
return err;
321315

@@ -351,8 +345,7 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
351345
if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
352346
return -EFAULT;
353347

354-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
355-
DRM_IOCTL_GET_STATS, (unsigned long)stats);
348+
err = drm_ioctl(file, DRM_IOCTL_GET_STATS, (unsigned long)stats);
356349
if (err)
357350
return err;
358351

@@ -395,8 +388,7 @@ static int compat_drm_addbufs(struct file *file, unsigned int cmd,
395388
|| __put_user(agp_start, &buf->agp_start))
396389
return -EFAULT;
397390

398-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
399-
DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
391+
err = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
400392
if (err)
401393
return err;
402394

@@ -427,8 +419,7 @@ static int compat_drm_markbufs(struct file *file, unsigned int cmd,
427419
|| __put_user(b32.high_mark, &buf->high_mark))
428420
return -EFAULT;
429421

430-
return drm_ioctl(file->f_path.dentry->d_inode, file,
431-
DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
422+
return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
432423
}
433424

434425
typedef struct drm_buf_info32 {
@@ -469,8 +460,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
469460
|| __put_user(list, &request->list))
470461
return -EFAULT;
471462

472-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
473-
DRM_IOCTL_INFO_BUFS, (unsigned long)request);
463+
err = drm_ioctl(file, DRM_IOCTL_INFO_BUFS, (unsigned long)request);
474464
if (err)
475465
return err;
476466

@@ -531,8 +521,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
531521
|| __put_user(list, &request->list))
532522
return -EFAULT;
533523

534-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
535-
DRM_IOCTL_MAP_BUFS, (unsigned long)request);
524+
err = drm_ioctl(file, DRM_IOCTL_MAP_BUFS, (unsigned long)request);
536525
if (err)
537526
return err;
538527

@@ -578,8 +567,7 @@ static int compat_drm_freebufs(struct file *file, unsigned int cmd,
578567
&request->list))
579568
return -EFAULT;
580569

581-
return drm_ioctl(file->f_path.dentry->d_inode, file,
582-
DRM_IOCTL_FREE_BUFS, (unsigned long)request);
570+
return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, (unsigned long)request);
583571
}
584572

585573
typedef struct drm_ctx_priv_map32 {
@@ -605,8 +593,7 @@ static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
605593
&request->handle))
606594
return -EFAULT;
607595

608-
return drm_ioctl(file->f_path.dentry->d_inode, file,
609-
DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
596+
return drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
610597
}
611598

612599
static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
@@ -628,8 +615,7 @@ static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
628615
if (__put_user(ctx_id, &request->ctx_id))
629616
return -EFAULT;
630617

631-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
632-
DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
618+
err = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
633619
if (err)
634620
return err;
635621

@@ -664,8 +650,7 @@ static int compat_drm_resctx(struct file *file, unsigned int cmd,
664650
&res->contexts))
665651
return -EFAULT;
666652

667-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
668-
DRM_IOCTL_RES_CTX, (unsigned long)res);
653+
err = drm_ioctl(file, DRM_IOCTL_RES_CTX, (unsigned long)res);
669654
if (err)
670655
return err;
671656

@@ -718,8 +703,7 @@ static int compat_drm_dma(struct file *file, unsigned int cmd,
718703
&d->request_sizes))
719704
return -EFAULT;
720705

721-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
722-
DRM_IOCTL_DMA, (unsigned long)d);
706+
err = drm_ioctl(file, DRM_IOCTL_DMA, (unsigned long)d);
723707
if (err)
724708
return err;
725709

@@ -751,8 +735,7 @@ static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
751735
if (put_user(m32.mode, &mode->mode))
752736
return -EFAULT;
753737

754-
return drm_ioctl(file->f_path.dentry->d_inode, file,
755-
DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
738+
return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
756739
}
757740

758741
typedef struct drm_agp_info32 {
@@ -781,8 +764,7 @@ static int compat_drm_agp_info(struct file *file, unsigned int cmd,
781764
if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
782765
return -EFAULT;
783766

784-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
785-
DRM_IOCTL_AGP_INFO, (unsigned long)info);
767+
err = drm_ioctl(file, DRM_IOCTL_AGP_INFO, (unsigned long)info);
786768
if (err)
787769
return err;
788770

@@ -827,16 +809,14 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
827809
|| __put_user(req32.type, &request->type))
828810
return -EFAULT;
829811

830-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
831-
DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
812+
err = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
832813
if (err)
833814
return err;
834815

835816
if (__get_user(req32.handle, &request->handle)
836817
|| __get_user(req32.physical, &request->physical)
837818
|| copy_to_user(argp, &req32, sizeof(req32))) {
838-
drm_ioctl(file->f_path.dentry->d_inode, file,
839-
DRM_IOCTL_AGP_FREE, (unsigned long)request);
819+
drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
840820
return -EFAULT;
841821
}
842822

@@ -856,8 +836,7 @@ static int compat_drm_agp_free(struct file *file, unsigned int cmd,
856836
|| __put_user(handle, &request->handle))
857837
return -EFAULT;
858838

859-
return drm_ioctl(file->f_path.dentry->d_inode, file,
860-
DRM_IOCTL_AGP_FREE, (unsigned long)request);
839+
return drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
861840
}
862841

863842
typedef struct drm_agp_binding32 {
@@ -881,8 +860,7 @@ static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
881860
|| __put_user(req32.offset, &request->offset))
882861
return -EFAULT;
883862

884-
return drm_ioctl(file->f_path.dentry->d_inode, file,
885-
DRM_IOCTL_AGP_BIND, (unsigned long)request);
863+
return drm_ioctl(file, DRM_IOCTL_AGP_BIND, (unsigned long)request);
886864
}
887865

888866
static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
@@ -898,8 +876,7 @@ static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
898876
|| __put_user(handle, &request->handle))
899877
return -EFAULT;
900878

901-
return drm_ioctl(file->f_path.dentry->d_inode, file,
902-
DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
879+
return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
903880
}
904881
#endif /* __OS_HAS_AGP */
905882

@@ -923,8 +900,7 @@ static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
923900
|| __put_user(x, &request->size))
924901
return -EFAULT;
925902

926-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
927-
DRM_IOCTL_SG_ALLOC, (unsigned long)request);
903+
err = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, (unsigned long)request);
928904
if (err)
929905
return err;
930906

@@ -950,8 +926,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
950926
|| __put_user(x << PAGE_SHIFT, &request->handle))
951927
return -EFAULT;
952928

953-
return drm_ioctl(file->f_path.dentry->d_inode, file,
954-
DRM_IOCTL_SG_FREE, (unsigned long)request);
929+
return drm_ioctl(file, DRM_IOCTL_SG_FREE, (unsigned long)request);
955930
}
956931

957932
#if defined(CONFIG_X86) || defined(CONFIG_IA64)
@@ -981,8 +956,7 @@ static int compat_drm_update_draw(struct file *file, unsigned int cmd,
981956
__put_user(update32.data, &request->data))
982957
return -EFAULT;
983958

984-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
985-
DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
959+
err = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
986960
return err;
987961
}
988962
#endif
@@ -1023,8 +997,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
1023997
|| __put_user(req32.request.signal, &request->request.signal))
1024998
return -EFAULT;
1025999

1026-
err = drm_ioctl(file->f_path.dentry->d_inode, file,
1027-
DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
1000+
err = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
10281001
if (err)
10291002
return err;
10301003

@@ -1094,16 +1067,14 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
10941067
* than always failing.
10951068
*/
10961069
if (nr >= ARRAY_SIZE(drm_compat_ioctls))
1097-
return drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
1070+
return drm_ioctl(filp, cmd, arg);
10981071

10991072
fn = drm_compat_ioctls[nr];
11001073

1101-
lock_kernel(); /* XXX for now */
11021074
if (fn != NULL)
11031075
ret = (*fn) (filp, cmd, arg);
11041076
else
1105-
ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
1106-
unlock_kernel();
1077+
ret = drm_ioctl(filp, cmd, arg);
11071078

11081079
return ret;
11091080
}

‎drivers/gpu/drm/i810/i810_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
115115
static const struct file_operations i810_buffer_fops = {
116116
.open = drm_open,
117117
.release = drm_release,
118-
.ioctl = drm_ioctl,
118+
.unlocked_ioctl = drm_ioctl,
119119
.mmap = i810_mmap_buffers,
120120
.fasync = drm_fasync,
121121
};

‎drivers/gpu/drm/i810/i810_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static struct drm_driver driver = {
5959
.owner = THIS_MODULE,
6060
.open = drm_open,
6161
.release = drm_release,
62-
.ioctl = drm_ioctl,
62+
.unlocked_ioctl = drm_ioctl,
6363
.mmap = drm_mmap,
6464
.poll = drm_poll,
6565
.fasync = drm_fasync,

‎drivers/gpu/drm/i830/i830_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
117117
static const struct file_operations i830_buffer_fops = {
118118
.open = drm_open,
119119
.release = drm_release,
120-
.ioctl = drm_ioctl,
120+
.unlocked_ioctl = drm_ioctl,
121121
.mmap = i830_mmap_buffers,
122122
.fasync = drm_fasync,
123123
};

‎drivers/gpu/drm/i830/i830_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static struct drm_driver driver = {
7070
.owner = THIS_MODULE,
7171
.open = drm_open,
7272
.release = drm_release,
73-
.ioctl = drm_ioctl,
73+
.unlocked_ioctl = drm_ioctl,
7474
.mmap = drm_mmap,
7575
.poll = drm_poll,
7676
.fasync = drm_fasync,

‎drivers/gpu/drm/i915/i915_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static struct drm_driver driver = {
329329
.owner = THIS_MODULE,
330330
.open = drm_open,
331331
.release = drm_release,
332-
.ioctl = drm_ioctl,
332+
.unlocked_ioctl = drm_ioctl,
333333
.mmap = drm_gem_mmap,
334334
.poll = drm_poll,
335335
.fasync = drm_fasync,

0 commit comments

Comments
 (0)