From nobody Tue Nov 11 03:19:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1560794112; cv=none; d=zoho.com; s=zohoarc; b=GtRG7j37W89PT2Qo97qlApmUoua6r8M1YHlsp2fbqsheiooUdOI0i4ufQyD6psaJ1yUIf6+F3hsdLXKmV2TvvsQjQCJJ/pnTUdzxfIT6ixaTQ66eQi0v0GdR1Oo5Q1Dk9y65ubObF8lH0Nu71t5HlUJbC0+GySrG5Yeb3hP+DZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560794112; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZqxuBGrvpyV7bVVdQeK9vpv5xyuxJzmNpj8ibO3gKBw=; b=i5hnWrcJVPAG+wDIlMYXc7pYzMaKXKf2m1nggq06f9Xe0s1QcPmDhk/U6YSi8J7t+un5w4vISI91xsF3nxnna1d3IAAtEhe0DTBxeMkjcLWZMrH5nYiQqA+GOLo1sweZ1HaAa8rFxw8PqNoY2r43i+OtKnqKI7b5wdjECh9bm1c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail 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 1560794112107165.47269811147783; Mon, 17 Jun 2019 10:55:12 -0700 (PDT) Received: from localhost ([::1]:50648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcvqZ-0001NR-2u for importer@patchew.org; Mon, 17 Jun 2019 13:55:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50692) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcvot-0007fM-T0 for qemu-devel@nongnu.org; Mon, 17 Jun 2019 13:53:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcvos-0000bl-3T for qemu-devel@nongnu.org; Mon, 17 Jun 2019 13:53:27 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40716) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hcvoq-0000Zy-E3 for qemu-devel@nongnu.org; Mon, 17 Jun 2019 13:53:26 -0400 Received: by mail-wr1-x444.google.com with SMTP id p11so10953438wre.7 for ; Mon, 17 Jun 2019 10:53:23 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id t14sm8713619wrr.33.2019.06.17.10.53.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 10:53:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZqxuBGrvpyV7bVVdQeK9vpv5xyuxJzmNpj8ibO3gKBw=; b=qBnMrqiDAX2devzhltrL3k5LNwxLL0pYFEAXPUwAhF+DEGVY0ImlTww8y8aHtNGju6 ffUdO85sB3X1bAvFocgGqqG7aHmxzLOmAU0hHzIAdhEJZ4hHseTTUW3Cd+1JfcK6AZuW FzniwmN9yUl2wE30w4XYIC9C44X0m8DeS4qawfB4u5ffFYXUTvfinP8QZLVoWbXNnX0V qJ/810BkgXp8Ttscsx5OkDZHVvKTN0JTRKJJ1DFtHP9fMRqfzx3vNGudVMnwcfqKGv9A svjn5Hqmk+LrJYmciUNKs/TQ02TBaHmj2TcCOoP95IgPGoXjH2gaaVsoEhdkXB6xXfyO ++Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZqxuBGrvpyV7bVVdQeK9vpv5xyuxJzmNpj8ibO3gKBw=; b=omuTGOJ1P9/0mldiY6oQ9PBVjy7DDycqpsQwD+yvxt6CuXXGq493g0enxeqlkxcdqb U5tAJdUTqybhMxnxXm7reEBg7TompaLBaCIfDobPpG/E9X3l+aKYLP9GD7bT9hlH0EXU 0+M7Vpgkbo25Apzcc2cNJjsr0pG32A+L1556riNGM0UWWlKKlUjYDXVSe+s/CNFDrAyJ ZIydeBPgrUpen1qLcj9QjLOP1Oa0K8fSk9Yn94UPwh3iz8okjuFutHoVywd3RkqUgv+a oVNwNEAPLjmCHnzwenWJs2AZq2LTOuKQRj1qZEZQhIREMN2SsfuV+MZ4Si+pA+HE3tBh 2K7Q== X-Gm-Message-State: APjAAAVcn+0OsJNbjf0fXifTRpMkqK4gEtgh8qdFn5ISxAWQtxUjci/K TXGejZVTRk56VmDVmIX0hGUttQ== X-Google-Smtp-Source: APXvYqxxS4QCSTWgZqAdD7qocatdg0ImvIfuRpBAHWAZaidoPNL4OV75AT2y5QLsDhedXiP9T6olXA== X-Received: by 2002:adf:afe8:: with SMTP id y40mr22388286wrd.328.1560794002222; Mon, 17 Jun 2019 10:53:22 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 17 Jun 2019 18:53:13 +0100 Message-Id: <20190617175317.27557-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190617175317.27557-1-peter.maydell@linaro.org> References: <20190617175317.27557-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 2/6] arm v8M: Forcibly clear negative-priority exceptions on deactivate 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To prevent execution priority remaining negative if the guest returns from an NMI or HardFault with a corrupted IPSR, the v8M interrupt deactivation process forces the HardFault and NMI to inactive based on the current raw execution priority, even if the interrupt the guest is trying to deactivate is something else. In the pseudocode this is done in the Deactivate() function. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/armv7m_nvic.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index b8ede30b3cb..330eb728dd5 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -812,15 +812,45 @@ void armv7m_nvic_get_pending_irq_info(void *opaque, int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure) { NVICState *s =3D (NVICState *)opaque; - VecInfo *vec; + VecInfo *vec =3D NULL; int ret; =20 assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq); =20 - if (secure && exc_is_banked(irq)) { - vec =3D &s->sec_vectors[irq]; - } else { - vec =3D &s->vectors[irq]; + /* + * For negative priorities, v8M will forcibly deactivate the appropria= te + * NMI or HardFault regardless of what interrupt we're being asked to + * deactivate (compare the DeActivate() pseudocode). This is a guard + * against software returning from NMI or HardFault with a corrupted + * IPSR and leaving the CPU in a negative-priority state. + * v7M does not do this, but simply deactivates the requested interrup= t. + */ + if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { + switch (armv7m_nvic_raw_execution_priority(s)) { + case -1: + if (s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) { + vec =3D &s->vectors[ARMV7M_EXCP_HARD]; + } else { + vec =3D &s->sec_vectors[ARMV7M_EXCP_HARD]; + } + break; + case -2: + vec =3D &s->vectors[ARMV7M_EXCP_NMI]; + break; + case -3: + vec =3D &s->sec_vectors[ARMV7M_EXCP_HARD]; + break; + default: + break; + } + } + + if (!vec) { + if (secure && exc_is_banked(irq)) { + vec =3D &s->sec_vectors[irq]; + } else { + vec =3D &s->vectors[irq]; + } } =20 trace_nvic_complete_irq(irq, secure); --=20 2.20.1