Skip to contentSkip to conversation

sbi: fwft: clear the config lock when warm boot

PATCH New Nick Hu 4 participants 5 messages Nov 15, 2024 – Nov 28, 2024

lore
Share & tools
lore

Nick Hu

author
#0 lore raw

PATCH 1/1 sbi: fwft: clear the config lock when warm boot

The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel.

---
 lib/sbi/sbi_fwft.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/sbi/sbi_fwft.c +15 -0
index 9cf14c16..0cb165b4 100644
@@ -311,6 +311,18 @@ static int fwft_get_feature(enum sbi_fwft_feature_t feature,
 	return SBI_SUCCESS;
 }
 
+static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature)
+{
+	int ret;
+	struct fwft_config *conf;
+
+	ret = fwft_get_feature(feature, &conf);
+	if (ret)
+		return;
+
+	conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK;
+}
+
 int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
 		 unsigned long flags)
 {
@@ -414,5 +426,8 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
 		fwft_set_hart_state_ptr(scratch, fhs);
 	}
 
+	for (i = 0; i < array_size(features); i++)
+		fwft_clear_config_lock(features[i].id);
+
 	return 0;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 sbi: fwft: clear the config lock when warm boot

? 2024-11-15?? 15:33 +0800?Nick Hu???

Quoted 6 lines

The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel.

In sbi_fwft_init, the memory for fwft_hart_state is allocated by? sbi_zalloc, which ensures that flags is 0. So no additional code is needed to clear the SBI_FWFT_SET_FLAG_LOCK bit.

Regards,
Xiang W

Quoted 40 lines

---
?lib/sbi/sbi_fwft.c | 15 +++++++++++++++
?1 file changed, 15 insertions(+)

lib/sbi/sbi_fwft.c +0 -0
index 9cf14c16..0cb165b4 100644
@@ -311,6 +311,18 @@ static int fwft_get_feature(enum sbi_fwft_feature_t feature,
 ?	return SBI_SUCCESS;
 ?}

?

lib/sbi/sbi_fwft.c +12 -0
+static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature)
+{
+	int ret;
+	struct fwft_config *conf;
+
+	ret = fwft_get_feature(feature, &conf);
+	if (ret)
+		return;
+
+	conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK;
+}
+

?int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
? unsigned long flags)
?{

lib/sbi/sbi_fwft.c +0 -0
@@ -414,5 +426,8 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
 ?		fwft_set_hart_state_ptr(scratch, fhs);
 ?	}

?

lib/sbi/sbi_fwft.c +3 -0
+	for (i = 0; i < array_size(features); i++)
+		fwft_clear_config_lock(features[i].id);
+

? return 0;
?}

Signature · 1 line
2.34.1
#2 lore raw

PATCH 1/1 sbi: fwft: clear the config lock when warm boot

Hi Xiang,

Quoted 11 lines · Xiang W

? 2024-11-15?? 15:33 +0800?Nick Hu???

Quoted 6 lines

The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel.

In sbi_fwft_init, the memory for fwft_hart_state is allocated by? sbi_zalloc, which ensures that flags is 0. So no additional code is needed to clear the SBI_FWFT_SET_FLAG_LOCK bit.

That allocation only occurs the first time a hart is started. After a sbi_hsm_hart_stop() and sbi_hsm_hart_start(), the FWFT features will be reset to their default values per the SBI spec, and the flags need to be reset as well.

Regards,
Samuel

Quoted 42 lines
Quoted 40 lines

---
?lib/sbi/sbi_fwft.c | 15 +++++++++++++++
?1 file changed, 15 insertions(+)

lib/sbi/sbi_fwft.c +0 -0
index 9cf14c16..0cb165b4 100644
@@ -311,6 +311,18 @@ static int fwft_get_feature(enum sbi_fwft_feature_t feature,
 ?	return SBI_SUCCESS;
 ?}

?

lib/sbi/sbi_fwft.c +12 -0
+static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature)
+{
+	int ret;
+	struct fwft_config *conf;
+
+	ret = fwft_get_feature(feature, &conf);
+	if (ret)
+		return;
+
+	conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK;
+}
+

?int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
? unsigned long flags)
?{

lib/sbi/sbi_fwft.c +0 -0
@@ -414,5 +426,8 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
 ?		fwft_set_hart_state_ptr(scratch, fhs);
 ?	}

?

lib/sbi/sbi_fwft.c +3 -0
+	for (i = 0; i < array_size(features); i++)
+		fwft_clear_config_lock(features[i].id);
+

? return 0;
?}

Signature · 1 line
2.34.1
#3 lore raw

PATCH 1/1 sbi: fwft: clear the config lock when warm boot

? 2024-11-21?? 21:24 -0600?Samuel Holland???

Quoted 11 lines

Hi Xiang,

Quoted 8 lines · Xiang W

? 2024-11-15?? 15:33 +0800?Nick Hu???

Quoted 6 lines

The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel.

Quoted 8 lines
Quoted 3 lines

In sbi_fwft_init, the memory for fwft_hart_state is allocated by? sbi_zalloc, which ensures that flags is 0. So no additional code is needed to clear the SBI_FWFT_SET_FLAG_LOCK bit.

That allocation only occurs the first time a hart is started. After a sbi_hsm_hart_stop() and sbi_hsm_hart_start(), the FWFT features will be reset to their default values per the SBI spec, and the flags need to be reset as well.

Yes, you are right, I ignored the situation you mentioned.

Regards,
Xiang W

Quoted 47 lines

Regards,
Samuel

Quoted 42 lines
Quoted 40 lines

---
?lib/sbi/sbi_fwft.c | 15 +++++++++++++++
?1 file changed, 15 insertions(+)

lib/sbi/sbi_fwft.c +0 -0
index 9cf14c16..0cb165b4 100644
@@ -311,6 +311,18 @@ static int fwft_get_feature(enum sbi_fwft_feature_t feature,
 ?	return SBI_SUCCESS;
 ?}

?

lib/sbi/sbi_fwft.c +12 -0
+static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature)
+{
+	int ret;
+	struct fwft_config *conf;
+
+	ret = fwft_get_feature(feature, &conf);
+	if (ret)
+		return;
+
+	conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK;
+}
+

?int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
? unsigned long flags)
?{

lib/sbi/sbi_fwft.c +0 -0
@@ -414,5 +426,8 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
 ?		fwft_set_hart_state_ptr(scratch, fhs);
 ?	}

?

lib/sbi/sbi_fwft.c +3 -0
+	for (i = 0; i < array_size(features); i++)
+		fwft_clear_config_lock(features[i].id);
+

? return 0;
?}

Signature · 1 line
2.34.1
Applied
#4 lore raw

PATCH 1/1 sbi: fwft: clear the config lock when warm boot

In reply to Nick Hu
Quoted 7 lines · On Fri, Nov 15, 2024 at 1:03?PM Nick Hu <[email protected]> wrote:

The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel.

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 44 lines
---
 lib/sbi/sbi_fwft.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/sbi/sbi_fwft.c +15 -1
index 9cf14c16..0cb165b4 100644
@@ -311,6 +311,18 @@ static int fwft_get_feature(enum sbi_fwft_feature_t feature,
        return SBI_SUCCESS;
 }
 
+static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature)
+{
+       int ret;
+       struct fwft_config *conf;
+
+       ret = fwft_get_feature(feature, &conf);
+       if (ret)
+               return;
+
+       conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK;
+}
+
 int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
                 unsigned long flags)
 {
@@ -414,5 +426,8 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
                fwft_set_hart_state_ptr(scratch, fhs);
        }
 
+       for (i = 0; i < array_size(features); i++)
+               fwft_clear_config_lock(features[i].id);
+
        return 0;
 }
--

2.34.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi