|
30 | 30 | #include <linux/uaccess.h> |
31 | 31 | #include <asm/unistd.h> |
32 | 32 | #include <asm/switch_to.h> |
| 33 | +#include <asm/runtime_instr.h> |
| 34 | +#include <asm/facility.h> |
| 35 | + |
33 | 36 | #include "entry.h" |
34 | 37 |
|
35 | 38 | #ifdef CONFIG_COMPAT |
@@ -1239,6 +1242,96 @@ static int s390_gs_bc_set(struct task_struct *target, |
1239 | 1242 | data, 0, sizeof(struct gs_cb)); |
1240 | 1243 | } |
1241 | 1244 |
|
| 1245 | +static bool is_ri_cb_valid(struct runtime_instr_cb *cb) |
| 1246 | +{ |
| 1247 | + return (cb->rca & 0x1f) == 0 && |
| 1248 | + (cb->roa & 0xfff) == 0 && |
| 1249 | + (cb->rla & 0xfff) == 0xfff && |
| 1250 | + cb->s == 1 && |
| 1251 | + cb->k == 1 && |
| 1252 | + cb->h == 0 && |
| 1253 | + cb->reserved1 == 0 && |
| 1254 | + cb->ps == 1 && |
| 1255 | + cb->qs == 0 && |
| 1256 | + cb->pc == 1 && |
| 1257 | + cb->qc == 0 && |
| 1258 | + cb->reserved2 == 0 && |
| 1259 | + cb->key == PAGE_DEFAULT_KEY && |
| 1260 | + cb->reserved3 == 0 && |
| 1261 | + cb->reserved4 == 0 && |
| 1262 | + cb->reserved5 == 0 && |
| 1263 | + cb->reserved6 == 0 && |
| 1264 | + cb->reserved7 == 0 && |
| 1265 | + cb->reserved8 == 0 && |
| 1266 | + cb->rla >= cb->roa && |
| 1267 | + cb->rca >= cb->roa && |
| 1268 | + cb->rca <= cb->rla+1 && |
| 1269 | + cb->m < 3; |
| 1270 | +} |
| 1271 | + |
| 1272 | +static int s390_runtime_instr_get(struct task_struct *target, |
| 1273 | + const struct user_regset *regset, |
| 1274 | + unsigned int pos, unsigned int count, |
| 1275 | + void *kbuf, void __user *ubuf) |
| 1276 | +{ |
| 1277 | + struct runtime_instr_cb *data = target->thread.ri_cb; |
| 1278 | + |
| 1279 | + if (!test_facility(64)) |
| 1280 | + return -ENODEV; |
| 1281 | + if (!data) |
| 1282 | + return -ENODATA; |
| 1283 | + |
| 1284 | + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 1285 | + data, 0, sizeof(struct runtime_instr_cb)); |
| 1286 | +} |
| 1287 | + |
| 1288 | +static int s390_runtime_instr_set(struct task_struct *target, |
| 1289 | + const struct user_regset *regset, |
| 1290 | + unsigned int pos, unsigned int count, |
| 1291 | + const void *kbuf, const void __user *ubuf) |
| 1292 | +{ |
| 1293 | + struct runtime_instr_cb ri_cb = { }, *data = NULL; |
| 1294 | + int rc; |
| 1295 | + |
| 1296 | + if (!test_facility(64)) |
| 1297 | + return -ENODEV; |
| 1298 | + |
| 1299 | + if (!target->thread.ri_cb) { |
| 1300 | + data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 1301 | + if (!data) |
| 1302 | + return -ENOMEM; |
| 1303 | + } |
| 1304 | + |
| 1305 | + if (target->thread.ri_cb) { |
| 1306 | + if (target == current) |
| 1307 | + store_runtime_instr_cb(&ri_cb); |
| 1308 | + else |
| 1309 | + ri_cb = *target->thread.ri_cb; |
| 1310 | + } |
| 1311 | + |
| 1312 | + rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 1313 | + &ri_cb, 0, sizeof(struct runtime_instr_cb)); |
| 1314 | + if (rc) { |
| 1315 | + kfree(data); |
| 1316 | + return -EFAULT; |
| 1317 | + } |
| 1318 | + |
| 1319 | + if (!is_ri_cb_valid(&ri_cb)) { |
| 1320 | + kfree(data); |
| 1321 | + return -EINVAL; |
| 1322 | + } |
| 1323 | + |
| 1324 | + preempt_disable(); |
| 1325 | + if (!target->thread.ri_cb) |
| 1326 | + target->thread.ri_cb = data; |
| 1327 | + *target->thread.ri_cb = ri_cb; |
| 1328 | + if (target == current) |
| 1329 | + load_runtime_instr_cb(target->thread.ri_cb); |
| 1330 | + preempt_enable(); |
| 1331 | + |
| 1332 | + return 0; |
| 1333 | +} |
| 1334 | + |
1242 | 1335 | static const struct user_regset s390_regsets[] = { |
1243 | 1336 | { |
1244 | 1337 | .core_note_type = NT_PRSTATUS, |
@@ -1312,6 +1405,14 @@ static const struct user_regset s390_regsets[] = { |
1312 | 1405 | .get = s390_gs_bc_get, |
1313 | 1406 | .set = s390_gs_bc_set, |
1314 | 1407 | }, |
| 1408 | + { |
| 1409 | + .core_note_type = NT_S390_RI_CB, |
| 1410 | + .n = sizeof(struct runtime_instr_cb) / sizeof(__u64), |
| 1411 | + .size = sizeof(__u64), |
| 1412 | + .align = sizeof(__u64), |
| 1413 | + .get = s390_runtime_instr_get, |
| 1414 | + .set = s390_runtime_instr_set, |
| 1415 | + }, |
1315 | 1416 | }; |
1316 | 1417 |
|
1317 | 1418 | static const struct user_regset_view user_s390_view = { |
@@ -1548,6 +1649,14 @@ static const struct user_regset s390_compat_regsets[] = { |
1548 | 1649 | .get = s390_gs_cb_get, |
1549 | 1650 | .set = s390_gs_cb_set, |
1550 | 1651 | }, |
| 1652 | + { |
| 1653 | + .core_note_type = NT_S390_RI_CB, |
| 1654 | + .n = sizeof(struct runtime_instr_cb) / sizeof(__u64), |
| 1655 | + .size = sizeof(__u64), |
| 1656 | + .align = sizeof(__u64), |
| 1657 | + .get = s390_runtime_instr_get, |
| 1658 | + .set = s390_runtime_instr_set, |
| 1659 | + }, |
1551 | 1660 | }; |
1552 | 1661 |
|
1553 | 1662 | static const struct user_regset_view user_s390_compat_view = { |
|
0 commit comments