Skip to contentSkip to conversation

lib: sbi: Clear all IPI devices when processing an IPI

PATCH In review Troy Mitchell 2 participants 4 messages Sep 8 – Sep 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: Clear all IPI devices when processing an IPI

Hart start sends wake-up IPIs through all registered IPI devices, but sbi_ipi_process() only clears the preferred device. A notification from another device can arrive after warm initialization has cleared it.

With both IMSIC and ACLINT MSWI, IMSIC is preferred and has no ipi_clear
callback: its interrupts are acknowledged through MTOPEI. A late ACLINT notification therefore leaves MSIP asserted, trapping the hart in the machine-mode interrupt handler and potentially timing out Linux CPU bring-up.

Clear all registered IPI devices before consuming the software IPI event bits so that late wake-up notifications are acknowledged too.

Fixes 94f0f8465622 ("lib: sbi: Extends sbi_ipi_raw_send() to use all available IPI devices")
---
 lib/sbi/sbi_ipi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/sbi/sbi_ipi.c +6 -1
index b04a5877..683d559d 100644
@@ -263,7 +263,12 @@ void sbi_ipi_process(void)
 			sbi_scratch_offset_ptr(scratch, ipi_data_off);
 
 	sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
-	sbi_ipi_raw_clear(false);
+	/*
+	 * A wake-up IPI is sent through all devices. A notification from a
+	 * non-preferred device can arrive after warm-boot initialization
+	 * cleared it, so acknowledge all devices when processing the IPI.
+	 */
+	sbi_ipi_raw_clear(true);
 
 	ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0);
 	ipi_event = 0;

---
base-commit: 3593a5facc4c6938b90429a6973ba9ee21fc5899
change-id: 20260908-ipi-clear-all-54c3def85689

Best regards,

Signature · 7 lines
Troy Mitchell <[email protected]>


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw

Hi Troy,

Quoted 24 lines · Troy Mitchell

Hart start sends wake-up IPIs through all registered IPI devices, but sbi_ipi_process() only clears the preferred device. A notification from another device can arrive after warm initialization has cleared it.

With both IMSIC and ACLINT MSWI, IMSIC is preferred and has no ipi_clear
callback: its interrupts are acknowledged through MTOPEI. A late ACLINT notification therefore leaves MSIP asserted, trapping the hart in the machine-mode interrupt handler and potentially timing out Linux CPU bring-up.

Clear all registered IPI devices before consuming the software IPI event bits so that late wake-up notifications are acknowledged too.

Fixes 94f0f8465622 ("lib: sbi: Extends sbi_ipi_raw_send() to use all available IPI devices")
---
  lib/sbi/sbi_ipi.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
lib/sbi/sbi_ipi.c +0 -0
index b04a5877..683d559d 100644

lib/sbi/sbi_ipi.c void sbi_ipi_process(void) · line 271

Quoted 10 lines
lib/sbi/sbi_ipi.c +6 -1
@@ -263,7 +263,12 @@ void sbi_ipi_process(void)
  			sbi_scratch_offset_ptr(scratch, ipi_data_off);
 
  	sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
-	sbi_ipi_raw_clear(false);
+	/*
+	 * A wake-up IPI is sent through all devices. A notification from a
+	 * non-preferred device can arrive after warm-boot initialization
+	 * cleared it, so acknowledge all devices when processing the IPI.
+	 */
+	sbi_ipi_raw_clear(true);

I feel like this is not the proper way to fix the issue. It introduces unnecessary overhead for *every* IPI processing, because you need to call clear on all IPI devices, even the non-preferred, inactive ones.

IMO, the "int sbi_ipi_raw_send(u32 hartindex, bool all_devices)" interface is a bad idea. It opened the door for such issues. AFAIK, the only reason such interface exists is that sometimes, some platform requires the use of a different IPI device during HSM kicking. E.g., some Sifive cores can't use imsic, but only aclint. Why not introduce another interface "int sbi_ipi_raw_send_safe(u32 hartindex)" just for this purpose? Then we can have a separate rating on how safe that IPI device could be for cold startup, and pick the right one in the function. E.g., favor clint over imsic for sbi_ipi_raw_send_safe.

In this way, we ensure that only 1 IPI is active at any given time, and ipi_process can still use sbi_ipi_raw_clear(false) to clear the preferred IPI device, and HSM/init code still does sbi_ipi_raw_clear(true). There'd be no more cases like Troy encountered, where IPI from another device arrives late, and you have no ideal way of dealing with it other than what Troy was proposing.

Let me test with this approach and prepare a patchset.

Quoted 8 lines
lib/sbi/sbi_ipi.c +0 -1
  	ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0);
  	ipi_event = 0;
 
---

base-commit: 3593a5facc4c6938b90429a6973ba9ee21fc5899
change-id: 20260908-ipi-clear-all-54c3def85689

Quoted 5 lines

Best regards,
--
Troy Mitchell <[email protected]>

Bo

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw

Hi Bo,

Quoted 52 lines · Bo Gan

Hi Troy,

Quoted 24 lines · Troy Mitchell

Hart start sends wake-up IPIs through all registered IPI devices, but sbi_ipi_process() only clears the preferred device. A notification from another device can arrive after warm initialization has cleared it.

With both IMSIC and ACLINT MSWI, IMSIC is preferred and has no ipi_clear
callback: its interrupts are acknowledged through MTOPEI. A late ACLINT notification therefore leaves MSIP asserted, trapping the hart in the machine-mode interrupt handler and potentially timing out Linux CPU bring-up.

