qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-7.1 v6 26/51] target/nios2: Prevent writes to read-only o


From: Peter Maydell
Subject: Re: [PATCH for-7.1 v6 26/51] target/nios2: Prevent writes to read-only or reserved control fields
Date: Thu, 17 Mar 2022 15:49:45 +0000

On Thu, 17 Mar 2022 at 05:53, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Create an array of masks which detail the writable and readonly
> bits for each control register.  Apply them when writing to
> control registers, including the write to status during eret.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> @@ -34,6 +34,15 @@ void helper_raise_exception(CPUNios2State *env, uint32_t 
> index)
>  #ifndef CONFIG_USER_ONLY
>  void helper_eret(CPUNios2State *env, uint32_t new_status, uint32_t new_pc)
>  {
> +    Nios2CPU *cpu = env_archcpu(env);
> +
> +    /*
> +     * Both estatus and bstatus have no constraints on write;
> +     * do not allow reserved fields in status to be set.
> +     */
> +    new_status &= (cpu->cr_state[CR_STATUS].writable |
> +                   cpu->cr_state[CR_STATUS].readonly);
> +
>      env->ctrl[CR_STATUS] = new_status;

Isn't this allowing the guest to write to readonly bits ?

>      env->pc = new_pc;
>      cpu_loop_exit(env_cpu(env));

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]