From patchwork Mon Jul 18 13:59:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 591456 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp3035964max; Mon, 18 Jul 2022 07:04:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tj8wfiAVVTNDd1FIvlAUgch2DlvkklIGGJZlnwBIfwI6tbrZ/rtD9ccY06xWilmeNmSiRv X-Received: by 2002:a05:6214:e8f:b0:473:8284:b4ae with SMTP id hf15-20020a0562140e8f00b004738284b4aemr21058746qvb.86.1658153045334; Mon, 18 Jul 2022 07:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658153045; cv=none; d=google.com; s=arc-20160816; b=i3KYlSNqXK4fHJ4+IXY2BjWBjoV0wNHuSv3aBGnWJdyRmYRc/Ql9nUndorkCcdKBlt 7x9xtai0gYKnHAzORGg3Zw+BG7zmoUFkJ0jqa34wNI0Y+k1uCVeMZpTP8Jwqn6H3EnqW bKrNwTsP/bSCxBmKmMNksEgytvg5HaGoiOUTwZXThMS4gVycmc/3wxI7bj7ZtsARQh7P 2UoY2csyIuhax2ooyqXDHAOjKWtTorDzfi+vk+zt+Lb4JIiSMlo9Tzq4ckFwqY77bJkL 00rqzE0NPfvsqCM/OEw5tPHdaF1X0Mlatq0SUcf7pcFpB+Wvs0DGf4jRbKADkNX2wikB tdQw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=4XCUImSLdHKkyI8geHYTH1ofyLU9VSFDcDRAFOqUvzE=; b=Km0OGElpD1yIMMM712RkyXbxA8mVKLduBE11FX1si58L3vkA7TW3Q56D7Wuz+P/ly6 LrO4+Lidteh2eXYjDdsxhsGpAfIkw+zpeSqlXheZzPGv+/qCoOIrhLVN7C1DZ1doty9c bHfKsS+e/+B0Umw3UBc5svw+kckoA9d/gNQSZbZbRdcAgtMCfaM30Y4YdbVc/QU3UgRk 47CJWtBLiKYQ0XORcdBpBnHVh1HzM1apt834cOS2VEqju8d6+K8ipWdXgbSFNlDJbPZ4 Jn+kVsAB5n1msZsvNW831MhwrS4acVyDzgnFZl09k60IFWGGhJ4LGUecWXLxh0EYl+zA BPOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uz0iQXze; 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 w11-20020a05620a424b00b006b5aa1e06c8si5927135qko.99.2022.07.18.07.04.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jul 2022 07:04:05 -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=pass header.i=@linaro.org header.s=google header.b=Uz0iQXze; 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]:33682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDRLw-0005A0-UJ for patch@linaro.org; Mon, 18 Jul 2022 10:04:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDRHU-00023v-84 for qemu-devel@nongnu.org; Mon, 18 Jul 2022 09:59:29 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:41967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDRHS-00039t-KY for qemu-devel@nongnu.org; Mon, 18 Jul 2022 09:59:27 -0400 Received: by mail-wr1-x433.google.com with SMTP id n12so4335839wrc.8 for ; Mon, 18 Jul 2022 06:59:26 -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=4XCUImSLdHKkyI8geHYTH1ofyLU9VSFDcDRAFOqUvzE=; b=Uz0iQXzehnlIPq2NrFZu/wrxZjSvY5RsdfpS8Q1d7P1memboTsMpQgQG5DtlBOX0qa 9gb5kqfRW2mfzxoC/T3tiHmLrYpHqLtLVhcYBBf1jAGTr1gLT6iPOyvqA9L1xHE7cRNT 0VydP1nwY0901ouUYNUXwGsNz4PI0vVrJBSWWxq/28ED1pMC/5Lyvgm7Kkw09fUd0gu2 G4bNqgUiKKcyrwizjz/hY769F5CmtQOoURkUaB9A8Q7/3dVgZnuRzhMq9XQsXN+012OI UGZ1D/ecpBeHfgco+renZH2+0YzaGBNEUFiYlZ3Y0Xhf8tmUqdmwA07qiXCPUgY2157C 6+JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4XCUImSLdHKkyI8geHYTH1ofyLU9VSFDcDRAFOqUvzE=; b=IM4OmWpYuZNQ34m/JH2CddKDh+kF39vfsKZQ5v3Zy3IaxgugYLq85ABqTBhdpjsfEH 6tdRKZNMSO5w5QUJIIDLI2hC1Ns0sCDa5HyTig1DNgVujOupyiUAYHy38I8vuPAHzoJv GdLQxkCwQb6eJEYstI8MGusyIuzlPiwUXYSEoiMc6XMLgqgcameM7YE5hqvYSnJRf3uk eatAwcFyV8Bu4GGMfKp/82xgT1B4rxiQ9bUGNPl+QYsxtEjv6A4Nah3CSOeLhaF7wy+G IFAMqUmiV6Lh+0pJPE6evUhrcdbmUFUtNrFrKlk3GkdYThPHFHx9AkxZRVPpnGOgzYXM gAyA== X-Gm-Message-State: AJIora9VOJ6CmGRG/46Ve5NVYBhZOv7BtgxgbQ5ZGnQPQARs9VbDNeG0 8gtqwcUYWro1BLqpy0Z6MHEwD1tmZMxIjA== X-Received: by 2002:a05:6000:1e04:b0:21d:7ec3:fe5a with SMTP id bj4-20020a0560001e0400b0021d7ec3fe5amr23319088wrb.116.1658152764826; Mon, 18 Jul 2022 06:59:24 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id id15-20020a05600ca18f00b003a31f1edfa7sm1805798wmb.41.2022.07.18.06.59.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 06:59:24 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 01/15] hw/intc/armv7m_nvic: ICPRn must not unpend an IRQ that is being held high Date: Mon, 18 Jul 2022 14:59:06 +0100 Message-Id: <20220718135920.13667-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718135920.13667-1-peter.maydell@linaro.org> References: <20220718135920.13667-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 the M-profile Arm ARM, rule R_CVJS defines when an interrupt should be set to the Pending state: A) when the input line is high and the interrupt is not Active B) when the input line transitions from low to high and the interrupt is Active (Note that the first of these is an ongoing condition, and the second is a point-in-time event.) This can be rephrased as: 1 when the line goes from low to high, set Pending 2 when Active goes from 1 to 0, if line is high then set Pending 3 ignore attempts to clear Pending when the line is high and Active is 0 where 1 covers both B and one of the "transition into condition A" cases, 2 deals with the other "transition into condition A" possibility, and 3 is "don't drop Pending if we're already in condition A". Transitions out of condition A don't affect Pending state. We handle case 1 in set_irq_level(). For an interrupt (as opposed to other kinds of exception) the only place where we clear Active is in armv7m_nvic_complete_irq(), where we handle case 2 by checking for whether we need to re-pend the exception. For case 3, the only places where we clear Pending state on an interrupt are in armv7m_nvic_acknowledge_irq() (where we are setting Active so it doesn't count) and for writes to NVIC_ICPRn. It is the "write to NVIC_ICPRn" case that we missed: we must ignore this if the input line is high and the interrupt is not Active. (This required behaviour is differently and perhaps more clearly stated in the v7M Arm ARM, which has pseudocode in section B3.4.1 that implies it.) Reported-by: Igor Kotrasiński Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20220628154724.3297442-1-peter.maydell@linaro.org --- hw/intc/armv7m_nvic.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 13df002ce4d..1f7763964c3 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -2389,8 +2389,15 @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr, startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { + /* + * Note that if the input line is still held high and the interrupt + * is not active then rule R_CVJS requires that the Pending state + * remains set; in that case we mustn't let it be cleared. + */ if (value & (1 << i) && - (attrs.secure || s->itns[startvec + i])) { + (attrs.secure || s->itns[startvec + i]) && + !(setval == 0 && s->vectors[startvec + i].level && + !s->vectors[startvec + i].active)) { s->vectors[startvec + i].pending = setval; } }