From: "Souza, Jose" Subject: Re: [PATCH v2 3/6] drm/i915/psr: Make intel_psr_set_debugfs_mode() only handle PSR mode Date: Fri, 4 Jan 2019 15:52:13 +0000 Message-ID: References: <20190103142107.18304-1-jose.souza@intel.com> <20190103142107.18304-3-jose.souza@intel.com> <3702a2a4-06c5-f963-6882-37fe1a915411@linux.intel.com> <5735b5d6023030708546f909c37703ed1666ae7f.camel@intel.com> <030cad5d-991a-2ff7-fa86-a56af092e6b2@linux.intel.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0386971861==" Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 28D9C6EC9A for ; Fri, 4 Jan 2019 15:52:16 +0000 (UTC) In-Reply-To: <030cad5d-991a-2ff7-fa86-a56af092e6b2@linux.intel.com> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: "intel-gfx@lists.freedesktop.org" , "maarten.lankhorst@linux.intel.com" Cc: "Pandiyan, Dhinakaran" , "Vivi, Rodrigo" List-Id: intel-gfx@lists.freedesktop.org --===============0386971861== Content-Language: en-US Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="=-KolU1cCssUD79HFWvVSu" --=-KolU1cCssUD79HFWvVSu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2019-01-04 at 15:35 +0100, Maarten Lankhorst wrote: > Op 04-01-2019 om 14:28 schreef Souza, Jose: > > On Fri, 2019-01-04 at 07:53 +0100, Maarten Lankhorst wrote: > > > Op 03-01-2019 om 15:21 schreef Jos=C3=A9 Roberto de Souza: > > > > intel_psr_set_debugfs_mode() don't just handle the PSR mode but > > > > it > > > > is > > > > also handling input validation, setting the new debug value and > > > > changing PSR IRQ masks. > > > > Lets move the roles listed above to the caller to make the > > > > function > > > > name and what it does accurate. > > > >=20 > > > > Cc: Dhinakaran Pandiyan > > > > Cc: Rodrigo Vivi > > > > Cc: Maarten Lankhorst > > > > Signed-off-by: Jos=C3=A9 Roberto de Souza > > > > --- > > > > drivers/gpu/drm/i915/i915_debugfs.c | 22 ++++++++++++++++++++- > > > > - > > > > drivers/gpu/drm/i915/intel_drv.h | 2 +- > > > > drivers/gpu/drm/i915/intel_psr.c | 26 ++++++++++----------- > > > > ---- > > > > - > > > > 3 files changed, 31 insertions(+), 19 deletions(-) > > > >=20 > > > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c > > > > b/drivers/gpu/drm/i915/i915_debugfs.c > > > > index 1a31921598e7..77b097b50fd5 100644 > > > > --- a/drivers/gpu/drm/i915/i915_debugfs.c > > > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c > > > > @@ -2639,19 +2639,29 @@ i915_edp_psr_debug_set(void *data, u64 > > > > val) > > > > { > > > > struct drm_i915_private *dev_priv =3D data; > > > > struct drm_modeset_acquire_ctx ctx; > > > > - int ret; > > > > + const u32 mode =3D val & I915_PSR_DEBUG_MODE_MASK; > > > > + int ret =3D 0; > > > > =20 > > > > if (!CAN_PSR(dev_priv)) > > > > return -ENODEV; > > > > =20 > > > > DRM_DEBUG_KMS("Setting PSR debug to %llx\n", val); > > > > =20 > > > > + if (val & ~(I915_PSR_DEBUG_IRQ | > > > > I915_PSR_DEBUG_MODE_MASK) || > > > > + mode > I915_PSR_DEBUG_FORCE_PSR1) { > > > > + DRM_DEBUG_KMS("Invalid debug mask %llx\n", > > > > val); > > > > + return -EINVAL; > > > > + } > > > This would only work for (psr.debug & MASK) =3D=3D (val & MASK). > > >=20 > > > So you need to take the lock before you can be sure. > > >=20 > > > While at it, you probably also need the intel_runtime_pm_get() > > > reference.. so you really don't complicate locking much. > > >=20 > > > I would honestly just grab the extra locks unnecessarily for > > > simplicity. It's only used from debugfs after all. > > Thanks for the catch. > >=20 > > Something like this? > >=20 > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c > > b/drivers/gpu/drm/i915/i915_debugfs.c > > index 938ad2107ead..3a6ccf815ee1 100644 > > --- a/drivers/gpu/drm/i915/i915_debugfs.c > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c > > @@ -2656,11 +2656,13 @@ i915_edp_psr_debug_set(void *data, u64 val) > > return -EINVAL; > > } > >=20 > > - if (!mode) > > - goto skip_mode; > > - > > intel_runtime_pm_get(dev_priv); > >=20 > > + mutex_lock(&dev_priv->psr.lock); > > + if (mode =3D=3D (dev_priv->psr.debug & > > I915_PSR_DEBUG_MODE_MASK)) > > + goto skip_mode; > > + mutex_unlock(&dev_priv->psr.lock); > > + > > drm_modeset_acquire_init(&ctx, > > DRM_MODESET_ACQUIRE_INTERRUPTIBLE); > >=20 > > retry: > > @@ -2674,8 +2676,6 @@ i915_edp_psr_debug_set(void *data, u64 val) > > drm_modeset_drop_locks(&ctx); > > drm_modeset_acquire_fini(&ctx); > >=20 > > - intel_runtime_pm_put(dev_priv); > > - > > skip_mode: > > if (!ret) { > > mutex_lock(&dev_priv->psr.lock); > > @@ -2684,6 +2684,8 @@ i915_edp_psr_debug_set(void *data, u64 val) > > mutex_unlock(&dev_priv->psr.lock); > > } > >=20 > > + intel_runtime_pm_put(dev_priv); > > + > > return ret; > > } > >=20 > >=20 > >=20 > >=20 > > > > + > > > > + if (!mode) > > > > + goto skip_mode; > > > > + > > > > intel_runtime_pm_get(dev_priv); > > > > =20 > > > > drm_modeset_acquire_init(&ctx, > > > > DRM_MODESET_ACQUIRE_INTERRUPTIBLE); > > > > =20 > > > > retry: > > > > - ret =3D intel_psr_set_debugfs_mode(dev_priv, &ctx, val); > > > > + ret =3D intel_psr_set_debugfs_mode(dev_priv, &ctx, mode); > > > > if (ret =3D=3D -EDEADLK) { > > > > ret =3D drm_modeset_backoff(&ctx); > > > > if (!ret) > > > > @@ -2663,6 +2673,14 @@ i915_edp_psr_debug_set(void *data, u64 > > > > val) > > > > =20 > > > > intel_runtime_pm_put(dev_priv); > > > > =20 > > > > +skip_mode: > > > > + if (!ret) { > > > > + mutex_lock(&dev_priv->psr.lock); > > > > + dev_priv->psr.debug =3D val; > > > > + intel_psr_irq_control(dev_priv, dev_priv- > > > > >psr.debug); > > > > + mutex_unlock(&dev_priv->psr.lock); > > > > + } > > > > + > > > > return ret; > > > > } > > > > =20 > > > > diff --git a/drivers/gpu/drm/i915/intel_drv.h > > > > b/drivers/gpu/drm/i915/intel_drv.h > > > > index 1a11c2beb7f3..2367f07ba29e 100644 > > > > --- a/drivers/gpu/drm/i915/intel_drv.h > > > > +++ b/drivers/gpu/drm/i915/intel_drv.h > > > > @@ -2063,7 +2063,7 @@ void intel_psr_disable(struct intel_dp > > > > *intel_dp, > > > > const struct intel_crtc_state > > > > *old_crtc_state); > > > > int intel_psr_set_debugfs_mode(struct drm_i915_private > > > > *dev_priv, > > > > struct drm_modeset_acquire_ctx > > > > *ctx, > > > > - u64 value); > > > > + u32 mode); > > > > void intel_psr_invalidate(struct drm_i915_private *dev_priv, > > > > unsigned frontbuffer_bits, > > > > enum fb_op_origin origin); > > > > diff --git a/drivers/gpu/drm/i915/intel_psr.c > > > > b/drivers/gpu/drm/i915/intel_psr.c > > > > index 0ef6c5f8c298..bba4f7da68b3 100644 > > > > --- a/drivers/gpu/drm/i915/intel_psr.c > > > > +++ b/drivers/gpu/drm/i915/intel_psr.c > > > > @@ -69,13 +69,14 @@ static bool psr_global_enabled(u32 debug) > > > > } > > > > =20 > > > > static bool intel_psr2_enabled(struct drm_i915_private > > > > *dev_priv, > > > > - const struct intel_crtc_state > > > > *crtc_state) > > > > + const struct intel_crtc_state > > > > *crtc_state, > > > > + u32 debug) > > > > { > > > > /* Cannot enable DSC and PSR2 simultaneously */ > > > > WARN_ON(crtc_state->dsc_params.compression_enable && > > > > crtc_state->has_psr2); > > > > =20 > > > > - switch (dev_priv->psr.debug & I915_PSR_DEBUG_MODE_MASK) > > > > { > > > > + switch (debug & I915_PSR_DEBUG_MODE_MASK) { > > > > case I915_PSR_DEBUG_DISABLE: > > > > case I915_PSR_DEBUG_FORCE_PSR1: > > > > return false; > > > > @@ -758,7 +759,8 @@ void intel_psr_enable(struct intel_dp > > > > *intel_dp, > > > > goto unlock; > > > > } > > > > =20 > > > > - dev_priv->psr.psr2_enabled =3D > > > > intel_psr2_enabled(dev_priv, > > > > crtc_state); > > > > + dev_priv->psr.psr2_enabled =3D > > > > intel_psr2_enabled(dev_priv, > > > > crtc_state, > > > > + dev_pri > > > > v- > > > > > psr.debug); > > > > dev_priv->psr.busy_frontbuffer_bits =3D 0; > > > > dev_priv->psr.prepared =3D true; > > > > dev_priv->psr.pipe =3D to_intel_crtc(crtc_state- > > > > >base.crtc)- > > > > > pipe; > > > > @@ -944,7 +946,7 @@ static bool switching_psr(struct > > > > drm_i915_private *dev_priv, > > > > =20 > > > > int intel_psr_set_debugfs_mode(struct drm_i915_private > > > > *dev_priv, > > > > struct drm_modeset_acquire_ctx > > > > *ctx, > > > > - u64 val) > > > > + u32 mode) > > > > { > > > > struct drm_device *dev =3D &dev_priv->drm; > > > > struct drm_connector_state *conn_state; > > > > @@ -954,13 +956,6 @@ int intel_psr_set_debugfs_mode(struct > > > > drm_i915_private *dev_priv, > > > > struct intel_dp *dp; > > > > int ret; > > > > bool enable; > > > > - u32 mode =3D val & I915_PSR_DEBUG_MODE_MASK; > > > > - > > > > - if (val & ~(I915_PSR_DEBUG_IRQ | > > > > I915_PSR_DEBUG_MODE_MASK) || > > > > - mode > I915_PSR_DEBUG_FORCE_PSR1) { > > > > - DRM_DEBUG_KMS("Invalid debug mask %llx\n", > > > > val); > > > > - return -EINVAL; > > > > - } > > > > =20 > > > > ret =3D drm_modeset_lock(&dev- > > > > >mode_config.connection_mutex, > > > > ctx); > > > > if (ret) > > > > @@ -990,16 +985,15 @@ int intel_psr_set_debugfs_mode(struct > > > > drm_i915_private *dev_priv, > > > > if (ret) > > > > return ret; > > > > =20 > > > > - enable =3D psr_global_enabled(val); > > > > + enable =3D psr_global_enabled(mode); > > > > =20 > > > > if (!enable || switching_psr(dev_priv, crtc_state, > > > > mode)) > > > > intel_psr_disable_locked(dev_priv->psr.dp); > > > > =20 > > > > - dev_priv->psr.debug =3D val; > > > > if (crtc) > > > > - dev_priv->psr.psr2_enabled =3D > > > > intel_psr2_enabled(dev_priv, crtc_state); > > > > - > > > > - intel_psr_irq_control(dev_priv, dev_priv->psr.debug); > > > > + dev_priv->psr.psr2_enabled =3D > > > > intel_psr2_enabled(dev_priv, > > > > + =09 > > > > crtc_st > > > > ate, > > > > + =09 > > > > mode); > > > > =20 > > > > if (dev_priv->psr.prepared && enable) > > > > intel_psr_enable_locked(dev_priv, crtc_state); > Hm I would change the psr irq inside the lock, then jump to pm_put to > finish and call that label out. Most race-free way to do so. :) >=20 Well doing that will keep intel_psr_set_debugfs_mode() doing more stuff than it is supposed to but yeah it is taking the lock 3 times through i915_edp_psr_debug_set(), I'm not so concerned about race conditions because the use cases that we have would not cause it. --=-KolU1cCssUD79HFWvVSu Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEVNG051EijGa0MiaQVenbO/mOWkkFAlwvgSsACgkQVenbO/mO WkmTwwf+P7GaFv0c0dmDWNszlBR80JlmvaEv/1wDTh2gsJfAQGPpmvk4vVi0Nbcw QYjFlyM/NVCfqLnpExXL3z7j6a81kTMpXJGltSZh+3uvyKBzcUxVQ4w7+5uBAtix gjSSsm2gY6/5bdrDuDLsE/9GbP0goFcSNhBzhHj6Yf6Wdvs/ruUU+t0uQYJdYS1R aNe96HXM0DXYiF24zFjxpo74QbAaqUx10yk3pGbD8GLdyb5llyndJtph9WTEi+ad ZVob/BO+vkiZj5fs4qyfvbqmam3/SBFlwVMNbPR2FuMTiX8R7LHbZSQvbPhMfgtJ 8grY1789b81s2m6jdIRC7j93JTy7HQ== =fYO6 -----END PGP SIGNATURE----- --=-KolU1cCssUD79HFWvVSu-- --===============0386971861== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSW50ZWwtZ2Z4 IG1haWxpbmcgbGlzdApJbnRlbC1nZnhAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vaW50ZWwtZ2Z4Cg== --===============0386971861==--