Commit c5ed021
KVM: arm64: Update id_reg limit value based on per vcpu flags
There are multiple features the availability of which is enabled/disabled
and tracked on a per vcpu level in vcpu->arch.flagset e.g. sve, ptrauth,
and pmu. While the vm wide value of the id regs which represent the
availability of these features is stored in the id_regs kvm struct their
value needs to be manipulated on a per vcpu basis. This is done at read
time in kvm_arm_read_id_reg().
The value of these per vcpu flags needs to be factored in when calculating
the id_reg limit value in check_features() as otherwise we can run into the
following scenario.
[ running on cpu which supports sve ]
1. AA64PFR0.SVE set in id_reg by kvm_arm_init_id_regs() (cpu supports it
and so is set in value returned from read_sanitised_ftr_reg())
2. vcpus created without sve feature enabled
3. vmm reads AA64PFR0 and attempts to write the same value back
(writing the same value back is allowed)
4. write fails in check_features() as limit has AA64PFR0.SVE set however it
is not set in the value being written and although a lower value is
allowed for this feature it is not in the mask of bits which can be
modified and so much match exactly.
Thus add a step in check_features() to update the limit returned from
id_reg->reset() with the per vcpu features which may have been
enabled/disabled at vcpu creation time after the id_regs were initialised.
Split this update into a new function named kvm_arm_update_id_reg() so it
can be called from check_features() as well as kvm_arm_read_id_reg() to
dedup code.
Note: Processing of the DFR0 and AA64DFR0 registers remains in
kvm_arm_read_id_reg() as the value of these cannot be modified based
on vcpu feature flags, all changes to these registers must go through
the id_regs mechanism.
Also add a check for RAZ (read a zero) registers to arm64_check_features()
as even though the host may support a non-zero value for these, it is only
valid to set them to zero from userspace.
Finally return -EINVAL from set_id_reg() rather than -E2BIG to remain
consistent with the UAPI.
Signed-off-by: Suraj Jitindar Singh <surajjs@amazon.com>1 parent abe7ccc commit c5ed021
1 file changed
+28
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
1143 | 1144 | | |
1144 | 1145 | | |
1145 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1146 | 1151 | | |
1147 | 1152 | | |
1148 | 1153 | | |
| 1154 | + | |
1149 | 1155 | | |
1150 | 1156 | | |
1151 | 1157 | | |
| |||
1252 | 1258 | | |
1253 | 1259 | | |
1254 | 1260 | | |
1255 | | - | |
| 1261 | + | |
1256 | 1262 | | |
1257 | | - | |
1258 | | - | |
1259 | 1263 | | |
1260 | 1264 | | |
1261 | 1265 | | |
| |||
1285 | 1289 | | |
1286 | 1290 | | |
1287 | 1291 | | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
1288 | 1302 | | |
1289 | 1303 | | |
1290 | 1304 | | |
| |||
1298 | 1312 | | |
1299 | 1313 | | |
1300 | 1314 | | |
1301 | | - | |
| 1315 | + | |
1302 | 1316 | | |
1303 | 1317 | | |
1304 | 1318 | | |
| |||
1551 | 1565 | | |
1552 | 1566 | | |
1553 | 1567 | | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1554 | 1578 | | |
1555 | 1579 | | |
1556 | 1580 | | |
| |||
0 commit comments