Skip to contentSkip to conversation

drm/i915: Don't dereference fb when disabling primary plane

PATCH Superseded [email protected] 3 participants 7 messages Aug 27, 2014

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

PATCH 1/2 drm/i915: Don't dereference fb when disabling primary plane

From: Ville Syrjälä <[email protected]>

During driver init we may not have a valid framebuffer for the primary plane even though the plane is enabled due to failed BIOS fb takeover. This means we have to avoid dereferencing the fb in .update_primary_plane() when disabling the plane.

The introduction of the primary plane rotation in

commit d91a2cb8e5104233c02bbde539bd4ee455ec12ac
Author: Sonika Jindal <[email protected]>
Date: Fri Aug 22 14:06:04 2014 +0530

drm/i915: Add 180 degree primary plane rotation support

caused a regression by trying to look up the pixel format before we can be sure there's a valid fb available. This isn't entirely unsurprising since the rotation patches originally predate the change to the primary plane code that calls .update_primary_plane() also when disabling the plane:

commit fdd508a6419217cce28213f3c9bd27c02a0d4c71
Author: Ville Syrjälä <[email protected]>
Date: Fri Aug 8 21:51:11 2014 +0300

drm/i915: Call .update_primary_plane in intel_{enable, disable}_primary_hw_plane()

---
 drivers/gpu/drm/i915/intel_display.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +4 -4
index 16ac5ae..d5ba1f6 100644
@@ -2393,8 +2393,6 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 	u32 reg = DSPCNTR(plane);
 	int pixel_size;
 
-	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
-
 	if (!intel_crtc->primary_enabled) {
 		I915_WRITE(reg, 0);
 		if (INTEL_INFO(dev)->gen >= 4)
@@ -2405,6 +2403,8 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 		return;
 	}
 
+	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
+
 	dspcntr = DISPPLANE_GAMMA_ENABLE;
 
 	dspcntr |= DISPLAY_PLANE_ENABLE;
@@ -2515,8 +2515,6 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 	u32 reg = DSPCNTR(plane);
 	int pixel_size;
 
-	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
-
 	if (!intel_crtc->primary_enabled) {
 		I915_WRITE(reg, 0);
 		I915_WRITE(DSPSURF(plane), 0);
@@ -2524,6 +2522,8 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 		return;
 	}
 
+	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
+
 	dspcntr = DISPPLANE_GAMMA_ENABLE;
 
 	dspcntr |= DISPLAY_PLANE_ENABLE;
Signature · 6 lines
1.8.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/2 drm/i915: s, fb->bits_per_pixel/8, pixel_size, in primary plane code

From: Ville Syrjälä <[email protected]>

Use the pixel_size we got from drm_format_plane_cpp() instead of fb->bits_per_pixel/8 when computing the primary plane page/linear offsets. Avoids a few divs and makes the code more future proof against funky pixel formats where bits_per_pixel isn't well defined. This is what we already did in the sprite code.

---
 drivers/gpu/drm/i915/intel_display.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +4 -4
index d5ba1f6..9a80e28 100644
@@ -2460,12 +2460,12 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 	if (IS_G4X(dev))
 		dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
 
-	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
+	linear_offset = y * fb->pitches[0] + x * pixel_size;
 
 	if (INTEL_INFO(dev)->gen >= 4) {
 		intel_crtc->dspaddr_offset =
 			intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
-						       fb->bits_per_pixel / 8,
+						       pixel_size,
 						       fb->pitches[0]);
 		linear_offset -= intel_crtc->dspaddr_offset;
 	} else {
@@ -2564,10 +2564,10 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 	if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
 		dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
 
-	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
+	linear_offset = y * fb->pitches[0] + x * pixel_size;
 	intel_crtc->dspaddr_offset =
 		intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
-					       fb->bits_per_pixel / 8,
+					       pixel_size,
 					       fb->pitches[0]);
 	linear_offset -= intel_crtc->dspaddr_offset;
 	if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
Signature · 6 lines
1.8.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/i915: s, fb->bits_per_pixel/8, pixel_size, in primary plane code

Quoted 7 lines · On Wed, Aug 27, 2014 at 04:51:22PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Use the pixel_size we got from drm_format_plane_cpp() instead of fb->bits_per_pixel/8 when computing the primary plane page/linear offsets. Avoids a few divs and makes the code more future proof against funky pixel formats where bits_per_pixel isn't well defined. This is what we already did in the sprite code.

A little bit of software archeology revealed

commit ca320ac456099c29290568353d924157e626ede9

Author: Chris Wilson <[email protected]>
Date:   Wed Dec 19 12:14:22 2012 +0000

drm/i915: Use pixel size for computing linear offsets into a sprite

I misremembered that as an oops in the primary plane when using pixel_size. That concern addressed,

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/2] drm/i915: s, fb->bits_per_pixel/8, pixel_size, in primary plane code

Quoted 11 lines · Chris Wilson
Quoted 7 lines · On Wed, Aug 27, 2014 at 04:51:22PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Use the pixel_size we got from drm_format_plane_cpp() instead of fb->bits_per_pixel/8 when computing the primary plane page/linear offsets. Avoids a few divs and makes the code more future proof against funky pixel formats where bits_per_pixel isn't well defined. This is what we already did in the sprite code.

A little bit of software archeology revealed

Quoted 8 lines

commit ca320ac456099c29290568353d924157e626ede9

Author: Chris Wilson <[email protected]>
Date:   Wed Dec 19 12:14:22 2012 +0000

