All of lore.kernel.org
 help / color / mirror / Atom feed
From: Drew Fustini <fustini@kernel.org>
To: "Radim Krčmář" <rkrcmar@ventanamicro.com>
Cc: qemu-devel@nongnu.org, "Palmer Dabbelt" <palmer@dabbelt.com>,
	"Alistair Francis" <Alistair.Francis@wdc.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	qemu-riscv@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Nicolas Pitre" <npitre@baylibre.com>,
	"Kornel Dulęba" <mindal@semihalf.com>,
	"Atish Kumar Patra" <atishp@rivosinc.com>,
	"Atish Patra" <atish.patra@linux.dev>,
	"Vasudevan Srinivasan" <vasu@rivosinc.com>,
	"yunhui cui" <cuiyunhui@bytedance.com>,
	"Chen Pei" <cp0613@linux.alibaba.com>,
	guo.wenjia23@zte.com.cn, liu.qingtao2@zte.com.cn,
	qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org
Subject: Re: [PATCH 1/7] riscv: implement Ssqosid extension and srmcfg CSR
Date: Thu, 20 Nov 2025 12:46:46 -0800	[thread overview]
Message-ID: <aR9+NoQVkxq3mcP6@x1> (raw)
In-Reply-To: <DEDNGGQCPNKP.25HNT2IHYB0C2@ventanamicro.com>

On Thu, Nov 20, 2025 at 05:07:03PM +0100, Radim Krčmář wrote:

Thanks for the review!

> 2025-11-19T16:42:17-08:00, Drew Fustini <fustini@kernel.org>:
> > From: Kornel Dulęba <mindal@semihalf.com>
> >
> > Implement the srmcfg CSR defined by the Ssqosid ISA extension
> > (Supervisor-mode Quality of Service ID). The CSR contains two fields:
> >
> >   - Resource Control ID (RCID) used determine resource allocation
> >   - Monitoring Counter ID (MCID) used to track resource usage
> >
> > The CSR is defined for S-mode but accessing it when V=1 shall cause a
> > virtual instruction exception. Implement this behavior by calling the
> > hmode predicate.
> >
> > Link: https://github.com/riscv-non-isa/riscv-cbqri/releases/download/v1.0/riscv-cbqri.pdf
> > Signed-off-by: Kornel Dulęba <mindal@semihalf.com>
> > [fustini: rebase on v10.1.50, fix check_srmcfg]
> > Signed-off-by: Drew Fustini <fustini@kernel.org>
> > ---
> > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > @@ -216,6 +216,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
> >      ISA_EXT_DATA_ENTRY(ssdbltrp, PRIV_VERSION_1_13_0, ext_ssdbltrp),
> >      ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm),
> >      ISA_EXT_DATA_ENTRY(sspm, PRIV_VERSION_1_13_0, ext_sspm),
> > +    ISA_EXT_DATA_ENTRY(ssqosid, PRIV_VERSION_1_12_0, ext_ssqosid),
> 
> Just out of curiosity, where does PRIV_VERSION_1_12_0 come from?

Ssqosid was originally ratified as a separate document but it since was
add to the Privileged Architecture document [1]. However, the Supervisor
Level ISA was version 1.13 when Ssqosid was added, so I should change
the above to PRIV_VERSION_1_13_0.

> 
> > diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> > @@ -1759,6 +1759,37 @@ static RISCVException write_stimecmph(CPURISCVState *env, int csrno,
> > +static RISCVException check_srmcfg(CPURISCVState *env, int csrno)
> > +{
> > +    RISCVCPU *cpu = env_archcpu(env);
> > +
> > +    if (!cpu->cfg.ext_ssqosid) {
> > +        return RISCV_EXCP_ILLEGAL_INST;
> > +    }
> > +
> > +    /*
> > +     * Even though this is an S-mode CSR the spec says that we need to throw
> > +     * and virt instruction fault if a guest tries to access it.
> > +     */
> > +    return env->virt_enabled ?
> > +           RISCV_EXCP_VIRT_INSTRUCTION_FAULT : smode(env, csrno);
> > +}
> 
> The check is missing interaction with mstateen0.SRMCFG.

Good point. It looks like I should check mstateen0.SRMCFG which it bit
55. I'll add something like the following to the next revision:

---------------------------------------------------------------------
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index ebb400bf6f2c..bd73f9232d70 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -359,6 +359,7 @@
 #define SMSTATEEN0_FCSR     (1ULL << 1)
 #define SMSTATEEN0_JVT      (1ULL << 2)
 #define SMSTATEEN0_CTR      (1ULL << 54)
+#define SMSTATEEN0_SRMCFG   (1ULL << 55)
 #define SMSTATEEN0_P1P13    (1ULL << 56)
 #define SMSTATEEN0_HSCONTXT (1ULL << 57)
 #define SMSTATEEN0_IMSIC    (1ULL << 58)
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 06a6212c672d..8f609e826fcd 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1767,6 +1767,11 @@ static RISCVException check_srmcfg(CPURISCVState *env, int csrno)
         return RISCV_EXCP_ILLEGAL_INST;
     }

