Re: i915 driver fails on i686 userspace + x86_64 kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 15 Oct 2013 21:59:08 +0100
Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> wrote:

> Yikes, that implies we have a size mismatch with the kernel - ideally
> we construct the struct to have the same size when compiled with 32
> or 64 bits.
> 
> Please try:
> 
> commit a63b4d5a0766a7e98efeff8dd520c58e9a1bea88
> Author: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
> Date:   Tue Oct 15 21:53:16 2013 +0100
> 
>     sna: Expand packed KMS structs for 64-bit alignment

It helps.  Xorg starts.

However, I feel uneasy about that patch.  I tried to debug the problem,
and it looked not as a data corruption, but as something opposite.  The
kernel writes correct data to the userspace, but the userspace gets the
old value.

My theory is that the compat code incorrectly restores some data on the
stack that should not be restored.  It would happen to the value that
is the closest to the stack pointer.  gcc orders variables on the stack
on its own, so additional arrays would only protect the enc structure
only if gcc would place them below enc.

The attached patch makes ioctl calls with enc and the 4 members of the
encoderid array.  encoderid[0] keeps the original value of 0x12345678.
Other calls return the right value.  The kernel can be changed to show
the pointer address and read back the value with get_user.  The value
and the pointer address are correct.

I tried Linux 3.8.12 and it made no difference.  I also recompiled the
kernel and xf86-video-intel with gcc 4.4.7 (the Ubuntu default is
4.6.3), and it also made no difference.

It's hard to believe that there is a bug in the stack saving code that
went unnoticed for so long, but I cannot think of anything else that
would explain the results I'm observing.

If the compiler gets the size of a certain structure wrong, why would
the compat call restore any data on stack on return?

I have an impression that your patch complicates things too much
without addressing the actual problem.

-- 
Regards,
Pavel Roskin
Protect array

From: Pavel Roskin <proski@xxxxxxx>


---
 src/sna/sna_display.c |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index 28151ab..27e429c 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -2588,7 +2588,8 @@ sna_output_init(ScrnInfoPtr scrn, struct sna_mode *mode, int num)
 	struct sna *sna = to_sna(scrn);
 	xf86OutputPtr output;
 	struct drm_mode_get_connector conn;
-	struct drm_mode_get_encoder enc;
+	int encoderid[4];
+	static struct drm_mode_get_encoder enc;
 	struct drm_mode_modeinfo dummy;
 	struct sna_output *sna_output;
 	const char *output_name;
@@ -2601,17 +2602,38 @@ sna_output_init(ScrnInfoPtr scrn, struct sna_mode *mode, int num)
 	VG_CLEAR(conn);
 	VG_CLEAR(enc);
 
+	DBG(("%s: &encoderid=%p\n", __FUNCTION__, &encoderid));
+	DBG(("%s: &enc.encoder_id=%p\n", __FUNCTION__, &enc.encoder_id));
+
 	conn.connector_id = mode->kmode->connectors[num];
 	conn.count_props = 0;
 	conn.count_modes = 1; /* skip detect */
 	conn.modes_ptr = (uintptr_t)&dummy;
 	conn.count_encoders = 1;
 	conn.encoders_ptr = (uintptr_t)&enc.encoder_id;
+	enc.encoder_id = 0x12345678;
 
 	if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) {
 		DBG(("%s: GETCONNECTOR failed, ret=%d\n", __FUNCTION__, errno));
 		return false;
 	}
+	DBG(("%s: enc.encoder_id=%#x\n", __FUNCTION__, enc.encoder_id));
+
+	for (i = 0; i < 4; i++) {
+		conn.connector_id = mode->kmode->connectors[num];
+		conn.count_props = 0;
+		conn.count_modes = 1; /* skip detect */
+		conn.modes_ptr = (uintptr_t)&dummy;
+		conn.count_encoders = 1;
+		conn.encoders_ptr = (uintptr_t)&encoderid[i];
+		encoderid[i] = 0x12345678;
+
+		if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) {
+			DBG(("%s: GETCONNECTOR failed, ret=%d\n", __FUNCTION__, errno));
+			return false;
+		}
+		DBG(("%s: encoderid[%d]=%#x\n", __FUNCTION__, i, encoderid[i]));
+	}
 
 	if (conn.count_encoders != 1) {
 		DBG(("%s: unexpected number [%d] of encoders attached\n",
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux