Module Name:    src
Committed By:   riastradh
Date:           Mon Aug 27 14:47:02 UTC 2018

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/i915: i915_dma.c i915_drv.h
            i915_gem.c

Log Message:
Work around ioctl ABI mistake in i915 drm.

A flags argument was added to the I915_GEM_MMAP ioctl.  The version
of xf86-video-intel we imported was compiled to use the new ioctl
structure including the flags argument, but without initializing the
flags argument, so it would be userland stack garbage causing
i915_gem_mmap_ioctl to fail.

Newer xf86-video-intel will query the mmap version first before
trying to use either the older ioctl structure, with the original
shorter argument and thus no stack garbage (which will be padded with
to the full length in the kernel by drm_ioctl), or the newer ioctl
structure, with the argument initialized.

libdrm does not appear to be affected by this -- it zeroes the longer
structure before passing it in.

Patch from mrg@, diagnosis and explanation by me.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c \
    src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h
cvs rdiff -u -r1.51 -r1.52 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.23 src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.24
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.23	Mon Aug 27 13:43:39 2018
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c	Mon Aug 27 14:47:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_dma.c,v 1.23 2018/08/27 13:43:39 riastradh Exp $	*/
+/*	$NetBSD: i915_dma.c,v 1.24 2018/08/27 14:47:02 riastradh Exp $	*/
 
 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
  */
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_dma.c,v 1.23 2018/08/27 13:43:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_dma.c,v 1.24 2018/08/27 14:47:02 riastradh Exp $");
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
@@ -160,6 +160,9 @@ static int i915_getparam(struct drm_devi
 		value = 1;
 		break;
 	case I915_PARAM_MMAP_VERSION:
+#ifdef __NetBSD__
+		dev_priv->quirks |= QUIRK_NETBSD_VERSION_CALLED;
+#endif
 		value = 1;
 		break;
 	case I915_PARAM_SUBSLICE_TOTAL:
Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h:1.23 src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h:1.24
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h:1.23	Mon Aug 27 13:43:39 2018
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_drv.h	Mon Aug 27 14:47:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_drv.h,v 1.23 2018/08/27 13:43:39 riastradh Exp $	*/
+/*	$NetBSD: i915_drv.h,v 1.24 2018/08/27 14:47:02 riastradh Exp $	*/
 
 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
  */
@@ -1042,6 +1042,11 @@ enum intel_sbi_destination {
 #define QUIRK_PIPEB_FORCE (1<<4)
 #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
 
+#ifdef __NetBSD__
+/* NetBSD hack to note version was called and thus mmap flags valid. */
+#define QUIRK_NETBSD_VERSION_CALLED (1ul<<31)
+#endif
+
 struct intel_fbdev;
 struct intel_fbc_work;
 

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c:1.51 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c:1.52
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c:1.51	Mon Aug 27 14:44:46 2018
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.c	Mon Aug 27 14:47:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem.c,v 1.51 2018/08/27 14:44:46 riastradh Exp $	*/
+/*	$NetBSD: i915_gem.c,v 1.52 2018/08/27 14:47:02 riastradh Exp $	*/
 
 /*
  * Copyright © 2008-2015 Intel Corporation
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_gem.c,v 1.51 2018/08/27 14:44:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem.c,v 1.52 2018/08/27 14:47:02 riastradh Exp $");
 
 #ifdef __NetBSD__
 #if 0				/* XXX uvmhist option?  */
@@ -1930,7 +1930,11 @@ i915_gem_mmap_ioctl(struct drm_device *d
 	struct drm_gem_object *obj;
 	unsigned long addr;
 #ifdef __NetBSD__
+	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
+
+	if ((dev_priv->quirks & QUIRK_NETBSD_VERSION_CALLED) == 0)
+		args->flags = 0;
 #endif
 
 	if (args->flags & ~(I915_MMAP_WC))

Reply via email to