public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Apple Display Pipe driver fixes
@ 2025-04-16 20:25 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
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Janne Grunau via B4 Relay @ 2025-04-16 20:25 UTC (permalink / raw)
  To: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Alyssa Rosenzweig, Dmitry Baryshkov
  Cc: dri-devel, asahi, linux-kernel, Janne Grunau

While looking at a suspend issue in the Asahi downstream kernel I
noticed several issues in the the ADP driver. This series fixes those
issue.

The root cause of the issue was that the device is unexpectedly powered
down on suspend. The driver relies on initialization done by the boot
loader and can not bring the device up from reset. The change in [1]
annotates the power-domain as always on on devices with touchbars. This
is preferable to driver changes since keeps the device powered on if the
adpdrm module is not available during boot.

The device comes out of reset firing interrupts with a rate of 60Hz even
if vblank interrupts are disabled. This itself is not an issue.
The event_lock outside of the irq handler is locked with spin_lock()
resulting in a deadlock if the irq fires while the lock is held and
processed on the same CPU core. This happens eventually and results in a
soft-locked CPU. [Patch 1/4] "drm: adp: Use spin_lock_irqsave for drm
device event_lock" addresses this.

In addition I noticed that the driver does not use drm_crtc_vblank_on()
and instead enables HW vblank interrupts in probe(). This may have been
done to avoid errors from drm_crtc_vblank_get() after crtc reset. 
drm_crtc_vblank_reset() intentionally leaves struct drm_vblank_crtc in
state where drm_crtc_vblank_get() cannot enable vblank interrupts.
Handle this case explictly in [Patch 2/4] "drm: adp: Handle
drm_crtc_vblank_get() errors".

[Patch 3/4] "drm: adp: Enable vblank interrupts in crtc's
.atomic_enable" then uses the expected drm_crtc_vblank_on() call to
enable vblank interrupts.

[Patch 4/4] "drm: adp: Remove pointless irq_lock spinlock" removes an
unnecessary spinlock protecting the irq handler from itself.

[1] https://lore.kernel.org/asahi/20250416-arm64_dts_apple_touchbar-v1-1-e1c0b53b9125@jannau.net/

---
Janne Grunau (4):
      drm: adp: Use spin_lock_irqsave for drm device event_lock
      drm: adp: Handle drm_crtc_vblank_get() errors
      drm: adp: Enable vblank interrupts in crtc's .atomic_enable
      drm: adp: Remove pointless irq_lock spin lock

 drivers/gpu/drm/adp/adp_drv.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250416-drm_adp_fixes-1abfd4edecfe

Best regards,
-- 
Janne Grunau <j@jannau.net>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] drm: adp: Use spin_lock_irqsave for drm device event_lock
  2025-04-16 20:25 [PATCH 0/4] Apple Display Pipe driver fixes Janne Grunau via B4 Relay
@ 2025-04-16 20:25 ` 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
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Janne Grunau via B4 Relay @ 2025-04-16 20:25 UTC (permalink / raw)
  To: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Alyssa Rosenzweig, Dmitry Baryshkov
  Cc: dri-devel, asahi, linux-kernel, Janne Grunau

From: Janne Grunau <j@jannau.net>

The lock is used in the interrupt handler so use spin_lock_irqsave to
disable interrupts and avoid deadlocks with the irq handler.

Fixes: 332122eba628 ("drm: adp: Add Apple Display Pipe driver")
Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/gpu/drm/adp/adp_drv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
index c98c647f981d5383149647126762a5cdec8f4e4b..157298a8ff42b95275411dd4a7a0c70780fd86fd 100644
--- a/drivers/gpu/drm/adp/adp_drv.c
+++ b/drivers/gpu/drm/adp/adp_drv.c
@@ -310,6 +310,7 @@ static void adp_crtc_atomic_flush(struct drm_crtc *crtc,
 				  struct drm_atomic_state *state)
 {
 	u32 frame_num = 1;
+	unsigned long flags;
 	struct adp_drv_private *adp = crtc_to_adp(crtc);
 	struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
 	u64 new_size = ALIGN(new_state->mode.hdisplay *
@@ -330,13 +331,13 @@ static void adp_crtc_atomic_flush(struct drm_crtc *crtc,
 	}
 	writel(ADBE_FIFO_SYNC | frame_num, adp->be + ADBE_FIFO);
 	//FIXME: use adbe flush interrupt
-	spin_lock_irq(&crtc->dev->event_lock);
+	spin_lock_irqsave(&crtc->dev->event_lock, flags);
 	if (crtc->state->event) {
 		drm_crtc_vblank_get(crtc);
 		adp->event = crtc->state->event;
 	}
 	crtc->state->event = NULL;
-	spin_unlock_irq(&crtc->dev->event_lock);
+	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 }
 
 static const struct drm_crtc_funcs adp_crtc_funcs = {

-- 
2.49.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors
  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:25 ` Janne Grunau via B4 Relay
  2025-04-16 20:58   ` Alyssa Rosenzweig
  2025-04-16 20:25 ` [PATCH 3/4] drm: adp: Enable vblank interrupts in crtc's .atomic_enable Janne Grunau via B4 Relay
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Janne Grunau via B4 Relay @ 2025-04-16 20:25 UTC (permalink / raw)
  To: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Alyssa Rosenzweig, Dmitry Baryshkov
  Cc: dri-devel, asahi, linux-kernel, Janne Grunau

From: Janne Grunau <j@jannau.net>

drm_crtc_vblank_get() may fail when it's called before
drm_crtc_vblank_on() on a resetted CRTC. This occurs in
drm_crtc_helper_funcs' atomic_flush() calls after
drm_atomic_helper_crtc_reset() for example directly after probe.
Send the vblank event directly in such cases.
Avoids following warning in the subsequent drm_crtc_vblank_put() call
from the vblank irq handler as below:

adp 228200000.display-pipe: [drm] drm_WARN_ON(atomic_read(&vblank->refcount) == 0)
WARNING: CPU: 5 PID: 1206 at drivers/gpu/drm/drm_vblank.c:1247 drm_vblank_put+0x158/0x170
Modules linked in: uinput nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat videodev drm_dma_helper mc apple_soc_cpufreq drm_display_helper leds_pwm phram
CPU: 5 UID: 0 PID: 1206 Comm: systemctl Not tainted 6.14.2-asahi+ #asahi-dev
Hardware name: Apple MacBook Pro (13-inch, M2, 2022) (DT)
pstate: 614000c5 (nZCv daIF +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
pc : drm_vblank_put+0x158/0x170
lr : drm_vblank_put+0x158/0x170
sp : ffffc00082aa7e70
x29: ffffc00082aa7e70 x28: ffff80003419e000 x27: ffff80003419e000
x26: 0000000000000001 x25: 0000000000012400 x24: 0000000000000066
x23: ffff800033fc8800 x22: 0000000000000000 x21: ffff800029688e70
x20: ffff800029688000 x19: ffff800029688000 x18: 0000000000000000
x17: ffffc0015c868000 x16: 0000000000000020 x15: 0000000000000004
x14: 0000000000000000 x13: 0000000000000001 x12: ffffc000825b3a90
x11: ffffc00082960e88 x10: ffffc00081b0ec88 x9 : ffffc0008017d0ec
x8 : 000000000002ffe8 x7 : fefefefefefefefe x6 : ffffc00081bbec88
x5 : ffff8001de237548 x4 : 0000000000000000 x3 : ffffc0015c868000
x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff80003419e000
Call trace:
 drm_vblank_put+0x158/0x170 (P)
 drm_crtc_vblank_put+0x24/0x38
 adp_fe_irq+0xd8/0xe8 [adpdrm]
 __handle_irq_event_percpu+0x94/0x318
 handle_irq_event+0x54/0xd0
 handle_fasteoi_irq+0xa8/0x240
 handle_irq_desc+0x3c/0x68
 generic_handle_domain_irq+0x24/0x40

Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/gpu/drm/adp/adp_drv.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
index 157298a8ff42b95275411dd4a7a0c70780fd86fd..27119acac92238858d58a690eb4196dbb2ae0c1a 100644
--- a/drivers/gpu/drm/adp/adp_drv.c
+++ b/drivers/gpu/drm/adp/adp_drv.c
@@ -331,13 +331,17 @@ static void adp_crtc_atomic_flush(struct drm_crtc *crtc,
 	}
 	writel(ADBE_FIFO_SYNC | frame_num, adp->be + ADBE_FIFO);
 	//FIXME: use adbe flush interrupt
-	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);
 }
 
 static const struct drm_crtc_funcs adp_crtc_funcs = {

-- 
2.49.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] drm: adp: Enable vblank interrupts in crtc's .atomic_enable
  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:25 ` [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors Janne Grunau via B4 Relay
@ 2025-04-16 20:25 ` 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:54 ` [PATCH 0/4] Apple Display Pipe driver fixes Alyssa Rosenzweig
  4 siblings, 1 reply; 12+ messages in thread
From: Janne Grunau via B4 Relay @ 2025-04-16 20:25 UTC (permalink / raw)
  To: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Alyssa Rosenzweig, Dmitry Baryshkov
  Cc: dri-devel, asahi, linux-kernel, Janne Grunau

From: Janne Grunau <j@jannau.net>

Calling drm_crtc_vblank_on() drm_crtc_helper_funcs' atomic_enable is
expected to enable vblank interrupts. It may have been avoided here to
due to drm_crtc_vblank_get()'s error behavior after
drm_crtc_vblank_reset(). With that fixed in the preceding change the
driver can call drm_crtc_vblank_on() from adp_crtc_atomic_enable().

Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/gpu/drm/adp/adp_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
index 27119acac92238858d58a690eb4196dbb2ae0c1a..c6238fb059342eebafddd53650a499fea0079dea 100644
--- a/drivers/gpu/drm/adp/adp_drv.c
+++ b/drivers/gpu/drm/adp/adp_drv.c
@@ -288,6 +288,7 @@ static void adp_crtc_atomic_enable(struct drm_crtc *crtc,
 	writel(BIT(0), adp->be + ADBE_BLEND_EN3);
 	writel(BIT(0), adp->be + ADBE_BLEND_BYPASS);
 	writel(BIT(0), adp->be + ADBE_BLEND_EN4);
+	drm_crtc_vblank_on(crtc);
 }
 
 static void adp_crtc_atomic_disable(struct drm_crtc *crtc,
@@ -517,8 +518,7 @@ static int adp_drm_bind(struct device *dev)
 	struct adp_drv_private *adp = to_adp(drm);
 	int err;
 
-	adp_disable_vblank(adp);
-	writel(ADP_CTRL_FIFO_ON | ADP_CTRL_VBLANK_ON, adp->fe + ADP_CTRL);
+	writel(ADP_CTRL_FIFO_ON, adp->fe + ADP_CTRL);
 
 	adp->next_bridge = drmm_of_get_bridge(&adp->drm, dev->of_node, 0, 0);
 	if (IS_ERR(adp->next_bridge)) {

-- 
2.49.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] drm: adp: Remove pointless irq_lock spin lock
  2025-04-16 20:25 [PATCH 0/4] Apple Display Pipe driver fixes Janne Grunau via B4 Relay
                   ` (2 preceding siblings ...)
  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:25 ` 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
  4 siblings, 1 reply; 12+ messages in thread
From: Janne Grunau via B4 Relay @ 2025-04-16 20:25 UTC (permalink / raw)
  To: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Alyssa Rosenzweig, Dmitry Baryshkov
  Cc: dri-devel, asahi, linux-kernel, Janne Grunau

From: Janne Grunau <j@jannau.net>

Interrupt handlers run with interrupts disabled so it is not necessary
to protect them against reentrancy.

Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/gpu/drm/adp/adp_drv.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
index c6238fb059342eebafddd53650a499fea0079dea..abb42f57fe5984a8f0f4be7081fb6803866b5d5b 100644
--- a/drivers/gpu/drm/adp/adp_drv.c
+++ b/drivers/gpu/drm/adp/adp_drv.c
@@ -121,7 +121,6 @@ struct adp_drv_private {
 	dma_addr_t mask_iova;
 	int be_irq;
 	int fe_irq;
-	spinlock_t irq_lock;
 	struct drm_pending_vblank_event *event;
 };
 
@@ -488,8 +487,6 @@ static irqreturn_t adp_fe_irq(int irq, void *arg)
 	u32 int_status;
 	u32 int_ctl;
 
-	spin_lock(&adp->irq_lock);
-
 	int_status = readl(adp->fe + ADP_INT_STATUS);
 	if (int_status & ADP_INT_STATUS_VBLANK) {
 		drm_crtc_handle_vblank(&adp->crtc);
@@ -507,7 +504,6 @@ static irqreturn_t adp_fe_irq(int irq, void *arg)
 
 	writel(int_status, adp->fe + ADP_INT_STATUS);
 
-	spin_unlock(&adp->irq_lock);
 
 	return IRQ_HANDLED;
 }
@@ -572,8 +568,6 @@ static int adp_probe(struct platform_device *pdev)
 	if (IS_ERR(adp))
 		return PTR_ERR(adp);
 
-	spin_lock_init(&adp->irq_lock);
-
 	dev_set_drvdata(&pdev->dev, &adp->drm);
 
 	err = adp_parse_of(pdev, adp);

-- 
2.49.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] Apple Display Pipe driver fixes
  2025-04-16 20:25 [PATCH 0/4] Apple Display Pipe driver fixes Janne Grunau via B4 Relay
                   ` (3 preceding siblings ...)
  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:54 ` Alyssa Rosenzweig
  2025-04-16 22:04   ` Janne Grunau
  4 siblings, 1 reply; 12+ messages in thread
