Skip to contentSkip to conversation

lib: sbi: fwft: check feature value to be exactly 1 or 0

PATCH New Clément Léger 3 participants 6 messages Jun 24, 2024 – Jun 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib: sbi: fwft: check feature value to be exactly 1 or 0

As stated by the spec and pointed out by Andrew Jones, the value passed for MISALIGNED_EXC_DELEG and PTE_AD_HW_UPDATING should be either 0 or 1. Add check for these values and return SBI_EINVAL if not.

---
 lib/sbi/sbi_fwft.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/sbi/sbi_fwft.c +8 -4
index aff087f..595819b 100644
@@ -84,10 +84,12 @@ static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
 static int fwft_set_misaligned_delegation(struct fwft_config *conf,
 					 unsigned long value)
 {
-	if (value)
+	if (value == 1)
 		csr_set(CSR_MEDELEG, MIS_DELEG);
-	else
+	else if (value == 0)
 		csr_clear(CSR_MEDELEG, MIS_DELEG);
+	else
+		return SBI_EINVAL;
 
 	return SBI_OK;
 }
@@ -111,18 +113,20 @@ static int fwft_adue_supported(struct fwft_config *conf)
 
 static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
 {
-	if (value)
+	if (value == 1)
 #if __riscv_xlen == 32
 		csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
 		csr_set(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
-	else
+	else if (value == 0)
 #if __riscv_xlen == 32
 		csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
 		csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
+	else
+		return SBI_EINVAL;
 
 	return SBI_OK;
 }
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 lib: sbi: fwft: return SBI_EINVAL rather than SBI_ERR_INVALID_PARAM

Error code returned by the ecall handles should use the defines from sbi_ecall_interface.h rather than sbi_error.h.

---
 lib/sbi/sbi_fwft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_fwft.c +1 -1
index 595819b..f1ae915 100644
@@ -196,7 +196,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
 		return ret;
 
 	if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
-		return SBI_ERR_INVALID_PARAM;
+		return SBI_EINVAL;
 
 	if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
 		return SBI_EDENIED;
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/2 lib: sbi: fwft: return SBI_EINVAL rather than SBI_ERR_INVALID_PARAM

Quoted 24 lines · Cl?ment L?ger

Error code returned by the ecall handles should use the defines from sbi_ecall_interface.h rather than sbi_error.h.

---
 lib/sbi/sbi_fwft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_fwft.c +1 -1
index 595819b..f1ae915 100644
@@ -196,7 +196,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
 		return ret;
 
 	if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
-		return SBI_ERR_INVALID_PARAM;
+		return SBI_EINVAL;
 
 	if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
 		return SBI_EDENIED;
Signature · 1 line
2.45.2
Applied
#3 lore raw

PATCH 2/2 lib: sbi: fwft: return SBI_EINVAL rather than SBI_ERR_INVALID_PARAM

In reply to Clément Léger
Quoted 5 lines · On Mon, Jun 24, 2024 at 4:08?PM Cl?ment L?ger <[email protected]> wrote:

Error code returned by the ecall handles should use the defines from sbi_ecall_interface.h rather than sbi_error.h.

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
index 595819b..f1ae915 100644
@@ -196,7 +196,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
                return ret;
 
        if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
-               return SBI_ERR_INVALID_PARAM;
+               return SBI_EINVAL;
 
        if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
                return SBI_EDENIED;
--

2.45.2

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

#4 lore raw

PATCH 1/2 lib: sbi: fwft: check feature value to be exactly 1 or 0

In reply to Clément Léger
Quoted 54 lines · Cl?ment L?ger

As stated by the spec and pointed out by Andrew Jones, the value passed for MISALIGNED_EXC_DELEG and PTE_AD_HW_UPDATING should be either 0 or 1. Add check for these values and return SBI_EINVAL if not.

---
 lib/sbi/sbi_fwft.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/sbi/sbi_fwft.c +8 -4
index aff087f..595819b 100644
@@ -84,10 +84,12 @@ static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
 static int fwft_set_misaligned_delegation(struct fwft_config *conf,
 					 unsigned long value)
 {
-	if (value)
+	if (value == 1)
 		csr_set(CSR_MEDELEG, MIS_DELEG);
-	else
+	else if (value == 0)
 		csr_clear(CSR_MEDELEG, MIS_DELEG);
+	else
+		return SBI_EINVAL;
 
 	return SBI_OK;
 }
@@ -111,18 +113,20 @@ static int fwft_adue_supported(struct fwft_config *conf)
 
 static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
 {
-	if (value)
+	if (value == 1)
 #if __riscv_xlen == 32
 		csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
 		csr_set(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
-	else
+	else if (value == 0)
 #if __riscv_xlen == 32
 		csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
 		csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
+	else
+		return SBI_EINVAL;
 
 	return SBI_OK;
 }
Signature · 1 line
2.45.2
Applied
#5 lore raw

PATCH 1/2 lib: sbi: fwft: check feature value to be exactly 1 or 0

In reply to Clément Léger
Quoted 6 lines · On Mon, Jun 24, 2024 at 4:08?PM Cl?ment L?ger <[email protected]> wrote:

As stated by the spec and pointed out by Andrew Jones, the value passed for MISALIGNED_EXC_DELEG and PTE_AD_HW_UPDATING should be either 0 or 1. Add check for these values and return SBI_EINVAL if not.

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 54 lines
---
 lib/sbi/sbi_fwft.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/sbi/sbi_fwft.c +8 -5
index aff087f..595819b 100644
@@ -84,10 +84,12 @@ static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
 static int fwft_set_misaligned_delegation(struct fwft_config *conf,
                                         unsigned long value)
 {
-       if (value)
+       if (value == 1)
                csr_set(CSR_MEDELEG, MIS_DELEG);
-       else
+       else if (value == 0)
                csr_clear(CSR_MEDELEG, MIS_DELEG);
+       else
+               return SBI_EINVAL;
 
        return SBI_OK;
 }
@@ -111,18 +113,20 @@ static int fwft_adue_supported(struct fwft_config *conf)
 
 static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
 {
-       if (value)
+       if (value == 1)
 #if __riscv_xlen == 32
                csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
                csr_set(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
-       else
+       else if (value == 0)
 #if __riscv_xlen == 32
                csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
 #else
                csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
 #endif
+       else
+               return SBI_EINVAL;
 
        return SBI_OK;
 }
--

2.45.2

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