{"id":2228038,"url":"http://patchwork.ozlabs.org/api/patches/2228038/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-riscv/patch/20260425005916.3321811-4-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-4-guoren@kernel.org>","list_archive_url":null,"date":"2026-04-25T00:59:15","name":"[V2,3/4] irqchip/riscv-imsic: Move nr_guest_files to per-HART local config","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"3887f2ff92a1c0c2964e069166cb582e7f86d002","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-4-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/2228038/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228038/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=zPn3q8pG;\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=iVR8FtSh;\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 4g2WhJ1nHFz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 11:00:00 +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 1wGRNG-0000000DwaK-30wS;\n\tSat, 25 Apr 2026 00:59:58 +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 1wGRNF-0000000Dwa2-0tMA;\n\tSat, 25 Apr 2026 00:59:57 +0000","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id 0754160052;\n\tSat, 25 Apr 2026 00:59:56 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id D4BAAC2BCB5;\n\tSat, 25 Apr 2026 00:59:51 +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=BM83aGde6TLW1QcQGlf5nmou4GYCkX+908GCofMbR8k=; b=zPn3q8pGkzv2Em\n\tbKL3+VPLhszrg20lnaL/TJ1q4P5KWjW0L+0ZEroKVswXBl89LIyz+BNmQtzS1d/rw2uBMS275E2VR\n\t1zqmsa+pkOE3W3xpSsICc38dEwxdkiB8DHw8Bw22/Ljlpa30RfdBO20Zeqp16YaHmrXehpct7cKVk\n\t5J8OI7FQyQTnT+QSexLFcddXPKIv/hce2BPTjxt/hU7PsLGAQGXvfrSX5qRkDU44ofohx+Lu0T3x8\n\t/yEkXtM4H7KiwVqgnMI/KRsooY3i057hlPM/O2BzrzRNWcX+op8WxHAO0yREGkIoisltpmMbgIxCP\n\teUKEmAeqJB6NCMpU2f5A==;","v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1777078795;\n\tbh=7uQ0gjeqEPD6nPlkRBOxKlYHRuy/F0gDZ8rMmS8aYzE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=iVR8FtShNzdaxPaI5u0kaR0SDRKtyeuyA0azvOPHDlNXRRDcCYZ1WMk4SzB4nuyN2\n\t ScIpNayyJLSYkFEXP0qIBwGRCGQ9Yufhp7UBtIzYj7wg2PFsLM7N84fRIA9MaIp7sz\n\t mxHKuswu/FhIDWcGI8fTfF2cACfGiCOd/e/nxbSMNWWhitRTRX5UVPoJzWDo3N+dZX\n\t SJB2sjmMlGggVJE1HRZtx41I/j3Cno1cGW4aCwxLQkSJf1uaIOd7RcaDlbPLFtb2am\n\t 6V5TXLmroYqxvjDheBh7EN03+Zelu15yyfHmSUL00bBUecK/8lp07xUb4lxU/EhqnD\n\t caINHRMDPIQAQ=="],"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 3/4] irqchip/riscv-imsic: Move nr_guest_files to per-HART\n local config","Date":"Sat, 25 Apr 2026 00:59:15 +0000","Message-ID":"<20260425005916.3321811-4-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\nWith the recent KVM AIA per-HART HGEI conversion, the global\nnr_guest_files is no longer appropriate. Different HARTs in\nheterogeneous SoCs may have different numbers of guest interrupt\nfiles.\n\nMove `nr_guest_files` from `struct imsic_global_config` to\n`struct imsic_local_config`, and compute it per-CPU in\nimsic_setup_state() based on the actual MMIO guest file region size.\n\nUpdate the related comment to reflect that KVM now uses the\nper-HART value.\n\nThis eliminates the last global assumption about guest files and\ncompletes the per-HART conversion series for RISC-V AIA/IMSIC.\n\nSigned-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>\n---\n drivers/irqchip/irq-riscv-imsic-state.c | 10 ++++++----\n include/linux/irqchip/riscv-imsic.h     |  6 +++---\n 2 files changed, 9 insertions(+), 7 deletions(-)","diff":"diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c\nindex e3ed874d89e7..f01525362cf7 100644\n--- a/drivers/irqchip/irq-riscv-imsic-state.c\n+++ b/drivers/irqchip/irq-riscv-imsic-state.c\n@@ -878,7 +878,6 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)\n \t}\n \n \t/* Configure handlers for target CPUs */\n-\tglobal->nr_guest_files = BIT(global->guest_index_bits) - 1;\n \tfor (i = 0; i < nr_parent_irqs; i++) {\n \t\trc = imsic_get_parent_hartid(fwnode, i, &hartid);\n \t\tif (rc) {\n@@ -910,23 +909,26 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)\n \t\t\treloff -= ALIGN(resource_size(&mmios[j]),\n \t\t\tBIT(global->guest_index_bits) * IMSIC_MMIO_PAGE_SZ);\n \t\t}\n+\n+\t\tlocal = per_cpu_ptr(global->local, cpu);\n+\t\tlocal->nr_guest_files = BIT(global->guest_index_bits) - 1;\n+\n \t\tif (index >= nr_mmios) {\n \t\t\tpr_warn(\"%pfwP: MMIO not found for parent irq%d\\n\", fwnode, i);\n \t\t\tcontinue;\n \t\t}\n \n-\t\tlocal = per_cpu_ptr(global->local, cpu);\n \t\tlocal->msi_pa = mmios[index].start + reloff;\n \t\tlocal->msi_va = mmios_va[index] + reloff;\n \n \t\t/*\n-\t\t * KVM uses global->nr_guest_files to determine the available guest\n+\t\t * KVM uses local->nr_guest_files to determine the available guest\n \t\t * interrupt files on each CPU. Take the minimum number of guest\n \t\t * interrupt files across all CPUs to avoid KVM incorrectly allocating\n \t\t * an unexisted or unmapped guest interrupt file on some CPUs.\n \t\t */\n \t\tnr_guest_files = (resource_size(&mmios[index]) - reloff) / IMSIC_MMIO_PAGE_SZ - 1;\n-\t\tglobal->nr_guest_files = min(global->nr_guest_files, nr_guest_files);\n+\t\tlocal->nr_guest_files = min(local->nr_guest_files, nr_guest_files);\n \n \t\tnr_handlers++;\n \t}\ndiff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h\nindex 4b348836de7a..13e8bd7ff4b4 100644\n--- a/include/linux/irqchip/riscv-imsic.h\n+++ b/include/linux/irqchip/riscv-imsic.h\n@@ -40,6 +40,9 @@\n struct imsic_local_config {\n \tphys_addr_t\t\t\t\tmsi_pa;\n \tvoid __iomem\t\t\t\t*msi_va;\n+\n+\t/* Number of guest interrupt files per core */\n+\tu32\t\t\t\t\tnr_guest_files;\n };\n \n struct imsic_global_config {\n@@ -68,9 +71,6 @@ struct imsic_global_config {\n \t/* Number of guest interrupt identities */\n \tu32\t\t\t\t\tnr_guest_ids;\n \n-\t/* Number of guest interrupt files per core */\n-\tu32\t\t\t\t\tnr_guest_files;\n-\n \t/* Per-CPU IMSIC addresses */\n \tstruct imsic_local_config __percpu\t*local;\n };\n","prefixes":["V2","3/4"]}