From: Philipp Stanner <phasta@mailbox.org>
To: "Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Gustavo Padovan" <gustavo@padovan.org>,
"Felix Kuehling" <Felix.Kuehling@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Huang Rui" <ray.huang@amd.com>,
"Matthew Auld" <matthew.auld@intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 2/8] dma-buf/dma-fence: Add dma_fence_check_and_signal()
Date: Mon, 01 Dec 2025 14:55:36 +0100 [thread overview]
Message-ID: <2a9c83b4a428bb3cc993499c39d0da01f9563278.camel@mailbox.org> (raw)
In-Reply-To: <80554ed2-4454-489b-873f-533d68c8d2ae@amd.com>
On Mon, 2025-12-01 at 14:23 +0100, Christian König wrote:
> On 12/1/25 11:50, Philipp Stanner wrote:
> > The overwhelming majority of users of dma_fence signaling functions
> > don't care about whether the fence had already been signaled by someone
> > else. Therefore, the return code shall be removed from those functions.
> >
> > For the few users who rely on the check, a new, specialized function
> > shall be provided.
> >
> > Add dma_fence_check_and_signal(), which signals a fence if it had not
> > yet been signaled, and informs the user about that.
> >
> > Add a counter part, dma_fence_check_and_signal_locked(), which doesn't
> > take the spinlock.
> >
> > Signed-off-by: Philipp Stanner <phasta@kernel.org>
> > ---
> > drivers/dma-buf/dma-fence.c | 44 +++++++++++++++++++++++++++++++++++++
> > include/linux/dma-fence.h | 2 ++
> > 2 files changed, 46 insertions(+)
> >
> > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> > index 96d72ffc0750..146de62887cf 100644
> > --- a/drivers/dma-buf/dma-fence.c
> > +++ b/drivers/dma-buf/dma-fence.c
> > @@ -445,6 +445,50 @@ int dma_fence_signal_locked(struct dma_fence *fence)
> > }
> > EXPORT_SYMBOL(dma_fence_signal_locked);
> >
> > +/**
> > + * dma_fence_check_and_signal_locked - signal the fence if it's not yet signaled
> > + * @fence: the fence to check and signal
> > + *
> > + * Checks whether a fence was signaled and signals it if it was not yet signaled.
> > + *
> > + * Unlike dma_fence_check_and_signal(), this function must be called with
> > + * &struct dma_fence.lock being held.
> > + *
> > + * Return: true if fence has been signaled already, false otherwise.
> > + */
> > +bool dma_fence_check_and_signal_locked(struct dma_fence *fence)
>
> I'm seriously considering to nuke all the unlocked variants of dma_fence functions and just make it mandatory for callers to grab the lock manually.
>
You mean "nuke the *locked* variants.
Why, though? Aren't they enough for most users?
I suppose you have all those subtle races in mind..
> > +{
> > + bool ret;
> > +
> > + ret = dma_fence_test_signaled_flag(fence);
> > + dma_fence_signal_locked(fence);
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL(dma_fence_check_and_signal_locked);
> > +
> > +/**
> > + * dma_fence_check_and_signal - signal the fence if it's not yet signaled
> > + * @fence: the fence to check and signal
> > + *
> > + * Checks whether a fence was signaled and signals it if it was not yet signaled.
> > + * All this is done in a race-free manner.
> > + *
> > + * Return: true if fence has been signaled already, false otherwise.
> > + */
> > +bool dma_fence_check_and_signal(struct dma_fence *fence)
>
> So I think we should name this one here dma_fence_check_and_signal_unlocked() and drop the postfix from the locked variant.
postfix?
Well, now, IDK. Can't we, for this series, keep the _locked() variant
so that it's congruent with all the other dma_fence code?
And then later if you want to force manual locking you can add that
kernel-wide in a separate series, since it'll be a discussion-worthy,
bigger chunk of work.
That's cleaner, and my series here won't prevent that once merged.
>
> > +{
> > + unsigned long flags;
> > + bool ret;
> > +
> > + spin_lock_irqsave(fence->lock, flags);
> > + ret = dma_fence_check_and_signal_locked(fence);
> > + spin_unlock_irqrestore(fence->lock, flags);
>
> Could this use guard(fence->lock, flags) ?
guard? You mean a lockdep guard? Do you have a pointer to someplace in
dma_fence who does what you mean / want?
P.
>
> Regards,
> Christian.
>
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL(dma_fence_check_and_signal);
> > +
> > /**
> > * dma_fence_signal - signal completion of a fence
> > * @fence: the fence to signal
> > diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
> > index 19972f5d176f..0504afe52c2a 100644
> > --- a/include/linux/dma-fence.h
> > +++ b/include/linux/dma-fence.h
> > @@ -365,6 +365,8 @@ static inline void __dma_fence_might_wait(void) {}
> > #endif
> >
> > int dma_fence_signal(struct dma_fence *fence);
> > +bool dma_fence_check_and_signal(struct dma_fence *fence);
> > +bool dma_fence_check_and_signal_locked(struct dma_fence *fence);
> > int dma_fence_signal_locked(struct dma_fence *fence);
> > int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp);
> > int dma_fence_signal_timestamp_locked(struct dma_fence *fence,
>
next prev parent reply other threads:[~2025-12-02 14:23 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 10:50 [PATCH 0/6] dma-fence: Remove return code of dma_fence_signal() et al Philipp Stanner
2025-12-01 10:50 ` [PATCH v2 1/8] dma-buf/dma-fence: Add dma_fence_test_signaled_flag() Philipp Stanner
2025-12-03 13:03 ` Christian König
2025-12-01 10:50 ` [PATCH v2 2/8] dma-buf/dma-fence: Add dma_fence_check_and_signal() Philipp Stanner
2025-12-01 13:23 ` Christian König
2025-12-01 13:55 ` Philipp Stanner [this message]
2025-12-01 15:20 ` Christian König
2025-12-01 15:34 ` Philipp Stanner
2025-12-01 16:06 ` Christian König
2025-12-01 15:53 ` Philipp Stanner
2025-12-01 16:08 ` Christian König
2025-12-02 9:19 ` Philipp Stanner
2025-12-03 13:05 ` Christian König
2025-12-01 10:50 ` [PATCH v2 3/8] amd/amdkfd: Use dma_fence_check_and_signal() Philipp Stanner
2025-12-01 15:21 ` Felix Kuehling
2025-12-03 13:10 ` Christian König
2025-12-01 10:50 ` [PATCH v2 4/8] drm/xe: Use dma_fence_check_and_signal_locked() Philipp Stanner
2025-12-01 19:38 ` Matthew Brost
2025-12-02 7:17 ` Philipp Stanner
2025-12-02 15:57 ` Matthew Brost
2025-12-02 20:47 ` Andi Shyti
2025-12-02 21:04 ` Matthew Brost
2025-12-03 21:13 ` Rodrigo Vivi
2025-12-03 13:14 ` Christian König
2025-12-01 10:50 ` [PATCH v2 5/8] dma-buf: Don't misuse dma_fence_signal() Philipp Stanner
2025-12-03 13:11 ` Christian König
2025-12-01 10:50 ` [PATCH v2 6/8] drm/ttm: Use dma_fence_check_and_signal() Philipp Stanner
2025-12-03 13:11 ` Christian König
2025-12-01 10:50 ` [PATCH v2 7/8] dma-buf/dma-fence: Remove return code of signaling-functions Philipp Stanner
2025-12-03 13:13 ` Christian König
2025-12-01 10:50 ` [PATCH v2 8/8] drm/xe: Use dma_fence_test_signaled_flag() Philipp Stanner
2025-12-01 19:33 ` Matthew Brost
2025-12-02 8:29 ` Philipp Stanner
2025-12-03 13:15 ` Christian König
2025-12-03 15:18 ` Philipp Stanner
2025-12-03 15:24 ` Christian König
2025-12-03 17:31 ` Matthew Brost
2025-12-03 21:12 ` Rodrigo Vivi
2025-12-04 14:10 ` [PATCH 0/6] dma-fence: Remove return code of dma_fence_signal() et al Philipp Stanner
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=2a9c83b4a428bb3cc993499c39d0da01f9563278.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo@padovan.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=phasta@kernel.org \
--cc=ray.huang@amd.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).