All of lore.kernel.org
 help / color / mirror / Atom feed
From: Drew Fustini <fustini@kernel.org>
To: Alistair Francis <Alistair.Francis@wdc.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"mindal@semihalf.com" <mindal@semihalf.com>,
	"sunilvl@oss.qualcomm.com" <sunilvl@oss.qualcomm.com>,
	"zhiwei_liu@linux.alibaba.com" <zhiwei_liu@linux.alibaba.com>,
	"liu.qingtao2@zte.com.cn" <liu.qingtao2@zte.com.cn>,
	"anup.patel@oss.qualcomm.com" <anup.patel@oss.qualcomm.com>,
	"cp0613@linux.alibaba.com" <cp0613@linux.alibaba.com>,
	"palmer@dabbelt.com" <palmer@dabbelt.com>,
	"daniel.barboza@oss.qualcomm.com"
	<daniel.barboza@oss.qualcomm.com>,
	"radim.krcmar@oss.qualcomm.com" <radim.krcmar@oss.qualcomm.com>,
	"qemu-riscv@nongnu.org" <qemu-riscv@nongnu.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"guo.wenjia23@zte.com.cn" <guo.wenjia23@zte.com.cn>,
	"npitre@baylibre.com" <npitre@baylibre.com>,
	"cuiyunhui@bytedance.com" <cuiyunhui@bytedance.com>,
	"atish.patra@linux.dev" <atish.patra@linux.dev>,
	"liwei1518@gmail.com" <liwei1518@gmail.com>,
	"chao.liu@processmission.com" <chao.liu@processmission.com>
Subject: Re: [PATCH v6 1/6] riscv: implement Ssqosid extension and srmcfg CSR
Date: Tue, 27 Oct 2026 19:59:16 -0700	[thread overview]
Message-ID: <auFlBAtOZSw94vnk@thelio> (raw)
In-Reply-To: <20219a9e5fcaf2f50eee2bd123a12a04c05cb97a.camel@wdc.com>

On Tue, Oct 27, 2026 at 12:22:02AM +0000, Alistair Francis wrote:
> On Mon, 2026-10-26 at 10:47 -0700, Drew Fustini wrote:
> > 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, so check mstateen0.srmcfg to determine
> > if s-mode is allowed to access it. In addition, accessing it when V=1
> > shall cause a virtual instruction exception.
> > 
> > Link:
> > https://github.com/riscv-non-isa/riscv-cbqri/releases/download/v1.0/riscv-cbqri.pdf
> > Link: https://docs.riscv.org/reference/isa/priv/smstateen.html
> > Signed-off-by: Kornel Dulęba <mindal@semihalf.com>
> > [fustini: rebase on v10.1.50, fix check_srmcfg]
> > Reviewed-by: Radim Krčmář <radim.krcmar@oss.qualcomm.com>
> > Signed-off-by: Drew Fustini <fustini@kernel.org>
> 
> I'm just meat proxying this one, but it looks believable, let me know
> if it's wrong though:

Is this something I can run myself in the future?

I can run local sashiko for my linux patches but I wasn't sure what to
do for qemu.

> - [HIGH] In target/riscv/tcg/csr.c, none of write_mstateen0,
> write_mstateen0h, write_hstateen0, or write_hstateen0h ever ORs
> SMSTATEEN0_SRMCFG into wr_mask when ext_ssqosid is set, so bit 55 of
> mstateen0/hstateen0 stays read-only zero and M-mode firmware writes
> that enable srmcfg access are silently dropped, violating the
> Smstateen spec (a bit for an implemented extension must not be
> read-only zero). check_srmcfg gates the new CSR on
> smstateen_acc_ok(..., SMSTATEEN0_SRMCFG), and Smstateen is enabled by
> default on the same dynamic CPUs that get ext_ssqosid by default, so
> on the stock virt machine every S-mode (V=0) srmcfg access traps
> illegal instruction and VS-mode additionally takes a virtual
> instruction fault: the QoS feature this series exists to expose is
> systematically unusable. Fix by ORing the bit into the stateen write
> masks like the existing CTR, P1P13, and SVSLCT cases.

