Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/hisilicon/hibmc: lost hotplug event on unplug+plug in
  hibmc_dp_hpd_isr()
- [Medium] drm/hisilicon/hibmc: stale HIBMC_HPD_OUT breaks detect in
  hibmc_dp_detect()
- [Medium] drm/hisilicon/hibmc: race on link.status in
  hibmc_dp_reset_link()
--

commit 66c780066116f4c8c3ae6a3396cdf80d86327a1d
Author: Lin He <[email protected]>

drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status

This commit replaces HPD status polling in the threaded IRQ handler with
reading the HPD state in the hardirq handler, skips connector detection
when hpd_status is not HIBMC_HPD_IN, and resets link status on unplug in
hardirq context.

> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c 
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
> index 9cf0b6be15bdc..245d6b9e2836a 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
[ ... ]
> @@ -60,13 +58,13 @@ static int hibmc_dp_detect(struct drm_connector 
> *connector,
>  {
>       struct hibmc_dp *dp = to_hibmc_dp(connector);
>       struct hibmc_dp_dev *dp_dev = dp->dp_dev;
> +     int hpd_status = READ_ONCE(dp->hpd_status);
>       int ret = connector_status_disconnected;
>  
> -     if (dp->irq_status) {
> -             if (dp_dev->hpd_status != HIBMC_HPD_IN) {
> -                     ret = connector_status_disconnected;
> -                     goto exit;
> -             }
> +     if (hpd_status != HIBMC_HPD_IN) {
> +             drm_dbg_dp(dp->drm_dev, "dp detect skipped, hpd (%d)\n",
> +                        hpd_status);
> +             goto exit;
>       }

[Severity: Medium]
Does unconditionally gating hibmc_dp_detect() on dp->hpd_status ==
HIBMC_HPD_IN break detection when dp->hpd_status has not been updated by
hibmc_dp_interrupt()?

hibmc_dp_init() sets dp->hpd_status to HIBMC_HPD_OUT, and only
hibmc_dp_interrupt() ever updates it.  If pci_alloc_irq_vectors() in
hibmc_msi_init() allocates only HIBMC_MIN_VECTORS (1), the HPD MSI handler
is never registered and dp->hpd_status stays HIBMC_HPD_OUT forever.  Even
with two MSI vectors, detection before the initial HPD MSI and threaded
handler complete after hibmc_dp_late_register(), or after a monitor change
across system suspend/resume, sees a stale dp->hpd_status and reports
connector_status_disconnected.

> @@ -188,24 +186,26 @@ irqreturn_t hibmc_dp_hpd_isr(int irq, void *arg)
>  {
>       struct drm_device *dev = (struct drm_device *)arg;
>       struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> -     int idx, exp_status;
> +     int status = READ_ONCE(priv->dp.hpd_status);
> +     int idx;
>  
>       if (!drm_dev_enter(dev, &idx))
>               return -ENODEV;
>  
> -     if (priv->dp.irq_status & DP_MASKED_SINK_HPD_PLUG_INT) {
> +     if (status == HIBMC_HPD_IN) {
> +             /* Plug takes aux_lock, so it must run in the thread. */
>               drm_dbg_dp(&priv->dev, "HPD IN isr occur!\n");
>               hibmc_dp_hpd_cfg(&priv->dp);
> -             exp_status = HIBMC_HPD_IN;
> -     } else {
> +     } else if (status == HIBMC_HPD_OUT) {
>               drm_dbg_dp(&priv->dev, "HPD OUT isr occur!\n");
> -             hibmc_dp_reset_link(&priv->dp);
> -             exp_status = HIBMC_HPD_OUT;
> +     } else {
> +             drm_err(&priv->dev, "HPD status (%d) error\n", status);
> +             goto exit;
>       }
>  
> -     if (hibmc_dp_check_hpd_status(&priv->dp, exp_status))
> -             drm_connector_helper_hpd_irq_event(&priv->dp.connector);
> +     drm_connector_helper_hpd_irq_event(&priv->dp.connector);

[Severity: Medium]
Can an unplug followed by a plug before hibmc_dp_hpd_isr() runs still
drop the hotplug event and leave the DP link untrained?

<hardirq>                         irq/hpd
hibmc_dp_interrupt() [unplug]
  priv->dp.hpd_status = HIBMC_HPD_OUT
  hibmc_dp_reset_link()
    channel_equalized = false
hibmc_dp_interrupt() [plug]
  priv->dp.hpd_status = HIBMC_HPD_IN
                                  hibmc_dp_hpd_isr()
                                    drm_connector_helper_hpd_irq_event()
                                      check_connector_changed()
                                        hibmc_dp_detect() -> connected
                                        old_epoch_counter == epoch_counter
                                        return false  <-- event dropped

Because hibmc_dp_detect() never ran while dp->hpd_status was
HIBMC_HPD_OUT, connector->status was already connector_status_connected,
so drm_helper_probe_detect_ctx() does not increment
connector->epoch_counter and drm_connector_helper_hpd_irq_event() sends no
hotplug event.  Since hibmc_dp_link_training() is only called from
hibmc_dp_mode_set(), clearing channel_equalized in hibmc_dp_reset_link()
without triggering a modeset or re-training leaves the display with an
untrained link.

Also, if hibmc_dp_hpd_isr() reads status == HIBMC_HPD_OUT at entry and a
plug hardirq updates dp->hpd_status to HIBMC_HPD_IN before
hibmc_dp_detect() runs, hibmc_dp_detect() performs DPCD AUX transfers
before hibmc_dp_hpd_cfg() has configured the AUX block; and if both unplug
and plug latch before hibmc_dp_interrupt() reads HIBMC_DP_HPD_STATUS,
hibmc_dp_get_hpd_status() returns HIBMC_HPD_IN and skips
hibmc_dp_reset_link() while clearing both interrupt bits.

> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index 602930964e930..a110b5e15e596 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -59,11 +59,18 @@ static irqreturn_t hibmc_dp_interrupt(int irq, void *arg)
>  {
>       struct drm_device *dev = (struct drm_device *)arg;
>       struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> +     int hpd_status;
>       u32 status;
>  
>       status = readl(priv->mmio + HIBMC_DP_INTSTAT);
>       if (status) {
> -             priv->dp.irq_status = status;
> +             hpd_status = hibmc_dp_get_hpd_status(&priv->dp);
> +             WRITE_ONCE(priv->dp.hpd_status, hpd_status);
> +
> +             /* Reset here so a later plug cannot hide this unplug. */
> +             if (hpd_status == HIBMC_HPD_OUT)
> +                     hibmc_dp_reset_link(&priv->dp);

[Severity: Medium]
Can hibmc_dp_reset_link() in hardirq context race with
hibmc_dp_link_training_channel_eq() and leave
dp_dev->link.status.channel_equalized set to true after an unplug?

hibmc_dp_mode_set()
  hibmc_dp_link_training()
    hibmc_dp_link_training_channel_eq()
      drm_dp_dpcd_read_link_status(..., lane_status)
      <hardirq>
        hibmc_dp_interrupt()
          hibmc_dp_reset_link()
            channel_equalized = false
      if (drm_dp_channel_eq_ok(lane_status, ...))
        channel_equalized = true  <-- overwrites unplug reset

hibmc_dp_link_training_channel_eq() then returns 0 using the pre-unplug
lane_status, leaving channel_equalized true so subsequent
hibmc_dp_mode_set() calls skip link training.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to