Clear all registered IPI devices before consuming the software IPI event bits so that late wake-up notifications are acknowledged too.

Fixes 94f0f8465622 ("lib: sbi: Extends sbi_ipi_raw_send() to use all available IPI devices")
---
  lib/sbi/sbi_ipi.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
lib/sbi/sbi_ipi.c +0 -0
index b04a5877..683d559d 100644

lib/sbi/sbi_ipi.c void sbi_ipi_process(void) · line 271

Quoted 10 lines
lib/sbi/sbi_ipi.c +6 -1
@@ -263,7 +263,12 @@ void sbi_ipi_process(void)
  			sbi_scratch_offset_ptr(scratch, ipi_data_off);
 
  	sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
-	sbi_ipi_raw_clear(false);
+	/*
+	 * A wake-up IPI is sent through all devices. A notification from a
+	 * non-preferred device can arrive after warm-boot initialization
+	 * cleared it, so acknowledge all devices when processing the IPI.
+	 */
+	sbi_ipi_raw_clear(true);

I feel like this is not the proper way to fix the issue. It introduces unnecessary overhead for *every* IPI processing, because you need to call clear on all IPI devices, even the non-preferred, inactive ones.

IMO, the "int sbi_ipi_raw_send(u32 hartindex, bool all_devices)" interface is a bad idea. It opened the door for such issues. AFAIK, the only reason such interface exists is that sometimes, some platform requires the use of a different IPI device during HSM kicking. E.g., some Sifive cores can't use imsic, but only aclint. Why not introduce another interface "int sbi_ipi_raw_send_safe(u32 hartindex)" just for this purpose? Then we can have a separate rating on how safe that IPI device could be for cold startup, and pick the right one in the function. E.g., favor clint over imsic for sbi_ipi_raw_send_safe.

Quoted 8 lines

In this way, we ensure that only 1 IPI is active at any given time, and ipi_process can still use sbi_ipi_raw_clear(false) to clear the preferred IPI device, and HSM/init code still does sbi_ipi_raw_clear(true). There'd be no more cases like Troy encountered, where IPI from another device arrives late, and you have no ideal way of dealing with it other than what Troy was proposing.

Let me test with this approach and prepare a patchset.

Ok. wait for your feedback.

Signature · 1 line
Troy Mitchell
Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw

Just sent the patch. I've changed the function names slightly:

https://lore.kernel.org/opensbi/[email protected]/

Quoted 62 lines · Troy Mitchell

Hi Bo,

Quoted 59 lines · Bo Gan

Hi Troy,

Quoted 24 lines · Troy Mitchell

Hart start sends wake-up IPIs through all registered IPI devices, but sbi_ipi_process() only clears the preferred device. A notification from another device can arrive after warm initialization has cleared it.

With both IMSIC and ACLINT MSWI, IMSIC is preferred and has no ipi_clear
callback: its interrupts are acknowledged through MTOPEI. A late ACLINT notification therefore leaves MSIP asserted, trapping the hart in the machine-mode interrupt handler and potentially timing out Linux CPU bring-up.

Clear all registered IPI devices before consuming the software IPI event bits so that late wake-up notifications are acknowledged too.

Fixes 94f0f8465622 ("lib: sbi: Extends sbi_ipi_raw_send() to use all available IPI devices")
---
   lib/sbi/sbi_ipi.c | 7 ++++++-
   1 file changed, 6 insertions(+), 1 deletion(-)
lib/sbi/sbi_ipi.c +0 -0
index b04a5877..683d559d 100644

lib/sbi/sbi_ipi.c void sbi_ipi_process(void) · line 271

Quoted 10 lines
lib/sbi/sbi_ipi.c +6 -1
@@ -263,7 +263,12 @@ void sbi_ipi_process(void)
   			sbi_scratch_offset_ptr(scratch, ipi_data_off);
 
   	sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
-	sbi_ipi_raw_clear(false);
+	/*
+	 * A wake-up IPI is sent through all devices. A notification from a
+	 * non-preferred device can arrive after warm-boot initialization
+	 * cleared it, so acknowledge all devices when processing the IPI.
+	 */
+	sbi_ipi_raw_clear(true);

I feel like this is not the proper way to fix the issue. It introduces unnecessary overhead for *every* IPI processing, because you need to call clear on all IPI devices, even the non-preferred, inactive ones.

IMO, the "int sbi_ipi_raw_send(u32 hartindex, bool all_devices)" interface is a bad idea. It opened the door for such issues. AFAIK, the only reason such interface exists is that sometimes, some platform requires the use of a different IPI device during HSM kicking. E.g., some Sifive cores can't use imsic, but only aclint. Why not introduce another interface "int sbi_ipi_raw_send_safe(u32 hartindex)" just for this purpose? Then we can have a separate rating on how safe that IPI device could be for cold startup, and pick the right one in the function. E.g., favor clint over imsic for sbi_ipi_raw_send_safe.

In this way, we ensure that only 1 IPI is active at any given time, and ipi_process can still use sbi_ipi_raw_clear(false) to clear the preferred IPI device, and HSM/init code still does sbi_ipi_raw_clear(true). There'd be no more cases like Troy encountered, where IPI from another device arrives late, and you have no ideal way of dealing with it other than what Troy was proposing.

Quoted 3 lines
Quoted 1 line

Let me test with this approach and prepare a patchset.

Ok. wait for your feedback.

Bo

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi