Re: [PATCH v6] drm/i915/dsc: Add Per connector debugfs node for DSC support/enable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2018-12-05 at 11:29 -0800, Manasi Navare wrote:
> On Wed, Dec 05, 2018 at 02:00:39PM -0500, Lyude Paul wrote:
> > Looks good, some small nitpicks
> > 
> > On Tue, 2018-12-04 at 11:55 -0800, Manasi Navare wrote:
> > > DSC can be supported per DP connector. This patch adds a per connector
> > > debugfs node to expose DSC support capability by the kernel.
> > > The same node can be used from userspace to force DSC enable.
> > > 
> > > force_dsc_en written through this debugfs node is used to force
> > > DSC even for lower resolutions.
> > > 
> > > v6:
> > > * Read fec_capable only for non edp (Manasi)
> > > v5:
> > > * Name it dsc sink support and also add
> > > fec support in the same node (Ville)
> > > v4:
> > > * Add missed connector_status check (Manasi)
> > > * Create i915_dsc_support node only for Gen >=10 (manasi)
> > > * Access intel_dp->dsc_dpcd only if its not NULL (Manasi)
> > > v3:
> > > * Combine Force_dsc_en with this patch (Ville)
> > > v2:
> > > * Use kstrtobool_from_user to avoid explicit error checking (Lyude)
> > > * Rebase on drm-tip (Manasi)
> > > 
> > > Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
> > > Cc: Ville Syrjala <ville.syrjala@xxxxxxxxxxxxxxx>
> > > Cc: Anusha Srivatsa <anusha.srivatsa@xxxxxxxxx>
> > > Cc: Lyude Paul <lyude@xxxxxxxxxx>
> > > Signed-off-by: Manasi Navare <manasi.d.navare@xxxxxxxxx>
> > > ---
> > >  drivers/gpu/drm/i915/i915_debugfs.c | 80 +++++++++++++++++++++++++++++
> > >  drivers/gpu/drm/i915/intel_dp.c     |  3 +-
> > >  drivers/gpu/drm/i915/intel_drv.h    |  3 ++
> > >  3 files changed, 85 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c
> > > b/drivers/gpu/drm/i915/i915_debugfs.c
> > > index 129b9a6f8309..ec10ab027d18 100644
> > > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > > @@ -5086,6 +5086,79 @@ static int i915_hdcp_sink_capability_show(struct
> > > seq_file *m, void *data)
> > >  }
> > >  DEFINE_SHOW_ATTRIBUTE(i915_hdcp_sink_capability);
> > >  
> > > +static int i915_dsc_fec_support_show(struct seq_file *m, void *data)
> > > +{
> > > +	struct drm_connector *connector = m->private;
> > > +	struct intel_encoder *encoder = intel_attached_encoder(connector);
> > > +	struct intel_dp *intel_dp =
> > > +		enc_to_intel_dp(&encoder->base);
> > > +	struct intel_crtc *crtc;
> > > +	struct intel_crtc_state *crtc_state;
> > > +
> > > +	if (connector->status != connector_status_connected)
> > > +		return -ENODEV;
> > > +
> > > +	crtc = to_intel_crtc(encoder->base.crtc);
> > > +	crtc_state = to_intel_crtc_state(crtc->base.state);
> 
> I am seeing a kernel NULl pointer dereferencing here in CI possibly because
> the crtc is NULL and as per Ville and Danvet I should be grabbing both
> connection mutex
> and crtc mutex and use the acquire ctx and backoff stuff so I am trying to
> understand that part
> and seeing how I can use that.
> 
> Let me know if you have any inputs/examples on that too..

Mhm, so here's why they are asking for each lock:

connection_mutex: Protects any connector->state, and connector->status.

(As an extra note: ignore connector->mutex for modesetting purposes, only
 dev->mode_config.connection_mutex is important.)

crtc->mutex: Anything in crtc->state for the given crtc

In order to avoid to avoid a NULL dereference due to connector->crtc->state
changing, you'd start grabbing locks with something like this:


  /* pretend we have 'connector' already set to the drm_connector */
  /* also pretend we have 'dev' set to the struct drm_device* */
  struct drm_crtc *crtc;
  struct drm_modeset_acquire_ctx ctx;
  bool try_again = false;
  int ret = 0;

  drm_modeset_acquire_init(&ctx, 0);

  do {
    /* We don't check the return code here because since this is
     * our first lock, so there isn't any chance of us deadlocking
     * yet.
     */
    drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);

    /* Cool! Now that we're holding connection_mutex, we can start
     * reading from the connector struct and friends
     */
    crtc = connector->state->crtc;
    if (connector->status != connector_status_connected || !crtc) {
      ret = -ENODEV;
      break;
    }

    /* Now we need to check the return code from
     * drm_modeset_lock(), because.......
     */
    ret = drm_modeset_lock(&crtc->mutex, &ctx);
    if (ret == -EDEADLK) {
      /* We could deadlock! If we're here, then this is
       * probably what happened:
       *
       * <CPU1> (us)                 <CPU2>
       * modeset_lock(&conn_mutex);  modeset_lock(&crtc->mutex);
       * modeset_lock(&crtc->mutex); modeset_lock(&conn_mutex);
       *
       * CPU1 is waiting for crtc->mutex which is held by CPU2, but
       * CPU2 is waiting for conn_mutex, which is held by CPU1
       *
       * Normally the kernel doesn't run into this issue
       * because a lot of care has been put into ordering
       * mutex_lock() calls correctly. But, with modesetting
       * we don't have the benefit of knowing what order these
       * locks will be acquired in. Since drm_modeset_lock()
       * has informed us of this scenario however, we can
       * avoid hanging the entire kernel by simply dropping
       * our locks, in this case that would just include
       * connection_mutex. We call this "backing off"
       */
      drm_modeset_backoff(&ctx);

      /* Now, things will look like this:
       *
       * <CPU1> (us)                    <CPU2>
       * modeset_lock(&conn_mutex);     modeset_lock(&crtc->mutex);
       * modeset_lock(&crtc->mutex);    modeset_lock(&conn_mutex);
       * (oh no, a deadlock!)           ...
       * modeset_backoff();             (Oh hey, I locked &conn_mutex)
       * modeset_lock(&conn_mutex);     (now I'm doing stuff, wee!)
       * ...                            modeset_drop_locks();
       * (Oh hey, I locked &conn_mutex) ...
       * (do stuff)                     ...
       * (etc. etc.)
       */
      go_again = true;
      continue;
    }

    /* Now if we're here, we managed to grab both locks correctly,
     * and we know neither connector->state or crtc->state will
     * change.
     */
    intel_dp = enc_to_intel_dp(intel_attached_encoder(connector));
    if (intel_dp->dsc_dpcd)
      /* etc. etc. */

    /* ... */

  } while (go_again);

  /* Now, we can finally drop any locks we're holding */
  drm_modeset_drop_locks(&ctx);
  /* And release our acquisition context */
  drm_modeset_acquire_fini(&ctx);

  return ret;


Does that help explain things?

> 
> > > +	drm_modeset_lock(&crtc->base.mutex, NULL);
> > > +	seq_printf(m, "DSC_Enabled: %s\n",
> > > +		   yesno(crtc_state->dsc_params.compression_enable));
> > > +	if (intel_dp->dsc_dpcd)
> > > +		seq_printf(m, "DSC_Sink_Support: %s\n",
> > > +			   yesno(drm_dp_sink_supports_dsc(intel_dp-
> > > > dsc_dpcd)));
> > > +	if (!intel_dp_is_edp(intel_dp))
> > > +		seq_printf(m, "FEC_Sink_Support: %s\n",
> > > +			   yesno(drm_dp_sink_supports_fec(intel_dp-
> > > > fec_capable)));
> > > +	drm_modeset_unlock(&crtc->base.mutex);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static ssize_t i915_dsc_fec_support_write(struct file *file,
> > > +					  const char __user *ubuf,
> > > +					  size_t len, loff_t *offp)
> > > +{
> > > +	bool dsc_enable = false;
> > > +	int ret;
> > > +	struct drm_connector *connector =
> > > +		((struct seq_file *)file->private_data)->private;
> > > +	struct intel_encoder *encoder = intel_attached_encoder(connector);
> > > +	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
> > > +
> > > +	if (len == 0)
> > > +		return 0;
> > > +
> > > +	DRM_DEBUG_DRIVER("Copied %d bytes from user to force DSC\n",
> > > +			 (unsigned int)len);
> > You can just use %zu instead of %d here, see:
> > 
> > https://01.org/linuxgraphics/gfx-docs/drm/core-api/printk-formats.html
> 
> Cool I will make this change. Thanks for the review.
> 
> Regards
> Manasi
> 
> > Other then that, looks good to me! With that change:
> > 
> > Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>
> > 
> > > +
> > > +	ret = kstrtobool_from_user(ubuf, len, &dsc_enable);
> > > +	if (ret < 0)
> > > +		return ret;
> > > +
> > > +	DRM_DEBUG_DRIVER("Got %s for DSC Enable\n",
> > > +			 (dsc_enable) ? "true" : "false");
> > > +	intel_dp->force_dsc_en = dsc_enable;
> > > +
> > > +	*offp += len;
> > > +	return len;
> > > +}
> > > +
> > > +static int i915_dsc_fec_support_open(struct inode *inode,
> > > +				     struct file *file)
> > > +{
> > > +	return single_open(file, i915_dsc_fec_support_show,
> > > +			   inode->i_private);
> > > +}
> > > +
> > > +static const struct file_operations i915_dsc_fec_support_fops = {
> > > +	.owner = THIS_MODULE,
> > > +	.open = i915_dsc_fec_support_open,
> > > +	.read = seq_read,
> > > +	.llseek = seq_lseek,
> > > +	.release = single_release,
> > > +	.write = i915_dsc_fec_support_write
> > > +};
> > > +
> > >  /**
> > >   * i915_debugfs_connector_add - add i915 specific connector debugfs
> > > files
> > >   * @connector: pointer to a registered drm_connector
> > > @@ -5098,6 +5171,7 @@ DEFINE_SHOW_ATTRIBUTE(i915_hdcp_sink_capability);
> > >  int i915_debugfs_connector_add(struct drm_connector *connector)
> > >  {
> > >  	struct dentry *root = connector->debugfs_entry;
> > > +	struct drm_i915_private *dev_priv = to_i915(connector->dev);
> > >  
> > >  	/* The connector must have been registered beforehands. */
> > >  	if (!root)
> > > @@ -5122,5 +5196,11 @@ int i915_debugfs_connector_add(struct
> > > drm_connector
> > > *connector)
> > >  				    connector,
> > > &i915_hdcp_sink_capability_fops);
> > >  	}
> > >  
> > > +	if (INTEL_GEN(dev_priv) >= 10 &&
> > > +	    (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
> > > +	     connector->connector_type == DRM_MODE_CONNECTOR_eDP))
> > > +		debugfs_create_file("i915_dsc_fec_support", S_IRUGO, root,
> > > +				    connector, &i915_dsc_fec_support_fops);
> > > +
> > >  	return 0;
> > >  }
> > > diff --git a/drivers/gpu/drm/i915/intel_dp.c
> > > b/drivers/gpu/drm/i915/intel_dp.c
> > > index a6907a1761ab..2e3097cae277 100644
> > > --- a/drivers/gpu/drm/i915/intel_dp.c
> > > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > > @@ -2051,7 +2051,8 @@ intel_dp_compute_link_config(struct intel_encoder
> > > *encoder,
> > >  							&limits);
> > >  
> > >  	/* enable compression if the mode doesn't fit available BW */
> > > -	if (!ret) {
> > > +	DRM_DEBUG_KMS("Force DSC en = %d\n", intel_dp->force_dsc_en);
> > > +	if (!ret || intel_dp->force_dsc_en) {
> > >  		if (!intel_dp_dsc_compute_config(intel_dp, pipe_config,
> > >  						 conn_state, &limits))
> > >  			return false;
> > > diff --git a/drivers/gpu/drm/i915/intel_drv.h
> > > b/drivers/gpu/drm/i915/intel_drv.h
> > > index f94a04b4ad87..0cedce438433 100644
> > > --- a/drivers/gpu/drm/i915/intel_drv.h
> > > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > > @@ -1209,6 +1209,9 @@ struct intel_dp {
> > >  
> > >  	/* Displayport compliance testing */
> > >  	struct intel_dp_compliance compliance;
> > > +
> > > +	/* Display stream compression testing */
> > > +	bool force_dsc_en;
> > >  };
> > >  
> > >  enum lspcon_vendor {
> > -- 
> > Cheers,
> > 	Lyude Paul
> > 
-- 
Cheers,
	Lyude Paul

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux