qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis <alistair23@gmail.com>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
	alistair.francis@wdc.com,  bmeng@tinylab.org,
	liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com,
	 palmer@rivosinc.com, ajones@ventanamicro.com,
	vladimir.isaev@syntacore.com
Subject: Re: [PATCH v3 04/16] target/riscv: move 'mmu' to riscv_cpu_properties[]
Date: Fri, 5 Jan 2024 15:00:00 +1000	[thread overview]
Message-ID: <CAKmqyKOT6JRsh=4zWVBTSHNKYF1kU1f+5YcnA==-5FSTbWhAkQ@mail.gmail.com> (raw)
In-Reply-To: <20240103174013.147279-5-dbarboza@ventanamicro.com>

On Thu, Jan 4, 2024 at 3:43 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Commit 7f0bdfb5bfc ("target/riscv/cpu.c: remove cfg setup from
> riscv_cpu_init()") already did some of the work by making some
> cpu_init() functions to explictly enable their own 'mmu' default.
>
> The generic CPUs didn't get update by that commit, so they are still
> relying on the defaults set by the 'mmu' option. But having 'mmu' and
> 'pmp' being default=true will force CPUs that doesn't implement these
> options to set them to 'false' in their cpu_init(), which isn't ideal.
>
> We'll move 'mmu' to riscv_cpu_properties[] without any defaults, i.e.
> the default will be 'false'. Compensate it by manually setting 'mmu =
> true' to the generic CPUs that requires it.
>
> Implement a setter for it to forbid the 'mmu' setting to be changed for
> vendor CPUs. This will allow the option to exist for all CPUs and, at
> the same time, protect vendor CPUs from undesired changes:
>
> $ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,mmu=true
> qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.mmu=true:
>    CPU 'sifive-e51' does not allow changing the value of 'mmu'
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/cpu.c | 55 ++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 51 insertions(+), 4 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index e90b70c0a7..9f1407b73f 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -419,6 +419,8 @@ static void riscv_max_cpu_init(Object *obj)
>      CPURISCVState *env = &cpu->env;
>      RISCVMXL mlx = MXL_RV64;
>
> +    cpu->cfg.mmu = true;
> +
>  #ifdef TARGET_RISCV32
>      mlx = MXL_RV32;
>  #endif
> @@ -433,7 +435,11 @@ static void riscv_max_cpu_init(Object *obj)
>  #if defined(TARGET_RISCV64)
>  static void rv64_base_cpu_init(Object *obj)
>  {
> -    CPURISCVState *env = &RISCV_CPU(obj)->env;
> +    RISCVCPU *cpu = RISCV_CPU(obj);
> +    CPURISCVState *env = &cpu->env;
> +
> +    cpu->cfg.mmu = true;
> +
>      /* We set this in the realise function */
>      riscv_cpu_set_misa(env, MXL_RV64, 0);
>      /* Set latest version of privileged specification */
> @@ -551,13 +557,18 @@ static void rv64_veyron_v1_cpu_init(Object *obj)
>
>  static void rv128_base_cpu_init(Object *obj)
>  {
> +    RISCVCPU *cpu = RISCV_CPU(obj);
> +    CPURISCVState *env = &cpu->env;
> +
>      if (qemu_tcg_mttcg_enabled()) {
>          /* Missing 128-bit aligned atomics */
>          error_report("128-bit RISC-V currently does not work with Multi "
>                       "Threaded TCG. Please use: -accel tcg,thread=single");
>          exit(EXIT_FAILURE);
>      }
> -    CPURISCVState *env = &RISCV_CPU(obj)->env;
> +
> +    cpu->cfg.mmu = true;
> +
>      /* We set this in the realise function */
>      riscv_cpu_set_misa(env, MXL_RV128, 0);
>      /* Set latest version of privileged specification */
> @@ -569,7 +580,11 @@ static void rv128_base_cpu_init(Object *obj)
>  #else
>  static void rv32_base_cpu_init(Object *obj)
>  {
> -    CPURISCVState *env = &RISCV_CPU(obj)->env;
> +    RISCVCPU *cpu = RISCV_CPU(obj);
> +    CPURISCVState *env = &cpu->env;
> +
> +    cpu->cfg.mmu = true;
> +
>      /* We set this in the realise function */
>      riscv_cpu_set_misa(env, MXL_RV32, 0);
>      /* Set latest version of privileged specification */
> @@ -1550,8 +1565,38 @@ static const PropertyInfo prop_pmu_mask = {
>      .set = prop_pmu_mask_set,
>  };
>
> +static void prop_mmu_set(Object *obj, Visitor *v, const char *name,
> +                         void *opaque, Error **errp)
> +{
> +    RISCVCPU *cpu = RISCV_CPU(obj);
> +    bool value;
> +
> +    visit_type_bool(v, name, &value, errp);
> +
> +    if (cpu->cfg.mmu != value && riscv_cpu_is_vendor(obj)) {
> +        cpu_set_prop_err(cpu, "mmu", errp);
> +        return;
> +    }
> +
> +    cpu_option_add_user_setting(name, value);
> +    cpu->cfg.mmu = value;
> +}
> +
> +static void prop_mmu_get(Object *obj, Visitor *v, const char *name,
> +                         void *opaque, Error **errp)
> +{
> +    bool value = RISCV_CPU(obj)->cfg.mmu;
> +
> +    visit_type_bool(v, name, &value, errp);
> +}
> +
> +static const PropertyInfo prop_mmu = {
> +    .name = "mmu",
> +    .get = prop_mmu_get,
> +    .set = prop_mmu_set,
> +};
> +
>  Property riscv_cpu_options[] = {
> -    DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
>      DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
>
>      DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
> @@ -1572,6 +1617,8 @@ static Property riscv_cpu_properties[] = {
>      {.name = "pmu-mask", .info = &prop_pmu_mask},
>      {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
>
> +    {.name = "mmu", .info = &prop_mmu},
> +
>  #ifndef CONFIG_USER_ONLY
>      DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
>  #endif
> --
> 2.43.0
>
>


  reply	other threads:[~2024-01-05  5:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 17:39 [PATCH v3 00/16] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
2024-01-03 17:39 ` [PATCH v3 01/16] target/riscv/cpu_cfg.h: remove unused fields Daniel Henrique Barboza
2024-01-05  3:51   ` Alistair Francis
2024-01-03 17:39 ` [PATCH v3 02/16] target/riscv: make riscv_cpu_is_generic() public Daniel Henrique Barboza
2024-01-05  3:51   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 03/16] target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05  3:55   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 04/16] target/riscv: move 'mmu' " Daniel Henrique Barboza
2024-01-05  5:00   ` Alistair Francis [this message]
2024-01-03 17:40 ` [PATCH v3 05/16] target/riscv: move 'pmp' " Daniel Henrique Barboza
2024-01-05  5:03   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 06/16] target/riscv: rework 'priv_spec' Daniel Henrique Barboza
2024-01-05  4:23   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 07/16] target/riscv: rework 'vext_spec' Daniel Henrique Barboza
2024-01-05  5:15   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 08/16] target/riscv: move 'vlen' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05  5:05   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 09/16] target/riscv: move 'elen' " Daniel Henrique Barboza
2024-01-05  5:17   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 10/16] target/riscv: create finalize_features() for KVM Daniel Henrique Barboza
2024-01-05  4:54   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 11/16] target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05  4:56   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 12/16] target/riscv: move 'cboz_blocksize' " Daniel Henrique Barboza
2024-01-05  4:57   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 13/16] target/riscv: remove riscv_cpu_options[] Daniel Henrique Barboza
2024-01-05  5:01   ` Alistair Francis
2024-01-03 17:40 ` [PATCH v3 14/16] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-03 17:40 ` [PATCH v3 15/16] target/riscv/cpu.c: move 'mimpid' " Daniel Henrique Barboza
2024-01-03 17:40 ` [PATCH v3 16/16] target/riscv/cpu.c: move 'marchid' " 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='CAKmqyKOT6JRsh=4zWVBTSHNKYF1kU1f+5YcnA==-5FSTbWhAkQ@mail.gmail.com' \
    --to=alistair23@gmail.com \
    --cc=ajones@ventanamicro.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng@tinylab.org \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@rivosinc.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=vladimir.isaev@syntacore.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 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).