qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aaron Lindsay OS via Qemu-devel <qemu-devel@nongnu.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"bobby.prani@gmail.com" <bobby.prani@gmail.com>,
	"cota@braap.org" <cota@braap.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"open list:ARM TCG CPUs" <qemu-arm@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v4 04/54] target/arm: remove run time semihosting checks
Date: Thu, 1 Aug 2019 13:27:15 +0000	[thread overview]
Message-ID: <20190801132659.GJ5034@quinoa.localdomain> (raw)
In-Reply-To: <20190731160719.11396-5-alex.bennee@linaro.org>

On Jul 31 17:06, Alex Bennée wrote:
> Now we do all our checking and use a common EXCP_SEMIHOST for
> semihosting operations we can make helper code a lot simpler.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> 
> ---
> v2
>   - fix re-base conflicts
>   - hoist EXCP_SEMIHOST check
>   - comment cleanups
> ---
>  target/arm/helper.c | 90 +++++++++------------------------------------
>  1 file changed, 18 insertions(+), 72 deletions(-)
> 
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index b74c23a9bc0..c5b90a83d36 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -8259,86 +8259,30 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
>                    new_el, env->pc, pstate_read(env));
>  }
>  
> -static inline bool check_for_semihosting(CPUState *cs)
> +/*
> + * Do semihosting call and set the appropriate return value. All the
> + * permission and validity checks have been done at translate time.
> + *
> + * We only see semihosting exceptions in TCG only as they are not
> + * trapped to the hypervisor in KVM.
> + */
> +static void handle_semihosting(CPUState *cs)
>  {
>  #ifdef CONFIG_TCG
> -    /* Check whether this exception is a semihosting call; if so
> -     * then handle it and return true; otherwise return false.
> -     */
>      ARMCPU *cpu = ARM_CPU(cs);
>      CPUARMState *env = &cpu->env;
>  
>      if (is_a64(env)) {
> -        if (cs->exception_index == EXCP_SEMIHOST) {
> -            /* This is always the 64-bit semihosting exception.
> -             * The "is this usermode" and "is semihosting enabled"
> -             * checks have been done at translate time.
> -             */
> -            qemu_log_mask(CPU_LOG_INT,
> -                          "...handling as semihosting call 0x%" PRIx64 "\n",
> -                          env->xregs[0]);
> -            env->xregs[0] = do_arm_semihosting(env);
> -            return true;
> -        }
> -        return false;
> +        qemu_log_mask(CPU_LOG_INT,
> +                      "...handling as semihosting call 0x%" PRIx64 "\n",
> +                      env->xregs[0]);
> +        env->xregs[0] = do_arm_semihosting(env);
>      } else {
> -        uint32_t imm;
> -
> -        /* Only intercept calls from privileged modes, to provide some
> -         * semblance of security.
> -         */
> -        if (cs->exception_index != EXCP_SEMIHOST &&
> -            (!semihosting_enabled() ||
> -             ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR))) {
> -            return false;
> -        }
> -
> -        switch (cs->exception_index) {
> -        case EXCP_SEMIHOST:
> -            /* This is always a semihosting call; the "is this usermode"
> -             * and "is semihosting enabled" checks have been done at
> -             * translate time.
> -             */
> -            break;
> -        case EXCP_SWI:
> -            /* Check for semihosting interrupt.  */
> -            if (env->thumb) {
> -                imm = arm_lduw_code(env, env->regs[15] - 2, arm_sctlr_b(env))
> -                    & 0xff;
> -                if (imm == 0xab) {
> -                    break;
> -                }
> -            } else {
> -                imm = arm_ldl_code(env, env->regs[15] - 4, arm_sctlr_b(env))
> -                    & 0xffffff;
> -                if (imm == 0x123456) {
> -                    break;
> -                }
> -            }
> -            return false;
> -        case EXCP_BKPT:
> -            /* See if this is a semihosting syscall.  */
> -            if (env->thumb) {
> -                imm = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env))
> -                    & 0xff;
> -                if (imm == 0xab) {
> -                    env->regs[15] += 2;
> -                    break;
> -                }
> -            }
> -            return false;
> -        default:
> -            return false;
> -        }
> -
>          qemu_log_mask(CPU_LOG_INT,
>                        "...handling as semihosting call 0x%x\n",
>                        env->regs[0]);
>          env->regs[0] = do_arm_semihosting(env);
> -        return true;
>      }
> -#else
> -    return false;
>  #endif
>  }
>  
> @@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs)
>          return;
>      }
>  
> -    /* Semihosting semantics depend on the register width of the
> -     * code that caused the exception, not the target exception level,
> -     * so must be handled here.
> +    /*
> +     * Semihosting semantics depend on the register width of the code
> +     * that caused the exception, not the target exception level, so
> +     * must be handled here.
>       */
> -    if (check_for_semihosting(cs)) {
> +    if (cs->exception_index == EXCP_SEMIHOST) {
> +        handle_semihosting(cs);
>          return;
>      }

Previously, this code would never return here if CONFIG_TCG was not
defined because check_for_semihosting() always returned false in that
case. Is it now true that `cs->exception_index` will never hold a value
of EXCP_SEMIHOST if CONFIG_TCG is not defined (or that it is otherwise
correct to return here in that case where it wasn't previously)?

-Aaron


  reply	other threads:[~2019-08-01 13:28 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-31 16:06 [Qemu-devel] [PATCH v4 00/54] plugins for TCG Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 01/54] target/arm: handle M-profile semihosting at translate time Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 02/54] target/arm: handle A-profile T32 " Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 03/54] target/arm: handle A-profile A32 " Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 04/54] target/arm: remove run time semihosting checks Alex Bennée
2019-08-01 13:27   ` Aaron Lindsay OS via Qemu-devel [this message]
2019-08-01 13:36     ` Peter Maydell
2019-08-01 14:53   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 05/54] includes: remove stale [smp|max]_cpus externs Alex Bennée
2019-08-01 14:54   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 06/54] trace: expand mem_info:size_shift to 4 bits Alex Bennée
2019-08-01 15:01   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 07/54] trace: add mmu_index to mem_info Alex Bennée
2019-08-01 15:17   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 08/54] tcg/README: fix typo s/afterwise/afterwards/ Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 09/54] cpu: introduce cpu_in_exclusive_context() Alex Bennée
2019-08-01 15:23   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 10/54] translate-all: use cpu_in_exclusive_work_context() in tb_flush Alex Bennée
2019-08-01 15:25   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 11/54] docs/devel: add plugins.rst design document Alex Bennée
2019-08-01 15:31   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 12/54] configure: add --enable-plugins (MOVE TO END) Alex Bennée
2019-08-01 15:33   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API Alex Bennée
2019-08-01 15:39   ` Richard Henderson
2019-08-02 18:25   ` Aaron Lindsay OS via Qemu-devel
2019-09-06 19:31     ` Alex Bennée
2019-09-10 16:24       ` Aaron Lindsay OS via Qemu-devel
2019-09-10 17:41         ` Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 14/54] plugin: add core code Alex Bennée
2019-08-01 15:58   ` Richard Henderson
2019-09-12  9:17   ` Daniel P. Berrangé
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 15/54] plugin: add implementation of the api Alex Bennée
2019-08-01 16:14   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 16/54] queue: add QTAILQ_REMOVE_SEVERAL Alex Bennée
2019-08-01 16:16   ` Richard Henderson
2019-08-01 16:16   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 17/54] cputlb: document get_page_addr_code Alex Bennée
2019-08-01 17:08   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 18/54] cputlb: introduce get_page_addr_code_hostp Alex Bennée
2019-08-01 17:10   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 19/54] tcg: add tcg_gen_st_ptr Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 20/54] plugin-gen: add module for TCG-related code Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 21/54] atomic_template: fix indentation in GEN_ATOMIC_HELPER Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 22/54] atomic_template: add inline trace/plugin helpers Alex Bennée
2019-08-01 18:23   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 23/54] tcg: let plugins instrument virtual memory accesses Alex Bennée
2019-08-01 18:29   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr Alex Bennée
2019-08-01 14:14   ` Aaron Lindsay OS via Qemu-devel
2019-08-01 18:37     ` Richard Henderson
2019-10-09 17:45     ` Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 25/54] translate-all: notify plugin code of tb_flush Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 26/54] *-user: notify plugin of exit Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 27/54] *-user: plugin syscalls Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 28/54] cpu: hook plugin vcpu events Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 29/54] plugin-gen: add plugin_insn_append Alex Bennée
2019-08-01 18:39   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 30/54] translator: add translator_ld{ub, sw, uw, l, q} Alex Bennée
2019-08-01 19:24   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 31/54] target/arm: fetch code with translator_ld Alex Bennée
2019-08-01 19:26   ` Richard Henderson
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 32/54] target/ppc: " Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 33/54] target/sh4: " Alex Bennée
2019-07-31 16:06 ` [Qemu-devel] [PATCH v4 34/54] target/i386: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 35/54] target/hppa: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 36/54] target/m68k: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 37/54] target/alpha: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 38/54] target/riscv: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 39/54] target/sparc: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 40/54] target/xtensa: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 41/54] target/openrisc: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 42/54] translator: inject instrumentation from plugins Alex Bennée
2019-08-01 19:35   ` Richard Henderson
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 43/54] plugin: add API symbols to qemu-plugins.symbols Alex Bennée
2019-08-01 19:42   ` Richard Henderson
2019-10-11 16:46     ` Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 44/54] vl: support -plugin option Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 45/54] linux-user: " Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 46/54] tests/plugin: add sample plugins Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 47/54] tests/tcg: enable plugin testing Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 48/54] tests/plugin: add a hotblocks plugin Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 49/54] plugin: add qemu_plugin_insn_disas helper Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 50/54] tests/plugin: add instruction execution breakdown Alex Bennée
2019-08-01 14:31   ` Aaron Lindsay OS via Qemu-devel
2019-10-09 18:49     ` Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 51/54] tests/plugin: add hotpages plugin to breakdown memory access patterns Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 52/54] accel/stubs: reduce headers from tcg-stub Alex Bennée
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 53/54] include/exec: wrap cpu_ldst.h in CONFIG_TCG Alex Bennée
2019-08-01 19:51   ` Richard Henderson
2019-07-31 16:07 ` [Qemu-devel] [PATCH v4 54/54] include/exec/cpu-defs.h: fix typo Alex Bennée
2019-07-31 17:00 ` [Qemu-devel] [PATCH v4 00/54] plugins for TCG no-reply
2019-08-01  4:19 ` Markus Armbruster
2019-09-06 19:52   ` Alex Bennée
2019-09-10 16:16     ` Aaron Lindsay OS via Qemu-devel
2019-09-10 17:37       ` Alex Bennée
2019-09-10 16:34     ` Peter Maydell
2019-09-12  6:46     ` [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG) Markus Armbruster
2019-09-12  9:03       ` Alex Bennée
2019-09-12  9:21         ` Peter Maydell
2019-09-12 10:07           ` Alex Bennée
2019-09-12 10:16             ` Daniel P. Berrangé
2019-09-12 10:21               ` Peter Maydell
2019-09-12 10:18             ` Peter Maydell
2019-09-12 10:35               ` Alex Bennée
2019-09-12  9:32         ` Daniel P. Berrangé
2019-08-01 14:20 ` [Qemu-devel] [PATCH v4 00/54] plugins for TCG no-reply

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=20190801132659.GJ5034@quinoa.localdomain \
    --to=qemu-devel@nongnu.org \
    --cc=aaron@os.amperecomputing.com \
    --cc=alex.bennee@linaro.org \
    --cc=bobby.prani@gmail.com \
    --cc=cota@braap.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 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).