From patchwork Tue Dec 3 22:53:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 180776 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp2193871ile; Tue, 3 Dec 2019 15:26:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxmmGHWG4AejMm7tWdAcGGpI8VocfT8npzuq5bJg4YrVSwwVYI9WdODnY+7uFGsTzPRuPlN X-Received: by 2002:a37:a914:: with SMTP id s20mr46251qke.92.1575415604728; Tue, 03 Dec 2019 15:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575415604; cv=none; d=google.com; s=arc-20160816; b=JTYVSn/qbU1D0MZ7VcRSCIulBR9rk+pQf76TihzbVQEhJDAa0QEKtAhKkQN8lwBW8+ 9gt4Du4aiqZbsO8DAZhd0PtA8JVhLGajbNqaOdiALLk8Gg+jpdxYOwudTCBKB01Sw0i8 p+FD/LzCO+ifc+TtYof/0f2n+FFXGFzcuUVBsVgFXYBVUYH/vcqKBpAS8/AHiPAH6wR5 blTwl7IBBKAp7MFtLP878q7VDvFdbfZPItzu0U9s62967LiFOJcuNpyTonBwFxhKyerU C1xTRzkeM/cQWDTjx8l+XPb+GkMBxHwrRIV2Cu3DUt7eXJLCRJmvP3sBVA6Sn9f9/fN7 bbwA== 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:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=CW2EPJtOmxl4BSZSTFMUahqoZD/6rAAwVofwfa2CqPY=; b=sPoKjrl2gXp6HNGptrMlitga9pqJtqDi+7lz/MJhicudCMXRBUMrU00lAP+7Pt5OMr MSSuqhtGvp3BMyFFS3j6Qr1pn+1PDwPV3g3/G+UxxRN+618rFLnbJqpheB0MJs4tfsXd q9LiovNt+GW0LiwaD4Di0T+nJRtBH/aDq3KwR8Ab1bnfrCXf4fG2fyC9dWAytmXqnk8S FTGAfaBX2jrq4rvhM1LULnggWoWbh6Zimwqf7hnEXx2wXg+zuX7jWowFpgErCi1FpOTd z7Y/fXh+E7ocwr5xV6YBUrvsAmnkIQ/UiWEwXoN+IfNefODPdIdzbANnVKdac1+Ny+4z jC1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i9iXMUtl; 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=pass (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 m1si3170978qtm.347.2019.12.03.15.26.44 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2019 15:26:44 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=i9iXMUtl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icHZ5-0004nF-V6 for patch@linaro.org; Tue, 03 Dec 2019 18:26:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58631) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icH3e-0002wp-VL for qemu-devel@nongnu.org; Tue, 03 Dec 2019 17:54:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icH3Z-0006uv-63 for qemu-devel@nongnu.org; Tue, 03 Dec 2019 17:54:11 -0500 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icH3V-0006aj-9R for qemu-devel@nongnu.org; Tue, 03 Dec 2019 17:54:05 -0500 Received: by mail-pf1-x443.google.com with SMTP id s18so2577878pfm.4 for ; Tue, 03 Dec 2019 14:53:48 -0800 (PST) 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; bh=CW2EPJtOmxl4BSZSTFMUahqoZD/6rAAwVofwfa2CqPY=; b=i9iXMUtl7S9kXYrXaO6jMQ2JlSFVx5US+lcZQijuDMQdlT8b5nJs7vbrHyxknWNPEH z16qZxgXtKzm9Tcz1TsgM1oFotzJKz6TEhVuQVxcc3RevIjgTxTaxo0HLl9PlCMNeU6g EKyVRdvqj+9Iepd94LK/Gyjc2UgQaQ08uzoSbR7Nf41pFK0mArn7XFWY+8fDBejAZhtN zLY2kqOgSY586MnxPYED5WuVfoJN2illYRT/DDfIxOeKNCLnCySkEj0Teu92k26/PhIX j/fOE3a6b/+IdHHkQjUSFBo40KZwsyFhbz1BxazZVcuDABIW3hZjq3kLUZAuJCIJFcsi qY+w== 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; bh=CW2EPJtOmxl4BSZSTFMUahqoZD/6rAAwVofwfa2CqPY=; b=cMd6PYM4jlkTTvw7Uoj7PCj7xg79R5yE0vIt4vhV67R9O0KBthz4sAmzIvI7Y40qQY ip/wv//erMx9TFK9roCwT8CDSXiOzVhgMhCPhEMiulcncCV4SJomOqKiwVVPJ8OKD7q7 eYdqg3SfN1CgKpnE8YQZ+j5DxC+vpGIY6oQCRI0u1aigY9GNH0COt3RoCPn/DIePk8sk kLU0kUW59HjHi7M1hYOCwPBqHPo0q8SI5O+IPCiFS1knNPnLmGYVv3y7dvdGixkQJTeC FIP0QTtr2z4Wdv2S2E/aTxnMpEAW60l2c74NUtEHvSBGJprOlkg2mHRnj+omGCbUgyhw aRQQ== X-Gm-Message-State: APjAAAWk1BzeOit7ADIlP++1zUpmYfF1wZ4kR3TpA0JhglR7WSRwByJR VCqVfRTeHM2VaXyO/s7EQF7mfta3/zY= X-Received: by 2002:a63:5962:: with SMTP id j34mr37304pgm.421.1575413626664; Tue, 03 Dec 2019 14:53:46 -0800 (PST) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id d22sm3789713pjd.2.2019.12.03.14.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 14:53:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/11] target/arm: Set PAN bit as required on exception entry Date: Tue, 3 Dec 2019 14:53:31 -0800 Message-Id: <20191203225333.17055-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191203225333.17055-1-richard.henderson@linaro.org> References: <20191203225333.17055-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The PAN bit is preserved, or set as per SCTLR_ELx.SPAN, plus several other conditions listed in the ARM ARM. Signed-off-by: Richard Henderson --- target/arm/helper.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index a1dbafb9b2..043e44d73d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8634,8 +8634,12 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, uint32_t mask, uint32_t offset, uint32_t newpc) { + int new_el; + /* Change the CPU state so as to actually take the exception. */ switch_mode(env, new_mode); + new_el = arm_current_el(env); + /* * For exceptions taken to AArch32 we must clear the SS bit in both * PSTATE and in the old-state value we save to SPSR_, so zero it now. @@ -8648,7 +8652,7 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, env->uncached_cpsr = (env->uncached_cpsr & ~CPSR_M) | new_mode; /* Set new mode endianness */ env->uncached_cpsr &= ~CPSR_E; - if (env->cp15.sctlr_el[arm_current_el(env)] & SCTLR_EE) { + if (env->cp15.sctlr_el[new_el] & SCTLR_EE) { env->uncached_cpsr |= CPSR_E; } /* J and IL must always be cleared for exception entry */ @@ -8659,6 +8663,14 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, env->thumb = (env->cp15.sctlr_el[2] & SCTLR_TE) != 0; env->elr_el[2] = env->regs[15]; } else { + /* CPSR.PAN is preserved unless target is EL1 and SCTLR.SPAN == 0. */ + if (cpu_isar_feature(aa64_pan, env_archcpu(env))) { + env->uncached_cpsr |= + (new_el == 1 && + (env->cp15.sctlr_el[1] & SCTLR_SPAN) == 0 + ? CPSR_PAN + : env->spsr & CPSR_PAN); + } /* * this is a lie, as there was no c1_sys on V4T/V5, but who cares * and we should just guard the thumb mode on V4 @@ -8921,6 +8933,7 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) unsigned int new_el = env->exception.target_el; target_ulong addr = env->cp15.vbar_el[new_el]; unsigned int new_mode = aarch64_pstate_mode(new_el, true); + unsigned int old_mode; unsigned int cur_el = arm_current_el(env); /* @@ -9006,20 +9019,43 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) } if (is_a64(env)) { - env->banked_spsr[aarch64_banked_spsr_index(new_el)] = pstate_read(env); + old_mode = pstate_read(env); aarch64_save_sp(env, arm_current_el(env)); env->elr_el[new_el] = env->pc; } else { - env->banked_spsr[aarch64_banked_spsr_index(new_el)] = cpsr_read(env); + old_mode = cpsr_read(env); env->elr_el[new_el] = env->regs[15]; aarch64_sync_32_to_64(env); env->condexec_bits = 0; } + env->banked_spsr[aarch64_banked_spsr_index(new_el)] = old_mode; + qemu_log_mask(CPU_LOG_INT, "...with ELR 0x%" PRIx64 "\n", env->elr_el[new_el]); + if (cpu_isar_feature(aa64_pan, cpu)) { + /* The value of PSTATE.PAN is normally preserved, except when ... */ + new_mode |= old_mode & PSTATE_PAN; + switch (new_el) { + case 2: + /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */ + if ((arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) + != (HCR_E2H | HCR_TGE)) { + break; + } + /* fall through */ + case 1: + /* ... the target is EL1 ... */ + /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */ + if ((env->cp15.sctlr_el[new_el] & SCTLR_SPAN) == 0) { + new_mode |= PSTATE_PAN; + } + break; + } + } + pstate_write(env, PSTATE_DAIF | new_mode); env->aarch64 = 1; aarch64_restore_sp(env, new_el);