public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>,
	intel-gfx <intel-gfx@lists.freedesktop.org>,
	dri-devel <dri-devel@lists.freedesktop.org>
Cc: John Harrison <John.C.Harrison@Intel.com>,
	Andi Shyti <andi.shyti@kernel.org>,
	Matthew Brost <matthew.brost@intel.com>, <stable@vger.kernel.org>
Subject: Re: [PATCH] drm/i915/gt/uc: Evaluate GuC priority within locks
Date: Fri, 7 Jun 2024 11:19:04 -0700	[thread overview]
Message-ID: <185a4d70-4f1b-4b95-acc2-d2e26cb0052b@intel.com> (raw)
In-Reply-To: <20240606001702.59005-1-andi.shyti@linux.intel.com>



On 6/5/2024 5:17 PM, Andi Shyti wrote:
> The ce->guc_state.lock was made to protect guc_prio, which
> indicates the GuC priority level.
>
> But at the begnning of the function we perform some sanity check
> of guc_prio outside its protected section. Move them within the
> locked region.
>
> Use this occasion to expand the if statement to make it clearer.
>
> Fixes: ee242ca704d3 ("drm/i915/guc: Implement GuC priority management")
> Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: <stable@vger.kernel.org> # v5.15+
> ---
>   drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 15 +++++++++++----
>   1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> index 0eaa1064242c..1181043bc5e9 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> @@ -4267,13 +4267,18 @@ static void guc_bump_inflight_request_prio(struct i915_request *rq,
>   	u8 new_guc_prio = map_i915_prio_to_guc_prio(prio);
>   
>   	/* Short circuit function */
> -	if (prio < I915_PRIORITY_NORMAL ||
> -	    rq->guc_prio == GUC_PRIO_FINI ||
> -	    (rq->guc_prio != GUC_PRIO_INIT &&
> -	     !new_guc_prio_higher(rq->guc_prio, new_guc_prio)))
> +	if (prio < I915_PRIORITY_NORMAL)
>   		return;
>   

My understanding was that those checks are purposely done outside of the 
lock to avoid taking it when not needed and that the early exit is not 
racy. In particular:

- GUC_PRIO_FINI is the end state for the priority, so if we're there 
that's not changing anymore and therefore the lock is not required.

- the priority only goes up with the bumping, so if 
new_guc_prio_higher() is false that's not going to be changed by a 
different thread running at the same time and increasing the priority 
even more.

I think there is still a possible race is if new_guc_prio_higher() is 
true when we check it outside the lock but then changes before we 
execute the protected chunk inside, so a fix would still be required for 
that.

All this said, I don't really have anything against moving the whole 
thing inside the lock since this isn't on a critical path, just wanted 
to point out that it's not all strictly required.

One nit on the code below.

>   	spin_lock(&ce->guc_state.lock);
> +
> +	if (rq->guc_prio == GUC_PRIO_FINI)
> +		goto exit;
> +
> +	if (rq->guc_prio != GUC_PRIO_INIT &&
> +	    !new_guc_prio_higher(rq->guc_prio, new_guc_prio))
> +		goto exit;
> +
>   	if (rq->guc_prio != GUC_PRIO_FINI) {

You're now checking for rq->guc_prio == GUC_PRIO_FINI inside the lock, 
so no need to check it again here as it can't have changed.

Daniele

>   		if (rq->guc_prio != GUC_PRIO_INIT)
>   			sub_context_inflight_prio(ce, rq->guc_prio);
> @@ -4281,6 +4286,8 @@ static void guc_bump_inflight_request_prio(struct i915_request *rq,
>   		add_context_inflight_prio(ce, rq->guc_prio);
>   		update_context_prio(ce);
>   	}
> +
> +exit:
>   	spin_unlock(&ce->guc_state.lock);
>   }
>   


  parent reply	other threads:[~2024-06-07 18:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06  0:17 [PATCH] drm/i915/gt/uc: Evaluate GuC priority within locks Andi Shyti
2024-06-06  2:57 ` Matthew Brost
2024-06-07 18:19 ` Daniele Ceraolo Spurio [this message]
2024-06-11 13:31   ` Andi Shyti

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=185a4d70-4f1b-4b95-acc2-d2e26cb0052b@intel.com \
    --to=daniele.ceraolospurio@intel.com \
    --cc=John.C.Harrison@Intel.com \
    --cc=andi.shyti@kernel.org \
    --cc=andi.shyti@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox