From: Tao Cui <cui.tao@linux.dev>
To: zhaotianrui@loongson.cn, maobibo@loongson.cn, chenhuacai@kernel.org
Cc: kernel@xen0n.name, lixianglai@loongson.cn, kvm@vger.kernel.org,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH 2/2] LoongArch: KVM: EIOINTC: factor IP-number decode into a helper
Date: Tue, 14 Jul 2026 09:24:52 +0800 [thread overview]
Message-ID: <20260714012452.1021833-3-cui.tao@linux.dev> (raw)
In-Reply-To: <20260714012452.1021833-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
The ipmap IP-number decode is duplicated in eiointc_set_sw_coreisr() and
eiointc_update_irq(). Factor it into eiointc_get_ipnum().
No functional change.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index 0c34d7ab264d..c1e0cd8dca16 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -7,19 +7,27 @@
#include <asm/kvm_vcpu.h>
#include <linux/count_zeros.h>
+static int eiointc_get_ipnum(struct loongarch_eiointc *s, int irq)
+{
+ int ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff;
+
+ if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) {
+ ipnum = count_trailing_zeros(ipnum);
+ ipnum = ipnum < 4 ? ipnum : 0;
+ } else {
+ ipnum = (ipnum < LOONGSON_IP_NUM) ? ipnum : 0;
+ }
+
+ return ipnum;
+}
+
static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
{
int ipnum, cpu, cpuid, irq;
struct kvm_vcpu *vcpu;
for (irq = 0; irq < EIOINTC_IRQS; irq++) {
- ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff;
- if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) {
- ipnum = count_trailing_zeros(ipnum);
- ipnum = ipnum < 4 ? ipnum : 0;
- } else {
- ipnum = (ipnum < LOONGSON_IP_NUM) ? ipnum : 0;
- }
+ ipnum = eiointc_get_ipnum(s, irq);
cpuid = ((u8 *)s->coremap)[irq];
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
@@ -40,13 +48,7 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
struct kvm_vcpu *vcpu;
struct kvm_interrupt vcpu_irq;
- ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff;
- if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) {
- ipnum = count_trailing_zeros(ipnum);
- ipnum = ipnum < 4 ? ipnum : 0;
- } else {
- ipnum = (ipnum < LOONGSON_IP_NUM) ? ipnum : 0;
- }
+ ipnum = eiointc_get_ipnum(s, irq);
cpu = s->sw_coremap[irq];
vcpu = kvm_get_vcpu_by_id(s->kvm, cpu);
--
2.43.0
next prev parent reply other threads:[~2026-07-14 1:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 1:24 [PATCH 0/2] LoongArch: KVM: EIOINTC: fix INT_ENCODE ipnum out-of-bounds access Tao Cui
2026-07-14 1:24 ` [PATCH 1/2] LoongArch: KVM: EIOINTC: clamp ipnum to valid range in INT_ENCODE mode Tao Cui
2026-07-14 1:39 ` sashiko-bot
2026-07-14 2:32 ` Bibo Mao
2026-07-14 3:19 ` Tao Cui
2026-07-14 1:24 ` Tao Cui [this message]
2026-07-14 1:37 ` [PATCH 2/2] LoongArch: KVM: EIOINTC: factor IP-number decode into a helper sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260714012452.1021833-3-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=cuitao@kylinos.cn \
--cc=kernel@xen0n.name \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixianglai@loongson.cn \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=stable@vger.kernel.org \
--cc=zhaotianrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.