drm/i915: Use pixel size for computing linear offsets into a sprite

I misremembered that as an oops in the primary plane when using pixel_size. That concern addressed,

I've added this for additional context as a note to the commit message.

Quoted 1 line

Both patches merged, thanks.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw
In reply to [email protected]
Quoted 6 lines · On Wed, Aug 27, 2014 at 04:51:21PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

During driver init we may not have a valid framebuffer for the primary plane even though the plane is enabled due to failed BIOS fb takeover. This means we have to avoid dereferencing the fb in .update_primary_plane() when disabling the plane.

Ok, that's a bit non-obvious from the code.

Perhaps, something like

drivers/gpu/drm/i915/intel_display.c +7 -4
index fac2f6859cd2..a575454b6f45 100644
@@ -2388,15 +2388,13 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+       struct drm_i915_gem_object *obj;
        int plane = intel_crtc->plane;
        unsigned long linear_offset;
        u32 dspcntr;
        u32 reg = DSPCNTR(plane);
        int pixel_size;
 
-       pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
-
        if (!intel_crtc->primary_enabled) {
                I915_WRITE(reg, 0);
                if (INTEL_INFO(dev)->gen >= 4)
@@ -2407,8 +2405,13 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
                return;
        }
 
-       dspcntr = DISPPLANE_GAMMA_ENABLE;
+       obj = intel_fb_obj(fb);
+       if (WARN_ON(obj == NULL))
+               return;
+
+       pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
 
+       dspcntr = DISPPLANE_GAMMA_ENABLE;
        dspcntr |= DISPLAY_PLANE_ENABLE;
 
        if (INTEL_INFO(dev)->gen < 4) {

would help.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

PATCH v2 1/2 drm/i915: Don't dereference fb when disabling primary plane

From: Ville Syrjälä <[email protected]>

During driver init we may not have a valid framebuffer for the primary plane even though the plane is enabled due to failed BIOS fb takeover. This means we have to avoid dereferencing the fb in .update_primary_plane() when disabling the plane.

The introduction of the primary plane rotation in

commit d91a2cb8e5104233c02bbde539bd4ee455ec12ac
Author: Sonika Jindal <[email protected]>
Date: Fri Aug 22 14:06:04 2014 +0530

drm/i915: Add 180 degree primary plane rotation support

caused a regression by trying to look up the pixel format before we can be sure there's a valid fb available. This isn't entirely unsurprising since the rotation patches originally predate the change to the primary plane code that calls .update_primary_plane() also when disabling the plane:

commit fdd508a6419217cce28213f3c9bd27c02a0d4c71
Author: Ville Syrjälä <[email protected]>
Date: Fri Aug 8 21:51:11 2014 +0300

drm/i915: Call .update_primary_plane in intel_{enable, disable}_primary_hw_plane()

v2: Warn but don't blow up when trying to enable a plane w/o an fb (Chris)

---
 drivers/gpu/drm/i915/intel_display.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/intel_display.c +14 -6
index 16ac5ae..69bb088 100644
@@ -2386,15 +2386,13 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *obj;
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg = DSPCNTR(plane);
 	int pixel_size;
 
-	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
-
 	if (!intel_crtc->primary_enabled) {
 		I915_WRITE(reg, 0);
 		if (INTEL_INFO(dev)->gen >= 4)
@@ -2405,6 +2403,12 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 		return;
 	}
 
+	obj = intel_fb_obj(fb);
+	if (WARN_ON(obj == NULL))
+		return;
+
+	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
+
 	dspcntr = DISPPLANE_GAMMA_ENABLE;
 
 	dspcntr |= DISPLAY_PLANE_ENABLE;
@@ -2508,15 +2512,13 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *obj;
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg = DSPCNTR(plane);
 	int pixel_size;
 
-	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
-
 	if (!intel_crtc->primary_enabled) {
 		I915_WRITE(reg, 0);
 		I915_WRITE(DSPSURF(plane), 0);
@@ -2524,6 +2526,12 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 		return;
 	}
 
+	obj = intel_fb_obj(fb);
+	if (WARN_ON(obj == NULL))
+		return;
+
+	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
+
 	dspcntr = DISPPLANE_GAMMA_ENABLE;
 
 	dspcntr |= DISPLAY_PLANE_ENABLE;
Signature · 6 lines
1.8.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v2 1/2
#6 lore raw
Quoted 25 lines · On Wed, Aug 27, 2014 at 05:48:41PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

During driver init we may not have a valid framebuffer for the primary plane even though the plane is enabled due to failed BIOS fb takeover. This means we have to avoid dereferencing the fb in .update_primary_plane() when disabling the plane.

The introduction of the primary plane rotation in

commit d91a2cb8e5104233c02bbde539bd4ee455ec12ac
Author: Sonika Jindal <[email protected]>
Date: Fri Aug 22 14:06:04 2014 +0530

drm/i915: Add 180 degree primary plane rotation support

caused a regression by trying to look up the pixel format before we can be sure there's a valid fb available. This isn't entirely unsurprising since the rotation patches originally predate the change to the primary plane code that calls .update_primary_plane() also when disabling the plane:

commit fdd508a6419217cce28213f3c9bd27c02a0d4c71
Author: Ville Syrjälä <[email protected]>
Date: Fri Aug 8 21:51:11 2014 +0300

Quoted 7 lines

drm/i915: Call .update_primary_plane in intel_{enable, disable}_primary_hw_plane()

v2: Warn but don't blow up when trying to enable a plane w/o an fb (Chris)

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre