Skip to contentSkip to conversation

irqchip/stm32mp-exti: fix the unit of the hwspinlock timeout

PATCH Superseded Ju Nan 5 participants 8 messages Aug 5 – Sep 4

Subsystems (3)
lore
Share & tools
lore

Ju Nan

author
#0 lore raw

PATCH 1/1 irqchip/stm32mp-exti: fix the unit of the hwspinlock timeout

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Pass the value the comment always described. The core retries every HWSPINLOCK_RETRY_DELAY_US (100 us), so the semaphore is still polled ten times before giving up, which is far longer than any plausible hold time on the coprocessor side. A timeout is reported with pr_err() and fails the trigger type configuration, so shortening it degrades gracefully.

---
 drivers/irqchip/irq-stm32mp-exti.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-stm32mp-exti.c +1 -1
index a24f4f1a4..f5f0109bf 100644
@@ -23,7 +23,7 @@
 
 #define IRQS_PER_BANK			32
 
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT		1 /* msec */
 
 #define EXTI_EnCIDCFGR(n)		(0x180 + (n) * 4)
 #define EXTI_HWCFGR1			0x3f0
Signature · 1 line
2.55.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 40 lines · Ju Nan

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

  If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Pass the value the comment always described. The core retries every HWSPINLOCK_RETRY_DELAY_US (100 us), so the semaphore is still polled ten times before giving up, which is far longer than any plausible hold time on the coprocessor side. A timeout is reported with pr_err() and fails the trigger type configuration, so shortening it degrades gracefully.

---
 drivers/irqchip/irq-stm32mp-exti.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-stm32mp-exti.c +0 -0
index a24f4f1a4..f5f0109bf 100644
@@ -23,7 +23,7 @@


 #define IRQS_PER_BANK 32

drivers/irqchip/irq-stm32mp-exti.c +1 -1
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT		1 /* msec */
Quoted 3 lines


 #define EXTI_EnCIDCFGR(n) (0x180 + (n) * 4)
 #define EXTI_HWCFGR1 0x3f0

reviewer
#2 lore raw
Quoted 31 lines · Radu Rendec
Quoted 30 lines · Ju Nan

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

  If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Pass the value the comment always described. The core retries every HWSPINLOCK_RETRY_DELAY_US (100 us), so the semaphore is still polled ten times before giving up, which is far longer than any plausible hold time on the coprocessor side. A timeout is reported with pr_err() and fails the trigger type configuration, so shortening it degrades gracefully.

---
 drivers/irqchip/irq-stm32mp-exti.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 10 lines
drivers/irqchip/irq-stm32mp-exti.c +0 -0
index a24f4f1a4..f5f0109bf 100644
@@ -23,7 +23,7 @@


 #define IRQS_PER_BANK 32

drivers/irqchip/irq-stm32mp-exti.c +1 -1
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT		1 /* msec */
Quoted 3 lines


 #define EXTI_EnCIDCFGR(n) (0x180 + (n) * 4)
 #define EXTI_HWCFGR1 0x3f0

Oops! Hit the "send" button too soon. The patch is OK, so the r-b tag stays. But it also needs this:

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")
maintainer
#3 lore raw
Quoted 48 lines · Radu Rendec
Quoted 31 lines · Radu Rendec
Quoted 30 lines · Ju Nan

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

  If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Pass the value the comment always described. The core retries every HWSPINLOCK_RETRY_DELAY_US (100 us), so the semaphore is still polled ten times before giving up, which is far longer than any plausible hold time on the coprocessor side. A timeout is reported with pr_err() and fails the trigger type configuration, so shortening it degrades gracefully.

---
 drivers/irqchip/irq-stm32mp-exti.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 10 lines
drivers/irqchip/irq-stm32mp-exti.c +0 -0
index a24f4f1a4..f5f0109bf 100644
@@ -23,7 +23,7 @@


 #define IRQS_PER_BANK 32

drivers/irqchip/irq-stm32mp-exti.c +1 -1
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT		1 /* msec */
Quoted 3 lines


 #define EXTI_EnCIDCFGR(n) (0x180 + (n) * 4)
 #define EXTI_HWCFGR1 0x3f0

Quoted 4 lines

Oops! Hit the "send" button too soon. The patch is OK, so the r-b tag stays. But it also needs this:

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")

That's correct, but the real problem with that culprit commit is that it just used the existing HWSPNLCK_TIMEOUT define without looking what the units are, which in turn is a stupidity of the original code which picked the most generic naming convention for that define. That should have been:

#define HWSPNLCK_TIMEOUT_US 1000

which would have made it entirely clear what the unit is without the stupid tail comment.

Now this "fix" just proliferates the same stupidity instead of changing the define to:

#define HWSPNLCK_TIMEOUT_MS 1

No?

Ju, please send a V3 to that effect.

Thanks,

tglx

author
#4 lore raw

PATCH v3 1/1 irqchip/stm32mp-exti: fix the unit of the hwspinlock timeout

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")

---
changelog:

v3: redefine the timeout macro with time unit on it
v2: add "Fixes" tag suggested by Radu Rendec
v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/irqchip/irq-stm32mp-exti.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-stm32mp-exti.c +2 -2
index a24f4f1a4..ce4e03ee1 100644
@@ -23,7 +23,7 @@
 
 #define IRQS_PER_BANK			32
 
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT_MS		1
 
 #define EXTI_EnCIDCFGR(n)		(0x180 + (n) * 4)
 #define EXTI_HWCFGR1			0x3f0
@@ -377,7 +377,7 @@ static int stm32mp_exti_set_type(struct irq_data *d, unsigned int type)
 	raw_spin_lock(&chip_data->rlock);
 
 	if (hwlock) {
-		err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT);
+		err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT_MS);
 		if (err) {
 			pr_err("%s can't get hwspinlock (%d)\n", __func__, err);
 			goto unlock;
Signature · 1 line
2.55.0
Reviewed-by on v3 1/1
#5 lore raw
Quoted 47 lines · Ju Nan

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

  If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")

---
changelog:

v3: redefine the timeout macro with time unit on it
v2: add "Fixes" tag suggested by Radu Rendec
v1: https://lore.kernel.org/all/[email protected]/
---
 drivers/irqchip/irq-stm32mp-exti.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-stm32mp-exti.c +0 -0
index a24f4f1a4..ce4e03ee1 100644
@@ -23,7 +23,7 @@


 #define IRQS_PER_BANK                  32

drivers/irqchip/irq-stm32mp-exti.c +1 -1
-#define HWSPNLCK_TIMEOUT               1000 /* usec */
+#define HWSPNLCK_TIMEOUT_MS            1


 #define EXTI_EnCIDCFGR(n)              (0x180 + (n) * 4) #define EXTI_HWCFGR1                   0x3f0

drivers/irqchip/irq-stm32mp-exti.c +0 -0
@@ -377,7 +377,7 @@ static int stm32mp_exti_set_type(struct irq_data *d, unsigned int type)
         raw_spin_lock(&chip_data->rlock);
Quoted 7 lines


        if (hwlock) {
-               err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT); +               err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT_MS); if (err) {
                        pr_err("%s can't get hwspinlock (%d)\n", __func__, err); goto unlock;

Thanks!

merge bot Applied
#6 lore raw

[tip: irq/urgent] irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout

In reply to Ju Nan
The following commit has been merged into the irq/urgent branch of tip:

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     d31fbbade43f880b7e59e2b3a72722fe2725d93f
Gitweb:        https://git.kernel.org/tip/d31fbbade43f880b7e59e2b3a72722fe2725d93f
Author:        Ju Nan <[email protected]>
AuthorDate:    Fri, 21 Aug 2026 10:47:57 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 04 Sep 2026 16:19:04 +02:00

irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")
---
 drivers/irqchip/irq-stm32mp-exti.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-stm32mp-exti.c +2 -2
index bf3a2de..a19e91f 100644
@@ -22,7 +22,7 @@
 
 #define IRQS_PER_BANK			32
 
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT_MS		1
 
 #define EXTI_EnCIDCFGR(n)		(0x180 + (n) * 4)
 #define EXTI_HWCFGR1			0x3f0
@@ -376,7 +376,7 @@ static int stm32mp_exti_set_type(struct irq_data *d, unsigned int type)
 	raw_spin_lock(&chip_data->rlock);
 
 	if (hwlock) {
-		err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT);
+		err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT_MS);
 		if (err) {
 			pr_err("%s can't get hwspinlock (%d)\n", __func__, err);
 			goto unlock;
author
#7 lore raw

PATCH v2 1/1 irqchip/stm32mp-exti: fix the unit of the hwspinlock timeout

In reply to Ju Nan

HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:

  atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
  if (atomic_delay > to * 1000)
          return -ETIMEDOUT;

So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.

The hwspinlock core documents this explicitly:

If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.

Pass the value the comment always described. The core retries every HWSPINLOCK_RETRY_DELAY_US (100 us), so the semaphore is still polled ten times before giving up, which is far longer than any plausible hold time on the coprocessor side. A timeout is reported with pr_err() and fails the trigger type configuration, so shortening it degrades gracefully.

Fixes 5257169ade8c ("irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API")

---
changelog:

v2: Add Fixes tag suggested by Radu Rendec
v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/irqchip/irq-stm32mp-exti.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-stm32mp-exti.c +1 -1
index a24f4f1a4..f5f0109bf 100644
@@ -23,7 +23,7 @@
 
 #define IRQS_PER_BANK			32
 
-#define HWSPNLCK_TIMEOUT		1000 /* usec */
+#define HWSPNLCK_TIMEOUT		1 /* msec */
 
 #define EXTI_EnCIDCFGR(n)		(0x180 + (n) * 4)
 #define EXTI_HWCFGR1			0x3f0
Signature · 1 line
2.55.0