From nobody Mon Nov 23 04:26:29 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 ARC-Seal: i=1; a=rsa-sha256; t=1794378613; cv=none; d=zohomail.com; s=zohoarc; b=Yuak1aaU5YMkXwEOlX23wCATihjdrhxbC+UyKTbjVJTjYbJI8a7mq8xWOAWbcGcvNZsr23naik5ld2SwJ7+sDfHgWQHSrqCC5aW+oN3brsUB1RPBl+hErut/bfXedd3oYu+rlBZMRdTAjR60yCexnaVCP4FxDZy5dbykOR3nh5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794378613; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kzxh7/DC1bf4hnVVE6T+siDS+anoQANlbP58xi0M24I=; b=YhpC493qdhaVP8zqsYW3UGKbkglo3LvKtOyNsrOEN5e0qdPmoRvbnP/YImcqsbm3IzUOcUqmy6Wa/y3MGqNv5Y1evNyWMVzv1vw8IMxEMnstDMmvErsBuIzbjSCBsT5tyFviw36nldJ8wU9054qCevN/Yj4DjfkvX/12Cq1AAjk= 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 Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794378613499370.39672774974804; Tue, 10 Nov 2026 22:30:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xR1pa-0002vD-Lv; Wed, 11 Nov 2026 01:29:14 -0500 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 1xR1pY-0002t6-RP for qemu-devel@nongnu.org; Wed, 11 Nov 2026 01:29:13 -0500 Received: from va-2-20.ptr.blmpb.com ([209.127.231.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xR1pU-0000vw-LB for qemu-devel@nongnu.org; Wed, 11 Nov 2026 01:29:12 -0500 Received: from lanxin-ThinkBook-16-G5-IRH.lan ([123.120.4.67]) by smtp.feishu.cn with ESMTP; Wed, 11 Nov 2026 14:28:52 +0800 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=lanxincomputing-com.20200927.dkim.feishu.cn; t=1794378535; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=kzxh7/DC1bf4hnVVE6T+siDS+anoQANlbP58xi0M24I=; b=AKFmBdBp9Rn/BVih0r599k9AQ39J0fSSFDRO8qIOex/7IeyFw79LFF8XSzLufBM2TaDyVx 1HYJA+eBrPEsEHrcqoBOooyxNm2/1r/+VzQlgWJ4b2hH3HeHxEDwGPlBXO2ZAAcl8BDZph BFfgDGJxfxNNe5UWAfwNnTfpkDvA8uwklrLayethufXPvohkBN1704tKA24bHmhxvb+ptr m6Z/4M6KwrfV+YcCwn0CdDyCtVOw+Bh+ycMXIOI97F0w7xlbugMCVjXfUNyk1eviH9RpMN +Dz78FwBAf/dbzYanqfoDAft4FUw1GN+9JoqtB9phVXJkZ9wDcDdh6zgYjqkvw== Cc: , , , , , , , , , Subject: [PATCH v3] hw/intc/aplic: Fix msicfgaddrH in split mode Message-Id: <20261111062823.328813-1-xiangwencheng@lanxincomputing.com> X-Original-From: BillXiang X-Mailer: git-send-email 2.53.0 To: Date: Wed, 11 Nov 2026 14:28:23 +0800 Content-Transfer-Encoding: quoted-printable From: "BillXiang" Mime-Version: 1.0 X-Lms-Return-Path: 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=209.127.231.20; envelope-from=xiangwencheng@lanxincomputing.com; helo=va-2-20.ptr.blmpb.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, MSGID_FROM_MTA_HEADER=0.001, 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 @lanxincomputing-com.20200927.dkim.feishu.cn) X-ZM-MESSAGEID: 1794378619136158500 Content-Type: text/plain; charset="utf-8" Add hart_bits and guest_bits to msicfgaddrH in KVM irqchip split mode. Also remove the redundant left shift when loading kvm_msicfgaddrH in riscv_aplic_msi_send(). Rationale: static void riscv_aplic_msi_send(RISCVAPLICState *aplic, uint32_t hart_idx, uint32_t guest_idx, uint32_t eiid) { uint64_t addr; MemTxResult result; RISCVAPLICState *aplic_m; uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; ... if (aplic->kvm_splitmode) { msicfgaddr =3D aplic->kvm_msicfgaddr; 1. msicfgaddrH =3D ((uint64_t)aplic->kvm_msicfgaddrH << 32); } ... lhxs =3D (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & APLIC_xMSICFGADDRH_LHXS_MASK; lhxw =3D (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) & APLIC_xMSICFGADDRH_LHXW_MASK; hhxs =3D (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) & APLIC_xMSICFGADDRH_HHXS_MASK; hhxw =3D (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) & APLIC_xMSICFGADDRH_HHXW_MASK; ... group_idx =3D hart_idx >> lhxw; addr =3D msicfgaddr; 2. addr |=3D ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; addr |=3D ((uint64_t)(group_idx & APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) << APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs); 3. addr |=3D ((uint64_t)(hart_idx & APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) << APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs); 4. addr |=3D (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); addr <<=3D APLIC_xMSICFGADDR_PPN_SHIFT; ... } Since msicfgaddrH is left-shifted at (2), the left shift at (1) is redundant. At (3) and (4), hart_idx and guest_idx are masked/shifted using lhxw and lhxs, which are extracted from the LHXW/LHXS fields of msicfgaddrH. However, riscv_aplic_set_kvm_msicfgaddr() did not program the LHXW/LHXS fields into kvm_msicfgaddrH, so lhxs/lhxw always read as zero, and the hart/guest idxs were never encoded into the MSI address. Fix this by programming hart_bits (LHXW) and guest_bits (LHXS) into kvm_msicfgaddrH in riscv_aplic_set_kvm_msicfgaddr(). Reviewed-by: Nutty Liu Reviewed-by: Daniel Henrique Barboza Signed-off-by: BillXiang --- Changes in v3: - Add assertions for hart_bits and guest_bits. Changes in v2: - Add rationale. --- hw/intc/riscv_aplic.c | 16 ++++++++++++---- hw/riscv/aia.c | 6 +++++- include/hw/intc/riscv_aplic.h | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 03a0852b8b..c0c1da7804 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -182,8 +182,12 @@ bool riscv_use_emulated_aplic(bool msimode) return kvm_kernel_irqchip_split(); } =20 -void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr, + uint32_t hart_bits, uint32_t guest_bit= s) { + assert(hart_bits <=3D APLIC_xMSICFGADDRH_LHXW_MASK); + assert(guest_bits <=3D APLIC_xMSICFGADDRH_LHXS_MASK); + if (!kvm_enabled()) { return; } @@ -191,8 +195,12 @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *a= plic, hwaddr addr) if (riscv_use_emulated_aplic(aplic->msimode)) { addr >>=3D APLIC_xMSICFGADDR_PPN_SHIFT; aplic->kvm_msicfgaddr =3D extract64(addr, 0, 32); - aplic->kvm_msicfgaddrH =3D extract64(addr, 32, 32) & - APLIC_MMSICFGADDRH_VALID_MASK; + aplic->kvm_msicfgaddrH =3D + ((hart_bits & APLIC_xMSICFGADDRH_LHXW_MASK) << + APLIC_xMSICFGADDRH_LHXW_SHIFT) | + ((guest_bits & APLIC_xMSICFGADDRH_LHXS_MASK) << + APLIC_xMSICFGADDRH_LHXS_SHIFT) | + (extract64(addr, 32, 32) & APLIC_xMSICFGADDRH_BAPPN_MASK); } } =20 @@ -404,7 +412,7 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, =20 if (aplic->kvm_splitmode) { msicfgaddr =3D aplic->kvm_msicfgaddr; - msicfgaddrH =3D ((uint64_t)aplic->kvm_msicfgaddrH << 32); + msicfgaddrH =3D aplic->kvm_msicfgaddrH; } else { msicfgaddr =3D aplic_m->mmsicfgaddr; msicfgaddrH =3D aplic_m->mmsicfgaddrH; diff --git a/hw/riscv/aia.c b/hw/riscv/aia.c index 56fc064533..bd608bd7a6 100644 --- a/hw/riscv/aia.c +++ b/hw/riscv/aia.c @@ -38,6 +38,7 @@ DeviceState *riscv_create_aia(MemoryRegion *container, { int i; hwaddr addr =3D 0; + uint32_t hart_bits, guest_bits; DeviceState *aplic_s_dev =3D NULL; DeviceState *aplic_m_dev =3D NULL; =20 @@ -93,7 +94,10 @@ DeviceState *riscv_create_aia(MemoryRegion *container, msimode, false, aplic_m_dev); =20 if (kvm_enabled() && msimode) { - riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s_dev), addr); + hart_bits =3D imsic_num_bits(hart_count); + guest_bits =3D imsic_num_bits(aia_guests + 1); + riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s_dev), addr, + hart_bits, guest_bits); } =20 return kvm_enabled() ? aplic_s_dev : aplic_m_dev; diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h index 62d2b33ade..d3ee2e537a 100644 --- a/include/hw/intc/riscv_aplic.h +++ b/include/hw/intc/riscv_aplic.h @@ -78,7 +78,8 @@ 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); -void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr); +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr, + uint32_t hart_bits, uint32_t guest_bit= s); =20 DeviceState *riscv_aplic_create(MemoryRegion *container, hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, --=20 2.53.0