From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057472; cv=none; d=zohomail.com; s=zohoarc; b=GEk238Z1otcFb3RjrNELfCDvM6uW1tshvTqfCcB6ZZ9m5QhpcX5nPnc9/mWZiAHjlnTG8iOyRB8os9uNUrF/IAukpsVafuRKmtnqkdrBr6y4oepCkjUbOOdAoCH6sYklTgzLZGijnSx3R2IEqH+dKFp/A7yQ1n+I+rlM6g9QF/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057472; 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; bh=6bcSsnl6u82JYa+g2MBv9GVvdo5DY+x1DAHdRtbYsP0=; b=g9DkyZj+b8rPnsMjo96951u2C+KgfKMVDVFHlQxhjh/F2VkOXqLBt+xP3JQ57IYdcIFLWHRlM4H9StSppxoLyeH1nGY+KnJR5M8alfW4Rd7eHcSdxs+ffNcBqJE+9gMv8AaGpJDiE+gwYJs0xOwBkPQP6kFPDP+G+PUObWtlNiE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627057472541286.1941990311983; Fri, 23 Jul 2021 09:24:32 -0700 (PDT) Received: from localhost ([::1]:49398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6xyR-0003ls-8W for importer@patchew.org; Fri, 23 Jul 2021 12:24:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvt-0008QX-DS for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:53 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:33329) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvr-0000kp-Dt for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:53 -0400 Received: by mail-wr1-x430.google.com with SMTP id q3so3038867wrx.0 for ; Fri, 23 Jul 2021 09:21:50 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:49 -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=6bcSsnl6u82JYa+g2MBv9GVvdo5DY+x1DAHdRtbYsP0=; b=H6dZBnzoqjJDX0KwISIefbEulJ+2575Ex/SNWD2GZw3VU+DRfn66XFWLBFyviC07Wp 9rqtcANTpIqSaGZhQNBGEHK/I3k+eIs4aPEQrgcahzyEuJjIJrREjhW6HwY8vVVfw6mI CnVRlXQJT3pkxO5bO6VEb+luJV4Jfx7CnR/JDxOJFhI/P1TBqROdcQZ8Li2dreCljxzw SAROfw4mXaVtrsTHgijweLG9D7GEz+a+7Pc1KZiLnK555YavSLRRiO+WF2+doDLj9zTz i9aCfwLhfUAEyJ4GutqdZM7GOiYFfcGm/ojAdIup2IFprvHCtSmtYn0ku9f8im39RIao ooaA== 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=6bcSsnl6u82JYa+g2MBv9GVvdo5DY+x1DAHdRtbYsP0=; b=ZoPYmh7L55cyZ5/GG9QX1CFR1+6RcRFtkOFxOtUC8lL8B7ZAFlRw5Bgtat5oufeyW6 Z51S62NAPWtTfRFo9UIhrj/kwTIbJkmPqtvhvnr4prmae/lhJU1pY6w8gd2VoxPLc8hw MwEGbnXRSAN+KomutRqKponK9AoOhzNCHHKU81ZrZd5E5tYNrkDl5LwTnxVLoQRKUbnt V8bSGfSsb3wT3BB+SRxkc4eiYgcJUYQTSy8KE1lIm3uOZhvkuUOSueGGQMJXEieI5WfI Z5GqLtd1pRVfq5JJkQOJOovVEkigh75aCNyvLHnciYU7Xf530+IwTR0+03ZpAIihifzC h2vQ== X-Gm-Message-State: AOAM533mwAlPozPRzx6Z+JbSbpTT8O88eCZODAB/R2t7wfQdUDYXWKd5 f1diYPV3eNrg98HG8HKLTr5AkBx2SNfdiA== X-Google-Smtp-Source: ABdhPJxUATm+Q1J61YDeZF2AL8KvQj3g5hrmc3V2ZqcS/9bjzctOJOep08cRQ5GbiSaLR7Hbnk8ZOg== X-Received: by 2002:adf:dfcb:: with SMTP id q11mr864529wrn.16.1627057309409; Fri, 23 Jul 2021 09:21:49 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 1/6] target/arm: Enforce that M-profile SP low 2 bits are always zero Date: Fri, 23 Jul 2021 17:21:41 +0100 Message-Id: <20210723162146.5167-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057473883100001 Content-Type: text/plain; charset="utf-8" For M-profile, unlike A-profile, the low 2 bits of SP are defined to be RES0H, which is to say that they must be hardwired to zero so that guest attempts to write non-zero values to them are ignored. Implement this behaviour by masking out the low bits: * for writes to r13 by the gdbstub * for writes to any of the various flavours of SP via MSR * for writes to r13 via store_reg() in generated code Note that all the direct uses of cpu_R[] in translate.c are in places where the register is definitely not r13 (usually because that has been checked for as an UNDEFINED or UNPREDICTABLE case and handled as UNDEF). All the other writes to regs[13] in C code are either: * A-profile only code * writes of values we can guarantee to be aligned, such as - writes of previous-SP-value plus or minus a 4-aligned constant - writes of the value in an SP limit register (which we already enforce to be aligned) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- This is one of those changes where the code changed is clearly OK and the review is more "did we miss anything?". Optimization of cases in generated code where we know the value is already aligned would obviously be possible (eg "ADD SP, SP, #8") but I haven't looked at that; after all, it's only one extra AND insn. --- target/arm/gdbstub.c | 4 ++++ target/arm/m_helper.c | 14 ++++++++------ target/arm/translate.c | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index a8fff2a3d09..826601b3415 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -84,6 +84,10 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *me= m_buf, int n) =20 if (n < 16) { /* Core integer register. */ + if (n =3D=3D 13 && arm_feature(env, ARM_FEATURE_M)) { + /* M profile SP low bits are always 0 */ + tmp &=3D ~3; + } env->regs[n] =3D tmp; return 4; } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index 7a1e35ab5b6..f9a9cb466c9 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2563,13 +2563,13 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t mas= kreg, uint32_t val) if (!env->v7m.secure) { return; } - env->v7m.other_ss_msp =3D val; + env->v7m.other_ss_msp =3D val & ~3; return; case 0x89: /* PSP_NS */ if (!env->v7m.secure) { return; } - env->v7m.other_ss_psp =3D val; + env->v7m.other_ss_psp =3D val & ~3; return; case 0x8a: /* MSPLIM_NS */ if (!env->v7m.secure) { @@ -2638,6 +2638,8 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskr= eg, uint32_t val) =20 limit =3D is_psp ? env->v7m.psplim[false] : env->v7m.msplim[fa= lse]; =20 + val &=3D ~0x3; + if (val < limit) { raise_exception_ra(env, EXCP_STKOF, 0, 1, GETPC()); } @@ -2660,16 +2662,16 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t mas= kreg, uint32_t val) break; case 8: /* MSP */ if (v7m_using_psp(env)) { - env->v7m.other_sp =3D val; + env->v7m.other_sp =3D val & ~3; } else { - env->regs[13] =3D val; + env->regs[13] =3D val & ~3; } break; case 9: /* PSP */ if (v7m_using_psp(env)) { - env->regs[13] =3D val; + env->regs[13] =3D val & ~3; } else { - env->v7m.other_sp =3D val; + env->v7m.other_sp =3D val & ~3; } break; case 10: /* MSPLIM */ diff --git a/target/arm/translate.c b/target/arm/translate.c index 351afa43a29..80c282669f0 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -291,6 +291,9 @@ void store_reg(DisasContext *s, int reg, TCGv_i32 var) */ tcg_gen_andi_i32(var, var, s->thumb ? ~1 : ~3); s->base.is_jmp =3D DISAS_JUMP; + } else if (reg =3D=3D 13 && arm_dc_feature(s, ARM_FEATURE_M)) { + /* For M-profile SP bits [1:0] are always zero */ + tcg_gen_andi_i32(var, var, ~3); } tcg_gen_mov_i32(cpu_R[reg], var); tcg_temp_free_i32(var); --=20 2.20.1 From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057520; cv=none; d=zohomail.com; s=zohoarc; b=mj79t2xTf3UgAoeDucb788KMcwVm7ab5xNenofthI7XvpAsvacKg6Dxm4GWs6lCNIqDkUWo11Pq2f9BsBg66kti7lX3eho8qluKXAHVOU/gDy67i4LkhrFXGXTnTvvm2QoZwBTCdjEw98n+JfuTcfOaSdazIYKxnAFbVHpdcQfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057520; 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; bh=ACI532LNdXUXkP6ZLogSGJNZsbzdsfTkMdhJh+PsYgE=; b=VamI/RTdJ+P0kL5ijAMJPo5gjj0LIPmsC38CMBcIAfJyKiKJO8p6TUTd/wsdx81m1AJMKMmQwCZ56PU0zl39SdReAHy/AejfskTVbpSdVEUbdlC+7IueTkM+PhQIVeI9KMAHOF+sEOItFw377YwPL/RLBkUpRKoJLAHGH/k5sVU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162705752026317.12976937734652; Fri, 23 Jul 2021 09:25:20 -0700 (PDT) Received: from localhost ([::1]:51728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6xzC-0005KH-HC for importer@patchew.org; Fri, 23 Jul 2021 12:25:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvv-00008K-S4 for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:55 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:39935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvr-0000lX-E3 for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:55 -0400 Received: by mail-wr1-x436.google.com with SMTP id e2so2962184wrq.6 for ; Fri, 23 Jul 2021 09:21:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:49 -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=ACI532LNdXUXkP6ZLogSGJNZsbzdsfTkMdhJh+PsYgE=; b=R/0Fftc4OuG+6LGRRv1QsPli84hUDQxMqxbibcURt/PPTyiojlJe8/n4LJe2tMtXde 2zkhE5azVv2EudV1syzBz5n4D6yQrghixe63AibGYDTDohKpcHzR24yzSzmEXmEKErt6 NdiNDNJhGzEBCbRZ5TcCzqdd9amLnHm3dEGKVxjn4aEH34gEtNED0cu6VNTsj7hUh+7c kLoNqTH/Z0p1yYKM2jl/1+rCUEmv7LYyLRRJNRFexKsyxq4xS0X8wp4HP7O/9hecCubU khrY510pN9rLdr0jUwEvG5ZpdlDtNRZOHbv+MbeugYMzn2lu19rX4jZMmnyjM5bDf8/L ywYw== 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=ACI532LNdXUXkP6ZLogSGJNZsbzdsfTkMdhJh+PsYgE=; b=bOPXmzdVHitMsacVvBaL8O6vdBZjtruOZbhwzpNIjlLqr0TkgqAgUvtyKyDGjkje7E dybOLaZRPEGQU7RbjgR+aHkFGE4imRRhhWYvDJPo1uv2P1z95Qw7ArTRACiX0JZPQlrT 1S0gm8M1WCNQapPuwDZD7/1huBvLXcnSU/w2hdwaJL8+k910hgd69vMdy3sylm+ZZYS5 BzigL3PGd1r8AtwSTNwimpwf8H6EEP9VosQUp4+SuFYYF3/DSkpdU8p3nRpUtIJ8vWuu Mvlw5/STR9GUxXDxhC/zApC0Z4JvXpP7wH2l13dKhAvWrhuf5nIB2mZBTR9VsRAR6PwA lyYQ== X-Gm-Message-State: AOAM530TDxI8Y5n7Kk1rlPM9NR66I2j5t3PhcqU7ymx8Pt9bSpqaPMHy BNDVwPWe2ClcZElKFgNMKmSu3Fu/zwpxmQ== X-Google-Smtp-Source: ABdhPJw396ib9ePD/p10QE3kj3p5kUCaeOfR7436zra85yEEEg8AXuVyvXdkHfxRP8ID/JKG7ewmSA== X-Received: by 2002:adf:fcca:: with SMTP id f10mr6048912wrs.323.1627057310098; Fri, 23 Jul 2021 09:21:50 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 2/6] target/arm: Add missing 'return's after calling v7m_exception_taken() Date: Fri, 23 Jul 2021 17:21:42 +0100 Message-Id: <20210723162146.5167-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057521201100001 Content-Type: text/plain; charset="utf-8" In do_v7m_exception_exit(), we perform various checks as part of performing the exception return. If one of these checks fails, the architecture requires that we take an appropriate exception on the existing stackframe. We implement this by calling v7m_exception_taken() to set up to take the new exception, and then immediately returning from do_v7m_exception_exit() without proceeding any further with the unstack-and-exception-return process. In a couple of checks that are new in v8.1M, we forgot the "return" statement, with the effect that if bad code in the guest tripped over these checks we would set up to take a UsageFault exception but then blunder on trying to also unstack and return from the original exception, with the probable result that the guest would crash. Add the missing return statements. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/m_helper.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index f9a9cb466c9..f352346a964 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -1554,6 +1554,7 @@ static void do_v7m_exception_exit(ARMCPU *cpu) qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on ex= isting " "stackframe: NSACR prevents clearing FPU registers= \n"); v7m_exception_taken(cpu, excret, true, false); + return; } else if (!cpacr_pass) { armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, exc_secure); @@ -1561,6 +1562,7 @@ static void do_v7m_exception_exit(ARMCPU *cpu) qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on ex= isting " "stackframe: CPACR prevents clearing FPU registers= \n"); v7m_exception_taken(cpu, excret, true, false); + return; } } /* Clear s0..s15, FPSCR and VPR */ --=20 2.20.1 From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057588; cv=none; d=zohomail.com; s=zohoarc; b=A6ekFhAmhGBdYlPa+5kS3UgZ/GqvGaAvn0VNlj5EBEjTa9X6it5SxeEeRzgovQfs0JSQz4q+CipKFO9nkjy0xrNVi2MA4ixhz6GPKVmFrhSkqe6Il96ztUZnsYF4R0Xxn3JvXE5h+s9yKcocA6T4H0mmvuvSn/RKeNcrIOCGvac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057588; 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; bh=9nvGoOgx6h6XmbBua01EVVw7UXwgA9qVC9DjO1im9I8=; b=MTVmfcrDbLkHHEn5zhd53S5MFKQFyikdCa/fGttuYooaI4hsOOXGitWA9pXzI+YzSCjwD7vh7f1h16IaSipRMkl218+Uqj31lAvoC7rw/RCcptwP/MvQeAac6ZY5ghX2iH+nz/aUvGivKLPmr0re9aAmm5/KRYm/sYgY8qQTWWg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627057588628234.8725122397509; Fri, 23 Jul 2021 09:26:28 -0700 (PDT) Received: from localhost ([::1]:57882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6y0J-00014c-FX for importer@patchew.org; Fri, 23 Jul 2021 12:26:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvt-0008Rq-PG for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:53 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:46625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvs-0000lf-52 for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:53 -0400 Received: by mail-wr1-x42c.google.com with SMTP id w12so2896113wro.13 for ; Fri, 23 Jul 2021 09:21:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:50 -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=9nvGoOgx6h6XmbBua01EVVw7UXwgA9qVC9DjO1im9I8=; b=mU5feMaCGu8BBRFIKhPl/v5gTzExIgjISaZWcEaPKwyDQc27xBkXLZeR9ndAsAnjkY eblmDUyFFhZTq/lu2EZjXYfdrMQj39T7jsJIBXe3ZPtM7hWLuajBXfqfe00skItUaYiw z7eRLDKTCnTNwDmW2tTanUE3eMWsww4gpc+5eUxe/ksVQMzGPPEY7AuJJ8ioa1V2Onkz 1FkT0/omccDIYwsRWB/76VtdLNlPoNgGgt882L2PduHLJ0ADZrQOgVS6cG420w+9Wqan NwJCFtCWNXaMI17R+kfa3c/Qt8y32MaQ5jhNCXikNL0lGil0fljDMDXFjpieNER0ua+g W/uA== 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=9nvGoOgx6h6XmbBua01EVVw7UXwgA9qVC9DjO1im9I8=; b=a4HiAo83Z+kWXkhySVTeO2WqAGS+KWuW3m8xYBfPcNaymUahRg9H4Hv7YVqPEkAI0L GakVROwrhXIS1gaal1W8KxODAD24YN9COftGBpjKBHETkSEpQomsO6vbgAvw1RwVt8fe sGGCFRazHkh4Q0oFgnDbEkSMCWEjVYc4SMG4fdG7LJZlcnMsRMSg5ecAm2+gGad7p10E ou/RvbocGSpghGKP45Kxdor92zz5dlRSF8V/RczHSZNp8PqnbDQkR8oR+DS9Xu8WCeeU Mhzb/CMnII1bXeXYDrcM7WGnk9YpKPTuAYgnRescUTtD1FFIF+M61wbmwz3QEifLg+iN LBFQ== X-Gm-Message-State: AOAM530AcQ8H0kNsstwpIi/NHqaHTVXSI9V2V0ubhAneu96ZsqFr7ZvY DVYTwXC4mmQ2FKAuLc7tVT5rBg== X-Google-Smtp-Source: ABdhPJwEMFWBa0a4mcEhtikINci74e5qMkm6phEo7Ez7s3TTPuvF2rOr9mMGzcvnKCDuUemUxqHl3A== X-Received: by 2002:adf:e610:: with SMTP id p16mr6456978wrm.98.1627057310805; Fri, 23 Jul 2021 09:21:50 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 3/6] target/arm: Report M-profile alignment faults correctly to the guest Date: Fri, 23 Jul 2021 17:21:43 +0100 Message-Id: <20210723162146.5167-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057589521100001 Content-Type: text/plain; charset="utf-8" For M-profile, we weren't reporting alignment faults triggered by the generic TCG code correctly to the guest. These get passed into arm_v7m_cpu_do_interrupt() as an EXCP_DATA_ABORT with an A-profile style exception.fsr value of 1. We didn't check for this, and so they fell through into the default of "assume this is an MPU fault" and were reported to the guest as a data access violation MPU fault. Report these alignment faults as UsageFaults which set the UNALIGNED bit in the UFSR. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- The other approach would be to have arm_cpu_do_unaligned_access() raise the EXCP_UNALIGNED which we already use for Unaligned UsageFaults which are raised by m-profile specific helper code, but I think this way is in line with the current design that generally prefers to report exception information in an A-profile format and then re-arrange that into the M-profile information in arm_v7m_cpu_do_interrupt(). --- target/arm/m_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index f352346a964..20761c94877 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2248,6 +2248,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) env->v7m.sfsr |=3D R_V7M_SFSR_LSERR_MASK; break; case EXCP_UNALIGNED: + /* Unaligned faults reported by M-profile aware code */ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.sec= ure); env->v7m.cfsr[env->v7m.secure] |=3D R_V7M_CFSR_UNALIGNED_MASK; break; @@ -2320,6 +2321,13 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) } armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false); break; + case 0x1: /* Alignment fault reported by generic code */ + qemu_log_mask(CPU_LOG_INT, + "...really UsageFault with UFSR.UNALIGNED\n"); + env->v7m.cfsr[env->v7m.secure] |=3D R_V7M_CFSR_UNALIGNED_MASK; + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, + env->v7m.secure); + break; default: /* * All other FSR values are either MPU faults or "can't happen --=20 2.20.1 From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057568; cv=none; d=zohomail.com; s=zohoarc; b=anX38W0kJMT9qv1Osx/9PTrjNVtUBL5N3AwFsf2J5abeSro6pS/2venpI1AsRcfQ4R9cD3xl6uUKYxeFaqKPrO7R6K3O8m1WzcI5FGRnn+gGELZ+1OHBbsruQ828/66Y37vHPRiwwOK3usedtkxs1NCWXQ51JkdAvYaaOpohLnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057568; 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; bh=jtp3KRCI/WqcQZFgyWlDzbbEg7X9yExcchTvn/7fMB4=; b=FlqMEFWv/WdOrx/DUhBqaC2tySn+NQ7Cn8DGAg4zZRheLBn2gD5UNkgDs6fo8KuCRiAVsrZuI4hiO/ZTcA/GZoWtl9rwnZT9SNs+F3Ej9kUeX6dpM4wZSSP2M16kPw5/r3A5wP2SXcT9hcbH0XYx1rPhMgkWCW0Dhw+wNFKBAkQ= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627057568993835.0850939899074; Fri, 23 Jul 2021 09:26:08 -0700 (PDT) Received: from localhost ([::1]:55996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6xzz-0008FH-Uc for importer@patchew.org; Fri, 23 Jul 2021 12:26:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvu-0008Vj-VU for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:54 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:37725) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvt-0000mD-3G for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:54 -0400 Received: by mail-wr1-x429.google.com with SMTP id l4so2971169wrs.4 for ; Fri, 23 Jul 2021 09:21:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:51 -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=jtp3KRCI/WqcQZFgyWlDzbbEg7X9yExcchTvn/7fMB4=; b=uSG0rBN/5LXC/+w1ZA/oKc31355sHypP072dMWPEcK4OgXmO011TftO+3pbQkY/PvO z7Jfz3V+MrN/s2fVLple/sxHVBo0fkUmxwUX9VuqmeCxEyAL1M7BkR8ReOTFK9TYTanb kUlxsevFG+DOuKRwOuhneofW3mRH7YfmuGlOE4z+sT1wQ8+L3ce5Du4PrPj1GMeO1pB+ wq5ORlNkHjY8mtl/ry9jZZBCdjxx/ozNAX2zVTzrjpaxlyy0kKdA+PvlslJMxgDi7rK+ DbCFmlwBMmCKeHMDlC+XXM8MLUu1NbgISjiKcrJGWiuqfMQwDKqKeizA/0gP05w9pz9r cpIg== 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=jtp3KRCI/WqcQZFgyWlDzbbEg7X9yExcchTvn/7fMB4=; b=DspiabZuvo4wXn1xLb4VfPsrwjpF3fQg4zeukG4zxhIzr3suWTCgncYUuhFf1Fkfme sxIP1uMk9cof2vOSyJEr9uLjVyVe6Pp330U85spi+HEppUzm9booHNEAGQF1uyAVb4TV 2IAXwEatfGeKeKSW18MuriZVfPgMWL70kJDhmHwzmtLfu6J1huogsFC1Y5a7b272ffc9 X9cfOdui4v3NmHA62VOuNTSl2B93+dihARfkv1WetwqmUBEi+QG16lqJ+Ui/T7aZ/PQZ 4zTq4ekfv5fjiefZlIXZvPpUAZJ2TD4XiRj4F5RoW3kelNIVg94P9KO2Hqp0YII6A48c TRmw== X-Gm-Message-State: AOAM531OGk6VBkfexci+KwjYbWJHxpBGzthF/Qvpq9GAUvPWMaHlDsjF C0wqtHDvJjZS6NXTBqFw1LtTVA== X-Google-Smtp-Source: ABdhPJxUJhizYLBzeg6sqLQe0ETFttIB8ezMd1EIAeqZxlUyIHF56Thde9JeA31gfndQEtBoUUPQZQ== X-Received: by 2002:a5d:53c5:: with SMTP id a5mr6264256wrw.15.1627057311454; Fri, 23 Jul 2021 09:21:51 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 4/6] hw/intc/armv7m_nvic: ISCR.ISRPENDING is set for non-enabled pending interrupts Date: Fri, 23 Jul 2021 17:21:44 +0100 Message-Id: <20210723162146.5167-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057569869100001 Content-Type: text/plain; charset="utf-8" The ISCR.ISRPENDING bit is set when an external interrupt is pending. This is true whether that external interrupt is enabled or not. This means that we can't use 's->vectpending =3D=3D 0' as a shortcut to "ISRPENDING is zero", because s->vectpending indicates only the highest priority pending enabled interrupt. Remove the incorrect optimization so that if there is no pending enabled interrupt we fall through to scanning through the whole interrupt array. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/armv7m_nvic.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 94fe00235af..2aba2136822 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -127,15 +127,14 @@ static bool nvic_isrpending(NVICState *s) { int irq; =20 - /* We can shortcut if the highest priority pending interrupt - * happens to be external or if there is nothing pending. + /* + * We can shortcut if the highest priority pending interrupt + * happens to be external; if not we need to check the whole + * vectors[] array. */ if (s->vectpending > NVIC_FIRST_IRQ) { return true; } - if (s->vectpending =3D=3D 0) { - return false; - } =20 for (irq =3D NVIC_FIRST_IRQ; irq < s->num_irq; irq++) { if (s->vectors[irq].pending) { --=20 2.20.1 From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057652; cv=none; d=zohomail.com; s=zohoarc; b=L/kwT2oTRvPTEagN57DgcvxDdHgJY/pccETywtDIdJHFLe7/NovWnZMfohMLrM/drfCSeW1H0r+G1Syi5hmEIUC4W++yglKtsvm4Pu/XTsdWihYs5mYtLnZUfU0dD00H8SZTebl5UbLi83wJxEs3PTCiXTUwHHgesY9ACmxbCzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057652; 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; bh=25KPohKxJgwnGi/5F22vyFBpbh7T5Mv/FLljFv1RBvg=; b=WMu0vWxdveujrWbBN4D1yOpUEKS0qiktQ8A+8I/IZLfs3lNoCnRwR9ZPX77IgWEikNZRVRyH5N833BQb5EOOfLFl5f9HBh870Ji/EIuwijfy2wZIgu7cSeyRWgKwJp+oSy9jFtgJEQLR8ItRlsgNUYJFSUOK42IJIGQ0EnHIZT4= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627057652185441.89110095371154; Fri, 23 Jul 2021 09:27:32 -0700 (PDT) Received: from localhost ([::1]:33170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6y1L-0003Np-8U for importer@patchew.org; Fri, 23 Jul 2021 12:27:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvv-00004q-4x for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:55 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:40713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvt-0000mQ-EQ for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:54 -0400 Received: by mail-wr1-x436.google.com with SMTP id z8so2956897wru.7 for ; Fri, 23 Jul 2021 09:21:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:51 -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=25KPohKxJgwnGi/5F22vyFBpbh7T5Mv/FLljFv1RBvg=; b=MVR+KH17X035bYJ7dmzqEKZ2hDNHNNdUuB6zq44bsqU17LRdNmyZEs5nwVsMT6xqSG MuWTZQ0w7UbbOCoGz7GA2Q+ZivwNTs+HwK9LYPzJhZoA9kT9NEqZ4nolJcDOQK3X2X/3 5wlgUoHnBgjyPgTxCv2aTlDlzXv8mnmTm0RZtpL++TPZyw1drb5casLeXRCaGhStL40H 4MnE0tGxn5NYMqeJdjuii7bUTkUxIJPC/SmO7M6+2/RYSOT0TMl6vCiGxdSQ3ZMu+mLR ScmiBgLguIqkfGr80i7JZnYz6KMpN2lkXiWY6/aIZYYYX/IW0iKw4gQ0MSIWZW7TWo2u 0Fug== 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=25KPohKxJgwnGi/5F22vyFBpbh7T5Mv/FLljFv1RBvg=; b=lJUfl3ZGiMsc83zO2rI3pjlxIoju9V2YuPI2RNfdGfKBl4sgnrTydeZJKN4YH4bFGI /lunMDpwuQpFEcaGjwEEkv3xygGa82IhvexBcJj/YEAMHlK2UkQ7N9ll7luv/Uj2NIDs XEge+9cEURXLIu0chdhKrELKYm/XR/36G5fEFn9JTz0k1CBBuS8k6m7lFo9kbDmSASmh 36uW4iBafjUoDuErGXzyHEizFoRkg0RKLZwEgw1y7b6O2bPrBPwNg3YQ5eXJA+9Crdvm dvfqbUlPj7Anwt6ll1zrwdHlD6tNyAalrG9AbjLCEHz+kmWCnLrdjEvxJfIr25QGUiRK PIhQ== X-Gm-Message-State: AOAM532VaRWr/VZrW/ss9cmb0JIhccjFu8WXhCFbhf1uUQSbSxRHQVnm 8jRaHVJU2h0JYDWx5Xjcjd8KjA== X-Google-Smtp-Source: ABdhPJzHBxOi2Q56WD1gGDWjXh3g/yu4Z8MrZAj+lQCi5Wez8c1pOYq/qetNeGD3M9QfYHigWwddJw== X-Received: by 2002:a5d:610b:: with SMTP id v11mr6237736wrt.58.1627057312106; Fri, 23 Jul 2021 09:21:52 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 5/6] hw/intc/armv7m_nvic: Correct size of ICSR.VECTPENDING Date: Fri, 23 Jul 2021 17:21:45 +0100 Message-Id: <20210723162146.5167-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057653432100001 Content-Type: text/plain; charset="utf-8" The VECTPENDING field in the ICSR is 9 bits wide, in bits [20:12] of the register. We were incorrectly masking it to 8 bits, so it would report the wrong value if the pending exception was greater than 256. Fix the bug. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/armv7m_nvic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 2aba2136822..c9149a3b221 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -1039,7 +1039,7 @@ static uint32_t nvic_readl(NVICState *s, uint32_t off= set, MemTxAttrs attrs) /* VECTACTIVE */ val =3D cpu->env.v7m.exception; /* VECTPENDING */ - val |=3D (s->vectpending & 0xff) << 12; + val |=3D (s->vectpending & 0x1ff) << 12; /* ISRPENDING - set if any external IRQ is pending */ if (nvic_isrpending(s)) { val |=3D (1 << 22); --=20 2.20.1 From nobody Sat May 11 17:56:05 2024 Delivered-To: importer@patchew.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=1627057474; cv=none; d=zohomail.com; s=zohoarc; b=k9Z3RMj+xf5VtHyfIBYbCU20qOz9Hv27XxVec/TxSL23a8MwbE1TCHlG4qbe2jXc7gIY31Ri8Hf/9O6MMUNsIofZBSp0CYGnwWw4ZrStg75PPoDYcdNvNKtLYYdtdmda9cp5NiSrWCbO0eR4yjq0titxhQST6QMrIh4mUJNnpK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627057474; 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; bh=ka61wmIogbeS4FZRJa7FPEYoz1c9JdTmedELNF//a8M=; b=k+R85TyPXoCQ36PKp40hrfky3GvhTk4aMKS4y1T3PdvJotSqqKDEpovkSK/0QGHA9eEBqlceUIe0yYPai4WQSXvxEQDuRyc8eeO4rIs0lXIrh4NIOTS8vAiCOUolhGqqurhBM+IeuAiM/X63jAlwC18csZZ/eaBfz3EqyhXJFO4= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627057474016831.0392951420125; Fri, 23 Jul 2021 09:24:34 -0700 (PDT) Received: from localhost ([::1]:49526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6xyS-0003s6-T0 for importer@patchew.org; Fri, 23 Jul 2021 12:24:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6xvx-0000F3-Ao for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:57 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:52840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6xvu-0000nh-KZ for qemu-devel@nongnu.org; Fri, 23 Jul 2021 12:21:57 -0400 Received: by mail-wm1-x334.google.com with SMTP id n11so1137561wmd.2 for ; Fri, 23 Jul 2021 09:21:54 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y11sm5721416wmi.33.2021.07.23.09.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 09:21:52 -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=ka61wmIogbeS4FZRJa7FPEYoz1c9JdTmedELNF//a8M=; b=Rv47M0cPeysNEuw9bwXgXRnEZbbSso/VLRh3u8fwAs/ypEUJtHwex+yaZv29iycxif klJAWGaatDMJo8negcMnTYIy4Up2bT4wrVPF8jaiERMi5NgTNW7B0zoxwb6x/A+90nRJ l2IK+ZPmb7rhgpgbVorKGeoAjpjIU97tgoty+X0I+WXecJC5KXNSlSFKQJKfV8SCyT65 /3uBEDRNZUVJeVaO2v7vcijemF2ud/Giu64+MNqG3eAtupSdAXLj1lKlzkqXPlnnA/R3 1lhF86cZLROvYz+rXy5Myr6igY5E9nWzrrgV93ZE+PCZ0etPHjjZL5JLA3ucZndLbglt vyKg== 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=ka61wmIogbeS4FZRJa7FPEYoz1c9JdTmedELNF//a8M=; b=POd7qdUboVUY6STs/Yug9YKS3opAxQMhlvCHS/xtb+BuQQpNN0dbh2rsRK1EnW0ye/ v7phBLTXKiT8G0MIb3mbsBF1ocLT4yUJBLtIOJJN8/iJUDfXVLOBfM3j4PPcxQzlCU2j 5G+LFObUrcKfs+Wbp3EGtHbGx7et7zNTMQthdgPv0tpVDB7WlQvH4zEmVB1jYL2ZBeoj YQd1zc+1EDdLjxtRVxo3doLc/sYW3+vAy1v3XGulWPb5Hr4Ogfena/54Gy0uFWJ8pUWl ABHmQK6JX4aT6Pb4MchLUBL0m8J5dh3hqt5DvUEnzukBkWqdnQwm8tYFTIPrDKt8Cbwj h3tA== X-Gm-Message-State: AOAM533Cp3gGrUBEgy92uGVZdE0qV7b3083sOPqo6YcE0pg5k5ktZovX PsI+OLs2vMSwUcNaVNkgWIfBLRsi6Wqo/g== X-Google-Smtp-Source: ABdhPJza8TWz2i9slPelU5OQYXwHCIXdLqxFY4ptTkygfdoSuXRzd08K35NASqUBOo1tAc5oWE3vhw== X-Received: by 2002:a1c:494:: with SMTP id 142mr5400663wme.60.1627057313236; Fri, 23 Jul 2021 09:21:53 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-6.1 6/6] hw/intc/armv7m_nvic: for v8.1M VECTPENDING hides S exceptions from NS Date: Fri, 23 Jul 2021 17:21:46 +0100 Message-Id: <20210723162146.5167-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210723162146.5167-1-peter.maydell@linaro.org> References: <20210723162146.5167-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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: pass (identity @linaro.org) X-ZM-MESSAGEID: 1627057475923100003 Content-Type: text/plain; charset="utf-8" In Arm v8.1M the VECTPENDING field in the ICSR has new behaviour: if the register is accessed NonSecure and the highest priority pending enabled exception (that would be returned in the VECTPENDING field) targets Secure, then the VECTPENDING field must read 1 rather than the exception number of the pending exception. Implement this. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/armv7m_nvic.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index c9149a3b221..1e7ddcb94cb 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -804,6 +804,16 @@ void armv7m_nvic_acknowledge_irq(void *opaque) nvic_irq_update(s); } =20 +static bool vectpending_targets_secure(NVICState *s) +{ + /* Return true if s->vectpending targets Secure state */ + if (s->vectpending_is_s_banked) { + return true; + } + return !exc_is_banked(s->vectpending) && + exc_targets_secure(s, s->vectpending); +} + void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq, bool *ptargets_secure) { @@ -813,12 +823,7 @@ void armv7m_nvic_get_pending_irq_info(void *opaque, =20 assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); =20 - if (s->vectpending_is_s_banked) { - targets_secure =3D true; - } else { - targets_secure =3D !exc_is_banked(pending) && - exc_targets_secure(s, pending); - } + targets_secure =3D vectpending_targets_secure(s); =20 trace_nvic_get_pending_irq_info(pending, targets_secure); =20 @@ -1039,7 +1044,19 @@ static uint32_t nvic_readl(NVICState *s, uint32_t of= fset, MemTxAttrs attrs) /* VECTACTIVE */ val =3D cpu->env.v7m.exception; /* VECTPENDING */ - val |=3D (s->vectpending & 0x1ff) << 12; + if (s->vectpending) { + /* + * From v8.1M VECTPENDING must read as 1 if accessed as + * NonSecure and the highest priority pending and enabled + * exception targets Secure. + */ + int vp =3D s->vectpending; + if (!attrs.secure && arm_feature(&cpu->env, ARM_FEATURE_V8_1M)= && + vectpending_targets_secure(s)) { + vp =3D 1; + } + val |=3D (vp & 0x1ff) << 12; + } /* ISRPENDING - set if any external IRQ is pending */ if (nvic_isrpending(s)) { val |=3D (1 << 22); --=20 2.20.1