Skip to contentSkip to conversation

lib: sbi: Enable Ssqosid Ext using mstateen0

PATCH Superseded [email protected] 2 participants 8 messages Nov 7, 2025 – Nov 11, 2025 RISC-V

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lib: sbi: Enable Ssqosid Ext using mstateen0

From: Chen Pei <[email protected]>

The QoS Identifiers extension (Ssqosid) introduces the srmcfg register, which configures a hart with two identifiers: a Resource Control ID (RCID) and a Monitoring Counter ID (MCID). These identifiers accompany each request issued by the hart to shared resource controllers.

If extension Smstateen is implemented together with Ssqosid, then Ssqosid also requires the SRMCFG bit in mstateen0 to be implemented. If mstateen0.SRMCFG is 0, attempts to access srmcfg in privilege modes less privileged than M-mode raise an illegal-instruction exception. If mstateen0.SRMCFG is 1 or if extension Smstateen is not implemented, attempts to access srmcfg when V=1 raise a virtual-instruction exception.

This extension can be found in the RISC-V Instruction Set Manual:
https://github.com/riscv/riscv-isa-manual

---
 include/sbi/riscv_encoding.h | 5 +++++
 include/sbi/sbi_hart.h       | 2 ++
 lib/sbi/sbi_domain_context.c | 7 ++++++-
 lib/sbi/sbi_hart.c           | 6 ++++++
 4 files changed, 19 insertions(+), 1 deletion(-)
include/sbi/riscv_encoding.h +5 -0
index 61e4b635..b738e209 100644
@@ -378,6 +378,9 @@
 #define CSR_SSTATEEN2			0x10E
 #define CSR_SSTATEEN3			0x10F
 
+/* Supervisor Resource Management Configuration CSRs */
+#define CSR_SRMCFG			0x181
+
 /* Machine-Level Control transfer records CSRs */
 #define CSR_MCTRCTL                     0x34e
 
@@ -849,6 +852,8 @@
 #define SMSTATEEN0_FCSR			(_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
 #define SMSTATEEN0_CTR_SHIFT		54
 #define SMSTATEEN0_CTR			(_ULL(1) << SMSTATEEN0_CTR_SHIFT)
+#define SMSTATEEN0_SRMCFG_SHIFT		55
+#define SMSTATEEN0_SRMCFG		(_ULL(1) << SMSTATEEN0_SRMCFG_SHIFT)
 #define SMSTATEEN0_CONTEXT_SHIFT	57
 #define SMSTATEEN0_CONTEXT		(_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
 #define SMSTATEEN0_IMSIC_SHIFT		58
include/sbi/sbi_hart.h +2 -0
index e66dd52f..c51b0689 100644
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
 	SBI_HART_EXT_SMCTR,
 	/** HART has CTR S-mode CSRs */
 	SBI_HART_EXT_SSCTR,
+	/** Hart has Ssqosid extension */
+	SBI_HART_EXT_SSQOSID,
 	/** HART has Ssstateen extension **/
 	SBI_HART_EXT_SSSTATEEN,
 	/** Hart has Xsfcflushdlone extension */
lib/sbi/sbi_domain_context.c +6 -1
index 74ad25e8..a5b7c530 100644
@@ -45,6 +45,8 @@ struct hart_context {
 	unsigned long scounteren;
 	/** Supervisor environment configuration register */
 	unsigned long senvcfg;
+	/** Supervisor resource management configuration register */
+	unsigned long srmcfg;
 
 	/** Reference to the owning domain */
 	struct sbi_domain *dom;
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	ctx->satp	= csr_swap(CSR_SATP, dom_ctx->satp);
 	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
 		ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
-	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
 		ctx->senvcfg	= csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+		if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+			ctx->srmcfg	= csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+	}
 
 	/* Save current trap state and restore target domain's trap state */
 	trap_ctx = sbi_trap_get_context(scratch);
lib/sbi/sbi_hart.c +6 -0
index a91703b4..549906f6 100644
@@ -112,6 +112,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
 		else
 			mstateen_val &= ~SMSTATEEN0_CTR;
 
+		if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+			mstateen_val |= (SMSTATEEN0_SRMCFG);
+		else
+			mstateen_val &= ~(SMSTATEEN0_SRMCFG);
+
 		csr_write64(CSR_MSTATEEN0, mstateen_val);
 		csr_write64(CSR_MSTATEEN1, SMSTATEEN_STATEN);
 		csr_write64(CSR_MSTATEEN2, SMSTATEEN_STATEN);
@@ -685,6 +690,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {
 	__SBI_HART_EXT_DATA(ssdbltrp, SBI_HART_EXT_SSDBLTRP),
 	__SBI_HART_EXT_DATA(smctr, SBI_HART_EXT_SMCTR),
 	__SBI_HART_EXT_DATA(ssctr, SBI_HART_EXT_SSCTR),
+	__SBI_HART_EXT_DATA(ssqosid, SBI_HART_EXT_SSQOSID),
 	__SBI_HART_EXT_DATA(ssstateen, SBI_HART_EXT_SSSTATEEN),
 	__SBI_HART_EXT_DATA(xsfcflushdlone, SBI_HART_EXT_XSIFIVE_CFLUSH_D_L1),
 	__SBI_HART_EXT_DATA(xsfcease, SBI_HART_EXT_XSIFIVE_CEASE),
Signature · 7 lines
2.50.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw
2025-11-07T16:32:00+08:00, <[email protected]>:
Quoted 21 lines

From: Chen Pei <[email protected]>

The QoS Identifiers extension (Ssqosid) introduces the srmcfg register, which configures a hart with two identifiers: a Resource Control ID (RCID) and a Monitoring Counter ID (MCID). These identifiers accompany each request issued by the hart to shared resource controllers.

If extension Smstateen is implemented together with Ssqosid, then Ssqosid also requires the SRMCFG bit in mstateen0 to be implemented. If mstateen0.SRMCFG is 0, attempts to access srmcfg in privilege modes less privileged than M-mode raise an illegal-instruction exception. If mstateen0.SRMCFG is 1 or if extension Smstateen is not implemented, attempts to access srmcfg when V=1 raise a virtual-instruction exception.

This extension can be found in the RISC-V Instruction Set Manual:
https://github.com/riscv/riscv-isa-manual

---

include/sbi/sbi_hart.h enum sbi_hart_extensions { · line 83

Quoted 5 lines
include/sbi/sbi_hart.h +2 -0
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
 	SBI_HART_EXT_SMCTR,
 	/** HART has CTR S-mode CSRs */
 	SBI_HART_EXT_SSCTR,
+	/** Hart has Ssqosid extension */
+	SBI_HART_EXT_SSQOSID,

Don't we also need something like

__check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN,

                  CSR_SRMCFG, SBI_HART_EXT_SSQOSID);

to detect the SSQOSID extension?

lib/sbi/sbi_domain_context.c static int switch_to_next_domain_context(struct hart_context *ctx, · line 152

Quoted 11 lines
lib/sbi/sbi_domain_context.c +4 -1
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	ctx->satp	= csr_swap(CSR_SATP, dom_ctx->satp);
 	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
 		ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
-	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
 		ctx->senvcfg	= csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+		if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+			ctx->srmcfg	= csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+	}

Why would we want Ssqosid to depend on S >= 1.12?

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 116

Quoted 7 lines
lib/sbi/sbi_hart.c +2 -0
@@ -112,6 +112,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
 		else
 			mstateen_val &= ~SMSTATEEN0_CTR;
 
+		if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+			mstateen_val |= (SMSTATEEN0_SRMCFG);

(Style nit: please remove parentheses arounds SMSTATEEN0_SRMCFG.)

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 118

Quoted 2 lines
lib/sbi/sbi_hart.c +2 -0
+		else
+			mstateen_val &= ~(SMSTATEEN0_SRMCFG);

The else branch is pointless, because the bit is known to be 0.

Thanks.

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw
Quoted 10 lines · Radim Krčmář

include/sbi/sbi_hart.h enum sbi_hart_extensions { · line 83

Quoted 7 lines
include/sbi/sbi_hart.h +2 -0
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
  SBI_HART_EXT_SMCTR,
  /** HART has CTR S-mode CSRs */
  SBI_HART_EXT_SSCTR,
+ /** Hart has Ssqosid extension */
+ SBI_HART_EXT_SSQOSID,

Don't we also need something like

Quoted 4 lines

__check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN,

                  CSR_SRMCFG, SBI_HART_EXT_SSQOSID);

to detect the SSQOSID extension?

Hi Radim,

I added this detection mechanism in the first patch, but Anup said, "For newer extensions, detecting from ISA strings is sufficient, so there's no need to trap-n-detect here." Therefore, it has been removed here.

Quoted 5 lines
Quoted 5 lines
lib/sbi/sbi_domain_context.c +0 -0
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
  ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
  if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
   ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
Quoted 8 lines

lib/sbi/sbi_domain_context.c static int switch_to_next_domain_context(struct hart_context *ctx, · line 152

Quoted 6 lines
lib/sbi/sbi_domain_context.c +4 -1
- if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
   ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+  if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+   ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ }

Why would we want Ssqosid to depend on S >= 1.12?

I'm guessing you read the RISC-V Instruction Set Manual, which describes ssqoid as requiring priv version 1.14. However, the highest priv version currently supported by OpenSBI is 1.12. Therefore, this implementation is based on the current situation, and the previous implementations such as CTR also follow this approach.

Quoted 9 lines

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 116

Quoted 7 lines
lib/sbi/sbi_hart.c +2 -0
@@ -112,6 +112,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
   else
    mstateen_val &= ~SMSTATEEN0_CTR;
 
+  if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+   mstateen_val |= (SMSTATEEN0_SRMCFG);

(Style nit: please remove parentheses arounds SMSTATEEN0_SRMCFG.)

Thank you for pointing this out.

Quoted 6 lines

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 118

Quoted 2 lines
lib/sbi/sbi_hart.c +2 -0
+  else
+   mstateen_val &= ~(SMSTATEEN0_SRMCFG);

The else branch is pointless, because the bit is known to be 0.

Thanks.

Here we need to consider the following scenario: even if HART supports the SSQOSID extension, but the user doesn't want to use this feature and removes the ssqosid field from the ISA string, then this bit needs to be explicitly cleared.

Thanks,
Pei

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw
2025-11-08T19:22:00+08:00, <[email protected]>:
Quoted 15 lines · Radim Krčmář
Quoted 13 lines

include/sbi/sbi_hart.h enum sbi_hart_extensions { · line 83

Quoted 8 lines
include/sbi/sbi_hart.h +2 -0
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
  SBI_HART_EXT_SMCTR,
  /** HART has CTR S-mode CSRs */
  SBI_HART_EXT_SSCTR,
+ /** Hart has Ssqosid extension */
+ SBI_HART_EXT_SSQOSID,

Don't we also need something like

__check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN,

                  CSR_SRMCFG, SBI_HART_EXT_SSQOSID);
Quoted 7 lines
Quoted 1 line

to detect the SSQOSID extension?

Hi Radim,

I added this detection mechanism in the first patch, but Anup said, "For newer extensions, detecting from ISA strings is sufficient, so there's no need to trap-n-detect here." Therefore, it has been removed here.

Ah, that is a great decision.

(I missed that this isn't the first version, please try to maintain a
changelog when posting subsequent modifications.)

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
lib/sbi/sbi_domain_context.c +0 -0
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
  ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
  if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
   ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
Quoted 8 lines

lib/sbi/sbi_domain_context.c static int switch_to_next_domain_context(struct hart_context *ctx, · line 152

Quoted 6 lines
lib/sbi/sbi_domain_context.c +4 -1
- if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
   ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+  if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+   ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ }

Why would we want Ssqosid to depend on S >= 1.12?

Quoted 4 lines

I'm guessing you read the RISC-V Instruction Set Manual, which describes ssqoid as requiring priv version 1.14. However, the highest priv version currently supported by OpenSBI is 1.12. Therefore, this implementation is based on the current situation, and the previous implementations such as CTR also follow this approach.

Does it? There is even a non-normative note:

The Ssqosid extension does not require that S-mode mode be implemented.

I think it's because srmcfg has effect on M-mode, so the extension is completely independent to allow it in pure M systems.

(We enable srmcfg in mstateen regardless of S version, so there is a
potential bug where we wouldn't correctly context switch the csr, given a system with weird combination of extensions.)

Quoted 7 lines
Quoted 6 lines

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 113

Quoted 4 lines
lib/sbi/sbi_hart.c +2 -0
@@ -112,6 +112,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
+  else
+   mstateen_val &= ~(SMSTATEEN0_SRMCFG);

The else branch is pointless, because the bit is known to be 0.

Quoted 5 lines
Quoted 1 line

Thanks.

Here we need to consider the following scenario: even if HART supports the SSQOSID extension, but the user doesn't want to use this feature and removes the ssqosid field from the ISA string, then this bit needs to be explicitly cleared.

We zero a zero bit. The code flows like this:

  mstateen_val = 0;
  ...
  mstateen_val &= ~(SMSTATEEN0_SRMCFG);

I would prefer if we didn't add the else branch, but I don't mind it too much either if that's the opensbi style.
(Optimizing compiler should generate the same code.)

Thanks.

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#4 lore raw
Quoted 17 lines · Radim Krčmář
Quoted 17 lines
Quoted 10 lines

include/sbi/sbi_hart.h enum sbi_hart_extensions { · line 83

Quoted 7 lines
include/sbi/sbi_hart.h +2 -0
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
  SBI_HART_EXT_SMCTR,
  /** HART has CTR S-mode CSRs */
  SBI_HART_EXT_SSCTR,
+ /** Hart has Ssqosid extension */
+ SBI_HART_EXT_SSQOSID,

Don't we also need something like

Quoted 4 lines

__check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN,

                  CSR_SRMCFG, SBI_HART_EXT_SSQOSID);

to detect the SSQOSID extension?

Hi Radim,

Quoted 8 lines
Quoted 3 lines

I added this detection mechanism in the first patch, but Anup said, "For newer extensions, detecting from ISA strings is sufficient, so there's no need to trap-n-detect here." Therefore, it has been removed here.

Ah, that is a great decision.

(I missed that this isn't the first version, please try to maintain a
changelog when posting subsequent modifications.)

Thanks for the reminder, I will keep a changelog in the next patch.

Quoted 22 lines
Quoted 15 lines
Quoted 14 lines

lib/sbi/sbi_domain_context.c static int switch_to_next_domain_context(struct hart_context *ctx, · line 152

Quoted 12 lines
lib/sbi/sbi_domain_context.c +4 -1
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
  ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
  if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
   ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
- if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
   ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+  if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+   ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ }

Why would we want Ssqosid to depend on S >= 1.12?

Quoted 4 lines

I'm guessing you read the RISC-V Instruction Set Manual, which describes ssqoid as requiring priv version 1.14. However, the highest priv version currently supported by OpenSBI is 1.12. Therefore, this implementation is based on the current situation, and the previous implementations such as CTR also follow this approach.

Does it? There is even a non-normative note:

Quoted 9 lines

The Ssqosid extension does not require that S-mode mode be implemented.

I think it's because srmcfg has effect on M-mode, so the extension is completely independent to allow it in pure M systems.

(We enable srmcfg in mstateen regardless of S version, so there is a
potential bug where we wouldn't correctly context switch the csr, given a system with weird combination of extensions.)

I have a different opinion on this point. This extension is basically unrelated to M-mode, instead, it runs in S-mode. It may be necessary to consider the background of ssqosid's introduction. This is to ensure that certain critical business processes can obtain sufficient hardware resources to run and thus guarantee service quality.

Similar technologies include Intel-RDT and ARM MPAM. On the Linux side, Drew has already submitted relevant patches [1]. It can be seen that in the future, it will inevitably be used in conjunction with Linux resctrl, so there is no need to consider the execution situation in M-mode, it is only necessary to enable the relevant permissions.

Quoted 19 lines
Quoted 7 lines
Quoted 6 lines

lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 113

Quoted 4 lines
lib/sbi/sbi_hart.c +2 -0
@@ -112,6 +112,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
+  else
+   mstateen_val &= ~(SMSTATEEN0_SRMCFG);

The else branch is pointless, because the bit is known to be 0.

Quoted 5 lines
Quoted 1 line

Thanks.

Here we need to consider the following scenario: even if HART supports the SSQOSID extension, but the user doesn't want to use this feature and removes the ssqosid field from the ISA string, then this bit needs to be explicitly cleared.

We zero a zero bit. The code flows like this:

  mstateen_val = 0;
  ...
  mstateen_val &= ~(SMSTATEEN0_SRMCFG);
Quoted 5 lines

I would prefer if we didn't add the else branch, but I don't mind it too much either if that's the opensbi style.
(Optimizing compiler should generate the same code.)

Thanks.

Yes, I'm just maintaining consistency with existing coding styles.

Thanks,
Pei

[1] https://lore.kernel.org/lkml/[email protected]/

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#5 lore raw
2025-11-10T20:31:15+08:00, <[email protected]>:
Quoted 5 lines · Radim Krčmář
Quoted 2 lines

(I missed that this isn't the first version, please try to maintain a
changelog when posting subsequent modifications.)

Thanks for the reminder, I will keep a changelog in the next patch.

(Appreciated. I would have searched mailbox before posting if I noticed
the v3 in the header, but having it summarized is even better.)

Quoted 21 lines
Quoted 21 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
lib/sbi/sbi_domain_context.c +0 -0
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
  ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
  if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
   ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
Quoted 8 lines

lib/sbi/sbi_domain_context.c static int switch_to_next_domain_context(struct hart_context *ctx, · line 152

Quoted 6 lines
lib/sbi/sbi_domain_context.c +4 -1
- if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
   ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+  if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+   ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ }

Why would we want Ssqosid to depend on S >= 1.12?

Quoted 4 lines

I'm guessing you read the RISC-V Instruction Set Manual, which describes ssqoid as requiring priv version 1.14. However, the highest priv version currently supported by OpenSBI is 1.12. Therefore, this implementation is based on the current situation, and the previous implementations such as CTR also follow this approach.

Does it? There is even a non-normative note:

Quoted 8 lines
Quoted 8 lines

The Ssqosid extension does not require that S-mode mode be implemented.

I think it's because srmcfg has effect on M-mode, so the extension is completely independent to allow it in pure M systems.

(We enable srmcfg in mstateen regardless of S version, so there is a
potential bug where we wouldn't correctly context switch the csr, given a system with weird combination of extensions.)

We might have taked past each other here.

I'm arguing that RISC-V allows a hart with ISA S1p11_Ssqosid to exist, because Ssqosid doesn't depend on S, so opensbi should context switch srmcfg on such potential (albeit unlikely) machine.

Otherwise domains could observe srmcfg set by other domains.

Quoted 8 lines

I have a different opinion on this point. This extension is basically unrelated to M-mode, instead, it runs in S-mode. It may be necessary to consider the background of ssqosid's introduction. This is to ensure that certain critical business processes can obtain sufficient hardware resources to run and thus guarantee service quality.

Similar technologies include Intel-RDT and ARM MPAM. On the Linux side, Drew has already submitted relevant patches [1]. It can be seen that in the future, it will inevitably be used in conjunction with Linux resctrl,

Yeah, I'm planning to look at the patches as well, because Ssqosid's design has a lot of potential for side-channels.

Quoted 2 lines

so there is no need to consider the execution
situation in M-mode, it is only necessary to enable the relevant permissions.

The execution of M-mode is affected by srmcfg, so we have to be extremely careful about isolation in opensbi too, especially when juggling multiple domains.

(I think we might be fine now, but having opensbi switch to a srmcfg
that isn't controlled by S-mode will result in a lot less headaches...)

Thanks.

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw
Quoted 30 lines · Radim Krčmář
Quoted 6 lines

I think it's because srmcfg has effect on M-mode, so the extension is completely independent to allow it in pure M systems.

(We enable srmcfg in mstateen regardless of S version, so there is a
potential bug where we wouldn't correctly context switch the csr, given a system with weird combination of extensions.)

We might have taked past each other here.

I'm arguing that RISC-V allows a hart with ISA S1p11_Ssqosid to exist, because Ssqosid doesn't depend on S, so opensbi should context switch srmcfg on such potential (albeit unlikely) machine.

Otherwise domains could observe srmcfg set by other domains.

Quoted 8 lines

I have a different opinion on this point. This extension is basically unrelated to M-mode, instead, it runs in S-mode. It may be necessary to consider the background of ssqosid's introduction. This is to ensure that certain critical business processes can obtain sufficient hardware resources to run and thus guarantee service quality.

Similar technologies include Intel-RDT and ARM MPAM. On the Linux side, Drew has already submitted relevant patches [1]. It can be seen that in the future, it will inevitably be used in conjunction with Linux resctrl,

Yeah, I'm planning to look at the patches as well, because Ssqosid's design has a lot of potential for side-channels.

Quoted 2 lines

so there is no need to consider the execution
situation in M-mode, it is only necessary to enable the relevant permissions.

Quoted 8 lines

The execution of M-mode is affected by srmcfg, so we have to be extremely careful about isolation in opensbi too, especially when juggling multiple domains.

(I think we might be fine now, but having opensbi switch to a srmcfg
that isn't controlled by S-mode will result in a lot less headaches...)

Thanks.

Indeed, strictly speaking, the execution of M-mode is also affected by srmcfg. When dealing with multiple domains, attention needs to be paid to isolation and context switching issues. I understand your point of view.

However, I wonder if it could be done in a later stage of the work, because there is currently a draft specification smmtt[1] that is also related to this. This extension involves multiple Supervisor Domains, and at this time, it is necessary to implement context switching of srmcfg between different domains.

Thanks,
Pei

[1] https://github.com/riscv/riscv-smmtt

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#7 lore raw
2025-11-11T17:49:36+08:00, <[email protected]>:
Quoted 13 lines · Radim Krčmář
Quoted 11 lines
Quoted 2 lines

so there is no need to consider the execution
situation in M-mode, it is only necessary to enable the relevant permissions.

The execution of M-mode is affected by srmcfg, so we have to be extremely careful about isolation in opensbi too, especially when juggling multiple domains.

(I think we might be fine now, but having opensbi switch to a srmcfg
that isn't controlled by S-mode will result in a lot less headaches...)

Thanks.

Quoted 8 lines

Indeed, strictly speaking, the execution of M-mode is also affected by srmcfg. When dealing with multiple domains, attention needs to be paid to isolation and context switching issues. I understand your point of view.

However, I wonder if it could be done in a later stage of the work, because there is currently a draft specification smmtt[1] that is also related to this. This extension involves multiple Supervisor Domains, and at this time, it is necessary to implement context switching of srmcfg between different domains.

I agree that we can return to that issue later, as it's not clearly buggy for now. For this patch, I would just like to fix the condition.

Thanks.

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi