diff mbox series

[v3,1/2] drm/i915/gem: Flush contexts on driver release

Message ID 20220916092403.201355-2-janusz.krzysztofik@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/gem: Really move i915_gem_context.link under ref protection | expand

Commit Message

Janusz Krzysztofik Sept. 16, 2022, 9:24 a.m. UTC
Due to i915_perf assuming that it can use the i915_gem_context reference
to protect its i915->gem.contexts.list iteration, we need to defer removal
of the context from the list until last reference to the context is put.
However, there is a risk of triggering kernel warning on contexts list not
empty at driver release time if we deleagate that task to a worker for
i915_gem_context_release_work(), unless that work is flushed first.
Unfortunately, it is not flushed on driver release.  Fix it.

Instead of additionally calling flush_workqueue(), either directly or via
a new dedicated wrapper around it, replace last call to
i915_gem_drain_freed_objects() with existing i915_gem_drain_workqueue()
that performs both tasks.

Fixes: 75eefd82581f ("drm/i915: Release i915_gem_context from a worker")
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Cc: stable@kernel.org # v5.16+
---
 drivers/gpu/drm/i915/i915_gem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Gwan-gyeong Mun Sept. 16, 2022, 12:03 p.m. UTC | #1
Reviewed-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>

On 9/16/22 12:24 PM, Janusz Krzysztofik wrote:
> Due to i915_perf assuming that it can use the i915_gem_context reference
> to protect its i915->gem.contexts.list iteration, we need to defer removal
> of the context from the list until last reference to the context is put.
> However, there is a risk of triggering kernel warning on contexts list not
> empty at driver release time if we deleagate that task to a worker for
> i915_gem_context_release_work(), unless that work is flushed first.
> Unfortunately, it is not flushed on driver release.  Fix it.
> 
> Instead of additionally calling flush_workqueue(), either directly or via
> a new dedicated wrapper around it, replace last call to
> i915_gem_drain_freed_objects() with existing i915_gem_drain_workqueue()
> that performs both tasks.
> 
> Fixes: 75eefd82581f ("drm/i915: Release i915_gem_context from a worker")
> Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: stable@kernel.org # v5.16+
> ---
>   drivers/gpu/drm/i915/i915_gem.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index c8e14ed9c2a96..172c29a15f118 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1195,7 +1195,8 @@ void i915_gem_driver_release(struct drm_i915_private *dev_priv)
>   
>   	intel_uc_cleanup_firmwares(&to_gt(dev_priv)->uc);
>   
> -	i915_gem_drain_freed_objects(dev_priv);
> +	/* Flush any outstanding work, including i915_gem_context.release_work. */
> +	i915_gem_drain_workqueue(dev_priv);
>   
>   	drm_WARN_ON(&dev_priv->drm, !list_empty(&dev_priv->gem.contexts.list));
>   }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index c8e14ed9c2a96..172c29a15f118 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1195,7 +1195,8 @@  void i915_gem_driver_release(struct drm_i915_private *dev_priv)
 
 	intel_uc_cleanup_firmwares(&to_gt(dev_priv)->uc);
 
-	i915_gem_drain_freed_objects(dev_priv);
+	/* Flush any outstanding work, including i915_gem_context.release_work. */
+	i915_gem_drain_workqueue(dev_priv);
 
 	drm_WARN_ON(&dev_priv->drm, !list_empty(&dev_priv->gem.contexts.list));
 }