Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: SRINIVASAN SHANMUGAM <srinivasan.shanmugam@amd.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH v8 1/3] drm: Add drm_work_fence helper
Date: Wed, 9 Sep 2026 10:50:59 +0530	[thread overview]
Message-ID: <a57e8cd4-f664-4ab7-a702-52ab291f8112@amd.com> (raw)
In-Reply-To: <a7ad31f9-262a-4d85-b4d0-051b722147a8@amd.com>


On 9/9/2026 8:30 AM, SRINIVASAN SHANMUGAM wrote:
>
> On 9/9/2026 1:46 AM, Matthew Brost wrote:
>> On Tue, Sep 08, 2026 at 08:58:39AM +0000, sashiko-bot@kernel.org wrote:
>>
>> All of this looks right. So I believe the solution is:
>>
>> - s/cancel_work_/disable_work_
>> - In drm_work_fence_queue if queue_work returns false, call 
>> drm_work_fence_put()
>>
>> Matt
>
> Agreed — the race is real. Will fix in Patch 1
>
>    as you suggested:
>    - In drm_work_fence_queue: drop ref if queue_work returns false
>
>    - In drm_work_fence_cancel_sync: switch to disable_work_sync()

Hi Matt,

Sashiko flagged two more issues on v9 Patch 1 [1][2]:

In v9 we applied suggested fix:
- drm_work_fence_queue: drop ref if queue_work() returns false
- drm_work_fence_cancel_sync: switched to disable_work_sync()

However, Sashiko found two remaining problems:

1. ops->destroy() called in IRQ context:

    When the GPU fence signals, the callback runs. If queue_work()
    returns false (work already done or disabled), we call
    drm_work_fence_put() immediately — but we are inside an interrupt
    with IRQs disabled. If that drops the last ref, ops->destroy()
    runs in that interrupt context, which is not safe for drivers that
    sleep in destroy.

    Fix: instead of calling drm_work_fence_put() directly, post a
    small cleanup task via schedule_work() on system_wq. This ensures
    destroy() always runs in process context where sleeping is allowed.

2. disable_work_sync() still has a timing gap:

    The callback does two things in sequence:
      a. Removes itself from the fence list
      b. Calls queue_work()

    If driver teardown starts between (a) and (b), disable_work_sync()
    sees no pending work and returns immediately — teardown proceeds.
    The callback then calls queue_work() on an already-destroyed
    workqueue, causing a use-after-free.

    Fix: add an atomic flag. The callback sets the flag ON before (b)
    and OFF after. cancel_sync() waits until the flag is OFF before
    returning. This closes the gap between (a) and (b).

Are these approaches acceptable, or may I kno pls if do you have a 
preferred solution?

Also for Patch 3 — xe_sync_ufence_cancel() is now unused after v9
removed its only caller. Will remove it in v10.

[1] v9 Patch 1:
https://patchwork.freedesktop.org/patch/751979/?series=173582&rev=2

[2] Sashiko v9 review:
https://sashiko.dev/#/patchset/20260909044454.399340-1-srinivasan.shanmugam%40amd.com

Thanks,
Srini


  reply	other threads:[~2026-09-09  5:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  8:46 [PATCH v8 0/3] drm: Extract dma-fence-to-workqueue pattern into common helpers Srinivasan Shanmugam
2026-09-08  8:46 ` [PATCH v8 1/3] drm: Add drm_work_fence helper Srinivasan Shanmugam
2026-09-08  8:58   ` sashiko-bot
2026-09-08 20:16     ` Matthew Brost
2026-09-09  3:00       ` SRINIVASAN SHANMUGAM
2026-09-09  5:20         ` SRINIVASAN SHANMUGAM [this message]
2026-09-08  8:46 ` [PATCH v8 2/3] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-09-08  8:58   ` sashiko-bot
2026-09-08  8:46 ` [PATCH v8 3/3] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-09-08  9:00   ` sashiko-bot
2026-09-08 20:22   ` Matthew Brost
2026-09-09  3:04     ` SRINIVASAN SHANMUGAM
2026-09-08  9:48 ` ✗ CI.checkpatch: warning for drm: Extract dma-fence-to-workqueue pattern into common helpers Patchwork
2026-09-08  9:50 ` ✓ CI.KUnit: success " Patchwork
2026-09-08 10:27 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-08 13:25 ` ✗ Xe.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=a57e8cd4-f664-4ab7-a702-52ab291f8112@amd.com \
    --to=srinivasan.shanmugam@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=thomas.hellstrom@linux.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