From: Janne Grunau <j@jannau.net>
To: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Cc: Sasha Finkelstein <fnkl.kernel@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Neal Gompa <neal@gompa.dev>, Dmitry Baryshkov <lumag@kernel.org>,
dri-devel@lists.freedesktop.org, asahi@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors
Date: Thu, 17 Apr 2025 00:39:31 +0200 [thread overview]
Message-ID: <20250416223931.GC8400@robin.jannau.net> (raw)
In-Reply-To: <aAAZ6iIUtYcfpcdm@blossom>
On Wed, Apr 16, 2025 at 04:58:18PM -0400, Alyssa Rosenzweig wrote:
> > - spin_lock_irqsave(&crtc->dev->event_lock, flags);
> > if (crtc->state->event) {
> > - drm_crtc_vblank_get(crtc);
> > - adp->event = crtc->state->event;
> > + spin_lock_irqsave(&crtc->dev->event_lock, flags);
> > +
> > + if (drm_crtc_vblank_get(crtc) != 0)
> > + drm_crtc_send_vblank_event(crtc, crtc->state->event);
> > + else
> > + adp->event = crtc->state->event;
> > +
> > + spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
> > }
> > crtc->state->event = NULL;
> > - spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
>
> Kind of confused about
>
> > crtc->state->event = NULL;
>
> now being out of the lock. Should we set to NULL in the if, since
> if we don't take the if, we know event is already NULL? Or should we
> hold the lock for the whole time, the way the code did before your
> change? I'm not sure between the two, but the in-between here smells
> wrong.
I struggled with this as well. To my understanding event_lock is
necessary for drm_crtc_send_vblank_event(), adp->event and
drm_crtc_vblank_get(). The first according to event_lock's
documentation, the second to avoid avoid races with the irq handler and
the third to ensure vblank interrupts are not disabled.
Based on examples in other drivers I assumed `crtc->state->event` is
protected by another lock held externally. Not sure about that now. To
my understanding sruct drm_crtc::mutex protects `crtc->state`.
I did not move "crtc->state->event = NULL;" to avoid churn. No point
setting it to NULL if it is already NULL.
I'll look tomorrow if the locking for crtc->state->event is sufficient.
Janne
next prev parent reply other threads:[~2025-04-16 22:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 20:25 [PATCH 0/4] Apple Display Pipe driver fixes Janne Grunau via B4 Relay
2025-04-16 20:25 ` [PATCH 1/4] drm: adp: Use spin_lock_irqsave for drm device event_lock Janne Grunau via B4 Relay
2025-04-16 20:56 ` Alyssa Rosenzweig
2025-04-16 20:25 ` [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors Janne Grunau via B4 Relay
2025-04-16 20:58 ` Alyssa Rosenzweig
2025-04-16 22:39 ` Janne Grunau [this message]
2025-04-16 20:25 ` [PATCH 3/4] drm: adp: Enable vblank interrupts in crtc's .atomic_enable Janne Grunau via B4 Relay
2025-04-16 20:59 ` Alyssa Rosenzweig
2025-04-16 20:25 ` [PATCH 4/4] drm: adp: Remove pointless irq_lock spin lock Janne Grunau via B4 Relay
2025-04-16 20:59 ` Alyssa Rosenzweig
2025-04-16 20:54 ` [PATCH 0/4] Apple Display Pipe driver fixes Alyssa Rosenzweig
2025-04-16 22:04 ` Janne Grunau
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=20250416223931.GC8400@robin.jannau.net \
--to=j@jannau.net \
--cc=airlied@gmail.com \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=dri-devel@lists.freedesktop.org \
--cc=fnkl.kernel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=neal@gompa.dev \
--cc=simona@ffwll.ch \
--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