Skip to content

Commit 56d77aa

Browse files
committed
KVM: arm64: Allow userspace to change ID_AA64ISAR{0-2}_EL1
Almost all of the features described by the ISA registers have no KVM involvement. Allow userspace to change the value of these registers with a couple exceptions: - MOPS is not writable as KVM does not currently virtualize FEAT_MOPS. - The PAuth fields are not writable as KVM requires both address and generic authentication be enabled. Co-developed-by: Jing Zhang <[email protected]> Signed-off-by: Jing Zhang <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 9f9917b commit 56d77aa

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,14 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu,
18511851
* from userspace.
18521852
*/
18531853

1854-
/* sys_reg_desc initialiser for known cpufeature ID registers */
1855-
#define ID_SANITISED(name) { \
1854+
#define ID_DESC(name) \
18561855
SYS_DESC(SYS_##name), \
18571856
.access = access_id_reg, \
1858-
.get_user = get_id_reg, \
1857+
.get_user = get_id_reg \
1858+
1859+
/* sys_reg_desc initialiser for known cpufeature ID registers */
1860+
#define ID_SANITISED(name) { \
1861+
ID_DESC(name), \
18591862
.set_user = set_id_reg, \
18601863
.visibility = id_visibility, \
18611864
.reset = kvm_read_sanitised_id_reg, \
@@ -1864,15 +1867,22 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu,
18641867

18651868
/* sys_reg_desc initialiser for known cpufeature ID registers */
18661869
#define AA32_ID_SANITISED(name) { \
1867-
SYS_DESC(SYS_##name), \
1868-
.access = access_id_reg, \
1869-
.get_user = get_id_reg, \
1870+
ID_DESC(name), \
18701871
.set_user = set_id_reg, \
18711872
.visibility = aa32_id_visibility, \
18721873
.reset = kvm_read_sanitised_id_reg, \
18731874
.val = 0, \
18741875
}
18751876

1877+
/* sys_reg_desc initialiser for writable ID registers */
1878+
#define ID_WRITABLE(name, mask) { \
1879+
ID_DESC(name), \
1880+
.set_user = set_id_reg, \
1881+
.visibility = id_visibility, \
1882+
.reset = kvm_read_sanitised_id_reg, \
1883+
.val = mask, \
1884+
}
1885+
18761886
/*
18771887
* sys_reg_desc initialiser for architecturally unallocated cpufeature ID
18781888
* register with encoding Op0=3, Op1=0, CRn=0, CRm=crm, Op2=op2
@@ -1894,9 +1904,7 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu,
18941904
* RAZ for the guest.
18951905
*/
18961906
#define ID_HIDDEN(name) { \
1897-
SYS_DESC(SYS_##name), \
1898-
.access = access_id_reg, \
1899-
.get_user = get_id_reg, \
1907+
ID_DESC(name), \
19001908
.set_user = set_id_reg, \
19011909
.visibility = raz_visibility, \
19021910
.reset = kvm_read_sanitised_id_reg, \
@@ -2075,9 +2083,15 @@ static const struct sys_reg_desc sys_reg_descs[] = {
20752083
ID_UNALLOCATED(5,7),
20762084

20772085
/* CRm=6 */
2078-
ID_SANITISED(ID_AA64ISAR0_EL1),
2079-
ID_SANITISED(ID_AA64ISAR1_EL1),
2080-
ID_SANITISED(ID_AA64ISAR2_EL1),
2086+
ID_WRITABLE(ID_AA64ISAR0_EL1, ~ID_AA64ISAR0_EL1_RES0),
2087+
ID_WRITABLE(ID_AA64ISAR1_EL1, ~(ID_AA64ISAR1_EL1_GPI |
2088+
ID_AA64ISAR1_EL1_GPA |
2089+
ID_AA64ISAR1_EL1_API |
2090+
ID_AA64ISAR1_EL1_APA)),
2091+
ID_WRITABLE(ID_AA64ISAR2_EL1, ~(ID_AA64ISAR2_EL1_RES0 |
2092+
ID_AA64ISAR2_EL1_MOPS |
2093+
ID_AA64ISAR2_EL1_APA3 |
2094+
ID_AA64ISAR2_EL1_GPA3)),
20812095
ID_UNALLOCATED(6,3),
20822096
ID_UNALLOCATED(6,4),
20832097
ID_UNALLOCATED(6,5),

0 commit comments

Comments
 (0)