lib: sbi: fwft: Fix return error values according to the spec
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.
Cl?ment L?ger (3):
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
include/sbi/sbi_ecall_interface.h | 3 ++- include/sbi/sbi_error.h | 1 + include/sbi/sbi_fwft.h | 4 ++-- lib/sbi/sbi_fwft.c | 13 +++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/3 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
PATCH 2/3 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 2/3 lib: sbi: fwft: Return SBI_ERR_DENIED_LOCKED when setting a locked feature
Quoted 5 lines · On Thu, Jan 23, 2025 at 9:36?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 3/3 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 | 11 ++++++++--- 2 files changed, 10 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 +8 -3
@@ -287,12 +287,17 @@ 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 (32 ) -1 )) { +return SBI_EINVAL ; + } + tconf =get_feature_config (feature);if (!tconf) {if (fwft_is_defined_feature (feature))
@@ -323,7 +328,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 +353,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 3/3 lib: sbi: fwft: Fix error return value for feature > 32 bits
? 2025-01-23?? 17:05 +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???? | 11 ++++++++--- ?2 files changed, 10 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,17 @@ 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 297
Quoted 2 lines
lib/sbi/sbi_fwft.c +2
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT (32 ) -1 )) {
The macro expansion of BIT(32) is 1UL<<32. In RV32, unsigned long is 32 bits,?so integer overflow will occur. It is recommended to replace BIT with BIT_ULL.
Regards,
Xiang W
Quoted 28 lines
lib/sbi/sbi_fwft.c +3
-0+return SBI_EINVAL ; + } +? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +328,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 +353,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;Signature · 1 line
2.47.1
PATCH 3/3 lib: sbi: fwft: Fix error return value for feature > 32 bits
Quoted 41 lines · Xiang W
? 2025-01-23?? 17:05 +0100?Cl?ment L?ger???
Quoted 40 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???? | 11 ++++++++--- ?2 files changed, 10 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,17 @@ 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)
Quoted 8 lines
lib/sbi/sbi_fwft.c static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) · line 297
Quoted 6 lines
?{
? int ret;
? structfwft_config*tconf;
?lib/sbi/sbi_fwft.c +2
-0+/* Feature are defined as 32 bits identifiers */ +if (feature & ~(BIT (32 ) -1 )) {The macro expansion of BIT(32) is 1UL<<32. In RV32, unsigned long is 32 bits,?so integer overflow will occur. It is recommended to replace BIT with
BIT_ULL.
Oh yes nice catch. That is UB indeed. I'll fix that.
Quoted 32 lines
Regards,
Xiang WQuoted 28 lines
lib/sbi/sbi_fwft.c +3
-0+return SBI_EINVAL ; + } +? tconf =
get_feature_config(feature);
? if (!tconf) {
? if (fwft_is_defined_feature(feature))lib/sbi/sbi_fwft.c +0
-0@@ -323,7 +328,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 +353,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;Signature · 1 line
2.47.1