From: Alyssa Rosenzweig @ 2025-04-16 20:54 UTC (permalink / raw)
  To: j
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

> This is preferable to driver changes since keeps the device powered on
> if the adpdrm module is not available during boot.

Struggling to parse this sentence, do you mean to say:

> Driver changes are preferred, since that patch keeps the device
> powered on if the adpdrm module is not available during boot.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/4] drm: adp: Use spin_lock_irqsave for drm device event_lock
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Alyssa Rosenzweig @ 2025-04-16 20:56 UTC (permalink / raw)
  To: j
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Le Wed , Apr 16, 2025 at 10:25:27PM +0200, Janne Grunau via B4 Relay a écrit :
> From: Janne Grunau <j@jannau.net>
> 
> The lock is used in the interrupt handler so use spin_lock_irqsave to
> disable interrupts and avoid deadlocks with the irq handler.
> 
> Fixes: 332122eba628 ("drm: adp: Add Apple Display Pipe driver")
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---
>  drivers/gpu/drm/adp/adp_drv.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
> index c98c647f981d5383149647126762a5cdec8f4e4b..157298a8ff42b95275411dd4a7a0c70780fd86fd 100644
> --- a/drivers/gpu/drm/adp/adp_drv.c
> +++ b/drivers/gpu/drm/adp/adp_drv.c
> @@ -310,6 +310,7 @@ static void adp_crtc_atomic_flush(struct drm_crtc *crtc,
>  				  struct drm_atomic_state *state)
>  {
>  	u32 frame_num = 1;
> +	unsigned long flags;
>  	struct adp_drv_private *adp = crtc_to_adp(crtc);
>  	struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
>  	u64 new_size = ALIGN(new_state->mode.hdisplay *
> @@ -330,13 +331,13 @@ static void adp_crtc_atomic_flush(struct drm_crtc *crtc,
>  	}
>  	writel(ADBE_FIFO_SYNC | frame_num, adp->be + ADBE_FIFO);
>  	//FIXME: use adbe flush interrupt
> -	spin_lock_irq(&crtc->dev->event_lock);
> +	spin_lock_irqsave(&crtc->dev->event_lock, flags);
>  	if (crtc->state->event) {
>  		drm_crtc_vblank_get(crtc);
>  		adp->event = crtc->state->event;
>  	}
>  	crtc->state->event = NULL;
> -	spin_unlock_irq(&crtc->dev->event_lock);
> +	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
>  }
>  
>  static const struct drm_crtc_funcs adp_crtc_funcs = {
> 
> -- 
> 2.49.0
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Alyssa Rosenzweig @ 2025-04-16 20:58 UTC (permalink / raw)
  To: j
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

> -	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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] drm: adp: Enable vblank interrupts in crtc's .atomic_enable
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Alyssa Rosenzweig @ 2025-04-16 20:59 UTC (permalink / raw)
  To: j
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Le Wed , Apr 16, 2025 at 10:25:29PM +0200, Janne Grunau via B4 Relay a écrit :
> From: Janne Grunau <j@jannau.net>
> 
> Calling drm_crtc_vblank_on() drm_crtc_helper_funcs' atomic_enable is
> expected to enable vblank interrupts. It may have been avoided here to
> due to drm_crtc_vblank_get()'s error behavior after
> drm_crtc_vblank_reset(). With that fixed in the preceding change the
> driver can call drm_crtc_vblank_on() from adp_crtc_atomic_enable().
> 
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---
>  drivers/gpu/drm/adp/adp_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
> index 27119acac92238858d58a690eb4196dbb2ae0c1a..c6238fb059342eebafddd53650a499fea0079dea 100644
> --- a/drivers/gpu/drm/adp/adp_drv.c
> +++ b/drivers/gpu/drm/adp/adp_drv.c
> @@ -288,6 +288,7 @@ static void adp_crtc_atomic_enable(struct drm_crtc *crtc,
>  	writel(BIT(0), adp->be + ADBE_BLEND_EN3);
>  	writel(BIT(0), adp->be + ADBE_BLEND_BYPASS);
>  	writel(BIT(0), adp->be + ADBE_BLEND_EN4);
> +	drm_crtc_vblank_on(crtc);
>  }
>  
>  static void adp_crtc_atomic_disable(struct drm_crtc *crtc,
> @@ -517,8 +518,7 @@ static int adp_drm_bind(struct device *dev)
>  	struct adp_drv_private *adp = to_adp(drm);
>  	int err;
>  
> -	adp_disable_vblank(adp);
> -	writel(ADP_CTRL_FIFO_ON | ADP_CTRL_VBLANK_ON, adp->fe + ADP_CTRL);
> +	writel(ADP_CTRL_FIFO_ON, adp->fe + ADP_CTRL);
>  
>  	adp->next_bridge = drmm_of_get_bridge(&adp->drm, dev->of_node, 0, 0);
>  	if (IS_ERR(adp->next_bridge)) {
> 
> -- 
> 2.49.0
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] drm: adp: Remove pointless irq_lock spin lock
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Alyssa Rosenzweig @ 2025-04-16 20:59 UTC (permalink / raw)
  To: j
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Le Wed , Apr 16, 2025 at 10:25:30PM +0200, Janne Grunau via B4 Relay a écrit :
> From: Janne Grunau <j@jannau.net>
> 
> Interrupt handlers run with interrupts disabled so it is not necessary
> to protect them against reentrancy.
> 
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---
>  drivers/gpu/drm/adp/adp_drv.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/adp/adp_drv.c b/drivers/gpu/drm/adp/adp_drv.c
> index c6238fb059342eebafddd53650a499fea0079dea..abb42f57fe5984a8f0f4be7081fb6803866b5d5b 100644
> --- a/drivers/gpu/drm/adp/adp_drv.c
> +++ b/drivers/gpu/drm/adp/adp_drv.c
> @@ -121,7 +121,6 @@ struct adp_drv_private {
>  	dma_addr_t mask_iova;
>  	int be_irq;
>  	int fe_irq;
> -	spinlock_t irq_lock;
>  	struct drm_pending_vblank_event *event;
>  };
>  
> @@ -488,8 +487,6 @@ static irqreturn_t adp_fe_irq(int irq, void *arg)
>  	u32 int_status;
>  	u32 int_ctl;
>  
> -	spin_lock(&adp->irq_lock);
> -
>  	int_status = readl(adp->fe + ADP_INT_STATUS);
>  	if (int_status & ADP_INT_STATUS_VBLANK) {
>  		drm_crtc_handle_vblank(&adp->crtc);
> @@ -507,7 +504,6 @@ static irqreturn_t adp_fe_irq(int irq, void *arg)
>  
>  	writel(int_status, adp->fe + ADP_INT_STATUS);
>  
> -	spin_unlock(&adp->irq_lock);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -572,8 +568,6 @@ static int adp_probe(struct platform_device *pdev)
>  	if (IS_ERR(adp))
>  		return PTR_ERR(adp);
>  
> -	spin_lock_init(&adp->irq_lock);
> -
>  	dev_set_drvdata(&pdev->dev, &adp->drm);
>  
>  	err = adp_parse_of(pdev, adp);
> 
> -- 
> 2.49.0
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] Apple Display Pipe driver fixes
  2025-04-16 20:54 ` [PATCH 0/4] Apple Display Pipe driver fixes Alyssa Rosenzweig
@ 2025-04-16 22:04   ` Janne Grunau
  0 siblings, 0 replies; 12+ messages in thread
From: Janne Grunau @ 2025-04-16 22:04 UTC (permalink / raw)
  To: Alyssa Rosenzweig
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

On Wed, Apr 16, 2025 at 04:54:38PM -0400, Alyssa Rosenzweig wrote:
> > This is preferable to driver changes since keeps the device powered on
> > if the adpdrm module is not available during boot.
> 
> Struggling to parse this sentence, do you mean to say:
> 
> > Driver changes are preferred, since that patch keeps the device
> > powered on if the adpdrm module is not available during boot.

no. The sentence misses "it" between "since" and "keeps". I meant to say
that the linked devicetree change is preferable. A hypothetical
adp_drv.c change to keep the power-domain during s2idle only works if
the driver is loaded.

The changes in this series (especially Patch 1/4) just prevent the
soft-locked CPU after resume. The touch bar display won't display
anything.

Janne

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/4] drm: adp: Handle drm_crtc_vblank_get() errors
  2025-04-16 20:58   ` Alyssa Rosenzweig
@ 2025-04-16 22:39     ` Janne Grunau
  0 siblings, 0 replies; 12+ messages in thread
From: Janne Grunau @ 2025-04-16 22:39 UTC (permalink / raw)
  To: Alyssa Rosenzweig
  Cc: Sasha Finkelstein, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Neal Gompa,
	Dmitry Baryshkov, dri-devel, asahi, linux-kernel

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-04-16 22:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox