Skip to content

Conversation

@arichardson
Copy link
Member

No description provided.

atishp04 and others added 25 commits November 7, 2025 13:42
commit a46d410c5c19fa752d0ba03333e70170b8a6f57a upstream

Currently, the privileged specification version are defined in
a complex manner for no benefit.

Simplify it by changing it to a simple enum based on.

Suggested-by: Richard Henderson <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
commit 3a4af26d7a821b0299d25a2b002455899f1303ff upstream

Add the definition for ratified privileged specification version v1.12

Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
commit a4b2fa433125af0305b0695d7f8dda61db3364b0 upstream

To allow/disallow the CSR access based on the privilege spec, a new field
in the csr_ops is introduced. It also adds the privileged specification
version (v1.12) for the CSRs introduced in the v1.12. This includes the
new ratified extensions such as Vector, Hypervisor and secconfig CSR.
However, it doesn't enforce the privilege version in this commit.

Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
[ Changed CSR function table initialisation to use macros ]
Signed-off-by: Stuart Menefy <[email protected]>
commit 7100fe6c2441741ca6fa7c28b8a372d8ff7c2953 upstream

Virt machine uses privileged specification version 1.12 now.
All other machine continue to use the default one defined for that
machine unless changed to 1.12 by the user explicitly.

This commit enforces the privilege version for csrs introduced in
v1.12 or after.

Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
commit b1675eeb3e6e38b042a23a9647559c9c548c733d upstream

As per the privilege specification v1.11, mcountinhibit allows to start/stop
a pmu counter selectively.

Reviewed-by: Bin Meng <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
[ Changed CSR function table initialisations to use macros ]
Signed-off-by: Stuart Menefy <[email protected]>
commit 598ca8370634febb3438e7125278fd86b971a4a1 upstream

The minimum priv spec versino for mcountinhibit to v1.11 so that it
is not available for v1.10 (or lower).

Fixes: eab4776b2bad ("target/riscv: Add support for hpmcounters/hpmevents")
Signed-off-by: Anup Patel <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
[ Changed CSR function table initialisations to use macros ]
Signed-off-by: Stuart Menefy <[email protected]>
Add a henvcfg component to struct CPURISCVState.

This avoids a conflict when backporting the Zicboz extension.
This is gone in 0.9.6 so guard it with an ifdef
commit 29a9ec9bd8a7a7a4d98aa9a2260db6b2e815fb77 upstream

The RISC-V privileged specification v1.12 defines few execution
environment configuration CSRs that can be used enable/disable
extensions per privilege levels.

Add the basic support for these CSRs.

Reviewed-by: Alistair Francis <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
[ Changed CSR function table initialisations to use macros ]
Signed-off-by: Stuart Menefy <[email protected]>
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

