lib: sbi: fwft: Fix return error values according to the spec
v2 cover lib: sbi: fwft: Fix return error values according to the spec
The fwft spec mandates that an invalid feature ID return SBI_ERR_INVALID_PARAM and that setting a locked value should return SBI_ERR_DENIED_LOCKED. Add support for both cases.
---
v2:
- Use BIT_ULL instead of BIT to avoid shift overflow.
- Include another patch to optimize flags clearing.
Cl?ment L?ger (4):
include: sbi: Add SBI_ERR_DENIED_LOCKED
lib: sbi: fwft: Return SBI_ERR_DENIED_LOCKED when setting a locked
feature
lib: sbi: fwft: Fix error return value for feature > 32 bits
lib: sbi: Clear lock only for local events
include/sbi/sbi_ecall_interface.h | 3 ++- include/sbi/sbi_error.h | 1 + include/sbi/sbi_fwft.h | 4 ++-- lib/sbi/sbi_fwft.c | 38 +++++++++++++++++++------------ 4 files changed, 29 insertions(+), 17 deletions(-)
Signature · 1 line
2.47.1
PATCH v2 1/4 include: sbi: Add SBI_ERR_DENIED_LOCKED
Add SBI_ERR_DENIED_LOCKED and set it as the SBI_LAST_ERR which was wrongly set to SBI_ERR_BAD_RANGE.
--- include/sbi/sbi_ecall_interface.h | 3 ++- include/sbi/sbi_error.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
include/sbi/sbi_ecall_interface.h +2 -1
@@ -455,8 +455,9 @@ enum sbi_sse_state {#define SBI_ERR_BAD_RANGE -11#define SBI_ERR_TIMEOUT -12#define SBI_ERR_IO -13 +#define SBI_ERR_DENIED_LOCKED -14 -#define SBI_LAST_ERR SBI_ERR_BAD_RANGE +#define SBI_LAST_ERR SBI_ERR_DENIED_LOCKED/* clang-format on */
include/sbi/sbi_error.h +1 -0
@@ -29,6 +29,7 @@#define SBI_ETIMEOUT SBI_ERR_TIMEOUT#define SBI_ETIMEDOUT SBI_ERR_TIMEOUT#define SBI_EIO SBI_ERR_IO +#define SBI_EDENIED_LOCKED SBI_ERR_DENIED_LOCKED#define SBI_ENODEV -1000#define SBI_ENOSYS -1001
Signature · 1 line
2.47.1
Anup Patel
AppliedPATCH v2 1/4 include: sbi: Add SBI_ERR_DENIED_LOCKED
Quoted 5 lines · On Fri, Jan 24, 2025 at 10:23?PM Cl?ment L?ger <[email protected]> wrote:
Add
SBI_ERR_DENIED_LOCKEDand set it as theSBI_LAST_ERRwhich was wrongly set toSBI_ERR_BAD_RANGE.Signed-off-by Cl?ment L?ger <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 40 lines
--- include/sbi/sbi_ecall_interface.h | 3 ++- include/sbi/sbi_error.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)include/sbi/sbi_ecall_interface.h +2
-1@@ -455,8 +455,9 @@ enum sbi_sse_state {#define SBI_ERR_BAD_RANGE -11#define SBI_ERR_TIMEOUT -12#define SBI_ERR_IO -13 +#define SBI_ERR_DENIED_LOCKED -14 -#define SBI_LAST_ERR SBI_ERR_BAD_RANGE +#define SBI_LAST_ERR SBI_ERR_DENIED_LOCKED/* clang-format on */ include/sbi/sbi_error.h +1
-1@@ -29,6 +29,7 @@#define SBI_ETIMEOUT SBI_ERR_TIMEOUT#define SBI_ETIMEDOUT SBI_ERR_TIMEOUT#define SBI_EIO SBI_ERR_IO +#define SBI_EDENIED_LOCKED SBI_ERR_DENIED_LOCKED#define SBI_ENODEV -1000#define SBI_ENOSYS -1001 --2.47.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/4 lib: sbi: fwft: Return SBI_ERR_DENIED_LOCKED when setting a locked feature
In reply to Clément LégerLatest modifications to the spec mandates that a set on a lock feature returns SBI_ERR_DENIED_LOCKED.
--- lib/sbi/sbi_fwft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_fwft.c +1 -1
@@ -337,7 +337,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,return SBI_EINVAL ;if (conf->flags &SBI_FWFT_SET_FLAG_LOCK ) -return SBI_EDENIED ; +return SBI_EDENIED_LOCKED ; ret = conf->feature->set (conf, value);if (ret)
Signature · 1 line
2.47.1
Anup Patel
AppliedPATCH v2 2/4 lib: sbi: fwft: Return SBI_ERR_DENIED_LOCKED when setting a locked feature
Quoted 5 lines · On Fri, Jan 24, 2025 at 10:23?PM Cl?ment L?ger <[email protected]> wrote:
Latest modifications to the spec mandates that a set on a lock feature returns
SBI_ERR_DENIED_LOCKED.Signed-off-by Cl?ment L?ger <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 25 lines
--- lib/sbi/sbi_fwft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/sbi/sbi_fwft.c +1
-2@@ -337,7 +337,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,return SBI_EINVAL ;if (conf->flags &SBI_FWFT_SET_FLAG_LOCK ) -return SBI_EDENIED ; +return SBI_EDENIED_LOCKED ; ret = conf->feature->set (conf, value);if (ret) --2.47.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
In reply to Clément LégerBased on the spec, invalid feature should return SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returning SBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.
--- include/sbi/sbi_fwft.h | 4 ++-- lib/sbi/sbi_fwft.c | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-)
include/sbi/sbi_fwft.h +2 -2
@@ -14,9 +14,9 @@struct sbi_scratch ; -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags); -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);int sbi_fwft_init (struct sbi_scratch *scratch,bool cold_boot);
lib/sbi/sbi_fwft.c +7 -3
@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)return NULL ; } -static int fwft_get_feature (enum sbi_fwft_feature_t feature, +static int fwft_get_feature (unsigned long feature,struct fwft_config **conf) {int ret;struct fwft_config *tconf; +/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; + tconf =get_feature_config (feature);if (!tconf) {if (fwft_is_defined_feature (feature))
@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; } -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags) {int ret;
@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,return SBI_OK ; } -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val) {int ret;struct fwft_config *conf;
Signature · 1 line
2.47.1
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
? 2025-01-24?? 17:51 +0100?Cl?ment L?ger???
Quoted 44 lines
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>---
?include/sbi/sbi_fwft.h |? 4 ++--
?lib/sbi/sbi_fwft.c???? | 10 +++++++---
?2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0@@ -14,9 +14,9 @@?
?structsbi_scratch;
?include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags);
include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);?
?intsbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot); ?lib/sbi/sbi_fwft.c +0
-0@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) ? return NULL; ?}?
lib/sbi/sbi_fwft.c +1
-1-static int fwft_get_feature(enum sbi_fwft_feature_t feature, +static int fwft_get_feature(unsigned long feature,? ??? struct
fwft_config**conf)
?{
? int ret;
? structfwft_config*tconf;
?
lib/sbi/sbi_fwft.c static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) · line 299
Quoted 4 lines
lib/sbi/sbi_fwft.c +4
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; +
We can specify the type of enumeration at the time of definition in the following way
enum sbi_fwft_feature_t : long {
In this way we don't need to change the declaration of the function, and we don't need the extra detection of the high 32 bits, because get_feature_config would return a null pointer because it couldn't find the
Regards,
Xiang W
Quoted 21 lines
? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) ? conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags)
?{
? int ret;lib/sbi/sbi_fwft.c +0
-0@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, ? return SBI_OK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val)?{
? int ret;
? structfwft_config*conf;
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
Quoted 52 lines · Xiang W
? 2025-01-24?? 17:51 +0100?Cl?ment L?ger???
Quoted 44 lines
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>---
?include/sbi/sbi_fwft.h |? 4 ++--
?lib/sbi/sbi_fwft.c???? | 10 +++++++---
?2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0@@ -14,9 +14,9 @@?
?structsbi_scratch;
?include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags);
include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);?
?intsbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot); ?lib/sbi/sbi_fwft.c +0
-0@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) ? return NULL; ?}?
lib/sbi/sbi_fwft.c +1
-1-static int fwft_get_feature(enum sbi_fwft_feature_t feature, +static int fwft_get_feature(unsigned long feature,? ??? struct
fwft_config**conf)
?{
? int ret;
? structfwft_config*tconf;
?lib/sbi/sbi_fwft.c static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) · line 299
Quoted 4 lines
lib/sbi/sbi_fwft.c +4
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; +We can specify the type of enumeration at the time of definition in the following way
Quoted 1 line
enum
sbi_fwft_feature_t: long {
TIL !:) After searching a bit, it seems like this is only available since C23. Is this something we allow in OpenSBI ?
Thanks,
Cl?ment
Quoted 30 lines
In this way we don't need to change the declaration of the function, and we don't need the extra detection of the high 32 bits, because
get_feature_configwould return a null pointer because it couldn't find theRegards,
Xiang WQuoted 21 lines
? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) ? conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags)
?{
? int ret;lib/sbi/sbi_fwft.c +0
-0@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, ? return SBI_OK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val)?{
? int ret;
? structfwft_config*conf;
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
? 2025-02-11?? 11:42 +0100?Cl?ment L?ger???
Quoted 55 lines · Xiang W
Quoted 52 lines
? 2025-01-24?? 17:51 +0100?Cl?ment L?ger???
Quoted 44 lines
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>---
?include/sbi/sbi_fwft.h |? 4 ++--
?lib/sbi/sbi_fwft.c???? | 10 +++++++---
?2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0@@ -14,9 +14,9 @@?
?structsbi_scratch;
?include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags);
include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);?
?intsbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot); ?lib/sbi/sbi_fwft.c +0
-0@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) ? return NULL; ?}?
lib/sbi/sbi_fwft.c +1
-1-static int fwft_get_feature(enum sbi_fwft_feature_t feature, +static int fwft_get_feature(unsigned long feature,? ??? struct
fwft_config**conf)
?{
? int ret;
? structfwft_config*tconf;
?lib/sbi/sbi_fwft.c static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) · line 299
Quoted 4 lines
lib/sbi/sbi_fwft.c +4
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; +We can specify the type of enumeration at the time of definition in the following way
Quoted 8 lines
Quoted 1 line
enum
sbi_fwft_feature_t: long {TIL !:) After searching a bit, it seems like this is only available since C23. Is this something we allow in OpenSBI ?
Thanks,
Cl?ment
Add a value to the enumeration
enum sbi_fwft_feature_t {
......
SBI_FWFT_NOT_USED_ANYWHERE = -1UL
};The compiler will select the appropriate type to save the -1UL.
Regards,
Xiang W
Quoted 31 lines
Quoted 31 lines
In this way we don't need to change the declaration of the function, and we don't need the extra detection of the high 32 bits, because
get_feature_configwould return a null pointer because it couldn't find theRegards,
Xiang WQuoted 21 lines
? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) ? conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags)
?{
? int ret;lib/sbi/sbi_fwft.c +0
-0@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, ? return SBI_OK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val)?{
? int ret;
? structfwft_config*conf;
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
Quoted 65 lines · Xiang W
? 2025-02-11?? 11:42 +0100?Cl?ment L?ger???
Quoted 55 lines · Xiang W
Quoted 52 lines
? 2025-01-24?? 17:51 +0100?Cl?ment L?ger???
Quoted 44 lines
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>---
?include/sbi/sbi_fwft.h |? 4 ++--
?lib/sbi/sbi_fwft.c???? | 10 +++++++---
?2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0@@ -14,9 +14,9 @@?
?structsbi_scratch;
?include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags);
include/sbi/sbi_fwft.h +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);?
?intsbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot); ?lib/sbi/sbi_fwft.c +0
-0@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) ? return NULL; ?}?
lib/sbi/sbi_fwft.c +1
-1-static int fwft_get_feature(enum sbi_fwft_feature_t feature, +static int fwft_get_feature(unsigned long feature,? ??? struct
fwft_config**conf)
?{
? int ret;
? structfwft_config*tconf;
?lib/sbi/sbi_fwft.c static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) · line 299
Quoted 4 lines
lib/sbi/sbi_fwft.c +4
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; +We can specify the type of enumeration at the time of definition in the following way
Quoted 8 lines
Quoted 1 line
enum
sbi_fwft_feature_t: long {TIL !:) After searching a bit, it seems like this is only available since C23. Is this something we allow in OpenSBI ?
Thanks,
Cl?ment
Quoted 8 lines
Add a value to the enumeration
enum sbi_fwft_feature_t { ...... SBI_FWFT_NOT_USED_ANYWHERE = -1UL };The compiler will select the appropriate type to save the -1UL.
I prefer to keep it as is, the enum only contains what is needed, the interface uses unsigned long and validates them to be passed to other functions.
Moreover doing so would be wrong regarding to the spec which states that features are 32 bits identifier. So modifying the feature enum storage to accommodate the internal interface is wrong.
Regards,
Cl?ment
Quoted 35 lines
Regards,
Xiang WQuoted 31 lines
Quoted 31 lines
In this way we don't need to change the declaration of the function, and we don't need the extra detection of the high 32 bits, because
get_feature_configwould return a null pointer because it couldn't find theRegards,
Xiang WQuoted 21 lines
? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) ? conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, +int sbi_fwft_set(unsigned long feature, unsigned long value,? unsigned long flags)
?{
? int ret;lib/sbi/sbi_fwft.c +0
-0@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value, ? return SBI_OK; ?}?
lib/sbi/sbi_fwft.c +1
-1-int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val)?{
? int ret;
? structfwft_config*conf;
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
In reply to Clément LégerQuoted 19 lines · On Fri, Jan 24, 2025 at 10:23?PM Cl?ment L?ger <[email protected]> wrote:
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_fwft.h | 4 ++-- lib/sbi/sbi_fwft.c | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0
include/sbi/sbi_fwft.h line 19
Quoted 8 lines
include/sbi/sbi_fwft.h +2
-2@@ -14,9 +14,9 @@struct sbi_scratch ; -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags); -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);
The feature should be uint32_t as defined by the SBI spec.
Also, the uint32_t overflow check if required should be done in sbi_ecall_fwft_handler().
Regards,
Anup
Quoted 51 lines
include/sbi/sbi_fwft.h +0
-0int sbi_fwft_init (struct sbi_scratch *scratch,bool cold_boot);lib/sbi/sbi_fwft.c +7
-4@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)return NULL ; } -static int fwft_get_feature (enum sbi_fwft_feature_t feature, +static int fwft_get_feature (unsigned long feature,struct fwft_config **conf) {int ret;struct fwft_config *tconf; +/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; + tconf =get_feature_config (feature);if (!tconf) {if (fwft_is_defined_feature (feature))@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; } -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags) {int ret;@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,return SBI_OK ; } -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val) {int ret;struct fwft_config *conf; --2.47.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 3/4 lib: sbi: fwft: Fix error return value for feature > 32 bits
Quoted 31 lines · Anup Patel
Quoted 19 lines · On Fri, Jan 24, 2025 at 10:23?PM Cl?ment L?ger <[email protected]> wrote:
Based on the spec, invalid feature should return
SBI_ERR_INVALID_PARAM. This was not the case with the current implementation since the upper 32 bits were not considered when checking the feature thus returningSBI_ERR_DENIED. Fix that by passing the raw unsigned long rather than the enum to be sure we are passing the full 64 bits and then check for upper bits to be cleared.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_fwft.h | 4 ++-- lib/sbi/sbi_fwft.c | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-)include/sbi/sbi_fwft.h +0
-0include/sbi/sbi_fwft.h line 19
Quoted 8 lines
include/sbi/sbi_fwft.h +2
-2@@ -14,9 +14,9 @@struct sbi_scratch ; -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags); -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val); +int sbi_fwft_get (unsigned long feature,unsigned long *out_val);The feature should be
uint32_tas defined by the SBI spec.
Quoted 2 lines
Also, the
uint32_toverflow check if required should be done insbi_ecall_fwft_handler().
Yes, I'll re-spin that patch with the SSE one as well.
Thanks,
Cl?ment
Quoted 55 lines
Regards,
AnupQuoted 51 lines
include/sbi/sbi_fwft.h +0
-0int sbi_fwft_init (struct sbi_scratch *scratch,bool cold_boot);lib/sbi/sbi_fwft.c +7
-4@@ -287,12 +287,16 @@ static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)return NULL ; } -static int fwft_get_feature (enum sbi_fwft_feature_t feature, +static int fwft_get_feature (unsigned long feature,struct fwft_config **conf) {int ret;struct fwft_config *tconf; +/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT_ULL (32 ) -1 )) +return SBI_EINVAL ; + tconf =get_feature_config (feature);if (!tconf) {if (fwft_is_defined_feature (feature))@@ -323,7 +327,7 @@ static void fwft_clear_config_lock(enum sbi_fwft_feature_t feature) conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; } -int sbi_fwft_set (enum sbi_fwft_feature_t feature,unsigned long value, +int sbi_fwft_set (unsigned long feature,unsigned long value,unsigned long flags) {int ret;@@ -348,7 +352,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,return SBI_OK ; } -int sbi_fwft_get (enum sbi_fwft_feature_t feature,unsigned long *out_val) +int sbi_fwft_get (unsigned long feature,unsigned long *out_val) {int ret;struct fwft_config *conf; --2.47.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 4/4 lib: sbi: Clear lock only for local events
In reply to Clément LégerUpon hart reset, only the local events state should be reset. While this implicitely worked since fwft_get_feature() return NULL for global events this is a bit fragile to do so. Additionally, the loop on feature list plus the call to fwft_get_feature was unneeded since we already have a direct access to the fwft hart state and thus can directly reset lock flags for each config. Lastly, we can only clear the lock when the fwft hart state was already allocated, in the other case, it is allocated with a zalloc which guarantees us that the feature flags are clear at boot.
--- lib/sbi/sbi_fwft.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
lib/sbi/sbi_fwft.c +16 -10
@@ -271,12 +271,17 @@ static int fwft_get_pmlen(struct fwft_config *conf, unsigned long *value) }#endif +static bool fwft_feature_is_global (enum sbi_fwft_feature_t feature) +{ +return feature &SBI_FWFT_GLOBAL_FEATURE_BIT ; +} +static struct fwft_config *get_feature_config (enum sbi_fwft_feature_t feature) {int i;struct fwft_hart_state *fhs =fwft_thishart_state_ptr (); -if (feature &SBI_FWFT_GLOBAL_FEATURE_BIT ) +if (fwft_feature_is_global (feature))return NULL ;for (i =0 ; i < fhs->config_count; i++){
@@ -315,16 +320,18 @@ static int fwft_get_feature(unsigned long feature,return SBI_SUCCESS ; } -static void fwft_clear_config_lock (enum sbi_fwft_feature_t feature) +static void fwft_clear_local_lock (struct fwft_hart_state *fhs) { -int ret; +int i;struct fwft_config *conf; - ret =fwft_get_feature (feature, &conf); -if (ret) -return ; +for (i =0 ; i < fhs->config_count; i++) { + conf = &fhs->configs[i]; +if (fwft_feature_is_global (conf->feature->id)) +continue ; - conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; + conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; + } } int sbi_fwft_set(unsigned long feature, unsigned long value,
@@ -428,10 +435,9 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) fhs->configs[i].feature = &features[i];fwft_set_hart_state_ptr (scratch, fhs); + }else { +fwft_clear_local_lock (fhs); } -for (i =0 ; i <array_size (features); i++) -fwft_clear_config_lock (features[i].id); -return 0 ; }
Signature · 1 line
2.47.1
PATCH v2 4/4 lib: sbi: Clear lock only for local events
Quoted 78 lines · Cl?ment L?ger
Upon hart reset, only the local events state should be reset. While this implicitely worked since
fwft_get_feature()return NULL for global events this is a bit fragile to do so. Additionally, the loop on feature list plus the call tofwft_get_featurewas unneeded since we already have a direct access to the fwft hart state and thus can directly reset lock flags for each config. Lastly, we can only clear the lock when the fwft hart state was already allocated, in the other case, it is allocated with a zalloc which guarantees us that the feature flags are clear at boot.Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_fwft.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)lib/sbi/sbi_fwft.c +16
-10@@ -271,12 +271,17 @@ static int fwft_get_pmlen(struct fwft_config *conf, unsigned long *value) }#endif +static bool fwft_feature_is_global (enum sbi_fwft_feature_t feature) +{ +return feature &SBI_FWFT_GLOBAL_FEATURE_BIT ; +} +static struct fwft_config *get_feature_config (enum sbi_fwft_feature_t feature) {int i;struct fwft_hart_state *fhs =fwft_thishart_state_ptr (); -if (feature &SBI_FWFT_GLOBAL_FEATURE_BIT ) +if (fwft_feature_is_global (feature))return NULL ;for (i =0 ; i < fhs->config_count; i++){@@ -315,16 +320,18 @@ static int fwft_get_feature(unsigned long feature,return SBI_SUCCESS ; } -static void fwft_clear_config_lock (enum sbi_fwft_feature_t feature) +static void fwft_clear_local_lock (struct fwft_hart_state *fhs) { -int ret; +int i;struct fwft_config *conf; - ret =fwft_get_feature (feature, &conf); -if (ret) -return ; +for (i =0 ; i < fhs->config_count; i++) { + conf = &fhs->configs[i]; +if (fwft_feature_is_global (conf->feature->id)) +continue ; - conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; + conf->flags &= ~SBI_FWFT_SET_FLAG_LOCK ; + } } int sbi_fwft_set(unsigned long feature, unsigned long value,@@ -428,10 +435,9 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) fhs->configs[i].feature = &features[i];fwft_set_hart_state_ptr (scratch, fhs); + }else { +fwft_clear_local_lock (fhs); } -for (i =0 ; i <array_size (features); i++) -fwft_clear_config_lock (features[i].id); -return 0 ; }Signature · 1 line
2.47.1