From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68D83346AE8 for ; Thu, 23 Apr 2026 04:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776918047; cv=none; b=RbkQ3xiWBkoP1GjUCgKJLtYK+RJJ6Ogmb5Lq8M3MnxT44UOs8x6hy194M5eqQjNoSAtvBsC8gYGuEVeAbfRNwsg5FPWwITeszZyUTlPwLRtDv1xuOVZ+fjHbr8DeWotrBssXpLtTdeaqHJi/zp2MyFN+OKiGoZbPT/LZvfTocSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776918047; c=relaxed/simple; bh=rQR/Gxa7esLwjh/1GhruJvDmkidRrkrPjdXuMifO1mY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ooc9CChyGFCBsEs2t/pFnNZZRZ5LJ0XN3QQQCwnv69Ano1u/0ZQzYdv12tz6SQbGDNDomtqpzmBLjdwhC0ldety4CLoQcfjZWWvYMOu468BP0/NMbh8IiDM49jr8h6cSlQtdWH2T+bJ7Phxv1Oxli3cbB/ZftibMp9HE8orqGQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sAb/1bXr; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sAb/1bXr" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-82f8cebc935so2706330b3a.0 for ; Wed, 22 Apr 2026 21:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776918045; x=1777522845; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=GfOCDFeuRY0gBaADLpxF7xAt7ukg8gVW7Q9qKSqhzCQ=; b=sAb/1bXrdacb61GJ47yLpcTkU+K6jwZ2hOm71OJScI2JFlX1VCXGGoV0gIeJuTqztp m1AHzuifEoegLxWPlTq/KI242eFpnGQUVf+XaYFxgHOqg5ktXjGPbbsmoDLkiSysv7FL U1pppRWbWSB9tyhL1XsGsYExb/DhQXW4OttZq86fUTmWzxcU/de/VuvfGctT89s8fxAO iMdjiIt8Xfru6MpWl5TgHI9CETWzFiVaxGdR49c8IJgWwKGrnh8d2htsKycKGIKA8u94 kWdN1Lci7Kin+fdBIaerc/9bZFE9MgFKN+6+8HHy5BTcT9fvU9LntQ1SUvqqEB03oova F4GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776918045; x=1777522845; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GfOCDFeuRY0gBaADLpxF7xAt7ukg8gVW7Q9qKSqhzCQ=; b=NZa5qQYDeITIWvs3ojnS4gpG9Fl5+MD6hwYfy23BxqgXkZhBJUj1gz1bGXbhFKBbBP XrkNALCV9tUwNMI8mKNrblyDgpzgRjnvTG/vw/htpbXulqmxtCx1oKjfNZ3eKh0CAyDN AeW3zooboj9+943wlS/WvNRSkgd78kILSI4hkJcn+QbuDI0B7atn7jUIXbWGMQXcVsh1 rrEi42U0PR1FzEzJTe1Gw6ZkiodNaBcNpMneCH3XV16Lilxn+k4gD8jWwAaJ3VuSjNx2 oCP4FUYfIIZNcPeYTRFEGbfbRTbE0Eg9Zf98h9PAuD/vIWy0d2Rnwo7LSwiaJvSuYSqz +zWQ== X-Forwarded-Encrypted: i=1; AFNElJ/9848X2Te9BvI+QC6bCIM5cnfmW+uKYppVE1Qx4dNesRrBEyBysfo5qKR7UJLQWgpRjv5BlVDmDPC9iDU=@vger.kernel.org X-Gm-Message-State: AOJu0YzITt49r49/MOFWu+W5jp4Lw0QGJGmRdLKrGDOsePvvVz2QOVBb i0uJG7UfQ+paQmfeVs8UfwykR99gVpAfiHNrFB4vCj16Bm1r5nq7mpjz X-Gm-Gg: AeBDievWyUzFhqS7Rindge3IbdXh8TSU2VdmKTV3QQhNB07uXIIFqjJGjz2CHaf5IVW NskfhblfqREHYqz6zBK1ICnc0ymawiP3wnPCkl5np/W9RJBT2X6VsFdS5PqdIOgfRPqvvsBjWWQ 64BPOoaO8X4OMDrjsi2lR9yUsvXQWfiYKweY2j4CHlKAz+YIKXe3UfymeX/Xwgd6lkRBwtlFPJN sY8eRBCTQxhIpvMey1ab2IG2MsRHTMb/Edks81uJBNCQwMF5FGT48YgnDMdvDVRPTIx25D55kFf z5mVhjxxuoW+5xeLI433K1gC5Y6ZOOryIxP0NqKljTNPUEM+zscShEIj0kpbly0DcR6WfhgRLU5 UP7+GI87dgjRTigWmpZOymkbm4bLCal2DHPesgTkc3Me6BzMgF93VCxFxovYoOuRPs35H78wgjk HFpafEnWLvyFrSELWXQ0rZSikWvB03a5/7ugC0V43IFU3Q X-Received: by 2002:a05:6a00:bb84:b0:81f:be3c:9c9e with SMTP id d2e1a72fcca58-82f8c8d67d0mr26456125b3a.33.1776918044598; Wed, 22 Apr 2026 21:20:44 -0700 (PDT) Received: from localhost ([2001:19f0:8001:1b2d:5400:5ff:fefa:a95d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebb3829sm19490565b3a.31.2026.04.22.21.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 21:20:43 -0700 (PDT) Date: Thu, 23 Apr 2026 12:20:26 +0800 From: Inochi Amaoto To: Guo Ren , fangyu.yu@linux.alibaba.com, cp0613@linux.alibaba.com, inochiama@gmail.com, me@ziyao.cc, gaohan@iscas.ac.cn, anup@brainfault.org, atish.patra@linux.dev, pjw@kernel.org, palmer@dabbelt.com, alex@ghiti.fr, tglx@kernel.org, Albert Ou Cc: kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH 3/3] irqchip/riscv-imsic: Remove global nr_guest_files after KVM AIA per-HART conversion Message-ID: References: <20260421145451.1597930-1-guoren@kernel.org> <20260421145451.1597930-4-guoren@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 22, 2026 at 11:09:30AM +0800, Guo Ren wrote: > Hi all, > > This patch simply removed `nr_guest_files`, which is suboptimal. For > v2, I will keep `nr_guest_files` inside `struct imsic_local_config` > (per-HART) and compute the effective HGEI count in > `kvm_riscv_aia_enable()` as: > > min(hgctrl->nr_hgei, lc->nr_guest_files) > > This provides a more accurate and robust per-HART configuration. > > Here are the updated two patches for your review: > > irqchip/riscv-imsic: Move nr_guest_files to per-HART local config > > With the recent KVM AIA per-HART HGEI conversion, the global > nr_guest_files is no longer appropriate. Different HARTs in > heterogeneous SoCs may have different numbers of guest interrupt > files. > > Move `nr_guest_files` from `struct imsic_global_config` to > `struct imsic_local_config`, and compute it per-CPU in > imsic_setup_state() based on the actual MMIO guest file region size. > > Update the related comment to reflect that KVM now uses the > per-HART value. > > This eliminates the last global assumption about guest files and > completes the per-HART conversion series for RISC-V AIA/IMSIC. > > Signed-off-by: Guo Ren (Alibaba DAMO Academy) > > diff --git a/drivers/irqchip/irq-riscv-imsic-state.c > b/drivers/irqchip/irq-riscv-imsic-state.c > index e3ed874d89e7..3d455ef43298 100644 > --- a/drivers/irqchip/irq-riscv-imsic-state.c > +++ b/drivers/irqchip/irq-riscv-imsic-state.c > @@ -784,7 +784,7 @@ static int __init imsic_parse_fwnode(struct > fwnode_handle *fwnode, > > int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) > { > - u32 i, j, index, nr_parent_irqs, nr_mmios, nr_guest_files, > nr_handlers = 0; > + u32 i, j, index, nr_parent_irqs, nr_mmios, nr_handlers = 0; > struct imsic_global_config *global; > struct imsic_local_config *local; > void __iomem **mmios_va = NULL; > @@ -878,7 +878,6 @@ int __init imsic_setup_state(struct fwnode_handle > *fwnode, void *opaque) > } > > /* Configure handlers for target CPUs */ > - global->nr_guest_files = BIT(global->guest_index_bits) - 1; > for (i = 0; i < nr_parent_irqs; i++) { > rc = imsic_get_parent_hartid(fwnode, i, &hartid); > if (rc) { > @@ -920,13 +919,13 @@ int __init imsic_setup_state(struct > fwnode_handle *fwnode, void *opaque) > local->msi_va = mmios_va[index] + reloff; > > /* > - * KVM uses global->nr_guest_files to determine the > available guest > + * KVM uses local->nr_guest_files to determine the > available guest > * interrupt files on each CPU. Take the minimum number of guest > * interrupt files across all CPUs to avoid KVM > incorrectly allocating > * an unexisted or unmapped guest interrupt file on some CPUs. > */ > - nr_guest_files = (resource_size(&mmios[index]) - > reloff) / IMSIC_MMIO_PAGE_SZ - 1; > - global->nr_guest_files = min(global->nr_guest_files, > nr_guest_files); > + local->nr_guest_files = > + (resource_size(&mmios[index]) - reloff) / > IMSIC_MMIO_PAGE_SZ - 1; > The min is still required, otherwise the local->nr_guest_files can be bigger than BIT(global->guest_index_bits) - 1, which is the max number of the guest interrupt files that a hart can have. This condition is true if the IMSIC group has more than one harts. Regards, Inochi > nr_handlers++; > } > diff --git a/include/linux/irqchip/riscv-imsic.h > b/include/linux/irqchip/riscv-imsic.h > index 4b348836de7a..13e8bd7ff4b4 100644 > --- a/include/linux/irqchip/riscv-imsic.h > +++ b/include/linux/irqchip/riscv-imsic.h > @@ -40,6 +40,9 @@ > struct imsic_local_config { > phys_addr_t msi_pa; > void __iomem *msi_va; > + > + /* Number of guest interrupt files per core */ > + u32 nr_guest_files; > }; > > struct imsic_global_config { > @@ -68,9 +71,6 @@ struct imsic_global_config { > /* Number of guest interrupt identities */ > u32 nr_guest_ids; > > - /* Number of guest interrupt files per core */ > - u32 nr_guest_files; > - > /* Per-CPU IMSIC addresses */ > struct imsic_local_config __percpu *local; > }; > > ------------------------ > The other one: > > RISC-V: KVM: AIA: Use per-HART IMSIC guest files to compute final HGEI count > > Now that `nr_guest_files` has been moved to `struct imsic_local_config` > and is computed per-HART, KVM must respect the actual number of guest > interrupt files available on each HART when setting up HGEI. > > In `kvm_riscv_aia_enable()`: > > - Retrieve the per-CPU IMSIC local config > - Take `min(hgctrl->nr_hgei, lc->nr_guest_files)` as the final usable > HGEI count for this HART > - Use the result to initialize `free_bitmap` > > This ensures correct HGEI allocation on heterogeneous RISC-V SoCs > where different cores may have different IMSIC guest file counts, and > completes the per-HART conversion series. > > Signed-off-by: Guo Ren (Alibaba DAMO Academy) > > diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c > index 70ff1d25dd99..a5f4b7fe1dce 100644 > --- a/arch/riscv/kvm/aia.c > +++ b/arch/riscv/kvm/aia.c > @@ -534,6 +534,9 @@ static void aia_hgei_exit(void) > void kvm_riscv_aia_enable(void) > { > struct aia_hgei_control *hgctrl; > + const struct imsic_global_config *gc; > + const struct imsic_local_config *lc; > + unsigned int nr_hgei; > > if (!kvm_riscv_aia_available()) > return; > @@ -547,8 +550,13 @@ void kvm_riscv_aia_enable(void) > if (hgctrl->nr_hgei) > hgctrl->nr_hgei--; > > - if (hgctrl->nr_hgei) { > - hgctrl->free_bitmap = BIT(hgctrl->nr_hgei + 1) - 1; > + gc = imsic_get_global_config(); > + lc = (gc) ? this_cpu_ptr(gc->local) : NULL; > + if (lc) > + nr_hgei = min(hgctrl->nr_hgei, lc->nr_guest_files); > + > + if (nr_hgei) { > + hgctrl->free_bitmap = BIT(nr_hgei + 1) - 1; > hgctrl->free_bitmap &= ~BIT(0); > } else { > hgctrl->free_bitmap = 0; > > > On Tue, Apr 21, 2026 at 10:55 PM wrote: > > > > From: "Guo Ren (Alibaba DAMO Academy)" > > > > With the recent KVM AIA changes, HGEI line management is now fully > > per-CPU (via struct aia_hgei_control::nr_hgei) and the global > > kvm_riscv_aia_nr_hgei has been replaced by a simple enabled flag. > > The IMSIC driver no longer needs to compute and enforce a global > > minimum number of guest interrupt files across all HARTs. > > > > Remove: > > - `u32 nr_guest_files` from `struct imsic_global_config` > > - the initial `BIT(global->guest_index_bits) - 1` assignment > > - the entire per-CPU MMIO-based min() calculation and its comment > > (which was specifically there to protect old KVM) > > > > The per-HART guest file count is already handled locally in > > `imsic_local_config` during the parent IRQ loop, so this global > > field was redundant. > > > > This completes the cleanup series, eliminates the last global > > assumption about guest files, and improves support for heterogeneous > > (big.LITTLE / multi-vendor) RISC-V platforms. > > > > Signed-off-by: Guo Ren (Alibaba DAMO Academy) > > --- > > drivers/irqchip/irq-riscv-imsic-state.c | 12 +----------- > > include/linux/irqchip/riscv-imsic.h | 3 --- > > 2 files changed, 1 insertion(+), 14 deletions(-) > > > > diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c > > index e3ed874d89e7..fef27247a34f 100644 > > --- a/drivers/irqchip/irq-riscv-imsic-state.c > > +++ b/drivers/irqchip/irq-riscv-imsic-state.c > > @@ -784,7 +784,7 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode, > > > > int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) > > { > > - u32 i, j, index, nr_parent_irqs, nr_mmios, nr_guest_files, nr_handlers = 0; > > + u32 i, j, index, nr_parent_irqs, nr_mmios, nr_handlers = 0; > > struct imsic_global_config *global; > > struct imsic_local_config *local; > > void __iomem **mmios_va = NULL; > > @@ -878,7 +878,6 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) > > } > > > > /* Configure handlers for target CPUs */ > > - global->nr_guest_files = BIT(global->guest_index_bits) - 1; > > for (i = 0; i < nr_parent_irqs; i++) { > > rc = imsic_get_parent_hartid(fwnode, i, &hartid); > > if (rc) { > > @@ -919,15 +918,6 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque) > > local->msi_pa = mmios[index].start + reloff; > > local->msi_va = mmios_va[index] + reloff; > > > > - /* > > - * KVM uses global->nr_guest_files to determine the available guest > > - * interrupt files on each CPU. Take the minimum number of guest > > - * interrupt files across all CPUs to avoid KVM incorrectly allocating > > - * an unexisted or unmapped guest interrupt file on some CPUs. > > - */ > > - nr_guest_files = (resource_size(&mmios[index]) - reloff) / IMSIC_MMIO_PAGE_SZ - 1; > > - global->nr_guest_files = min(global->nr_guest_files, nr_guest_files); > > - > > nr_handlers++; > > } > > > > diff --git a/include/linux/irqchip/riscv-imsic.h b/include/linux/irqchip/riscv-imsic.h > > index 4b348836de7a..7f3ff5c5ea53 100644 > > --- a/include/linux/irqchip/riscv-imsic.h > > +++ b/include/linux/irqchip/riscv-imsic.h > > @@ -68,9 +68,6 @@ struct imsic_global_config { > > /* Number of guest interrupt identities */ > > u32 nr_guest_ids; > > > > - /* Number of guest interrupt files per core */ > > - u32 nr_guest_files; > > - > > /* Per-CPU IMSIC addresses */ > > struct imsic_local_config __percpu *local; > > }; > > -- > > 2.40.1 > > > > > -- > Best Regards > Guo Ren > > -- > kvm-riscv mailing list > kvm-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kvm-riscv