lib: sbi: Fix PMP address bits detection
PATCH 1/1 lib: sbi: Fix PMP address bits detection
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
of address bits")
--- lib/sbi/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/sbi/sbi_hart.c +4 -0
@@ -339,6 +339,10 @@ static unsigned long hart_pmp_get_allowed_addr(void)unsigned long val =0 ;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) { val =csr_read_allowed (CSR_PMPADDR0 , (ulong)&trap);
Signature · 1 line
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
Quoted 33 lines · Anup Patel
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>--- lib/sbi/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-1@@ -339,6 +339,10 @@ static unsigned long hart_pmp_get_allowed_addr(void)unsigned long val =0 ;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) { val =csr_read_allowed (CSR_PMPADDR0 , (ulong)&trap); --2.25.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 2 lines
Regards, Atish
PATCH 1/1 lib: sbi: Fix PMP address bits detection
In reply to Anup Patel? 2021-11-08???? 10:36 +0530?Anup Patel???
Quoted 4 lines
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Why? Disable PMP? Prevent the generated PMP from affecting program execution? If so, I think the PMP configuration should be backed up first, then tested, and finally restored
Regards,
Xiang W
Quoted 29 lines
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>---
?lib/sbi/sbi_hart.c | 4 ++++
?1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +0
-0@@ -339,6 +339,10 @@ static unsigned longhart_pmp_get_allowed_addr (void) ????????unsigned long val = 0; ????????struct sbi_trap_info trap = {0};?
+???????csr_write_allowed(CSR_PMPCFG0, (ulong)&trap, 0); +???????if (trap.cause)
+???????????????return 0;
+
????????csr_write_allowed(CSR_PMPADDR0, (ulong)&trap,PMP_ADDR_MASK); ????????if (!trap.cause) {
????????????????val =csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);Signature · 1 line
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
Quoted 9 lines · Xiang W
? 2021-11-08???? 10:36 +0530?Anup Patel???
Quoted 4 lines
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Why? Disable PMP? Prevent the generated PMP from affecting program execution? If so, I think the PMP configuration should be backed up first, then tested, and finally restored
We don't need to save/restore PMP configuration here because it is very early during HART feature detection.
For the rest refer,
https://github.com/riscv-software-src/opensbi/issues/225
Regards,
Anup
Quoted 34 lines
Regards,
Xiang WQuoted 29 lines
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>--- lib/sbi/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-0@@ -339,6 +339,10 @@ static unsigned longhart_pmp_get_allowed_addr (void ) unsigned long val = 0;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) {val = csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);--
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
? 2021-11-11???? 18:38 +0530?Anup Patel???
Quoted 11 lines · Xiang W
Quoted 9 lines
? 2021-11-08???? 10:36 +0530?Anup Patel???
Quoted 4 lines
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Why? Disable PMP? Prevent the generated PMP from affecting program execution? If so, I think the PMP configuration should be backed up first, then tested, and finally restored
Quoted 8 lines
We don't need to save/restore PMP configuration here because it is very early during HART feature detection.
For the rest refer,
https://github.com/riscv-software-src/opensbi/issues/225Regards,
Anup
This code will be executed after each warm boot, pmpcfg0 may be locked, and writing 0 may not work. I suggest to make this code execute once through a static variable
Regards,
Xiang W
Quoted 37 lines
Quoted 37 lines
Regards,
Xiang WQuoted 31 lines
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>---
?lib/sbi/sbi_hart.c | 4 ++++
?1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-0@@ -339,6 +339,10 @@ static unsigned longhart_pmp_get_allowed_addr (void) ??????? unsigned long val = 0; ??????? struct sbi_trap_info trap = {0}; +?????? csr_write_allowed(CSR_PMPCFG0, (ulong)&trap, 0); +?????? if (trap.cause) +?????????????? return 0; + ??????? csr_write_allowed(CSR_PMPADDR0, (ulong)&trap,PMP_ADDR_MASK );??????? if (!trap.cause) {
??????????????? val =csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);
--
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
Quoted 19 lines · Xiang W
? 2021-11-11???? 18:38 +0530?Anup Patel???
Quoted 17 lines · Xiang W
Quoted 9 lines
? 2021-11-08???? 10:36 +0530?Anup Patel???
Quoted 4 lines
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Why? Disable PMP? Prevent the generated PMP from affecting program execution? If so, I think the PMP configuration should be backed up first, then tested, and finally restored
We don't need to save/restore PMP configuration here because it is very early during HART feature detection.
For the rest refer,
https://github.com/riscv-software-src/opensbi/issues/225
Quoted 6 lines
Quoted 2 lines
Regards,
AnupThis code will be executed after each warm boot, pmpcfg0 may be locked, and writing 0 may not work. I suggest to make this code execute once through a static variable
No need for a static variable, we can just check "hfeatures->pmp_addr_bits" to be zero before calling hart_pmp_get_allowed_addr().
Regards,
Anup
Quoted 42 lines
Regards,
Xiang WQuoted 37 lines
Quoted 37 lines
Regards,
Xiang WQuoted 31 lines
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>--- lib/sbi/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-0@@ -339,6 +339,10 @@ static unsigned longhart_pmp_get_allowed_addr (void ) unsigned long val = 0;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) {
val = csr_read_allowed(CSR_PMPADDR0,
(ulong)&trap);
--
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
? 2021-11-11???? 21:01 +0530?Anup Patel???
Quoted 33 lines · Xiang W
Quoted 23 lines
? 2021-11-11???? 18:38 +0530?Anup Patel???
Quoted 21 lines · Xiang W
Quoted 4 lines
? 2021-11-08???? 10:36 +0530?Anup Patel???
Quoted 2 lines
From: Vasan VS <[email protected]>
Quoted 8 lines
Quoted 3 lines
We should ensure that pmpcfg0.pmp0cfg is set to zero before using
pmpaddr0 CSR for detecting implemented PMP address bits.Why? Disable PMP? Prevent the generated PMP from affecting program
execution? If so, I think the PMP configuration should be backed up
first, then tested, and finally restoredWe don't need to save/restore PMP configuration here because it is
very early during HART feature detection.For the rest refer,
https://github.com/riscv-software-src/opensbi/issues/225Quoted 8 lines
Quoted 2 lines
Regards,
AnupThis code will be executed after each warm boot, pmpcfg0 may be locked,
and writing 0 may not work. I suggest to make this code execute once
through a static variable
Quoted 4 lines
No need for a static variable, we can just check "hfeatures-
Quoted 1 line
pmp_addr_bits"to be zero before calling
hart_pmp_get_allowed_addr().
Yes, good idea
Regards,
Xiang W
Quoted 47 lines
Regards,
AnupQuoted 43 lines
Regards,
Xiang WQuoted 38 lines
Quoted 38 lines
Regards,
Xiang WQuoted 32 lines
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity andnumber
of address bits")Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>---
?lib/sbi/sbi_hart.c | 4 ++++
?1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-0@@ -339,6 +339,10 @@ static unsigned longhart_pmp_get_allowed_addr (void) ??????? unsigned long val = 0; ??????? struct sbi_trap_info trap = {0}; +?????? csr_write_allowed(CSR_PMPCFG0, (ulong)&trap, 0); +?????? if (trap.cause) +?????????????? return 0; + ??????? csr_write_allowed(CSR_PMPADDR0, (ulong)&trap,PMP_ADDR_MASK );??????? if (!trap.cause) {
??????????????? val =csr_read_allowed(CSR_PMPADDR0, (ulong)&trap);
--
2.25.1
PATCH 1/1 lib: sbi: Fix PMP address bits detection
In reply to Anup PatelQuoted 10 lines · anup patel anup.patel at wdc.com
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>---
Looks good to me.
Quoted 26 lines
lib/sbi/sbi_hart.c| 4 ++++1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-1@@ -339,6 +339,10 @@ static unsigned long hart_pmp_get_allowed_addr(void)unsigned long val =0 ;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) { val =csr_read_allowed (CSR_PMPADDR0 , (ulong)&trap); --2.25.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedPATCH 1/1 lib: sbi: Fix PMP address bits detection
In reply to Anup PatelQuoted 10 lines · Anup Patel
From: Vasan VS <[email protected]>
We should ensure that pmpcfg0.pmp0cfg is set to zero before using pmpaddr0 CSR for detecting implemented PMP address bits.
Fixes bf21632860b4 ("lib: sbi: Detect PMP granularity and numberof address bits")
Signed-off-by Vasan VS <[email protected]>Signed-off-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo
Regards,
Anup
Quoted 22 lines
--- lib/sbi/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_hart.c +4
-1@@ -339,6 +339,10 @@ static unsigned long hart_pmp_get_allowed_addr(void)unsigned long val =0 ;struct sbi_trap_info trap = {0 }; +csr_write_allowed (CSR_PMPCFG0 , (ulong)&trap,0 ); +if (trap.cause) +return 0 ; +csr_write_allowed (CSR_PMPADDR0 , (ulong)&trap,PMP_ADDR_MASK );if (!trap.cause) { val =csr_read_allowed (CSR_PMPADDR0 , (ulong)&trap); --2.25.1