From a1d9e5abafe60ca2b7f96cadd1013695ada4ac41 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Sun, 7 Nov 2004 04:11:15 +0000 Subject: Refine the locking of the DRM. Most significant is covering the driver ioctls with dev_lock, which is a major step toward being able to remove Giant. Covers some new pieces (dev->unique*) in the core, and avoids one call down into system internals with the drm lock held, which is usually bad (FreeBSD LOR #23, #27). --- bsd-core/drm_drv.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'bsd-core/drm_drv.c') diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c index 7880f76c..fb9313af 100644 --- a/bsd-core/drm_drv.c +++ b/bsd-core/drm_drv.c @@ -809,9 +809,17 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, drm_ioctl_desc_t *ioctl; int (*func)(DRM_IOCTL_ARGS); int nr = DRM_IOCTL_NR(cmd); + int is_driver_ioctl = 0; drm_file_t *priv; + DRMFILE filp = (DRMFILE)(uintptr_t)DRM_CURRENTPID; - DRM_GET_PRIV_WITH_RETURN(priv, (DRMFILE)(uintptr_t)DRM_CURRENTPID); + DRM_LOCK(); + priv = drm_find_file_by_proc(dev, p); + DRM_UNLOCK(); + if (priv == NULL) { + DRM_ERROR("can't find authenticator\n"); + return EINVAL; + } atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] ); ++priv->ioctl_count; @@ -868,6 +876,7 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, return EINVAL; } ioctl = &dev->driver_ioctls[nr]; + is_driver_ioctl = 1; } func = ioctl->func; @@ -879,7 +888,11 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, !priv->authenticated)) return EACCES; - retcode = func(kdev, cmd, data, flags, p, (void *)(uintptr_t)DRM_CURRENTPID); + if (is_driver_ioctl) + DRM_LOCK(); + retcode = func(kdev, cmd, data, flags, p, filp); + if (is_driver_ioctl) + DRM_UNLOCK(); if (retcode != 0) DRM_DEBUG(" returning %d\n", retcode); -- cgit v1.2.3