Skip to contentSkip to conversation

drm cruft removal

PATCH In review Daniel Vetter 7 participants 40 messages Aug 8, 2013 – Aug 15, 2013

Subsystems (18)
lore
Share & tools
lore
#0 lore raw

cover drm cruft removal

Hi all,

So a bunch of patches went in already, and a few of the ones here small fixups (DocBook, compile fail for funny .configs and 1 unused variable). And slight rebasing on top of David's drm_dev cleanup refactoring. The big change is that the get_client ioclt isn't a complete noop now but fakes enough of the old thing so that libva will keep on working - libva uses the get_client ioctl to figure out whether it's authenticated or not.

Of course I've dutifully taken that libva code and pressed it into an igt testcase to make sure we don't break anything.

r-b tags and acks for individual patches I've added, but there's the overall review from Alex and testing from David on the series:

Comments and review highly welcome and please consider merging for drm-next.

Note that the patch "drm/imx: kill firstopen callback" is already merged into the staging tree, but it's probably simplest if we merge it again through drm-next.

Thanks, Daniel

Daniel Vetter (25):
drm/omap: kill firstopen callback
drm/radeon: kill firstopen callback for kms driver drm/imx: kill firstopen callback
drm/vmwgfx: remove ->firstopen callback
drm: don't call ->firstopen for KMS drivers
drm: kill dev->driver->set_version
drm: hide legacy sg cleanup better from common code
drm: disallow legacy sg ioctls for modesetting drivers
drm: mark dma setup/teardown as legacy systems
drm: disallow legacy dma ioctls for modesetting drivers
drm: mark context support as a legacy subsystem drm/vmwgfx: remove redundant clearing of driver->dma_quiescent
drm: remove FASYNC support
drm: rip out DRIVER_FB_DMA and related code
drm: rip out a few unused DRIVER flags
drm: remove a bunch of unused #defines from drmP.h
drm: rip out drm_core_has_MTRR checks
drm/docs: rip out removed driver flags documentation
drm: remove the dma_ioctl special-case
drm/memory: don't export agp helpers
drm: hollow-out GET_CLIENT ioctl
drm: no-op out GET_STATS ioctl
drm: fix locking in gem debugfs/procfs file
drm: remove procfs code, take 2
drm: move dev data clearing from drm_setup to lastclose

 Documentation/DocBook/drm.tmpl           |  57 +++------
 drivers/gpu/drm/Makefile                 |   2 +-
 drivers/gpu/drm/ast/ast_drv.c            |   3 +-
 drivers/gpu/drm/cirrus/cirrus_drv.c      |   3 +-
 drivers/gpu/drm/drm_bufs.c               | 201 +++++------------------------
 drivers/gpu/drm/drm_context.c            |  73 +++++++++--
 drivers/gpu/drm/drm_dma.c                |  17 ++-
 drivers/gpu/drm/drm_drv.c                |  51 ++++----
 drivers/gpu/drm/drm_fops.c               |  71 +----------
 drivers/gpu/drm/drm_info.c               |   4 +
 drivers/gpu/drm/drm_ioctl.c              |  59 ++++-----
 drivers/gpu/drm/drm_memory.c             |   2 -
 drivers/gpu/drm/drm_pci.c                |  14 +--
 drivers/gpu/drm/drm_proc.c               | 209 -------------------------------
 drivers/gpu/drm/drm_scatter.c            |  16 ++-
 drivers/gpu/drm/drm_stub.c               |  42 ++-----
 drivers/gpu/drm/drm_vm.c                 |   3 +-
 drivers/gpu/drm/gma500/psb_drv.c         |   3 +-
 drivers/gpu/drm/i810/i810_dma.c          |   1 -
 drivers/gpu/drm/i810/i810_drv.c          |   3 +-
 drivers/gpu/drm/i915/i915_drv.c          |   3 +-
 drivers/gpu/drm/mga/mga_drv.c            |   3 +-
 drivers/gpu/drm/mgag200/mgag200_drv.c    |   3 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c    |   1 -
 drivers/gpu/drm/omapdrm/omap_drv.c       |   8 --
 drivers/gpu/drm/qxl/qxl_drv.c            |   1 -
 drivers/gpu/drm/r128/r128_drv.c          |   3 +-
 drivers/gpu/drm/radeon/radeon_drv.c      |   8 +-
 drivers/gpu/drm/radeon/radeon_kms.c      |  13 --
 drivers/gpu/drm/rcar-du/rcar_du_drv.c    |   1 -
 drivers/gpu/drm/savage/savage_drv.c      |   3 +-
 drivers/gpu/drm/shmobile/shmob_drm_drv.c |   1 -
 drivers/gpu/drm/sis/sis_drv.c            |   3 +-
 drivers/gpu/drm/tdfx/tdfx_drv.c          |   2 -
 drivers/gpu/drm/tilcdc/tilcdc_drv.c      |   1 -
 drivers/gpu/drm/udl/udl_drv.c            |   1 -
 drivers/gpu/drm/via/via_drv.c            |   3 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c      |  20 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h      |   1 -
 drivers/gpu/host1x/drm/drm.c             |   1 -
 drivers/staging/imx-drm/imx-drm-core.c   |  21 +---
 include/drm/drmP.h                       |  52 ++------
 42 files changed, 253 insertions(+), 734 deletions(-)
 delete mode 100644 drivers/gpu/drm/drm_proc.c
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/25 drm/omap: kill firstopen callback

KMS drivers really shouldn't need to do anything on firstopen, so kill empty callbacks.

---
 drivers/gpu/drm/omapdrm/omap_drv.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +0 -7
index 2f9e22e..47e64f9 100644
@@ -524,12 +524,6 @@ static int dev_open(struct drm_device *dev, struct drm_file *file)
 	return 0;
 }
 
-static int dev_firstopen(struct drm_device *dev)
-{
-	DBG("firstopen: dev=%p", dev);
-	return 0;
-}
-
 /**
  * lastclose - clean up after all DRM clients have exited
  * @dev: DRM device
@@ -609,7 +603,6 @@ static struct drm_driver omap_drm_driver = {
 		.load = dev_load,
 		.unload = dev_unload,
 		.open = dev_open,
-		.firstopen = dev_firstopen,
 		.lastclose = dev_lastclose,
 		.preclose = dev_preclose,
 		.postclose = dev_postclose,
Signature · 1 line
1.8.3.2
Acked-by on v1 1/25
#2 lore raw

Re: [PATCH 01/25] drm/omap: kill firstopen callback

Quoted 4 lines · Daniel Vetter

KMS drivers really shouldn't need to do anything on firstopen, so kill empty callbacks.

Quoted 36 lines
---
 drivers/gpu/drm/omapdrm/omap_drv.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +0 -8
index 2f9e22e..47e64f9 100644
@@ -524,12 +524,6 @@ static int dev_open(struct drm_device *dev, struct drm_file *file)
        return 0;
 }
 
-static int dev_firstopen(struct drm_device *dev)
-{
-       DBG("firstopen: dev=%p", dev);
-       return 0;
-}
-
 /**
  * lastclose - clean up after all DRM clients have exited
  * @dev: DRM device
@@ -609,7 +603,6 @@ static struct drm_driver omap_drm_driver = {
                .load = dev_load,
                .unload = dev_unload,
                .open = dev_open,
-               .firstopen = dev_firstopen,
                .lastclose = dev_lastclose,
                .preclose = dev_preclose,
                .postclose = dev_postclose,
--

1.8.3.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH 2/25 drm/radeon: kill firstopen callback for kms driver

In reply to Daniel Vetter

Again, it does nothing.

---
 drivers/gpu/drm/radeon/radeon_drv.c |  2 --
 drivers/gpu/drm/radeon/radeon_kms.c | 13 -------------
 2 files changed, 15 deletions(-)
drivers/gpu/drm/radeon/radeon_drv.c +0 -2
index fa7a7e1..3585f22 100644
@@ -81,7 +81,6 @@
 #define KMS_DRIVER_PATCHLEVEL	0
 int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
 int radeon_driver_unload_kms(struct drm_device *dev);
-int radeon_driver_firstopen_kms(struct drm_device *dev);
 void radeon_driver_lastclose_kms(struct drm_device *dev);
 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
 void radeon_driver_postclose_kms(struct drm_device *dev,
@@ -390,7 +389,6 @@ static struct drm_driver kms_driver = {
 	    DRIVER_PRIME,
 	.dev_priv_size = 0,
 	.load = radeon_driver_load_kms,
-	.firstopen = radeon_driver_firstopen_kms,
 	.open = radeon_driver_open_kms,
 	.preclose = radeon_driver_preclose_kms,
 	.postclose = radeon_driver_postclose_kms,
drivers/gpu/drm/radeon/radeon_kms.c +0 -13
index 866c2b7..b46a561 100644
@@ -449,19 +449,6 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  * Outdated mess for old drm with Xorg being in charge (void function now).
  */
 /**
- * radeon_driver_firstopen_kms - drm callback for first open
- *
- * @dev: drm dev pointer
- *
- * Nothing to be done for KMS (all asics).
- * Returns 0 on success.
- */
-int radeon_driver_firstopen_kms(struct drm_device *dev)
-{
-	return 0;
-}
-
-/**
  * radeon_driver_firstopen_kms - drm callback for last close
  *
  * @dev: drm dev pointer
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH 3/25 drm/imx: kill firstopen callback

In reply to Daniel Vetter

This thing seems to do some kind of delayed setup. Really, real kms drivers shouldn't do that at all. Either stuff needs to be dynamically hotplugged or the driver setup sequence needs to be fixed.

This patch here just moves the setup at the very end of the driver load callback, with the locking adjusted accordingly.

v2: Also move the corresponding put from ->lastclose to ->unload.

Cc Sascha Hauer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

Note that this is already in the staging tree but due to the follow-up cleanup it's probably best to merge it again through drm-next.
-Daniel

 drivers/staging/imx-drm/imx-drm-core.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/staging/imx-drm/imx-drm-core.c +5 -15
index a890049..2c58533 100644
@@ -69,28 +69,20 @@ struct imx_drm_connector {
 	struct module				*owner;
 };
 
-static int imx_drm_driver_firstopen(struct drm_device *drm)
-{
-	if (!imx_drm_device_get())
-		return -EINVAL;
-
-	return 0;
-}
-
 static void imx_drm_driver_lastclose(struct drm_device *drm)
 {
 	struct imx_drm_device *imxdrm = drm->dev_private;
 
 	if (imxdrm->fbhelper)
 		drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
-
-	imx_drm_device_put();
 }
 
 static int imx_drm_driver_unload(struct drm_device *drm)
 {
 	struct imx_drm_device *imxdrm = drm->dev_private;
 
+	imx_drm_device_put();
+
 	drm_mode_config_cleanup(imxdrm->drm);
 	drm_kms_helper_poll_fini(imxdrm->drm);
 
@@ -226,8 +218,6 @@ struct drm_device *imx_drm_device_get(void)
 	struct imx_drm_connector *con;
 	struct imx_drm_crtc *crtc;
 
-	mutex_lock(&imxdrm->mutex);
-
 	list_for_each_entry(enc, &imxdrm->encoder_list, list) {
 		if (!try_module_get(enc->owner)) {
 			dev_err(imxdrm->dev, "could not get module %s\n",
@@ -254,8 +244,6 @@ struct drm_device *imx_drm_device_get(void)
 
 	imxdrm->references++;
 
-	mutex_unlock(&imxdrm->mutex);
-
 	return imxdrm->drm;
 
 unwind_crtc:
@@ -447,6 +435,9 @@ static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
 	 */
 	imxdrm->drm->vblank_disable_allowed = 1;
 
+	if (!imx_drm_device_get())
+		ret = -EINVAL;
+
 	ret = 0;
 
 err_init:
@@ -791,7 +782,6 @@ static struct drm_driver imx_drm_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_GEM,
 	.load			= imx_drm_driver_load,
 	.unload			= imx_drm_driver_unload,
-	.firstopen		= imx_drm_driver_firstopen,
 	.lastclose		= imx_drm_driver_lastclose,
 	.gem_free_object	= drm_gem_cma_free_object,
 	.gem_vm_ops		= &drm_gem_cma_vm_ops,
Signature · 1 line
1.8.3.2
maintainer Acked-by on v1 3/25
#5 lore raw

Re: [PATCH 03/25] drm/imx: kill firstopen callback

Quoted 9 lines · Daniel Vetter

This thing seems to do some kind of delayed setup. Really, real kms drivers shouldn't do that at all. Either stuff needs to be dynamically hotplugged or the driver setup sequence needs to be fixed.

This patch here just moves the setup at the very end of the driver load callback, with the locking adjusted accordingly.

v2: Also move the corresponding put from ->lastclose to ->unload.

Quoted 8 lines
Cc Sascha Hauer <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

Note that this is already in the staging tree but due to the follow-up cleanup it's probably best to merge it again through drm-next.
-Daniel

That's fine with me:

#6 lore raw

PATCH 4/25 drm/vmwgfx: remove ->firstopen callback

In reply to Daniel Vetter

So if we survey kms drivers there's a bunch of things they commonly do in ->lastclose
- delayed processing of vga switcheroo requests (i915, nouveau, radeon)
- force-restoring the fbcon (most)
- resetting a bunch properties to make fbcon work better (omap)
- disabling all outputs (vmwgfx)

In short besides the semantically important vga switcheroo stuff they all try very hard to keep fbcon working in case X dies.

But none of them try to not do this at driver unload time safe for vmwgfx, and digging through logs I couldn't find any reason for why vmwgfx is special.

Since ->firstopen has lots of potential for abuse with kms drivers (like delaying driver setup to pamper over races in the load sequence) it's imo very much worth it to remove this logic so that we can stop using the ->firstopen callback for kms drivers.

Also module unloading is rather a debug feature and developers should know how to restore the display to a sane configuration.

Cc Jakob Bornecrantz <[email protected]>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 18 ------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  1 -
 2 files changed, 19 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -18
index 5086150..cebd847 100644
@@ -795,29 +795,12 @@ static long vmw_unlocked_ioctl(struct file *filp, unsigned int cmd,
 	return drm_ioctl(filp, cmd, arg);
 }
 
