From patchwork Thu Jul 4 16:07:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 168478 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2459268ilk; Thu, 4 Jul 2019 09:14:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbHVrVjQOPrtvVHdYfnGthkNQTwrVwMToNZWVE1cyX/h7jMRxB4Qz/E0RqFKUyOm/EUTec X-Received: by 2002:a17:906:414:: with SMTP id d20mr41913878eja.275.1562256872248; Thu, 04 Jul 2019 09:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562256872; cv=none; d=google.com; s=arc-20160816; b=gauSFQ9OvwCKp5s1xeyaKZ9JG4X+32ropGeJFb/7mATjbeVGXXOncbONsAdmoorSIc 4Lr1kDjgu1O8lLl1UF3cOWKj91tFkQsiEMwGDRUJ8FQv/9Aj82RZGyn9UaTcVxyg1vJc 8BBFuNjnznmZvBhcUlRwQMcsaOyMufUcBpDOHYvdm9PKHnS7Dg5gC2TiFk+WW15EGuNf DuP3cGRqKFZeIcAZ75UP9uB7uuMLI9RlhZ2pmiQyUXppCpeG7X309Xon1tLWRQf2HHqI Wc5kB0ukuP+MXqpxC8j0EuuMlamxUNaY4Xjo3VuJMbUgdt5y1QMDTb5aKSVKRGO5JvmG dckw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=yj2MtKDVZXdSKXJUOki1opdC2pkjoIjecllTKPnecKA=; b=iFznZxPkB942XbI1KpNBHGgBnbi+kkfwJRRD7anMvXYCJrGVZaf3ufnC7FFASnEPo3 k/2ovP25xT3Y4RvSkzBoEnn3tSL6kx8qnTw1OeeziMeO5TGpy65LwsmNKjqeoVIOAMqY CgU9LCErKCgBEf5Vr5ipS+hh/CuDnC/XPCnyshgaOu3pfMRFAMkl88M5iMM7ZvEbzABT yqiA74yHqYbolucqzHuW0Z7Cp3MyqySYcJoF2fTvBYzrmcwggW85vC0lySMVdEuwGJwW cWMqOr4mtCaSC8SA3ih2SE7zi4BRNhqILTZpTHKWs6S6U3rlJ+tbPjzBo4e0we88vpWR 3ewQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qW7pyOpl; 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 p7si4214639ejj.70.2019.07.04.09.14.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2019 09:14:32 -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=qW7pyOpl; 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]:47448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj4NR-0006Rw-IR for patch@linaro.org; Thu, 04 Jul 2019 12:14:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44174) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj4HU-000802-97 for qemu-devel@nongnu.org; Thu, 04 Jul 2019 12:08:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hj4HS-0002AM-3g for qemu-devel@nongnu.org; Thu, 04 Jul 2019 12:08:20 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:46243) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hj4HQ-00026z-Ck for qemu-devel@nongnu.org; Thu, 04 Jul 2019 12:08:16 -0400 Received: by mail-wr1-x42d.google.com with SMTP id z1so2539230wru.13 for ; Thu, 04 Jul 2019 09:08:15 -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=yj2MtKDVZXdSKXJUOki1opdC2pkjoIjecllTKPnecKA=; b=qW7pyOplwRLn1LKQJRwt3ABOlbmEVfj3WNS2lEDnWNv/raBsnO7br6KaY7WsyTqqwJ Y/wUYA8NqiGlNYvRrns3fv1E3vTaaXFE0WAq9o/pJAL7uY6M2H+RUZ8Cdplm4Dv8+yAu mrhyr7vxhwwsvNgThg3xyoQsH0q9j86+eRmk8icBumpOMrzq6GmDDe2+uA+SAAKbZdTe umul4btJVy/ZYCEIeG7l131bzXTQMUaMgOZ4npM0chCLA0Na660UyzHvVxRemEBhoUou rHaEJ8OROYzcRvOXDfTAGggIqhN1g3KWZ9SoI17bPReOM27u/j0cgzo8z8wGBq6qp/Pk qb3g== 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=yj2MtKDVZXdSKXJUOki1opdC2pkjoIjecllTKPnecKA=; b=SXG/J4Qh204mNeCht5YU0uvDIPiJoripE/DxsPSGdhDD5XHcYL54CyWjHh4Td7kfXs s1rvwyDh9dXoptmaKarmBx8GmFqvaMdFXok0G6wgP4gFtr2Jly5WgmdeCYE/v/PgXETA D6kqJ4wqj/qrNjhWCRgYsQiwCkObCD/sIRCZWA5dxXTloPXLMzY7vNEEEoXf+bH0R21k 0Wg0Yem7SOd0k/nG6PzerYzD1IWPbM6VpPOvUlXhxRDsWzCs0aldXKAtn64stJW3aOJn i9BiDrYioF3hqtXFlcy33p5mIJ3rVBco3bi85E3Y4WQYDsUbE0AhZizwyg68IfpgyOOY SNlQ== X-Gm-Message-State: APjAAAWcccKjy+08mGATJtpJizRgzm6gNg8LoXdvnG9moD3UZUdo+kbP sSE/Z8PCBECTYGb018V+PJtC9x29yS9eyw== X-Received: by 2002:a5d:5186:: with SMTP id k6mr37209531wrv.30.1562256493932; Thu, 04 Jul 2019 09:08:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id s2sm3849690wmj.33.2019.07.04.09.08.13 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 09:08:13 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 4 Jul 2019 17:07:58 +0100 Message-Id: <20190704160802.12419-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190704160802.12419-1-peter.maydell@linaro.org> References: <20190704160802.12419-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42d Subject: [Qemu-devel] [PULL 5/9] target/arm: v8M: Check state of exception being returned from 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In v8M, an attempt to return from an exception which is not active is an illegal exception return. For this purpose, exceptions which can configurably target either Secure or NonSecure are not considered to be active if they are configured for the opposite security state for the one we're trying to return from (eg attempt to return from an NS NMI but NMI targets Secure). In the pseudocode this is handled by IsActiveForState(). Detect this case rather than counting an active exception possibly of the wrong security state as being sufficient. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20190617175317.27557-4-peter.maydell@linaro.org --- hw/intc/armv7m_nvic.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 330eb728dd5..9f8f0d3ff55 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -860,7 +860,19 @@ int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure) return -1; } - ret = nvic_rettobase(s); + /* + * If this is a configurable exception and it is currently + * targeting the opposite security state from the one we're trying + * to complete it for, this counts as an illegal exception return. + * We still need to deactivate whatever vector the logic above has + * selected, though, as it might not be the same as the one for the + * requested exception number. + */ + if (!exc_is_banked(irq) && exc_targets_secure(s, irq) != secure) { + ret = -1; + } else { + ret = nvic_rettobase(s); + } vec->active = 0; if (vec->level) {