From patchwork Tue Aug 6 00:05:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 170618 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4916293ile; Mon, 5 Aug 2019 17:05:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9BmWpEVeyeaWoIikzOZYVJ9Nl3inQ4ajhX3O2om44zaOCRWqaHDCBU/HNxjmE29s16dI8 X-Received: by 2002:a50:940b:: with SMTP id p11mr993774eda.194.1565049947742; Mon, 05 Aug 2019 17:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565049947; cv=none; d=google.com; s=arc-20160816; b=EdaBMRJgc8H7HUKamh8TaNSYxhlXD3IJK8G9H1BbNWyCWVMeUem5ucYcDnp9uKja6z 9caYTWm859OmNrgjnP4xeA2goropnxWCECpt4mws8foJFF35wahmDArhsLGSB12AzeBe 549ePgqp4o6Woj+bkFhn4pLwdEGQQ1H+TkXp2zXy2ATuy3qo5rhhRfcFKrfa05VJXQrc jdPIc3aJwQCekVU3S+/VwUinfbEz13wwSqhCKH0j9Dkm8HFThX9FxXvLkZYmQiazgnRe 60t1YZieQY6qtisP86tDIsLXDo5kpotJwPJML0moYePo+czwVeGLwYTvrivLhJlBS6Jz 5GJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SmJ5Hdt1lX0FZop+Dbb79p/hOPSk025oMFCmVoyvZFY=; b=m+2bEmb9nYXDS3SBT/Oy5Z6jDI6NH5dF6Iq31Ii7OJSMk/C8QRlTSPcDDqifhXjuI6 mhWdHU7YfZ1wGKUp5XPRCrTOGV3s3VBh5lCy+O5FFCH//DX/1T4xCHbDSookgQUtoAwM PHdbDP7MB6BmY7xdlICc84G5qU4MlRXaT2RVdLAYZGSZMm1erVC8o4JE2bplbUoqUfAQ rqancNa/VwMJXgo85in3rdtK1OZT2Jz2zOPfx7B4oVQ3j9JCmsq+hMx6InbsStHbVxCb CXZZ0jv5fRjrSGTvDyKHVH1dJbS4O0fb+2C+vxGvTozKE+6g+7SMT3e4vdsNXEkXaqWR ybxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BbzBdBjO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g37si29989012edb.268.2019.08.05.17.05.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Aug 2019 17:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BbzBdBjO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1humz4-00042z-Nj for patch@linaro.org; Mon, 05 Aug 2019 20:05:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33664) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1humyZ-0003xE-IT for qemu-devel@nongnu.org; Mon, 05 Aug 2019 20:05:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1humyX-0008Ff-Vr for qemu-devel@nongnu.org; Mon, 05 Aug 2019 20:05:15 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:46283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1humyX-0008F1-Q2 for qemu-devel@nongnu.org; Mon, 05 Aug 2019 20:05:13 -0400 Received: by mail-pf1-x443.google.com with SMTP id c3so17316230pfa.13 for ; Mon, 05 Aug 2019 17:05:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SmJ5Hdt1lX0FZop+Dbb79p/hOPSk025oMFCmVoyvZFY=; b=BbzBdBjO4n7vzM3PZK0IUtakO9usQ8aWxkJOng54QjZaoyKvGUxqLNz2I3WV9UmbjI hpyXFOWOd/vQ0bVh8UndVF8I3SIEvsDEPzPKfwjVJfA1DHVemQj4IFGlQj14cGSytR25 VLFHE3QHCWbU1QOBMSuLkvQlBQ8GY3WGRKwkCv6LqHyEhh+OVOFkJBspyfRtRVzrbopB PeOqPc4SMbO7KvIZk8DqkjqEsMsGjyHRqp/x48pS8ojuicgztFRDdvCyLQbFC8kXOLR+ hbIglURis2KyhoAxgiiPVxefhxymNsTa2pqgRcJwwwEseqRFbVteXMIHvSpJt/jQRolL nn0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SmJ5Hdt1lX0FZop+Dbb79p/hOPSk025oMFCmVoyvZFY=; b=c1Kmg1CE2Y1Dz/IIOlgEhWwodlhW3w6iGvnoh6k5/mIfjz+c7+L2Yg/XPT81gjtFq9 QrqQCPcTkuESgTZkrjyIoLB3HlkOdyMduH4dbuNPR1BvhRKW7zBHSnDiR7dYJ69ixL+R jHTk7Wd1AnHVoz2T/qkRKxnfoxutKnz4rw7cLKbxI9Lqt+X+TNhEod8O07s0RBX21o4t n59A5UMMyqDrKwOoewpOMZZ9parFNjs2GQVxqxSsV7scQA5DFNCnftZL8UsZJPwYMz4k 9XryFjgd3hF28S4WGjUZP21HSViRwSofI/17n4JOWHuwDv/PR3oo3uRkOFOUkaqBiImB +TfQ== X-Gm-Message-State: APjAAAWe4jLWC9yQ+dZXJrqk7f6IxsEEovqX2UKCttuS1l+hbFfbkN+a TNO0KLWW3o7CkGQN1va86OFoyFLMo9o= X-Received: by 2002:a17:90a:21ac:: with SMTP id q41mr295306pjc.31.1565049912549; Mon, 05 Aug 2019 17:05:12 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id i3sm92149782pfo.138.2019.08.05.17.05.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 17:05:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 5 Aug 2019 17:05:05 -0700 Message-Id: <20190806000506.10833-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806000506.10833-1-richard.henderson@linaro.org> References: <20190806000506.10833-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v4 2/3] target/arm: Rebuild hflags at EL changes and MSR writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Now setting, but not relying upon, env->hflags. Tested-by: Alex Bennée Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- v2: Fixed partial conversion to assignment to env->hflags. --- linux-user/syscall.c | 1 + target/arm/cpu.c | 1 + target/arm/helper-a64.c | 3 +++ target/arm/helper.c | 2 ++ target/arm/machine.c | 1 + target/arm/op_helper.c | 1 + target/arm/translate-a64.c | 6 +++++- target/arm/translate.c | 14 ++++++++++++-- 8 files changed, 26 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8367cb138d..55d5fdadf3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9979,6 +9979,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, aarch64_sve_narrow_vq(env, vq); } env->vfp.zcr_el[1] = vq - 1; + arm_rebuild_hflags(env); ret = vq * 16; } return ret; diff --git a/target/arm/cpu.c b/target/arm/cpu.c index ec2ab95dbe..995f4ea355 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -406,6 +406,7 @@ static void arm_cpu_reset(CPUState *s) hw_breakpoint_update_all(cpu); hw_watchpoint_update_all(cpu); + arm_rebuild_hflags(env); } bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 060699b901..3bc364ebb7 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -1025,6 +1025,7 @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc) } else { env->regs[15] = new_pc & ~0x3; } + env->hflags = rebuild_hflags_a32(env, new_el); qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " "AArch32 EL%d PC 0x%" PRIx32 "\n", cur_el, new_el, env->regs[15]); @@ -1036,10 +1037,12 @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc) } aarch64_restore_sp(env, new_el); env->pc = new_pc; + env->hflags = rebuild_hflags_a64(env, new_el); qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " "AArch64 EL%d PC 0x%" PRIx64 "\n", cur_el, new_el, env->pc); } + /* * Note that cur_el can never be 0. If new_el is 0, then * el0_a64 is return_to_aa64, else el0_a64 is ignored. diff --git a/target/arm/helper.c b/target/arm/helper.c index 43b7c41f11..9b07350cfe 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7905,6 +7905,7 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, env->regs[14] = env->regs[15] + offset; } env->regs[15] = newpc; + env->hflags = rebuild_hflags_a32(env, arm_current_el(env)); } static void arm_cpu_do_interrupt_aarch32_hyp(CPUState *cs) @@ -8251,6 +8252,7 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) pstate_write(env, PSTATE_DAIF | new_mode); env->aarch64 = 1; + env->hflags = rebuild_hflags_a64(env, new_el); aarch64_restore_sp(env, new_el); env->pc = addr; diff --git a/target/arm/machine.c b/target/arm/machine.c index 3fd319a309..838d154a3c 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -758,6 +758,7 @@ static int cpu_post_load(void *opaque, int version_id) if (!kvm_enabled()) { pmu_op_finish(&cpu->env); } + arm_rebuild_hflags(&cpu->env); return 0; } diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 5e1625a1c8..6e6613b8a8 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -420,6 +420,7 @@ void HELPER(cpsr_write_eret)(CPUARMState *env, uint32_t val) */ env->regs[15] &= (env->thumb ? ~1 : ~3); + env->hflags = rebuild_hflags_a32(env, arm_current_el(env)); qemu_mutex_lock_iothread(); arm_call_el_change_hook(env_archcpu(env)); qemu_mutex_unlock_iothread(); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index d3231477a2..f8b5debf82 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1799,11 +1799,15 @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, /* I/O operations must end the TB here (whether read or write) */ gen_io_end(); s->base.is_jmp = DISAS_UPDATE; - } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { + } + if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { /* We default to ending the TB on a coprocessor register write, * but allow this to be suppressed by the register definition * (usually only necessary to work around guest bugs). */ + TCGv_i32 tcg_el = tcg_const_i32(s->current_el); + gen_helper_rebuild_hflags_a64(cpu_env, tcg_el); + tcg_temp_free_i32(tcg_el); s->base.is_jmp = DISAS_UPDATE; } } diff --git a/target/arm/translate.c b/target/arm/translate.c index 7853462b21..cd14bbebf1 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -7164,6 +7164,8 @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn) ri = get_arm_cp_reginfo(s->cp_regs, ENCODE_CP_REG(cpnum, is64, s->ns, crn, crm, opc1, opc2)); if (ri) { + bool need_exit_tb; + /* Check access permissions */ if (!cp_access_ok(s->current_el, ri, isread)) { return 1; @@ -7336,15 +7338,23 @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn) } } + need_exit_tb = false; if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) { /* I/O operations must end the TB here (whether read or write) */ gen_io_end(); - gen_lookup_tb(s); - } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { + need_exit_tb = true; + } + if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { /* We default to ending the TB on a coprocessor register write, * but allow this to be suppressed by the register definition * (usually only necessary to work around guest bugs). */ + TCGv_i32 tcg_el = tcg_const_i32(s->current_el); + gen_helper_rebuild_hflags_a32(cpu_env, tcg_el); + tcg_temp_free_i32(tcg_el); + need_exit_tb = true; + } + if (need_exit_tb) { gen_lookup_tb(s); }