Skip to content

Commit 048fb1d

Browse files
Suraj Jitindar Singhabuehaze14
authored andcommitted
KVM: arm64: Enable writable for ID_AA64ISAR2_EL0
All valid fields in ID_AA64ISAR2_EL0 are writable from userspace with this change. Return an error if userspace tries to set gpa3 to an invalid configuration based on the Arm Architecture Reference Manual for A-profile architecture [1]. [1] https://developer.arm.com/documentation/ddi0487/latest/ Signed-off-by: Suraj Jitindar Singh <surajjs@amazon.com>
1 parent fc63c7e commit 048fb1d

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,46 @@ static int set_id_aa64isar1_el1(struct kvm_vcpu *vcpu,
17361736
return set_id_reg(vcpu, rd, val);
17371737
}
17381738

1739+
static int set_id_aa64isar2_el1(struct kvm_vcpu *vcpu,
1740+
const struct sys_reg_desc *rd,
1741+
u64 val)
1742+
{
1743+
u8 gpi, gpa, gpa3;
1744+
1745+
/* Fields in the register we're trying to set - ISAR2 */
1746+
gpa3 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR2_EL1_GPA3), val);
1747+
1748+
/* Fields in ISAR1 */
1749+
gpi = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_GPI),
1750+
IDREG(vcpu->kvm, SYS_ID_AA64ISAR1_EL1));
1751+
gpa = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_GPA),
1752+
IDREG(vcpu->kvm, SYS_ID_AA64ISAR1_EL1));
1753+
1754+
/*
1755+
* From Arm Architecture Reference Manual for A-profile architecture
1756+
* (https://developer.arm.com/documentation/ddi0487/latest/)
1757+
* D19.2.63:
1758+
* GPA3, bits [11:8]
1759+
* If the value of ID_AA64ISAR1_EL1.GPI is nonzero, or the value of
1760+
* ID_AA64ISAR1_EL1.GPA is nonzero, this field must have the value
1761+
* 0b0000.
1762+
*/
1763+
if (gpa3 && (gpi || gpa)) {
1764+
return -EINVAL;
1765+
}
1766+
1767+
/* Check ptrauth state matches that requested in vcpu features */
1768+
if ((gpi || gpa || gpa3) != vcpu_has_ptrauth(vcpu))
1769+
return -EINVAL;
1770+
1771+
/*
1772+
* No need to validate APA3, since it is FTR_EXACT it must match the
1773+
* host value. And who are we to argue if the host screwed it up.
1774+
*/
1775+
1776+
return set_id_reg(vcpu, rd, val);
1777+
}
1778+
17391779
static u64 read_sanitised_id_aa64isar2_el1(struct kvm_vcpu *vcpu,
17401780
const struct sys_reg_desc *rd)
17411781
{
@@ -2108,9 +2148,9 @@ static const struct sys_reg_desc sys_reg_descs[] = {
21082148
{ SYS_DESC(SYS_ID_AA64ISAR2_EL1),
21092149
.access = access_id_reg,
21102150
.get_user = get_id_reg,
2111-
.set_user = set_id_reg,
2151+
.set_user = set_id_aa64isar2_el1,
21122152
.reset = read_sanitised_id_aa64isar2_el1,
2113-
.val = 0, },
2153+
.val = GENMASK(63, 0), },
21142154
ID_UNALLOCATED(6,3),
21152155
ID_UNALLOCATED(6,4),
21162156
ID_UNALLOCATED(6,5),

0 commit comments

Comments
 (0)