Skip to content

Commit 004d6dd

Browse files
Suraj Jitindar Singhabuehaze14
authored andcommitted
KVM: arm64: Enable writable for ID_AA64ISAR0_EL0
All valid fields in ID_AA64ISAR0_EL0 are writable from userspace with this change. Return an error if userspace tries to set sha[1|2|3] 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 169e52f commit 004d6dd

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,53 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu,
15911591
return pmuver_update(vcpu, rd, val, perfmon_to_pmuver(perfmon), valid_pmu);
15921592
}
15931593

1594+
static int set_id_aa64isar0_el1(struct kvm_vcpu *vcpu,
1595+
const struct sys_reg_desc *rd,
1596+
u64 val)
1597+
{
1598+
u8 sm4, sm3, sha1, sha2, sha3;
1599+
1600+
sm4 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SM4), val);
1601+
sm3 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SM3), val);
1602+
sha1 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA1), val);
1603+
sha2 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA2), val);
1604+
sha3 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA3), val);
1605+
1606+
/*
1607+
* From Arm Architecture Reference Manual for A-profile architecture
1608+
* (https://developer.arm.com/documentation/ddi0487/latest/)
1609+
* D19.2.61:
1610+
* SM4, bits [43:40]
1611+
* This field must have the same value as ID_AA64ISAR0_EL1.SM3.
1612+
*/
1613+
if (sm4 != sm3)
1614+
return -EINVAL;
1615+
1616+
/*
1617+
* From Arm Architecture Reference Manual for A-profile architecture
1618+
* (https://developer.arm.com/documentation/ddi0487/latest/)
1619+
* D19.2.61:
1620+
* SHA1, bits [11:8]
1621+
* If the value of ID_AA64ISAR0_EL1.SHA2 is 0b0000,
1622+
* this field must have the value 0b0000.
1623+
* SHA2, bits [15:12]
1624+
* If the value of this field is 0b0010,
1625+
* ID_AA64ISAR0_EL1.SHA3 must have the value 0b0001.
1626+
* SHA3, bits [35:32]
1627+
* If the value of ID_AA64ISAR0_EL1.SHA1 is 0b0000,
1628+
* this field must have the value 0b0000.
1629+
*/
1630+
if (!sha1) {
1631+
if (sha2 || sha3)
1632+
return -EINVAL;
1633+
} else {
1634+
if (sha3 && (sha2 != 0b0010))
1635+
return -EINVAL;
1636+
}
1637+
1638+
return set_id_reg(vcpu, rd, val);
1639+
}
1640+
15941641
static u64 read_sanitised_id_aa64isar2_el1(struct kvm_vcpu *vcpu,
15951642
const struct sys_reg_desc *rd)
15961643
{
@@ -1948,7 +1995,12 @@ static const struct sys_reg_desc sys_reg_descs[] = {
19481995
ID_UNALLOCATED(5,7),
19491996

19501997
/* CRm=6 */
1951-
ID_SANITISED(ID_AA64ISAR0_EL1),
1998+
{ SYS_DESC(SYS_ID_AA64ISAR0_EL1),
1999+
.access = access_id_reg,
2000+
.get_user = get_id_reg,
2001+
.set_user = set_id_aa64isar0_el1,
2002+
.reset = general_read_kvm_sanitised_reg,
2003+
.val = GENMASK(63, 0), },
19522004
ID_SANITISED(ID_AA64ISAR1_EL1),
19532005
{ SYS_DESC(SYS_ID_AA64ISAR2_EL1),
19542006
.access = access_id_reg,

0 commit comments

Comments
 (0)