Skip to content

Commit 262832b

Browse files
Alice FrosiMartin Schwidefsky
authored andcommitted
s390/ptrace: add runtime instrumention register get/set
Add runtime instrumention register get and set which allows to read and modify the runtime instrumention control block. Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent bb59c2d commit 262832b

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎arch/s390/kernel/ptrace.c‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include <linux/uaccess.h>
3131
#include <asm/unistd.h>
3232
#include <asm/switch_to.h>
33+
#include <asm/runtime_instr.h>
34+
#include <asm/facility.h>
35+
3336
#include "entry.h"
3437

3538
#ifdef CONFIG_COMPAT
@@ -1239,6 +1242,96 @@ static int s390_gs_bc_set(struct task_struct *target,
12391242
data, 0, sizeof(struct gs_cb));
12401243
}
12411244

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+
12421335
static const struct user_regset s390_regsets[] = {
12431336
{
12441337
.core_note_type = NT_PRSTATUS,
@@ -1312,6 +1405,14 @@ static const struct user_regset s390_regsets[] = {
13121405
.get = s390_gs_bc_get,
13131406
.set = s390_gs_bc_set,
13141407
},
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+
},
13151416
};
13161417

13171418
static const struct user_regset_view user_s390_view = {
@@ -1548,6 +1649,14 @@ static const struct user_regset s390_compat_regsets[] = {
15481649
.get = s390_gs_cb_get,
15491650
.set = s390_gs_cb_set,
15501651
},
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+
},
15511660
};
15521661

15531662
static const struct user_regset_view user_s390_compat_view = {

‎include/uapi/linux/elf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ typedef struct elf64_shdr {
411411
#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
412412
#define NT_S390_GS_CB 0x30b /* s390 guarded storage registers */
413413
#define NT_S390_GS_BC 0x30c /* s390 guarded storage broadcast control block */
414+
#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */
414415
#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
415416
#define NT_ARM_TLS 0x401 /* ARM TLS register */
416417
#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */

0 commit comments

Comments
 (0)