Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sk Anirban" <sk.anirban@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/xe/xe_late_bind_fw: Skip OCODE late bind if same version is already running
Date: Tue, 17 Nov 2026 13:29:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-218878@kernel.org> (raw)
In-Reply-To: <20261117125904.2877468-2-sk.anirban@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: tautological SDK API version check in
  xe_late_bind_ocode_is_current()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] drm/xe/xe_late_bind_fw: race condition accessing
  component.ops and mei_dev [1]
--

commit d49ce25c764e04b076452ac50c66f624a91a9db3
Author: Sk Anirban <sk.anirban@intel.com>

drm/xe/xe_late_bind_fw: Skip OCODE late bind if same version is already running

This commit adds xe_late_bind_ocode_is_current() to check whether OCODE
firmware is initialized and skip uploading the late-binding payload when the
queried SDK API version matches lbfw->sdk_api_version.

> diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c
> index 355d7c841871d..4b8c48871d8ca 100644
> --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
> +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
> @@ -246,6 +246,31 @@ static void wait_for_worker_completion(struct xe_late_bind *late_bind)
>  	}
>  }
>  
> +static bool xe_late_bind_ocode_is_current(struct xe_late_bind_fw *lbfw)
> +{
> +	struct xe_device *xe = late_bind_fw_to_xe(lbfw);
> +	u16 running_ver;
> +	int ret;
> +
> +	if (lbfw->type != INTEL_LB_TYPE_OCODE || !xe->info.has_sysctrl)
> +		return false;
> +
> +	if (!xe_sysctrl_is_oobmsm_fw_ready(xe))
> +		return false;
> +
> +	ret = xe_sysctrl_sdk_api_version(xe, &running_ver);
> +	if (ret) {
> +		drm_dbg(&xe->drm, "Failed to get running OCODE SDK API version: %pe\n",
> +			ERR_PTR(ret));
> +		return false;
> +	}
> +
> +	drm_dbg(&xe->drm, "OCODE SDK API version running %u, payload %u\n",
> +		running_ver, lbfw->sdk_api_version);
> +
> +	return running_ver == lbfw->sdk_api_version;
> +}

[Severity: Medium]
Does running_ver == lbfw->sdk_api_version always evaluate to true here
instead of checking the actual OCODE firmware release version
(lbfw->version)?

During initialization, __xe_late_bind_fw_init() already calls
xe_sysctrl_sdk_api_version() to pick the compatible xe/cri_ocode_<sdk_ver>.bin
file and rejects the blob before allocating lb_fw->payload if
lb_fw->sdk_api_version != sdk_ver:

drivers/gpu/drm/xe/xe_late_bind_fw.c:__xe_late_bind_fw_init() {
	...
	if (lb_fw->type == INTEL_LB_TYPE_OCODE) {
		/* Get SDK API version */
		ret = xe_sysctrl_sdk_api_version(xe, &sdk_ver);
		...
		snprintf(lb_fw->blob_path, sizeof(lb_fw->blob_path),
			 "xe/cri_ocode_%u.bin", sdk_ver);
	}
	...
	if (lb_fw->type == INTEL_LB_TYPE_OCODE && lb_fw->sdk_api_version != sdk_ver) {
		drm_warn(&xe->drm, "%s late binding fw: SDK API version mismatch %u != %u\n",
			 fw_id_to_name[lb_fw->id], lb_fw->sdk_api_version, sdk_ver);
		ret = 0;
		goto release_fw;
	}
	...
}

Because xe_late_bind_fw_load() only queues work when lbfw->payload is set,
lbfw->sdk_api_version is guaranteed to match the System Controller SDK API
version, so late binding will skip uploading newer OCODE firmware builds for
the same SDK API version whenever an older OCODE image is already running.

> +
>  static void xe_late_bind_work(struct work_struct *work)
>  {
>  	struct xe_late_bind_fw *lbfw = container_of(work, struct xe_late_bind_fw, work);
> @@ -258,6 +283,12 @@ static void xe_late_bind_work(struct work_struct *work)
>  
>  	xe_device_assert_mem_access(xe);
>  
> +	if (xe_late_bind_ocode_is_current(lbfw)) {
> +		drm_dbg(&xe->drm, "%s firmware already loaded, skipping\n",
> +			fw_id_to_name[lbfw->id]);
> +		goto out;
> +	}
> +
>  	/* we can queue this before the component is bound */
>  	for (slept = 0; slept < LB_INIT_TIMEOUT_MS; slept += 100) {
>  		if (late_bind->component.ops)

[Severity: Critical]
This problem wasn't introduced by this patch, but can xe_late_bind_work()
race [1] with xe_late_bind_component_bind() and
xe_late_bind_component_unbind() on late_bind->component.ops and
late_bind->component.mei_dev?

CPU0                                  CPU1
xe_late_bind_work()
  if (!late_bind->component.ops)
  do {
    ops->push_payload(...) -> -EBUSY
    msleep(LB_FW_LOAD_RETRY_PAUSE_MS)
                                      xe_late_bind_component_unbind()
                                        wait_for_worker_completion()
                                          (resume queues new work or
                                           unbind races after check)
                                        late_bind->component.ops = NULL
  } while (--retry && ret == -EBUSY)
  late_bind->component.ops->push_payload(...)
    <-- NULL pointer dereference (or use-after-free on mei_dev)

Nothing serializes xe_late_bind_fw_load() during PM resume against
xe_late_bind_component_unbind(), so a worker queued after
wait_for_worker_completion() can observe component.ops before it is cleared
and then dereference NULL or pass a freed mei_dev pointer to push_payload().
In addition, xe_late_bind_component_bind() writes late_bind->component.ops
before late_bind->component.mei_dev without a lock or barrier, so a polling
worker can see non-NULL ops and invoke push_payload() while mei_dev is still
NULL or stale.

[1] https://sashiko.dev/#/bug/linux-88e26b7c-a817-48ba-9352-5bb39eea1357

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117125904.2877468-2-sk.anirban@intel.com?part=1

      parent reply	other threads:[~2026-11-17 13:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:59 [PATCH] drm/xe/xe_late_bind_fw: Skip OCODE late bind if same version is already running Sk Anirban
2026-11-17 13:24 ` ✓ CI.KUnit: success for " Patchwork
2026-11-17 13:29 ` sashiko-bot [this message]

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=sashiko-outbox-218878@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sk.anirban@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox