All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim MacArthur <jim.macarthur@linaro.org>
To: qemu-arm@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [PATCH] target/arm: Get HVC UNDEF cases for Secure mode right
Date: Fri, 30 Oct 2026 09:49:48 +0000	[thread overview]
Message-ID: <auRoPIM25ZVH4Smb@linaro.org> (raw)
In-Reply-To: <20261030092815.573973-1-peter.maydell@linaro.org>

On Fri, Oct 30, 2026 at 09:28:15AM +0000, Peter Maydell wrote:
> In the pre_hvc helper, we have a "bool secure = false" and a FIXME
> comment that we should use the actual Secure state. This is a
> signpost to the fact that we're not getting the UNDEF cases right.
> Specifically, we get most of them correct but are missing the ones
> related to Secure state:
> 
>  * For A64: HVC must UNDEF at EL1 if EL2 is not enabled in the
>    current Security state
> 
>  * For v8 A32/T32, HVC must UNDEF in Secure state, if EL2 is not
>    enabled in the current Security state
> 
>  * For v7, HVC must UNDEF in Secure state
> 
> The v7 requirement is identical to the v8 A32/T32 one, since
> there is no Secure EL2 in v7.
> 
> This fixes a bug where HVC should have UNDEFed but instead trapped
> when in Secure state with Secure EL2 disabled.  The bug is unlikely
> to affect real-world code, because only test code puts itself in a
> situation where HVC should UNDEF and then executes HVC and requires
> it to UNDEF.
> 
> This was noticed by Coverity, because the "if (secure && ...)"
> check was dead code.
> 
> CID: 1689834
> Cc: qemu-stable@nongnu.org
> Fixes: 35979d71c401 ("target-arm: A64: Emulate the HVC insn")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target/arm/tcg/op_helper.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c
> index 6a673e5ae6e..3d3c850a198 100644
> --- a/target/arm/tcg/op_helper.c
> +++ b/target/arm/tcg/op_helper.c
> @@ -1295,8 +1295,6 @@ void HELPER(pre_hvc)(CPUARMState *env)
>  {
>      ARMCPU *cpu = env_archcpu(env);
>      int cur_el = arm_current_el(env);
> -    /* FIXME: Use actual secure state.  */
> -    bool secure = false;
>      bool undef;
>  
>      if (arm_is_psci_call(cpu, EXCP_HVC)) {
> @@ -1306,6 +1304,8 @@ void HELPER(pre_hvc)(CPUARMState *env)
>          return;
>      }
>  
> +    /* Note that we have already UNDEFed HVC from EL0 at translation time */
> +
>      if (!arm_feature(env, ARM_FEATURE_EL2)) {
>          /* If EL2 doesn't exist, HVC always UNDEFs */
>          undef = true;
> @@ -1316,12 +1316,19 @@ void HELPER(pre_hvc)(CPUARMState *env)
>          undef = env->cp15.hcr_el2 & HCR_HCD;
>      }
>  
> -    /* In ARMv7 and ARMv8/AArch32, HVC is undef in secure state.
> -     * For ARMv8/AArch64, HVC is allowed in EL3.
> -     * Note that we've already trapped HVC from EL0 at translation
> -     * time.
> +    /*
> +     * In ARMv7 and ARMv8/AArch32, HVC is undef in Secure state if
> +     * EL2 is not enabled in the current security state (which is
> +     * always for Secure in v7, as Secure EL2 doesn't exist there).
> +     *
> +     * For ARMv8/AArch64, HVC is undef at EL1 if EL2 is not enabled in
> +     * the current security state.
> +     *
> +     * Because we've already dealt with "EL2 not implemented" above,
> +     * arm_is_el2_enabled() is effectively always true here in NonSecure,
> +     * and we don't need to explicitly also check for secure/non-secure.
>       */
> -    if (secure && (!is_a64(env) || cur_el == 1)) {
> +    if (!arm_is_el2_enabled(env) && (!is_a64(env) || cur_el == 1)) {
>          undef = true;
>      }
>  
> -- 
> 2.43.0

Looks good to me

Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>



  reply	other threads:[~2026-10-30  9:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  9:28 [PATCH] target/arm: Get HVC UNDEF cases for Secure mode right Peter Maydell
2026-10-30  9:49 ` Jim MacArthur [this message]
2026-10-30 15:00 ` Richard Henderson

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=auRoPIM25ZVH4Smb@linaro.org \
    --to=jim.macarthur@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.