From patchwork Tue Nov 19 19:16:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBF05D6C28B for ; Tue, 19 Nov 2024 19:20:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTj1-0002hS-73; Tue, 19 Nov 2024 14:17:23 -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 1tDTiy-0002gL-M8 for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:21 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTiu-0007b0-Ri for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:19 -0500 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-71e61b47c6cso1104062b3a.2 for ; Tue, 19 Nov 2024 11:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043834; x=1732648634; 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=MfqPL2ceZbuv9319yPCtViJk/QQq83eorbQLKJC/kgc=; b=GK+PEsK94nwXDf9SSEgkVm43iorMau4OdW/cV+13NLNVteFWzopi/AonQVengI4ORQ 7BJexfKcJiZDvOofBZqJ2mX/B4A4/eY4SMepp2fyfYPD6RDgXZfDcA3kpZ43DPsmT56D F9dZvn8PyXsiSWJ/1+gozHNyGSsLVQkkcYJyvtg6GVctCIJfLmA0YC/sp2oHYvxLFLLm VPJa9A9g21N+TQTBd4lCgE/dvb1MxtWE5DrCdX2Isdfrtx2AWHq1gFj+p8TQbNijK8xe VAZwppN7Vfmwx5M52XnByY7tK+zKAbJ4ySJ4nXcFDevTMxJjzLxi4J/BL6Ju3/0f6BC9 CBww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043834; x=1732648634; 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=MfqPL2ceZbuv9319yPCtViJk/QQq83eorbQLKJC/kgc=; b=YOMXjk0dj/R+GijoWb/TNJiwT/Qm+PUvCC7F+SPKBQOnO40xqg6ZAB2gs3l6HCAt/U fqXq8JW/NIujErohLVbxAL3OKR8+RGvHenVj4rM3Q5zSg97z3n9wSVPkFOlKGH1gGPXQ f4kP4cm2mc6LB1yGbXnOTSJ87nybaFEhVQ5xOyCZGkFYpMtD4l5jBIcXrek5Fceq5dmN uC8j8hzltFUlsPVh8kOiUT1Vkwe1/9tzWGy7u6R/femsVg1NGQF9PbvWvdGQDF+cl+w7 8WZ9SnIJU09929OA5dXS6dHY1VElmV5T5TIKth4Zc/PhmlPhCJxwFY4eYk6ez3lCnTTF 5mww== X-Gm-Message-State: AOJu0YzU5vFVsoxc1XDJUEwYsiyYZ1zN2vcQKlCqLcILyC4JnVj/ejjx h+7tg7oYIrU8jMbpAJwRmDVrPjNbqaCmYlicxvr8vVFM1QrTMmXU0AJicIZSHHzLvhqOuUkKA5o V X-Google-Smtp-Source: AGHT+IEOurxfnAW28OaXHwwOZ7jeUujAh8Ztn2FgTZzY5O8BY8LefV3tM19VwZBrbWgPIi/V7q770Q== X-Received: by 2002:a05:6a00:3a12:b0:71e:5d1d:1aa2 with SMTP id d2e1a72fcca58-724bec9ad56mr141015b3a.7.1732043834575; Tue, 19 Nov 2024 11:17:14 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:14 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 1/8] hw/intc/riscv_aplic: rename is_kvm_aia() Date: Tue, 19 Nov 2024 16:16:59 -0300 Message-ID: <20241119191706.718860-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x429.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The helper is_kvm_aia() is checking not only for AIA, but for aplic-imsic (i.e. "aia=aplic-imsic" in 'virt' RISC-V machine) with an in-kernel chip present. Rename it to be a bit clear what the helper is doing since we'll add more AIA helpers in the next patches. Make the helper public because the 'virt' machine will use it as well. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/intc/riscv_aplic.c | 8 ++++---- include/hw/intc/riscv_aplic.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 4a262c82f0..20de8c63a2 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -154,7 +154,7 @@ * KVM AIA only supports APLIC MSI, fallback to QEMU emulation if we want to use * APLIC Wired. */ -static bool is_kvm_aia(bool msimode) +bool riscv_is_kvm_aia_aplic_imsic(bool msimode) { return kvm_irqchip_in_kernel() && msimode; } @@ -853,7 +853,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) uint32_t i; RISCVAPLICState *aplic = RISCV_APLIC(dev); - if (!is_kvm_aia(aplic->msimode)) { + if (!riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); aplic->state = g_new0(uint32_t, aplic->num_irqs); @@ -877,7 +877,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) * have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { - if (kvm_enabled() && is_kvm_aia(aplic->msimode)) { + if (kvm_enabled() && riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); } else { qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); @@ -1021,7 +1021,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - if (!is_kvm_aia(msimode)) { + if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); } diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h index de8532fbc3..fd0e6427d9 100644 --- a/include/hw/intc/riscv_aplic.h +++ b/include/hw/intc/riscv_aplic.h @@ -71,6 +71,7 @@ struct RISCVAPLICState { }; void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); +bool riscv_is_kvm_aia_aplic_imsic(bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, From patchwork Tue Nov 19 19:17:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9584D6C28D for ; Tue, 19 Nov 2024 19:19:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTj2-0002i0-79; Tue, 19 Nov 2024 14:17:24 -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 1tDTj0-0002h6-JF for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:22 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTiy-0007bp-2s for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:21 -0500 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7ea8de14848so2885807a12.2 for ; Tue, 19 Nov 2024 11:17:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043837; x=1732648637; 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=aBuLzPP/B8/86QP5/ZU+SYT0fd/LUTlpVZf64COogLU=; b=BMivpZjUgHOBgfepECeN1+cDkjDgFFbso8SJPsrPrUPN7m/F+bWEj1j6aNqx7l/T0w FBpyLkdiF/xM7Lp1exwz3mhgCXsf/TRXyUJdCZNCahXKAg36zD9u9IRSAfqo5/obsuy9 xQqkdsfgsvPfeRGcJiDpFDOV1ASMHDpkO/rnK5hc/Nr0ALLHli/Q13v3Ml6YajFDQpQ+ hjFo8ClBckdcCSSCV+/WHAtQGQXid9kSOVRJMBNTt+IF7gRfu2SQRd4x/VN9AJrDHdD8 EM6LMHQFOcnYDh8mcbhl7mLR0eanWSQyqQWH6alJVil1NmjCjX3voCXHilZ4Yz6auzQo Zyig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043837; x=1732648637; 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=aBuLzPP/B8/86QP5/ZU+SYT0fd/LUTlpVZf64COogLU=; b=YwXxxNCFn6GWapjK8YNs9j8gZwdV29j2V5RGO33sb5n6W1W5hx5R/VyIv8aQCd/9K9 h/gUQ9eyF0TinGJClmUaMTX8P79CwL5kyiIWlb8waSi/SKWf78Df9OKBezVXEUBb7Rkr 3BDiiHGXdDaf/2602OIMANds/AwynfAYsDnKWuaDjUBt2yJKhpkIPUbxOWT1zy0AAbK/ ev9fx0lfDvnt4SWVMivpAZ87QfQc9vICWYvNelph8z21ofRrxr9XNQ/wI6WmpVdkRkQk lgSyLIIAzzAdTtLA/KhahSaGNh1+cTJ96MHOwvHdwM0VaF2S1byzJqMz0h9NF+FkIyQ5 Of2A== X-Gm-Message-State: AOJu0YwNFhGEecl/cY5ZbdqXETPLk8BnrfMrgPqeOxWyxVjEYxKDoRMC TKrfCgWRM/Ivt5k67iWlD8bNBV6QB8qJclm127PPt/hLaRcY2M/80Dqh7pvZbjmOtwu5InmlYXZ 0 X-Google-Smtp-Source: AGHT+IFcTmWIvLRb22P+yc9zcL2nj2CrEfBQa5Uze2xQ2dTUGxsQYyYFNxDX8nZjD2DS353Un2M6YQ== X-Received: by 2002:a05:6a20:918f:b0:1d9:11d0:1215 with SMTP id adf61e73a8af0-1ddaedcd994mr325067637.13.1732043837441; Tue, 19 Nov 2024 11:17:17 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:17 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 2/8] hw/riscv/virt.c: reduce virt_use_kvm_aia() usage Date: Tue, 19 Nov 2024 16:17:00 -0300 Message-ID: <20241119191706.718860-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=dbarboza@ventanamicro.com; helo=mail-pg1-x530.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In create_fdt_sockets() we have the following pattern: if (kvm_enabled() && virt_use_kvm_aia(s)) { (... do stuff ...) } else { (... do other stuff ...) } if (kvm_enabled() && virt_use_kvm_aia(s)) { (... do more stuff ...) } else { (... do more other stuff) } Do everything in a single if/else clause to reduce the usage of virt_use_kvm_aia() helper and to make the code a bit less repetitive. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 45a8c4f819..e200fc561a 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -781,6 +781,10 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, ms->smp.cpus); + + *irq_mmio_phandle = xplic_phandles[0]; + *irq_virtio_phandle = xplic_phandles[0]; + *irq_pcie_phandle = xplic_phandles[0]; } else { phandle_pos = ms->smp.cpus; for (socket = (socket_count - 1); socket >= 0; socket--) { @@ -798,13 +802,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, s->soc[socket].num_harts); } } - } - if (kvm_enabled() && virt_use_kvm_aia(s)) { - *irq_mmio_phandle = xplic_phandles[0]; - *irq_virtio_phandle = xplic_phandles[0]; - *irq_pcie_phandle = xplic_phandles[0]; - } else { for (socket = 0; socket < socket_count; socket++) { if (socket == 0) { *irq_mmio_phandle = xplic_phandles[socket]; From patchwork Tue Nov 19 19:17:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4675D6C28B for ; Tue, 19 Nov 2024 19:19:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTj5-0002jD-3r; Tue, 19 Nov 2024 14:17:27 -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 1tDTj3-0002iP-3z for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:25 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTj0-0007cy-Eu for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:24 -0500 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7245a9d0e92so4569714b3a.0 for ; Tue, 19 Nov 2024 11:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043841; x=1732648641; 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=PhW2FSBGXHAYwMA8dkq4vzQjZXR1p5LWWIboLCYp7gM=; b=kgXhaalxDbdN+2294Cpb68Lqq31/3YTRGZL0fHHqcf62HwgUfoFjVL+V+Q1MP2JNaZ v8PB0tjcTsT6Uch2OH2HPs1NDqOqAh+QGUZrOhuFP80o/jqHvktPFuBfA+SINWPQ8UPu tdSVznkKaBqTkjyFe5BkW63URcm2MOlezfhT3h7KFsp6AW8CJteT79EnEbNtCeK0RkSq 0agOAQZEoYeZp8zZNtRv5wggb0nB9lR81mGPMr+53GocZvfTE5oaD6ajBS9UVgX5wLQ+ vKB2NAFcCJL5plp0WsmRuYNuH0oLh6a4x0xcNwvhj02Kq/iT7IWtmLBdpkt41mm14TzG trDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043841; x=1732648641; 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=PhW2FSBGXHAYwMA8dkq4vzQjZXR1p5LWWIboLCYp7gM=; b=fXnOfzDguzmIhW/XjcpjcunjZpwkU1frn6eln97m0T9b6YY03xo4rYsQ6NXu5+IIGS kMxjMRBn/dJTCIrIsn8wJATWibRY58QUPVSXRxrWrDQxAPCXfq1vAHmM4n88D1mRJd0f psiTx42xjLZy5Oq0h+EqbybXlu42hXqcJkV27f9phRrDjpDHOuU6L8K3rVsHmSH/5XBR gGix+hNkO0daPEmWgUyYIWxEQq2Eze8FTY8PwySgWqiAwrEgg1GlwemdMx/WoEzAEiKe uON1BZTWvkt4PMVJcsAhLVW3DNOYRtTYBJ1MwwyHMfkUfm+LmOuLzut0wSJ7HC1RVlvb yT5g== X-Gm-Message-State: AOJu0Yw0OgB10iHkQ9IRJAAOdG+M7C99KNwIEL9n67RUdykd9Xn4gmIe lsvXqugA85CM/kAdaQZIhWENZUn/wtYwwakyV9JKY4VGn2kXbsMPFD7oF+ELu9qnDqxwYjfqp/r s X-Google-Smtp-Source: AGHT+IEwV+X94YGX7mnZrhjl05S8fc22Mo52WJsdy3gaIxYje7r5rPbvAxwB/Uue7WskqyX75pIbWQ== X-Received: by 2002:a05:6a00:852:b0:71e:4c34:e294 with SMTP id d2e1a72fcca58-724beca52e9mr131079b3a.7.1732043840589; Tue, 19 Nov 2024 11:17:20 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:20 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 3/8] hw/riscv/virt.c: rename helper to virt_use_kvm_aia_aplic_imsic() Date: Tue, 19 Nov 2024 16:17:01 -0300 Message-ID: <20241119191706.718860-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x42b.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Similar to the riscv_is_kvm_aia_aplic_imsic() helper from riscv_aplic.c, the existing virt_use_kvm_aia() is testing for KVM aia=aplic-imsic with in-kernel irqchip enabled. It is not checking for a generic AIA support. Rename the helper to virt_use_kvm_aia_aplic_imsic() to reflect what the helper is doing, and use the existing riscv_is_kvm_aia_aplic_imsic() to obscure details such as the presence of the in-kernel irqchip. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index e200fc561a..12176ae871 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -58,9 +58,11 @@ #include "hw/virtio/virtio-iommu.h" /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ -static bool virt_use_kvm_aia(RISCVVirtState *s) +static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type) { - return kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; + bool msimode = aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; + + return riscv_is_kvm_aia_aplic_imsic(msimode); } static bool virt_aclint_allowed(void) @@ -775,8 +777,8 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } - /* KVM AIA only has one APLIC instance */ - if (kvm_enabled() && virt_use_kvm_aia(s)) { + /* KVM AIA aplic-imsic only has one APLIC instance */ + if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, @@ -1565,7 +1567,7 @@ static void virt_machine_init(MachineState *machine) } } - if (kvm_enabled() && virt_use_kvm_aia(s)) { + if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, memmap[VIRT_APLIC_S].base, From patchwork Tue Nov 19 19:17:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3941D6C287 for ; Tue, 19 Nov 2024 19:19:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTj7-0002k1-P8; Tue, 19 Nov 2024 14:17:30 -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 1tDTj4-0002jE-VH for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:27 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTj3-0007dv-Ff for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:26 -0500 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-723db2798caso4801232b3a.0 for ; Tue, 19 Nov 2024 11:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043843; x=1732648643; 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=bFpahzsVJtnI1jlusgbxiTRns2vx5vCUwt4fV8qKZAY=; b=YyqQ/fajTT8c8Wxu1kU5c9aUTdex9ApcqqpGUo9Qo3iefnJUeQ+kDA2qycZ6CBnTnZ l3yF18f5cqB034mjg1jmUmUCDASnvPoMryEFEVKOpXIV48bFPUCADIlnvJ4mn9I2G9sa +hKvYpUXFP/AvZUFZwtNj3hR9t85c/bXfF6WFH3EYVG/s5igcPMIcRQg0mIkFk9YWTOF +Uw9fMit1DggifCLvcugiS3NS4hTgD4TXQCXwMDfQM7D3zZ6mBkxeoFrJMJexxs9Thmt ScN0M+ULqQQh6NfPfxrcA/zu0kW45XlqmJ47AZAUGSAD3f1hD+i+ukeiX/T7bti86yYk l13w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043843; x=1732648643; 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=bFpahzsVJtnI1jlusgbxiTRns2vx5vCUwt4fV8qKZAY=; b=tWkpJEOyB6HO/FyLWqU8u8N9nrBY0P8bMGf9iw/l54fdR4VlgI+obMcyzpi8QZqcHp 6x3pbY3IvNYKIGJ9amjHPonp+evAVsy0EpLEu99Pkonm7es0pHxtrs5WvH/Z90jl/tFb YuLTKnT6mMNUqpx1IADMEImY+iAVqB9bavlJfeFF/74BZ5/6eCP6PI1GUc32W+LEqWcs r1IonUgLhxNG0W71R7VZnB1qZb0+d/3sekRFD1UICtllyWOaqnQg8lSRA9wMpkSh8T7e wbT3Rl8MnmKoxWODHI5mil57qpXxd3KKAFsiQOmICrAjZ3dn0xRR5L4AGRf6maed8B+w dLzA== X-Gm-Message-State: AOJu0Yz8NZdbGcX2Evugpbzt1pSapZmW2SFCN7BYLmA2BxFZAWjmXw1n au/VyUreRfxxVfg6rxTD4Z+MaEDFWf7qAzlmrjpdeAmoP9Dp/hmdPBAyb4MaRcRl/Ppg5tnuLoV v X-Google-Smtp-Source: AGHT+IEw2vSpxNg2KPu5e9uAY7tHDToOHkc1gwHplVYGS+E/PphGGpyPjjxfJut/TUppIXMxo9ZQyQ== X-Received: by 2002:a05:6a00:3d07:b0:724:67dd:2615 with SMTP id d2e1a72fcca58-724bed54619mr157465b3a.22.1732043843494; Tue, 19 Nov 2024 11:17:23 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:23 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 4/8] target/riscv/kvm: consider irqchip_split() in aia_create() Date: Tue, 19 Nov 2024 16:17:02 -0300 Message-ID: <20241119191706.718860-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x42a.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Before adding support to kernel-irqchip=split when using KVM AIA we need to change how we create the in-kernel AIA device. In the use case we have so far, i.e. in-kernel irqchip without split mode, both the s-mode APLIC and IMSIC controllers are provided by the irqchip. In irqchip_split() mode we'll emulate the s-mode APLIC controller, which will send MSIs to the in-kernel IMSIC controller. To do that we need to change kvm_riscv_aia_create() to not create the in-kernel s-mode APLIC controller. In the kernel source arch/riscv/kvm/aia_aplic.c, function kvm_riscv_aia_aplic_init(), we verify that the APLIC controller won't be instantiated by KVM if we do not set 'nr_sources', which is set via KVM_DEV_RISCV_AIA_CONFIG_SRCS. For QEMU this means that we should not set 'aia_irq_num' during kvm_riscv_aia_create() in irqchip_split() mode. In this same condition, skip KVM_DEV_RISCV_AIA_ADDR_APLIC as well since it is used to set the base address for the in-kernel APLIC controller. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- target/riscv/kvm/kvm-cpu.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c index c53ca1f76b..a9680f2447 100644 --- a/target/riscv/kvm/kvm-cpu.c +++ b/target/riscv/kvm/kvm-cpu.c @@ -1734,13 +1734,29 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, } } - ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, - KVM_DEV_RISCV_AIA_CONFIG_SRCS, - &aia_irq_num, true, NULL); - if (ret < 0) { - error_report("KVM AIA: failed to set number of input irq lines"); - exit(1); - } + /* + * Skip APLIC creation in KVM if we're running split mode. + * This is done by leaving KVM_DEV_RISCV_AIA_CONFIG_SRCS + * unset. We can also skip KVM_DEV_RISCV_AIA_ADDR_APLIC + * since KVM won't be using it. + */ + if (!kvm_kernel_irqchip_split()) { + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, + KVM_DEV_RISCV_AIA_CONFIG_SRCS, + &aia_irq_num, true, NULL); + if (ret < 0) { + error_report("KVM AIA: failed to set number of input irq lines"); + exit(1); + } + + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, + KVM_DEV_RISCV_AIA_ADDR_APLIC, + &aplic_base, true, NULL); + if (ret < 0) { + error_report("KVM AIA: failed to set the base address of APLIC"); + exit(1); + } + } ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, KVM_DEV_RISCV_AIA_CONFIG_IDS, @@ -1781,14 +1797,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, exit(1); } - ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, - KVM_DEV_RISCV_AIA_ADDR_APLIC, - &aplic_base, true, NULL); - if (ret < 0) { - error_report("KVM AIA: failed to set the base address of APLIC"); - exit(1); - } - for (socket = 0; socket < socket_count; socket++) { socket_imsic_base = imsic_base + socket * (1U << group_shift); hart_count = riscv_socket_hart_count(machine, socket); From patchwork Tue Nov 19 19:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E31ED6C28B for ; Tue, 19 Nov 2024 19:19:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTjA-0002kw-TV; Tue, 19 Nov 2024 14:17:32 -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 1tDTj9-0002kW-5E for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:31 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTj6-0007ew-8b for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:30 -0500 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7245a9d0e92so4569803b3a.0 for ; Tue, 19 Nov 2024 11:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043846; x=1732648646; 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=r+dqWcuY/4IVl9sC0fRXQIh7posLIMzyH0HnJSrHue0=; b=HjGZp1/uyRHaQkam6UZSg3VooJ/ppUeg1xFHNevmamMA7n4t4ZP8X44p/IUa9eFzm0 6mB/3YzjY72j6newcxKmUbUxgXA4DuZA2BWrfvRRH7PyqeDF9Dhpm4Y0aiI2phlz05k3 Ix/elYIlYdAqm278nlmn2TKJNRoAHizh1rEHacyw17J8Bq7COL96vmy3bfn2A3kTVEB5 9xQMmRIS2Bue3+2lVa7GuCei+jS4TbZzFFvdbSez37Oxd/fC9KrEfglszgULL7KcQwMq aAmIm6/q0BJVaGzYL2CyGTgH5cmPkn5hEufRsERRyzT4dbPQVMSNrn+txLynW1otn4c6 CRcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043846; x=1732648646; 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=r+dqWcuY/4IVl9sC0fRXQIh7posLIMzyH0HnJSrHue0=; b=nTEGqcEn81VfiTrIZrPsNaiMqVbZHTNS7NB+OF7OI8i8XED2q3XaaMVQlmpdLOSnQa hUxyVk8M/l1tvXC/mOVpRNSE60aLfw69BbP+4nLSkHWTe+8XvVrcWUpzhDvU/ty2tdpU zNFbLZYFEWxtPG3xWNdHCtRsluJFkN5zoGJSbbf4ZRdcYpuqM1fVE+dTPeVOgk31lz45 bWUzWafL+ORgYV88RcnhZXnini7yXwWHg4hOAOXh4XqOZKyssqCy+2CgWPj76t/WqmVQ erTR4VJvk9qroTxqsnNqlBvj1WA2EhT7JZTG3urNcxzRmAwLLbqh5Ue55Fu5JSQDEUVK 1XFQ== X-Gm-Message-State: AOJu0Yxd6iwemz1Qe4cibIeZKo7eBDwRw4a6L2abEFhdVXWiamObjUwW vdn9s5Kr+6fU3WvmSxu7SYECmrkwrFInPqNOtqlEnGI4GMdYUPCkkuFuRzcee7s1iKeHklEbQi6 a X-Google-Smtp-Source: AGHT+IG+AP3MhOME0N7FECPxvahlZHOOJsH4K0U7vO8OACB+T9frxQOxjSb+MIizMqYo6U65pXIpXQ== X-Received: by 2002:a05:6a00:852:b0:71e:4c34:e294 with SMTP id d2e1a72fcca58-724beca52e9mr131381b3a.7.1732043846510; Tue, 19 Nov 2024 11:17:26 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:26 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 5/8] hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers Date: Tue, 19 Nov 2024 16:17:03 -0300 Message-ID: <20241119191706.718860-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x432.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The current logic to determine if we don't need an emulated APLIC controller, i.e. KVM will provide for us, is to determine if we're running KVM, with in-kernel irqchip support, and running aia=aplic-imsic. This is modelled by riscv_is_kvm_aia_aplic_imsic() and virt_use_kvm_aia_aplic_imsic(). This won't suffice to support irqchip_split() mode: it will match exactly the same conditions as the one above, but setting the irqchip to 'split' mode will now require us to emulate an APLIC s-mode controller, like we're doing with 'aia=aplic'. Create a new riscv_use_emulated_aplic() helper that will encapsulate this logic. Replace the uses of "riscv_is_kvm_aia_aplic_imsic()" with this helper every time we're taking a decision on emulate an APLIC controller or not. Do the same in virt.c with virt_use_emulated_aplic(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/intc/riscv_aplic.c | 24 +++++++++++++++++++++--- hw/riscv/virt.c | 14 ++++++++++++-- include/hw/intc/riscv_aplic.h | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 20de8c63a2..0696e20ddf 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -32,6 +32,7 @@ #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" @@ -159,6 +160,23 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode) return kvm_irqchip_in_kernel() && msimode; } +bool riscv_use_emulated_aplic(bool msimode) +{ +#ifdef CONFIG_KVM + if (tcg_enabled()) { + return true; + } + + if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { + return true; + } + + return kvm_kernel_irqchip_split(); +#else + return true; +#endif +} + static bool riscv_aplic_irq_rectified_val(RISCVAPLICState *aplic, uint32_t irq) { @@ -853,7 +871,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) uint32_t i; RISCVAPLICState *aplic = RISCV_APLIC(dev); - if (!riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { + if (riscv_use_emulated_aplic(aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); aplic->state = g_new0(uint32_t, aplic->num_irqs); @@ -877,7 +895,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) * have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { - if (kvm_enabled() && riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { + if (kvm_enabled() && !riscv_use_emulated_aplic(aplic->msimode)) { qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); } else { qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); @@ -1021,7 +1039,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { + if (riscv_use_emulated_aplic(msimode)) { sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); } diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 12176ae871..a954ca2104 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -65,6 +65,13 @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type) return riscv_is_kvm_aia_aplic_imsic(msimode); } +static bool virt_use_emulated_aplic(RISCVVirtAIAType aia_type) +{ + bool msimode = aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; + + return riscv_use_emulated_aplic(msimode); +} + static bool virt_aclint_allowed(void) { return tcg_enabled() || qtest_enabled(); @@ -777,8 +784,11 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, *msi_pcie_phandle = msi_s_phandle; } - /* KVM AIA aplic-imsic only has one APLIC instance */ - if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { + /* + * With KVM AIA aplic-imsic, using an irqchip without split + * mode, we'll use only one APLIC instance. + */ + if (!virt_use_emulated_aplic(s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h index fd0e6427d9..74ae5d87b5 100644 --- a/include/hw/intc/riscv_aplic.h +++ b/include/hw/intc/riscv_aplic.h @@ -72,6 +72,7 @@ struct RISCVAPLICState { void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); bool riscv_is_kvm_aia_aplic_imsic(bool msimode); +bool riscv_use_emulated_aplic(bool msimode); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, From patchwork Tue Nov 19 19:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FF0BD6C28C for ; Tue, 19 Nov 2024 19:19:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTjD-0002mb-MI; Tue, 19 Nov 2024 14:17:35 -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 1tDTjB-0002lq-NQ for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:33 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTj9-0007g4-3J for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:33 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-724a96f188cso1632314b3a.1 for ; Tue, 19 Nov 2024 11:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043849; x=1732648649; 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=et/XKpCq8FfunkNiTWjfwypcxxKP1J2/i2fCKASeod0=; b=eYpnRiErAWqKtqmVd4BnnoWJstZDA1Wp6jeCbJXMRK3bdmF/W/Nj32XgV3bAZlv9eg iKvN75W8RpTtzu5EE+3t7wKbnSQLfV5RA9gNYmlCCqFeseKbNY5KXm1qc4M6U6CNb4+c YBs8Cq4vPShEcnub5KRNqWc1fdLx0fjaCsYZE5vTh19eS5SFuQbot895ZcJf++ku9YS0 F0nrAk4dqaPjXmZR3Y21sW1dzQZy3Pjm0OxYRYtKimHCgnPl4cmySofIOaAsOlYslFHg OnOj2u3SAJB+8aPGNtbGYqnaHL1OOb/XBn+2f5ABA4JjUeopFtbCiTIKH8BfhczbMphp e5WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043849; x=1732648649; 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=et/XKpCq8FfunkNiTWjfwypcxxKP1J2/i2fCKASeod0=; b=PpReuYw/pz9i2QY6lTB5JqCNUCPDwM1KSbjE5z17lNBvPHbmwR37E0PKXqiF2db5FR VzxGpghIqIFsnQFvvi81VxtQEeQENSSV+21ClV/IIfqBIJLiFNI5D82SqfvM0Hb3YrSO r0gzxUNlv3K+3uy4+LWJbvP5ib6yuT1rOQXA0GCe1/Impwjj8NzuDXKfLNsDa/0Gtpei l97gq3FypSW0hkiMeDGPGvvuCkHAL9alJGMbgSOfdac5L1gkn6lNoNdxlTHbNpMd2aou VYwF1TQWKtZLgRIGkVz28FGb+5JMR/pV5yaWzJw/YOWjLlBzoszDpFLlTqz77ADHr0Fu Be5w== X-Gm-Message-State: AOJu0YwGquZE6ZjVbFBFtz8bumZFZGN20FG2GSw3SxXQ8DXbt+5go5oI RLgjz4srQfBCC/P9ZWNx5yGBELk8uZJ+/I7embS84M6tbuKwjg/dS5r/8KTKI1i+CC2SvLa25Of x X-Google-Smtp-Source: AGHT+IF2aBWtd8Mn1XU+YpwStt3yD/YqROSZx9NvYOIy5/mwcuqTEPhkDoMwFnzD3m0tbc8+T7QHNg== X-Received: by 2002:a17:902:e5c9:b0:20b:ce88:1b9d with SMTP id d9443c01a7336-211d0ec0544mr221588405ad.45.1732043849548; Tue, 19 Nov 2024 11:17:29 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:29 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 6/8] hw/intc/riscv_aplic: add kvm_msicfgaddr for split mode aplic-imsic Date: Tue, 19 Nov 2024 16:17:04 -0300 Message-ID: <20241119191706.718860-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x42c.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The last step to enable KVM AIA aplic-imsic with irqchip in split mode is to deal with how MSIs are going to be sent. In our current design we don't allow an APLIC controller to send MSIs unless it's on m-mode. And we also do not allow Supervisor MSI address configuration via the 'smsiaddrcfg' and 'smsiaddrcfgh' registers unless it's also a m-mode APLIC controller. Add a new RISCVACPLICState attribute called 'kvm_msicfgaddr'. This attribute represents the base configuration address for MSIs, in our case the base addr of the IMSIC controller. This attribute is being set only when running irqchip_split() mode with aia=aplic-imsic. During riscv_aplic_msi_send() we'll check if the attribute was set to skip the check for a m-mode APLIC controller and to change the resulting MSI addr by adding kvm_msicfgaddr right before address_space_stl_le(). Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/intc/riscv_aplic.c | 42 +++++++++++++++++++++++++++-------- hw/riscv/virt.c | 6 ++++- include/hw/intc/riscv_aplic.h | 6 +++++ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 0696e20ddf..4de458e395 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -177,6 +177,16 @@ bool riscv_use_emulated_aplic(bool msimode) #endif } +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) +{ +#ifdef CONFIG_KVM + if (riscv_use_emulated_aplic(aplic->msimode)) { + aplic->kvm_msicfgaddr = extract64(addr, 0, 32); + aplic->kvm_msicfgaddrH = extract64(addr, 32, 32); + } +#endif +} + static bool riscv_aplic_irq_rectified_val(RISCVAPLICState *aplic, uint32_t irq) { @@ -377,13 +387,16 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; aplic_m = aplic; - while (aplic_m && !aplic_m->mmode) { - aplic_m = aplic_m->parent; - } - if (!aplic_m) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", - __func__); - return; + + if (!aplic->kvm_splitmode) { + while (aplic_m && !aplic_m->mmode) { + aplic_m = aplic_m->parent; + } + if (!aplic_m) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", + __func__); + return; + } } if (aplic->mmode) { @@ -415,6 +428,11 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; + if (aplic->kvm_splitmode) { + addr |= aplic->kvm_msicfgaddr; + addr |= ((uint64_t)aplic->kvm_msicfgaddrH << 32); + } + address_space_stl_le(&address_space_memory, addr, eiid, MEMTXATTRS_UNSPECIFIED, &result); if (result != MEMTX_OK) { @@ -888,6 +906,10 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, TYPE_RISCV_APLIC, aplic->aperture_size); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); + + if (kvm_enabled()) { + aplic->kvm_splitmode = true; + } } /* @@ -935,8 +957,8 @@ static Property riscv_aplic_properties[] = { static const VMStateDescription vmstate_riscv_aplic = { .name = "riscv_aplic", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (const VMStateField[]) { VMSTATE_UINT32(domaincfg, RISCVAPLICState), VMSTATE_UINT32(mmsicfgaddr, RISCVAPLICState), @@ -944,6 +966,8 @@ static const VMStateDescription vmstate_riscv_aplic = { VMSTATE_UINT32(smsicfgaddr, RISCVAPLICState), VMSTATE_UINT32(smsicfgaddrH, RISCVAPLICState), VMSTATE_UINT32(genmsi, RISCVAPLICState), + VMSTATE_UINT32(kvm_msicfgaddr, RISCVAPLICState), + VMSTATE_UINT32(kvm_msicfgaddrH, RISCVAPLICState), VMSTATE_VARRAY_UINT32(sourcecfg, RISCVAPLICState, num_irqs, 0, vmstate_info_uint32, uint32_t), diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index a954ca2104..ee223f86ec 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1246,7 +1246,7 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, int base_hartid, int hart_count) { int i; - hwaddr addr; + hwaddr addr = 0; uint32_t guest_bits; DeviceState *aplic_s = NULL; DeviceState *aplic_m = NULL; @@ -1296,6 +1296,10 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, VIRT_IRQCHIP_NUM_PRIO_BITS, msimode, false, aplic_m); + if (kvm_enabled() && msimode) { + riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s), addr); + } + return kvm_enabled() ? aplic_s : aplic_m; } diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h index 74ae5d87b5..489b9133c2 100644 --- a/include/hw/intc/riscv_aplic.h +++ b/include/hw/intc/riscv_aplic.h @@ -68,11 +68,17 @@ struct RISCVAPLICState { uint32_t num_irqs; bool msimode; bool mmode; + + /* To support KVM aia=aplic-imsic with irqchip split mode */ + bool kvm_splitmode; + uint32_t kvm_msicfgaddr; + uint32_t kvm_msicfgaddrH; }; void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); bool riscv_is_kvm_aia_aplic_imsic(bool msimode); bool riscv_use_emulated_aplic(bool msimode); +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr); DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, From patchwork Tue Nov 19 19:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880468 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8A5FD6C28B for ; Tue, 19 Nov 2024 19:19:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTjK-0002oB-BA; Tue, 19 Nov 2024 14:17:42 -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 1tDTjH-0002nT-6q for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:39 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTjC-0007gz-A7 for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:38 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-72487ebd2f5so2857756b3a.1 for ; Tue, 19 Nov 2024 11:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043852; x=1732648652; 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=AtwIk6HkYOGhU19AjHqQe2GTivk7yu3nAfc701TP3rY=; b=SFhUoCFtiyJkooZ1abyOYMckkBAhSb2QVkIs5A8oxNlcz+Vkrk3YciRqC2Ajpa9g53 zxWlWxeADQkn7H3RHHeYgXavc91+A0Su69VxhFDfffuefBgxPKk8pNeHIyyDKbAjcyeC +xwykqy87c9NTnfXW9bfvbR2JPd3+8do1Vn2LXlpOWvMRsZmP4ePOtqMHl8KwRJHcQFc wRj7y2fo1xHWXlQs5x7FMpy+leSsxFgUr6d1fWlzDmBCW47njotYA+aEAuCcjWYly1TA P5fvzVanrpu100JeMePP42UreHQq+vQIAED7Md7STfUPBvD4P2gQ5HpkvS4Daguv2amp tzKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043852; x=1732648652; 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=AtwIk6HkYOGhU19AjHqQe2GTivk7yu3nAfc701TP3rY=; b=fQxiGemkkRRzO+DNBh/a+UxyOpw1Ucqtmwj8fYLComMkkZZBieOTxCrwFtpM6WdHaA /eJRHDNOCrL6ZR6LyzYsm+9r344bEExOv7Zxyay3bG2QLLBBbJc+efmv9LP+aN5Ty+ON vkD25Z5MWAkVX9TJmzP+2NMb/Mt/qt4IkpQZUhLPAKeMJ/yvcuvJo9J2m9hBd9x9GLi6 e7LotMaOrBLR6/g/M7j0ZESB444p+ZoP+8HOeSqXwNRoG8zwpDeW1lb0/oE/UqDEsgV3 hx6MwWkJgSH+sY/1x4obReMZTu01IDK1MH0QTaVKswYAmf/GZoScYPGvIxBe/cb8kkwm WH7Q== X-Gm-Message-State: AOJu0YxV2xTBQifbM5zGyLn5NYzrg5qDC22ZRHEDYrG1KybC7tQyYv/0 WYhNXSD9IvedsJqk3hqAg/hU+vpO3vwOhefQY8YYUzGHst6wCAJiGaG3jorRjRjTz1dD61PO8NU 3 X-Google-Smtp-Source: AGHT+IFJ7QTNystlVZ/PA1M42dL8S4Kpg058GD/3NGQH57Q90TlCuRQ2Edmv3MwHWx3o0Zuo7P5fOA== X-Received: by 2002:a05:6a00:1311:b0:724:5aac:1687 with SMTP id d2e1a72fcca58-724bed54e77mr175242b3a.20.1732043852617; Tue, 19 Nov 2024 11:17:32 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:32 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 7/8] target/riscv/kvm: remove irqchip_split() restriction Date: Tue, 19 Nov 2024 16:17:05 -0300 Message-ID: <20241119191706.718860-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x42e.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, T_SPF_TEMPERROR=0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Remove the 'irqchip_split()' restriction in kvm_arch_init() now that we have support for "-accel kvm,kernel-irqchip=split". Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- target/riscv/kvm/kvm-cpu.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c index a9680f2447..aaff4a0f42 100644 --- a/target/riscv/kvm/kvm-cpu.c +++ b/target/riscv/kvm/kvm-cpu.c @@ -1408,11 +1408,6 @@ int kvm_arch_init(MachineState *ms, KVMState *s) int kvm_arch_irqchip_create(KVMState *s) { - if (kvm_kernel_irqchip_split()) { - error_report("-machine kernel_irqchip=split is not supported on RISC-V."); - exit(1); - } - /* * We can create the VAIA using the newer device control API. */ From patchwork Tue Nov 19 19:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13880469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC1A2D6C287 for ; Tue, 19 Nov 2024 19:20:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDTjO-0002pM-BM; Tue, 19 Nov 2024 14:17:46 -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 1tDTjI-0002ne-2N for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:40 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDTjF-0007hk-9G for qemu-devel@nongnu.org; Tue, 19 Nov 2024 14:17:39 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-72483f6e2fbso2942142b3a.2 for ; Tue, 19 Nov 2024 11:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1732043856; x=1732648656; 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=xsTb34GN4ViZbRmdsc1D7ztxOvyrze/RXxWHRe6RRhA=; b=Zv//HfcGo6ntoz4JLS4jk2P82LqIzMD95NuS01Pj4P9Gpm+BdZp2qg8HKmsRZXzTpl LGCmdLj/NSEl1SDs5N5bTTGz2qreJPGoFFEjWqhgUkNib8cSVGLD1SVN6ksgIRZw0NxP fcNqwY1i3dim2BrEysXqewta26MKJD3uUm07wWtUvnyxkXic3oewek0kg/ohztRQSegB XkqlpZojvygIEy05SyfYsP3Bg24ePVWBWuvMApk+RSlHif4dUAyeQqtyNXCON6TqA3WU SAqRWZB119vsw1ZepdNV34lhwtWjsAQ9/p5CTCwu04rsUThEVx3VllEzeAkkhg9QB6D3 8Bnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732043856; x=1732648656; 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=xsTb34GN4ViZbRmdsc1D7ztxOvyrze/RXxWHRe6RRhA=; b=spu2SYf8onYfoBEgTaND5UO0HQV3GUhw9/hKsPztjcEySyiHvYtkQTQCPa8w5bEvZL H8/HihyltMdrcTtXdH0HPU/XSaQ6V7ZZpnySomqhzDLQRkjiGsIb9iq6zrG5cExoF0qT mlzYTChhs1h9ms+FmY0R93pHbsU/iWnD9q+zKaIFH+EFT1PJZTxMCF0j5jCdZU3YalAu SwurkulzyUElqLBWFxuLEa+AX0q3qGm637/tZBsktt0r7yTCBLP4tQ7D65nKUtqJ5J+s jeyTryX9yM3JpnnkI81T0mdgWCc3rIqMShfKc7hDk+1QGSrK/2Lnt3tBAMqZ2t0O0Am2 PD3g== X-Gm-Message-State: AOJu0Yy8NrVKNr5EGRNVmg4f9S9pEOfLPUvXIxwFesdMU6OcFcU15ZOw n4z8axjiuhTT/dXb2eR2ZHOLgICTHXqBoQ0jfGL2dUU76YvkW1VOOw1JEZ70qDIGxYsQlU2uNDw s X-Google-Smtp-Source: AGHT+IHDIL2QEkJZSU2bWHPxmZ23ZPHLdmGVmlFKC+1VddDH46erDhrcoegQ5I7pm2fOLIFt0pWeqw== X-Received: by 2002:a05:6a00:2285:b0:71e:55e2:2c58 with SMTP id d2e1a72fcca58-724becc5a22mr171603b3a.15.1732043855609; Tue, 19 Nov 2024 11:17:35 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([187.101.65.72]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82f2sm24271b3a.35.2024.11.19.11.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 11:17:35 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-10.0 v2 8/8] docs: update riscv/virt.rst with kernel-irqchip=split support Date: Tue, 19 Nov 2024 16:17:06 -0300 Message-ID: <20241119191706.718860-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119191706.718860-1-dbarboza@ventanamicro.com> References: <20241119191706.718860-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x433.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Also add a new page, docs/specs/riscv-aia.rst, where we're documenting the state of AIA support in QEMU w.r.t the controllers being emulated or not depending on the AIA and accelerator settings. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- docs/specs/index.rst | 1 + docs/specs/riscv-aia.rst | 83 ++++++++++++++++++++++++++++++++++++++ docs/system/riscv/virt.rst | 7 ++++ 3 files changed, 91 insertions(+) create mode 100644 docs/specs/riscv-aia.rst diff --git a/docs/specs/index.rst b/docs/specs/index.rst index ff5a1f03da..d7675cebc2 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -37,3 +37,4 @@ guest hardware that is specific to QEMU. rapl-msr rocker riscv-iommu + riscv-aia diff --git a/docs/specs/riscv-aia.rst b/docs/specs/riscv-aia.rst new file mode 100644 index 0000000000..8097e2f897 --- /dev/null +++ b/docs/specs/riscv-aia.rst @@ -0,0 +1,83 @@ +.. _riscv-aia: + +RISC-V AIA support for RISC-V machines +====================================== + +AIA (Advanced Interrupt Architecture) support is implemented in the ``virt`` +RISC-V machine for TCG and KVM accelerators. + +The support consists of two main modes: + +- "aia=aplic": adds one or more APLIC (Advanced Platform Level Interrupt Controller) + devices +- "aia=aplic-imsic": adds one or more APLIC device and an IMSIC (Incoming MSI + Controller) device for each CPU + +From an user standpoint, these modes will behave the same regardless of the accelerator +used. From a developer standpoint the accelerator settings will change what it being +emulated in userspace versus what is being emulated by an in-kernel irqchip. + +When running TCG, all controllers are emulated in userspace, including machine mode +(m-mode) APLIC and IMSIC (when applicable). + +When running KVM: + +- no m-mode is provided, so there is no m-mode APLIC or IMSIC emulation regardless of + the AIA mode chosen +- with "aia=aplic", s-mode APLIC will be emulated by userspace +- with "aia=aplic-imsic" there are two possibilities. If no additional KVM option + is provided there will be no APLIC or IMSIC emulation in userspace, and the virtual + machine will use the provided in-kernel APLIC and IMSIC controllers. If the user + chooses to use the irqchip in split mode via "-accel kvm,kernel-irqchip=split", + s-mode APLIC will be emulated while using the s-mode IMSIC from the irqchip + +The following table summarizes how the AIA and accelerator options defines what +we will emulate in userspace: + + +.. list-table:: How AIA and accel options changes controller emulation + :widths: 25 25 25 25 25 25 25 + :header-rows: 1 + + * - Accel + - Accel props + - AIA type + - APLIC m-mode + - IMSIC m-mode + - APLIC s-mode + - IMSIC s-mode + * - tcg + - --- + - aplic + - emul + - n/a + - emul + - n/a + * - tcg + - --- + - aplic-imsic + - emul + - emul + - emul + - emul + * - kvm + - --- + - aplic + - n/a + - n/a + - emul + - n/a + * - kvm + - none + - aplic-imsic + - n/a + - n/a + - in-kernel + - in-kernel + * - kvm + - irqchip=split + - aplic-imsic + - n/a + - n/a + - emul + - in-kernel diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 8e9a2e4dda..ae4a2031e1 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -123,6 +123,13 @@ The following machine-specific options are supported: MSIs. When not specified, this option is assumed to be "none" which selects SiFive PLIC to handle wired interrupts. + This option also interacts with '-accel kvm'. When using "aia=aplic-imsic" + with KVM, it is possible to set the use of the kernel irqchip in split mode + by using "-accel kvm,kernel-irqchip=split". In this case the ``virt`` machine + will emulate the APLIC controller instead of using the APLIC controller from + the irqchip. See :ref:`riscv-aia` for more details on all available AIA + modes. + - aia-guests=nnn The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest