Skip to contentSkip to conversation

lib: sbi: Fix PMP entry detetcion mechanism

PATCH New Vincent Chen 2 participants 3 messages Oct 27, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: Fix PMP entry detetcion mechanism

The granularity of PMP access control settings is platform-specific. If the granularity is greater than 4 bytes, the current mechanism will not work because the return value will be forced to be granularity alignment so that the returned value is not equal to the written value. This patch writes PMP_ADDR_MASK to each PMP addr registers and checks the return value that is unequaled to zero to identify whether this PMP entry is support or not.

---
 lib/sbi/sbi_hart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_hart.c +2 -2
index 6413194..42c4f51 100644
@@ -372,7 +372,7 @@ static void hart_detect_features(struct sbi_scratch *scratch)
 		} else {						\
 			csr_write_allowed(__csr, (ulong)&trap, __wrval);\
 			if (!trap.cause) {				\
-				if (csr_swap(__csr, val) == __wrval)	\
+				if (csr_swap(__csr, val))		\
 					(hfeatures->__field)++;		\
 				else					\
 					goto __skip;			\
@@ -403,7 +403,7 @@ static void hart_detect_features(struct sbi_scratch *scratch)
 	__check_csr_32(__csr + 32, __rdonly, __wrval, __field, __skip)
 
 	/* Detect number of PMP regions */
-	__check_csr_64(CSR_PMPADDR0, 0, 1UL, pmp_count, __pmp_skip);
+	__check_csr_64(CSR_PMPADDR0, 0, PMP_ADDR_MASK, pmp_count, __pmp_skip);
 __pmp_skip:
 
 	/* Detect number of MHPM counters */
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 lib: sbi: Fix PMP entry detetcion mechanism

Quoted 10 lines

-----Original Message-----
From: opensbi <[email protected]> On Behalf Of Vincent Chen
Sent: 27 October 2020 13:24
To: opensbi at lists.infradead.org
Cc: vincent.chen at sifive.com
Subject: [PATCH] lib: sbi: Fix PMP entry detetcion mechanism

Quoted 7 lines

The granularity of PMP access control settings is platform-specific. If the granularity is greater than 4 bytes, the current mechanism will not work because the return value will be forced to be granularity alignment so that the returned value is not equal to the written value. This patch writes PMP_ADDR_MASK to each PMP addr registers and checks the return value that is unequaled to zero to identify whether this PMP entry is support or not.

This was initially fixed by Pragnesh for SiFive Unleashed platform and finally it has been fixed correctly by Atish.

Can you try latest OpenSBI repo ?

Regards,
Anup

Quoted 40 lines
---
 lib/sbi/sbi_hart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_hart.c index 6413194..42c4f51 renamed from lib/sbi/sbi_hart.c +0 -0

100644

lib/sbi/sbi_hart.c +1 -1
@@ -372,7 +372,7 @@ static void hart_detect_features(struct sbi_scratch
 *scratch)
 		} else {						\
 			csr_write_allowed(__csr, (ulong)&trap, __wrval);\
 			if (!trap.cause) {				\
-				if (csr_swap(__csr, val) == __wrval)	\
+				if (csr_swap(__csr, val))		\
 					(hfeatures->__field)++;
 	\
lib/sbi/sbi_hart.c +1 -1
 				else					\
 					goto __skip;			\
@@ -403,7 +403,7 @@ static void hart_detect_features(struct sbi_scratch
 *scratch)
 	__check_csr_32(__csr + 32, __rdonly, __wrval, __field, __skip)
 
 	/* Detect number of PMP regions */
-	__check_csr_64(CSR_PMPADDR0, 0, 1UL, pmp_count, __pmp_skip);
+	__check_csr_64(CSR_PMPADDR0, 0, PMP_ADDR_MASK,
 pmp_count, __pmp_skip);
 __pmp_skip:

/* Detect number of MHPM counters */
--
2.7.4

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

#2 lore raw

PATCH 1/1 lib: sbi: Fix PMP entry detetcion mechanism

Quoted 19 lines · Anup Patel
Quoted 11 lines

-----Original Message-----
From: opensbi <[email protected]> On Behalf Of Vincent Chen
Sent: 27 October 2020 13:24
To: opensbi at lists.infradead.org
Cc: vincent.chen at sifive.com
Subject: [PATCH] lib: sbi: Fix PMP entry detetcion mechanism

Quoted 7 lines

The granularity of PMP access control settings is platform-specific. If the granularity is greater than 4 bytes, the current mechanism will not work because the return value will be forced to be granularity alignment so that the returned value is not equal to the written value. This patch writes PMP_ADDR_MASK to each PMP addr registers and checks the return value that is unequaled to zero to identify whether this PMP entry is support or not.

Quoted 8 lines

This was initially fixed by Pragnesh for SiFive Unleashed platform and finally it has been fixed correctly by Atish.

Can you try latest OpenSBI repo ?

Regards,
Anup

Sure, Thanks.
Regards,
Vincent