From nobody Sat Sep 26 20:52:10 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1788445393; cv=none; d=zohomail.com; s=zohoarc; b=SF2K4jpLDPQSk7jt9hYbvKdlU71c0bIctERLCb2V1ipcI8iZV7CZbRCIFOwmaSTOxob0X5YafLEhay5Pe4q7lg/vOY6Hbx8w5s1Qz4fFTWem92LZq25gm7C07qmwLmzlLYiHfx7KyMQMNNMUTlEBtaes4/jAUnfaMEa150lVm1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788445393; h=Content-Type: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=SofEA0kMSl55YTMq/QL7igbuZI2km1bjwW02TPvg6d0=; b=ieK/H9beMa4w+EODpUwJCiYTojpMiHkzEPViwNPBpKZmr0u9iNGNZHEeeq7pnKBGWhEykT673JlFXFZZwbAxXcDHfver2xEowqO5cr227SOjz4aoM0mjeP17NJ9uSFyVzqpgaeysTH/44P8V+oerUS1TO7zRObfO/Te1iWx3ZJw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788445393871470.34167739956945; Thu, 3 Sep 2026 07:23:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x28Kf-0003qC-H5; Thu, 03 Sep 2026 10:22:27 -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 1x28KZ-0003pZ-Ut for qemu-devel@nongnu.org; Thu, 03 Sep 2026 10:22:21 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x28KW-0006LS-Vt for qemu-devel@nongnu.org; Thu, 03 Sep 2026 10:22:19 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-49cd9add88aso15686495e9.3 for ; Thu, 03 Sep 2026 07:22:16 -0700 (PDT) Received: from draig.lan ([185.124.0.156]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5d1fa6sm82031215e9.1.2026.09.03.07.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 07:22:13 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8149B5F9CC; Thu, 03 Sep 2026 15:22:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788445335; x=1789050135; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=SofEA0kMSl55YTMq/QL7igbuZI2km1bjwW02TPvg6d0=; b=gBj+0O+7MWWhO9RgVpzmtJGd4j3PIRikC14BQdMDnV4m2/zmqJXmkaGXCyqBSBuiTF PBNLlJg0bai8N3Bbs+JqKAaMo8RZwri7GzqJ3P+Vz8IiKrcbxm9JBQFp6LsrX0tlwxvY G3AveO5QmQHkZQNqR57TpQCjuPjpZpOJ2O+YyYu5rHszGiJhb0pKEm9UBSNTlqOtyzNZ uh1X1yHdxwagEbj/UnvjzB88via6Cq/do1dRzbffa0n/8csJtJBhXS1Z6q5GDMY9ERtt thu0sqSOeyBwd6a/TTf3JRlxXZgfF7k0hwnBMtsJzR2622pQY3bUTP9Y2Rvi7dhF3FQV vbBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788445335; x=1789050135; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SofEA0kMSl55YTMq/QL7igbuZI2km1bjwW02TPvg6d0=; b=qPdMo+M4ghv8teS2qcKsuce3yRz7t3NsQ8pDq6MCyh0n1npApFCXtkam4RQyD/3JcE pQ9xSBRAnPHcurgvzJbNbm3hknvf13kkZZrYmAYc8TztGqiaoknts0e/aG4b6AHaeoKJ svVjEAJ+fY0LhXrqs/qFw+RkkBOBQyEwFha8YB6xrttDcloptZrVjzkeNROpHPHQW9QF PMrVBH3MFhlvljJ/ZGQ4cvI5xnJ+WDy3QvSNCu7ljF27SAI4IVK/TOvgnThMJOBz7v2j rKaP1cyIncvPeHW56rVlMqSpucCLxXdI7t66v6BoyYIHUpH7EjJszwJ1RtFfEPqogjre tfuA== X-Gm-Message-State: AFuF++k75N9vJqjjjHMQqK+8ZzfWGatC5Gx883qj1hY6Mh7gQd15Cuvs CF5nwt2rsoo3QI40FrpZ2YJv95i7r2mFZJwZ9s3oxRbnetA3Kyrm2HWG30EvJSfxh8o= X-Gm-Gg: AYBFou20pfJUtU5/wayVj3oejv/JjmDu5aQNq4KfTKPWG7RDyRhMZViWohHRL/pZfF1 H+PsuZdKbYJkxlI8wX3X6OjJkrPZaskLg9E8UinRzRLFqbpmYF4OeBg6zrBoYZiqaclMoKvViIV YWA9jNu5J9OhIcf9ZwZD0kKepb54lsPnuBGa5KyzmauE9pbjwa3B/57wlJXgB9/mXlU7cS9vWOA yPiAeakWYmWNbnGE4h2UDbSVrHr+YjsvqPaeHtRgdx/Bj/K+faxCN94YItCkitsYrHjF4672hCd DhTlkVQmrsRdGB+5mh413kAilC+AO1IOGO8PltTXKs5frSFsi8ZBNX015b5HzO2EWofFEQqMfpg WxoAaySmp/5UOSkrdI26gM4TEcPE4Xp6DB7MwnfXMf0asCphJQm2d1TMnFQHzHXjZsTSE1q9vDV psDdrq4erxa0KKNXlNCSZYIyQLiQugjFiaZw3hWhk0uNyCYGXnEiav/WH5VS8y X-Received: by 2002:a05:600c:46d4:b0:49c:ee1c:d582 with SMTP id 5b1f17b1804b1-49cf5baa0demr6027175e9.14.1788445335348; Thu, 03 Sep 2026 07:22:15 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Fabiano Rosas , Peter Maydell , Laurent Vivier , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 1/2] hw/intc: include CPUID for SGIs on GIC HPPIR reads Date: Thu, 3 Sep 2026 15:22:11 +0100 Message-ID: <20260903142212.1451770-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903142212.1451770-1-alex.bennee@linaro.org> References: <20260903142212.1451770-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.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.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 @linaro.org) X-ZM-MESSAGEID: 1788445396725158500 In ARM GICv2 (and GICv1), reads of the Highest Priority Pending Interrupt Register (GICC_HPPIR and GICV_HPPIR) must include the requesting CPU ID in bits [12:10] when the highest priority pending interrupt is an SGI (interrupt IDs 0-15). Introduce gic_get_sgi_source() to look up the source CPU ID for both physical and virtual interfaces, and include it in bits [12:10] of the HPPIR read value for SGIs. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4402 AI-used-for: initial prototype changes Signed-off-by: Alex Benn=C3=A9e --- NOTE: - the initial patch was more expansive and included re-factoring gic_clear_pending_sgi to use the new helper. I dumped that change so I could reason through the fix on its own. --- hw/intc/arm_gic.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c index 4d4b79e6f34..181d17ead7c 100644 --- a/hw/intc/arm_gic.c +++ b/hw/intc/arm_gic.c @@ -568,6 +568,17 @@ static void gic_drop_prio(GICState *s, int cpu, int gr= oup) s->running_priority[cpu] =3D gic_get_prio_from_apr_bits(s, cpu); } =20 +static inline int gic_get_sgi_source(GICState *s, int irq, int cpu) +{ + if (gic_is_vcpu(cpu)) { + uint32_t *lr_entry =3D gic_get_lr_entry(s, irq, cpu); + return GICH_LR_HW(*lr_entry) ? 0 : GICH_LR_CPUID(*lr_entry); + } else { + assert(s->sgi_pending[irq][cpu] !=3D 0); + return ctz32(s->sgi_pending[irq][cpu]) & 0x7; + } +} + static inline uint32_t gic_clear_pending_sgi(GICState *s, int irq, int cpu) { int src; @@ -1648,8 +1659,16 @@ static MemTxResult gic_cpu_read(GICState *s, int cpu= , int offset, *data =3D gic_get_running_priority(s, cpu, attrs); break; case 0x18: /* Highest Pending Interrupt */ - *data =3D gic_get_current_pending_irq(s, cpu, attrs); + { + uint16_t p =3D gic_get_current_pending_irq(s, cpu, attrs); + + if (p < GIC_NR_SGIS && s->revision !=3D REV_11MPCORE) { + *data =3D p | (gic_get_sgi_source(s, p, cpu) << 10); + } else { + *data =3D p; + } break; + } case 0x1c: /* Aliased Binary Point */ /* GIC v2, no security: ABPR * GIC v1, no security: not implemented (RAZ/WI) --=20 2.47.3 From nobody Sat Sep 26 20:52:10 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1788445394; cv=none; d=zohomail.com; s=zohoarc; b=n8ONpfdPX+uU2nNR/38RULZBAPLnE1LhFk5p/+sf4iQphVyBRB7CvlgKCyPNoTGBk5cj31gCqv89bA1MO6or+joqSRC3GAYsduO/jxF8Ls7ezr/oi8Y61iCUH3tS/2zLGqnh1kI9SAMvtHePm++16x8tWujtQC8WGqD5J59XfbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788445394; h=Content-Type: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=NwDxLC/oWMRhdUIEhVG9Gi2RPoeDyYc/cxpG7J021lY=; b=M7Ql6QGXk+xGXNGfWAIBRrF4ik3AZrTLcWQb56lsOuNNZqxjnlQgg4DCdJAwf2p1mkBi22Pd15CdWOoOIDkNFdVQYlbpbmnVUTp9UgWA6SA3QyGRESnjPzPlZfX7UF4uJCPXI7kl6JvENrHPDS7V6Kbw/8LdSu5WNB0I1MPjmEE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788445394183925.2768328001981; Thu, 3 Sep 2026 07:23:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x28Kh-0003r3-Sj; Thu, 03 Sep 2026 10:22:27 -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 1x28Kb-0003pu-Q3 for qemu-devel@nongnu.org; Thu, 03 Sep 2026 10:22:21 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x28KY-0006MB-3K for qemu-devel@nongnu.org; Thu, 03 Sep 2026 10:22:19 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4995b0343c1so27301825e9.3 for ; Thu, 03 Sep 2026 07:22:17 -0700 (PDT) Received: from draig.lan ([185.124.0.156]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48448ed3716sm15312142f8f.22.2026.09.03.07.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 07:22:13 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 982675F9CF; Thu, 03 Sep 2026 15:22:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788445336; x=1789050136; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=NwDxLC/oWMRhdUIEhVG9Gi2RPoeDyYc/cxpG7J021lY=; b=ZgfWbj7ddC+zLKSlam88r1WYX27jgaodqd1cdDR1tjG3Nu9NWRrR4/r9L/ExZ4P9ui N3JH9xywkG6HOuoyIRodY/q85Siy3cenvb38hQ32PPNZkANSyTz7fMNO/X2jmJhalGXT NA0ZKXP8Xbr389wuu3EHPqW8mu7WiJHHy8rN62Z1TAULE2ocIB9UzDV1eZyg3qPdEGjD L7NENXMIB8b05yC+xuE2honQfsXpX0p0FxR9l8vI0KBup1bcKAjYRURwTmGSIYtu1tkZ 0bSSXPuXefI88vqqJKC9k6HscqGm0KtRhriEmu4V8aeI3Dgl++W/pmUxWe3HRXL02Kk3 HGjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788445336; x=1789050136; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NwDxLC/oWMRhdUIEhVG9Gi2RPoeDyYc/cxpG7J021lY=; b=pM5IExt7hejwe9UFAWe38uW9T+n9d/uf3Mg0EmoX877apNQr/ynrxGcvcivkupFMJk EwZiJufJTm/MpEt3i4/OoK0PQuUlhio59oVKMdXTmVcVDefFuWrPcZUARwIzZ0qQctvc AmQ6crvLwECIC5DPV4r6IABTE1TXQgASvxBSjPPBK1GQvOL389Rfxt44Rzn3MYTeQzUV vj8+CLxJ7XXiwAxSmLhKPJHLTHtXPnELNDThXopCxPEbKPnIiY4cAz2gJUTtPkHNJ8WP dx9TarZuwY2k5L7y/0TAGVU1V5y8jVVXJoWtKhXULmGmKJj0HzCwBELr2wHmM2uNJvI/ bhsg== X-Gm-Message-State: AFuF++kGb3fWOeB/dHBipChyrg9w7wti0f04ZJhV7E+fAB56V0ZCwZbt jSaaz6+I66fLU9N2n3xhCb2Co9ZOAaSO/F+VD/AUjmUY4X8P9+hL68s10ec1gyzmXA4= X-Gm-Gg: AYBFou2vm24eNQufGlhrox7nFRcJXtbSDmQRTUX7AmcJwMtB+B4yiBaCGrLnzOvzi1e qqqESDtyPyaukz2HwVUHp6oLX1E5WwRzK6ahQaQCU7/jBSAgALNg8dA5kTdZp5xVFq4TIGhkwD0 iqX/jbllOhiSv9Gmb8eHiW2URS13u8BRHUBkWb28JsIGIlKwFRmOH2S1BxSClJABQWElyrqTpgE 4o1erDQFLhOM9f6eWWTKIMftUKd5XKD+mx8Im1W0engrXioJhiL8YdwdJgZdWN+JbFJcwT9IEET 1AbUnaf3860JvjNAvsPDcSwIX1EmmjVJEOcQnrBGOa2rUinV7b0664fRl5RylHETUbrxD3fFDW/ edAav9PdybRxTIhOA5s71SBgRdseCgOAtIyweT7IMX/iI3nHnnZHwf/nGKnFWOfRoHV53ON9XdP UGigNTkuNzhtYMKLxC8Xl9xOfW71IgpT0FJkBtVI+zuH6nmY8uJRM2H9j8nCy8 X-Received: by 2002:a05:600c:8b88:b0:49c:e1cd:536 with SMTP id 5b1f17b1804b1-49ce584b899mr224444315e9.12.1788445336451; Thu, 03 Sep 2026 07:22:16 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Fabiano Rosas , Peter Maydell , Laurent Vivier , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 2/2] tests/qtest: add gicv2 qtest test case Date: Thu, 3 Sep 2026 15:22:12 +0100 Message-ID: <20260903142212.1451770-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903142212.1451770-1-alex.bennee@linaro.org> References: <20260903142212.1451770-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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.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 @linaro.org) X-ZM-MESSAGEID: 1788445396748158500 We have a bunch of bugs which provide qtest sequences to show faults in the GIC. Create a qtest to hold these and populate with the first test case. Link: https://gitlab.com/qemu-project/qemu/-/work_items/4402 AI-used-for: created qtest boilerplate based on bug report Signed-off-by: Alex Benn=C3=A9e --- tests/qtest/arm-gicv2-test.c | 84 ++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 2 files changed, 86 insertions(+) create mode 100644 tests/qtest/arm-gicv2-test.c diff --git a/tests/qtest/arm-gicv2-test.c b/tests/qtest/arm-gicv2-test.c new file mode 100644 index 00000000000..dbfb2cd801d --- /dev/null +++ b/tests/qtest/arm-gicv2-test.c @@ -0,0 +1,84 @@ +/* + * ARM GICv2 Virtual Interface Control and Virtual CPU Interface Tests + * + * Copyright (c) 2026 Linaro Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest.h" + +/* Addresses in the virt machine when virtualization=3Don */ +#define GICH_BASE 0x08030000 +#define GICV_BASE 0x08040000 + +/* Hypervisor Control Registers */ +#define GICH_HCR 0x0000 +#define GICH_LR0 0x0100 + +/* Virtual CPU Interface Registers */ +#define GICV_CTLR 0x0000 +#define GICV_PMR 0x0004 +#define GICV_IAR 0x000c +#define GICV_EOIR 0x0010 +#define GICV_HPPIR 0x0018 + +/* + * Test Highest Priority Pending Interrupt Register (GICV_HPPIR) + * and Interrupt Acknowledge Register (GICV_IAR) for a virtual SGI. + * + * In GICv2, for an SGI, both HPPIR and IAR report: + * Bits [9:0]: INTID + * Bits [12:10]: CPUID of the requesting processor + * (See Issue 4402: GICV_HPPIR dropped the CPUID field and returned only I= NTID). + */ +static void test_virtual_interface_sgi(void) +{ + QTestState *qts =3D qtest_init("-machine virt,virtualization=3Don,gic-= version=3D2"); + + /* Enable virtual CPU interface and allow all interrupt priorities */ + qtest_writel(qts, GICV_BASE + GICV_CTLR, 0x1); + qtest_writel(qts, GICV_BASE + GICV_PMR, 0xff); + + /* Enable virtual interface in hypervisor control */ + qtest_writel(qts, GICH_BASE + GICH_HCR, 0x1); + + /* + * Configure GICH_LR0 with a pending SGI: + * VirtualID =3D 5 (bits [9:0]) + * CPUID =3D 1 (bits [12:10]) -> 1 << 10 =3D 0x400 + * Priority =3D 4 (bits [27:23]) -> 4 << 23 =3D 0x02000000 + * State =3D 1 (bits [29:28]) -> PENDING =3D 0x10000000 + * Value: 0x12000405 + */ + qtest_writel(qts, GICH_BASE + GICH_LR0, 0x12000405); + + /* Read highest pending interrupt and acknowledge register */ + uint32_t hppir =3D qtest_readl(qts, GICV_BASE + GICV_HPPIR); + uint32_t iar =3D qtest_readl(qts, GICV_BASE + GICV_IAR); + + g_test_message("GICV_HPPIR =3D 0x%08x, GICV_IAR =3D 0x%08x", hppir, ia= r); + + /* GICV_IAR must report CPUID 1 and INTID 5 (0x405) */ + g_assert_cmphex(iar, =3D=3D, 0x405); + + /* + * GICV_HPPIR must also report CPUID 1 and INTID 5 (0x405). + * In buggy QEMU, GICV_HPPIR erroneously returns 0x5. + */ + g_assert_cmphex(hppir, =3D=3D, 0x405); + + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (qtest_has_machine("virt")) { + qtest_add_func("/arm/gicv2/virtual_interface_sgi", test_virtual_in= terface_sgi); + } + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 50a1a5272fa..37c21b8f9fb 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -265,6 +265,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ ['arm-cpu-features', + 'arm-gicv2-test', 'boot-serial-test'] =20 # TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-tes= t unconditional @@ -284,6 +285,7 @@ qtests_aarch64 =3D \ ['iommu-smmuv3-test'] : []) + \ qtests_cxl + = \ ['arm-cpu-features', + 'arm-gicv2-test', 'numa-test', 'boot-serial-test', 'migration-test'] --=20 2.47.3