[RFC PATCH 12/12] arm64: [HACK] Check that out-of-range SVE register IDs can't be dumped

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As a sanity-check that invalid SVE register IDs can't be accessed
via KVM_GET_ONE_REG, this patch adds code to attempt to do just
that (at the expense of making dumping even slower).

Because of the way the register IDs are encoded, out-of-range slice
IDs may still result in a valid register encoding, so there is
nothing to test for that case.

Signed-off-by: Dave Martin <Dave.Martin@xxxxxxx>
---
 arm/aarch64/kvm-cpu.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c
index 28c5010..6b1580c 100644
--- a/arm/aarch64/kvm-cpu.c
+++ b/arm/aarch64/kvm-cpu.c
@@ -247,7 +247,7 @@ static void show_sve_zn_slice(int debug_fd, struct kvm_cpu const *vcpu,
 	sappendf(&strp, &strsz, " Z%.2u/%.2u:", n, i);
 	if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, &reg) < 0) {
 		dprintf(debug_fd, "%s(%s)\n", str, strerror(errno));
-		if (vcpu->kvm->cfg.arch.has_sve)
+		if (n < 32 && vcpu->kvm->cfg.arch.has_sve)
 			die("Z-reg unexpectedly absent on SVE vcpu");
 
 		return;
@@ -256,6 +256,9 @@ static void show_sve_zn_slice(int debug_fd, struct kvm_cpu const *vcpu,
 	if (!vcpu->kvm->cfg.arch.has_sve)
 		die("Z-reg unexpectedly present on non-SVE vcpu");
 
+	if (n >= 32)
+		die("Out-of-range Z-reg unexpectedly present");
+
 	sappend_bytes(&strp, &strsz, bytes, sizeof bytes);
 	dprintf(debug_fd, "%s\n", str);
 }
@@ -292,7 +295,7 @@ static void show_sve_pn_slice(int debug_fd, struct kvm_cpu const *vcpu,
 
 	if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, &reg) < 0) {
 		dprintf(debug_fd, "%s(%s)\n", str, strerror(errno));
-		if (vcpu->kvm->cfg.arch.has_sve)
+		if (n < 16 + 1 /* FFR */ && vcpu->kvm->cfg.arch.has_sve)
 			die("P-reg unexpectedly absent on SVE vcpu");
 
 		return;
@@ -301,6 +304,9 @@ static void show_sve_pn_slice(int debug_fd, struct kvm_cpu const *vcpu,
 	if (!vcpu->kvm->cfg.arch.has_sve)
 		die("P-reg unexpectedly present on non-SVE vcpu");
 
+	if (n >= 16 && reg.id != KVM_REG_ARM64_SVE_FFR(i))
+		die("Out-of-range P-reg unexpectedly present");
+
 	sappend_bytes(&strp, &strsz, bytes, sizeof bytes);
 	dprintf(debug_fd, "%s\n", str);
 }
@@ -406,9 +412,9 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu)
 		dprintf(debug_fd, " ZCR_EL1:0x%lx\n", data);
 	}
 
-	for (i = 0; i < 32; ++i)
+	for (i = 0; i < 32 + 1 /* should fail */; ++i)
 		show_sve_zn(debug_fd, vcpu, i);
 
-	for (i = 0; i < 16 + 1 /*FFR*/; ++i)
+	for (i = 0; i < 16 + 1 /* FFR */ + 1 /* should fail */; ++i)
 		show_sve_pn(debug_fd, vcpu, i);
 }
-- 
2.1.4

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm



[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux