From: Alistair Francis <alistair23@gmail.com>
To: Alexey Baturo <baturo.alexey@gmail.com>
Cc: richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com,
palmer@dabbelt.com, Alistair.Francis@wdc.com,
sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de,
qemu-devel@nongnu.org, qemu-riscv@nongnu.org
Subject: Re: [PATCH v4 2/6] target/riscv: Add new CSR fields for S{sn, mn, m}pm extensions as part of Zjpm v0.8
Date: Mon, 22 Jan 2024 17:04:49 +1000 [thread overview]
Message-ID: <CAKmqyKNRk_on+ZqKBGGhmXnwLNdmHhXoXK+yTr5p3FEhezOJxg@mail.gmail.com> (raw)
In-Reply-To: <20240109102930.405323-3-me@deliversmonkey.space>
On Tue, Jan 9, 2024 at 8:32 PM Alexey Baturo <baturo.alexey@gmail.com> wrote:
>
> From: Alexey Baturo <baturo.alexey@gmail.com>
>
> Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.h | 8 ++++++++
> target/riscv/cpu_bits.h | 3 +++
> target/riscv/cpu_cfg.h | 3 +++
> target/riscv/csr.c | 11 +++++++++++
> target/riscv/machine.c | 10 +++++++---
> target/riscv/pmp.c | 13 ++++++++++---
> target/riscv/pmp.h | 11 ++++++-----
> 7 files changed, 48 insertions(+), 11 deletions(-)
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index a43c8fba57..c9bed5c9fc 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -101,6 +101,14 @@ typedef enum {
> EXT_STATUS_DIRTY,
> } RISCVExtStatus;
>
> +/* Enum holds PMM field values for Zjpm v0.8 extension */
> +typedef enum {
> + PMM_FIELD_DISABLED = 0,
> + PMM_FIELD_RESERVED = 1,
> + PMM_FIELD_PMLEN7 = 2,
> + PMM_FIELD_PMLEN16 = 3,
> +} RISCVPmPmm;
> +
> #define MMU_USER_IDX 3
>
> #define MAX_RISCV_PMPS (16)
> diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> index 1c92458a01..7cf1049bf4 100644
> --- a/target/riscv/cpu_bits.h
> +++ b/target/riscv/cpu_bits.h
> @@ -715,6 +715,7 @@ typedef enum RISCVException {
> #define MENVCFG_CBIE (3UL << 4)
> #define MENVCFG_CBCFE BIT(6)
> #define MENVCFG_CBZE BIT(7)
> +#define MENVCFG_PMM (3ULL << 32)
> #define MENVCFG_ADUE (1ULL << 61)
> #define MENVCFG_PBMTE (1ULL << 62)
> #define MENVCFG_STCE (1ULL << 63)
> @@ -728,11 +729,13 @@ typedef enum RISCVException {
> #define SENVCFG_CBIE MENVCFG_CBIE
> #define SENVCFG_CBCFE MENVCFG_CBCFE
> #define SENVCFG_CBZE MENVCFG_CBZE
> +#define SENVCFG_PMM MENVCFG_PMM
>
> #define HENVCFG_FIOM MENVCFG_FIOM
> #define HENVCFG_CBIE MENVCFG_CBIE
> #define HENVCFG_CBCFE MENVCFG_CBCFE
> #define HENVCFG_CBZE MENVCFG_CBZE
> +#define HENVCFG_PMM MENVCFG_PMM
> #define HENVCFG_ADUE MENVCFG_ADUE
> #define HENVCFG_PBMTE MENVCFG_PBMTE
> #define HENVCFG_STCE MENVCFG_STCE
> diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
> index f4605fb190..201f8af6ae 100644
> --- a/target/riscv/cpu_cfg.h
> +++ b/target/riscv/cpu_cfg.h
> @@ -113,6 +113,9 @@ struct RISCVCPUConfig {
> bool ext_ssaia;
> bool ext_sscofpmf;
> bool ext_smepmp;
> + bool ext_ssnpm;
> + bool ext_smnpm;
> + bool ext_smmpm;
> bool rvv_ta_all_1s;
> bool rvv_ma_all_1s;
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index ea4e1ac6ef..a67ba30494 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -527,6 +527,9 @@ static RISCVException have_mseccfg(CPURISCVState *env, int csrno)
> if (riscv_cpu_cfg(env)->ext_zkr) {
> return RISCV_EXCP_NONE;
> }
> + if (riscv_cpu_cfg(env)->ext_smmpm) {
> + return RISCV_EXCP_NONE;
> + }
>
> return RISCV_EXCP_ILLEGAL_INST;
> }
> @@ -2030,6 +2033,10 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
> (cfg->ext_sstc ? MENVCFG_STCE : 0) |
> (cfg->ext_svadu ? MENVCFG_ADUE : 0);
> }
> + /* Update PMM field only if the value is valid according to Zjpm v0.8 */
> + if (((val & MENVCFG_PMM) >> 32) != PMM_FIELD_RESERVED) {
> + mask |= MENVCFG_PMM;
> + }
> env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
>
> return RISCV_EXCP_NONE;
> @@ -2074,6 +2081,10 @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno,
> target_ulong val)
> {
> uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE;
> + /* Update PMM field only if the value is valid according to Zjpm v0.8 */
> + if (((val & SENVCFG_PMM) >> 32) != PMM_FIELD_RESERVED) {
> + mask |= SENVCFG_PMM;
> + }
> RISCVException ret;
>
> ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG);
> diff --git a/target/riscv/machine.c b/target/riscv/machine.c
> index 71ee8bab19..0ad593ed5a 100644
> --- a/target/riscv/machine.c
> +++ b/target/riscv/machine.c
> @@ -152,15 +152,19 @@ static const VMStateDescription vmstate_vector = {
>
> static bool pointermasking_needed(void *opaque)
> {
> - return false;
> + RISCVCPU *cpu = opaque;
> + return cpu->cfg.ext_ssnpm || cpu->cfg.ext_smnpm || cpu->cfg.ext_smmpm;
> }
>
> static const VMStateDescription vmstate_pointermasking = {
> .name = "cpu/pointer_masking",
> - .version_id = 1,
> - .minimum_version_id = 1,
> + .version_id = 2,
> + .minimum_version_id = 2,
> .needed = pointermasking_needed,
> .fields = (VMStateField[]) {
> + VMSTATE_UINTTL(env.mseccfg, RISCVCPU),
> + VMSTATE_UINTTL(env.senvcfg, RISCVCPU),
> + VMSTATE_UINTTL(env.menvcfg, RISCVCPU),
> VMSTATE_END_OF_LIST()
> }
> };
> diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> index 162e88a90a..893ccd58d8 100644
> --- a/target/riscv/pmp.c
> +++ b/target/riscv/pmp.c
> @@ -576,6 +576,12 @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index)
> void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
> {
> int i;
> + uint64_t mask = MSECCFG_MMWP | MSECCFG_MML;
> +
> + /* Update PMM field only if the value is valid according to Zjpm v0.8 */
> + if (((val & MSECCFG_PMM) >> 32) != PMM_FIELD_RESERVED) {
> + mask |= MSECCFG_PMM;
> + }
>
> trace_mseccfg_csr_write(env->mhartid, val);
>
> @@ -591,12 +597,13 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
>
> if (riscv_cpu_cfg(env)->ext_smepmp) {
> /* Sticky bits */
> - val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML));
> - if ((val ^ env->mseccfg) & (MSECCFG_MMWP | MSECCFG_MML)) {
> + val |= (env->mseccfg & mask);
> + if ((val ^ env->mseccfg) & mask) {
> tlb_flush(env_cpu(env));
> }
> } else {
> - val &= ~(MSECCFG_MMWP | MSECCFG_MML | MSECCFG_RLB);
> + mask |= MSECCFG_RLB;
> + val &= ~(mask);
> }
>
> env->mseccfg = val;
> diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
> index 9af8614cd4..b3ca51c26d 100644
> --- a/target/riscv/pmp.h
> +++ b/target/riscv/pmp.h
> @@ -40,11 +40,12 @@ typedef enum {
> } pmp_am_t;
>
> typedef enum {
> - MSECCFG_MML = 1 << 0,
> - MSECCFG_MMWP = 1 << 1,
> - MSECCFG_RLB = 1 << 2,
> - MSECCFG_USEED = 1 << 8,
> - MSECCFG_SSEED = 1 << 9
> + MSECCFG_MML = 1 << 0,
> + MSECCFG_MMWP = 1 << 1,
> + MSECCFG_RLB = 1 << 2,
> + MSECCFG_USEED = 1 << 8,
> + MSECCFG_SSEED = 1 << 9,
> + MSECCFG_PMM = 3UL << 32,
> } mseccfg_field_t;
>
> typedef struct {
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2024-01-22 7:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 10:29 [PATCH v4 0/6] Pointer Masking update for Zjpm v0.8 Alexey Baturo
2024-01-09 10:29 ` [PATCH v4 1/6] target/riscv: Remove obsolete pointer masking extension code Alexey Baturo
2024-01-22 6:53 ` Alistair Francis
2024-01-09 10:29 ` [PATCH v4 2/6] target/riscv: Add new CSR fields for S{sn, mn, m}pm extensions as part of Zjpm v0.8 Alexey Baturo
2024-01-22 7:04 ` Alistair Francis [this message]
2024-01-09 10:29 ` [PATCH v4 3/6] target/riscv: Add helper functions to calculate current number of masked bits for pointer masking Alexey Baturo
2024-01-18 17:21 ` Deepak Gupta
2024-01-18 20:50 ` Richard Henderson
2024-01-18 22:40 ` Deepak Gupta
2024-01-20 7:37 ` Richard Henderson
2024-01-21 7:13 ` Alexey Baturo
2024-01-23 17:44 ` Deepak Gupta
2024-01-09 10:29 ` [PATCH v4 4/6] target/riscv: Add pointer masking tb flags Alexey Baturo
2024-01-22 7:01 ` Alistair Francis
2024-01-09 10:29 ` [PATCH v4 5/6] target/riscv: Update address modify functions to take into account pointer masking Alexey Baturo
2024-01-22 7:01 ` Alistair Francis
2024-01-09 10:29 ` [PATCH v4 6/6] target/riscv: Enable updates for pointer masking variables and thus enable pointer masking extension Alexey Baturo
2024-01-22 6:54 ` Alistair Francis
2024-01-22 6:52 ` [PATCH v4 0/6] Pointer Masking update for Zjpm v0.8 Alistair Francis
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=CAKmqyKNRk_on+ZqKBGGhmXnwLNdmHhXoXK+yTr5p3FEhezOJxg@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=Alistair.Francis@wdc.com \
--cc=baturo.alexey@gmail.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sagark@eecs.berkeley.edu \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).