{"id":2228039,"url":"http://patchwork.ozlabs.org/api/patches/2228039/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260425005916.3321811-5-guoren@kernel.org/","project":{"id":70,"url":"http://patchwork.ozlabs.org/api/projects/70/?format=json","name":"Linux KVM RISC-V","link_name":"kvm-riscv","list_id":"kvm-riscv.lists.infradead.org","list_email":"kvm-riscv@lists.infradead.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"http://lists.infradead.org/pipermail/kvm-riscv/","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260425005916.3321811-5-guoren@kernel.org>","list_archive_url":null,"date":"2026-04-25T00:59:16","name":"[V2,4/4] RISC-V: KVM: AIA: Use per-HART IMSIC guest files to compute final HGEI count","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"60afbe326234d9c5e699fda55c1cf9903cfe0be7","submitter":{"id":75626,"url":"http://patchwork.ozlabs.org/api/people/75626/?format=json","name":"Guo Ren","email":"guoren@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260425005916.3321811-5-guoren@kernel.org/mbox/","series":[{"id":501412,"url":"http://patchwork.ozlabs.org/api/series/501412/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/list/?series=501412","date":"2026-04-25T00:59:13","name":"RISC-V: KVM: AIA: Convert HGEI management to fully per-HART","version":2,"mbox":"http://patchwork.ozlabs.org/series/501412/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2228039/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228039/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Lc8b6f4o;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=KDKbLWUA;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g2WhN5v7Nz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 11:00:04 +1000 (AEST)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wGRNL-0000000DwdT-1F9K;\n\tSat, 25 Apr 2026 01:00:03 +0000","from tor.source.kernel.org ([172.105.4.254])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wGRNI-0000000Dwc3-3xGC;\n\tSat, 25 Apr 2026 01:00:02 +0000","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id 633A860052;\n\tSat, 25 Apr 2026 01:00:00 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 3A364C19425;\n\tSat, 25 Apr 2026 00:59:56 +0000 (UTC)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=zkprTv8RNgtgPl1Vwmm4yW451DiLgPlu21G/lFTlvMk=; b=Lc8b6f4oYSG9aM\n\tyfq7lMjY506P0juempPixEPao23fvlC2i4ndLN7xrtSyihOorT3fsndwvH/6jL/rn/q+kI3Tlveuf\n\twVhwrLqlBjAxovVtGFfNA4byOb+vAsBlCP1i8SrTmz/tl5GKeXmaBY4y5I0R/Pc4JlAgAwpXIpt0v\n\t8ilsL1vdV2/VJw2Yd0fZxmqpwTA/gxFFqBbtyicJynTL8/UZCF7q/nn8v+++61nGgjmEmJVgfVwGA\n\toaxnZe3vw0jfJhfqOrS1I1Zn7stA1MtLsWQKQjBRubxGUkx2h2uqg/Q7FS2GsrgWIg3mIe0RejhDe\n\tePgccWzPehVJ40IaAPHA==;","v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1777078800;\n\tbh=P/xWdbYp78TUgmPmZpbvCjaH6uZ1DZD8kPFRZWdzOHw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KDKbLWUAnL2XCg9gxeKEyc2mXC8E7299WLTINp8SuZiaodeEbDHdZ15OMfGvHI51r\n\t qAAfTAqehCQMylrcSdbrZaRwQ+ER1eT11KhMYuYKY8eYkKDxOiasQgi9gwGbpb3QCt\n\t qCFdHKsXzjTd+xcJCn/8TyRFJboFgvedtanFG6xOOVaLJpyJKfh5g9ywbxPm0SWI4Z\n\t yx/Hc24Y65Xe0c31BkGvvdqpneCpvSJwGPvB8PkvLET7SBsag/goxIZXVFOpSiebcz\n\t gC7W1WoqAHWMz5/QMUjv3qfJoEZmkEiugPU+q07GjlylR7C1FExQUSFm9Dycj43Ztd\n\t BHf4O00FBv8DA=="],"From":"guoren@kernel.org","To":"guoren@kernel.org","Cc":"alex@ghiti.fr,\n\tanup@brainfault.org,\n\taou@eecs.berkeley.edu,\n\tatish.patra@linux.dev,\n\tcp0613@linux.alibaba.com,\n\tfangyu.yu@linux.alibaba.com,\n\tgaohan@iscas.ac.cn,\n\tinochiama@gmail.com,\n\tkvm-riscv@lists.infradead.org,\n\tkvm@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tlinux-riscv@lists.infradead.org,\n\tme@ziyao.cc,\n\tpalmer@dabbelt.com,\n\tpjw@kernel.org,\n\ttglx@kernel.org","Subject":"[PATCH V2 4/4] RISC-V: KVM: AIA: Use per-HART IMSIC guest files to\n compute final HGEI count","Date":"Sat, 25 Apr 2026 00:59:16 +0000","Message-ID":"<20260425005916.3321811-5-guoren@kernel.org>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260425005916.3321811-1-guoren@kernel.org>","References":"<20260425005916.3321811-1-guoren@kernel.org>","MIME-Version":"1.0","X-BeenThere":"kvm-riscv@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"<kvm-riscv.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/kvm-riscv>,\n <mailto:kvm-riscv-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/kvm-riscv/>","List-Post":"<mailto:kvm-riscv@lists.infradead.org>","List-Help":"<mailto:kvm-riscv-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/kvm-riscv>,\n <mailto:kvm-riscv-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"kvm-riscv\" <kvm-riscv-bounces@lists.infradead.org>","Errors-To":"kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"From: \"Guo Ren (Alibaba DAMO Academy)\" <guoren@kernel.org>\n\nNow that `nr_guest_files` has been moved to `struct imsic_local_config`\nand is computed per-HART, KVM must respect the actual number of guest\ninterrupt files available on each HART when setting up HGEI.\n\nIn `kvm_riscv_aia_enable()`:\n\n - Retrieve the per-CPU IMSIC local config\n - Take `min(hgctrl->nr_hgei, lc->nr_guest_files)` as the final usable\n   HGEI count for this HART\n - Use the result to initialize `free_bitmap`\n\nThis ensures correct HGEI allocation on heterogeneous RISC-V SoCs\nwhere different cores may have different IMSIC guest file counts, and\ncompletes the per-HART conversion series.\n\nSigned-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>\n---\n arch/riscv/kvm/aia.c | 12 ++++++++++--\n 1 file changed, 10 insertions(+), 2 deletions(-)","diff":"diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c\nindex 70ff1d25dd99..a5f4b7fe1dce 100644\n--- a/arch/riscv/kvm/aia.c\n+++ b/arch/riscv/kvm/aia.c\n@@ -534,6 +534,9 @@ static void aia_hgei_exit(void)\n void kvm_riscv_aia_enable(void)\n {\n \tstruct aia_hgei_control *hgctrl;\n+\tconst struct imsic_global_config *gc;\n+\tconst struct imsic_local_config *lc;\n+\tunsigned int nr_hgei;\n \n \tif (!kvm_riscv_aia_available())\n \t\treturn;\n@@ -547,8 +550,13 @@ void kvm_riscv_aia_enable(void)\n \tif (hgctrl->nr_hgei)\n \t\thgctrl->nr_hgei--;\n \n-\tif (hgctrl->nr_hgei) {\n-\t\thgctrl->free_bitmap = BIT(hgctrl->nr_hgei + 1) - 1;\n+\tgc = imsic_get_global_config();\n+\tlc = (gc) ? this_cpu_ptr(gc->local) : NULL;\n+\tif (lc)\n+\t\tnr_hgei = min(hgctrl->nr_hgei, lc->nr_guest_files);\n+\n+\tif (nr_hgei) {\n+\t\thgctrl->free_bitmap = BIT(nr_hgei + 1) - 1;\n \t\thgctrl->free_bitmap &= ~BIT(0);\n \t} else {\n \t\thgctrl->free_bitmap = 0;\n","prefixes":["V2","4/4"]}