Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Ville Syrjala <ville.syrjala@linux.intel.com>,
	intel-gfx@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 1/5] drm/i915/frontbuffer: Move bo refcounting intel_frontbuffer_{get, release}()
Date: Wed, 08 Oct 2025 17:14:13 +0300	[thread overview]
Message-ID: <79938f1fb87149221a274eae89aa1e755ac8ab00@intel.com> (raw)
In-Reply-To: <20251003145734.7634-2-ville.syrjala@linux.intel.com>

On Fri, 03 Oct 2025, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Currently xe's intel_frontbuffer implementation forgets to
> hold a reference on the bo. This makes the entire thing
> extremely fragile as the cleanup order now depends on bo
> references held by other things
> (namely intel_fb_bo_framebuffer_fini()).
>
> Move the bo refcounting to intel_frontbuffer_{get,release}()
> so that both i915 and xe do this the same way.
>
> I first tried to fix this by having xe do the refcounting
> from its intel_bo_set_frontbuffer() implementation
> (which is what i915 does currently), but turns out xe's
> drm_gem_object_free() can sleep and thus drm_gem_object_put()
> isn't safe to call while we hold fb_tracking.lock.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

I'm a bit uneasy about all of this code, but the change looks all right,

Reviewed-by: Jani Nikula <jani.nikula@intel.com>



> ---
>  drivers/gpu/drm/i915/display/intel_frontbuffer.c       | 10 +++++++++-
>  drivers/gpu/drm/i915/gem/i915_gem_object_frontbuffer.h |  2 --
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_frontbuffer.c b/drivers/gpu/drm/i915/display/intel_frontbuffer.c
> index 43be5377ddc1..73ed28ac9573 100644
> --- a/drivers/gpu/drm/i915/display/intel_frontbuffer.c
> +++ b/drivers/gpu/drm/i915/display/intel_frontbuffer.c
> @@ -270,6 +270,8 @@ static void frontbuffer_release(struct kref *ref)
>  	spin_unlock(&display->fb_tracking.lock);
>  
>  	i915_active_fini(&front->write);
> +
> +	drm_gem_object_put(obj);
>  	kfree_rcu(front, rcu);
>  }
>  
> @@ -287,6 +289,8 @@ intel_frontbuffer_get(struct drm_gem_object *obj)
>  	if (!front)
>  		return NULL;
>  
> +	drm_gem_object_get(obj);
> +
>  	front->obj = obj;
>  	kref_init(&front->ref);
>  	atomic_set(&front->bits, 0);
> @@ -299,8 +303,12 @@ intel_frontbuffer_get(struct drm_gem_object *obj)
>  	spin_lock(&display->fb_tracking.lock);
>  	cur = intel_bo_set_frontbuffer(obj, front);
>  	spin_unlock(&display->fb_tracking.lock);
> -	if (cur != front)
> +
> +	if (cur != front) {
> +		drm_gem_object_put(obj);
>  		kfree(front);
> +	}
> +
>  	return cur;
>  }
>  
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_frontbuffer.h b/drivers/gpu/drm/i915/gem/i915_gem_object_frontbuffer.h
> index b6dc3d1b9bb1..b682969e3a29 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object_frontbuffer.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_frontbuffer.h
> @@ -89,12 +89,10 @@ i915_gem_object_set_frontbuffer(struct drm_i915_gem_object *obj,
>  
>  	if (!front) {
>  		RCU_INIT_POINTER(obj->frontbuffer, NULL);
> -		drm_gem_object_put(intel_bo_to_drm_bo(obj));
>  	} else if (rcu_access_pointer(obj->frontbuffer)) {
>  		cur = rcu_dereference_protected(obj->frontbuffer, true);
>  		kref_get(&cur->ref);
>  	} else {
> -		drm_gem_object_get(intel_bo_to_drm_bo(obj));
>  		rcu_assign_pointer(obj->frontbuffer, front);
>  	}

-- 
Jani Nikula, Intel

  reply	other threads:[~2025-10-08 14:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-03 14:57 [PATCH v2 0/5] drm/i915: fb fixes and claenups Ville Syrjala
2025-10-03 14:57 ` [PATCH v2 1/5] drm/i915/frontbuffer: Move bo refcounting intel_frontbuffer_{get, release}() Ville Syrjala
2025-10-08 14:14   ` Jani Nikula [this message]
2025-10-03 14:57 ` [PATCH v2 2/5] drm/i915/fb: Fix the set_tiling vs. addfb race, again Ville Syrjala
2025-10-03 14:57 ` [PATCH v2 3/5] drm/i915/fbdev: Select linear modifier explicitly Ville Syrjala
2025-10-03 14:57 ` [PATCH v2 4/5] drm/i915/fb: Drop the 'fb' argument from intel_fb_bo_framebuffer_init() Ville Syrjala
2025-10-03 14:57 ` [PATCH v2 5/5] drm/i915/wm: Use fb->modfier to check for tiled vs. untiled Ville Syrjala
2025-10-03 15:29 ` ✓ CI.KUnit: success for drm/i915: fb fixes and claenups (rev3) Patchwork
2025-10-03 16:04 ` ✓ Xe.CI.BAT: " Patchwork
2025-10-03 18:01 ` ✓ Xe.CI.Full: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=79938f1fb87149221a274eae89aa1e755ac8ab00@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=ville.syrjala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox