All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [PATCH i-g-t 3/3] lib/kms: use CRTC index for __igt_output_crtc_populate()
Date: Thu, 26 Mar 2026 13:36:16 +0200	[thread overview]
Message-ID: <acUaMLSxqYTN63hG@intel.com> (raw)
In-Reply-To: <5f13f6e087209ee05ffc9e3cfd0f58cf2f82b83a.1774267502.git.jani.nikula@intel.com>

On Mon, Mar 23, 2026 at 02:06:26PM +0200, Jani Nikula wrote:
> Fill the valid output/crtc combos in __igt_output_crtc_populate() using
> CRTC index instead of pipe. This avoids buffer overruns if we reduce
> igt_display_n_crtcs() to the actual number of CRTCs on the device.
> 
> To keep the for_each_crtc_with_single_output() iteration in pipe order
> on Intel devices, sort the resulting array in a separate
> step. Presumably the performance impact of qsort() on an array of at
> most 16 elements is neglible.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  lib/igt_kms.c | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 42329ad0303c..b92bb16aaf9c 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -3588,6 +3588,18 @@ bool output_is_internal_panel(igt_output_t *output)
>  	}
>  }
>  
> +static int output_crtc_pipe_compare(const void *_a, const void *_b)
> +{
> +	const igt_output_crtc_t *a = _a, *b = _b;
> +
> +	/* pipe order for valid output/crtc combos */
> +	if (a->crtc && b->crtc)
> +		return a->crtc->pipe - b->crtc->pipe;
> +
> +	/* valid combos before empty elements */
> +	return !b->crtc - !a->crtc;
> +}
> +
>  igt_output_crtc_t *__igt_output_crtc_populate(igt_display_t *display, igt_output_crtc_t *chosen_outputs)
>  {
>  	unsigned int full_crtc_index_mask = 0, assigned_crtc_index_mask = 0;
> @@ -3634,17 +3646,17 @@ igt_output_crtc_t *__igt_output_crtc_populate(igt_display_t *display, igt_output
>  					/* We found an unassigned CRTC, use it! */
>  					found = true;
>  					assigned_crtc_index_mask |= 1 << crtc->crtc_index;
> -					chosen_outputs[crtc->pipe].output = output;
> -					chosen_outputs[crtc->pipe].crtc = crtc;
> -				} else if (!chosen_outputs[crtc->pipe].output ||
> -					   output_is_internal_panel(chosen_outputs[crtc->pipe].output)) {
> +					chosen_outputs[crtc->crtc_index].output = output;
> +					chosen_outputs[crtc->crtc_index].crtc = crtc;
> +				} else if (!chosen_outputs[crtc->crtc_index].output ||
> +					   output_is_internal_panel(chosen_outputs[crtc->crtc_index].output)) {
>  					/*
>  					 * Overwrite internal panel if not
>  					 * assigned, external outputs are faster
>  					 * to do modesets
>  					 */
> -					chosen_outputs[crtc->pipe].output = output;
> -					chosen_outputs[crtc->pipe].crtc = crtc;
> +					chosen_outputs[crtc->crtc_index].output = output;
> +					chosen_outputs[crtc->crtc_index].crtc = crtc;
>  				}
>  			}
>  
> @@ -3654,6 +3666,11 @@ igt_output_crtc_t *__igt_output_crtc_populate(igt_display_t *display, igt_output
>  		}
>  	}
>  
> +	/* For Intel, sort the output/crtc combos in pipe order */
> +	if (is_intel_device(display->drm_fd))
> +		qsort(chosen_outputs, igt_display_n_crtcs(display),
> +		      sizeof(*chosen_outputs), output_crtc_pipe_compare);

Maybe one day we can drop this sorting entirely. But that needs some
testing, so this seems good for the moment.

Didn't spot anything bad, so for the series
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +
>  	return chosen_outputs;
>  }
>  
> -- 
> 2.47.3

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2026-03-26 11:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 12:06 [PATCH i-g-t 0/3] lib/kms: make for_each_crtc_with_single_output() independent of pipes Jani Nikula
2026-03-23 12:06 ` [PATCH i-g-t 1/3] lib/kms: don't special case igt_get_single_output_for_crtc() implementation Jani Nikula
2026-03-23 12:06 ` [PATCH i-g-t 2/3] lib/kms: refactor for_each_crtc_with_single_output() to avoid igt_crtc_for_pipe() Jani Nikula
2026-03-23 12:06 ` [PATCH i-g-t 3/3] lib/kms: use CRTC index for __igt_output_crtc_populate() Jani Nikula
2026-03-26 11:36   ` Ville Syrjälä [this message]
2026-03-26 12:36     ` Jani Nikula
2026-03-23 16:38 ` ✓ Xe.CI.BAT: success for lib/kms: make for_each_crtc_with_single_output() independent of pipes Patchwork
2026-03-23 16:54 ` ✓ i915.CI.BAT: " Patchwork
2026-03-23 23:39 ` ✓ Xe.CI.FULL: " Patchwork
2026-03-24  1:24 ` ✗ i915.CI.Full: failure " 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=acUaMLSxqYTN63hG@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jani.nikula@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.