From nobody Mon Nov 23 05:10:03 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=vmexit.de ARC-Seal: i=1; a=rsa-sha256; t=1790554275; cv=none; d=zohomail.com; s=zohoarc; b=AC/gIhG52bm/28Kpf93M3F0JFgn4rpi76K3nRM2xQfNy401KR6YlczCnedl/2886Ezc5QhTxl4BkmWg8Azq5W9shapFPwrxp38cMoGl8RTWAS+MNWOguppN2LPSI47yfwtDZQeKE2zh93iLIUBcmkl9VJYq08MgES8QC7Zs7rz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790554275; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LSVcCaB/lC+MLtJl6kRphvXsrliN21Zj5Sg5dUFUWHk=; b=erHX2ooBXzX662mjmiKu2BsfRLN1Hq/W8UCLPYEMlm9WKeLE7Kc0RkKWWsERti/uWsYTM8CHGKWMF9wDQjlHGuoh+dYe0UO+QVyEESvVKsviM5dh8LL4MuA1BNnreOKL2f3wVQ4SGEtaTJsBq99aAWyw3H/KlKIPhOoPt2Mix+U= 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 1790554275141653.9848622528305; Sun, 27 Sep 2026 17:11:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xAywu-0001Ko-I1; Sun, 27 Sep 2026 20:10:28 -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 1xAy93-00050W-Vk; Sun, 27 Sep 2026 19:18:57 -0400 Received: from vmexit.de ([2a0a:4cc0:c1:d4ba::2] helo=gizmo.vmexit.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xAy92-0001c8-0s; Sun, 27 Sep 2026 19:18:57 -0400 From: Ralf Ramsauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmexit.de; s=mail; t=1790551129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=LSVcCaB/lC+MLtJl6kRphvXsrliN21Zj5Sg5dUFUWHk=; b=kNyhf5jfvAC9Qel0jt8age10w9epG1s8XT44qKqS+ffSOUB59X+jlq7MKB5rwG5+XIlTCl e3VD4/4ohXDvWXtAnMQe/Q4yr/BtMLM/vO/R04CZw/7MVEEHlpGjWkOPTwVskjo/+1SMaf 2fql0WEV31uhOiCToBwnKk2ctkXxyMo= To: qemu-devel@nongnu.org Cc: Ralf Ramsauer , qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng Subject: [PATCH] hw/riscv/virt: only describe PLIC contexts that exist Date: Mon, 28 Sep 2026 01:18:37 +0200 Message-ID: <20260927231838.236616-1-ralf@vmexit.de> 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=2a0a:4cc0:c1:d4ba::2; envelope-from=ralf@vmexit.de; helo=gizmo.vmexit.de 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 27 Sep 2026 20:10:26 -0400 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 @vmexit.de) X-ZM-MESSAGEID: 1790554278721158500 Content-Type: text/plain; charset="utf-8" From: Ralf Ramsauer The PLIC device is created from the topology string built by riscv_plic_hart_config_string(), which gives a hart a supervisor context only if that hart actually has supervisor mode. The device tree, in contrast, lists a machine and a supervisor context for every hart, unconditionally. The two have disagreed since commit 7d10ff8a4d ("hw/riscv: virt: Use the PLIC config helper function") taught the device about harts without S-mode and left the device tree behind. Boot with -cpu rv64,s=3Dfalse,u=3Dfalse -smp 4 and the PLIC implements four contexts while the device tree advertises eight. Contexts are numbered by their position in 'interrupts-extended', so a guest that takes its context number from the property gets it wrong for every hart but the first: hart 1 drives the context of hart 2, and the upper harts address contexts the PLIC never created. This is what an M-mode kernel on the virt machine runs into; sifive_u already omits the supervisor entry for its management hart. Emit the supervisor entry only for the harts that have supervisor mode. Fixes: 7d10ff8a4d ("hw/riscv: virt: Use the PLIC config helper function") Signed-off-by: Ralf Ramsauer --- hw/riscv/virt.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d4b501802f..d0ce9dc862 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -165,14 +165,23 @@ static void create_fdt_socket_plic(RISCVVirtState *s, plic_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_S_EXT); } } else { - cells_length =3D s->soc[socket].num_harts * 4; - plic_cells =3D g_new0(uint32_t, cells_length); + plic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 4); + cells_length =3D 0; =20 for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { - plic_cells[cpu * 4 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cpu * 4 + 1] =3D cpu_to_be32(IRQ_M_EXT); - plic_cells[cpu * 4 + 2] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cpu * 4 + 3] =3D cpu_to_be32(IRQ_S_EXT); + CPURISCVState *env =3D &s->soc[socket].harts[cpu].env; + + plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); + plic_cells[cells_length++] =3D cpu_to_be32(IRQ_M_EXT); + + /* + * The PLIC implements a supervisor context only for harts that + * have supervisor mode, see riscv_plic_hart_config_string(). + */ + if (riscv_has_ext(env, RVS)) { + plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[c= pu]); + plic_cells[cells_length++] =3D cpu_to_be32(IRQ_S_EXT); + } } } =20 base-commit: 81ce3a87737aa50716c42db8886082d12783e0a1 --=20 2.54.0