From nobody Thu Nov 14 07:06:35 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704877233; cv=none; d=zohomail.com; s=zohoarc; b=AnJWfh8Fqxqvq9Wxb/KCA6yl2Tqmt8DbbJFrzu+hyU+1FPsgzjjXa9NEZhmzEiydyMlsuroTgG3hKSMQkxFO93KNNWzmD7D//ijgMGZxRNrezqFtAemj/bMh/rA9+R8dZjn/iYVNR+rWtNUr4AVHt/f8ph3sVaSI8kp8NUQx02Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704877233; 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=Nbco6y2Ui7OCD7BuZyHiT9zINXryXXOKQ/3cC8VY7N0=; b=Vukea2pAWWEGbE2IkAguQpUzhWzVxDPve2bA/REdEoaycNSx63eRPDJ+nEXqPAHj6FKQicGytITcU+ObUEfaGdfCPOlpsHA6gkMxIXrdOVXdgVWUr3G7p89QTeMEc+2YgxwnprrHe3pFjPgghoIkP+JAezki/tO1YI6axHjRN9Y= 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 170487723338935.95493328664111; Wed, 10 Jan 2024 01:00:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNURS-0005Xz-Kn; Wed, 10 Jan 2024 04:00:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNUQm-0004IF-IV for qemu-devel@nongnu.org; Wed, 10 Jan 2024 03:59:25 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNUQj-00043v-Tu for qemu-devel@nongnu.org; Wed, 10 Jan 2024 03:59:23 -0500 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3bbbf5a59b7so3534098b6e.3 for ; Wed, 10 Jan 2024 00:59:21 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id t65-20020a628144000000b006d9879ba6besm3223814pfd.170.2024.01.10.00.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 00:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704877160; x=1705481960; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Nbco6y2Ui7OCD7BuZyHiT9zINXryXXOKQ/3cC8VY7N0=; b=Bop916q+QVkFmrbbZBn3gwRY85tMJxvOw0x9BBGomefzh+DepdfVk71CXNr+54axkP ybcY66nSMk6foBq6x7Z1GWCeyonczhe2pcb01lk2xjTRh8AbEksFzxdhHKXFAo3C5hNO 3JSxaOzCvagXal8xrfVF3MAL+k7X9XMG8qdwiweE9WiEPMJfhBAeK1WfI8P7ytkIuQgx KJwLAKBY4IoERsuod0e5n+ISFVfcKnQ1YtUmxTCEEjDRi99xkArxeadm2t+JdUDJ3GIb RRcWrHbtg0ou8D0B05dbIp2sNpsLXZDI90WDvqBTM5GbngPom69IduPv4gfoYs3dI4Aj yj0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704877160; x=1705481960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nbco6y2Ui7OCD7BuZyHiT9zINXryXXOKQ/3cC8VY7N0=; b=BqfimF144ZXiNZSJXyBi21rcDqbPX/3V9HKryOqzQBi1z952iI3HsuVitzpAD+5QzJ vKpE7vWUxalTFpcbBwz91mkcU9/phnppOKCD9HaFX4AD0DdVafKCAnOlXL2nZrlVaG6/ KV6/Li1NisM3SN4Hflext2L4qirJwcImBeuVPcBkcFiSBrOjj4K14SXaXj3tUEIcJT2I H85AAwUUE52VS5Ex2Rhdgt3jAiGqeDlw+qFN8Bw4m2vyzGB9lxnaCRp1fRMh3DkXc0nI J+snMf3goZlZA9v/CAOsO/Tt0enWoQJlb7WD6m+TMmJKWlFZS7MqHyfWUqT1uE8ES8CZ e0rw== X-Gm-Message-State: AOJu0YwsY41Z6xaj2c+cLQ1J3ut8HgA0tO3s++SiOiyXSnj8A2hxQPsv DvADom+47c0uJ0isLX+KA0+yfcfYqk8MRq9G X-Google-Smtp-Source: AGHT+IHAimiSAAjovsGOQJ4qqUw27W2OgpGYumdOFZ2xt20HvmHKFnj0pwE/e60iaqJShYuG59nRvQ== X-Received: by 2002:a05:6808:14c8:b0:3bd:413a:e334 with SMTP id f8-20020a05680814c800b003bd413ae334mr847576oiw.58.1704877160449; Wed, 10 Jan 2024 00:59:20 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Yong-Xuan Wang , Jim Shu , Daniel Henrique Barboza , Alistair Francis Subject: [PULL 25/65] hw/riscv/virt.c: fix the interrupts-extended property format of PLIC Date: Wed, 10 Jan 2024 18:56:53 +1000 Message-ID: <20240110085733.1607526-26-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110085733.1607526-1-alistair.francis@wdc.com> References: <20240110085733.1607526-1-alistair.francis@wdc.com> 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=2607:f8b0:4864:20::235; envelope-from=alistair23@gmail.com; helo=mail-oi1-x235.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @gmail.com) X-ZM-MESSAGEID: 1704877234768100003 Content-Type: text/plain; charset="utf-8" From: Yong-Xuan Wang The interrupts-extended property of PLIC only has 2 * hart number fields when KVM enabled, copy 4 * hart number fields to fdt will expose some uninitialized value. In this patch, I also refactor the code about the setting of interrupts-extended property of PLIC for improved readability. Signed-off-by: Yong-Xuan Wang Reviewed-by: Jim Shu Reviewed-by: Daniel Henrique Barboza Message-ID: <20231218090543.22353-1-yongxuan.wang@sifive.com> Signed-off-by: Alistair Francis --- hw/riscv/virt.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index a7c4c3508e..4194ddcef1 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -437,24 +437,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, "sifive,plic-1.0.0", "riscv,plic0" }; =20 - if (kvm_enabled()) { - plic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); - } else { - plic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 4); - } - - for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { - if (kvm_enabled()) { - plic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - plic_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_S_EXT); - } else { - 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); - } - } - plic_phandles[socket] =3D (*phandle)++; plic_addr =3D memmap[VIRT_PLIC].base + (memmap[VIRT_PLIC].size * socke= t); plic_name =3D g_strdup_printf("/soc/plic@%lx", plic_addr); @@ -467,8 +449,33 @@ static void create_fdt_socket_plic(RISCVVirtState *s, (char **)&plic_compat, ARRAY_SIZE(plic_compat)); qemu_fdt_setprop(ms->fdt, plic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended", - plic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4); + + if (kvm_enabled()) { + plic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); + + 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); + } + + qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended", + plic_cells, + s->soc[socket].num_harts * sizeof(uint32_t) * 2); + } else { + plic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 4); + + 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); + } + + qemu_fdt_setprop(ms->fdt, plic_name, "interrupts-extended", + plic_cells, + s->soc[socket].num_harts * sizeof(uint32_t) * 4); + } + qemu_fdt_setprop_cells(ms->fdt, plic_name, "reg", 0x0, plic_addr, 0x0, memmap[VIRT_PLIC].size); qemu_fdt_setprop_cell(ms->fdt, plic_name, "riscv,ndev", --=20 2.43.0