sbi: add check for ipi device for hsm start
PATCH 1/1 sbi: add check for ipi device for hsm start
If the ecall SBI_EXT_HSM_HART_START is called it might try to wake the secondary hart using sbi_ipi_raw_send() to send an IPI to the hart. This can fail if there is no IPI device but no error is returned from sbi_ipi_raw_send() so the ecall returns as if the action completed and the caller continues without noticing (in the case of Linux it just hangs waiting for the secondary hart to become active)
Fix this by changing sbi_ipi_raw_send() to return and error, and if an error is returned, then return it via SBI_EXT_HSM_HART_START call.
--- include/sbi/sbi_ipi.h | 2 +- lib/sbi/sbi_hsm.c | 4 +++- lib/sbi/sbi_ipi.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-)
include/sbi/sbi_ipi.h +1 -1
@@ -75,7 +75,7 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase);void sbi_ipi_process (void ); -void sbi_ipi_raw_send (u32 target_hart); +int sbi_ipi_raw_send (u32 target_hart);const struct sbi_ipi_device *sbi_ipi_get_device (void );
lib/sbi/sbi_hsm.c +3 -1
@@ -289,7 +289,9 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, (hsm_device_has_hart_secondary_boot() && !init_count)) { return hsm_device_hart_start(hartid, scratch->warmboot_addr); } else { -sbi_ipi_raw_send (hartid); +int rc =sbi_ipi_raw_send (hartid); +if (rc) +return rc; }return 0 ;
lib/sbi/sbi_ipi.c +8 -3
@@ -208,10 +208,15 @@ skip: }; } -void sbi_ipi_raw_send (u32 target_hart) +int sbi_ipi_raw_send (u32 target_hart) { -if (ipi_dev && ipi_dev->ipi_send) - ipi_dev->ipi_send (target_hart); +if (!ipi_dev) +return SBI_EINVAL ; +if (!ipi_dev->ipi_send) +return SBI_EINVAL ; + + ipi_dev->ipi_send (target_hart); +return 0 ; }const struct sbi_ipi_device *sbi_ipi_get_device (void )
Signature · 1 line
2.35.1
PATCH 1/1 sbi: add check for ipi device for hsm start
Quoted 8 lines · Ben Dooks
If the ecall
SBI_EXT_HSM_HART_STARTis called it might try to wake the secondary hart usingsbi_ipi_raw_send()to send an IPI to the hart. This can fail if there is no IPI device but no error is returned fromsbi_ipi_raw_send()so the ecall returns as if the action completed and the caller continues without noticing (in the case of Linux it just hangs waiting for the secondary hart to become active)
Quoted 4 lines
Fix this by changing
sbi_ipi_raw_send()to return and error, and if an error is returned, then return it viaSBI_EXT_HSM_HART_STARTcall.Signed-off-by Ben Dooks <[email protected]>
For consistency use "lib: sbi:" as patch subject prefix.
Quoted 41 lines
--- include/sbi/sbi_ipi.h | 2 +- lib/sbi/sbi_hsm.c | 4 +++- lib/sbi/sbi_ipi.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-)include/sbi/sbi_ipi.h +1
-1@@ -75,7 +75,7 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase);void sbi_ipi_process (void ); -void sbi_ipi_raw_send (u32 target_hart); +int sbi_ipi_raw_send (u32 target_hart);const struct sbi_ipi_device *sbi_ipi_get_device (void );lib/sbi/sbi_hsm.c +3
-1@@ -289,7 +289,9 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, (hsm_device_has_hart_secondary_boot() && !init_count)) { return hsm_device_hart_start(hartid, scratch->warmboot_addr); } else { -sbi_ipi_raw_send (hartid); +int rc =sbi_ipi_raw_send (hartid); +if (rc) +return rc; }return 0 ;lib/sbi/sbi_ipi.c +0
-0@@ -208,10 +208,15 @@ skip: }; }
lib/sbi/sbi_ipi.c skip: · line 216
Quoted 10 lines
lib/sbi/sbi_ipi.c +5
-3-void sbi_ipi_raw_send (u32 target_hart) +int sbi_ipi_raw_send (u32 target_hart) { -if (ipi_dev && ipi_dev->ipi_send) - ipi_dev->ipi_send (target_hart); +if (!ipi_dev) +return SBI_EINVAL ; +if (!ipi_dev->ipi_send) +return SBI_EINVAL ;
Instead of two separate "if ()" you can short-circuit into one "if ()" like below:
if (!ipi_dev || !ipi_dev->ipi_send)
return SBI_EINVAL;
Quoted 10 lines
lib/sbi/sbi_ipi.c +3
-1+ + ipi_dev->ipi_send (target_hart); +return 0 ; }const struct sbi_ipi_device *sbi_ipi_get_device (void ) --2.35.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Apart from minor comments above, this looks good to me.
Regards,
Anup
PATCH 1/1 sbi: add check for ipi device for hsm start
Quoted 9 lines · Anup Patel
Quoted 8 lines · Ben Dooks
If the ecall
SBI_EXT_HSM_HART_STARTis called it might try to wake the secondary hart usingsbi_ipi_raw_send()to send an IPI to the hart. This can fail if there is no IPI device but no error is returned fromsbi_ipi_raw_send()so the ecall returns as if the action completed and the caller continues without noticing (in the case of Linux it just hangs waiting for the secondary hart to become active)
Quoted 6 lines
Quoted 4 lines
Fix this by changing
sbi_ipi_raw_send()to return and error, and if an error is returned, then return it viaSBI_EXT_HSM_HART_STARTcall.Signed-off-by Ben Dooks <[email protected]>For consistency use "lib: sbi:" as patch subject prefix.
ok, will fix.
Quoted 55 lines
Quoted 41 lines
--- include/sbi/sbi_ipi.h | 2 +- lib/sbi/sbi_hsm.c | 4 +++- lib/sbi/sbi_ipi.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-)include/sbi/sbi_ipi.h +1
-1@@ -75,7 +75,7 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase);void sbi_ipi_process (void ); -void sbi_ipi_raw_send (u32 target_hart); +int sbi_ipi_raw_send (u32 target_hart);const struct sbi_ipi_device *sbi_ipi_get_device (void );lib/sbi/sbi_hsm.c +3
-1@@ -289,7 +289,9 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, (hsm_device_has_hart_secondary_boot() && !init_count)) { return hsm_device_hart_start(hartid, scratch->warmboot_addr); } else { -sbi_ipi_raw_send (hartid); +int rc =sbi_ipi_raw_send (hartid); +if (rc) +return rc; }return 0 ;lib/sbi/sbi_ipi.c +0
-0@@ -208,10 +208,15 @@ skip: }; }lib/sbi/sbi_ipi.c skip: · line 216
Quoted 10 lines
lib/sbi/sbi_ipi.c +5
-3-void sbi_ipi_raw_send (u32 target_hart) +int sbi_ipi_raw_send (u32 target_hart) { -if (ipi_dev && ipi_dev->ipi_send) - ipi_dev->ipi_send (target_hart); +if (!ipi_dev) +return SBI_EINVAL ; +if (!ipi_dev->ipi_send) +return SBI_EINVAL ;Instead of two separate "if ()" you can short-circuit into one "if ()" like below:
Quoted 2 lines
if (!ipi_dev || !ipi_dev->ipi_send)
return SBI_EINVAL;
ok, fixed.
I really don't like compound if statements like this, but will sort out.
Quoted 15 lines
Quoted 10 lines
lib/sbi/sbi_ipi.c +3
-1+ + ipi_dev->ipi_send (target_hart); +return 0 ; }const struct sbi_ipi_device *sbi_ipi_get_device (void ) --2.35.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 7 lines
Apart from minor comments above, this looks good to me.
Reviewed-by Anup Patel <[email protected]>Regards,
Anup
I'll repost this Monday.