qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH 06/10] target/arm: Move arm_current_el() and arm_el_is_aa64() to internals.h
Date: Thu, 6 Mar 2025 14:40:59 -0800	[thread overview]
Message-ID: <a378cc0e-07fa-4514-8cd9-8826502e534a@linaro.org> (raw)
In-Reply-To: <20250306163925.2940297-7-peter.maydell@linaro.org>

On 3/6/25 08:39, Peter Maydell wrote:
> The functions arm_current_el() and arm_el_is_aa64() are used only in
> target/arm and in hw/intc/arm_gicv3_cpuif.c.  They're functions that
> query internal state of the CPU.  Move them out of cpu.h and into
> internals.h.
> 
> This means we need to include internals.h in arm_gicv3_cpuif.c, but
> this is justifiable because that file is implementing the GICv3 CPU
> interface, which really is part of the CPU proper; we just ended up
> implementing it in code in hw/intc/ for historical reasons.
> 
> The motivation for this move is that we'd like to change
> arm_el_is_aa64() to add a condition that uses cpu_isar_feature();
> but we don't want to include cpu-features.h in cpu.h.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/arm/cpu.h          | 66 --------------------------------------
>   target/arm/internals.h    | 67 +++++++++++++++++++++++++++++++++++++++
>   hw/intc/arm_gicv3_cpuif.c |  1 +
>   target/arm/arch_dump.c    |  1 +
>   4 files changed, 69 insertions(+), 66 deletions(-)

Likewise, is there a good reason to keep arm_current_el inline?

I can see that a fair fraction of arm_el_is_aa64 calls have a constant second argument 
(and most of those check el3).  Therefore I can see that keeping that function inline can 
eliminate quite a lot of tests.

Anyway,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


> +/* Return true if the specified exception level is running in AArch64 state. */
> +static inline bool arm_el_is_aa64(CPUARMState *env, int el)
> +{
> +    /*
> +     * This isn't valid for EL0 (if we're in EL0, is_a64() is what you want,
> +     * and if we're not in EL0 then the state of EL0 isn't well defined.)
> +     */
> +    assert(el >= 1 && el <= 3);
> +    bool aa64 = arm_feature(env, ARM_FEATURE_AARCH64);
> +
> +    /*
> +     * The highest exception level is always at the maximum supported
> +     * register width, and then lower levels have a register width controlled
> +     * by bits in the SCR or HCR registers.
> +     */
> +    if (el == 3) {
> +        return aa64;
> +    }
> +
> +    if (arm_feature(env, ARM_FEATURE_EL3) &&
> +        ((env->cp15.scr_el3 & SCR_NS) || !(env->cp15.scr_el3 & SCR_EEL2))) {
> +        aa64 = aa64 && (env->cp15.scr_el3 & SCR_RW);
> +    }
> +
> +    if (el == 2) {
> +        return aa64;
> +    }
> +
> +    if (arm_is_el2_enabled(env)) {
> +        aa64 = aa64 && (env->cp15.hcr_el2 & HCR_RW);
> +    }
> +
> +    return aa64;
> +}

I'll note that this would be clearer with early returns instead of &&.
E.g.

     if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
         return false;
     }
     if (el == 3) {
         return true;
     }

     if (arm_feature(env, ARM_FEATURE_EL3)
         && (env->cp15.scr_el3 & SCR_RW)
         && ((env->cp15.scr_el3 & SCR_NS)
             || !(env->cp15.scr_el3 & SCR_EEL2))) {
         return false;
     }
     if (el == 2) {
         return true;
     }
     ...

But of course not changed with code movement.


r~


  reply	other threads:[~2025-03-06 22:41 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 16:39 From ce9a42483c23c32cee233f648101a160b6604b45 Mon Sep 17 00:00:00 2001 Peter Maydell
2025-03-06 16:39 ` [PATCH 01/10] target/arm: Move A32_BANKED_REG_{GET, SET} macros to cpregs.h Peter Maydell
2025-03-06 22:09   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 02/10] target/arm: Un-inline access_secure_reg() Peter Maydell
2025-03-06 22:09   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 03/10] linux-user/aarch64: Remove unused get/put_user macros Peter Maydell
2025-03-06 22:09   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 04/10] linux-user/arm: Remove unused get_put_user macros Peter Maydell
2025-03-06 22:09   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 05/10] target/arm: Move arm_cpu_data_is_big_endian() etc to internals.h Peter Maydell
2025-03-06 22:12   ` Richard Henderson
2025-03-07  9:37     ` Peter Maydell
2025-03-06 16:39 ` [PATCH 06/10] target/arm: Move arm_current_el() and arm_el_is_aa64() " Peter Maydell
2025-03-06 22:40   ` Richard Henderson [this message]
2025-03-06 16:39 ` [PATCH 07/10] target/arm: SCR_EL3.RW should be treated as 1 if EL2 doesn't support AArch32 Peter Maydell
2025-03-06 17:12   ` Peter Maydell
2025-03-06 22:53   ` Richard Henderson
2025-03-07  9:39     ` Peter Maydell
2025-03-06 16:39 ` [PATCH 08/10] target/arm: HCR_EL2.RW should be RAO/WI if EL1 " Peter Maydell
2025-03-06 23:01   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 09/10] target/arm: Add cpu local variable to exception_return helper Peter Maydell
2025-03-06 23:02   ` Richard Henderson
2025-03-06 16:39 ` [PATCH 10/10] target/arm: Forbid return to AArch32 when CPU is AArch64-only Peter Maydell
2025-03-06 23:16   ` Richard Henderson
2025-03-13 16:19   ` Peter Maydell
2025-03-06 16:41 ` [PATCH 00/10] target/arm: Forbid exception returns to unimplemented AArch32 ELs Peter Maydell

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=a378cc0e-07fa-4514-8cd9-8826502e534a@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).