Skip to content

Commit 538c06e

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add address alignment check in pch_pic register access
With pch_pic device, its register is based on MMIO address space, different access size 1/2/4/8 is supported. And base address should be naturally aligned with its access size, here add alignment check in its register access emulation function. Cc: [email protected] Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 0dfd9ea commit 538c06e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arch/loongarch/kvm/intc/pch_pic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ static int kvm_pch_pic_read(struct kvm_vcpu *vcpu,
195195
return -EINVAL;
196196
}
197197

198+
if (addr & (len - 1)) {
199+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
200+
return -EINVAL;
201+
}
202+
198203
/* statistics of pch pic reading */
199204
vcpu->stat.pch_pic_read_exits++;
200205
ret = loongarch_pch_pic_read(s, addr, len, val);
@@ -302,6 +307,11 @@ static int kvm_pch_pic_write(struct kvm_vcpu *vcpu,
302307
return -EINVAL;
303308
}
304309

310+
if (addr & (len - 1)) {
311+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
312+
return -EINVAL;
313+
}
314+
305315
/* statistics of pch pic writing */
306316
vcpu->stat.pch_pic_write_exits++;
307317
ret = loongarch_pch_pic_write(s, addr, len, val);

0 commit comments

Comments
 (0)