From: "Laguna, Lukasz" <lukasz.laguna@intel.com>
To: <sashiko-reviews@lists.linux.dev>, Raag Jadav <raag.jadav@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v10 08/10] drm/xe: Introduce temporary device wedging
Date: Mon, 24 Aug 2026 16:30:25 +0200 [thread overview]
Message-ID: <45efbcf8-b598-463e-b415-dfee2a3afe66@intel.com> (raw)
In-Reply-To: <20260821113758.006681F000E9@smtp.kernel.org>
On 8/21/2026 13:37, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [Critical] Sleeping in atomic context due to `mutex_lock()` in `xe_device_declare_wedged()`.
Already discussed, can be addressed in a follow-up series.
> - [High] Unprotected state modification and double-increment of `wedged.ref` in `prepare_device_for_reset()`.
Valid. It should be enough to just take the lock and check
xe->wedged.perm before taking the reference.
> - [High] Temporary wedged state from PCI error recovery leaks PM reference and triggers teardown assert if recovery aborts.
It seems to be a false report. Reference is taken just before
RESULT_RECOVERED.
Lukasz
> --
>
> --- Patch [8]: [PATCH v10 08/10] drm/xe: Introduce temporary device wedging ---
> commit 102094142d418b8de53397ac8e1fbe1c7ca46ae9
> Author: Raag Jadav <raag.jadav@intel.com>
>
> drm/xe: Introduce temporary device wedging
>
> This commit converts the boolean wedged flag to a reference count to allow
> temporary wedged states. It also introduces a perm flag for permanent
> wedging and a mutex to protect the wedged state transitions.
>
>> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
>> --- a/drivers/gpu/drm/xe/xe_device.c
>> +++ b/drivers/gpu/drm/xe/xe_device.c
> [ ... ]
>> @@ -1476,36 +1526,40 @@ void xe_device_declare_wedged(struct xe_device *xe)
>> return;
>> }
>>
>> - if (!atomic_xchg(&xe->wedged.flag, 1)) {
>> - xe->needs_flr_on_fini = true;
>> - xe_pm_runtime_get_noresume(xe);
>> + mutex_lock(&xe->wedged.lock);
> [Severity: Critical]
> Can this cause a sleeping in atomic context panic?
>
> xe_device_declare_wedged() can be called from hard IRQ contexts, for
> example:
>
> xe_mert_irq_handler()
> mert_handle_cat_error()
> xe_device_declare_wedged()
>
> Since mutex_lock() can sleep, taking it here from an interrupt handler
> would lead to a scheduling while atomic regression.
>
> [ ... ]
>> diff --git a/drivers/gpu/drm/xe/xe_pci_error.c b/drivers/gpu/drm/xe/xe_pci_error.c
>> --- a/drivers/gpu/drm/xe/xe_pci_error.c
>> +++ b/drivers/gpu/drm/xe/xe_pci_error.c
>> @@ -25,8 +25,10 @@ static void prepare_device_for_reset(struct pci_dev *pdev)
>> * xe_device_wedged_fini() releases runtime pm if wedged flag is set, so acquire a runtime
>> * pm reference to avoid underflow.
>> */
>> - if (!atomic_xchg(&xe->wedged.flag, 1))
>> - xe_pm_runtime_get_noresume(xe);
>> + xe_device_wedged_get(xe);
>> +
>> + /* TODO: We shouldn't be doing such ugly hacks, reuse FLR helpers and drop this. */
>> + xe->wedged.perm = true;
> [Severity: High]
> Could this leak a reference and cause an assertion failure during device
> teardown if the device is already wedged?
>
> Unlike the old atomic_xchg code which checked if the device was already
> wedged, xe_device_wedged_get() increments the reference count unconditionally.
> If the device is already wedged from a previous event, the reference count
> will be incremented twice.
>
> During teardown, xe_device_wedged_fini() only drops a single reference
> when wedged.perm is true:
>
> drivers/gpu/drm/xe/xe_device.c:xe_device_wedged_fini() {
> if (xe->wedged.perm)
> xe_device_wedged_put(xe);
>
> xe_assert(xe, !xe_device_wedged(xe));
> }
>
> Will the second reference be left behind and trip the xe_assert() check?
> Also, should the state modification here be protected by xe->wedged.lock?
>
> [ ... ]
>> @@ -126,7 +128,7 @@ static pci_ers_result_t xe_pci_error_slot_reset(struct pci_dev *pdev)
>> xe = pdev_to_xe_device(pdev);
>>
>> /* Wedge the device to prevent I/O operations till the resume callback */
>> - atomic_set(&xe->wedged.flag, 1);
>> + xe_device_wedged_get(xe);
> [Severity: High]
> If the PCI error recovery aborts or fails here, and the device is subsequently
> unbound, will this leak the runtime PM reference?
>
> This code acquires a temporary wedged reference but does not set
> xe->wedged.perm to true. If the expected xe_pci_error_resume() is never
> called due to a recovery failure, xe_device_wedged_fini() will see
> xe->wedged.perm as false and skip dropping the reference, which would
> ultimately trigger the xe_assert(xe, !xe_device_wedged(xe)) on teardown.
>
next prev parent reply other threads:[~2026-08-24 14:30 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 11:23 [PATCH v10 00/10] Introduce Xe PCIe FLR Raag Jadav
2026-08-21 11:23 ` [PATCH v10 01/10] drm/xe/uc_fw: Allow re-initializing firmware Raag Jadav
2026-08-21 11:41 ` sashiko-bot
2026-08-21 11:23 ` [PATCH v10 02/10] drm/xe/guc_submit: Introduce guc_exec_queue_reinit_kernel() Raag Jadav
2026-08-21 11:52 ` sashiko-bot
2026-08-21 11:23 ` [PATCH v10 03/10] drm/xe/gt: Introduce FLR helpers Raag Jadav
2026-08-26 9:39 ` Tauro, Riana
2026-08-27 15:40 ` Raag Jadav
2026-08-21 11:23 ` [PATCH v10 04/10] drm/xe/bo_evict: Introduce xe_bo_restore_map() Raag Jadav
2026-08-21 11:23 ` [PATCH v10 05/10] drm/xe/exec_queue: Introduce xe_exec_queue_reinit() Raag Jadav
2026-08-21 11:43 ` sashiko-bot
2026-08-21 11:23 ` [PATCH v10 06/10] drm/xe/migrate: Introduce xe_migrate_reinit() Raag Jadav
2026-08-21 11:39 ` sashiko-bot
2026-08-21 11:23 ` [PATCH v10 07/10] drm/xe/pm: Introduce xe_device_suspend/resume() Raag Jadav
2026-08-21 11:43 ` sashiko-bot
2026-08-24 18:22 ` Rodrigo Vivi
2026-08-26 7:01 ` Raag Jadav
2026-08-21 11:23 ` [PATCH v10 08/10] drm/xe: Introduce temporary device wedging Raag Jadav
2026-08-21 11:37 ` sashiko-bot
2026-08-24 14:30 ` Laguna, Lukasz [this message]
2026-08-24 16:08 ` Raag Jadav
2026-08-24 18:29 ` Rodrigo Vivi
2026-08-25 7:41 ` Raag Jadav
2026-08-21 11:23 ` [PATCH v10 09/10] drm/xe/pci: Introduce PCIe Function Level Reset Raag Jadav
2026-08-21 11:39 ` sashiko-bot
2026-08-25 10:06 ` Laguna, Lukasz
2026-08-26 9:01 ` Raag Jadav
2026-08-26 9:52 ` Tauro, Riana
2026-08-26 11:38 ` Raag Jadav
2026-08-28 6:12 ` Tauro, Riana
2026-08-28 7:54 ` Raag Jadav
2026-08-21 11:23 ` [PATCH v10 10/10] drm/xe/doc: Wire up PCI Error Handling Raag Jadav
2026-08-21 11:31 ` ✗ CI.checkpatch: warning for Introduce Xe PCIe FLR (rev10) Patchwork
2026-08-21 11:33 ` ✓ CI.KUnit: success " Patchwork
2026-08-21 12:37 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-21 14:38 ` ✓ Xe.CI.FULL: " 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=45efbcf8-b598-463e-b415-dfee2a3afe66@intel.com \
--to=lukasz.laguna@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=raag.jadav@intel.com \
--cc=sashiko-reviews@lists.linux.dev \
/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