-static int vmw_firstopen(struct drm_device *dev)
-{
-	struct vmw_private *dev_priv = vmw_priv(dev);
-	dev_priv->is_opened = true;
-
-	return 0;
-}
-
 static void vmw_lastclose(struct drm_device *dev)
 {
-	struct vmw_private *dev_priv = vmw_priv(dev);
 	struct drm_crtc *crtc;
 	struct drm_mode_set set;
 	int ret;
 
-	/**
-	 * Do nothing on the lastclose call from drm_unload.
-	 */
-
-	if (!dev_priv->is_opened)
-		return;
-
-	dev_priv->is_opened = false;
 	set.x = 0;
 	set.y = 0;
 	set.fb = NULL;
@@ -1132,7 +1115,6 @@ static struct drm_driver driver = {
 	DRIVER_MODESET,
 	.load = vmw_driver_load,
 	.unload = vmw_driver_unload,
-	.firstopen = vmw_firstopen,
 	.lastclose = vmw_lastclose,
 	.irq_preinstall = vmw_irq_preinstall,
 	.irq_postinstall = vmw_irq_postinstall,
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 13aeda7..150ec64 100644
@@ -324,7 +324,6 @@ struct vmw_private {
 	 */
 
 	bool stealth;
-	bool is_opened;
 	bool enable_fb;
 
 	/**
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH 5/25 drm: don't call ->firstopen for KMS drivers

In reply to Daniel Vetter

It has way too much potential for driver writers to do stupid things like delayed hw setup because the load sequence is somehow racy (e.g. the imx driver in staging). So don't call it for modesetting drivers, which reduces the complexity of the drm core -> driver interface a notch.

v2: Don't forget to update DocBook.

v3: Go with Laurent's slightly more elaborate proposal for the DocBook update. Add a few words on top of his diff to elaborate a bit on what KMS drivers should and shouldn't do in lastclose. There was already a paragraph present talking about restoring properties, I've simply extended that one.

---
 Documentation/DocBook/drm.tmpl | 27 ++++++++++++++++-----------
 drivers/gpu/drm/drm_fops.c     |  3 ++-
 2 files changed, 18 insertions(+), 12 deletions(-)
Documentation/DocBook/drm.tmpl +16 -11
index 87e22ec..c62d2d4 100644
@@ -2428,18 +2428,18 @@ void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
       </abstract>
       <para>
         The <methodname>firstopen</methodname> method is called by the DRM core
-	when an application opens a device that has no other opened file handle.
-	Similarly the <methodname>lastclose</methodname> method is called when
-	the last application holding a file handle opened on the device closes
-	it. Both methods are mostly used for UMS (User Mode Setting) drivers to
-	acquire and release device resources which should be done in the
-	<methodname>load</methodname> and <methodname>unload</methodname>
-	methods for KMS drivers.
+	for legacy UMS (User Mode Setting) drivers only when an application
+	opens a device that has no other opened file handle. UMS drivers can
+	implement it to acquire device resources. KMS drivers can't use the
+	method and must acquire resources in the <methodname>load</methodname>
+	method instead.
       </para>
       <para>
-        Note that the <methodname>lastclose</methodname> method is also called
-	at module unload time or, for hot-pluggable devices, when the device is
-	unplugged. The <methodname>firstopen</methodname> and
+	Similarly the <methodname>lastclose</methodname> method is called when
+	the last application holding a file handle opened on the device closes
+	it, for both UMS and KMS drivers. Additionally, the method is also
+	called at module unload time or, for hot-pluggable devices, when the
+	device is unplugged. The <methodname>firstopen</methodname> and
 	<methodname>lastclose</methodname> calls can thus be unbalanced.
       </para>
       <para>
@@ -2468,7 +2468,12 @@ void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
       <para>
         The <methodname>lastclose</methodname> method should restore CRTC and
 	plane properties to default value, so that a subsequent open of the
-	device will not inherit state from the previous user.
+	device will not inherit state from the previous user. It can also be
+	used to execute delayed power switching state changes, e.g. in
+	conjunction with the vga-switcheroo infrastructure. Beyond that KMS
+	drivers should not do any further cleanup. Only legacy UMS drivers might
+	need to clean up device state so that the vga console or an independent
+	fbdev driver could take over.
       </para>
     </sect2>
     <sect2>
drivers/gpu/drm/drm_fops.c +2 -1
index 72acae9..10bf4f6 100644
@@ -51,7 +51,8 @@ static int drm_setup(struct drm_device * dev)
 	int i;
 	int ret;
 
-	if (dev->driver->firstopen) {
+	if (dev->driver->firstopen &&
+	    !drm_core_check_feature(dev, DRIVER_MODESET)) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
Signature · 1 line
1.8.3.2
#8 lore raw

PATCH 6/25 drm: kill dev->driver->set_version

In reply to Daniel Vetter

Totally unused, so just rip it out. Anyway, we want drivers to be fully backwards compatible, allowing them to change behaviour is just a recipe for them to break badly.

---
 drivers/gpu/drm/drm_ioctl.c | 3 ---
 include/drm/drmP.h          | 2 --
 2 files changed, 5 deletions(-)
drivers/gpu/drm/drm_ioctl.c +0 -3
index ffd7a7b..0acf080 100644
@@ -352,9 +352,6 @@ int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_pri
 			retcode = -EINVAL;
 			goto done;
 		}
-
-		if (dev->driver->set_version)
-			dev->driver->set_version(dev, sv);
 	}
 
 done:
include/drm/drmP.h +0 -2
index fba5473..7495fb2 100644
@@ -885,8 +885,6 @@ struct drm_driver {
 	void (*irq_preinstall) (struct drm_device *dev);
 	int (*irq_postinstall) (struct drm_device *dev);
 	void (*irq_uninstall) (struct drm_device *dev);
-	void (*set_version) (struct drm_device *dev,
-			     struct drm_set_version *sv);
 
 	/* Master routines */
 	int (*master_create)(struct drm_device *dev, struct drm_master *master);
Signature · 1 line
1.8.3.2
Reviewed-by on v1 6/25
#9 lore raw

Re: [PATCH 06/25] drm: kill dev->driver->set_version

Quoted 5 lines · Daniel Vetter

Totally unused, so just rip it out. Anyway, we want drivers to be fully backwards compatible, allowing them to change behaviour is just a recipe for them to break badly.

Quoted 39 lines
---
 drivers/gpu/drm/drm_ioctl.c | 3 ---
 include/drm/drmP.h          | 2 --
 2 files changed, 5 deletions(-)
drivers/gpu/drm/drm_ioctl.c +0 -3
index ffd7a7b..0acf080 100644
@@ -352,9 +352,6 @@ int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_pri
                        retcode = -EINVAL;
                        goto done;
                }
-
-               if (dev->driver->set_version)
-                       dev->driver->set_version(dev, sv);
        }
 
 done:
include/drm/drmP.h +0 -3
index fba5473..7495fb2 100644
@@ -885,8 +885,6 @@ struct drm_driver {
        void (*irq_preinstall) (struct drm_device *dev);
        int (*irq_postinstall) (struct drm_device *dev);
        void (*irq_uninstall) (struct drm_device *dev);
-       void (*set_version) (struct drm_device *dev,
-                            struct drm_set_version *sv);
 
        /* Master routines */
        int (*master_create)(struct drm_device *dev, struct drm_master *master);
--

1.8.3.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

PATCH 7/25 drm: hide legacy sg cleanup better from common code

In reply to Daniel Vetter

I've decided that some clear markers for what's legacy dri1/non-gem code is useful. I've opted to use the drm_legacy prefix and then hide all the checks in that function for better readability in the common code.

---
 drivers/gpu/drm/drm_drv.c     |  6 +-----
 drivers/gpu/drm/drm_scatter.c | 10 +++++++++-
 include/drm/drmP.h            |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_drv.c +1 -5
index dddd799..743b24d 100644
@@ -197,11 +197,7 @@ int drm_lastclose(struct drm_device * dev)
 
 	drm_agp_clear(dev);
 
-	if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg &&
-	    !drm_core_check_feature(dev, DRIVER_MODESET)) {
-		drm_sg_cleanup(dev->sg);
-		dev->sg = NULL;
-	}
+	drm_legacy_sg_cleanup(dev);
 
 	/* Clear vma list (only built for debugging) */
 	list_for_each_entry_safe(vma, vma_temp, &dev->vmalist, head) {
drivers/gpu/drm/drm_scatter.c +9 -1
index a4a076f..dd8a648 100644
@@ -46,7 +46,7 @@ static inline void *drm_vmalloc_dma(unsigned long size)
 #endif
 }
 
-void drm_sg_cleanup(struct drm_sg_mem * entry)
+static void drm_sg_cleanup(struct drm_sg_mem * entry)
 {
 	struct page *page;
 	int i;
@@ -64,6 +64,14 @@ void drm_sg_cleanup(struct drm_sg_mem * entry)
 	kfree(entry);
 }
 
+void drm_legacy_sg_cleanup(struct drm_device *dev)
+{
+	if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg &&
+	    !drm_core_check_feature(dev, DRIVER_MODESET)) {
+		drm_sg_cleanup(dev->sg);
+		dev->sg = NULL;
+	}
+}
 #ifdef _LP64
 # define ScatterHandle(x) (unsigned int)((x >> 32) + (x & ((1L << 32) - 1)))
 #else
include/drm/drmP.h +1 -1
index 7495fb2..bc38f99 100644
@@ -1567,7 +1567,7 @@ extern int drm_vma_info(struct seq_file *m, void *data);
 #endif
 
 				/* Scatter Gather Support (drm_scatter.h) */
-extern void drm_sg_cleanup(struct drm_sg_mem * entry);
+extern void drm_legacy_sg_cleanup(struct drm_device *dev);
 extern int drm_sg_alloc(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 extern int drm_sg_free(struct drm_device *dev, void *data,
Signature · 1 line
1.8.3.2
#11 lore raw

PATCH 8/25 drm: disallow legacy sg ioctls for modesetting drivers

In reply to Daniel Vetter

Only the radeon/r128/ati ums drivers use this. Furthermore the cleanup was already only done for UMS drivers. Also a quick check of the ATI ddx git history shows that only the UMS code ever used this facility.

So we can safely disallow these pair of ioctls for modesetting drivers.

---
 drivers/gpu/drm/drm_scatter.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/drm_scatter.c +6 -0
index dd8a648..1c78406 100644
@@ -87,6 +87,9 @@ int drm_sg_alloc(struct drm_device *dev, void *data,
 
 	DRM_DEBUG("\n");
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 		return -EINVAL;
 
@@ -197,6 +200,9 @@ int drm_sg_free(struct drm_device *dev, void *data,
 	struct drm_scatter_gather *request = data;
 	struct drm_sg_mem *entry;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 		return -EINVAL;
 
Signature · 1 line
1.8.3.2
#12 lore raw

PATCH 9/25 drm: mark dma setup/teardown as legacy systems

In reply to Daniel Vetter

And hide the checks a bit better. This was already disallowed for modesetting drivers, so no functinal change here.

---
 drivers/gpu/drm/drm_dma.c  | 17 +++++++++++++++--
 drivers/gpu/drm/drm_drv.c  |  4 +---
 drivers/gpu/drm/drm_fops.c | 12 +++---------
 include/drm/drmP.h         |  4 ++--
 4 files changed, 21 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_dma.c +15 -2
index 495b5fd..8a140a9 100644
@@ -44,10 +44,18 @@
  *
  * Allocate and initialize a drm_device_dma structure.
  */
-int drm_dma_setup(struct drm_device *dev)
+int drm_legacy_dma_setup(struct drm_device *dev)
 {
 	int i;
 
+	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
+	    drm_core_check_feature(dev, DRIVER_MODESET)) {
+		return 0;
+	}
+
+	dev->buf_use = 0;
+	atomic_set(&dev->buf_alloc, 0);
+
 	dev->dma = kzalloc(sizeof(*dev->dma), GFP_KERNEL);
 	if (!dev->dma)
 		return -ENOMEM;
@@ -66,11 +74,16 @@ int drm_dma_setup(struct drm_device *dev)
  * Free all pages associated with DMA buffers, the buffers and pages lists, and
  * finally the drm_device::dma structure itself.
  */
-void drm_dma_takedown(struct drm_device *dev)
+void drm_legacy_dma_takedown(struct drm_device *dev)
 {
 	struct drm_device_dma *dma = dev->dma;
 	int i, j;
 
+	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
+	    drm_core_check_feature(dev, DRIVER_MODESET)) {
+		return;
+	}
+
 	if (!dma)
 		return;
 
drivers/gpu/drm/drm_drv.c +1 -3
index 743b24d..5b949a7 100644
@@ -205,9 +205,7 @@ int drm_lastclose(struct drm_device * dev)
 		kfree(vma);
 	}
 
-	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
-	    !drm_core_check_feature(dev, DRIVER_MODESET))
-		drm_dma_takedown(dev);
+	drm_legacy_dma_takedown(dev);
 
 	dev->dev_mapping = NULL;
 	mutex_unlock(&dev->struct_mutex);
drivers/gpu/drm/drm_fops.c +3 -9
index 10bf4f6..702e2a8 100644
@@ -61,15 +61,9 @@ static int drm_setup(struct drm_device * dev)
 	atomic_set(&dev->ioctl_count, 0);
 	atomic_set(&dev->vma_count, 0);
 
-	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
-	    !drm_core_check_feature(dev, DRIVER_MODESET)) {
-		dev->buf_use = 0;
-		atomic_set(&dev->buf_alloc, 0);
-
-		i = drm_dma_setup(dev);
-		if (i < 0)
-			return i;
-	}
+	i = drm_legacy_dma_setup(dev);
+	if (i < 0)
+		return i;
 
 	for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
 		atomic_set(&dev->counts[i], 0);
include/drm/drmP.h +2 -2
index bc38f99..de19e97 100644
@@ -1394,8 +1394,8 @@ extern int drm_mapbufs(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv);
 
 				/* DMA support (drm_dma.h) */
-extern int drm_dma_setup(struct drm_device *dev);
-extern void drm_dma_takedown(struct drm_device *dev);
+extern int drm_legacy_dma_setup(struct drm_device *dev);
+extern void drm_legacy_dma_takedown(struct drm_device *dev);
 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
 extern void drm_core_reclaim_buffers(struct drm_device *dev,
 				     struct drm_file *filp);
Signature · 1 line
1.8.3.2
#13 lore raw

PATCH 10/25 drm: disallow legacy dma ioctls for modesetting drivers

In reply to Daniel Vetter

Now only legacy ums drivers have the DRIVER_HAVE_DMA driver feature flag set, so strictly speaking the modesetting check is redundant. But adding it has the upside that it makes it very clear that the dma support is legacy stuff.

---
 drivers/gpu/drm/drm_bufs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/drm_bufs.c +15 -0
index bef4abf..cccc25f 100644
@@ -1305,6 +1305,9 @@ int drm_addbufs(struct drm_device *dev, void *data,
 	struct drm_buf_desc *request = data;
 	int ret;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 
@@ -1348,6 +1351,9 @@ int drm_infobufs(struct drm_device *dev, void *data,
 	int i;
 	int count;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 
@@ -1427,6 +1433,9 @@ int drm_markbufs(struct drm_device *dev, void *data,
 	int order;
 	struct drm_buf_entry *entry;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 
@@ -1472,6 +1481,9 @@ int drm_freebufs(struct drm_device *dev, void *data,
 	int idx;
 	struct drm_buf *buf;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 
@@ -1524,6 +1536,9 @@ int drm_mapbufs(struct drm_device *dev, void *data,
 	struct drm_buf_map *request = data;
 	int i;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 
Signature · 1 line
1.8.3.2
#14 lore raw

PATCH 11/25 drm: mark context support as a legacy subsystem

In reply to Daniel Vetter

So after a lot of digging around in git histories it looks like this has only ever be used by dri1 render clients. Hence we can fully disable the entire thing for modesetting drivers and so greatly reduce the attack surface for potential exploits (or at least tools like trinity ...).

Also add the drm_legacy prefix for functions which are called from common code. To further reduce the impact on common code also extract all the ctx release handling into a function (instead of only releasing individual handles) and make ctxbitmap_cleanup return void - it can never fail.

---
 drivers/gpu/drm/drm_context.c | 73 ++++++++++++++++++++++++++++++++++++++-----
 drivers/gpu/drm/drm_fops.c    | 21 +------------
 drivers/gpu/drm/drm_stub.c    | 10 ++----
 include/drm/drmP.h            |  7 +++--
 4 files changed, 72 insertions(+), 39 deletions(-)
drivers/gpu/drm/drm_context.c +65 -8
index 224ff96..b4fb86d 100644
@@ -42,10 +42,6 @@
 
 #include <drm/drmP.h>
 
-/******************************************************************/
-/** \name Context bitmap support */
-/*@{*/
-
 /**
  * Free a handle from the context bitmap.
  *
@@ -56,13 +52,48 @@
  * in drm_device::ctx_idr, while holding the drm_device::struct_mutex
  * lock.
  */
-void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
+static void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
 {
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return;
+
 	mutex_lock(&dev->struct_mutex);
 	idr_remove(&dev->ctx_idr, ctx_handle);
 	mutex_unlock(&dev->struct_mutex);
 }
 
+/******************************************************************/
+/** \name Context bitmap support */
+/*@{*/
+
+void drm_legacy_ctxbitmap_release(struct drm_device *dev,
+				  struct drm_file *file_priv)
+{
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return;
+
+	mutex_lock(&dev->ctxlist_mutex);
+	if (!list_empty(&dev->ctxlist)) {
+		struct drm_ctx_list *pos, *n;
+
+		list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
+			if (pos->tag == file_priv &&
+			    pos->handle != DRM_KERNEL_CONTEXT) {
+				if (dev->driver->context_dtor)
+					dev->driver->context_dtor(dev,
+								  pos->handle);
+
+				drm_ctxbitmap_free(dev, pos->handle);
+
+				list_del(&pos->head);
+				kfree(pos);
+				--dev->ctx_count;
+			}
+		}
+	}
+	mutex_unlock(&dev->ctxlist_mutex);
+}
+
 /**
  * Context bitmap allocation.
  *
@@ -90,10 +121,12 @@ static int drm_ctxbitmap_next(struct drm_device * dev)
  *
  * Initialise the drm_device::ctx_idr
  */
-int drm_ctxbitmap_init(struct drm_device * dev)
+void drm_legacy_ctxbitmap_init(struct drm_device * dev)
 {
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return;
+
 	idr_init(&dev->ctx_idr);
-	return 0;
 }
 
 /**
@@ -104,7 +137,7 @@ int drm_ctxbitmap_init(struct drm_device * dev)
  * Free all idr members using drm_ctx_sarea_free helper function
  * while holding the drm_device::struct_mutex lock.
  */
-void drm_ctxbitmap_cleanup(struct drm_device * dev)
+void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
 {
 	mutex_lock(&dev->struct_mutex);
 	idr_destroy(&dev->ctx_idr);
@@ -136,6 +169,9 @@ int drm_getsareactx(struct drm_device *dev, void *data,
 	struct drm_local_map *map;
 	struct drm_map_list *_entry;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	mutex_lock(&dev->struct_mutex);
 
 	map = idr_find(&dev->ctx_idr, request->ctx_id);
@@ -180,6 +216,9 @@ int drm_setsareactx(struct drm_device *dev, void *data,
 	struct drm_local_map *map = NULL;
 	struct drm_map_list *r_list = NULL;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(r_list, &dev->maplist, head) {
 		if (r_list->map
@@ -280,6 +319,9 @@ int drm_resctx(struct drm_device *dev, void *data,
 	struct drm_ctx ctx;
 	int i;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	if (res->count >= DRM_RESERVED_CONTEXTS) {
 		memset(&ctx, 0, sizeof(ctx));
 		for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
@@ -310,6 +352,9 @@ int drm_addctx(struct drm_device *dev, void *data,
 	struct drm_ctx_list *ctx_entry;
 	struct drm_ctx *ctx = data;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	ctx->handle = drm_ctxbitmap_next(dev);
 	if (ctx->handle == DRM_KERNEL_CONTEXT) {
 		/* Skip kernel's context and get a new one. */
@@ -353,6 +398,9 @@ int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_ctx *ctx = data;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	/* This is 0, because we don't handle any context flags */
 	ctx->flags = 0;
 
@@ -375,6 +423,9 @@ int drm_switchctx(struct drm_device *dev, void *data,
 {
 	struct drm_ctx *ctx = data;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	DRM_DEBUG("%d\n", ctx->handle);
 	return drm_context_switch(dev, dev->last_context, ctx->handle);
 }
@@ -395,6 +446,9 @@ int drm_newctx(struct drm_device *dev, void *data,
 {
 	struct drm_ctx *ctx = data;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	DRM_DEBUG("%d\n", ctx->handle);
 	drm_context_switch_complete(dev, file_priv, ctx->handle);
 
@@ -417,6 +471,9 @@ int drm_rmctx(struct drm_device *dev, void *data,
 {
 	struct drm_ctx *ctx = data;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
 	DRM_DEBUG("%d\n", ctx->handle);
 	if (ctx->handle != DRM_KERNEL_CONTEXT) {
 		if (dev->driver->context_dtor)
drivers/gpu/drm/drm_fops.c +1 -20
index 702e2a8..dd47fef 100644
@@ -475,26 +475,7 @@ int drm_release(struct inode *inode, struct file *filp)
 	if (dev->driver->driver_features & DRIVER_GEM)
 		drm_gem_release(dev, file_priv);
 
-	mutex_lock(&dev->ctxlist_mutex);
-	if (!list_empty(&dev->ctxlist)) {
-		struct drm_ctx_list *pos, *n;
-
-		list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
-			if (pos->tag == file_priv &&
-			    pos->handle != DRM_KERNEL_CONTEXT) {
-				if (dev->driver->context_dtor)
-					dev->driver->context_dtor(dev,
-								  pos->handle);
-
-				drm_ctxbitmap_free(dev, pos->handle);
-
-				list_del(&pos->head);
-				kfree(pos);
-				--dev->ctx_count;
-			}
-		}
-	}
-	mutex_unlock(&dev->ctxlist_mutex);
+	drm_legacy_ctxbitmap_release(dev, file_priv);
 
 	mutex_lock(&dev->struct_mutex);
 
drivers/gpu/drm/drm_stub.c +2 -8
index d663f7d..aa0664d 100644
@@ -288,13 +288,7 @@ int drm_fill_in_dev(struct drm_device *dev,
 			goto error_out_unreg;
 	}
 
-
-
-	retcode = drm_ctxbitmap_init(dev);
-	if (retcode) {
-		DRM_ERROR("Cannot allocate memory for context bitmap.\n");
-		goto error_out_unreg;
-	}
+	drm_legacy_ctxbitmap_init(dev);
 
 	if (driver->driver_features & DRIVER_GEM) {
 		retcode = drm_gem_init(dev);
@@ -463,7 +457,7 @@ void drm_put_dev(struct drm_device *dev)
 		drm_rmmap(dev, r_list->map);
 	drm_ht_remove(&dev->map_hash);
 
-	drm_ctxbitmap_cleanup(dev);
+	drm_legacy_ctxbitmap_cleanup(dev);
 
 	if (drm_core_check_feature(dev, DRIVER_MODESET))
 		drm_put_minor(&dev->control);
include/drm/drmP.h +4 -3
index de19e97..d05beac 100644
@@ -1333,9 +1333,10 @@ extern int drm_newctx(struct drm_device *dev, void *data,
 extern int drm_rmctx(struct drm_device *dev, void *data,
 		     struct drm_file *file_priv);
 
-extern int drm_ctxbitmap_init(struct drm_device *dev);
-extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
-extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
+extern void drm_legacy_ctxbitmap_init(struct drm_device *dev);
+extern void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev);
+extern void drm_legacy_ctxbitmap_release(struct drm_device *dev,
+					 struct drm_file *file_priv);
 
 extern int drm_setsareactx(struct drm_device *dev, void *data,
 			   struct drm_file *file_priv);
Signature · 1 line
1.8.3.2
#15 lore raw

PATCH 12/25 drm/vmwgfx: remove redundant clearing of driver->dma_quiescent

In reply to Daniel Vetter

It's kzalloced ...

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -1
index cebd847..9c27d42 100644
@@ -1125,7 +1125,6 @@ static struct drm_driver driver = {
 	.disable_vblank = vmw_disable_vblank,
 	.ioctls = vmw_ioctls,
 	.num_ioctls = DRM_ARRAY_SIZE(vmw_ioctls),
-	.dma_quiescent = NULL,	/*vmw_dma_quiescent, */
 	.master_create = vmw_master_create,
 	.master_destroy = vmw_master_destroy,
 	.master_set = vmw_master_set,
Signature · 1 line
1.8.3.2
#16 lore raw

PATCH 13/25 drm: remove FASYNC support

In reply to Daniel Vetter

So I've stumbled over drm_fasync and wondered what it does. Digging that up is quite a story.

First I've had to read up on what this does and ended up being rather bewildered why peopled loved signals so much back in the days that they've created SIGIO just for that ...

Then I wondered how this ever works, and what that strange "No-op." comment right above it should mean. After all calling the core fasync helper is pretty obviously not a noop. After reading through the kernels FASYNC implementation I've noticed that signals are only sent out to the processes attached with FASYNC by calling kill_fasync.

No merged drm driver has ever done that.

After more digging I've found out that the only driver that ever used this is the so called GAMMA driver. I've frankly never heard of such a gpu brand ever before. Now FASYNC seems to not have been the only bad thing with that driver, since Dave Airlie removed it from the drm driver with prejudice:

commit 1430163b4bbf7b00367ea1066c1c5fe85dbeefed

Author: Dave Airlie <[email protected]>
Date:   Sun Aug 29 12:04:35 2004 +0000

Drop GAMMA DRM from a great height ...

Long story short, the drm fasync support seems to be doing absolutely nothing. And the only user of it was never merged into the upstream kernel. And we don't need any fops->fasync callback since the fcntl implementation in the kernel already implements the noop case correctly.

So stop this particular cargo-cult and rip it all out.

v2: Kill drm_fasync assignments in rcar (newly added) and imx drivers (somehow I've missed that one in staging). Also drop the reference in the drm DocBook. ARM compile-fail reported by Rob Clark.

v3: Move the removal of dev->buf_asnyc assignment in drm_setup to this patch here.

v4: Actually git add ... tsk.

---
 Documentation/DocBook/drm.tmpl           |  1 -
 drivers/gpu/drm/ast/ast_drv.c            |  1 -
 drivers/gpu/drm/cirrus/cirrus_drv.c      |  1 -
 drivers/gpu/drm/drm_fops.c               | 14 --------------
 drivers/gpu/drm/gma500/psb_drv.c         |  1 -
 drivers/gpu/drm/i810/i810_dma.c          |  1 -
 drivers/gpu/drm/i810/i810_drv.c          |  1 -
 drivers/gpu/drm/i915/i915_drv.c          |  1 -
 drivers/gpu/drm/mga/mga_drv.c            |  1 -
 drivers/gpu/drm/mgag200/mgag200_drv.c    |  1 -
 drivers/gpu/drm/nouveau/nouveau_drm.c    |  1 -
 drivers/gpu/drm/omapdrm/omap_drv.c       |  1 -
 drivers/gpu/drm/qxl/qxl_drv.c            |  1 -
 drivers/gpu/drm/r128/r128_drv.c          |  1 -
 drivers/gpu/drm/radeon/radeon_drv.c      |  2 --
 drivers/gpu/drm/rcar-du/rcar_du_drv.c    |  1 -
 drivers/gpu/drm/savage/savage_drv.c      |  1 -
 drivers/gpu/drm/shmobile/shmob_drm_drv.c |  1 -
 drivers/gpu/drm/sis/sis_drv.c            |  1 -
 drivers/gpu/drm/tdfx/tdfx_drv.c          |  1 -
 drivers/gpu/drm/tilcdc/tilcdc_drv.c      |  1 -
 drivers/gpu/drm/udl/udl_drv.c            |  1 -
 drivers/gpu/drm/via/via_drv.c            |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c      |  1 -
 drivers/gpu/host1x/drm/drm.c             |  1 -
 drivers/staging/imx-drm/imx-drm-core.c   |  1 -
 include/drm/drmP.h                       |  3 ---
 27 files changed, 43 deletions(-)
Documentation/DocBook/drm.tmpl +0 -1
index c62d2d4..d51d157 100644
@@ -2509,7 +2509,6 @@ void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
 	<programlisting>
 	.poll = drm_poll,
 	.read = drm_read,
-	.fasync = drm_fasync,
 	.llseek = no_llseek,
 	</programlisting>
       </para>
drivers/gpu/drm/ast/ast_drv.c +0 -1
index a144fb0..60f1ce3 100644
@@ -190,7 +190,6 @@ static const struct file_operations ast_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = ast_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/cirrus/cirrus_drv.c +0 -1
index d35d99c..dd9c908 100644
@@ -85,7 +85,6 @@ static const struct file_operations cirrus_driver_fops = {
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
-	.fasync = drm_fasync,
 };
 static struct drm_driver driver = {
 	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
drivers/gpu/drm/drm_fops.c +0 -14
index dd47fef..5679971 100644
@@ -74,8 +74,6 @@ static int drm_setup(struct drm_device * dev)
 	dev->last_context = 0;
 	dev->if_version = 0;
 
-	dev->buf_async = NULL;
-
 	DRM_DEBUG("\n");
 
 	/*
@@ -373,18 +371,6 @@ out_put_pid:
 	return ret;
 }
 
-/** No-op. */
-int drm_fasync(int fd, struct file *filp, int on)
-{
-	struct drm_file *priv = filp->private_data;
-	struct drm_device *dev = priv->minor->dev;
-
-	DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
-		  (long)old_encode_dev(priv->minor->device));
-	return fasync_helper(fd, filp, on, &dev->buf_async);
-}
-EXPORT_SYMBOL(drm_fasync);
-
 static void drm_master_release(struct drm_device *dev, struct file *filp)
 {
 	struct drm_file *file_priv = filp->private_data;
drivers/gpu/drm/gma500/psb_drv.c +0 -1
index d13c2fc..99b5293 100644
@@ -622,7 +622,6 @@ static const struct file_operations psb_gem_fops = {
 	.unlocked_ioctl = psb_unlocked_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 };
 
drivers/gpu/drm/i810/i810_dma.c +0 -1
index eac755b..ab1892eb 100644
@@ -113,7 +113,6 @@ static const struct file_operations i810_buffer_fops = {
 	.release = drm_release,
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = i810_mmap_buffers,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/i810/i810_drv.c +0 -1
index 2e91fc3..d85c05b 100644
@@ -49,7 +49,6 @@ static const struct file_operations i810_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/i915/i915_drv.c +0 -1
index 13457e3e..9411a74 100644
@@ -994,7 +994,6 @@ static const struct file_operations i915_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = i915_compat_ioctl,
drivers/gpu/drm/mga/mga_drv.c +0 -1
index 17d0a63..fe71e1e 100644
@@ -50,7 +50,6 @@ static const struct file_operations mga_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = mga_compat_ioctl,
 #endif
drivers/gpu/drm/mgag200/mgag200_drv.c +0 -1
index bd91964..b570127 100644
@@ -81,7 +81,6 @@ static const struct file_operations mgag200_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = mgag200_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -1
index 1faa75f..b29d04b 100644
@@ -673,7 +673,6 @@ nouveau_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = nouveau_ttm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 #if defined(CONFIG_COMPAT)
 	.compat_ioctl = nouveau_compat_ioctl,
drivers/gpu/drm/omapdrm/omap_drv.c +0 -1
index 47e64f9..2603d90 100644
@@ -592,7 +592,6 @@ static const struct file_operations omapdriver_fops = {
 		.release = drm_release,
 		.mmap = omap_gem_mmap,
 		.poll = drm_poll,
-		.fasync = drm_fasync,
 		.read = drm_read,
 		.llseek = noop_llseek,
 };
drivers/gpu/drm/qxl/qxl_drv.c +0 -1
index 48f2dfd..514118a 100644
@@ -84,7 +84,6 @@ static const struct file_operations qxl_fops = {
 	.release = drm_release,
 	.unlocked_ioctl = drm_ioctl,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.mmap = qxl_mmap,
 };
 
drivers/gpu/drm/r128/r128_drv.c +0 -1
index 472c38f..c2338cb 100644
@@ -48,7 +48,6 @@ static const struct file_operations r128_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = r128_compat_ioctl,
 #endif
drivers/gpu/drm/radeon/radeon_drv.c +0 -2
index 3585f22..3e52331 100644
@@ -266,7 +266,6 @@ static const struct file_operations radeon_driver_old_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = radeon_compat_ioctl,
@@ -375,7 +374,6 @@ static const struct file_operations radeon_driver_kms_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = radeon_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = radeon_kms_compat_ioctl,
drivers/gpu/drm/rcar-du/rcar_du_drv.c +0 -1
index 5069d9c..c9f7fbd 100644
@@ -230,7 +230,6 @@ static const struct file_operations rcar_du_fops = {
 #endif
 	.poll		= drm_poll,
 	.read		= drm_read,
-	.fasync		= drm_fasync,
 	.llseek		= no_llseek,
 	.mmap		= drm_gem_cma_mmap,
 };
drivers/gpu/drm/savage/savage_drv.c +0 -1
index 71b2081..9135c8b 100644
@@ -42,7 +42,6 @@ static const struct file_operations savage_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/shmobile/shmob_drm_drv.c +0 -1
index 7f2ea1a..0155518 100644
@@ -257,7 +257,6 @@ static const struct file_operations shmob_drm_fops = {
 #endif
 	.poll		= drm_poll,
 	.read		= drm_read,
-	.fasync		= drm_fasync,
 	.llseek		= no_llseek,
 	.mmap		= drm_gem_cma_mmap,
 };
drivers/gpu/drm/sis/sis_drv.c +0 -1
index 5a5325e..b88b2d3 100644
@@ -72,7 +72,6 @@ static const struct file_operations sis_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/tdfx/tdfx_drv.c +0 -1
index ddfa743..951ec13 100644
@@ -48,7 +48,6 @@ static const struct file_operations tdfx_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/tilcdc/tilcdc_drv.c +0 -1
index 14801c2..116da19 100644
@@ -497,7 +497,6 @@ static const struct file_operations fops = {
 #endif
 	.poll               = drm_poll,
 	.read               = drm_read,
-	.fasync             = drm_fasync,
 	.llseek             = no_llseek,
 	.mmap               = drm_gem_cma_mmap,
 };
drivers/gpu/drm/udl/udl_drv.c +0 -1
index bb0af58..7650dc0 100644
@@ -65,7 +65,6 @@ static const struct file_operations udl_driver_fops = {
 	.read = drm_read,
 	.unlocked_ioctl	= drm_ioctl,
 	.release = drm_release,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/via/via_drv.c +0 -1
index f4ae203..4487999 100644
@@ -64,7 +64,6 @@ static const struct file_operations via_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -1
index 9c27d42..0dcfa6b 100644
@@ -1103,7 +1103,6 @@ static const struct file_operations vmwgfx_driver_fops = {
 	.mmap = vmw_mmap,
 	.poll = vmw_fops_poll,
 	.read = vmw_fops_read,
-	.fasync = drm_fasync,
 #if defined(CONFIG_COMPAT)
 	.compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/host1x/drm/drm.c +0 -1
index b128b90..15684bf 100644
@@ -508,7 +508,6 @@ static const struct file_operations tegra_drm_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = tegra_drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = drm_compat_ioctl,
drivers/staging/imx-drm/imx-drm-core.c +0 -1
index 2c58533..e826086 100644
@@ -199,7 +199,6 @@ static const struct file_operations imx_drm_driver_fops = {
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_gem_cma_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.read = drm_read,
 	.llseek = noop_llseek,
 };
include/drm/drmP.h +0 -3
index d05beac..a79dcb0 100644
@@ -1168,8 +1168,6 @@ struct drm_device {
 
 	/*@} */
 
-	struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
-
 	struct drm_agp_head *agp;	/**< AGP data */
 
 	struct device *dev;             /**< Device structure */
@@ -1276,7 +1274,6 @@ extern int drm_lastclose(struct drm_device *dev);
 extern struct mutex drm_global_mutex;
 extern int drm_open(struct inode *inode, struct file *filp);
 extern int drm_stub_open(struct inode *inode, struct file *filp);
-extern int drm_fasync(int fd, struct file *filp, int on);
 extern ssize_t drm_read(struct file *filp, char __user *buffer,
 			size_t count, loff_t *offset);
 extern int drm_release(struct inode *inode, struct file *filp);
Signature · 1 line
1.8.3.2
Reviewed-by on v1 13/25
#17 lore raw

Re: [PATCH 13/25] drm: remove FASYNC support

Hi

Quoted 42 lines · Daniel Vetter

So I've stumbled over drm_fasync and wondered what it does. Digging that up is quite a story.

First I've had to read up on what this does and ended up being rather bewildered why peopled loved signals so much back in the days that they've created SIGIO just for that ...

Then I wondered how this ever works, and what that strange "No-op." comment right above it should mean. After all calling the core fasync helper is pretty obviously not a noop. After reading through the kernels FASYNC implementation I've noticed that signals are only sent out to the processes attached with FASYNC by calling kill_fasync.

No merged drm driver has ever done that.

After more digging I've found out that the only driver that ever used this is the so called GAMMA driver. I've frankly never heard of such a gpu brand ever before. Now FASYNC seems to not have been the only bad thing with that driver, since Dave Airlie removed it from the drm driver with prejudice:

commit 1430163b4bbf7b00367ea1066c1c5fe85dbeefed

Author: Dave Airlie <[email protected]>
Date:   Sun Aug 29 12:04:35 2004 +0000

Drop GAMMA DRM from a great height ...

Long story short, the drm fasync support seems to be doing absolutely nothing. And the only user of it was never merged into the upstream kernel. And we don't need any fops->fasync callback since the fcntl implementation in the kernel already implements the noop case correctly.

So stop this particular cargo-cult and rip it all out.

v2: Kill drm_fasync assignments in rcar (newly added) and imx drivers (somehow I've missed that one in staging). Also drop the reference in the drm DocBook. ARM compile-fail reported by Rob Clark.

v3: Move the removal of dev->buf_asnyc assignment in drm_setup to this patch here.

Quoted 7 lines

v4: Actually git add ... tsk.

Looks good now. It reminds me that I should resend the O_NONBLOCK implementation of drm_read() which would properly replace any SIGIO uses...

Regards
David

Quoted 398 lines
---
 Documentation/DocBook/drm.tmpl           |  1 -
 drivers/gpu/drm/ast/ast_drv.c            |  1 -
 drivers/gpu/drm/cirrus/cirrus_drv.c      |  1 -
 drivers/gpu/drm/drm_fops.c               | 14 --------------
 drivers/gpu/drm/gma500/psb_drv.c         |  1 -
 drivers/gpu/drm/i810/i810_dma.c          |  1 -
 drivers/gpu/drm/i810/i810_drv.c          |  1 -
 drivers/gpu/drm/i915/i915_drv.c          |  1 -
 drivers/gpu/drm/mga/mga_drv.c            |  1 -
 drivers/gpu/drm/mgag200/mgag200_drv.c    |  1 -
 drivers/gpu/drm/nouveau/nouveau_drm.c    |  1 -
 drivers/gpu/drm/omapdrm/omap_drv.c       |  1 -
 drivers/gpu/drm/qxl/qxl_drv.c            |  1 -
 drivers/gpu/drm/r128/r128_drv.c          |  1 -
 drivers/gpu/drm/radeon/radeon_drv.c      |  2 --
 drivers/gpu/drm/rcar-du/rcar_du_drv.c    |  1 -
 drivers/gpu/drm/savage/savage_drv.c      |  1 -
 drivers/gpu/drm/shmobile/shmob_drm_drv.c |  1 -
 drivers/gpu/drm/sis/sis_drv.c            |  1 -
 drivers/gpu/drm/tdfx/tdfx_drv.c          |  1 -
 drivers/gpu/drm/tilcdc/tilcdc_drv.c      |  1 -
 drivers/gpu/drm/udl/udl_drv.c            |  1 -
 drivers/gpu/drm/via/via_drv.c            |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c      |  1 -
 drivers/gpu/host1x/drm/drm.c             |  1 -
 drivers/staging/imx-drm/imx-drm-core.c   |  1 -
 include/drm/drmP.h                       |  3 ---
 27 files changed, 43 deletions(-)
Documentation/DocBook/drm.tmpl +0 -1
index c62d2d4..d51d157 100644
@@ -2509,7 +2509,6 @@ void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
        <programlisting>
        .poll = drm_poll,
        .read = drm_read,
-       .fasync = drm_fasync,
        .llseek = no_llseek,
        </programlisting>
       </para>
drivers/gpu/drm/ast/ast_drv.c +0 -1
index a144fb0..60f1ce3 100644
@@ -190,7 +190,6 @@ static const struct file_operations ast_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = ast_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/cirrus/cirrus_drv.c +0 -1
index d35d99c..dd9c908 100644
@@ -85,7 +85,6 @@ static const struct file_operations cirrus_driver_fops = {
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
-       .fasync = drm_fasync,
 };
 static struct drm_driver driver = {
        .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
drivers/gpu/drm/drm_fops.c +0 -14
index dd47fef..5679971 100644
@@ -74,8 +74,6 @@ static int drm_setup(struct drm_device * dev)
        dev->last_context = 0;
        dev->if_version = 0;
 
-       dev->buf_async = NULL;
-
        DRM_DEBUG("\n");
 
        /*
@@ -373,18 +371,6 @@ out_put_pid:
        return ret;
 }
 
-/** No-op. */
-int drm_fasync(int fd, struct file *filp, int on)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev = priv->minor->dev;
-
-       DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
-                 (long)old_encode_dev(priv->minor->device));
-       return fasync_helper(fd, filp, on, &dev->buf_async);
-}
-EXPORT_SYMBOL(drm_fasync);
-
 static void drm_master_release(struct drm_device *dev, struct file *filp)
 {
        struct drm_file *file_priv = filp->private_data;
drivers/gpu/drm/gma500/psb_drv.c +0 -1
index d13c2fc..99b5293 100644
@@ -622,7 +622,6 @@ static const struct file_operations psb_gem_fops = {
        .unlocked_ioctl = psb_unlocked_ioctl,
        .mmap = drm_gem_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 };
 
drivers/gpu/drm/i810/i810_dma.c +0 -1
index eac755b..ab1892eb 100644
@@ -113,7 +113,6 @@ static const struct file_operations i810_buffer_fops = {
        .release = drm_release,
        .unlocked_ioctl = drm_ioctl,
        .mmap = i810_mmap_buffers,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/i810/i810_drv.c +0 -1
index 2e91fc3..d85c05b 100644
@@ -49,7 +49,6 @@ static const struct file_operations i810_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/i915/i915_drv.c +0 -1
index 13457e3e..9411a74 100644
@@ -994,7 +994,6 @@ static const struct file_operations i915_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_gem_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = i915_compat_ioctl,
drivers/gpu/drm/mga/mga_drv.c +0 -1
index 17d0a63..fe71e1e 100644
@@ -50,7 +50,6 @@ static const struct file_operations mga_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = mga_compat_ioctl,
 #endif
drivers/gpu/drm/mgag200/mgag200_drv.c +0 -1
index bd91964..b570127 100644
@@ -81,7 +81,6 @@ static const struct file_operations mgag200_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = mgag200_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -1
index 1faa75f..b29d04b 100644
@@ -673,7 +673,6 @@ nouveau_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = nouveau_ttm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 #if defined(CONFIG_COMPAT)
        .compat_ioctl = nouveau_compat_ioctl,
drivers/gpu/drm/omapdrm/omap_drv.c +0 -1
index 47e64f9..2603d90 100644
@@ -592,7 +592,6 @@ static const struct file_operations omapdriver_fops = {
                .release = drm_release,
                .mmap = omap_gem_mmap,
                .poll = drm_poll,
-               .fasync = drm_fasync,
                .read = drm_read,
                .llseek = noop_llseek,
 };
drivers/gpu/drm/qxl/qxl_drv.c +0 -1
index 48f2dfd..514118a 100644
@@ -84,7 +84,6 @@ static const struct file_operations qxl_fops = {
        .release = drm_release,
        .unlocked_ioctl = drm_ioctl,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .mmap = qxl_mmap,
 };
 
drivers/gpu/drm/r128/r128_drv.c +0 -1
index 472c38f..c2338cb 100644
@@ -48,7 +48,6 @@ static const struct file_operations r128_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = r128_compat_ioctl,
 #endif
drivers/gpu/drm/radeon/radeon_drv.c +0 -2
index 3585f22..3e52331 100644
@@ -266,7 +266,6 @@ static const struct file_operations radeon_driver_old_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = radeon_compat_ioctl,
@@ -375,7 +374,6 @@ static const struct file_operations radeon_driver_kms_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = radeon_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = radeon_kms_compat_ioctl,
drivers/gpu/drm/rcar-du/rcar_du_drv.c +0 -1
index 5069d9c..c9f7fbd 100644
@@ -230,7 +230,6 @@ static const struct file_operations rcar_du_fops = {
 #endif
        .poll           = drm_poll,
        .read           = drm_read,
-       .fasync         = drm_fasync,
        .llseek         = no_llseek,
        .mmap           = drm_gem_cma_mmap,
 };
drivers/gpu/drm/savage/savage_drv.c +0 -1
index 71b2081..9135c8b 100644
@@ -42,7 +42,6 @@ static const struct file_operations savage_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/shmobile/shmob_drm_drv.c +0 -1
index 7f2ea1a..0155518 100644
@@ -257,7 +257,6 @@ static const struct file_operations shmob_drm_fops = {
 #endif
        .poll           = drm_poll,
        .read           = drm_read,
-       .fasync         = drm_fasync,
        .llseek         = no_llseek,
        .mmap           = drm_gem_cma_mmap,
 };
drivers/gpu/drm/sis/sis_drv.c +0 -1
index 5a5325e..b88b2d3 100644
@@ -72,7 +72,6 @@ static const struct file_operations sis_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/tdfx/tdfx_drv.c +0 -1
index ddfa743..951ec13 100644
@@ -48,7 +48,6 @@ static const struct file_operations tdfx_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/tilcdc/tilcdc_drv.c +0 -1
index 14801c2..116da19 100644
@@ -497,7 +497,6 @@ static const struct file_operations fops = {
 #endif
        .poll               = drm_poll,
        .read               = drm_read,
-       .fasync             = drm_fasync,
        .llseek             = no_llseek,
        .mmap               = drm_gem_cma_mmap,
 };
drivers/gpu/drm/udl/udl_drv.c +0 -1
index bb0af58..7650dc0 100644
@@ -65,7 +65,6 @@ static const struct file_operations udl_driver_fops = {
        .read = drm_read,
        .unlocked_ioctl = drm_ioctl,
        .release = drm_release,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/via/via_drv.c +0 -1
index f4ae203..4487999 100644
@@ -64,7 +64,6 @@ static const struct file_operations via_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -1
index 9c27d42..0dcfa6b 100644
@@ -1103,7 +1103,6 @@ static const struct file_operations vmwgfx_driver_fops = {
        .mmap = vmw_mmap,
        .poll = vmw_fops_poll,
        .read = vmw_fops_read,
-       .fasync = drm_fasync,
 #if defined(CONFIG_COMPAT)
        .compat_ioctl = drm_compat_ioctl,
 #endif
drivers/gpu/host1x/drm/drm.c +0 -1
index b128b90..15684bf 100644
@@ -508,7 +508,6 @@ static const struct file_operations tegra_drm_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = tegra_drm_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = drm_compat_ioctl,
drivers/staging/imx-drm/imx-drm-core.c +0 -1
index 2c58533..e826086 100644
@@ -199,7 +199,6 @@ static const struct file_operations imx_drm_driver_fops = {
        .unlocked_ioctl = drm_ioctl,
        .mmap = drm_gem_cma_mmap,
        .poll = drm_poll,
-       .fasync = drm_fasync,
        .read = drm_read,
        .llseek = noop_llseek,
 };
include/drm/drmP.h +0 -4
index d05beac..a79dcb0 100644
@@ -1168,8 +1168,6 @@ struct drm_device {
 
        /*@} */
 
-       struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
-
        struct drm_agp_head *agp;       /**< AGP data */
 
        struct device *dev;             /**< Device structure */
@@ -1276,7 +1274,6 @@ extern int drm_lastclose(struct drm_device *dev);
 extern struct mutex drm_global_mutex;
 extern int drm_open(struct inode *inode, struct file *filp);
 extern int drm_stub_open(struct inode *inode, struct file *filp);
-extern int drm_fasync(int fd, struct file *filp, int on);
 extern ssize_t drm_read(struct file *filp, char __user *buffer,
                        size_t count, loff_t *offset);
 extern int drm_release(struct inode *inode, struct file *filp);
--

1.8.3.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#18 lore raw

PATCH 14/25 drm: rip out DRIVER_FB_DMA and related code

In reply to Daniel Vetter

No driver ever sets that flag, so good riddance!

---
 drivers/gpu/drm/drm_bufs.c | 161 +--------------------------------------------
 include/drm/drmP.h         |   1 -
 2 files changed, 2 insertions(+), 160 deletions(-)
drivers/gpu/drm/drm_bufs.c +2 -159
index cccc25f..5f73f0a 100644
@@ -1130,161 +1130,6 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
 	return 0;
 }
 
-static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request)
-{
-	struct drm_device_dma *dma = dev->dma;
-	struct drm_buf_entry *entry;
-	struct drm_buf *buf;
-	unsigned long offset;
-	unsigned long agp_offset;
-	int count;
-	int order;
-	int size;
-	int alignment;
-	int page_order;
-	int total;
-	int byte_count;
-	int i;
-	struct drm_buf **temp_buflist;
-
-	if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
-		return -EINVAL;
-
-	if (!dma)
-		return -EINVAL;
-
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
-	count = request->count;
-	order = order_base_2(request->size);
-	size = 1 << order;
-
-	alignment = (request->flags & _DRM_PAGE_ALIGN)
-	    ? PAGE_ALIGN(size) : size;
-	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
-	total = PAGE_SIZE << page_order;
-
-	byte_count = 0;
-	agp_offset = request->agp_start;
-
-	DRM_DEBUG("count:      %d\n", count);
-	DRM_DEBUG("order:      %d\n", order);
-	DRM_DEBUG("size:       %d\n", size);
-	DRM_DEBUG("agp_offset: %lu\n", agp_offset);
-	DRM_DEBUG("alignment:  %d\n", alignment);
-	DRM_DEBUG("page_order: %d\n", page_order);
-	DRM_DEBUG("total:      %d\n", total);
-
-	if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-		return -EINVAL;
-
-	spin_lock(&dev->count_lock);
-	if (dev->buf_use) {
-		spin_unlock(&dev->count_lock);
-		return -EBUSY;
-	}
-	atomic_inc(&dev->buf_alloc);
-	spin_unlock(&dev->count_lock);
-
-	mutex_lock(&dev->struct_mutex);
-	entry = &dma->bufs[order];
-	if (entry->buf_count) {
-		mutex_unlock(&dev->struct_mutex);
-		atomic_dec(&dev->buf_alloc);
-		return -ENOMEM;	/* May only call once for each order */
-	}
-
-	if (count < 0 || count > 4096) {
-		mutex_unlock(&dev->struct_mutex);
-		atomic_dec(&dev->buf_alloc);
-		return -EINVAL;
-	}
-
-	entry->buflist = kzalloc(count * sizeof(*entry->buflist),
-				GFP_KERNEL);
-	if (!entry->buflist) {
-		mutex_unlock(&dev->struct_mutex);
-		atomic_dec(&dev->buf_alloc);
-		return -ENOMEM;
-	}
-
-	entry->buf_size = size;
-	entry->page_order = page_order;
-
-	offset = 0;
-
-	while (entry->buf_count < count) {
-		buf = &entry->buflist[entry->buf_count];
-		buf->idx = dma->buf_count + entry->buf_count;
-		buf->total = alignment;
-		buf->order = order;
-		buf->used = 0;
-
-		buf->offset = (dma->byte_count + offset);
-		buf->bus_address = agp_offset + offset;
-		buf->address = (void *)(agp_offset + offset);
-		buf->next = NULL;
-		buf->waiting = 0;
-		buf->pending = 0;
-		buf->file_priv = NULL;
-
-		buf->dev_priv_size = dev->driver->dev_priv_size;
-		buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
-		if (!buf->dev_private) {
-			/* Set count correctly so we free the proper amount. */
-			entry->buf_count = count;
-			drm_cleanup_buf_error(dev, entry);
-			mutex_unlock(&dev->struct_mutex);
-			atomic_dec(&dev->buf_alloc);
-			return -ENOMEM;
-		}
-
-		DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
-
-		offset += alignment;
-		entry->buf_count++;
-		byte_count += PAGE_SIZE << page_order;
-	}
-
-	DRM_DEBUG("byte_count: %d\n", byte_count);
-
-	temp_buflist = krealloc(dma->buflist,
-				(dma->buf_count + entry->buf_count) *
-				sizeof(*dma->buflist), GFP_KERNEL);
-	if (!temp_buflist) {
-		/* Free the entry because it isn't valid */
-		drm_cleanup_buf_error(dev, entry);
-		mutex_unlock(&dev->struct_mutex);
-		atomic_dec(&dev->buf_alloc);
-		return -ENOMEM;
-	}
-	dma->buflist = temp_buflist;
-
-	for (i = 0; i < entry->buf_count; i++) {
-		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
-	}
-
-	dma->buf_count += entry->buf_count;
-	dma->seg_count += entry->seg_count;
-	dma->page_count += byte_count >> PAGE_SHIFT;
-	dma->byte_count += byte_count;
-
-	DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
-	DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
-
-	mutex_unlock(&dev->struct_mutex);
-
-	request->count = entry->buf_count;
-	request->size = size;
-
-	dma->flags = _DRM_DMA_USE_FB;
-
-	atomic_dec(&dev->buf_alloc);
-	return 0;
-}
-
-
 /**
  * Add buffers for DMA transfers (ioctl).
  *
@@ -1319,7 +1164,7 @@ int drm_addbufs(struct drm_device *dev, void *data,
 	if (request->flags & _DRM_SG_BUFFER)
 		ret = drm_addbufs_sg(dev, request);
 	else if (request->flags & _DRM_FB_BUFFER)
-		ret = drm_addbufs_fb(dev, request);
+		ret = -EINVAL;
 	else
 		ret = drm_addbufs_pci(dev, request);
 
@@ -1556,9 +1401,7 @@ int drm_mapbufs(struct drm_device *dev, void *data,
 	if (request->count >= dma->buf_count) {
 		if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
 		    || (drm_core_check_feature(dev, DRIVER_SG)
-			&& (dma->flags & _DRM_DMA_USE_SG))
-		    || (drm_core_check_feature(dev, DRIVER_FB_DMA)
-			&& (dma->flags & _DRM_DMA_USE_FB))) {
+			&& (dma->flags & _DRM_DMA_USE_SG))) {
 			struct drm_local_map *map = dev->agp_buffer_map;
 			unsigned long token = dev->agp_buffer_token;
 
include/drm/drmP.h +0 -1
index a79dcb0..81de427 100644
@@ -149,7 +149,6 @@ int drm_err(const char *func, const char *format, ...);
 #define DRIVER_IRQ_SHARED  0x80
 #define DRIVER_IRQ_VBL     0x100
 #define DRIVER_DMA_QUEUE   0x200
-#define DRIVER_FB_DMA      0x400
 #define DRIVER_IRQ_VBL2    0x800
 #define DRIVER_GEM         0x1000
 #define DRIVER_MODESET     0x2000
Signature · 1 line
1.8.3.2
#19 lore raw

PATCH 15/25 drm: rip out a few unused DRIVER flags

In reply to Daniel Vetter

The gma500 driver somehow set the DRIVER_IRQ_VBL flag, but since there's no code at all to check for this we can kill it. The other two are completely unused.

---
 drivers/gpu/drm/gma500/psb_drv.c | 2 +-
 include/drm/drmP.h               | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/gma500/psb_drv.c +1 -1
index 99b5293..1383e75 100644
@@ -627,7 +627,7 @@ static const struct file_operations psb_gem_fops = {
 
 static struct drm_driver driver = {
 	.driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
-			   DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
+			   DRIVER_MODESET | DRIVER_GEM ,
 	.load = psb_driver_load,
 	.unload = psb_driver_unload,
 
include/drm/drmP.h +0 -3
index 81de427..f526a7a9 100644
@@ -147,9 +147,6 @@ int drm_err(const char *func, const char *format, ...);
 #define DRIVER_HAVE_DMA    0x20
 #define DRIVER_HAVE_IRQ    0x40
 #define DRIVER_IRQ_SHARED  0x80
-#define DRIVER_IRQ_VBL     0x100
-#define DRIVER_DMA_QUEUE   0x200
-#define DRIVER_IRQ_VBL2    0x800
 #define DRIVER_GEM         0x1000
 #define DRIVER_MODESET     0x2000
 #define DRIVER_PRIME       0x4000
Signature · 1 line
1.8.3.2
#20 lore raw

PATCH 16/25 drm: remove a bunch of unused #defines from drmP.h

In reply to Daniel Vetter
---
 include/drm/drmP.h | 9 ---------
 1 file changed, 9 deletions(-)
include/drm/drmP.h +0 -9
index f526a7a9..914055e 100644
@@ -165,13 +165,7 @@ int drm_err(const char *func, const char *format, ...);
 #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
 #define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
 #define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
-#define DRM_LOOPING_LIMIT     5000000
-#define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
-#define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
 
-#define DRM_FLAG_DEBUG	  0x01
-
-#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
 #define DRM_MAP_HASH_OFFSET 0x10000000
 
 /*@}*/
@@ -260,9 +254,6 @@ int drm_err(const char *func, const char *format, ...);
 
 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
 
-#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
-#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
-
 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
 
 /**
Signature · 1 line
1.8.3.2
#21 lore raw

PATCH 17/25 drm: rip out drm_core_has_MTRR checks

In reply to Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

David Herrmann suggest to also kill the DRIVER_USE_MTRR flag since it's now unused, which spurred me to do a bit a better audit of the affected drivers. David helped a lot in that. Quoting our mail discussion:

Quoted 37 lines · David Herrmann
Quoted 14 lines · Daniel Vetter
Quoted 4 lines · David Herrmann
Quoted 4 lines
(quoted diff) +0 -4
-#if __OS_HAS_MTRR
-static inline int drm_core_has_MTRR(struct drm_device *dev)
-{
-       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +0 -5
-}
-#else
-#define drm_core_has_MTRR(dev) (0)
-#endif
-

That was the last user of DRIVER_USE_MTRR (apart from drivers setting it in .driver_features). Any reason to keep it around?

Quoted 4 lines

Yeah, I guess we could rip things out. Which will also force me to properly audit drivers for the eventual behaviour change this could entail (in case there's an x86 driver which did not ask for an mtrr, but iirc there isn't).

david@david-mb ~/dev/kernel/linux $ for i in drivers/gpu/drm/* ; do if test -d "$i" ; then if ! grep -q USE_MTRR -r $i ; then echo $i ; fi ; fi ; done
drivers/gpu/drm/exynos
drivers/gpu/drm/gma500
drivers/gpu/drm/i2c
drivers/gpu/drm/nouveau
drivers/gpu/drm/omapdrm
drivers/gpu/drm/qxl
drivers/gpu/drm/rcar-du
drivers/gpu/drm/shmobile
drivers/gpu/drm/tilcdc
drivers/gpu/drm/ttm
drivers/gpu/drm/udl
drivers/gpu/drm/vmwgfx
david@david-mb ~/dev/kernel/linux $

Quoted 4 lines

So for x86 gma500,nouveau,qxl,udl,vmwgfx don't set DRIVER_USE_MTRR. But I cannot tell whether they break if we call arch_phys_wc_add/del, anyway. At least nouveau seemed to work here, but it doesn't use AGP or drm_bufs, I guess.

Cool, thanks a lot for stitching together the list of drivers to look at. So for real KMS drivers it's the drives responsibility to add an mtrr if it needs one. nouvea, radeon, mgag200, i915 and vmwgfx do that already. Somehow the savage driver also ends up doing that, I have no idea why.

Note that gma500 as a pure KMS driver doesn't need MTRR setup since the platforms that it supports all support PAT. So no MTRRs needed to get wc iomappings.

The mtrr support in the drm core is all for legacy mappings of garts, framebuffers and registers. All legacy drivers set the USE_MTRR flag, so we're good there.

All in all I think we can really just ditch this

/endquote

v2: Also kill DRIVER_USE_MTRR as suggested by David Herrmann

v3: Rebase on top of David Herrmann's agp setup/cleanup changes.

Cc David Herrmann <[email protected]>
Cc Andy Lutomirski <[email protected]>
---
 drivers/gpu/drm/ast/ast_drv.c         |  2 +-
 drivers/gpu/drm/cirrus/cirrus_drv.c   |  2 +-
 drivers/gpu/drm/drm_bufs.c            | 13 +++++--------
 drivers/gpu/drm/drm_pci.c             | 14 ++++++--------
 drivers/gpu/drm/drm_vm.c              |  3 +--
 drivers/gpu/drm/i810/i810_drv.c       |  2 +-
 drivers/gpu/drm/i915/i915_drv.c       |  2 +-
 drivers/gpu/drm/mga/mga_drv.c         |  2 +-
 drivers/gpu/drm/mgag200/mgag200_drv.c |  2 +-
 drivers/gpu/drm/r128/r128_drv.c       |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.c   |  4 ++--
 drivers/gpu/drm/savage/savage_drv.c   |  2 +-
 drivers/gpu/drm/sis/sis_drv.c         |  2 +-
 drivers/gpu/drm/tdfx/tdfx_drv.c       |  1 -
 drivers/gpu/drm/via/via_drv.c         |  2 +-
 include/drm/drmP.h                    | 11 -----------
 16 files changed, 24 insertions(+), 42 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +1 -1
index 60f1ce3..32e270d 100644
@@ -197,7 +197,7 @@ static const struct file_operations ast_fops = {
 };
 
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_MTRR | DRIVER_MODESET | DRIVER_GEM,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM,
 	.dev_priv_size = 0,
 
 	.load = ast_driver_load,
drivers/gpu/drm/cirrus/cirrus_drv.c +1 -1
index dd9c908..138364d 100644
@@ -87,7 +87,7 @@ static const struct file_operations cirrus_driver_fops = {
 #endif
 };
 static struct drm_driver driver = {
-	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM,
 	.load = cirrus_driver_load,
 	.unload = cirrus_driver_unload,
 	.fops = &cirrus_driver_fops,
drivers/gpu/drm/drm_bufs.c +5 -8
index 5f73f0a..f63133b 100644
@@ -207,12 +207,10 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
 			return 0;
 		}
 
-		if (drm_core_has_MTRR(dev)) {
-			if (map->type == _DRM_FRAME_BUFFER ||
-			    (map->flags & _DRM_WRITE_COMBINING)) {
-				map->mtrr =
-					arch_phys_wc_add(map->offset, map->size);
-			}
+		if (map->type == _DRM_FRAME_BUFFER ||
+		    (map->flags & _DRM_WRITE_COMBINING)) {
+			map->mtrr =
+				arch_phys_wc_add(map->offset, map->size);
 		}
 		if (map->type == _DRM_REGISTERS) {
 			if (map->flags & _DRM_WRITE_COMBINING)
@@ -464,8 +462,7 @@ int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map)
 		iounmap(map->handle);
 		/* FALLTHROUGH */
 	case _DRM_FRAME_BUFFER:
-		if (drm_core_has_MTRR(dev))
-			arch_phys_wc_del(map->mtrr);
+		arch_phys_wc_del(map->mtrr);
 		break;
 	case _DRM_SHM:
 		vfree(map->handle);
drivers/gpu/drm/drm_pci.c +6 -8
index 0f54ad8..3fca2db 100644
@@ -272,12 +272,11 @@ static int drm_pci_agp_init(struct drm_device *dev)
 			DRM_ERROR("Cannot initialize the agpgart module.\n");
 			return -EINVAL;
 		}
-		if (drm_core_has_MTRR(dev)) {
-			if (dev->agp)
-				dev->agp->agp_mtrr = arch_phys_wc_add(
-					dev->agp->agp_info.aper_base,
-					dev->agp->agp_info.aper_size *
-					1024 * 1024);
+		if (dev->agp) {
+			dev->agp->agp_mtrr = arch_phys_wc_add(
+				dev->agp->agp_info.aper_base,
+				dev->agp->agp_info.aper_size *
+				1024 * 1024);
 		}
 	}
 	return 0;
@@ -286,8 +285,7 @@ static int drm_pci_agp_init(struct drm_device *dev)
 static void drm_pci_agp_destroy(struct drm_device *dev)
 {
 	if (drm_core_has_AGP(dev) && dev->agp) {
-		if (drm_core_has_MTRR(dev))
-			arch_phys_wc_del(dev->agp->agp_mtrr);
+		arch_phys_wc_del(dev->agp->agp_mtrr);
 		drm_agp_clear(dev);
 		drm_agp_destroy(dev->agp);
 		dev->agp = NULL;
drivers/gpu/drm/drm_vm.c +1 -2
index feb2003..b5c5af7 100644
@@ -251,8 +251,7 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
 			switch (map->type) {
 			case _DRM_REGISTERS:
 			case _DRM_FRAME_BUFFER:
-				if (drm_core_has_MTRR(dev))
-					arch_phys_wc_del(map->mtrr);
+				arch_phys_wc_del(map->mtrr);
 				iounmap(map->handle);
 				break;
 			case _DRM_SHM:
drivers/gpu/drm/i810/i810_drv.c +1 -1
index d85c05b..d8180d2 100644
@@ -57,7 +57,7 @@ static const struct file_operations i810_driver_fops = {
 
 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP |
 	    DRIVER_HAVE_DMA,
 	.dev_priv_size = sizeof(drm_i810_buf_priv_t),
 	.load = i810_driver_load,
drivers/gpu/drm/i915/i915_drv.c +1 -1
index 9411a74..eec47bd 100644
@@ -1006,7 +1006,7 @@ static struct drm_driver driver = {
 	 * deal with them for Intel hardware.
 	 */
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP |
 	    DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME,
 	.load = i915_driver_load,
 	.unload = i915_driver_unload,
drivers/gpu/drm/mga/mga_drv.c +1 -1
index fe71e1e..6b1a87c 100644
@@ -58,7 +58,7 @@ static const struct file_operations mga_driver_fops = {
 
 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+	    DRIVER_USE_AGP | DRIVER_PCI_DMA |
 	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
 	.dev_priv_size = sizeof(drm_mga_buf_priv_t),
 	.load = mga_driver_load,
drivers/gpu/drm/mgag200/mgag200_drv.c +1 -1
index b570127..fcce7b2 100644
@@ -88,7 +88,7 @@ static const struct file_operations mgag200_driver_fops = {
 };
 
 static struct drm_driver driver = {
-	.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
+	.driver_features = DRIVER_GEM | DRIVER_MODESET,
 	.load = mgag200_driver_load,
 	.unload = mgag200_driver_unload,
 	.fops = &mgag200_driver_fops,
drivers/gpu/drm/r128/r128_drv.c +1 -1
index c2338cb..5bd307c 100644
@@ -56,7 +56,7 @@ static const struct file_operations r128_driver_fops = {
 
 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+	    DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
 	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
 	.dev_priv_size = sizeof(drm_r128_buf_priv_t),
 	.load = r128_driver_load,
drivers/gpu/drm/radeon/radeon_drv.c +2 -2
index 3e52331..1f93dd5 100644
@@ -275,7 +275,7 @@ static const struct file_operations radeon_driver_old_fops = {
 
 static struct drm_driver driver_old = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+	    DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
 	    DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED,
 	.dev_priv_size = sizeof(drm_radeon_buf_priv_t),
 	.load = radeon_driver_load,
@@ -382,7 +382,7 @@ static const struct file_operations radeon_driver_kms_fops = {
 
 static struct drm_driver kms_driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | 
+	    DRIVER_USE_AGP |
 	    DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
 	    DRIVER_PRIME,
 	.dev_priv_size = 0,
drivers/gpu/drm/savage/savage_drv.c +1 -1
index 9135c8b..3c03021 100644
@@ -50,7 +50,7 @@ static const struct file_operations savage_driver_fops = {
 
 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
+	    DRIVER_USE_AGP | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
 	.dev_priv_size = sizeof(drm_savage_buf_priv_t),
 	.load = savage_driver_load,
 	.firstopen = savage_driver_firstopen,
drivers/gpu/drm/sis/sis_drv.c +1 -1
index b88b2d3..4383b74 100644
@@ -102,7 +102,7 @@ void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
 }
 
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
+	.driver_features = DRIVER_USE_AGP,
 	.load = sis_driver_load,
 	.unload = sis_driver_unload,
 	.open = sis_driver_open,
drivers/gpu/drm/tdfx/tdfx_drv.c +0 -1
index 951ec13..3492ca5 100644
@@ -55,7 +55,6 @@ static const struct file_operations tdfx_driver_fops = {
 };
 
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_MTRR,
 	.fops = &tdfx_driver_fops,
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
drivers/gpu/drm/via/via_drv.c +1 -1
index 4487999..92684a9 100644
@@ -72,7 +72,7 @@ static const struct file_operations via_driver_fops = {
 
 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
+	    DRIVER_USE_AGP | DRIVER_HAVE_IRQ |
 	    DRIVER_IRQ_SHARED,
 	.load = via_driver_load,
 	.unload = via_driver_unload,
include/drm/drmP.h +0 -11
index 914055e..5b9462d 100644
@@ -76,7 +76,6 @@
 #include <linux/idr.h>
 
 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
-#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
 
 struct module;
 
@@ -141,7 +140,6 @@ int drm_err(const char *func, const char *format, ...);
 /* driver capabilities and requirements mask */
 #define DRIVER_USE_AGP     0x1
 #define DRIVER_REQUIRE_AGP 0x2
-#define DRIVER_USE_MTRR    0x4
 #define DRIVER_PCI_DMA     0x8
 #define DRIVER_SG          0x10
 #define DRIVER_HAVE_DMA    0x20
@@ -1219,15 +1217,6 @@ static inline int drm_core_has_AGP(struct drm_device *dev)
 #define drm_core_has_AGP(dev) (0)
 #endif
 
-#if __OS_HAS_MTRR
-static inline int drm_core_has_MTRR(struct drm_device *dev)
-{
-	return drm_core_check_feature(dev, DRIVER_USE_MTRR);
-}
-#else
-#define drm_core_has_MTRR(dev) (0)
-#endif
-
 static inline void drm_device_set_unplugged(struct drm_device *dev)
 {
 	smp_wmb();
Signature · 1 line
1.8.3.2
#22 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

Quoted 3 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

If any of the new arch_phys_wc_add calls are reachable and if the driver calls arch_phys_wc_add itself, then the lack of refcounting on non-PAT systems may cause a problem. (I don't understand the drm stuff well enough to know whether that can actually happen.)

--Andy

#23 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

If any of the new arch_phys_wc_add calls are reachable and if the driver calls arch_phys_wc_add itself, then the lack of refcounting on non-PAT systems may cause a problem. (I don't understand the drm stuff well enough to know whether that can actually happen.)

This is only about compile-time options really. Somehow drm had the idea to use these check functions instead of #ifdef plus dummy static inline noop functions. David Herrmann just did the same patch for the agp stuff. So refcounting is of no concern here.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#24 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

If any of the new arch_phys_wc_add calls are reachable and if the driver calls arch_phys_wc_add itself, then the lack of refcounting on non-PAT systems may cause a problem. (I don't understand the drm stuff well enough to know whether that can actually happen.)

Quoted 4 lines

This is only about compile-time options really. Somehow drm had the idea to use these check functions instead of #ifdef plus dummy static inline noop functions. David Herrmann just did the same patch for the agp stuff. So refcounting is of no concern here.

I feel like I'm missing something obvious here. On nouveau, prior to this patch, the drm maps code would not touch mtrrs. Now it will. Nouveau already calls arch_phys_wc_add, so if that maps code is reached on the same resource, then there could be refcounting issues.

--Andy

Quoted 5 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#25 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

Quoted 17 lines · Andy Lutomirski
Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

If any of the new arch_phys_wc_add calls are reachable and if the driver calls arch_phys_wc_add itself, then the lack of refcounting on non-PAT systems may cause a problem. (I don't understand the drm stuff well enough to know whether that can actually happen.)

Quoted 4 lines

This is only about compile-time options really. Somehow drm had the idea to use these check functions instead of #ifdef plus dummy static inline noop functions. David Herrmann just did the same patch for the agp stuff. So refcounting is of no concern here.

Quoted 4 lines

I feel like I'm missing something obvious here. On nouveau, prior to this patch, the drm maps code would not touch mtrrs. Now it will. Nouveau already calls arch_phys_wc_add, so if that maps code is reached on the same resource, then there could be refcounting issues.

Oh that kind of confusion. The maps code here is for old userspace drivers, I have some patches in the queue that will disable it properly for kms drivers. So it should never happen that both the kms driver and the maps code in the drm core set up a mtrr mapping. And if it happens someone is doing something really nasty, and that hole will soon be plugged.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#26 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

Quoted 23 lines · Daniel Vetter
Quoted 17 lines · Andy Lutomirski
Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

If any of the new arch_phys_wc_add calls are reachable and if the driver calls arch_phys_wc_add itself, then the lack of refcounting on non-PAT systems may cause a problem. (I don't understand the drm stuff well enough to know whether that can actually happen.)

Quoted 4 lines

This is only about compile-time options really. Somehow drm had the idea to use these check functions instead of #ifdef plus dummy static inline noop functions. David Herrmann just did the same patch for the agp stuff. So refcounting is of no concern here.

Quoted 4 lines

I feel like I'm missing something obvious here. On nouveau, prior to this patch, the drm maps code would not touch mtrrs. Now it will. Nouveau already calls arch_phys_wc_add, so if that maps code is reached on the same resource, then there could be refcounting issues.

Quoted 6 lines

Oh that kind of confusion. The maps code here is for old userspace drivers, I have some patches in the queue that will disable it properly for kms drivers. So it should never happen that both the kms driver and the maps code in the drm core set up a mtrr mapping. And if it happens someone is doing something really nasty, and that hole will soon be plugged.

In that case, I'm convinced. In case you care:

--Andy

Quoted 5 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
Reviewed-by on v1 17/25
#27 lore raw

Re: [PATCH 17/25] drm: rip out drm_core_has_MTRR checks

In reply to Daniel Vetter

Hi

Quoted 70 lines · Daniel Vetter

The new arch_phys_wc_add/del functions do the right thing both with and without MTRR support in the kernel. So we can drop these additional checks.

David Herrmann suggest to also kill the DRIVER_USE_MTRR flag since it's now unused, which spurred me to do a bit a better audit of the affected drivers. David helped a lot in that. Quoting our mail discussion:

Quoted 37 lines · David Herrmann
Quoted 14 lines · Daniel Vetter
Quoted 4 lines · David Herrmann
Quoted 4 lines
include/drm/drmP.h +0 -4
-#if __OS_HAS_MTRR
-static inline int drm_core_has_MTRR(struct drm_device *dev)
-{
-       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
Quoted 8 lines

include/drm/drmP.h static inline int drm_core_has_AGP(struct drm_device *dev) · line 1230

Quoted 5 lines
include/drm/drmP.h +0 -5
-}
-#else
-#define drm_core_has_MTRR(dev) (0)
-#endif
-

That was the last user of DRIVER_USE_MTRR (apart from drivers setting it in .driver_features). Any reason to keep it around?

Quoted 4 lines

Yeah, I guess we could rip things out. Which will also force me to properly audit drivers for the eventual behaviour change this could entail (in case there's an x86 driver which did not ask for an mtrr, but iirc there isn't).

david@david-mb ~/dev/kernel/linux $ for i in drivers/gpu/drm/* ; do if test -d "$i" ; then if ! grep -q USE_MTRR -r $i ; then echo $i ; fi ; fi ; done
drivers/gpu/drm/exynos
drivers/gpu/drm/gma500
drivers/gpu/drm/i2c
drivers/gpu/drm/nouveau
drivers/gpu/drm/omapdrm
drivers/gpu/drm/qxl
drivers/gpu/drm/rcar-du
drivers/gpu/drm/shmobile
drivers/gpu/drm/tilcdc
drivers/gpu/drm/ttm
drivers/gpu/drm/udl
drivers/gpu/drm/vmwgfx
david@david-mb ~/dev/kernel/linux $

Quoted 4 lines

So for x86 gma500,nouveau,qxl,udl,vmwgfx don't set DRIVER_USE_MTRR. But I cannot tell whether they break if we call arch_phys_wc_add/del, anyway. At least nouveau seemed to work here, but it doesn't use AGP or drm_bufs, I guess.

Cool, thanks a lot for stitching together the list of drivers to look at. So for real KMS drivers it's the drives responsibility to add an mtrr if it needs one. nouvea, radeon, mgag200, i915 and vmwgfx do that already. Somehow the savage driver also ends up doing that, I have no idea why.

Note that gma500 as a pure KMS driver doesn't need MTRR setup since the platforms that it supports all support PAT. So no MTRRs needed to get wc iomappings.

The mtrr support in the drm core is all for legacy mappings of garts, framebuffers and registers. All legacy drivers set the USE_MTRR flag, so we're good there.

All in all I think we can really just ditch this

/endquote

Quoted 7 lines

v2: Also kill DRIVER_USE_MTRR as suggested by David Herrmann

v3: Rebase on top of David Herrmann's agp setup/cleanup changes.

Cc David Herrmann <[email protected]>
Cc Andy Lutomirski <[email protected]>

Regards
David

Quoted 299 lines
---
 drivers/gpu/drm/ast/ast_drv.c         |  2 +-
 drivers/gpu/drm/cirrus/cirrus_drv.c   |  2 +-
 drivers/gpu/drm/drm_bufs.c            | 13 +++++--------
 drivers/gpu/drm/drm_pci.c             | 14 ++++++--------
 drivers/gpu/drm/drm_vm.c              |  3 +--
 drivers/gpu/drm/i810/i810_drv.c       |  2 +-
 drivers/gpu/drm/i915/i915_drv.c       |  2 +-
 drivers/gpu/drm/mga/mga_drv.c         |  2 +-
 drivers/gpu/drm/mgag200/mgag200_drv.c |  2 +-
 drivers/gpu/drm/r128/r128_drv.c       |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.c   |  4 ++--
 drivers/gpu/drm/savage/savage_drv.c   |  2 +-
 drivers/gpu/drm/sis/sis_drv.c         |  2 +-
 drivers/gpu/drm/tdfx/tdfx_drv.c       |  1 -
 drivers/gpu/drm/via/via_drv.c         |  2 +-
 include/drm/drmP.h                    | 11 -----------
 16 files changed, 24 insertions(+), 42 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +1 -1
index 60f1ce3..32e270d 100644
@@ -197,7 +197,7 @@ static const struct file_operations ast_fops = {
 };
 
 static struct drm_driver driver = {
-       .driver_features = DRIVER_USE_MTRR | DRIVER_MODESET | DRIVER_GEM,
+       .driver_features = DRIVER_MODESET | DRIVER_GEM,
        .dev_priv_size = 0,
 
        .load = ast_driver_load,
drivers/gpu/drm/cirrus/cirrus_drv.c +1 -1
index dd9c908..138364d 100644
@@ -87,7 +87,7 @@ static const struct file_operations cirrus_driver_fops = {
 #endif
 };
 static struct drm_driver driver = {
-       .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
+       .driver_features = DRIVER_MODESET | DRIVER_GEM,
        .load = cirrus_driver_load,
        .unload = cirrus_driver_unload,
        .fops = &cirrus_driver_fops,
drivers/gpu/drm/drm_bufs.c +5 -8
index 5f73f0a..f63133b 100644
@@ -207,12 +207,10 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
                        return 0;
                }
 
-               if (drm_core_has_MTRR(dev)) {
-                       if (map->type == _DRM_FRAME_BUFFER ||
-                           (map->flags & _DRM_WRITE_COMBINING)) {
-                               map->mtrr =
-                                       arch_phys_wc_add(map->offset, map->size);
-                       }
+               if (map->type == _DRM_FRAME_BUFFER ||
+                   (map->flags & _DRM_WRITE_COMBINING)) {
+                       map->mtrr =
+                               arch_phys_wc_add(map->offset, map->size);
                }
                if (map->type == _DRM_REGISTERS) {
                        if (map->flags & _DRM_WRITE_COMBINING)
@@ -464,8 +462,7 @@ int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map)
                iounmap(map->handle);
                /* FALLTHROUGH */
        case _DRM_FRAME_BUFFER:
-               if (drm_core_has_MTRR(dev))
-                       arch_phys_wc_del(map->mtrr);
+               arch_phys_wc_del(map->mtrr);
                break;
        case _DRM_SHM:
                vfree(map->handle);
drivers/gpu/drm/drm_pci.c +6 -8
index 0f54ad8..3fca2db 100644
@@ -272,12 +272,11 @@ static int drm_pci_agp_init(struct drm_device *dev)
                        DRM_ERROR("Cannot initialize the agpgart module.\n");
                        return -EINVAL;
                }
-               if (drm_core_has_MTRR(dev)) {
-                       if (dev->agp)
-                               dev->agp->agp_mtrr = arch_phys_wc_add(
-                                       dev->agp->agp_info.aper_base,
-                                       dev->agp->agp_info.aper_size *
-                                       1024 * 1024);
+               if (dev->agp) {
+                       dev->agp->agp_mtrr = arch_phys_wc_add(
+                               dev->agp->agp_info.aper_base,
+                               dev->agp->agp_info.aper_size *
+                               1024 * 1024);
                }
        }
        return 0;
@@ -286,8 +285,7 @@ static int drm_pci_agp_init(struct drm_device *dev)
 static void drm_pci_agp_destroy(struct drm_device *dev)
 {
        if (drm_core_has_AGP(dev) && dev->agp) {
-               if (drm_core_has_MTRR(dev))
-                       arch_phys_wc_del(dev->agp->agp_mtrr);
+               arch_phys_wc_del(dev->agp->agp_mtrr);
                drm_agp_clear(dev);
                drm_agp_destroy(dev->agp);
                dev->agp = NULL;
drivers/gpu/drm/drm_vm.c +1 -2
index feb2003..b5c5af7 100644
@@ -251,8 +251,7 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
                        switch (map->type) {
                        case _DRM_REGISTERS:
                        case _DRM_FRAME_BUFFER:
-                               if (drm_core_has_MTRR(dev))
-                                       arch_phys_wc_del(map->mtrr);
+                               arch_phys_wc_del(map->mtrr);
                                iounmap(map->handle);
                                break;
                        case _DRM_SHM:
drivers/gpu/drm/i810/i810_drv.c +1 -1
index d85c05b..d8180d2 100644
@@ -57,7 +57,7 @@ static const struct file_operations i810_driver_fops = {
 
 static struct drm_driver driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP |
            DRIVER_HAVE_DMA,
        .dev_priv_size = sizeof(drm_i810_buf_priv_t),
        .load = i810_driver_load,
drivers/gpu/drm/i915/i915_drv.c +1 -1
index 9411a74..eec47bd 100644
@@ -1006,7 +1006,7 @@ static struct drm_driver driver = {
         * deal with them for Intel hardware.
         */
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
+           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP |
            DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME,
        .load = i915_driver_load,
        .unload = i915_driver_unload,
drivers/gpu/drm/mga/mga_drv.c +1 -1
index fe71e1e..6b1a87c 100644
@@ -58,7 +58,7 @@ static const struct file_operations mga_driver_fops = {
 
 static struct drm_driver driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+           DRIVER_USE_AGP | DRIVER_PCI_DMA |
            DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
        .dev_priv_size = sizeof(drm_mga_buf_priv_t),
        .load = mga_driver_load,
drivers/gpu/drm/mgag200/mgag200_drv.c +1 -1
index b570127..fcce7b2 100644
@@ -88,7 +88,7 @@ static const struct file_operations mgag200_driver_fops = {
 };
 
 static struct drm_driver driver = {
-       .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
+       .driver_features = DRIVER_GEM | DRIVER_MODESET,
        .load = mgag200_driver_load,
        .unload = mgag200_driver_unload,
        .fops = &mgag200_driver_fops,
drivers/gpu/drm/r128/r128_drv.c +1 -1
index c2338cb..5bd307c 100644
@@ -56,7 +56,7 @@ static const struct file_operations r128_driver_fops = {
 
 static struct drm_driver driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+           DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
            DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
        .dev_priv_size = sizeof(drm_r128_buf_priv_t),
        .load = r128_driver_load,
drivers/gpu/drm/radeon/radeon_drv.c +2 -2
index 3e52331..1f93dd5 100644
@@ -275,7 +275,7 @@ static const struct file_operations radeon_driver_old_fops = {
 
 static struct drm_driver driver_old = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+           DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
            DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED,
        .dev_priv_size = sizeof(drm_radeon_buf_priv_t),
        .load = radeon_driver_load,
@@ -382,7 +382,7 @@ static const struct file_operations radeon_driver_kms_fops = {
 
 static struct drm_driver kms_driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR |
+           DRIVER_USE_AGP |
            DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
            DRIVER_PRIME,
        .dev_priv_size = 0,
drivers/gpu/drm/savage/savage_drv.c +1 -1
index 9135c8b..3c03021 100644
@@ -50,7 +50,7 @@ static const struct file_operations savage_driver_fops = {
 
 static struct drm_driver driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
+           DRIVER_USE_AGP | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
        .dev_priv_size = sizeof(drm_savage_buf_priv_t),
        .load = savage_driver_load,
        .firstopen = savage_driver_firstopen,
drivers/gpu/drm/sis/sis_drv.c +1 -1
index b88b2d3..4383b74 100644
@@ -102,7 +102,7 @@ void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
 }
 
 static struct drm_driver driver = {
-       .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
+       .driver_features = DRIVER_USE_AGP,
        .load = sis_driver_load,
        .unload = sis_driver_unload,
        .open = sis_driver_open,
drivers/gpu/drm/tdfx/tdfx_drv.c +0 -1
index 951ec13..3492ca5 100644
@@ -55,7 +55,6 @@ static const struct file_operations tdfx_driver_fops = {
 };
 
 static struct drm_driver driver = {
-       .driver_features = DRIVER_USE_MTRR,
        .fops = &tdfx_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
drivers/gpu/drm/via/via_drv.c +1 -1
index 4487999..92684a9 100644
@@ -72,7 +72,7 @@ static const struct file_operations via_driver_fops = {
 
 static struct drm_driver driver = {
        .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
+           DRIVER_USE_AGP | DRIVER_HAVE_IRQ |
            DRIVER_IRQ_SHARED,
        .load = via_driver_load,
        .unload = via_driver_unload,
include/drm/drmP.h +0 -12
index 914055e..5b9462d 100644
@@ -76,7 +76,6 @@
 #include <linux/idr.h>
 
 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
-#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
 
 struct module;
 
@@ -141,7 +140,6 @@ int drm_err(const char *func, const char *format, ...);
 /* driver capabilities and requirements mask */
 #define DRIVER_USE_AGP     0x1
 #define DRIVER_REQUIRE_AGP 0x2
-#define DRIVER_USE_MTRR    0x4
 #define DRIVER_PCI_DMA     0x8
 #define DRIVER_SG          0x10
 #define DRIVER_HAVE_DMA    0x20
@@ -1219,15 +1217,6 @@ static inline int drm_core_has_AGP(struct drm_device *dev)
 #define drm_core_has_AGP(dev) (0)
 #endif
 
-#if __OS_HAS_MTRR
-static inline int drm_core_has_MTRR(struct drm_device *dev)
-{
-       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
-}
-#else
-#define drm_core_has_MTRR(dev) (0)
-#endif
-
 static inline void drm_device_set_unplugged(struct drm_device *dev)
 {
        smp_wmb();
--

1.8.3.2

#28 lore raw

PATCH 18/25 drm/docs: rip out removed driver flags documentation

In reply to Daniel Vetter

I've forgotten this and shuffling all the little pieces into the respective patches is rather cumbersome ...

---
 Documentation/DocBook/drm.tmpl | 29 -----------------------------
 1 file changed, 29 deletions(-)
Documentation/DocBook/drm.tmpl +0 -29
index d51d157..4609cea 100644
@@ -156,13 +156,6 @@
             </para></listitem>
           </varlistentry>
           <varlistentry>
-            <term>DRIVER_USE_MTRR</term>
-            <listitem><para>
-              Driver uses MTRR interface for mapping memory, the DRM core will
-              manage MTRR resources. Deprecated.
-            </para></listitem>
-          </varlistentry>
-          <varlistentry>
             <term>DRIVER_PCI_DMA</term>
             <listitem><para>
               Driver is capable of PCI DMA, mapping of PCI DMA buffers to
@@ -195,28 +188,6 @@
             </para></listitem>
           </varlistentry>
           <varlistentry>
-            <term>DRIVER_IRQ_VBL</term>
-            <listitem><para>Unused. Deprecated.</para></listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>DRIVER_DMA_QUEUE</term>
-            <listitem><para>
-              Should be set if the driver queues DMA requests and completes them
-              asynchronously.  Deprecated.
-            </para></listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>DRIVER_FB_DMA</term>
-            <listitem><para>
-              Driver supports DMA to/from the framebuffer, mapping of frambuffer
-              DMA buffers to userspace will be supported. Deprecated.
-            </para></listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>DRIVER_IRQ_VBL2</term>
-            <listitem><para>Unused. Deprecated.</para></listitem>
-          </varlistentry>
-          <varlistentry>
             <term>DRIVER_GEM</term>
             <listitem><para>
               Driver use the GEM memory manager.
Signature · 1 line
1.8.3.2
#29 lore raw

PATCH 19/25 drm: remove the dma_ioctl special-case

In reply to Daniel Vetter

We might as well have a real ioctl function which checks for the callbacks. This seems to be a remnant from back in the days when each drm driver had their own complete ioctl table, with no shared core drm table at all.

To make really sure no mis-guided user in a kms driver pops up again explicitly check for that in the new ioctl implementation.

v2: Drop the unused variable I've accidentally left in the code, spotted by David Herrmann.

---
 drivers/gpu/drm/drm_bufs.c | 12 ++++++++++++
 drivers/gpu/drm/drm_drv.c  |  6 +-----
 include/drm/drmP.h         |  2 ++
 3 files changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_bufs.c +12 -0
index f63133b..471e051d 100644
@@ -1455,6 +1455,18 @@ int drm_mapbufs(struct drm_device *dev, void *data,
 	return retcode;
 }
 
+int drm_dma_ioctl(struct drm_device *dev, void *data,
+		  struct drm_file *file_priv)
+{
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
+	if (dev->driver->dma_ioctl)
+		return dev->driver->dma_ioctl(dev, data, file_priv);
+	else
+		return -EINVAL;
+}
+
 struct drm_local_map *drm_getsarea(struct drm_device *dev)
 {
 	struct drm_map_list *entry;
drivers/gpu/drm/drm_drv.c +1 -5
index 5b949a7..83078cd 100644
@@ -106,8 +106,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
 	DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
 	DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
-	/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
-	DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
+	DRM_IOCTL_DEF(DRM_IOCTL_DMA, drm_dma_ioctl, DRM_AUTH),
 
 	DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 
@@ -395,9 +394,6 @@ long drm_ioctl(struct file *filp,
 
 	/* Do not trust userspace, use our own definition */
 	func = ioctl->func;
-	/* is there a local override? */
-	if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
-		func = dev->driver->dma_ioctl;
 
 	if (!func) {
 		DRM_DEBUG("no function\n");
include/drm/drmP.h +2 -0
index 5b9462d..2a2a5b7 100644
@@ -1366,6 +1366,8 @@ extern int drm_freebufs(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 extern int drm_mapbufs(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv);
+extern int drm_dma_ioctl(struct drm_device *dev, void *data,
+			 struct drm_file *file_priv);
 
 				/* DMA support (drm_dma.h) */
 extern int drm_legacy_dma_setup(struct drm_device *dev);
Signature · 1 line
1.8.3.2
Reviewed-by on v1 19/25
#30 lore raw

Re: [PATCH 19/25] drm: remove the dma_ioctl special-case

Hi

Quoted 5 lines · Daniel Vetter

We might as well have a real ioctl function which checks for the callbacks. This seems to be a remnant from back in the days when each drm driver had their own complete ioctl table, with no shared core drm table at all.

Quoted 8 lines

To make really sure no mis-guided user in a kms driver pops up again explicitly check for that in the new ioctl implementation.

v2: Drop the unused variable I've accidentally left in the code, spotted by David Herrmann.

Regards
David

Quoted 69 lines
---
 drivers/gpu/drm/drm_bufs.c | 12 ++++++++++++
 drivers/gpu/drm/drm_drv.c  |  6 +-----
 include/drm/drmP.h         |  2 ++
 3 files changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_bufs.c +12 -0
index f63133b..471e051d 100644
@@ -1455,6 +1455,18 @@ int drm_mapbufs(struct drm_device *dev, void *data,
        return retcode;
 }
 
+int drm_dma_ioctl(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       if (drm_core_check_feature(dev, DRIVER_MODESET))
+               return -EINVAL;
+
+       if (dev->driver->dma_ioctl)
+               return dev->driver->dma_ioctl(dev, data, file_priv);
+       else
+               return -EINVAL;
+}
+
 struct drm_local_map *drm_getsarea(struct drm_device *dev)
 {
        struct drm_map_list *entry;
drivers/gpu/drm/drm_drv.c +1 -5
index 5b949a7..83078cd 100644
@@ -106,8 +106,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
        DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
        DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
        DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
-       DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_DMA, drm_dma_ioctl, DRM_AUTH),
 
        DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 
@@ -395,9 +394,6 @@ long drm_ioctl(struct file *filp,
 
        /* Do not trust userspace, use our own definition */
        func = ioctl->func;
-       /* is there a local override? */
-       if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
-               func = dev->driver->dma_ioctl;
 
        if (!func) {
                DRM_DEBUG("no function\n");
include/drm/drmP.h +2 -1
index 5b9462d..2a2a5b7 100644
@@ -1366,6 +1366,8 @@ extern int drm_freebufs(struct drm_device *dev, void *data,
                        struct drm_file *file_priv);
 extern int drm_mapbufs(struct drm_device *dev, void *data,
                       struct drm_file *file_priv);
+extern int drm_dma_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
 
                                /* DMA support (drm_dma.h) */
 extern int drm_legacy_dma_setup(struct drm_device *dev);
--

1.8.3.2

#31 lore raw

PATCH 20/25 drm/memory: don't export agp helpers

In reply to Daniel Vetter

They're only used by the agpgart support code in drm_agpgart.c, not by any drivers.

I think long-term we should create a drm_internal.h include file with all the various functions only used by the drm core and not exported to drivers, and remove them from drmP.h. Oh, and someone should kill that upper-case P sometimes ;-) But that's all stuff for future patch bombs.

---
 drivers/gpu/drm/drm_memory.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_memory.c +0 -2
index 126d50e..64e44fa 100644
@@ -86,7 +86,6 @@ void drm_free_agp(DRM_AGP_MEM * handle, int pages)
 {
 	agp_free_memory(handle);
 }
-EXPORT_SYMBOL(drm_free_agp);
 
 /** Wrapper around agp_bind_memory() */
 int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
@@ -99,7 +98,6 @@ int drm_unbind_agp(DRM_AGP_MEM * handle)
 {
 	return agp_unbind_memory(handle);
 }
-EXPORT_SYMBOL(drm_unbind_agp);
 
 #else  /*  __OS_HAS_AGP  */
 static inline void *agp_remap(unsigned long offset, unsigned long size,
Signature · 1 line
1.8.3.2
#32 lore raw

PATCH 21/25 drm: hollow-out GET_CLIENT ioctl

In reply to Daniel Vetter

We not only have debugfs files to do pretty much the equivalent of lsof, we also have an ioctl. Not that compared to lsof this dumps a wee bit more information, but we can still get at that from debugfs easily.

I've dug around in mesa, libdrm and ddx histories and the only users seem to be drm/tests/dristat.c and drm/tests/getclients.c. The later is a testcase for the ioctl itself since up to

commit b018fcdaa5e8b4eabb8cffda687d00004a3c4785

Author: Eric Anholt <[email protected]>
Date:   Thu Nov 22 18:46:54 2007 +1000

drm: Make DRM_IOCTL_GET_CLIENT return EINVAL when it can't find client #idx

there was actually no way at all for userspace to enumerate all clients since the kernel just wouldn't tell it when to stop. Which completely broke it's only user, dristat -c.

So obviously that ioctl wasn't much use for debugging. Hence I don't see any point in keeping support for a tool which was pretty obviously never really used, and while we have good replacements in the form of equivalent debugfs files.

Still, to keep dristat -c from looping forever again stop it early by returning an unconditional -EINVAL. Also add a comment in the code about why.

v2: Slightly less hollowed-out implementation. libva uses GET_CLIENTS to figure out whether the fd it has is already authenticated or not. So we need to keep that part of things working. Simplest way is to just return one entry to keep va_drm_is_authenticated in libva/va/drm/va_drm_auth.c working.

This is exercised by igt/drm_get_client_auth which contains a copypasta of the libva auth check code.

Cc Gwenole Beauchesne <[email protected]>
Cc David Herrmann <[email protected]>
Cc Eric Anholt <[email protected]>
---
 drivers/gpu/drm/drm_ioctl.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)
drivers/gpu/drm/drm_ioctl.c +22 -21
index 0acf080..ac8ca5c 100644
@@ -217,29 +217,30 @@ int drm_getclient(struct drm_device *dev, void *data,
 		  struct drm_file *file_priv)
 {
 	struct drm_client *client = data;
-	struct drm_file *pt;
-	int idx;
-	int i;
-
-	idx = client->idx;
-	i = 0;
 
-	mutex_lock(&dev->struct_mutex);
-	list_for_each_entry(pt, &dev->filelist, lhead) {
-		if (i++ >= idx) {
-			client->auth = pt->authenticated;
-			client->pid = pid_vnr(pt->pid);
-			client->uid = from_kuid_munged(current_user_ns(), pt->uid);
-			client->magic = pt->magic;
-			client->iocs = pt->ioctl_count;
-			mutex_unlock(&dev->struct_mutex);
-
-			return 0;
-		}
+	/*
+	 * Hollowed-out getclient ioctl to keep some dead old drm tests/tools
+	 * not breaking completely. Userspace tools stop enumerating one they
+	 * get -EINVAL, hence this is the return value we need to hand back for
+	 * no clients tracked.
+	 *
+	 * Unfortunately some clients (*cough* libva *cough*) use this in a fun
+	 * attempt to figure out whether they're authenticated or not. Since
+	 * that's the only thing they care about, give it to the directly
+	 * instead of walking one giant list.
+	 */
+	if (client->idx == 0) {
+		client->auth = file_priv->authenticated;
+		client->pid = pid_vnr(file_priv->pid);
+		client->uid = from_kuid_munged(current_user_ns(),
+					       file_priv->uid);
+		client->magic = 0;
+		client->iocs = 0;
+
+		return 0;
+	} else {
+		return -EINVAL;
 	}
-	mutex_unlock(&dev->struct_mutex);
-
-	return -EINVAL;
 }
 
 /**
Signature · 1 line
1.8.3.2
#33 lore raw

PATCH 22/25 drm: no-op out GET_STATS ioctl

In reply to Daniel Vetter

Again only used by a tests in libdrm and by dristat. Nowadays we have much better tracing tools to get detailed insights into what a drm driver is doing. And for a simple "does it work" kind of question that these stats could answer we have plenty of dmesg debug log spew.

So I don't see any use for this stat gathering complexity at all.

To be able to gradually drop things start with ripping out the interfaces to it, here the ioctl.

To prevent dristat from eating its own stack garbage we can't use the drm_noop ioctl though, since we need to clear the return data with a memset.

---
 drivers/gpu/drm/drm_ioctl.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/drm_ioctl.c +1 -12
index ac8ca5c..cffc7c0 100644
@@ -257,21 +257,10 @@ int drm_getstats(struct drm_device *dev, void *data,
 		 struct drm_file *file_priv)
 {
 	struct drm_stats *stats = data;
-	int i;
 
+	/* Clear stats to prevent userspace from eating its stack garbage. */
 	memset(stats, 0, sizeof(*stats));
 
-	for (i = 0; i < dev->counters; i++) {
-		if (dev->types[i] == _DRM_STAT_LOCK)
-			stats->data[i].value =
-			    (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
-		else
-			stats->data[i].value = atomic_read(&dev->counts[i]);
-		stats->data[i].type = dev->types[i];
-	}
-
-	stats->count = dev->counters;
-
 	return 0;
 }
 
Signature · 1 line
1.8.3.2
Reviewed-by on v1 22/25
#34 lore raw

Re: [PATCH 22/25] drm: no-op out GET_STATS ioctl

Quoted 5 lines · Daniel Vetter

Again only used by a tests in libdrm and by dristat. Nowadays we have much better tracing tools to get detailed insights into what a drm driver is doing. And for a simple "does it work" kind of question that these stats could answer we have plenty of dmesg debug log spew.

Quoted 8 lines

So I don't see any use for this stat gathering complexity at all.

To be able to gradually drop things start with ripping out the interfaces to it, here the ioctl.

To prevent dristat from eating its own stack garbage we can't use the drm_noop ioctl though, since we need to clear the return data with a memset.

I'm happy to see these two die. Even back in the day we didn't use them.

This has been quite a trip down memory lane.

Patch 9 typo: s/functinal/functional/
Patch 25 typo: s/loose/lose/

Patches 2, 6-11, 19, 21, 22, 24, 25 are:

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#35 lore raw

Re: [PATCH 22/25] drm: no-op out GET_STATS ioctl

Quoted 16 lines · Eric Anholt
Quoted 5 lines · Daniel Vetter

Again only used by a tests in libdrm and by dristat. Nowadays we have much better tracing tools to get detailed insights into what a drm driver is doing. And for a simple "does it work" kind of question that these stats could answer we have plenty of dmesg debug log spew.

Quoted 8 lines

So I don't see any use for this stat gathering complexity at all.

To be able to gradually drop things start with ripping out the interfaces to it, here the ioctl.

To prevent dristat from eating its own stack garbage we can't use the drm_noop ioctl though, since we need to clear the return data with a memset.

Quoted 7 lines

I'm happy to see these two die. Even back in the day we didn't use them.

This has been quite a trip down memory lane.

Patch 9 typo: s/functinal/functional/
Patch 25 typo: s/loose/lose/

Fixed.

Quoted 3 lines

Patches 2, 6-11, 19, 21, 22, 24, 25 are:

Thanks for the review. I've pushed a fixed branch with r-b tags to

http://cgit.freedesktop.org/~danvet/drm/log/?h=drm-cleanups

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#36 lore raw

PATCH 23/25 drm: fix locking in gem debugfs/procfs file

In reply to Daniel Vetter

The idr is protected with our spinlock, if we don't hold that nothing prevents the gem objects from disappearing from under us.

---
 drivers/gpu/drm/drm_info.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_info.c +4 -0
index d4b20ce..9f8fc4c 100644
@@ -218,7 +218,11 @@ int drm_gem_name_info(struct seq_file *m, void *data)
 	struct drm_device *dev = node->minor->dev;
 
 	seq_printf(m, "  name     size handles refcount\n");
+
+	spin_lock(&dev->object_name_lock);
 	idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
+	spin_unlock(&dev->object_name_lock);
+
 	return 0;
 }
 
Signature · 1 line
1.8.3.2
#37 lore raw

PATCH 24/25 drm: remove procfs code, take 2

In reply to Daniel Vetter

So almost two years ago I've tried to nuke the procfs code already once before:

http://lists.freedesktop.org/archives/dri-devel/2011-October/015707.html

The conclusion was that userspace drivers (specifically libdrm device node detection) stopped relying on procfs in 2001. But after some digging it turned out that the drmstat tool in libdrm is still using those files (but only when certain options are set). So we've decided to keep profcs.

But I when I've started to dig around again what exactly this tool does I've noticed that it tries to read the "mem", "vm", and "vma" files from procfs. Now as far my git history digging shows "mem" never did anything useful (at least in the version that first showed up in upstream history in 2004) and the file was remove in

commit 955b12def42e83287c1bdb1411d99451753c1391

Author: Ben Gamari <[email protected]>
Date:   Tue Feb 17 20:08:49 2009 -0500

drm: Convert proc files to seq_file and introduce debugfs

Which means that for over 4 years drmstat has been broken, and no one cared. In my opinion that's proof enough that no one is actually using drmstat, and so that we can savely nuke the procfs support from drm.

While at it fix up the error case cleanup for debugfs in drm_get_minor.

v2: Fix dates, libdrm stopped relying on procfs for drm node detection in 2001.

v3: fixup compilation warning for !CONFIG_DEBUG_FS, reported by Fengguang Wu.

Cc kbuild test robot <[email protected]>
Cc Dave Airlie <[email protected]>
---
 drivers/gpu/drm/Makefile   |   2 +-
 drivers/gpu/drm/drm_drv.c  |   8 --
 drivers/gpu/drm/drm_proc.c | 209 ---------------------------------------------
 drivers/gpu/drm/drm_stub.c |  32 ++-----
 include/drm/drmP.h         |   8 --
 5 files changed, 9 insertions(+), 250 deletions(-)
 delete mode 100644 drivers/gpu/drm/drm_proc.c
drivers/gpu/drm/Makefile +1 -1
index d943b94..55af865 100644
@@ -7,7 +7,7 @@ ccflags-y := -Iinclude/drm
 drm-y       :=	drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
 		drm_context.o drm_dma.o \
 		drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
-		drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
+		drm_lock.o drm_memory.o drm_stub.o drm_vm.o \
 		drm_agpsupport.o drm_scatter.o drm_pci.o \
 		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
 		drm_crtc.o drm_modes.o drm_edid.o \
drivers/gpu/drm/drm_drv.c +0 -8
index 83078cd..a845f31 100644
@@ -237,13 +237,6 @@ static int __init drm_core_init(void)
 		goto err_p2;
 	}
 
-	drm_proc_root = proc_mkdir("dri", NULL);
-	if (!drm_proc_root) {
-		DRM_ERROR("Cannot create /proc/dri\n");
-		ret = -1;
-		goto err_p3;
-	}
-
 	drm_debugfs_root = debugfs_create_dir("dri", NULL);
 	if (!drm_debugfs_root) {
 		DRM_ERROR("Cannot create /sys/kernel/debug/dri\n");
@@ -266,7 +259,6 @@ err_p1:
 
 static void __exit drm_core_exit(void)
 {
-	remove_proc_entry("dri", NULL);
 	debugfs_remove(drm_debugfs_root);
 	drm_sysfs_destroy();
 
drivers/gpu/drm/drm_proc.c deleted +0 -209

209 lines not on this page · raw message

drivers/gpu/drm/drm_stub.c +8 -24
index aa0664d..ea37c39 100644
@@ -68,7 +68,6 @@ module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600);
 struct idr drm_minors_idr;
 
 struct class *drm_class;
-struct proc_dir_entry *drm_proc_root;
 struct dentry *drm_debugfs_root;
 
 int drm_err(const char *func, const char *format, ...)
@@ -315,9 +314,8 @@ EXPORT_SYMBOL(drm_fill_in_dev);
  * \param sec-minor structure to hold the assigned minor
  * \return negative number on failure.
  *
- * Search an empty entry and initialize it to the given parameters, and
- * create the proc init entry via proc_init(). This routines assigns
- * minor numbers to secondary heads of multi-headed cards
+ * Search an empty entry and initialize it to the given parameters. This
+ * routines assigns minor numbers to secondary heads of multi-headed cards
  */
 int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
 {
@@ -345,20 +343,11 @@ int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
 
 	idr_replace(&drm_minors_idr, new_minor, minor_id);
 
-	if (type == DRM_MINOR_LEGACY) {
-		ret = drm_proc_init(new_minor, drm_proc_root);
-		if (ret) {
-			DRM_ERROR("DRM: Failed to initialize /proc/dri.\n");
-			goto err_mem;
-		}
-	} else
-		new_minor->proc_root = NULL;
-
 #if defined(CONFIG_DEBUG_FS)
 	ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root);
 	if (ret) {
 		DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
-		goto err_g2;
+		goto err_mem;
 	}
 #endif
 
@@ -366,7 +355,7 @@ int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
 	if (ret) {
 		printk(KERN_ERR
 		       "DRM: Error sysfs_device_add.\n");
-		goto err_g2;
+		goto err_debugfs;
 	}
 	*minor = new_minor;
 
@@ -374,10 +363,11 @@ int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
 	return 0;
 
 
-err_g2:
-	if (new_minor->type == DRM_MINOR_LEGACY)
-		drm_proc_cleanup(new_minor, drm_proc_root);
+err_debugfs:
+#if defined(CONFIG_DEBUG_FS)
+	drm_debugfs_cleanup(new_minor);
 err_mem:
+#endif
 	kfree(new_minor);
 err_idr:
 	idr_remove(&drm_minors_idr, minor_id);
@@ -391,10 +381,6 @@ EXPORT_SYMBOL(drm_get_minor);
  *
  * \param sec_minor - structure to be released
  * \return always zero
- *
- * Cleans up the proc resources. Not legal for this to be the
- * last minor released.
- *
  */
 int drm_put_minor(struct drm_minor **minor_p)
 {
@@ -402,8 +388,6 @@ int drm_put_minor(struct drm_minor **minor_p)
 
 	DRM_DEBUG("release secondary minor %d\n", minor->index);
 
-	if (minor->type == DRM_MINOR_LEGACY)
-		drm_proc_cleanup(minor, drm_proc_root);
 #if defined(CONFIG_DEBUG_FS)
 	drm_debugfs_cleanup(minor);
 #endif
include/drm/drmP.h +0 -8
index 2a2a5b7..46b3102 100644
@@ -45,7 +45,6 @@
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
 #include <linux/fs.h>
-#include <linux/proc_fs.h>
 #include <linux/init.h>
 #include <linux/file.h>
 #include <linux/platform_device.h>
@@ -1020,8 +1019,6 @@ struct drm_minor {
 	struct device kdev;		/**< Linux device */
 	struct drm_device *dev;
 
-	struct proc_dir_entry *proc_root;  /**< proc directory entry */
-	struct drm_info_node proc_nodes;
 	struct dentry *debugfs_root;
 
 	struct list_head debugfs_list;
@@ -1474,17 +1471,12 @@ extern unsigned int drm_timestamp_precision;
 extern unsigned int drm_timestamp_monotonic;
 
 extern struct class *drm_class;
-extern struct proc_dir_entry *drm_proc_root;
 extern struct dentry *drm_debugfs_root;
 
 extern struct idr drm_minors_idr;
 
 extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
 
-				/* Proc support (drm_proc.h) */
-extern int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root);
-extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
-
 				/* Debugfs support */
 #if defined(CONFIG_DEBUG_FS)
 extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
Signature · 1 line
1.8.3.2
#38 lore raw

PATCH 25/25 drm: move dev data clearing from drm_setup to lastclose

In reply to Daniel Vetter

We kzalloc this structure, and for real kms devices we should never loose track of things really.

But ums/legacy drivers rely on the drm core to clean up a bit of cruft between lastclose and firstopen (i.e. when X is being restarted), so keep this around. But give it a clear drm_legacy_ prefix and conditionalize the code on !DRIVER_MODESET.

---
 drivers/gpu/drm/drm_drv.c  | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fops.c | 27 +++------------------------
 2 files changed, 30 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +27 -0
index a845f31..3b8d044 100644
@@ -171,6 +171,31 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE( drm_ioctls )
 
 /**
+ * drm_legacy_dev_reinit
+ *
+ * Reinitializes a legacy/ums drm device in it's lastclose function.
+ */
+static void drm_legacy_dev_reinit(struct drm_device *dev)
+{
+	int i;
+
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return;
+
+	atomic_set(&dev->ioctl_count, 0);
+	atomic_set(&dev->vma_count, 0);
+
+	for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
+		atomic_set(&dev->counts[i], 0);
+
+	dev->sigdata.lock = NULL;
+
+	dev->context_flag = 0;
+	dev->last_context = 0;
+	dev->if_version = 0;
+}
+
+/**
  * Take down the DRM device.
  *
  * \param dev DRM device structure.
@@ -209,6 +234,8 @@ int drm_lastclose(struct drm_device * dev)
 	dev->dev_mapping = NULL;
 	mutex_unlock(&dev->struct_mutex);
 
+	drm_legacy_dev_reinit(dev);
+
 	DRM_DEBUG("lastclose completed\n");
 	return 0;
 }
drivers/gpu/drm/drm_fops.c +3 -24
index 5679971..59f4592 100644
@@ -48,7 +48,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
 
 static int drm_setup(struct drm_device * dev)
 {
-	int i;
 	int ret;
 
 	if (dev->driver->firstopen &&
@@ -58,32 +57,12 @@ static int drm_setup(struct drm_device * dev)
 			return ret;
 	}
 
-	atomic_set(&dev->ioctl_count, 0);
-	atomic_set(&dev->vma_count, 0);
-
-	i = drm_legacy_dma_setup(dev);
-	if (i < 0)
-		return i;
-
-	for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
-		atomic_set(&dev->counts[i], 0);
-
-	dev->sigdata.lock = NULL;
+	ret = drm_legacy_dma_setup(dev);
+	if (ret < 0)
+		return ret;
 
-	dev->context_flag = 0;
-	dev->last_context = 0;
-	dev->if_version = 0;
 
 	DRM_DEBUG("\n");
-
-	/*
-	 * The kernel's context could be created here, but is now created
-	 * in drm_dma_enqueue.  This is more resource-efficient for
-	 * hardware that does not do DMA, but may mean that
-	 * drm_select_queue fails between the time the interrupt is
-	 * initialized and the time the queues are initialized.
-	 */
-
 	return 0;
 }
 
Signature · 1 line
1.8.3.2
Reviewed-by on v1 25/25
#39 lore raw

Re: [PATCH 25/25] drm: move dev data clearing from drm_setup to lastclose

Hi

Quoted 10 lines · Daniel Vetter

We kzalloc this structure, and for real kms devices we should never loose track of things really.

But ums/legacy drivers rely on the drm core to clean up a bit of cruft between lastclose and firstopen (i.e. when X is being restarted), so keep this around. But give it a clear drm_legacy_ prefix and conditionalize the code on !DRIVER_MODESET.

Regards
David

Quoted 101 lines
---
 drivers/gpu/drm/drm_drv.c  | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fops.c | 27 +++------------------------
 2 files changed, 30 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +27 -0
index a845f31..3b8d044 100644
@@ -171,6 +171,31 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 #define DRM_CORE_IOCTL_COUNT   ARRAY_SIZE( drm_ioctls )
 
 /**
+ * drm_legacy_dev_reinit
+ *
+ * Reinitializes a legacy/ums drm device in it's lastclose function.
+ */
+static void drm_legacy_dev_reinit(struct drm_device *dev)
+{
+       int i;
+
+       if (drm_core_check_feature(dev, DRIVER_MODESET))
+               return;
+
+       atomic_set(&dev->ioctl_count, 0);
+       atomic_set(&dev->vma_count, 0);
+
+       for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
+               atomic_set(&dev->counts[i], 0);
+
+       dev->sigdata.lock = NULL;
+
+       dev->context_flag = 0;
+       dev->last_context = 0;
+       dev->if_version = 0;
+}
+
+/**
  * Take down the DRM device.
  *
  * \param dev DRM device structure.
@@ -209,6 +234,8 @@ int drm_lastclose(struct drm_device * dev)
        dev->dev_mapping = NULL;
        mutex_unlock(&dev->struct_mutex);
 
+       drm_legacy_dev_reinit(dev);
+
        DRM_DEBUG("lastclose completed\n");
        return 0;
 }
drivers/gpu/drm/drm_fops.c +3 -25
index 5679971..59f4592 100644
@@ -48,7 +48,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
 
 static int drm_setup(struct drm_device * dev)
 {
-       int i;
        int ret;
 
        if (dev->driver->firstopen &&
@@ -58,32 +57,12 @@ static int drm_setup(struct drm_device * dev)
                        return ret;
        }
 
-       atomic_set(&dev->ioctl_count, 0);
-       atomic_set(&dev->vma_count, 0);
-
-       i = drm_legacy_dma_setup(dev);
-       if (i < 0)
-               return i;
-
-       for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
-               atomic_set(&dev->counts[i], 0);
-
-       dev->sigdata.lock = NULL;
+       ret = drm_legacy_dma_setup(dev);
+       if (ret < 0)
+               return ret;
 
-       dev->context_flag = 0;
-       dev->last_context = 0;
-       dev->if_version = 0;
 
        DRM_DEBUG("\n");
-
-       /*
-        * The kernel's context could be created here, but is now created
-        * in drm_dma_enqueue.  This is more resource-efficient for
-        * hardware that does not do DMA, but may mean that
-        * drm_select_queue fails between the time the interrupt is
-        * initialized and the time the queues are initialized.
-        */
-
        return 0;
 }
 
--

1.8.3.2