This is a real issue for mstateen0 and mstateen0h. I will add
SMSTATEEN0_SRMCFG to wr_mask in write_mstateen0() and
write_mstateen0h(). However, I believe hstateen0 bit 55 is WPRI so I
think the current behavior is correct.

> - [MEDIUM] In target/riscv/cpu.h, env->srmcfg is new guest-writable
>   architected state (written via write_srmcfg in
>   target/riscv/tcg/csr.c) but target/riscv/machine.c never migrates
>   it: vmstate_riscv_cpu has no ssqosid/srmcfg field or subsection.
>   After live migration, savevm/loadvm, or snapshot restore the
>   destination CPU resumes with srmcfg = 0 while the guest believes its
>   programmed RCID/MCID are still in effect. Add a versioned
>   vmstate_ssqosid subsection with a .needed predicate on ext_ssqosid,
>   following the vmstate_smstateen/vmstate_envcfg pattern.

I'll add a VMStateDescription for Ssqosid.

> - [MEDIUM] In target/riscv/cpu.c (isa_edata_arr), Ssqosid is
> registered as a user-facing extension and enabled by default on
> BASE32/BASE64 with no tests/tcg coverage anywhere in the tree. The
> RISC-V upstreaming rules require unit tests for new extensions' CSR
> accesses, and the stateen gating and V=1 trap paths added in
> check_srmcfg are exactly what such tests would exercise -- they would
> have caught the broken SRMCFG stateen bit above. Add tests/tcg cases
> for srmcfg read/write, WARL masking, and the
> stateen/virtual-instruction-fault gating.

I'll add tests for srmcfg.

> - [LOW] nit: in target/riscv/tcg/csr.c, the check_srmcfg comment says
>   "we need to throw and virt instruction fault"; s/and virt/a virtual/.

I'll fix.

Thanks,
Drew


  reply	other threads:[~2026-10-28  3:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 17:47 [PATCH v6 0/6] riscv: implement Ssqosid extension and CBQRI controllers Drew Fustini
2026-10-26 17:47 ` [PATCH v6 1/6] riscv: implement Ssqosid extension and srmcfg CSR Drew Fustini
2026-10-27  0:22   ` Alistair Francis
2026-10-28  2:59     ` Drew Fustini [this message]
2026-10-28  3:55       ` Alistair Francis
2026-10-26 17:47 ` [PATCH v6 2/6] hw/riscv: define capabilities of CBQRI controllers Drew Fustini
2026-10-26 17:47 ` [PATCH v6 3/6] hw/riscv: implement CBQRI capacity controller Drew Fustini
2026-10-28 13:32   ` Prajwal N
2026-10-29 23:46     ` Drew Fustini
2026-10-26 17:47 ` [PATCH v6 4/6] hw/riscv: implement CBQRI bandwidth controller Drew Fustini
2026-10-27  0:18   ` Alistair Francis
2026-10-29 21:00     ` Drew Fustini
2026-10-26 17:47 ` [PATCH v6 5/6] hw/riscv: add CBQRI to Kconfig and build if enabled Drew Fustini
2026-10-26 17:47 ` [PATCH v6 6/6] hw/riscv: add CBQRI controllers to virt machine Drew Fustini
2026-10-28 13:56   ` Prajwal N
2026-10-30  0:18     ` Drew Fustini

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=auFlBAtOZSw94vnk@thelio \
    --to=fustini@kernel.org \
    --cc=Alistair.Francis@wdc.com \
    --cc=anup.patel@oss.qualcomm.com \
    --cc=atish.patra@linux.dev \
    --cc=chao.liu@processmission.com \
    --cc=cp0613@linux.alibaba.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=daniel.barboza@oss.qualcomm.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@nongnu.org \
    --cc=radim.krcmar@oss.qualcomm.com \
    --cc=sunilvl@oss.qualcomm.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.