drm/i915: Backport vma fixes for 4.10-rc6
Subsystems (3)
Maarten Lankhorst
maintainercover drm/i915: Backport vma fixes for 4.10-rc6
With atomic plane states we are able to track an allocation right from preparation, during use and through to the final free after being swapped out for a new plane. We can couple the VMA we pin for the framebuffer (and its rotation) to this lifetime and avoid all the clumsy lookups in between.
This is marked for rc6 because it seems the issue is triggerable on mainline and resulting in an oops.
The backport also requires a preparation patch, which is required because otherwise the vma is not always populated and then we dereference a null pointer.
References: https://bugs.freedesktop.org/show_bug.cgi?id=98829
Chris Wilson (1):
drm/i915: Track pinned vma in intel_plane_state
Maarten Lankhorst (1):
drm/atomic: Unconditionally call prepare_fb.
drivers/gpu/drm/drm_atomic_helper.c | 9 --- drivers/gpu/drm/i915/i915_drv.h | 16 +--- drivers/gpu/drm/i915/intel_atomic_plane.c | 20 +++++ drivers/gpu/drm/i915/intel_display.c | 125 ++++++++++-------------------- drivers/gpu/drm/i915/intel_drv.h | 9 ++- drivers/gpu/drm/i915/intel_fbc.c | 52 +++++-------- drivers/gpu/drm/i915/intel_fbdev.c | 4 +- drivers/gpu/drm/i915/intel_sprite.c | 8 +- 8 files changed, 99 insertions(+), 144 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Maarten Lankhorst
maintainerPATCH 1/2 drm/atomic: Unconditionally call prepare_fb.
Atomic drivers may set properties like rotation on the same fb, which may require a call to prepare_fb even when framebuffer stays identical.
Instead of handling all the special cases in the core, let the driver decide when prepare_fb and cleanup_fb are noops.
This is a revert of:
commit fcc60b413d14dd06ddbd79ec50e83c4fb2a097ba
Author: Keith Packard <[email protected]> Date: Sat Jun 4 01:16:22 2016 -0700
drm: Don't prepare or cleanup unchanging frame buffers [v3]
The original commit mentions that this prevents waiting in i915 on all previous rendering during cursor updates, but there are better ways to fix this.
--- drivers/gpu/drm/drm_atomic_helper.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +0 -9
@@ -1666,9 +1666,6 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev, funcs = plane->helper_private; -if (!drm_atomic_helper_framebuffer_changed (dev, state, plane_state->crtc)) -continue ; -if (funcs->prepare_fb) { ret = funcs->prepare_fb (plane, plane_state);if (ret)
@@ -1685,9 +1682,6 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev,if (j >= i)continue ; -if (!drm_atomic_helper_framebuffer_changed (dev, state, plane_state->crtc)) -continue ; - funcs = plane->helper_private;if (funcs->cleanup_fb)
@@ -1954,9 +1948,6 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,for_each_plane_in_state (old_state, plane, plane_state, i) {const struct drm_plane_helper_funcs *funcs; -if (!drm_atomic_helper_framebuffer_changed (dev, old_state, plane_state->crtc)) -continue ; - funcs = plane->helper_private;if (funcs->cleanup_fb)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH 2/2 drm/i915: Track pinned vma in intel_plane_state
In reply to Maarten LankhorstFrom: Chris Wilson <[email protected]>
With atomic plane states we are able to track an allocation right from preparation, during use and through to the final free after being swapped out for a new plane. We can couple the VMA we pin for the framebuffer (and its rotation) to this lifetime and avoid all the clumsy lookups in between.
v2: Remove residual vma on plane cleanup (Chris)
v3: Add a description for the vma destruction in
intel_plane_destroy_state (Maarten)
References: https://bugs.freedesktop.org/show_bug.cgi?id=98829
--- drivers/gpu/drm/i915/i915_drv.h | 16 +--- drivers/gpu/drm/i915/intel_atomic_plane.c | 20 +++++ drivers/gpu/drm/i915/intel_display.c | 125 ++++++++++-------------------- drivers/gpu/drm/i915/intel_drv.h | 9 ++- drivers/gpu/drm/i915/intel_fbc.c | 52 +++++-------- drivers/gpu/drm/i915/intel_fbdev.c | 4 +- drivers/gpu/drm/i915/intel_sprite.c | 8 +- 7 files changed, 99 insertions(+), 135 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -12
@@ -1012,6 +1012,8 @@ struct intel_fbc {struct work_struct underrun_work;struct intel_fbc_state_cache { +struct i915_vma *vma; +struct {unsigned int mode_flags;uint32_t hsw_bdw_pixel_rate;
@@ -1025,15 +1027,14 @@ struct intel_fbc { } plane;struct { -u64 ilk_ggtt_offset;uint32_t pixel_format;unsigned int stride; -int fence_reg; -unsigned int tiling_mode; } fb; } state_cache;struct intel_fbc_reg_params { +struct i915_vma *vma; +struct {enum pipe pipe;enum plane plane;
@@ -1041,10 +1042,8 @@ struct intel_fbc { } crtc;struct { -u64 ggtt_offset;uint32_t pixel_format;unsigned int stride; -int fence_reg; } fb;int cfb_size;
@@ -3168,13 +3167,6 @@ i915_gem_object_to_ggtt(struct drm_i915_gem_object *obj,return i915_gem_obj_to_vma (obj, &to_i915 (obj->base.dev)->ggtt.base, view); } -static inline unsigned long -i915_gem_object_ggtt_offset (struct drm_i915_gem_object *o, -const struct i915_ggtt_view *view) -{ -return i915_ggtt_offset (i915_gem_object_to_ggtt (o, view)); -} -/* i915_gem_fence_reg.c */ int __must_check i915_vma_get_fence (struct i915_vma *vma);int __must_check i915_vma_put_fence (struct i915_vma *vma);
drivers/gpu/drm/i915/intel_atomic_plane.c +20 -0
@@ -85,6 +85,8 @@ intel_plane_duplicate_state(struct drm_plane *plane)__drm_atomic_helper_plane_duplicate_state (plane, state); + intel_state->vma =NULL ; +return state; }
@@ -100,6 +102,24 @@ void intel_plane_destroy_state(struct drm_plane *plane, struct drm_plane_state *state) { + struct i915_vma *vma; + + vma =fetch_and_zero (&to_intel_plane_state (state)->vma); + +/* +* FIXME: Normally intel_cleanup_plane_fb handles destruction of vma. +* We currently don't clear all planes during driver unload, so we have +* to be able to unpin vma here for now. +* +* Normally this can only happen during unload when kmscon is disabled +* and userspace doesn't attempt to set a framebuffer at all. +*/ +if (vma) { +mutex_lock (&plane->dev->struct_mutex); +intel_unpin_fb_vma (vma); +mutex_unlock (&plane->dev->struct_mutex); + } +drm_atomic_helper_plane_destroy_state (plane, state); }
drivers/gpu/drm/i915/intel_display.c +42 -83
247 lines not on this page · raw message
drivers/gpu/drm/i915/intel_drv.h +7 -2
@@ -377,6 +377,7 @@ struct intel_atomic_state {struct intel_plane_state {struct drm_plane_state base;struct drm_rect clip; +struct i915_vma *vma;struct {u32 offset;
@@ -1046,6 +1047,7 @@ struct intel_flip_work {struct work_struct mmio_work;struct drm_crtc *crtc; +struct i915_vma *old_vma;struct drm_framebuffer *old_fb;struct drm_i915_gem_object *pending_flip_obj;struct drm_pending_vblank_event *event;
@@ -1273,7 +1275,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx);struct i915_vma *intel_pin_and_fence_fb_obj (struct drm_framebuffer *fb,unsigned int rotation); -void intel_unpin_fb_obj (struct drm_framebuffer *fb,unsigned int rotation); +void intel_unpin_fb_vma (struct i915_vma *vma);struct drm_framebuffer * __intel_framebuffer_create(struct drm_device *dev, struct drm_mode_fb_cmd2 *mode_cmd,
@@ -1362,7 +1364,10 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode,int skl_update_scaler_crtc (struct intel_crtc_state *crtc_state);int skl_max_scale (struct intel_crtc *crtc,struct intel_crtc_state *crtc_state); -u32 intel_fb_gtt_offset (struct drm_framebuffer *fb,unsigned int rotation); +static inline u32 intel_plane_ggtt_offset (const struct intel_plane_state *state) +{ +return i915_ggtt_offset (state->vma); +}u32 skl_plane_ctl_format (uint32_t pixel_format);u32 skl_plane_ctl_tiling (uint64_t fb_modifier);
drivers/gpu/drm/i915/intel_fbc.c +20 -32
134 lines not on this page · raw message
drivers/gpu/drm/i915/intel_fbdev.c +2 -2
@@ -284,7 +284,7 @@ static int intelfb_create(struct drm_fb_helper *helper, out_destroy_fbi:drm_fb_helper_release_fbi (helper); out_unpin: -intel_unpin_fb_obj (&ifbdev->fb->base,DRM_ROTATE_0 ); +intel_unpin_fb_vma (vma); out_unlock:mutex_unlock (&dev->struct_mutex);return ret;
@@ -549,7 +549,7 @@ static void intel_fbdev_destroy(struct intel_fbdev *ifbdev)if (ifbdev->fb) {mutex_lock (&ifbdev->helper.dev->struct_mutex); -intel_unpin_fb_obj (&ifbdev->fb->base,DRM_ROTATE_0 ); +intel_unpin_fb_vma (ifbdev->vma);mutex_unlock (&ifbdev->helper.dev->struct_mutex);drm_framebuffer_remove (&ifbdev->fb->base);
drivers/gpu/drm/i915/intel_sprite.c +4 -4
@@ -273,7 +273,7 @@ skl_update_plane(struct drm_plane *drm_plane,I915_WRITE (PLANE_CTL (pipe, plane), plane_ctl);I915_WRITE (PLANE_SURF (pipe, plane), -intel_fb_gtt_offset (fb, rotation) + surf_addr); +intel_plane_ggtt_offset (plane_state) + surf_addr);POSTING_READ (PLANE_SURF (pipe, plane)); }
@@ -458,7 +458,7 @@ vlv_update_plane(struct drm_plane *dplane,I915_WRITE (SPSIZE (pipe, plane), (crtc_h <<16 ) | crtc_w);I915_WRITE (SPCNTR (pipe, plane), sprctl);I915_WRITE (SPSURF (pipe, plane), -intel_fb_gtt_offset (fb, rotation) + sprsurf_offset); +intel_plane_ggtt_offset (plane_state) + sprsurf_offset);POSTING_READ (SPSURF (pipe, plane)); }
@@ -594,7 +594,7 @@ ivb_update_plane(struct drm_plane *plane,I915_WRITE (SPRSCALE (pipe), sprscale);I915_WRITE (SPRCTL (pipe), sprctl);I915_WRITE (SPRSURF (pipe), -intel_fb_gtt_offset (fb, rotation) + sprsurf_offset); +intel_plane_ggtt_offset (plane_state) + sprsurf_offset);POSTING_READ (SPRSURF (pipe)); }
@@ -721,7 +721,7 @@ ilk_update_plane(struct drm_plane *plane,I915_WRITE (DVSSCALE (pipe), dvsscale);I915_WRITE (DVSCNTR (pipe), dvscntr);I915_WRITE (DVSSURF (pipe), -intel_fb_gtt_offset (fb, rotation) + dvssurf_offset); +intel_plane_ggtt_offset (plane_state) + dvssurf_offset);POSTING_READ (DVSSURF (pipe)); }
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 3 lines · Maarten Lankhorst
This is marked for rc6 because it seems the issue is triggerable on mainline and resulting in an oops.
So I did apply my obvious "avoid the oops and just warn about it"
patch: commit 39cb2c9a316e ("drm/i915: Check for NULL i915_vma in intel_unpin_fb_obj()").
I haven't actually triggered the problem since, so I don't know if there might be some other downstream issue, but the workaround *may* just be acceptable from a 4.10 standpoint.
Some maintainer who knows the code better should make the judgment call.
Linus
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Maarten Lankhorst
This is marked for rc6 because it seems the issue is triggerable on mainline and resulting in an oops.
Quoted 7 lines
So I did apply my obvious "avoid the oops and just warn about it"
patch: commit39cb2c9a316e("drm/i915: Check for NULLi915_vmainintel_unpin_fb_obj()").I haven't actually triggered the problem since, so I don't know if there might be some other downstream issue, but the workaround *may* just be acceptable from a 4.10 standpoint.
You need sufficient memory pressure to start using partial views, and then kill the X server while it's using that partial view still (i.e. not too much memory pressure to prevent them from getting evicted). And it's global gttt pressure, so not much do to with what's going on on your machine. So hard to hit, but when you do the book-keeping is rather completely wreaked since we throw away the views while they're still in use.
Quoted 1 line
Some maintainer who knows the code better should make the judgment call.
It's a lot less scary than what I thought:
- the cherry picks needed are a lot less than what I feared, a lot of the prep work landed in 4.10 and a bunch of it in patches in linux-next aren't needed for 4.10 due to other reasons.
- we have a testcase to repro this instantly. It uses rotation instead of partial views (which depend upon allocation order to hit the bug, rotation is deterministic), but the same code blows up for the same reasons because it's a bug in the view code, not with a specific view.
The only thing that's mildly scary is that we need a drm core patch to make it happen. But that one has been for a while in linux-next too, so should be acceptable. Only thing left to do is let CI beat on this specifically for a bit, so pull request should be ready for -rc7 I hope. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx