Skip to content

Commit 9159c5e

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add address alignment check for IOCSR emulation
IOCSR instruction supports 1/2/4/8 bytes access, the address should be naturally aligned with its access size. Here address alignment check is added in the EIOINTC kernel emulation. Cc: [email protected] Fixes: 3956a52 ("LoongArch: KVM: Add EIOINTC read and write functions") Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 080e8d2 commit 9159c5e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ static int kvm_eiointc_read(struct kvm_vcpu *vcpu,
305305
return -EINVAL;
306306
}
307307

308+
if (addr & (len - 1)) {
309+
kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
310+
return -EINVAL;
311+
}
312+
308313
vcpu->kvm->stat.eiointc_read_exits++;
309314
spin_lock_irqsave(&eiointc->lock, flags);
310315
switch (len) {
@@ -676,6 +681,11 @@ static int kvm_eiointc_write(struct kvm_vcpu *vcpu,
676681
return -EINVAL;
677682
}
678683

684+
if (addr & (len - 1)) {
685+
kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
686+
return -EINVAL;
687+
}
688+
679689
vcpu->kvm->stat.eiointc_write_exits++;
680690
spin_lock_irqsave(&eiointc->lock, flags);
681691
switch (len) {

0 commit comments

Comments
 (0)