Skip to contentSkip to conversation

target/riscv: Add isa extenstion strings to the device tree

PATCH Superseded Atish Patra 7 participants 15 messages Feb 22, 2022 – Mar 8, 2022 RISC-V

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 target/riscv: Add isa extenstion strings to the device tree

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +29 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
Signature · 1 line
2.30.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Atish Patra

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Quoted 7 lines

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

Looks good to me.

Regards,
Anup

Quoted 71 lines

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +29 -1
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

Reviewed-by on v3 1/1
#2 lore raw
In reply to Atish Patra
Quoted 6 lines · Atish Patra

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Quoted 7 lines

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

Alistair

Quoted 71 lines

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +29 -1
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#3 lore raw
In reply to Atish Patra

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 48 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +7 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void
 *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void · line 901

Quoted 10 lines
target/riscv/cpu.c +8 -0
 max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },
 

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +13 -0
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+

char *riscv_isa_string(RISCVCPU *cpu)

 {
     int i;
target/riscv/cpu.c +1 -1
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#4 lore raw
Quoted 51 lines · Frank Chang

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 47 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
Quoted 14 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 9 lines
target/riscv/cpu.c +9 -0
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Do we really need it ? Does any OS actually parse it from the device tree ? AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software, I prefer to avoid bloating if possible.

Quoted 3 lines

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

Signature · 2 lines
Regards,
Atish
#5 lore raw

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 64 lines · Frank Chang
Quoted 48 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 47 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
Quoted 14 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 9 lines
target/riscv/cpu.c +9 -0
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Quoted 4 lines

Do we really need it ? Does any OS actually parse it from the device tree ? AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Heiko

Quoted 41 lines
Quoted 3 lines

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#6 lore raw
Quoted 80 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 1 line

On Fri, Feb 25, 2022 at 11:46 PM Frank Chang <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 7 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA

extensions

Quoted 1 line
Quoted 1 line
Quoted 1 line

to the "riscv,isa" string if it is enabled so that kernel can process

it.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual

check

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
Quoted 2 lines
Quoted 2 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c,

Quoted 2 lines
target/riscv/cpu.c +0 -0
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c,

void *data)

Quoted 4 lines
Quoted 4 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data)

Quoted 4 lines
target/riscv/cpu.c +1 -0
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int

max_str_len)

Quoted 11 lines
Quoted 11 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 8 lines
target/riscv/cpu.c +8 -0
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs...

etc.

Quoted 4 lines
Quoted 2 lines

Do you mind adding them as well?

Do we really need it ? Does any OS actually parse it from the device

tree ?

Quoted 3 lines

AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 7 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 3 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 52 lines

Heiko

Quoted 1 line
Quoted 1 line

Also, I think the order of ISA strings should be alphabetical as

described:

Quoted 1 line
Quoted 1 line

https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Quoted 39 lines
Quoted 1 line

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#7 lore raw
Quoted 92 lines · Atish Kumar Patra
Quoted 80 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 1 line

On Fri, Feb 25, 2022 at 11:46 PM Frank Chang <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 7 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA

extensions

Quoted 1 line
Quoted 1 line
Quoted 1 line

to the "riscv,isa" string if it is enabled so that kernel can

process it.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Changes from v1->v2:
1. Improved the code redability by using arrays instead of

individual check

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
Quoted 2 lines
Quoted 2 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass

Quoted 2 lines
target/riscv/cpu.c +0 -0
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass

*c, void *data)

Quoted 4 lines
Quoted 4 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data)

Quoted 4 lines
target/riscv/cpu.c +1 -0
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int

max_str_len)

Quoted 11 lines
Quoted 11 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 8 lines
target/riscv/cpu.c +8 -0
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs...

etc.

Quoted 4 lines
Quoted 2 lines

Do you mind adding them as well?

Do we really need it ? Does any OS actually parse it from the device

tree ?

Quoted 3 lines

AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 7 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 9 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications.
It really depends on how the application is written.

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

Regards,
Frank Chang

Quoted 70 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 3 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 53 lines

Heiko

Quoted 1 line
Quoted 1 line

Also, I think the order of ISA strings should be alphabetical as

described:

Quoted 1 line
Quoted 1 line

https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Quoted 14 lines
Quoted 1 line

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 9 lines

Regards,
Frank Chang

Quoted 6 lines
target/riscv/cpu.c +5 -0
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name,

NULL);

Quoted 25 lines
Quoted 22 lines
Quoted 22 lines
target/riscv/cpu.c +9 -1
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#8 lore raw
Quoted 94 lines · Frank Chang
Quoted 85 lines · Atish Kumar Patra
Quoted 73 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 64 lines · Frank Chang
Quoted 48 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 47 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
Quoted 14 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 9 lines
target/riscv/cpu.c +9 -0
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Quoted 4 lines

Do we really need it ? Does any OS actually parse it from the device tree ? AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 6 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 5 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Quoted 6 lines

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications. It really depends on how the application is written.

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

I agree. Adding all enabled extensions in ISA string is aligned with what this patch is doing so no harm in updating this patch.

Regards,
Anup

Quoted 69 lines

Regards,
Frank Chang

Quoted 65 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 3 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 50 lines

Heiko

Quoted 41 lines
Quoted 3 lines

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#9 lore raw
In reply to Frank Chang
Quoted 105 lines · Frank Chang
Quoted 92 lines · Atish Kumar Patra
Quoted 80 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 1 line

On Fri, Feb 25, 2022 at 11:46 PM Frank Chang <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 7 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA

extensions

Quoted 1 line
Quoted 1 line
Quoted 1 line

to the "riscv,isa" string if it is enabled so that kernel can

process it.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Changes from v1->v2:
1. Improved the code redability by using arrays instead of

individual check

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
Quoted 2 lines
Quoted 2 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass

Quoted 2 lines
target/riscv/cpu.c +0 -0
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass

*c, void *data)

Quoted 4 lines
Quoted 4 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data)

Quoted 4 lines
target/riscv/cpu.c +1 -0
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str,

int max_str_len)

Quoted 11 lines
Quoted 11 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 8 lines
target/riscv/cpu.c +8 -0
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs...

etc.

Quoted 4 lines
Quoted 2 lines

Do you mind adding them as well?

Do we really need it ? Does any OS actually parse it from the device

tree ?

Quoted 3 lines

AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 7 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 9 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Quoted 9 lines

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications.
It really depends on how the application is written.

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

Fair enough. I will update the patch to include all the extension available.

Quoted 75 lines

Regards,
Frank Chang

Quoted 71 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 4 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 53 lines

Heiko

Quoted 1 line
Quoted 1 line

Also, I think the order of ISA strings should be alphabetical as

described:

Quoted 1 line
Quoted 1 line

https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Quoted 14 lines
Quoted 1 line

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 9 lines

Regards,
Frank Chang

Quoted 6 lines
target/riscv/cpu.c +5 -0
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name,

NULL);

Quoted 25 lines
Quoted 22 lines
Quoted 22 lines
target/riscv/cpu.c +9 -1
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#10 lore raw
Quoted 116 lines · Atish Kumar Patra
Quoted 112 lines · Frank Chang
Quoted 94 lines · Atish Kumar Patra
Quoted 82 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 1 line

On Fri, Feb 25, 2022 at 11:46 PM Frank Chang <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 4 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was

proposed[1]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA

extensions

Quoted 1 line
Quoted 1 line
Quoted 1 line

to the "riscv,isa" string if it is enabled so that kernel can

process it.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length

as

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of

individual check

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
Quoted 2 lines
Quoted 2 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass

Quoted 2 lines
target/riscv/cpu.c +0 -0
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass

*c, void *data)

Quoted 4 lines
Quoted 4 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass · line 890

Quoted 4 lines
target/riscv/cpu.c +1 -0
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str,

int max_str_len)

Quoted 11 lines
Quoted 11 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass · line 898

Quoted 8 lines
target/riscv/cpu.c +8 -0
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs...

etc.

Quoted 4 lines
Quoted 2 lines

Do you mind adding them as well?

Do we really need it ? Does any OS actually parse it from the device

tree ?

Quoted 3 lines

AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 7 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 9 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications.
It really depends on how the application is written.

Quoted 9 lines
Quoted 4 lines

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

Fair enough. I will update the patch to include all the extension available.

Thanks, that would be great.

BTW, I think current QEMU RISC-V isa string includes both "s" and "u":
https://github.com/qemu/qemu/blob/master/target/riscv/cpu.c#L37
But in fact, they should not be presented in the DTS isa string. Do you think we should exclude them as well?

Regards,
Frank Chang

Quoted 76 lines
Quoted 76 lines

Regards,
Frank Chang

Quoted 71 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 4 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 53 lines

Heiko

Quoted 1 line
Quoted 1 line

Also, I think the order of ISA strings should be alphabetical as

described:

Quoted 1 line
Quoted 1 line

https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Quoted 14 lines
Quoted 1 line

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 9 lines

Regards,
Frank Chang

Quoted 6 lines
target/riscv/cpu.c +5 -0
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name,

NULL);

Quoted 25 lines
Quoted 22 lines
Quoted 22 lines
target/riscv/cpu.c +9 -1
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#11 lore raw
Quoted 112 lines · Frank Chang
Quoted 102 lines · Atish Kumar Patra
Quoted 98 lines · Frank Chang
Quoted 85 lines · Atish Kumar Patra
Quoted 73 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 64 lines · Frank Chang
Quoted 48 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 47 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
Quoted 14 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 9 lines
target/riscv/cpu.c +9 -0
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Quoted 4 lines

Do we really need it ? Does any OS actually parse it from the device tree ? AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 6 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 5 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications. It really depends on how the application is written.

Quoted 6 lines
Quoted 2 lines

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

Fair enough. I will update the patch to include all the extension available.

Quoted 7 lines

Thanks, that would be great.

BTW, I think current QEMU RISC-V isa string includes both "s" and "u":
https://github.com/qemu/qemu/blob/master/target/riscv/cpu.c#L37
But in fact, they should not be presented in the DTS isa string. Do you think we should exclude them as well?

There is a patch in the mailing list fixing that issue

https://lists.nongnu.org/archive/html/qemu-riscv/2022-02/msg00099.html

Quoted 73 lines

Regards,
Frank Chang

Quoted 70 lines
Quoted 70 lines

Regards,
Frank Chang

Quoted 65 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 3 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 50 lines

Heiko

Quoted 41 lines
Quoted 3 lines

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

Signature · 2 lines
Regards,
Atish
#12 lore raw
Quoted 122 lines · Atish Patra
Quoted 112 lines · Frank Chang
Quoted 102 lines · Atish Kumar Patra
Quoted 98 lines · Frank Chang
Quoted 85 lines · Atish Kumar Patra
Quoted 73 lines · Heiko Stuebner

Hi,

Am Donnerstag, 3. März 2022, 19:58:38 CET schrieb Atish Patra:

Quoted 64 lines · Frank Chang
Quoted 48 lines

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 47 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
Quoted 14 lines

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 9 lines
target/riscv/cpu.c +9 -0
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Quoted 4 lines

Do we really need it ? Does any OS actually parse it from the device tree ? AFAIK, Linux kernel doesn't use them. As the device tree is intended to keep the information useful
for supervisor software,

Quoted 6 lines

That actually isn't true ;-) .

The devicetree is intended to _describe_ the hardware present in full and has really nothing to do with what the userspace needs. So the argument "Linux doesn't need this" is never true when talking about devicetrees ;-) .

Quoted 5 lines

Yes. I didn’t mean that way. I was simply asking if these extensions currently in use. I just mentioned Linux as an example.

The larger point I was trying to make if we should add all the supported extensions when they are added to Qemu or on a need basis.

I don’t feel strongly either way. So I am okay with the former approach if that’s what everyone prefers!

Linux Kernel itself might not,
but userspace applications may query /proc/cpuinfo to get core's capabilities, e.g. for those vector applications. It really depends on how the application is written.

Quoted 6 lines
Quoted 2 lines

I still think adding all the enabled extensions into the isa string would be a proper solution, no matter they are used or not. However, we can leave that beyond this patch.

Fair enough. I will update the patch to include all the extension available.

Quoted 7 lines

Thanks, that would be great.

BTW, I think current QEMU RISC-V isa string includes both "s" and "u":
https://github.com/qemu/qemu/blob/master/target/riscv/cpu.c#L37
But in fact, they should not be presented in the DTS isa string. Do you think we should exclude them as well?

Quoted 4 lines

There is a patch in the mailing list fixing that issue

https://lists.nongnu.org/archive/html/qemu-riscv/2022-02/msg00099.html

I just realized that it was only sent to [email protected] not qemu-devel.

@Tsukasa OI : Can you please send it again to both qemu-riscv & qemu-devel so that it is accessible to the broader qemu community.

Quoted 78 lines
Quoted 73 lines

Regards,
Frank Chang

Quoted 70 lines
Quoted 70 lines

Regards,
Frank Chang

Quoted 65 lines
Quoted 5 lines

On the other hand the devicetree user doesn't need to parse everything from DT. So adding code to parse things only really is needed if you need that information.

Agreed.

Quoted 3 lines

So if some part of the kernel needs to know about those additional extensions, the array entries for them can also be added in a later patch.

Yes. That was the idea in isa extension framework series where the extension specific array entries will only be added when support for that extension is enabled.

Quoted 50 lines

Heiko

Quoted 41 lines
Quoted 3 lines

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Ahh yes. I will order them in alphabetical order and leave a big comment for future reference as well.

Quoted 31 lines

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

--
Regards,
Atish

Signature · 2 lines
Regards,
Atish
#13 lore raw
In reply to Frank Chang

Typo in patch title:
s/extenstion/extension/g

Regards,
Frank Chang

Quoted 103 lines · Frank Chang

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 50 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions
to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +7 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c,
 void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, · line 901

Quoted 10 lines
target/riscv/cpu.c +8 -0
 max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },
 

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +13 -0
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+

char *riscv_isa_string(RISCVCPU *cpu)

 {
     int i;
target/riscv/cpu.c +1 -1
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

#14 lore raw
Quoted 4 lines · Frank Chang

Typo in patch title:
s/extenstion/extension/g

Thanks for catching it. Will fix it.

Quoted 103 lines

Regards,
Frank Chang

Quoted 99 lines · Frank Chang

Atish Patra <[email protected]> 於 2022年2月23日 週三 上午6:39寫道:

Quoted 46 lines

The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well.

Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it.

[1] https://lkml.org/lkml/2022/2/15/263

---
Changes from v2->v3:
1. Used g_strconcat to replace snprintf & a max isa string length as suggested by Anup.
2. I have not included the Tested-by Tag from Heiko because the implementation changed from v2 to v3.

Changes from v1->v2:
1. Improved the code redability by using arrays instead of individual check

---
 target/riscv/cpu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
target/riscv/cpu.c +6 -0
index b0a40b83e7a8..2c7ff6ef555a 100644
@@ -34,6 +34,12 @@
 
 /* RISC-V CPU definitions */
 
+/* This includes the null terminated character '\0' */
+struct isa_ext_data {
+        const char *name;
+        bool enabled;
+};
+
 static const char riscv_exts[26] = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 
 const char * const riscv_int_regnames[] = {
@@ -881,6 +887,28 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
     device_class_set_props(dc, riscv_cpu_properties);
 }

target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data) · line 898

Quoted 10 lines
target/riscv/cpu.c +9 -0
 
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+    char *old = *isa_str;
+    char *new = *isa_str;
+    int i;
+    struct isa_ext_data isa_edata_arr[] = {
+        { "svpbmt", cpu->cfg.ext_svpbmt   },
+        { "svinval", cpu->cfg.ext_svinval },
+        { "svnapot", cpu->cfg.ext_svnapot },

We still have other sub-extensions, e.g. Zfh, Zba, Zbb, Zbc, Zbs... etc. Do you mind adding them as well?

Also, I think the order of ISA strings should be alphabetical as described:
https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L96

Regards,
Frank Chang

Quoted 28 lines
target/riscv/cpu.c +14 -1
+    };
+
+    for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+        if (isa_edata_arr[i].enabled) {
+            new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+            g_free(old);
+            old = new;
+        }
+    }
+
+    *isa_str = new;
+}
+
 char *riscv_isa_string(RISCVCPU *cpu)
 {
     int i;
@@ -893,6 +921,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
         }
     }
     *p = '\0';
+    riscv_isa_string_ext(cpu, &isa_str, maxlen);
     return isa_str;
 }
 
--

2.30.2

Signature · 2 lines
Regards,
Atish