Reviewed-by: Anup Patel <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Reviewed-by: Frank Chang <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
Tested-by: Bin Meng <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Suggested-by: Heiko Stubner <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from a775398be2e9ee2f2158dbdd0938593e3d002f62)
Signed-off-by: Stuart Menefy <[email protected]>
(Stuart: Removed extensions which aren't supported yet)
Now we have the ability to handle generic extension names has been
added to qemu and Linux, add the CHERI extension strings.

Signed-off-by: Stuart Menefy <[email protected]>
Add the zcherilevels extension to the isa string if this extension is
enabled.
The RISC-V base cache management operation (CBO) ISA extension has been
ratified. It defines three extensions: Cache-Block Management, Cache-Block
Prefetch and Cache-Block Zero. More information about the spec can be
found at [1].

Let's start by implementing the Cache-Block Zero extension, Zicboz. It
uses the cbo.zero instruction that, as with all CBO instructions that
will be added later, needs to be implemented in an overlap group with
the LQ instruction due to overlapping patterns.

cbo.zero throws a Illegal Instruction/Virtual Instruction exception
depending on CSR state. This is also the case for the remaining cbo
instructions we're going to add next, so create a check_zicbo_envcfg()
that will be used by all Zicbo[mz] instructions.

[1] https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.1.pdf

Reviewed-by: Richard Henderson <[email protected]>
Co-developed-by: Philipp Tomsich <[email protected]>
Signed-off-by: Christoph Muellner <[email protected]>
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Weiwei Li <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Palmer Dabbelt <[email protected]>

This is a manual backport of upstream commit a939c500793 ("target/riscv:
implement Zicboz extension").

Update the extension definition and properties for 6.x.
cpu_gpr[] is not used for cheri, use get_gpr to read a register value.
Zicbom is the Cache-Block Management extension defined in the already
ratified RISC-V Base Cache Management Operation (CBO) ISA extension [1].

The extension contains three instructions: cbo.clean, cbo.flush and
cbo.inval. All of them must be implemented in the same group as LQ and
cbo.zero due to overlapping patterns.

All these instructions can throw a Illegal Instruction/Virtual
Instruction exception, similar to the existing cbo.zero. The same
check_zicbo_envcfg() is used to handle these exceptions.

Aside from that, these instructions also need to handle page faults and
guest page faults. This is done in a new check_zicbom_access() helper.

As with Zicboz, the cache block size for Zicbom is also configurable.
Note that the spec determines that Zicbo[mp] and Zicboz can have
different cache sizes (Section 2.7 of [1]), so we also include a
'cbom_blocksize' to go along with the existing 'cboz_blocksize'. They
are set to the same size, so unless users want to play around with the
settings both sizes will be the same.

[1] https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.1.pdf

Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: Weiwei Li <[email protected]>
Co-developed-by: Philipp Tomsich <[email protected]>
Signed-off-by: Christoph Muellner <[email protected]>
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Palmer Dabbelt <[email protected]>

This is a manual backport of upstream commit e05da09b7cf ("target/riscv:
implement Zicbom extension").

Update the extension definition and properties for 6.x.
cpu_gpr[] is not used for cheri, use get_gpr to read a register value.
Explain the missing size parameter for probe_access_flags.
Check that the cache block size for cboz is a power of two.

The code for aligning the start address to the cache block size
requires this.

Define a macro, we need the same check for the cbom blocksize.
Check that the cache block size for cbom is a power of two.

The code for aligning the start address to the cache block size
requires this.

Use the existing macro for this check.
Move the code from helper_cbo_zero into do_cbo_zero. The latter can be
shared between the cheri and non-cheri cbo zero helpers.
Move some checks out of do_cbo_zero back into helper_cbo_zero.

We'll have two different cbo zero helpers for cheri and non-cheri, both
of which will call do_cbo_zero to do the actual zeroing.

The cheri helper must do things in this order

1.) check if the CSRs permit the cbo.zero
2.) align the address to the cache block size
3.) do cheri checks on the authorizing capability and the aligned address
4.) call do_cbo_zero

1.) and 2.) have to be done in the "upper" cheri/non-cheri helpers.
This patch moves them out of do_cbo_zero back into the non-cheri
helper. (The cheri helper will be added shortly.)
Add a helper function to emulate cbo.zero on a risc-v cheri system.

This helper works in both capability and integer pointer mode. It
performs the required cheri checks and passes the cache-block aligned
start address to do_cbo_zero, where the memory and the tags are erased.

Do the CSR checks first and abort if the cbo.zero instruction is not
allowed.

Co-authored-by: Alexander Richardson <[email protected]>
When we zero the memory region on a cheri system, we have to clear the
corresponding tags.

mem is a host memory pointer. Obtain its ram block. Protect the block
from being unlinked while we use it. Locate the tag memory for this ram
block and clear the tags for our region.
Upstream qemu added support for cbo.zero and introduced a helper that
receives the address from the rs1 register.

In order to support cheri, we added another cbo.zero helper for cheri
systems. It receives the (capability or integer) register number. We can
then read the register value (in integer pointer mode) or the authorizing
capability (in capability pointer mode).

This patch modifies trans_cbo_zero to call one of these two helper
depending on cheri support.
Co-authored-by: Martin Kaiser <[email protected]>
Co-authored-by: Paul Buxton <[email protected]>
Co-authored-by: Alexander Richardson <[email protected]>
Now qemu has the infrastructure to support privileged spec version 1.12
we can switch to the correct version.

Signed-off-by: Stuart Menefy <[email protected]>
@arichardson arichardson merged commit f486655 into CTSRD-CHERI:dev Nov 8, 2025
48 of 49 checks passed
@arichardson arichardson deleted the backport-priv-1-12 branch November 8, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants