From patchwork Tue Oct 25 16:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 618115 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3516676pvb; Tue, 25 Oct 2022 09:42:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4w+vhsnm22PP3EEHm2GKXIXCj0LqaidSDLeFlRr9Hj1mKBEPhho1o8slj4FqcyGUPsc3dW X-Received: by 2002:ac8:7fce:0:b0:3a4:ec00:aa92 with SMTP id b14-20020ac87fce000000b003a4ec00aa92mr370150qtk.161.1666716129921; Tue, 25 Oct 2022 09:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666716129; cv=none; d=google.com; s=arc-20160816; b=eVig//SVvNttbVPFyCz+t3ilAL22g0pCDEyQjSO6zwHG1DbhiEW0gib/zAqFNVEnlW SFxDl3PKMuXgmYHAdMM5QgR3b7MIBKZ95QEq8oFr40P/lHP5dvv/DlfkOzFwCYkY86At 9tFaMnst58ltn3GfaKrvEXsmJiLYvH1F7P2J792KIrJat+odNza7AHUzUbSNKf5MP6oD XV1XjEtSWTwzsNwA6j8rQr4yZRn3NnM/cKXbpFDYvx4l3GFbkJ27GghfO3EjDbsams34 evYgRBnnnlRwg9MGrTvGvZ+OkaViQpdALuI3/cCu89UFVl9D8XvoinLRPqWb3j0rtcfE 9jUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender: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=BkdsxeivDrs8B1ekF6DlyQ39i4YB9EYQepwnyoXzyuw=; b=O30igvN1NeTDObeRUgfj2HGi7MN/hCCZHhFLgr+tW3Bo7LEiy0VyBC5BiBtbU6Sf+s 4RpFBgZGTDmPXtMFl7doRW5T+aYRnu2KgnAj51JM2Rngu4lJga4d+SWpMLYfY7cvUSS3 ZHOFgJAfYwoOAxTTVJxCJrmpc3+iiNYlHaWR0y9ucirXL+U5mRMMuXRmwjtDW5AyZO3k ZiNTyo56nMn+GcUGsxCtVVCCi8fw5k5oKwiGJM5Lu8SjaS4WoHiUWHQOZ6sBYhGtUhsB O2rLIuRACwRJDH8I4JDxdDSc3jk2zx422HsQAY5jTEfWdBAFL0zv44ZoDrYxEGSjaslV pgFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jCUxJwlB; 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 s10-20020a05620a0bca00b006f3cd8c58b0si2233823qki.39.2022.10.25.09.42.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Oct 2022 09:42:09 -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=jCUxJwlB; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onMyS-0005pO-SV; Tue, 25 Oct 2022 12:40:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onMyN-0005St-3v for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:15 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onMy7-0001OZ-SL for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:14 -0400 Received: by mail-wm1-x32f.google.com with SMTP id l16-20020a05600c4f1000b003c6c0d2a445so8664441wmq.4 for ; Tue, 25 Oct 2022 09:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BkdsxeivDrs8B1ekF6DlyQ39i4YB9EYQepwnyoXzyuw=; b=jCUxJwlBRj9DLNOLPVPQlLd6FPKz0e6uAZo8ZfHPiZlu6YcDigTC3dDQM1xxo3KNys z3xd/74gxow04mgfxkX47vtuHJEPDynMgikw/adB4bDCbdnUaYMkuQhpvp8WOBRTpE9A aooA2jF7ugTZMRfUdQlHXlkGyzbVs0LZmAxfpz8ougRwLE8+zA8l1g89MOT3gIkOJf0H PMH0hSO6zM6H6Jhb4IZiTQeZo5pNvPuAcURF+c63RxrTSMFcaamvksHrMuVsStjK41yr N/aN+V5YDJX2ljqOS6UAubvrh7fKQVGblo1h7oLailDfUdmHfImJPRkKjAM5acDX4Zzi Yx7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BkdsxeivDrs8B1ekF6DlyQ39i4YB9EYQepwnyoXzyuw=; b=huWbHxS8+bDSE7TUETQKww6vs0Q50RGtizeqV5rWZ7UWpCMcW0NGe1F0LVishNe+vg t7RI4uoV4bPxE1Zn2+LOj8rD4BgMZsiZ02IGYgBSfD9mCVkz1tXpqolRXcG5k/CtNB+k akcXVfZs38tr+Y7bKeoFEu8vNWckBw55GV4o7GVl1oAw4vnQ2+qm3r2ReILAN+tFwoeP QMoYNIBpKoIXmAD2agWROtVtJVl5NxGy/bL4ardPEIoI2DV8lobWz0CLhloUdUDC9xAJ Za5cP4KH8k1H6PcK0YUgQruT0ZesjNoMeiHwmjPEiMCfesvCS4NU/5yvwepCky167itp Qe8g== X-Gm-Message-State: ACrzQf0acCfINJF787hv00erxkZKSEWdhweHusjmur1XSZGdY8BX2Xp/ /OEKsYv5Oy8y8wNcnetKGGk3uSStXpc/aA== X-Received: by 2002:a05:600c:3509:b0:3c6:fd36:ef19 with SMTP id h9-20020a05600c350900b003c6fd36ef19mr27261282wmq.191.1666715998429; Tue, 25 Oct 2022 09:39:58 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z12-20020a05600c220c00b003cd9c26a0basm2971084wml.40.2022.10.25.09.39.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:39:57 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/30] target/arm: honor HCR_E2H and HCR_TGE in arm_excp_unmasked() Date: Tue, 25 Oct 2022 17:39:25 +0100 Message-Id: <20221025163952.4131046-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025163952.4131046-1-peter.maydell@linaro.org> References: <20221025163952.4131046-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ake Koomsin An exception targeting EL2 from lower EL is actually maskable when HCR_E2H and HCR_TGE are both set. This applies to both secure and non-secure Security state. We can remove the conditions that try to suppress masking of interrupts when we are Secure and the exception targets EL2 and Secure EL2 is disabled. This is OK because in that situation arm_phys_excp_target_el() will never return 2 as the target EL. The 'not if secure' check in this function was originally written before arm_hcr_el2_eff(), and back then the target EL returned by arm_phys_excp_target_el() could be 2 even if we were in Secure EL0/EL1; but it is no longer needed. Signed-off-by: Ake Koomsin Message-id: 20221017092432.546881-1-ake@igel.co.jp [PMM: Add commit message paragraph explaining why it's OK to remove the checks on secure and SCR_EEL2] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/cpu.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 0bc5e9b125b..8aa8a1419df 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -562,14 +562,24 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, if ((target_el > cur_el) && (target_el != 1)) { /* Exceptions targeting a higher EL may not be maskable */ if (arm_feature(env, ARM_FEATURE_AARCH64)) { - /* - * 64-bit masking rules are simple: exceptions to EL3 - * can't be masked, and exceptions to EL2 can only be - * masked from Secure state. The HCR and SCR settings - * don't affect the masking logic, only the interrupt routing. - */ - if (target_el == 3 || !secure || (env->cp15.scr_el3 & SCR_EEL2)) { + switch (target_el) { + case 2: + /* + * According to ARM DDI 0487H.a, an interrupt can be masked + * when HCR_E2H and HCR_TGE are both set regardless of the + * current Security state. Note that we need to revisit this + * part again once we need to support NMI. + */ + if ((hcr_el2 & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { + unmasked = true; + } + break; + case 3: + /* Interrupt cannot be masked when the target EL is 3 */ unmasked = true; + break; + default: + g_assert_not_reached(); } } else { /*