* [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation
@ 2025-06-27 9:05 Bibo Mao
2025-06-27 9:05 ` [PATCH v4 1/6] LoongArch: KVM: Fix interrupt route update with eiointc Bibo Mao
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
This series fix five issues about kernel eiointc emulation list as
follows:
1. The first patch fixes type forced assignment issue.
2. The second patch fixes interrupt route with physical cpu.
3. The third patch disables update property num_cpu and feature
4. The fourth patch adds validation check about num_cpu from user
space.
5. Overflow with array index when emulate register EIOINTC_ENABLE
writing operation.
6. The sixth patch adds address alignment check
---
v3 ... v4:
1. Remove patch about enhancement and only keep bugfix relative
patches.
2. Remove INTC indication in the patch title.
3. With access size, keep default case unchanged besides 1/2/4/8 since
here all patches are bugfix
4. Firstly check return value of copy_from_user() with error path,
keep the same order with old patch in patch 4.
v2 ... v3:
1. Add prefix INTC: in title of every patch.
2. Fix array index overflow when emulate register EIOINTC_ENABLE
writing operation.
3. Add address alignment check with eiointc register access operation.
v1 ... v2:
1. Add extra fix in patch 3 and patch 4, add num_cpu validation check
2. Name of stat information keeps unchanged, only move it from VM stat
to vCPU stat.
---
Bibo Mao (6):
LoongArch: KVM: Fix interrupt route update with eiointc
LoongArch: KVM: Check interrupt route from physical cpu
LoongArch: KVM: Disable update property num_cpu and feature
LoongArch: KVM: Check validation of num_cpu from user space
LoongArch: KVM: Avoid overflow with array index
LoongArch: KVM: Add address alignment check
arch/loongarch/kvm/intc/eiointc.c | 96 ++++++++++++++++++++++---------
1 file changed, 68 insertions(+), 28 deletions(-)
base-commit: f02769e7f272d6f42b9767f066c5a99afd2338f3
--
2.39.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 1/6] LoongArch: KVM: Fix interrupt route update with eiointc
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
2025-06-27 9:05 ` [PATCH v4 2/6] LoongArch: KVM: Check interrupt route from physical cpu Bibo Mao
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
With function eiointc_update_sw_coremap(), there is forced assignment
like val = *(u64 *)pvalue. Parameter pvalue may be pointer to char type
or others, there is problem with forced assignment with u64 type.
Here the detailed value is passed rather address pointer.
Cc: stable@vger.kernel.org
Fixes: 3956a52bc05b ("LoongArch: KVM: Add EIOINTC read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index f39929d7bf8a..d2c521b0e923 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -66,10 +66,9 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
}
static inline void eiointc_update_sw_coremap(struct loongarch_eiointc *s,
- int irq, void *pvalue, u32 len, bool notify)
+ int irq, u64 val, u32 len, bool notify)
{
int i, cpu;
- u64 val = *(u64 *)pvalue;
for (i = 0; i < len; i++) {
cpu = val & 0xff;
@@ -398,7 +397,7 @@ static int loongarch_eiointc_writeb(struct kvm_vcpu *vcpu,
irq = offset - EIOINTC_COREMAP_START;
index = irq;
s->coremap.reg_u8[index] = data;
- eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
+ eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
break;
default:
ret = -EINVAL;
@@ -484,7 +483,7 @@ static int loongarch_eiointc_writew(struct kvm_vcpu *vcpu,
irq = offset - EIOINTC_COREMAP_START;
index = irq >> 1;
s->coremap.reg_u16[index] = data;
- eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
+ eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
break;
default:
ret = -EINVAL;
@@ -570,7 +569,7 @@ static int loongarch_eiointc_writel(struct kvm_vcpu *vcpu,
irq = offset - EIOINTC_COREMAP_START;
index = irq >> 2;
s->coremap.reg_u32[index] = data;
- eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
+ eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
break;
default:
ret = -EINVAL;
@@ -656,7 +655,7 @@ static int loongarch_eiointc_writeq(struct kvm_vcpu *vcpu,
irq = offset - EIOINTC_COREMAP_START;
index = irq >> 3;
s->coremap.reg_u64[index] = data;
- eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
+ eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
break;
default:
ret = -EINVAL;
@@ -809,7 +808,7 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
for (i = 0; i < (EIOINTC_IRQS / 4); i++) {
start_irq = i * 4;
eiointc_update_sw_coremap(s, start_irq,
- (void *)&s->coremap.reg_u32[i], sizeof(u32), false);
+ s->coremap.reg_u32[i], sizeof(u32), false);
}
break;
default:
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 2/6] LoongArch: KVM: Check interrupt route from physical cpu
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
2025-06-27 9:05 ` [PATCH v4 1/6] LoongArch: KVM: Fix interrupt route update with eiointc Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
2025-06-27 9:05 ` [PATCH v4 3/6] LoongArch: KVM: Disable update property num_cpu and feature Bibo Mao
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
With eiointc interrupt controller, physical cpu id is set for irq
route. However function kvm_get_vcpu() is used to get destination vCPU
when delivering irq. With API kvm_get_vcpu(), logical cpu is used.
With API kvm_get_vcpu_by_cpuid(), vCPU can be searched from physical
cpu id.
Cc: stable@vger.kernel.org
Fixes: 3956a52bc05b ("LoongArch: KVM: Add EIOINTC read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index d2c521b0e923..0b648c56b0c3 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -9,7 +9,8 @@
static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
{
- int ipnum, cpu, irq_index, irq_mask, irq;
+ int ipnum, cpu, irq_index, irq_mask, irq, cpuid;
+ struct kvm_vcpu *vcpu;
for (irq = 0; irq < EIOINTC_IRQS; irq++) {
ipnum = s->ipmap.reg_u8[irq / 32];
@@ -20,7 +21,12 @@ static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
irq_index = irq / 32;
irq_mask = BIT(irq & 0x1f);
- cpu = s->coremap.reg_u8[irq];
+ cpuid = s->coremap.reg_u8[irq];
+ vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
+ if (vcpu == NULL)
+ continue;
+
+ cpu = vcpu->vcpu_id;
if (!!(s->coreisr.reg_u32[cpu][irq_index] & irq_mask))
set_bit(irq, s->sw_coreisr[cpu][ipnum]);
else
@@ -68,17 +74,23 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
static inline void eiointc_update_sw_coremap(struct loongarch_eiointc *s,
int irq, u64 val, u32 len, bool notify)
{
- int i, cpu;
+ int i, cpu, cpuid;
+ struct kvm_vcpu *vcpu;
for (i = 0; i < len; i++) {
- cpu = val & 0xff;
+ cpuid = val & 0xff;
val = val >> 8;
if (!(s->status & BIT(EIOINTC_ENABLE_CPU_ENCODE))) {
- cpu = ffs(cpu) - 1;
- cpu = (cpu >= 4) ? 0 : cpu;
+ cpuid = ffs(cpuid) - 1;
+ cpuid = (cpuid >= 4) ? 0 : cpuid;
}
+ vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
+ if (vcpu == NULL)
+ continue;
+
+ cpu = vcpu->vcpu_id;
if (s->sw_coremap[irq + i] == cpu)
continue;
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 3/6] LoongArch: KVM: Disable update property num_cpu and feature
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
2025-06-27 9:05 ` [PATCH v4 1/6] LoongArch: KVM: Fix interrupt route update with eiointc Bibo Mao
2025-06-27 9:05 ` [PATCH v4 2/6] LoongArch: KVM: Check interrupt route from physical cpu Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
2025-06-27 9:05 ` [PATCH v4 4/6] LoongArch: KVM: Check validation of num_cpu from user space Bibo Mao
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
Property num_cpu and feature is read-only once eiointc is created, which
is set with KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL attr group before device
creation.
Attr group KVM_DEV_LOONGARCH_EXTIOI_GRP_SW_STATUS is to update register
and software state for migration and reset usage, property num_cpu and
feature can not be update again if it is created already.
Here discard write operation with property num_cpu and feature in attr
group KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL.
Cc: stable@vger.kernel.org
Fixes: 1ad7efa552fd ("LoongArch: KVM: Add EIOINTC user mode read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index 0b648c56b0c3..b48511f903b5 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -910,9 +910,22 @@ static int kvm_eiointc_sw_status_access(struct kvm_device *dev,
data = (void __user *)attr->addr;
switch (addr) {
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_NUM_CPU:
+ /*
+ * Property num_cpu and feature is read-only once eiointc is
+ * created with KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL group API
+ *
+ * Disable writing with KVM_DEV_LOONGARCH_EXTIOI_GRP_SW_STATUS
+ * group API
+ */
+ if (is_write)
+ return ret;
+
p = &s->num_cpu;
break;
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_FEATURE:
+ if (is_write)
+ return ret;
+
p = &s->features;
break;
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_STATE:
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 4/6] LoongArch: KVM: Check validation of num_cpu from user space
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
` (2 preceding siblings ...)
2025-06-27 9:05 ` [PATCH v4 3/6] LoongArch: KVM: Disable update property num_cpu and feature Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
2025-06-27 9:05 ` [PATCH v4 5/6] LoongArch: KVM: Avoid overflow with array index Bibo Mao
2025-06-27 9:05 ` [PATCH v4 6/6] LoongArch: KVM: Add address alignment check Bibo Mao
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
The maximum supported cpu number is EIOINTC_ROUTE_MAX_VCPUS about
irqchip eiointc, here add validation about cpu number to avoid array
pointer overflow.
Cc: stable@vger.kernel.org
Fixes: 1ad7efa552fd ("LoongArch: KVM: Add EIOINTC user mode read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index b48511f903b5..169fe1de2c92 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -798,7 +798,7 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
int ret = 0;
unsigned long flags;
unsigned long type = (unsigned long)attr->attr;
- u32 i, start_irq;
+ u32 i, start_irq, val;
void __user *data;
struct loongarch_eiointc *s = dev->kvm->arch.eiointc;
@@ -806,8 +806,14 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
spin_lock_irqsave(&s->lock, flags);
switch (type) {
case KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_NUM_CPU:
- if (copy_from_user(&s->num_cpu, data, 4))
+ if (copy_from_user(&val, data, 4))
ret = -EFAULT;
+ else {
+ if (val < EIOINTC_ROUTE_MAX_VCPUS)
+ s->num_cpu = val;
+ else
+ ret = -EINVAL;
+ }
break;
case KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_FEATURE:
if (copy_from_user(&s->features, data, 4))
@@ -835,7 +841,7 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
struct kvm_device_attr *attr,
bool is_write)
{
- int addr, cpuid, offset, ret = 0;
+ int addr, cpu, offset, ret = 0;
unsigned long flags;
void *p = NULL;
void __user *data;
@@ -843,7 +849,7 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
s = dev->kvm->arch.eiointc;
addr = attr->attr;
- cpuid = addr >> 16;
+ cpu = addr >> 16;
addr &= 0xffff;
data = (void __user *)attr->addr;
switch (addr) {
@@ -868,8 +874,11 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
p = &s->isr.reg_u32[offset];
break;
case EIOINTC_COREISR_START ... EIOINTC_COREISR_END:
+ if (cpu >= s->num_cpu)
+ return -EINVAL;
+
offset = (addr - EIOINTC_COREISR_START) / 4;
- p = &s->coreisr.reg_u32[cpuid][offset];
+ p = &s->coreisr.reg_u32[cpu][offset];
break;
case EIOINTC_COREMAP_START ... EIOINTC_COREMAP_END:
offset = (addr - EIOINTC_COREMAP_START) / 4;
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 5/6] LoongArch: KVM: Avoid overflow with array index
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
` (3 preceding siblings ...)
2025-06-27 9:05 ` [PATCH v4 4/6] LoongArch: KVM: Check validation of num_cpu from user space Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
2025-06-27 9:05 ` [PATCH v4 6/6] LoongArch: KVM: Add address alignment check Bibo Mao
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
Variable index is modified and reused as array index when modify
register EIOINTC_ENABLE. There will be array index overflow problem.
Cc: stable@vger.kernel.org
Fixes: 3956a52bc05b ("LoongArch: KVM: Add EIOINTC read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index 169fe1de2c92..d54fe805bf6e 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -447,17 +447,16 @@ static int loongarch_eiointc_writew(struct kvm_vcpu *vcpu,
break;
case EIOINTC_ENABLE_START ... EIOINTC_ENABLE_END:
index = (offset - EIOINTC_ENABLE_START) >> 1;
- old_data = s->enable.reg_u32[index];
+ old_data = s->enable.reg_u16[index];
s->enable.reg_u16[index] = data;
/*
* 1: enable irq.
* update irq when isr is set.
*/
data = s->enable.reg_u16[index] & ~old_data & s->isr.reg_u16[index];
- index = index << 1;
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index + i, mask, 1);
+ eiointc_enable_irq(vcpu, s, index * 2 + i, mask, 1);
}
/*
* 0: disable irq.
@@ -466,7 +465,7 @@ static int loongarch_eiointc_writew(struct kvm_vcpu *vcpu,
data = ~s->enable.reg_u16[index] & old_data & s->isr.reg_u16[index];
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index, mask, 0);
+ eiointc_enable_irq(vcpu, s, index * 2 + i, mask, 0);
}
break;
case EIOINTC_BOUNCE_START ... EIOINTC_BOUNCE_END:
@@ -540,10 +539,9 @@ static int loongarch_eiointc_writel(struct kvm_vcpu *vcpu,
* update irq when isr is set.
*/
data = s->enable.reg_u32[index] & ~old_data & s->isr.reg_u32[index];
- index = index << 2;
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index + i, mask, 1);
+ eiointc_enable_irq(vcpu, s, index * 4 + i, mask, 1);
}
/*
* 0: disable irq.
@@ -552,7 +550,7 @@ static int loongarch_eiointc_writel(struct kvm_vcpu *vcpu,
data = ~s->enable.reg_u32[index] & old_data & s->isr.reg_u32[index];
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index, mask, 0);
+ eiointc_enable_irq(vcpu, s, index * 4 + i, mask, 0);
}
break;
case EIOINTC_BOUNCE_START ... EIOINTC_BOUNCE_END:
@@ -626,10 +624,9 @@ static int loongarch_eiointc_writeq(struct kvm_vcpu *vcpu,
* update irq when isr is set.
*/
data = s->enable.reg_u64[index] & ~old_data & s->isr.reg_u64[index];
- index = index << 3;
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index + i, mask, 1);
+ eiointc_enable_irq(vcpu, s, index * 8 + i, mask, 1);
}
/*
* 0: disable irq.
@@ -638,7 +635,7 @@ static int loongarch_eiointc_writeq(struct kvm_vcpu *vcpu,
data = ~s->enable.reg_u64[index] & old_data & s->isr.reg_u64[index];
for (i = 0; i < sizeof(data); i++) {
u8 mask = (data >> (i * 8)) & 0xff;
- eiointc_enable_irq(vcpu, s, index, mask, 0);
+ eiointc_enable_irq(vcpu, s, index * 8 + i, mask, 0);
}
break;
case EIOINTC_BOUNCE_START ... EIOINTC_BOUNCE_END:
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 6/6] LoongArch: KVM: Add address alignment check
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
` (4 preceding siblings ...)
2025-06-27 9:05 ` [PATCH v4 5/6] LoongArch: KVM: Avoid overflow with array index Bibo Mao
@ 2025-06-27 9:05 ` Bibo Mao
5 siblings, 0 replies; 7+ messages in thread
From: Bibo Mao @ 2025-06-27 9:05 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li
Cc: kvm, loongarch, linux-kernel, stable
IOCSR instruction supports 1/2/4/8 bytes access, the address should
be naturally aligned with its access size. Here address alignment
checking is added in eiointc kernel emulation.
Cc: stable@vger.kernel.org
Fixes: 3956a52bc05b ("LoongArch: KVM: Add EIOINTC read and write functions")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/eiointc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c
index d54fe805bf6e..fab5cf52779c 100644
--- a/arch/loongarch/kvm/intc/eiointc.c
+++ b/arch/loongarch/kvm/intc/eiointc.c
@@ -316,6 +316,11 @@ static int kvm_eiointc_read(struct kvm_vcpu *vcpu,
return -EINVAL;
}
+ if (addr & (len - 1)) {
+ kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
+ return -EINVAL;
+ }
+
vcpu->kvm->stat.eiointc_read_exits++;
spin_lock_irqsave(&eiointc->lock, flags);
switch (len) {
@@ -687,6 +692,11 @@ static int kvm_eiointc_write(struct kvm_vcpu *vcpu,
return -EINVAL;
}
+ if (addr & (len - 1)) {
+ kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
+ return -EINVAL;
+ }
+
vcpu->kvm->stat.eiointc_write_exits++;
spin_lock_irqsave(&eiointc->lock, flags);
switch (len) {
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-27 9:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 9:05 [PATCH v4 0/6] LoongArch: KVM: Fixes with eiointc emulation Bibo Mao
2025-06-27 9:05 ` [PATCH v4 1/6] LoongArch: KVM: Fix interrupt route update with eiointc Bibo Mao
2025-06-27 9:05 ` [PATCH v4 2/6] LoongArch: KVM: Check interrupt route from physical cpu Bibo Mao
2025-06-27 9:05 ` [PATCH v4 3/6] LoongArch: KVM: Disable update property num_cpu and feature Bibo Mao
2025-06-27 9:05 ` [PATCH v4 4/6] LoongArch: KVM: Check validation of num_cpu from user space Bibo Mao
2025-06-27 9:05 ` [PATCH v4 5/6] LoongArch: KVM: Avoid overflow with array index Bibo Mao
2025-06-27 9:05 ` [PATCH v4 6/6] LoongArch: KVM: Add address alignment check Bibo Mao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).