diff mbox

[v4] drm/i915: Pin the ifbdev for the info->system_base GGTT mmapping

Message ID 1448036992-11749-1-git-send-email-chris@chris-wilson.co.uk
State New, archived
Headers show

Commit Message

Chris Wilson Nov. 20, 2015, 4:29 p.m. UTC
A long time ago (before 3.14) we relied on a permanent pinning of the
ifbdev to lock the fb in place inside the GGTT. However, the
introduction of stealing the BIOS framebuffer and reusing its address in
the GGTT for the fbdev has muddied waters and we use an inherited fb.
However, the inherited fb is only pinned whilst it is active and we no
longer have an explicit pin for the info->system_base mmapping used by
the fbdev. The result is that after some aperture pressure the fbdev may
be evicted, but we continue to write the fbcon into the same GGTT
address - overwriting anything else that may be put into that offset.
The effect is most pronounced across suspend/resume as
intel_fbdev_set_suspend() does a full clear over the whole scanout.

v2: Only unpin the intel_fb is we allocate it. If we inherit the fb from
the BIOS, we do not own the pinned vma (except for the reference we add
in this patch for our access via info->screen_base).

v3: Finish balancing the vma pinning for the normal !preallocated case.

v4: Try to simplify the pinning even further.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: "Goel, Akash" <akash.goel@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/i915/intel_fbdev.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Comments

Jesse Barnes Nov. 20, 2015, 4:35 p.m. UTC | #1
On 11/20/2015 08:29 AM, Chris Wilson wrote:
> A long time ago (before 3.14) we relied on a permanent pinning of the
> ifbdev to lock the fb in place inside the GGTT. However, the
> introduction of stealing the BIOS framebuffer and reusing its address in
> the GGTT for the fbdev has muddied waters and we use an inherited fb.
> However, the inherited fb is only pinned whilst it is active and we no
> longer have an explicit pin for the info->system_base mmapping used by
> the fbdev. The result is that after some aperture pressure the fbdev may
> be evicted, but we continue to write the fbcon into the same GGTT
> address - overwriting anything else that may be put into that offset.
> The effect is most pronounced across suspend/resume as
> intel_fbdev_set_suspend() does a full clear over the whole scanout.
> 
> v2: Only unpin the intel_fb is we allocate it. If we inherit the fb from
> the BIOS, we do not own the pinned vma (except for the reference we add
> in this patch for our access via info->screen_base).
> 
> v3: Finish balancing the vma pinning for the normal !preallocated case.
> 
> v4: Try to simplify the pinning even further.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: "Goel, Akash" <akash.goel@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/i915/intel_fbdev.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
> index 7ccde58f8c98..79f02e72da8a 100644
> --- a/drivers/gpu/drm/i915/intel_fbdev.c
> +++ b/drivers/gpu/drm/i915/intel_fbdev.c
> @@ -163,13 +163,6 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
>  		goto out;
>  	}
>  
> -	/* Flush everything out, we'll be doing GTT only from now on */
> -	ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL);
> -	if (ret) {
> -		DRM_ERROR("failed to pin obj: %d\n", ret);
> -		goto out;
> -	}
> -
>  	mutex_unlock(&dev->struct_mutex);
>  
>  	ifbdev->fb = to_intel_framebuffer(fb);
> @@ -225,6 +218,14 @@ static int intelfb_create(struct drm_fb_helper *helper,
>  
>  	mutex_lock(&dev->struct_mutex);
>  
> +	/* Pin the GGTT vma for our access via info->screen_base.
> +	 * This also validates that any existing fb inherited from the
> +	 * BIOS is suitable for own access.
> +	 */
> +	ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
> +	if (ret)
> +		goto out_unlock;
> +
>  	info = drm_fb_helper_alloc_fbi(helper);
>  	if (IS_ERR(info)) {
>  		DRM_ERROR("Failed to allocate fb_info\n");
> @@ -287,6 +288,7 @@ out_destroy_fbi:
>  	drm_fb_helper_release_fbi(helper);
>  out_unpin:
>  	i915_gem_object_ggtt_unpin(obj);
> +out_unlock:
>  	mutex_unlock(&dev->struct_mutex);
>  	return ret;
>  }
> @@ -524,6 +526,8 @@ static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
>  static void intel_fbdev_destroy(struct drm_device *dev,
>  				struct intel_fbdev *ifbdev)
>  {
> +	/* Release the pinning for the info->screen_base mmaping. */
> +	i915_gem_object_ggtt_unpin(ifbdev->fb->obj);
>  
>  	drm_fb_helper_unregister_fbi(&ifbdev->helper);
>  	drm_fb_helper_release_fbi(&ifbdev->helper);
> 

Ah even better.

Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>
kernel test robot Nov. 20, 2015, 4:46 p.m. UTC | #2
Hi Chris,

[auto build test ERROR on drm-intel/for-linux-next]
[cannot apply to v4.4-rc1 next-20151120]

url:    https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-i915-Pin-the-ifbdev-for-the-info-system_base-GGTT-mmapping/20151121-003300
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-x011-11191819 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/gpu/drm/i915/intel_fbdev.c: In function 'intelfb_create':
>> drivers/gpu/drm/i915/intel_fbdev.c:225:41: error: incompatible type for argument 2 of 'intel_pin_and_fence_fb_obj'
     ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
                                            ^
   In file included from drivers/gpu/drm/i915/intel_fbdev.c:44:0:
   drivers/gpu/drm/i915/intel_drv.h:1098:5: note: expected 'struct drm_framebuffer *' but argument is of type 'struct drm_framebuffer'
    int intel_pin_and_fence_fb_obj(struct drm_plane *plane,
        ^

vim +/intel_pin_and_fence_fb_obj +225 drivers/gpu/drm/i915/intel_fbdev.c

   219		mutex_lock(&dev->struct_mutex);
   220	
   221		/* Pin the GGTT vma for our access via info->screen_base.
   222		 * This also validates that any existing fb inherited from the
   223		 * BIOS is suitable for own access.
   224		 */
 > 225		ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
   226		if (ret)
   227			goto out_unlock;
   228	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Nov. 20, 2015, 6:01 p.m. UTC | #3
Hi Chris,

[auto build test WARNING on drm-intel/for-linux-next]
[cannot apply to v4.4-rc1 next-20151120]

url:    https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-i915-Pin-the-ifbdev-for-the-info-system_base-GGTT-mmapping/20151121-003300
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/i915/intel_fbdev.c:225:58: sparse: incorrect type in argument 2 (different base types)
   drivers/gpu/drm/i915/intel_fbdev.c:225:58:    expected struct drm_framebuffer *fb
   drivers/gpu/drm/i915/intel_fbdev.c:225:58:    got struct drm_framebuffer base
   drivers/gpu/drm/i915/intel_fbdev.c: In function 'intelfb_create':
   drivers/gpu/drm/i915/intel_fbdev.c:225:41: error: incompatible type for argument 2 of 'intel_pin_and_fence_fb_obj'
     ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
                                            ^
   In file included from drivers/gpu/drm/i915/intel_fbdev.c:44:0:
   drivers/gpu/drm/i915/intel_drv.h:1098:5: note: expected 'struct drm_framebuffer *' but argument is of type 'struct drm_framebuffer'
    int intel_pin_and_fence_fb_obj(struct drm_plane *plane,
        ^

vim +225 drivers/gpu/drm/i915/intel_fbdev.c

   209		} else {
   210			DRM_DEBUG_KMS("re-using BIOS fb\n");
   211			prealloc = true;
   212			sizes->fb_width = intel_fb->base.width;
   213			sizes->fb_height = intel_fb->base.height;
   214		}
   215	
   216		obj = intel_fb->obj;
   217		size = obj->base.size;
   218	
   219		mutex_lock(&dev->struct_mutex);
   220	
   221		/* Pin the GGTT vma for our access via info->screen_base.
   222		 * This also validates that any existing fb inherited from the
   223		 * BIOS is suitable for own access.
   224		 */
 > 225		ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
   226		if (ret)
   227			goto out_unlock;
   228	
   229		info = drm_fb_helper_alloc_fbi(helper);
   230		if (IS_ERR(info)) {
   231			DRM_ERROR("Failed to allocate fb_info\n");
   232			ret = PTR_ERR(info);
   233			goto out_unpin;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Daniel Vetter Nov. 24, 2015, 4:46 p.m. UTC | #4
On Sat, Nov 21, 2015 at 02:01:55AM +0800, kbuild test robot wrote:
> Hi Chris,
> 
> [auto build test WARNING on drm-intel/for-linux-next]
> [cannot apply to v4.4-rc1 next-20151120]
> 
> url:    https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-i915-Pin-the-ifbdev-for-the-info-system_base-GGTT-mmapping/20151121-003300
> base:   git://anongit.freedesktop.org/drm-intel for-linux-next
> reproduce:
>         # apt-get install sparse
>         make ARCH=x86_64 allmodconfig
>         make C=1 CF=-D__CHECK_ENDIAN__
> 
> 
> sparse warnings: (new ones prefixed by >>)
> 
> >> drivers/gpu/drm/i915/intel_fbdev.c:225:58: sparse: incorrect type in argument 2 (different base types)
>    drivers/gpu/drm/i915/intel_fbdev.c:225:58:    expected struct drm_framebuffer *fb
>    drivers/gpu/drm/i915/intel_fbdev.c:225:58:    got struct drm_framebuffer base
>    drivers/gpu/drm/i915/intel_fbdev.c: In function 'intelfb_create':
>    drivers/gpu/drm/i915/intel_fbdev.c:225:41: error: incompatible type for argument 2 of 'intel_pin_and_fence_fb_obj'
>      ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
>                                             ^
>    In file included from drivers/gpu/drm/i915/intel_fbdev.c:44:0:
>    drivers/gpu/drm/i915/intel_drv.h:1098:5: note: expected 'struct drm_framebuffer *' but argument is of type 'struct drm_framebuffer'
>     int intel_pin_and_fence_fb_obj(struct drm_plane *plane,

With the missing & ack for -fixes on both patches from my side.
-Daniel

>         ^
> 
> vim +225 drivers/gpu/drm/i915/intel_fbdev.c
> 
>    209		} else {
>    210			DRM_DEBUG_KMS("re-using BIOS fb\n");
>    211			prealloc = true;
>    212			sizes->fb_width = intel_fb->base.width;
>    213			sizes->fb_height = intel_fb->base.height;
>    214		}
>    215	
>    216		obj = intel_fb->obj;
>    217		size = obj->base.size;
>    218	
>    219		mutex_lock(&dev->struct_mutex);
>    220	
>    221		/* Pin the GGTT vma for our access via info->screen_base.
>    222		 * This also validates that any existing fb inherited from the
>    223		 * BIOS is suitable for own access.
>    224		 */
>  > 225		ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
>    226		if (ret)
>    227			goto out_unlock;
>    228	
>    229		info = drm_fb_helper_alloc_fbi(helper);
>    230		if (IS_ERR(info)) {
>    231			DRM_ERROR("Failed to allocate fb_info\n");
>    232			ret = PTR_ERR(info);
>    233			goto out_unpin;
> 
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Lukas Wunner Nov. 24, 2015, 9:20 p.m. UTC | #5
Hi Chris,

On Fri, Nov 20, 2015 at 04:29:52PM +0000, Chris Wilson wrote:
> A long time ago (before 3.14) we relied on a permanent pinning of the
> ifbdev to lock the fb in place inside the GGTT. However, the
> introduction of stealing the BIOS framebuffer and reusing its address in
> the GGTT for the fbdev has muddied waters and we use an inherited fb.
> However, the inherited fb is only pinned whilst it is active and we no
> longer have an explicit pin for the info->system_base mmapping used by
> the fbdev. The result is that after some aperture pressure the fbdev may
> be evicted, but we continue to write the fbcon into the same GGTT
> address - overwriting anything else that may be put into that offset.
> The effect is most pronounced across suspend/resume as
> intel_fbdev_set_suspend() does a full clear over the whole scanout.
> 
> v2: Only unpin the intel_fb is we allocate it. If we inherit the fb from
> the BIOS, we do not own the pinned vma (except for the reference we add
> in this patch for our access via info->screen_base).
> 
> v3: Finish balancing the vma pinning for the normal !preallocated case.
> 
> v4: Try to simplify the pinning even further.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: "Goel, Akash" <akash.goel@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/i915/intel_fbdev.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
> index 7ccde58f8c98..79f02e72da8a 100644
> --- a/drivers/gpu/drm/i915/intel_fbdev.c
> +++ b/drivers/gpu/drm/i915/intel_fbdev.c
> @@ -163,13 +163,6 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
>  		goto out;
>  	}
>  
> -	/* Flush everything out, we'll be doing GTT only from now on */
> -	ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL);
> -	if (ret) {
> -		DRM_ERROR("failed to pin obj: %d\n", ret);
> -		goto out;
> -	}
> -
>  	mutex_unlock(&dev->struct_mutex);
>  
>  	ifbdev->fb = to_intel_framebuffer(fb);
> @@ -225,6 +218,14 @@ static int intelfb_create(struct drm_fb_helper *helper,
>  
>  	mutex_lock(&dev->struct_mutex);
>  
> +	/* Pin the GGTT vma for our access via info->screen_base.
> +	 * This also validates that any existing fb inherited from the
> +	 * BIOS is suitable for own access.
> +	 */
> +	ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
> +	if (ret)
> +		goto out_unlock;
> +
>  	info = drm_fb_helper_alloc_fbi(helper);
>  	if (IS_ERR(info)) {
>  		DRM_ERROR("Failed to allocate fb_info\n");
> @@ -287,6 +288,7 @@ out_destroy_fbi:
>  	drm_fb_helper_release_fbi(helper);
>  out_unpin:
>  	i915_gem_object_ggtt_unpin(obj);
> +out_unlock:
>  	mutex_unlock(&dev->struct_mutex);
>  	return ret;
>  }
> @@ -524,6 +526,8 @@ static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
>  static void intel_fbdev_destroy(struct drm_device *dev,
>  				struct intel_fbdev *ifbdev)
>  {
> +	/* Release the pinning for the info->screen_base mmaping. */
> +	i915_gem_object_ggtt_unpin(ifbdev->fb->obj);

If the call to intelfb_alloc() failed, ifbdev->fb will be NULL and
intelfb_create() will return a non-zero value. Further up in the call
stack, intel_fbdev_initial_config() will then clobber the fbdev by
calling intel_fbdev_destroy(). This will oops because you dereference
ifbdev->fb here. So you need to add:
	if (ifbdev->fb)

If intel_pin_and_fence_fb_obj() failed, intelfb_create() will likewise
return a non-zero value and the fbdev gets clobbered. This will WARN
because you're calling i915_gem_object_ggtt_unpin() even though the
pin_count is 0.

Best regards,

Lukas

>  
>  	drm_fb_helper_unregister_fbi(&ifbdev->helper);
>  	drm_fb_helper_release_fbi(&ifbdev->helper);
> -- 
> 2.6.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Jani Nikula Dec. 1, 2015, 9:01 a.m. UTC | #6
On Tue, 24 Nov 2015, Daniel Vetter <daniel@ffwll.ch> wrote:
> On Sat, Nov 21, 2015 at 02:01:55AM +0800, kbuild test robot wrote:
>> Hi Chris,
>> 
>> [auto build test WARNING on drm-intel/for-linux-next]
>> [cannot apply to v4.4-rc1 next-20151120]
>> 
>> url:    https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-i915-Pin-the-ifbdev-for-the-info-system_base-GGTT-mmapping/20151121-003300
>> base:   git://anongit.freedesktop.org/drm-intel for-linux-next
>> reproduce:
>>         # apt-get install sparse
>>         make ARCH=x86_64 allmodconfig
>>         make C=1 CF=-D__CHECK_ENDIAN__
>> 
>> 
>> sparse warnings: (new ones prefixed by >>)
>> 
>> >> drivers/gpu/drm/i915/intel_fbdev.c:225:58: sparse: incorrect type in argument 2 (different base types)
>>    drivers/gpu/drm/i915/intel_fbdev.c:225:58:    expected struct drm_framebuffer *fb
>>    drivers/gpu/drm/i915/intel_fbdev.c:225:58:    got struct drm_framebuffer base
>>    drivers/gpu/drm/i915/intel_fbdev.c: In function 'intelfb_create':
>>    drivers/gpu/drm/i915/intel_fbdev.c:225:41: error: incompatible type for argument 2 of 'intel_pin_and_fence_fb_obj'
>>      ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
>>                                             ^
>>    In file included from drivers/gpu/drm/i915/intel_fbdev.c:44:0:
>>    drivers/gpu/drm/i915/intel_drv.h:1098:5: note: expected 'struct drm_framebuffer *' but argument is of type 'struct drm_framebuffer'
>>     int intel_pin_and_fence_fb_obj(struct drm_plane *plane,
>
> With the missing & ack for -fixes on both patches from my side.

Somehow the fact that this didn't even compile to begin with makes me
less than enthusiastic about queuing this to -fixes, let alone -stable.

BR,
Jani.



> -Daniel
>
>>         ^
>> 
>> vim +225 drivers/gpu/drm/i915/intel_fbdev.c
>> 
>>    209		} else {
>>    210			DRM_DEBUG_KMS("re-using BIOS fb\n");
>>    211			prealloc = true;
>>    212			sizes->fb_width = intel_fb->base.width;
>>    213			sizes->fb_height = intel_fb->base.height;
>>    214		}
>>    215	
>>    216		obj = intel_fb->obj;
>>    217		size = obj->base.size;
>>    218	
>>    219		mutex_lock(&dev->struct_mutex);
>>    220	
>>    221		/* Pin the GGTT vma for our access via info->screen_base.
>>    222		 * This also validates that any existing fb inherited from the
>>    223		 * BIOS is suitable for own access.
>>    224		 */
>>  > 225		ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
>>    226		if (ret)
>>    227			goto out_unlock;
>>    228	
>>    229		info = drm_fb_helper_alloc_fbi(helper);
>>    230		if (IS_ERR(info)) {
>>    231			DRM_ERROR("Failed to allocate fb_info\n");
>>    232			ret = PTR_ERR(info);
>>    233			goto out_unpin;
>> 
>> ---
>> 0-DAY kernel test infrastructure                Open Source Technology Center
>> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
index 7ccde58f8c98..79f02e72da8a 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -163,13 +163,6 @@  static int intelfb_alloc(struct drm_fb_helper *helper,
 		goto out;
 	}
 
-	/* Flush everything out, we'll be doing GTT only from now on */
-	ret = intel_pin_and_fence_fb_obj(NULL, fb, NULL);
-	if (ret) {
-		DRM_ERROR("failed to pin obj: %d\n", ret);
-		goto out;
-	}
-
 	mutex_unlock(&dev->struct_mutex);
 
 	ifbdev->fb = to_intel_framebuffer(fb);
@@ -225,6 +218,14 @@  static int intelfb_create(struct drm_fb_helper *helper,
 
 	mutex_lock(&dev->struct_mutex);
 
+	/* Pin the GGTT vma for our access via info->screen_base.
+	 * This also validates that any existing fb inherited from the
+	 * BIOS is suitable for own access.
+	 */
+	ret = intel_pin_and_fence_fb_obj(NULL, ifbdev->fb->base, NULL);
+	if (ret)
+		goto out_unlock;
+
 	info = drm_fb_helper_alloc_fbi(helper);
 	if (IS_ERR(info)) {
 		DRM_ERROR("Failed to allocate fb_info\n");
@@ -287,6 +288,7 @@  out_destroy_fbi:
 	drm_fb_helper_release_fbi(helper);
 out_unpin:
 	i915_gem_object_ggtt_unpin(obj);
+out_unlock:
 	mutex_unlock(&dev->struct_mutex);
 	return ret;
 }
@@ -524,6 +526,8 @@  static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
 static void intel_fbdev_destroy(struct drm_device *dev,
 				struct intel_fbdev *ifbdev)
 {
+	/* Release the pinning for the info->screen_base mmaping. */
+	i915_gem_object_ggtt_unpin(ifbdev->fb->obj);
 
 	drm_fb_helper_unregister_fbi(&ifbdev->helper);
 	drm_fb_helper_release_fbi(&ifbdev->helper);