Skip to contentSkip to conversation

RISC-V: minor fixes to the QEMU workaround in ISA string parser

PATCH Superseded Tsukasa OI 3 participants 10 messages Jul 22, 2023 – Jul 26, 2023 RISC-V

lore
Share & tools
lore

Tsukasa OI

author
#0 lore raw

cover RISC-V: minor fixes to the QEMU workaround in ISA string parser

Although hardly functional (mostly editorial), the author hopes this to be useful to give less confusion to kernel developers and improve the maintainability of the RISC-V ISA parser, including the QEMU-related workaround that is "fixed" by this patch set (intended for QEMU < v7.1).

v1:
(the initial submission; see the each PATCH for details)

Tsukasa OI (2):
RISC-V: make ISA string workaround case-insensitive
RISC-V: fix the comment for ISA string workaround

 arch/riscv/kernel/cpufeature.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 7 lines
2.40.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#1 lore raw

PATCH 1/2 RISC-V: make ISA string workaround case-insensitive

From: Tsukasa OI <[email protected]>

This is a follow-up for commit 255b34d799dd ("riscv: allow case-insensitive ISA string parsing").

Although the QEMU workaround in the ISA string parser works well with lowercase-only handling ('s' followed by 'u' and not preceded by '_'), case-sensitive handling in the case-insensitive parser can be confusing.

This commit makes the QEMU workaround case-insensitive and gives more robustness (against manually crafted Device Tree blobs) and less confusion to kernel developers.

---
 arch/riscv/kernel/cpufeature.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -2
index a8f66c015229..63277cdc1ea5 100644
@@ -168,19 +168,19 @@ void __init riscv_fill_hwcap(void)
 
 			switch (*ext) {
 			case 's':
+			case 'S':
 				/*
 				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
 				 * No need to set the bit in riscv_isa as 's' & 'u' are
 				 * not valid ISA extensions. It works until multi-letter
 				 * extension starting with "Su" appears.
 				 */
-				if (ext[-1] != '_' && ext[1] == 'u') {
+				if (ext[-1] != '_' && tolower(ext[1]) == 'u') {
 					++isa;
 					ext_err = true;
 					break;
 				}
 				fallthrough;
-			case 'S':
 			case 'x':
 			case 'X':
 			case 'z':
Signature · 7 lines
2.40.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw

Re: [PATCH 1/2] RISC-V: make ISA string workaround case-insensitive

Quoted 5 lines · Tsukasa OI

From: Tsukasa OI <[email protected]>

This is a follow-up for commit 255b34d799dd ("riscv: allow case-insensitive ISA string parsing").

Quoted 7 lines

Although the QEMU workaround in the ISA string parser works well with lowercase-only handling ('s' followed by 'u' and not preceded by '_'), case-sensitive handling in the case-insensitive parser can be confusing.

This commit makes the QEMU workaround case-insensitive and gives more robustness (against manually crafted Device Tree blobs) and less confusion to kernel developers.

If people are manually crafting their DT, they should check it for compliance with dt-validate (or dtbs_check). The case insensitivity only makes sense for ACPI, but by the time ACPI was supported, you'd already removed the "su" stuff from QEMU.

Thanks,
Conor.

Quoted 40 lines
---
 arch/riscv/kernel/cpufeature.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -2
index a8f66c015229..63277cdc1ea5 100644
@@ -168,19 +168,19 @@ void __init riscv_fill_hwcap(void)
 
 			switch (*ext) {
 			case 's':
+			case 'S':
 				/*
 				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
 				 * No need to set the bit in riscv_isa as 's' & 'u' are
 				 * not valid ISA extensions. It works until multi-letter
 				 * extension starting with "Su" appears.
 				 */
-				if (ext[-1] != '_' && ext[1] == 'u') {
+				if (ext[-1] != '_' && tolower(ext[1]) == 'u') {
 					++isa;
 					ext_err = true;
 					break;
 				}
 				fallthrough;
-			case 'S':
 			case 'x':
 			case 'X':
 			case 'z':
Signature · 7 lines
2.40.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#3 lore raw

PATCH 2/2 RISC-V: fix the comment for ISA string workaround

In reply to Tsukasa OI

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

This commit comes with another minor editorial fix.

---
 arch/riscv/kernel/cpufeature.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -4
index 63277cdc1ea5..91f1ef3e762c 100644
@@ -170,10 +170,11 @@ void __init riscv_fill_hwcap(void)
 			case 's':
 			case 'S':
 				/*
-				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
-				 * No need to set the bit in riscv_isa as 's' & 'u' are
-				 * not valid ISA extensions. It works until multi-letter
-				 * extension starting with "Su" appears.
+				 * Workaround for invalid single-letters 's' & 'u' (QEMU).
+				 * No need to set the bits in riscv_isa as 's' and 'u' are
+				 * not valid ISA extensions. It works unless the first multi-letter
+				 * extension in the ISA string begins with "Su" and not prefixed
+				 * with an underscore.
 				 */
 				if (ext[-1] != '_' && tolower(ext[1]) == 'u') {
 					++isa;
Signature · 7 lines
2.40.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] RISC-V: fix the comment for ISA string workaround

Quoted 20 lines · Tsukasa OI

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

Quoted 8 lines

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

This commit comes with another minor editorial fix.

Which is what?

The new wording is fine by me though..

Thanks,
Conor.

Quoted 33 lines
---
 arch/riscv/kernel/cpufeature.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -4
index 63277cdc1ea5..91f1ef3e762c 100644
@@ -170,10 +170,11 @@ void __init riscv_fill_hwcap(void)
 			case 's':
 			case 'S':
 				/*
-				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
-				 * No need to set the bit in riscv_isa as 's' & 'u' are
-				 * not valid ISA extensions. It works until multi-letter
-				 * extension starting with "Su" appears.
+				 * Workaround for invalid single-letters 's' & 'u' (QEMU).
+				 * No need to set the bits in riscv_isa as 's' and 'u' are
+				 * not valid ISA extensions. It works unless the first multi-letter
+				 * extension in the ISA string begins with "Su" and not prefixed
+				 * with an underscore.
 				 */
 				if (ext[-1] != '_' && tolower(ext[1]) == 'u') {
 					++isa;
Signature · 7 lines
2.40.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#5 lore raw

Re: [PATCH 2/2] RISC-V: fix the comment for ISA string workaround

Quoted 28 lines · Conor Dooley
Quoted 26 lines · Tsukasa OI

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

Quoted 6 lines
Quoted 1 line

This commit comes with another minor editorial fix.

Which is what?

The new wording is fine by me though..

1. Use of plurals ("letters" and "bits")
2. Second "'s' & 'u'" to "'s' and 'u'"
3. Spacing after the first "'s' & 'u'" (before "(QEMU).")

It feels they are too minor to separate to another commit. At least I should replace the commit message to "other minor editorial fixes" and... should I clarify editorial fixes?

Thanks,
Tsukasa

Quoted 33 lines

Thanks,
Conor.

Quoted 29 lines
---
 arch/riscv/kernel/cpufeature.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -4
index 63277cdc1ea5..91f1ef3e762c 100644
@@ -170,10 +170,11 @@ void __init riscv_fill_hwcap(void)
 			case 's':
 			case 'S':
 				/*
-				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
-				 * No need to set the bit in riscv_isa as 's' & 'u' are
-				 * not valid ISA extensions. It works until multi-letter
-				 * extension starting with "Su" appears.
+				 * Workaround for invalid single-letters 's' & 'u' (QEMU).
+				 * No need to set the bits in riscv_isa as 's' and 'u' are
+				 * not valid ISA extensions. It works unless the first multi-letter
+				 * extension in the ISA string begins with "Su" and not prefixed
+				 * with an underscore.
 				 */
 				if (ext[-1] != '_' && tolower(ext[1]) == 'u') {
 					++isa;
Signature · 1 line
2.40.0
Quoted 4 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw

Re: [PATCH 2/2] RISC-V: fix the comment for ISA string workaround

Quoted 38 lines · Tsukasa OI
Quoted 28 lines · Conor Dooley
Quoted 26 lines · Tsukasa OI

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

Quoted 6 lines
Quoted 1 line

This commit comes with another minor editorial fix.

Which is what?

The new wording is fine by me though..

Quoted 7 lines

1. Use of plurals ("letters" and "bits")
2. Second "'s' & 'u'" to "'s' and 'u'"
3. Spacing after the first "'s' & 'u'" (before "(QEMU).")

It feels they are too minor to separate to another commit. At least I should replace the commit message to "other minor editorial fixes" and... should I clarify editorial fixes?

I dunno, I just wasn't sure what you meant.

Quoted 4 lines
Quoted 4 lines

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 176

Quoted 4 lines
arch/riscv/kernel/cpufeature.c +4 -0
+				 * Workaround for invalid single-letters 's' & 'u' (QEMU).
+				 * No need to set the bits in riscv_isa as 's' and 'u' are
+				 * not valid ISA extensions. It works unless the first multi-letter
+				 * extension in the ISA string begins with "Su" and not prefixed

Re-reading I noticed this should be "is not prefixed".

Quoted 1 line
Quoted 1 line

arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 177

Quoted 1 line
arch/riscv/kernel/cpufeature.c +1 -0
+				 * with an underscore.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#7 lore raw

v2 cover RISC-V: clarification of the QEMU workaround in the ISA parser

In reply to Tsukasa OI

Hello,

This is the PATCH v2 to clarify the intent and a non-working example of the QEMU workaround in the RISC-V ISA parser. Along with comment fixes, I hope the commit message itself should be helpful to understand the workaround in the ISA string parser.

v1:
(the initial submission; see the each PATCH for details)

v2:
* PATCH 1/2 is withdrawn for now
(now only comment fix; previously PATCH 2/2)
* Other grammar fixes
* Clarification of the commit message

Tsukasa OI (1):
RISC-V: clarify the QEMU workaround in ISA parser

 arch/riscv/kernel/cpufeature.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 7 lines
2.41.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#8 lore raw

PATCH v2 1/1 RISC-V: clarify the QEMU workaround in ISA parser

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

This commit comes with other minor editorial fixes (for minor wording and spacing issues, without changing the meaning).

---
 arch/riscv/kernel/cpufeature.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -4
index a8f66c015229..5b2ac109980c 100644
@@ -169,10 +169,11 @@ void __init riscv_fill_hwcap(void)
 			switch (*ext) {
 			case 's':
 				/*
-				 * Workaround for invalid single-letter 's' & 'u'(QEMU).
-				 * No need to set the bit in riscv_isa as 's' & 'u' are
-				 * not valid ISA extensions. It works until multi-letter
-				 * extension starting with "Su" appears.
+				 * Workaround for invalid single-letters 's' & 'u' (QEMU).
+				 * No need to set the bits in riscv_isa as 's' and 'u' are
+				 * not valid ISA extensions. It works unless the first multi-letter
+				 * extension in the ISA string begins with "Su" and is not prefixed
+				 * with an underscore.
 				 */
 				if (ext[-1] != '_' && ext[1] == 'u') {
 					++isa;
Signature · 7 lines
2.41.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v2 1/1
#9 lore raw

Re: [PATCH v2 1/1] RISC-V: clarify the QEMU workaround in ISA parser

Quoted 22 lines · Tsukasa OI

From: Tsukasa OI <[email protected]>

Extensions prefixed with "Su" won't corrupt the workaround in many cases. The only exception is when the first multi-letter extension in the ISA string begins with "Su" and is not prefixed with an underscore.

For instance, following ISA string can confuse this QEMU workaround.

* "rv64imacsuclic" (RV64I + M + A + C + "Suclic")

However, this case is very unlikely because extensions prefixed by either "Z", "Sm" or "Ss" will most likely precede first.

For instance, the "Suclic" extension (draft as of now) will be placed after related "Smclic" and "Ssclic" extensions. It's also highly likely that other unprivileged extensions like "Zba" will precede.

It's also possible to suppress the issue in the QEMU workaround with an underscore. Following ISA string won't confuse the QEMU workaround.

* "rv64imac_suclic" (RV64I + M + A + C + delimited "Suclic")

Quoted 8 lines

This fix is to tell kernel developers the nature of this workaround precisely. There are some "Su*" extensions to be ratified but don't worry about this workaround too much.

This commit comes with other minor editorial fixes (for minor wording and spacing issues, without changing the meaning).

Pretty sure I gave you a Reviewed-by last time? Nevertheless,

Thanks,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv