Commit f7ef896e authored by Dave Martin's avatar Dave Martin
Browse files

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



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: default avatarDave Martin <Dave.Martin@arm.com>
parent 178439df
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment