diff mbox series

[01/18] target/riscv: gdbstub: Check priv spec version before reporting CSR

Message ID 20230213180215.1524938-2-bmeng@tinylab.org
State New
Headers show
Series target/riscv: Various fixes to gdbstub and CSR access | expand

Commit Message

Bin Meng Feb. 13, 2023, 6:01 p.m. UTC
The gdbstub CSR XML is dynamically generated according to the result
of the CSR predicate() result. This has been working fine until
commit 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
introduced the privilege spec version check in riscv_csrrw_check().

When debugging the 'sifive_u' machine whose priv spec is at 1.10,
gdbstub reports priv spec 1.12 CSRs like menvcfg in the XML, hence
we see "remote failure reply 'E14'" message when examining all CSRs
via "info register system" from gdb.

Add the priv spec version check in the CSR XML generation logic to
fix this issue.

Fixes: 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
Signed-off-by: Bin Meng <bmeng@tinylab.org>
---

 target/riscv/gdbstub.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Weiwei Li Feb. 14, 2023, 8:40 a.m. UTC | #1
On 2023/2/14 02:01, Bin Meng wrote:
> The gdbstub CSR XML is dynamically generated according to the result
> of the CSR predicate() result. This has been working fine until
> commit 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
> introduced the privilege spec version check in riscv_csrrw_check().
>
> When debugging the 'sifive_u' machine whose priv spec is at 1.10,
> gdbstub reports priv spec 1.12 CSRs like menvcfg in the XML, hence
> we see "remote failure reply 'E14'" message when examining all CSRs
> via "info register system" from gdb.
>
> Add the priv spec version check in the CSR XML generation logic to
> fix this issue.
>
> Fixes: 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
> Signed-off-by: Bin Meng <bmeng@tinylab.org>

Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>

Regards,
Weiwei Li
> ---
>
>   target/riscv/gdbstub.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
> index 6e7bbdbd5e..e57372db38 100644
> --- a/target/riscv/gdbstub.c
> +++ b/target/riscv/gdbstub.c
> @@ -290,6 +290,9 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)
>       g_string_append_printf(s, "<feature name=\"org.gnu.gdb.riscv.csr\">");
>   
>       for (i = 0; i < CSR_TABLE_SIZE; i++) {
> +        if (env->priv_ver < csr_ops[i].min_priv_ver) {
> +            continue;
> +        }
>           predicate = csr_ops[i].predicate;
>           if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) {
>               if (csr_ops[i].name) {
LIU Zhiwei Feb. 17, 2023, 2:11 a.m. UTC | #2
On 2023/2/14 2:01, Bin Meng wrote:
> The gdbstub CSR XML is dynamically generated according to the result
> of the CSR predicate() result. This has been working fine until
> commit 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
> introduced the privilege spec version check in riscv_csrrw_check().
>
> When debugging the 'sifive_u' machine whose priv spec is at 1.10,
> gdbstub reports priv spec 1.12 CSRs like menvcfg in the XML, hence
> we see "remote failure reply 'E14'" message when examining all CSRs
> via "info register system" from gdb.
>
> Add the priv spec version check in the CSR XML generation logic to
> fix this issue.
>
> Fixes: 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")
> Signed-off-by: Bin Meng <bmeng@tinylab.org>
> ---
>
>   target/riscv/gdbstub.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
> index 6e7bbdbd5e..e57372db38 100644
> --- a/target/riscv/gdbstub.c
> +++ b/target/riscv/gdbstub.c
> @@ -290,6 +290,9 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)
>       g_string_append_printf(s, "<feature name=\"org.gnu.gdb.riscv.csr\">");
>   
>       for (i = 0; i < CSR_TABLE_SIZE; i++) {
> +        if (env->priv_ver < csr_ops[i].min_priv_ver) {
> +            continue;
> +        }
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>

Zhiwei

>           predicate = csr_ops[i].predicate;
>           if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) {
>               if (csr_ops[i].name) {
diff mbox series

Patch

diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
index 6e7bbdbd5e..e57372db38 100644
--- a/target/riscv/gdbstub.c
+++ b/target/riscv/gdbstub.c
@@ -290,6 +290,9 @@  static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)
     g_string_append_printf(s, "<feature name=\"org.gnu.gdb.riscv.csr\">");
 
     for (i = 0; i < CSR_TABLE_SIZE; i++) {
+        if (env->priv_ver < csr_ops[i].min_priv_ver) {
+            continue;
+        }
         predicate = csr_ops[i].predicate;
         if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) {
             if (csr_ops[i].name) {