All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function
@ 2023-03-20 15:59 Anup Patel
  2023-03-20 15:59 ` [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug Anup Patel
  2023-04-06 13:19 ` [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel
  0 siblings, 2 replies; 4+ messages in thread
From: Anup Patel @ 2023-03-20 15:59 UTC (permalink / raw)
  To: opensbi

We introduce sbi_entry_count() function which counts the number
of times a HART enters OpenSBI via cold-boot or warm-boot path.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 include/sbi/sbi_init.h |  2 ++
 lib/sbi/sbi_init.c     | 42 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/include/sbi/sbi_init.h b/include/sbi/sbi_init.h
index 74eb1c0..9640fee 100644
--- a/include/sbi/sbi_init.h
+++ b/include/sbi/sbi_init.h
@@ -16,6 +16,8 @@ struct sbi_scratch;
 
 void __noreturn sbi_init(struct sbi_scratch *scratch);
 
+unsigned long sbi_entry_count(u32 hartid);
+
 unsigned long sbi_init_count(u32 hartid);
 
 void __noreturn sbi_exit(struct sbi_scratch *scratch);
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index ffa214c..f184248 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -238,12 +238,13 @@ static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
 	spin_unlock(&coldboot_lock);
 }
 
+static unsigned long entry_count_offset;
 static unsigned long init_count_offset;
 
 static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 {
 	int rc;
-	unsigned long *init_count;
+	unsigned long *count;
 	const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
 	/* Note: This has to be first thing in coldboot init sequence */
@@ -256,10 +257,17 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 	if (rc)
 		sbi_hart_hang();
 
+	entry_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
+	if (!entry_count_offset)
+		sbi_hart_hang();
+
 	init_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
 	if (!init_count_offset)
 		sbi_hart_hang();
 
+	count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
+	(*count)++;
+
 	rc = sbi_hsm_init(scratch, hartid, true);
 	if (rc)
 		sbi_hart_hang();
@@ -352,8 +360,8 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 
 	wake_coldboot_harts(scratch, hartid);
 
-	init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
-	(*init_count)++;
+	count = sbi_scratch_offset_ptr(scratch, init_count_offset);
+	(*count)++;
 
 	sbi_hsm_hart_start_finish(scratch, hartid);
 }
@@ -362,12 +370,15 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 					 u32 hartid)
 {
 	int rc;
-	unsigned long *init_count;
+	unsigned long *count;
 	const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
-	if (!init_count_offset)
+	if (!entry_count_offset || !init_count_offset)
 		sbi_hart_hang();
 
+	count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
+	(*count)++;
+
 	rc = sbi_hsm_init(scratch, hartid, false);
 	if (rc)
 		sbi_hart_hang();
@@ -408,8 +419,8 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 	if (rc)
 		sbi_hart_hang();
 
-	init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
-	(*init_count)++;
+	count = sbi_scratch_offset_ptr(scratch, init_count_offset);
+	(*count)++;
 
 	sbi_hsm_hart_start_finish(scratch, hartid);
 }
@@ -521,6 +532,23 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
 		init_warmboot(scratch, hartid);
 }
 
+unsigned long sbi_entry_count(u32 hartid)
+{
+	struct sbi_scratch *scratch;
+	unsigned long *entry_count;
+
+	if (!entry_count_offset)
+		return 0;
+
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch)
+		return 0;
+
+	entry_count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
+
+	return *entry_count;
+}
+
 unsigned long sbi_init_count(u32 hartid)
 {
 	struct sbi_scratch *scratch;
-- 
2.34.1



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

* [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug
  2023-03-20 15:59 [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel
@ 2023-03-20 15:59 ` Anup Patel
  2023-04-06 13:19   ` Anup Patel
  2023-04-06 13:19 ` [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel
  1 sibling, 1 reply; 4+ messages in thread
From: Anup Patel @ 2023-03-20 15:59 UTC (permalink / raw)
  To: opensbi

It possible that a platform supports hart hotplug (i.e. both hart_start
and hart_stop callbacks available) and all harts are start simultaneously
at platform boot-time. In this situation, the sbi_hsm_hart_start() will
call hsm_device_hart_start() for secondary harts at platform boot-time
which will fail because secondary harts were already started.

To fix above, we call hsm_device_hart_start() from sbi_hsm_hart_start()
only when entry_count is same as init_count for the secondary hart.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 lib/sbi/sbi_hsm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index 16e3846..b261410 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -301,7 +301,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
 		       const struct sbi_domain *dom,
 		       u32 hartid, ulong saddr, ulong smode, ulong arg1)
 {
-	unsigned long init_count;
+	unsigned long init_count, entry_count;
 	unsigned int hstate;
 	struct sbi_scratch *rscratch;
 	struct sbi_hsm_data *hdata;
@@ -325,6 +325,8 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
 		return SBI_EINVAL;
 
 	init_count = sbi_init_count(hartid);
+	entry_count = sbi_entry_count(hartid);
+
 	rscratch->next_arg1 = arg1;
 	rscratch->next_addr = saddr;
 	rscratch->next_mode = smode;
@@ -350,7 +352,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
 		goto err;
 	}
 
-	if (hsm_device_has_hart_hotplug() ||
+	if ((hsm_device_has_hart_hotplug() && (entry_count == init_count)) ||
 	   (hsm_device_has_hart_secondary_boot() && !init_count)) {
 		rc = hsm_device_hart_start(hartid, scratch->warmboot_addr);
 	} else {
-- 
2.34.1



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

* [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function
  2023-03-20 15:59 [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel
  2023-03-20 15:59 ` [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug Anup Patel
@ 2023-04-06 13:19 ` Anup Patel
  1 sibling, 0 replies; 4+ messages in thread
From: Anup Patel @ 2023-04-06 13:19 UTC (permalink / raw)
  To: opensbi

On Mon, Mar 20, 2023 at 9:29?PM Anup Patel <apatel@ventanamicro.com> wrote:
>
> We introduce sbi_entry_count() function which counts the number
> of times a HART enters OpenSBI via cold-boot or warm-boot path.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  include/sbi/sbi_init.h |  2 ++
>  lib/sbi/sbi_init.c     | 42 +++++++++++++++++++++++++++++++++++-------
>  2 files changed, 37 insertions(+), 7 deletions(-)
>
> diff --git a/include/sbi/sbi_init.h b/include/sbi/sbi_init.h
> index 74eb1c0..9640fee 100644
> --- a/include/sbi/sbi_init.h
> +++ b/include/sbi/sbi_init.h
> @@ -16,6 +16,8 @@ struct sbi_scratch;
>
>  void __noreturn sbi_init(struct sbi_scratch *scratch);
>
> +unsigned long sbi_entry_count(u32 hartid);
> +
>  unsigned long sbi_init_count(u32 hartid);
>
>  void __noreturn sbi_exit(struct sbi_scratch *scratch);
> diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> index ffa214c..f184248 100644
> --- a/lib/sbi/sbi_init.c
> +++ b/lib/sbi/sbi_init.c
> @@ -238,12 +238,13 @@ static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
>         spin_unlock(&coldboot_lock);
>  }
>
> +static unsigned long entry_count_offset;
>  static unsigned long init_count_offset;
>
>  static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>  {
>         int rc;
> -       unsigned long *init_count;
> +       unsigned long *count;
>         const struct sbi_platform *plat = sbi_platform_ptr(scratch);
>
>         /* Note: This has to be first thing in coldboot init sequence */
> @@ -256,10 +257,17 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>         if (rc)
>                 sbi_hart_hang();
>
> +       entry_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
> +       if (!entry_count_offset)
> +               sbi_hart_hang();
> +
>         init_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__);
>         if (!init_count_offset)
>                 sbi_hart_hang();
>
> +       count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
> +       (*count)++;
> +
>         rc = sbi_hsm_init(scratch, hartid, true);
>         if (rc)
>                 sbi_hart_hang();
> @@ -352,8 +360,8 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>
>         wake_coldboot_harts(scratch, hartid);
>
> -       init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
> -       (*init_count)++;
> +       count = sbi_scratch_offset_ptr(scratch, init_count_offset);
> +       (*count)++;
>
>         sbi_hsm_hart_start_finish(scratch, hartid);
>  }
> @@ -362,12 +370,15 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
>                                          u32 hartid)
>  {
>         int rc;
> -       unsigned long *init_count;
> +       unsigned long *count;
>         const struct sbi_platform *plat = sbi_platform_ptr(scratch);
>
> -       if (!init_count_offset)
> +       if (!entry_count_offset || !init_count_offset)
>                 sbi_hart_hang();
>
> +       count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
> +       (*count)++;
> +
>         rc = sbi_hsm_init(scratch, hartid, false);
>         if (rc)
>                 sbi_hart_hang();
> @@ -408,8 +419,8 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
>         if (rc)
>                 sbi_hart_hang();
>
> -       init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
> -       (*init_count)++;
> +       count = sbi_scratch_offset_ptr(scratch, init_count_offset);
> +       (*count)++;
>
>         sbi_hsm_hart_start_finish(scratch, hartid);
>  }
> @@ -521,6 +532,23 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
>                 init_warmboot(scratch, hartid);
>  }
>
> +unsigned long sbi_entry_count(u32 hartid)
> +{
> +       struct sbi_scratch *scratch;
> +       unsigned long *entry_count;
> +
> +       if (!entry_count_offset)
> +               return 0;
> +
> +       scratch = sbi_hartid_to_scratch(hartid);
> +       if (!scratch)
> +               return 0;
> +
> +       entry_count = sbi_scratch_offset_ptr(scratch, entry_count_offset);
> +
> +       return *entry_count;
> +}
> +
>  unsigned long sbi_init_count(u32 hartid)
>  {
>         struct sbi_scratch *scratch;
> --
> 2.34.1
>


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

* [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug
  2023-03-20 15:59 ` [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug Anup Patel
@ 2023-04-06 13:19   ` Anup Patel
  0 siblings, 0 replies; 4+ messages in thread
From: Anup Patel @ 2023-04-06 13:19 UTC (permalink / raw)
  To: opensbi

On Mon, Mar 20, 2023 at 9:29?PM Anup Patel <apatel@ventanamicro.com> wrote:
>
> It possible that a platform supports hart hotplug (i.e. both hart_start
> and hart_stop callbacks available) and all harts are start simultaneously
> at platform boot-time. In this situation, the sbi_hsm_hart_start() will
> call hsm_device_hart_start() for secondary harts at platform boot-time
> which will fail because secondary harts were already started.
>
> To fix above, we call hsm_device_hart_start() from sbi_hsm_hart_start()
> only when entry_count is same as init_count for the secondary hart.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/sbi_hsm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
> index 16e3846..b261410 100644
> --- a/lib/sbi/sbi_hsm.c
> +++ b/lib/sbi/sbi_hsm.c
> @@ -301,7 +301,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
>                        const struct sbi_domain *dom,
>                        u32 hartid, ulong saddr, ulong smode, ulong arg1)
>  {
> -       unsigned long init_count;
> +       unsigned long init_count, entry_count;
>         unsigned int hstate;
>         struct sbi_scratch *rscratch;
>         struct sbi_hsm_data *hdata;
> @@ -325,6 +325,8 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
>                 return SBI_EINVAL;
>
>         init_count = sbi_init_count(hartid);
> +       entry_count = sbi_entry_count(hartid);
> +
>         rscratch->next_arg1 = arg1;
>         rscratch->next_addr = saddr;
>         rscratch->next_mode = smode;
> @@ -350,7 +352,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
>                 goto err;
>         }
>
> -       if (hsm_device_has_hart_hotplug() ||
> +       if ((hsm_device_has_hart_hotplug() && (entry_count == init_count)) ||
>            (hsm_device_has_hart_secondary_boot() && !init_count)) {
>                 rc = hsm_device_hart_start(hartid, scratch->warmboot_addr);
>         } else {
> --
> 2.34.1
>


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

end of thread, other threads:[~2023-04-06 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-20 15:59 [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel
2023-03-20 15:59 ` [PATCH 2/2] lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug Anup Patel
2023-04-06 13:19   ` Anup Patel
2023-04-06 13:19 ` [PATCH 1/2] lib: sbi: Introduce sbi_entry_count() function Anup Patel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.