+    RISCVException ret = smstateen_acc_ok(env, 0, SMSTATEEN0_SRMCFG);
+    if (ret != RISCV_EXCP_NONE) {
+        return ret;
+    }
+
     /*
      * Even though this is an S-mode CSR the spec says that we need to throw
      * and virt instruction fault if a guest tries to access it.
---------------------------------------------------------------------

Thanks
Drew

[1] https://docs.riscv.org/reference/isa/priv/supervisor.html#ssqosid
[2] https://docs.riscv.org/reference/isa/priv/smstateen.html#state-enable-0-registersmstateen0.SRMCFG


  reply	other threads:[~2025-11-20 20:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20  0:42 [PATCH 0/7] riscv: implement Ssqosid extension and CBQRI controllers Drew Fustini
2025-11-20  0:42 ` [PATCH 1/7] riscv: implement Ssqosid extension and srmcfg CSR Drew Fustini
2025-11-20 11:30   ` Daniel Henrique Barboza
2025-11-20 21:34     ` Drew Fustini
2025-11-20 16:07   ` Radim Krčmář
2025-11-20 20:46     ` Drew Fustini [this message]
2025-11-24 16:54       ` Radim Krčmář
2025-11-20  0:42 ` [PATCH 2/7] hw/riscv: define capabilities of CBQRI controllers Drew Fustini
2025-11-20 11:59   ` Daniel Henrique Barboza
2025-11-20  0:42 ` [PATCH 3/7] hw/riscv: implement CBQRI capacity controller Drew Fustini
2025-11-20 11:47   ` Daniel Henrique Barboza
2025-11-21 18:57     ` Drew Fustini
2025-11-20 19:25   ` Radim Krčmář
2025-11-21 19:50     ` Drew Fustini
2025-11-24 17:02       ` Radim Krčmář
2025-11-24 18:37         ` Drew Fustini
2025-11-25 11:55           ` Radim Krčmář
2025-11-20  0:42 ` [PATCH 4/7] hw/riscv: implement CBQRI bandwidth controller Drew Fustini
2025-11-20 11:51   ` Daniel Henrique Barboza
2025-11-24 17:06   ` Radim Krčmář
2025-11-24 18:45     ` Drew Fustini
2025-11-20  0:42 ` [PATCH 5/7] hw/riscv: Kconfig: add CBQRI options Drew Fustini
2025-11-20  0:42 ` [PATCH 6/7] hw/riscv: meson: add CBQRI controllers to the build Drew Fustini
2025-11-20 12:01   ` Daniel Henrique Barboza
2025-11-20 20:56     ` Drew Fustini
2025-11-20  0:42 ` [PATCH 7/7] hw/riscv: add CBQRI controllers to virt machine Drew Fustini
2025-11-20 12:01   ` Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aR9+NoQVkxq3mcP6@x1 \
    --to=fustini@kernel.org \
    --cc=Alistair.Francis@wdc.com \
    --cc=atish.patra@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=cp0613@linux.alibaba.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=guo.wenjia23@zte.com.cn \
    --cc=liu.qingtao2@zte.com.cn \
    --cc=liwei1518@gmail.com \
    --cc=mindal@semihalf.com \
    --cc=npitre@baylibre.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=rkrcmar@ventanamicro.com \
    --cc=vasu@rivosinc.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.