From nobody Tue Feb 10 10:20:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1575415689; cv=none; d=zohomail.com; s=zohoarc; b=M/6SvFg50dk4iXC8Kcp9QtP78G7AZdh5IatmyA8LO0ZnoGJUT/WrULJVTM6Cw6xFs7MKmWH7nVtNdSlZbw9qMfqWOJGeNHjVBn8K4uG6xRZ9MLt8X/Hv2GY9UUivBGiSmpvLVseGKEd5jyF7OjcYYrsPA0ZxUZjXeKV1JGdrQ5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575415689; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=CW2EPJtOmxl4BSZSTFMUahqoZD/6rAAwVofwfa2CqPY=; b=AH5n84Eu+o1gU1TAbtFU4AkiMoqz8bFJghDyU/xsJNJLcEOBUfemMAIZaSayvd9UxpxrAg7EDvVtvN24NGwmaQBRQNTkEcojGCSfGVbn2azPSs4F8GO9CZD2lo/YQ4rHXPhTCeIzm9Y/+JkVNp+VUvP9RcHpRM+nbpHvahci+6w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575415689112670.8612147415214; Tue, 3 Dec 2019 15:28:09 -0800 (PST) Received: from localhost ([::1]:60394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icHaR-0005j8-3j for importer@patchew.org; Tue, 03 Dec 2019 18:28:07 -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) 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) 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-Google-Smtp-Source: APXvYqzD/XHQ0w/WY8XON6ZVogOAj9QhVcPIzKDnKqtYgyawuVtpwL/w/sNjpmfKHnea3KoHZTdm2Q== X-Received: by 2002:a63:5962:: with SMTP id j34mr37304pgm.421.1575413626664; Tue, 03 Dec 2019 14:53:46 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 =3D 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 i= t now. @@ -8648,7 +8652,7 @@ static void take_aarch32_exception(CPUARMState *env, = int new_mode, env->uncached_cpsr =3D (env->uncached_cpsr & ~CPSR_M) | new_mode; /* Set new mode endianness */ env->uncached_cpsr &=3D ~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 |=3D 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 =3D (env->cp15.sctlr_el[2] & SCTLR_TE) !=3D 0; env->elr_el[2] =3D env->regs[15]; } else { + /* CPSR.PAN is preserved unless target is EL1 and SCTLR.SPAN =3D= =3D 0. */ + if (cpu_isar_feature(aa64_pan, env_archcpu(env))) { + env->uncached_cpsr |=3D + (new_el =3D=3D 1 && + (env->cp15.sctlr_el[1] & SCTLR_SPAN) =3D=3D 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 =3D env->exception.target_el; target_ulong addr =3D env->cp15.vbar_el[new_el]; unsigned int new_mode =3D aarch64_pstate_mode(new_el, true); + unsigned int old_mode; unsigned int cur_el =3D arm_current_el(env); =20 /* @@ -9006,20 +9019,43 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *= cs) } =20 if (is_a64(env)) { - env->banked_spsr[aarch64_banked_spsr_index(new_el)] =3D pstate_rea= d(env); + old_mode =3D pstate_read(env); aarch64_save_sp(env, arm_current_el(env)); env->elr_el[new_el] =3D env->pc; } else { - env->banked_spsr[aarch64_banked_spsr_index(new_el)] =3D cpsr_read(= env); + old_mode =3D cpsr_read(env); env->elr_el[new_el] =3D env->regs[15]; =20 aarch64_sync_32_to_64(env); =20 env->condexec_bits =3D 0; } + env->banked_spsr[aarch64_banked_spsr_index(new_el)] =3D old_mode; + qemu_log_mask(CPU_LOG_INT, "...with ELR 0x%" PRIx64 "\n", env->elr_el[new_el]); =20 + if (cpu_isar_feature(aa64_pan, cpu)) { + /* The value of PSTATE.PAN is normally preserved, except when ... = */ + new_mode |=3D old_mode & PSTATE_PAN; + switch (new_el) { + case 2: + /* ... the target is EL2 with HCR_EL2.{E2H,TGE} =3D=3D '11' ..= . */ + if ((arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) + !=3D (HCR_E2H | HCR_TGE)) { + break; + } + /* fall through */ + case 1: + /* ... the target is EL1 ... */ + /* ... and SCTLR_ELx.SPAN =3D=3D 0, then set to 1. */ + if ((env->cp15.sctlr_el[new_el] & SCTLR_SPAN) =3D=3D 0) { + new_mode |=3D PSTATE_PAN; + } + break; + } + } + pstate_write(env, PSTATE_DAIF | new_mode); env->aarch64 =3D 1; aarch64_restore_sp(env, new_el); --=20 2.17.1