From nobody Mon Nov 23 04:34:00 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=1792700609; cv=none; d=zohomail.com; s=zohoarc; b=WvOuemT/q5ySDOah0PgKWtRIkqV0edmHdzLjDE3u3a9IV1g1CSRaShVGKf6bLpLPfL07/rpfOQGIJEcqeb6CADyBVUpjh6DDmxiDNp7i4aXlcRQcXci2WiYcIKj3Mk/1sFB4UBeCFA8ugyHHVihf/Q3mxPoeX/elbIaEb6fGm8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792700609; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r+mpMDVCNtI0vFaDlSQA7QXB7K/EOFIthhvvATom6gs=; b=Rhfe9MWxA3+gl0DeZ9ZqaVdrXfQu3ztO9e+We6ASi0+onl88wp/J+1Qa8Y15pBpvoGd3gXQP/c0W5bMFM9FyjzHZFCFJGLCfyT41ewTMYgdb7MiMJ2Lwr1DZsRpDrkQ+GePTCTpNm4u61jpHj0doKbThEbs1OBG3iLxbMajDMDU= 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 1792700609912996.7267835938409; Thu, 22 Oct 2026 13:23:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJzJ2-0006xt-Qn; Thu, 22 Oct 2026 16:22:34 -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 1xJzIx-0006vl-Dw; Thu, 22 Oct 2026 16:22:27 -0400 Received: from vmexit.de ([159.195.53.62] 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 1xJzIv-0006zO-AG; Thu, 22 Oct 2026 16:22:26 -0400 From: Ralf Ramsauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmexit.de; s=mail; t=1792700542; 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: in-reply-to:in-reply-to:references:references; bh=r+mpMDVCNtI0vFaDlSQA7QXB7K/EOFIthhvvATom6gs=; b=ikABUuVD2U331c+Uj1JYmZgO2jXFke0A0pK4oMI8njr0QDKi0i1+rxv+A1lGpUn9lOC/kr l1CdBVqkuO8Yh3liIIowB+m7kBO6iZyDAtsewULam7U8lN0bTPrLwGYIkDZtD+K9P9/kW6 M2FurjJ198nIgOdYWz3dzcuhgHW8L5s= To: qemu-devel@nongnu.org, Daniel Henrique Barboza Cc: Ralf Ramsauer , Ralf Ramsauer , qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu , Bin Meng , Lukas Landgraf Subject: [PATCH v3 1/4] target/riscv: add riscv_cpu_has_supervisor_mode() Date: Thu, 22 Oct 2026 22:22:15 +0200 Message-ID: <7ce612fe810e410dcac32b9da863182b1f6d2c5e.1792700406.git.ralf@vmexit.de> 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=159.195.53.62; 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-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: 1792700612326158500 Content-Type: text/plain; charset="utf-8" From: Ralf Ramsauer Whether a hart has supervisor mode is decided in two places: KVM harts always have it, and for TCG it follows from RVS in the ISA string. riscv_plic_hart_config_string() already spells out both cases. Board code needs the same answer to describe the interrupt controller, but it should not have to reach into CPURISCVState for it. Add a helper next to riscv_cpu_is_vendor() so the next patches can ask the CPU instead of inspecting its internals. Suggested-by: Daniel Henrique Barboza Signed-off-by: Ralf Ramsauer Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Chao Liu --- target/riscv/cpu.c | 14 ++++++++++++++ target/riscv/cpu.h | 1 + 2 files changed, 15 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 08a4d14ea1..7be1c65902 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -338,6 +338,20 @@ bool riscv_cpu_is_vendor(Object *cpu_obj) return object_dynamic_cast(cpu_obj, TYPE_RISCV_VENDOR_CPU) !=3D NULL; } =20 +bool riscv_cpu_has_supervisor_mode(RISCVCPU *cpu) +{ +#ifndef CONFIG_USER_ONLY + /* KVM always provides supervisor mode, regardless of the ISA string */ + if (kvm_enabled()) { + return true; + } + + return riscv_has_ext(&cpu->env, RVS); +#else + return false; +#endif +} + const char * const riscv_int_regnames[] =3D { "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b65d631994..a7509b0114 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -995,6 +995,7 @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext= _offset, bool en); bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); void riscv_cpu_set_misa_ext(CPURISCVState *env, uint32_t ext); bool riscv_cpu_is_vendor(Object *cpu_obj); +bool riscv_cpu_has_supervisor_mode(RISCVCPU *cpu); =20 typedef struct isa_ext_data { const char *name; --=20 2.54.0 From nobody Mon Nov 23 04:34:00 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=1792700594; cv=none; d=zohomail.com; s=zohoarc; b=XgPZcLesAajImq4wMUtPVqoZHS7g7HgTi6wuoBRfEn9F/+Pl/hCjjBDAhfD4v5HG3K/vT5C4szL5Hu3y1wwjjzm4IL1PwOh8dhKJ/FOh9FK81EGpL8MzZO3MQ3gxPHNWESUBdKq23Oaw/e6z1tjrciMVZqWVihRQu8oSC9aQ0a4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792700594; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ug9UjX0alH6Om50mqWAG19WZ6XZ6IwsEJDb1FlECrZs=; b=UNRevZmPNSD9/AdqJCvOvwH/qmKldJqL7PDLaJ/+tmnFAF6+uDlGVXRNl6CoJ+95/m0tPjk1YPW+fVfUSWLbjL9gYzNVuW90aJExHNeiMEGNlWOi9gCSSolTawaqPn28GBQMkdJFYM5LcefE503sj6HSzkg7ctMpBqLC1paFAr0= 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 1792700593751538.2844485601753; Thu, 22 Oct 2026 13: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 1xJzJ9-0006z1-0T; Thu, 22 Oct 2026 16:22: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 1xJzIy-0006wI-KN; Thu, 22 Oct 2026 16:22:28 -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 1xJzIw-0006zS-Hh; Thu, 22 Oct 2026 16:22:28 -0400 From: Ralf Ramsauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmexit.de; s=mail; t=1792700543; 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: in-reply-to:in-reply-to:references:references; bh=Ug9UjX0alH6Om50mqWAG19WZ6XZ6IwsEJDb1FlECrZs=; b=E2loLpQtLicnpxzDmWOyo5yPuY/jqPRKO1A43GvEBsuPD6tHG8IfHzrgeNUFNW6CpcB8SB 4Yx7kocUcJRI7RYsAbDEbR+PXoqeXYG7sdMkRa4cuktjPEVnkI1zFS7gHhp5mWwwxLjCsb A0tarV21DVMZrrd6mBsUhIfIYHd8lMo= To: qemu-devel@nongnu.org, Daniel Henrique Barboza Cc: Ralf Ramsauer , Ralf Ramsauer , qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu , Bin Meng , Lukas Landgraf Subject: [PATCH v3 2/4] hw/riscv/virt: only describe PLIC contexts that exist Date: Thu, 22 Oct 2026 22:22:16 +0200 Message-ID: <299b4ab6843fb4655355b449359eb38f717af445.1792700406.git.ralf@vmexit.de> 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=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-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: 1792700597933158500 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. Emit the supervisor entry only for the harts that have supervisor mode. The KVM case then becomes the same rule, not a separate one: its harts have no M-mode and always have supervisor mode, so the common loop describes the single supervisor context per hart that it used to spell out on its own. Fixes: 7d10ff8a4de7 ("hw/riscv: virt: Use the PLIC config helper function") Signed-off-by: Ralf Ramsauer Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Chao Liu --- hw/riscv/virt.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d4b501802f..a2851b506d 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -156,23 +156,19 @@ static void create_fdt_socket_plic(RISCVVirtState *s, =20 plic_name =3D g_strdup_printf("/soc/interrupt-controller@%lx", plic_ad= dr); =20 - if (kvm_enabled()) { - cells_length =3D s->soc[socket].num_harts * 2; - plic_cells =3D g_new0(uint32_t, cells_length); - - for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { - plic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_S_EXT); + plic_cells =3D g_new0(uint32_t, + s->soc[socket].num_harts * (kvm_enabled() ? 2 : 4)= ); + cells_length =3D 0; + + for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { + if (!kvm_enabled()) { + plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); + plic_cells[cells_length++] =3D cpu_to_be32(IRQ_M_EXT); } - } else { - cells_length =3D s->soc[socket].num_harts * 4; - plic_cells =3D g_new0(uint32_t, cells_length); - - 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); + + if (riscv_cpu_has_supervisor_mode(&s->soc[socket].harts[cpu])) { + plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); + plic_cells[cells_length++] =3D cpu_to_be32(IRQ_S_EXT); } } =20 --=20 2.54.0 From nobody Mon Nov 23 04:34:00 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=1792700603; cv=none; d=zohomail.com; s=zohoarc; b=LxPkjy3xmYgb2n/NiE7LdKPbU0lbHHOVXDHmPWyufsmtkHtelKQN+9ngRLWdsFqoe9h9dQ4NPM8nEIF8JDJb2EQsl9x0SKl/5MqgPE0AKDtnzhdtd2vJMl2tmlN1o1qXuZZO93s1B7WQVklMMEHtQjE7mEsCTU7UwN8DkCc7gVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792700603; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Kqwsoktma7Bn9UEwhZdrSXc2/D8sx6TG4M9rY/eSXU4=; b=nb5SM02sJvfX2dCd49yxc9ZrxTzDsX9Fx7Gcj2e+dG7Fg11JOW8L3ijgYaFf7Fb4hHwJUh+5s4Ss7+pbmhIqaw6mytLmlNjzd7v/uXKTPj84mn1OVAE8fBX8ro/1b74+D8cygE+kuTbYtbSw/ltqQxq3r84mbyLz9z/7lcWlWmM= 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 1792700603979192.7336291858328; Thu, 22 Oct 2026 13:23:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJzJ2-0006xu-Ro; Thu, 22 Oct 2026 16:22:34 -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 1xJzIy-0006wH-Iy; Thu, 22 Oct 2026 16:22:28 -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 1xJzIw-0006zX-64; Thu, 22 Oct 2026 16:22:28 -0400 From: Ralf Ramsauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmexit.de; s=mail; t=1792700543; 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: in-reply-to:in-reply-to:references:references; bh=Kqwsoktma7Bn9UEwhZdrSXc2/D8sx6TG4M9rY/eSXU4=; b=WqdaRZ7V0YKdfyjA0IubOyAAdA2QGKgLsM95w+cB9u3WR2y6C6qM0gOFwxJIkRfHlepdas 4Po61LR4L08NIRe3LY00uPR7N0evORNtlwtDZbcxMxEUzRFfbh3cBkCEByXx4WfQDU/mgQ 4Wht4wrGoy/oTXuvvCuKiCIOceUXYyc= To: qemu-devel@nongnu.org, Daniel Henrique Barboza Cc: Ralf Ramsauer , Ralf Ramsauer , qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu , Bin Meng , Lukas Landgraf Subject: [PATCH v3 3/4] hw/riscv/sifive_u: derive PLIC contexts from the harts Date: Thu, 22 Oct 2026 22:22:17 +0200 Message-ID: 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=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-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: 1792700606175158500 Content-Type: text/plain; charset="utf-8" From: Ralf Ramsauer The PLIC device is created from riscv_plic_hart_config_string(), which gives a hart a supervisor context only if that hart has supervisor mode. The device tree instead hardcodes the fu540 topology: no supervisor context for the management hart, one for every other hart. Both agree as long as the application harts keep the default CPU type. The board sets no valid_cpu_types, though, and passes machine->cpu_type on to the U cluster, so -cpu rv64,s=3Dfalse,u=3Dfalse builds a PLIC without any supervisor context while the device tree still advertises one per application hart. Contexts are numbered by their position in 'interrupts-extended', so from the second hart on the numbering drifts apart, as it does on the virt machine. Ask the harts instead of assuming, like create_fdt_socket_plic() does. No change for the default CPU type: the E51 management hart has no RVS, the U54 application harts have. Signed-off-by: Ralf Ramsauer Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Chao Liu --- hw/riscv/sifive_u.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index b7d5e7b4da..8f50c67a14 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -99,6 +99,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry= *memmap, MachineState *ms =3D MACHINE(s); void *fdt; int cpu; + RISCVCPU *hart; uint32_t *cells, cells_length; char *nodename; uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =3D 1; @@ -195,18 +196,18 @@ static void create_fdt(SiFiveUState *s, const MemMapE= ntry *memmap, g_free(nodename); =20 plic_phandle =3D phandle++; - cells_length =3D ms->smp.cpus * 4 - 2; - cells =3D g_new0(uint32_t, cells_length); + cells =3D g_new0(uint32_t, ms->smp.cpus * 4 - 2); + cells_length =3D 0; for (cpu =3D 0; cpu < ms->smp.cpus; cpu++) { /* cpu 0 is the management hart that does not have S-mode */ - if (cpu =3D=3D 0) { - cells[0] =3D cpu_to_be32(intc_phandles[cpu]); - cells[1] =3D cpu_to_be32(IRQ_M_EXT); - } else { - cells[cpu * 4 - 2] =3D cpu_to_be32(intc_phandles[cpu]); - cells[cpu * 4 - 1] =3D cpu_to_be32(IRQ_M_EXT); - cells[cpu * 4 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - cells[cpu * 4 + 1] =3D cpu_to_be32(IRQ_S_EXT); + hart =3D cpu ? &s->soc.u_cpus.harts[cpu - 1] : &s->soc.e_cpus.hart= s[0]; + + cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); + cells[cells_length++] =3D cpu_to_be32(IRQ_M_EXT); + + if (riscv_cpu_has_supervisor_mode(hart)) { + cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); + cells[cells_length++] =3D cpu_to_be32(IRQ_S_EXT); } } =20 --=20 2.54.0 From nobody Mon Nov 23 04:34:00 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=1792700628; cv=none; d=zohomail.com; s=zohoarc; b=TKGwWBKlP0ycFuu7CI4ate1iK1l9IoLqxYjrPusufplE7oZifpJ8aFY4E+a8gOl6hIuI+eCo4sxkCCoCgtdIs0O26679ZDPJ3jzDQoz8O6wwT2+SqamSD+bqn/1pUUmvsptQEpFHI3gg+h2CZBzxPLCEML8idKJ8zQJlkPdMBs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792700628; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iAgL6eapHhzmzcJfZCBk1h2nisCKGjCen8/Y713LuLY=; b=lTw9uE7LLJ4BlzrGadb5wLUYAQNHRfnZs+VkiguAFIzcHBAWZ4I+f4LZwyYbXaMvoTT1HI5uFltK8gTiXQdnWgit522zZg/Gy7tV8lLGieb+n/wmNaK5GVCbKfLYc6twTfFX0PbOf3dtlnYItwJSYncwLpqMlSCmVC28xoEvImo= 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 1792700628467862.0787339758552; Thu, 22 Oct 2026 13:23:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJzJI-000727-DS; Thu, 22 Oct 2026 16:22:48 -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 1xJzIy-0006wJ-Kc; Thu, 22 Oct 2026 16:22:28 -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 1xJzIv-0006zb-Qe; Thu, 22 Oct 2026 16:22:28 -0400 From: Ralf Ramsauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmexit.de; s=mail; t=1792700544; 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: in-reply-to:in-reply-to:references:references; bh=iAgL6eapHhzmzcJfZCBk1h2nisCKGjCen8/Y713LuLY=; b=PM4ADEVzx1cfIHmQ3xyfhjZtcj18Z1Ikq+aBu9V5qetqNDDi4VvvxFLTIV9EFxk8pPNonn JJbTun8pLczrSLN0VL/aDSa2dn07/m1fNO+2nY/04E8PrFLcYKgU1vOW4HPHNE6kLs2CZp TBw517jKqq84XhetmaQYN6a52v2eGro= To: qemu-devel@nongnu.org, Daniel Henrique Barboza Cc: Ralf Ramsauer , Ralf Ramsauer , qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu , Bin Meng , Lukas Landgraf Subject: [PATCH v3 4/4] hw/riscv: share the PLIC interrupt cells between boards Date: Thu, 22 Oct 2026 22:22:18 +0200 Message-ID: <1fab0bc3d752c924f1c83f2a1f59cef0f520c62a.1792700406.git.ralf@vmexit.de> 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=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-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: 1792700630048158500 Content-Type: text/plain; charset="utf-8" From: Ralf Ramsauer virt and sifive_u now describe a hart's PLIC contexts with the same rule: a machine context unless the hart runs under KVM, where there is no M-mode, and a supervisor context if the hart has supervisor mode. Writing that rule down twice is what let the virt device tree drift away from riscv_plic_hart_config_string(). This makes the sifive_u device tree ask whether KVM is in use, which it did not do before. Its PLIC device already does, so the two now agree. Signed-off-by: Ralf Ramsauer Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- Cleanup, not a fix. Can be dropped, the rest does not depend on it. hw/riscv/fdt-common.c | 18 ++++++++++++++++++ hw/riscv/sifive_u.c | 12 ++++-------- hw/riscv/virt.c | 16 ++++++---------- include/hw/riscv/fdt-common.h | 3 +++ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index ce2dcb43b4..503d818dd0 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -212,6 +212,24 @@ riscv_create_fdt_socket_cpu_sifive(void *fdt, char *cl= ust_name, phandle, intc_phandles, false, false); } =20 +uint32_t riscv_plic_hart_fdt_cells(uint32_t *cells, RISCVCPU *hart, + uint32_t intc_phandle, bool has_m_mode) +{ + uint32_t len =3D 0; + + if (has_m_mode) { + cells[len++] =3D cpu_to_be32(intc_phandle); + cells[len++] =3D cpu_to_be32(IRQ_M_EXT); + } + + if (riscv_cpu_has_supervisor_mode(hart)) { + cells[len++] =3D cpu_to_be32(intc_phandle); + cells[len++] =3D cpu_to_be32(IRQ_S_EXT); + } + + return len; +} + void riscv_create_fdt_plic(void *fdt, hwaddr addr, uint64_t size, uint32_t plic_phandle, uint32_t int_cells, uint32_t addr_cells, uint32_t *plic_cells, diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 8f50c67a14..be194f8aec 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -58,6 +58,7 @@ #include "chardev/char.h" #include "net/eth.h" #include "system/device_tree.h" +#include "system/kvm.h" #include "system/runstate.h" #include "system/system.h" =20 @@ -201,14 +202,9 @@ static void create_fdt(SiFiveUState *s, const MemMapEn= try *memmap, for (cpu =3D 0; cpu < ms->smp.cpus; cpu++) { /* cpu 0 is the management hart that does not have S-mode */ hart =3D cpu ? &s->soc.u_cpus.harts[cpu - 1] : &s->soc.e_cpus.hart= s[0]; - - cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); - cells[cells_length++] =3D cpu_to_be32(IRQ_M_EXT); - - if (riscv_cpu_has_supervisor_mode(hart)) { - cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); - cells[cells_length++] =3D cpu_to_be32(IRQ_S_EXT); - } + cells_length +=3D riscv_plic_hart_fdt_cells(&cells[cells_length], = hart, + intc_phandles[cpu], + !kvm_enabled()); } =20 riscv_create_fdt_plic(fdt, memmap[SIFIVE_U_DEV_PLIC].base, diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index a2851b506d..ece8ef0070 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -152,24 +152,20 @@ static void create_fdt_socket_plic(RISCVVirtState *s, unsigned long plic_addr =3D s->memmap[VIRT_PLIC].base + (s->memmap[VIRT_PLIC].size * socket); bool numa_enabled =3D riscv_numa_enabled(MACHINE(s)); + bool has_m_mode =3D !kvm_enabled(); uint32_t cells_length; =20 plic_name =3D g_strdup_printf("/soc/interrupt-controller@%lx", plic_ad= dr); =20 plic_cells =3D g_new0(uint32_t, - s->soc[socket].num_harts * (kvm_enabled() ? 2 : 4)= ); + s->soc[socket].num_harts * (has_m_mode ? 4 : 2)); cells_length =3D 0; =20 for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { - if (!kvm_enabled()) { - plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cells_length++] =3D cpu_to_be32(IRQ_M_EXT); - } - - if (riscv_cpu_has_supervisor_mode(&s->soc[socket].harts[cpu])) { - plic_cells[cells_length++] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cells_length++] =3D cpu_to_be32(IRQ_S_EXT); - } + cells_length +=3D riscv_plic_hart_fdt_cells(&plic_cells[cells_leng= th], + &s->soc[socket].harts[cp= u], + intc_phandles[cpu], + has_m_mode); } =20 plic_phandles[socket] =3D (*phandle)++; diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index eb9db8278d..58e635e9ed 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -93,6 +93,9 @@ void riscv_create_fdt_socket_cpu_sifive(void *fdt, char *= clust_name, int socket_hartid_base, uint32_t *phandle, uint32_t *intc_phandles); +/* Describe one hart's PLIC contexts, returns the number of cells written = */ +uint32_t riscv_plic_hart_fdt_cells(uint32_t *cells, RISCVCPU *hart, + uint32_t intc_phandle, bool has_m_mode); void riscv_create_fdt_plic(void *fdt, hwaddr addr, uint64_t size, uint32_t plic_phandle, uint32_t int_cells, uint32_t addr_cells, uint32_t *plic_cells, --=20 2.54.0