[PATCH v5 2/5] LoongArch: KVM: Return directly when IPI address is not aligned
From: Bibo Mao
Date: Tue Jul 14 2026 - 03:38:48 EST
When IPI address is not aligned with its access size, it should return
directly in read/write operations, rather than only print WARN_ON_ONCE().
The method is the same with in kernel extioi and pch_pic operations.
Signed-off-by: Bibo Mao <maobibo@xxxxxxxxxxx>
---
arch/loongarch/kvm/intc/ipi.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/arch/loongarch/kvm/intc/ipi.c b/arch/loongarch/kvm/intc/ipi.c
index 4fa0897d7bdb..928f9bd5e1f1 100644
--- a/arch/loongarch/kvm/intc/ipi.c
+++ b/arch/loongarch/kvm/intc/ipi.c
@@ -186,9 +186,13 @@ static int loongarch_ipi_readl(struct kvm_vcpu *vcpu, gpa_t addr, int len, void
uint32_t offset;
uint64_t res = 0;
- offset = (uint32_t)(addr & 0x1ff);
- WARN_ON_ONCE(offset & (len - 1));
+ if (addr & (len - 1)) {
+ *(uint64_t *)val = res;
+ kvm_pr_unimpl("%s: ipi not aligned addr %llx len %d\n", __func__, addr, len);
+ return 0;
+ }
+ offset = addr - IOCSR_IPI_BASE;
switch (offset) {
case IOCSR_IPI_STATUS:
spin_lock(&vcpu->arch.ipi_state.lock);
@@ -204,11 +208,6 @@ static int loongarch_ipi_readl(struct kvm_vcpu *vcpu, gpa_t addr, int len, void
case IOCSR_IPI_CLEAR:
break;
case IOCSR_IPI_BUF_20 ... IOCSR_IPI_BUF_38 + 7:
- if (offset + len > IOCSR_IPI_BUF_38 + 8) {
- kvm_err("%s: invalid offset or len: offset = %d, len = %d\n",
- __func__, offset, len);
- break;
- }
res = read_mailbox(vcpu, offset, len);
break;
default:
@@ -227,9 +226,12 @@ static int loongarch_ipi_writel(struct kvm_vcpu *vcpu, gpa_t addr, int len, cons
data = *(uint64_t *)val;
- offset = (uint32_t)(addr & 0x1ff);
- WARN_ON_ONCE(offset & (len - 1));
+ if (addr & (len - 1)) {
+ kvm_pr_unimpl("%s: ipi not aligned addr %llx len %d\n", __func__, addr, len);
+ return 0;
+ }
+ offset = addr - IOCSR_IPI_BASE;
switch (offset) {
case IOCSR_IPI_STATUS:
break;
--
2.39.3