[Intel-xe] [PATCH 2/2] drm/i915: handle uncore spinlock when not available

Coelho, Luciano luciano.coelho at intel.com
Wed Oct 18 11:45:45 UTC 2023


On Thu, 2023-10-12 at 15:05 -0400, Rodrigo Vivi wrote:
> On Tue, Sep 19, 2023 at 12:47:37PM +0300, Luca Coelho wrote:
> > The uncore code may not always be available (e.g. when we build the
> > display code with Xe), so we can't always rely on having the uncore's
> > spinlock.
> > 
> > To handle this, split the spin_lock/unlock_irqsave/restore() into
> > spin_lock/unlock() followed by a call to local_irq_save/restore() and
> > create wrapper functions for locking and unlocking the uncore's
> > spinlock.  In these functions, we have a condition check and only
> > actually try to lock/unlock the spinlock when I915 is defined, and
> > thus uncore is available.
> > 
> > This keeps the ifdefs contained in these new functions and all such
> > logic inside the display code.
> > 
> > Signed-off-by: Luca Coelho <luciano.coelho at intel.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_display.h | 20 +++++++++++++
> >  drivers/gpu/drm/i915/display/intel_vblank.c  | 31 +++++++-------------
> >  2 files changed, 30 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
> > index 51eb65109d39..fdf9ff68a8a6 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.h
> > +++ b/drivers/gpu/drm/i915/display/intel_display.h
> > @@ -565,4 +565,24 @@ bool assert_port_valid(struct drm_i915_private *i915, enum port port);
> >  
> >  bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915);
> >  
> > +/*
> > + * The uncore version of the spin lock functions is used to decide
> > + * whether we need to lock the uncore lock or not.  This is only
> > + * needed in i915, not in Xe.  Keep the decision-making centralized
> > + * here.
> > + */
> > +static inline void uncore_spin_lock(spinlock_t *lock)
> > +{
> > +#ifdef I915
> > +	spin_lock(lock);
> > +#endif
> > +}
> > +
> > +static inline void uncore_spin_unlock(spinlock_t *lock)
> > +{
> > +#ifdef I915
> > +	spin_unlock(lock);
> > +#endif
> > +}
> > +
> >  #endif
> > diff --git a/drivers/gpu/drm/i915/display/intel_vblank.c b/drivers/gpu/drm/i915/display/intel_vblank.c
> > index 416aa6749eaf..97841fcf5b0f 100644
> > --- a/drivers/gpu/drm/i915/display/intel_vblank.c
> > +++ b/drivers/gpu/drm/i915/display/intel_vblank.c
> > @@ -292,11 +292,9 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
> >  	 * register reads, potentially with preemption disabled, so the
> >  	 * following code must not block on uncore.lock.
> >  	 */
> > -#ifdef I915
> > -	spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
> > -#else
> 
> A patch like this should be done first purely in i915, then ported to drm-xe-next
> with the proper clean-up.

Right, this makes sense.


> But at this point, I'm asking myself why does display code needs
> to take the uncore lock to start with? what kind of races or serialization
> are we trying to accomplish with this?
> 
> Trying to understand the big picture here so we can try to find the right
> solution. I mean, maybe the right solution is even add the spin_locks to
> xe_mmio and make both xe_mmio and intel_uncore to export helpers for the
> external locking mechanism?

The intention of this patch is not to change anything functionally, so
I think this should be addressed separately.


> Although to me it sounds like the pitfall of using locks to protect code
> and not data: https://blog.ffwll.ch/2022/07/locking-engineering.html

Thanks for the link! I'll check it out.

And thanks for the review.  I'll respin this so it's done in i915
first, so we can include that one in xe with the needed modifications.

--
Cheers,
Luca.


More information about the Intel-xe mailing list