From nobody Mon Aug 24 03:18:15 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1779486748; cv=none; d=zohomail.com; s=zohoarc; b=ULI7DgYqGOOXBaUzsCnH2qLz48ERn6sQ0U+ElBJrpn+N0LrbhLumFCz4KJ3uT0uABcAn1GFONrU9cTg7YD4iHZA3JfV+cEZVzJustch2e/iqz0ggRekq+Lf15T3G/ZwRRp8Wjxigt1Fph4d6ovviemiiP39WxmAUk20aq1MVCiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779486748; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v9D5mm0ApSLznQa5JGT+rtI69dxSWmqNk5TTzrRQHps=; b=iHDguCxdRWelvCHoI7MtirATM4t72l7uicyRpx1Y9F6SBk3WrN0usStXtOoMCXMyP4DfrQTbK3GtGrCj5t+YeEI5hphE2OpF/VGJkue1RTTFmM7jQdgvdFvkjE5NzWDVuX9c1KstCYHmvgmMDExu2x4veoqw+tfm8oTh4XMAlWY= 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 Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779486748279330.01083438525416; Fri, 22 May 2026 14:52:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQXlS-0008I5-5I; Fri, 22 May 2026 17:50:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQXkU-0006td-UO; Fri, 22 May 2026 17:49:44 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQXkT-0002ZD-1c; Fri, 22 May 2026 17:49:42 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 75CDF1AFB61; Sat, 23 May 2026 00:49:19 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id 9DC5F3B71B0; Sat, 23 May 2026 00:49:23 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tls.msk.ru; s=202602; t=1779486559; bh=wiIxSKLWjGp/hnmDgWgykvj99Y/kdybHqbX062AqeJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MFVinSxW2TlV98oUJppyPC8hjlmWtHc2oHfryRkgwx9f2niN9cuB4Ot2RlwrYWrm3 rapYshkqS4zYnBozpoUaCIKCZSSxkPZbA0XdAwlwvgUciEDID8K4bWLro86Co4gzTf ciKjbKONVBviZ67EBLkshvsIu7LCRywWnqm7CmszIlypr8XhoRQHubnRCxlsLBglDw rlnwnA9SHdgA170cGfRiQTx/VoTKMOH5/RmOmhGUH8R8pas49AUFiSpTjo5VrLInYn 6i47TcEJb41pRKOWf3+hdhWkz+0lX9yd/AhhcSl68yMIiMasDdliW7YV62TIgVzD2U qO2+3PodHENMA== From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, liugan1 , Peter Maydell , Michael Tokarev Subject: [Stable-10.2.3 107/149] hw/intc/arm_gicv3: Fix NS write to ICC_AP1Rn_EL1 when prebits < 7 Date: Sat, 23 May 2026 00:48:39 +0300 Message-ID: <20260522214923.807017-8-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: 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=lists1p.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tls.msk.ru) X-ZM-MESSAGEID: 1779486749808158500 Content-Type: text/plain; charset="utf-8" From: liugan1 The existing code uses a blanket `regno < 2` check to make ICC_AP1R0_EL1 and ICC_AP1R1_EL1 writes from Non-secure code WI (Write Ignore) when EL3 is present. This is intended to prevent NS code from claiming active interrupts in the Secure priority range, which could block Secure interrupt delivery. However, that check assumes prebits=3D7 (4 APR registers), where the NS priority range (128..255) maps entirely to AP1R2/AP1R3. Since commit 39f29e599355 ("hw/intc/arm_gicv3: Use correct number of priority bits for the CPU", first in 7.1), all QEMU AArch64 CPUs are initialised with gic_pribits=3D5 (one APR register), so NS priorities map to AP1R0 bits [16:31]. Blanket WI of the entire AP1R0 register prevents NS code from clearing its own NS active priority bits. Machines using hw_compat_7_0 (e.g. virt-7.0) still force pribits=3D8 via force-8-bit-prio and are therefore unaffected. A concrete consequence observed in virtualisation scenarios: when a guest VM acknowledges an SPI interrupt but does not perform EOI, is force-killed and restarted, the new guest's attempt to clear the residual active state by writing ICC_AP1R0_EL1=3D0 is silently ignored. The running priority (RPR) remains stuck at the old interrupt's priority, preventing all equal-or-lower priority interrupts (including timer interrupts) from being delivered, and hanging the guest. Fix this by computing the exact Secure/NS boundary within the APR bank based on prebits. For registers entirely in the Secure range, keep the WI behaviour. For the register that straddles the boundary, preserve only the Secure bits while allowing NS bits to be modified. For registers entirely in the NS range, allow full write access. The new logic produces identical behaviour to the old code when prebits=3D7, preserving existing behaviour for machines that use force-8-bit-prio. Fixes: 39f29e599355 ("hw/intc/arm_gicv3: Use correct number of priority bit= s for the CPU") Cc: qemu-stable@nongnu.org Signed-off-by: liugan1 Message-id: 20260428083119.1400110-1-gs_liugan@163.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell (cherry picked from commit f35f0f1ca121fb4931fe98570cda3aeb06b7a87f) Signed-off-by: Michael Tokarev diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c index 2e6c1f778a..5b15e4ff1e 100644 --- a/hw/intc/arm_gicv3_cpuif.c +++ b/hw/intc/arm_gicv3_cpuif.c @@ -1869,9 +1869,40 @@ static void icc_ap_write(CPUARMState *env, const ARM= CPRegInfo *ri, * at a priority outside the Non-secure range (128..255), since this * would otherwise allow malicious NS code to block delivery of S inte= rrupts * by writing a bad value to these registers. + * + * The NS priority range (128..255) maps to APR bits starting at + * aprbit =3D 0x80 >> (8 - prebits). Depending on prebits, this bounda= ry + * may fall within AP1R0 or AP1R1, so we cannot simply WI the entire + * register. Instead we calculate which bits within each register + * correspond to the Secure range and preserve those, while allowing + * NS code to modify only the NS range bits. + * + * prebits=3D4: num_aprs=3D1, NS starts at AP1R0[8] + * prebits=3D5: num_aprs=3D1, NS starts at AP1R0[16] + * prebits=3D6: num_aprs=3D2, NS starts at AP1R1[0] + * prebits=3D7: num_aprs=3D4, NS starts at AP1R2[0] */ - if (grp =3D=3D GICV3_G1NS && regno < 2 && arm_feature(env, ARM_FEATURE= _EL3)) { - return; + if (grp =3D=3D GICV3_G1NS && arm_feature(env, ARM_FEATURE_EL3)) { + int ns_start_bit =3D 0x80 >> (8 - cs->prebits); + int ns_start_regno =3D ns_start_bit / 32; + int ns_start_regbit =3D ns_start_bit % 32; + + if (regno < ns_start_regno) { + /* This entire register is in the Secure range: WI */ + return; + } else if (regno =3D=3D ns_start_regno && ns_start_regbit > 0) { + /* + * This register is split: low bits are Secure, high bits are = NS. + * Preserve the Secure bits (below ns_start_regbit) from the + * current value, and take the NS bits (at and above + * ns_start_regbit) from the written value. + */ + uint32_t secure_mask =3D MAKE_64BIT_MASK(0, ns_start_regbit); + + value =3D (cs->icc_apr[grp][regno] & secure_mask) | + (value & ~secure_mask); + } + /* else: regno > ns_start_regno, entire register is NS: allow writ= e */ } =20 if (cs->nmi_support) { --=20 2.47.3