Skip to content

Commit 13b251b

Browse files
Harald FreudenbergerMartin Schwidefsky
authored andcommitted
s390/zcrypt: tracepoint definitions for zcrypt device driver.
This patch introduces tracepoint definitions and tracepoint event invocations for the s390 zcrypt device. Currently there are just two tracepoint events defined. An s390_zcrypt_req request event occurs as soon as the request is recognized by the zcrypt ioctl function. This event may act as some kind of request-processing-starts-now indication. As late as possible within the zcrypt ioctl function there occurs the s390_zcrypt_rep event which may act as the point in time where the request has been processed by the kernel and the result is about to be transferred back to userspace. The glue which binds together request and reply event is the ptr parameter, which is the local buffer address where the request from userspace has been stored by the ioctl function. The main purpose of this zcrypt tracepoint patch is to get some data for performance measurements together with information about the kind of request and on which card and queue the request has been processed. It is not an ffdc interface as there is already code in the zcrypt device driver to serve the s390 debug feature interface. Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent cccd85b commit 13b251b

2 files changed

Lines changed: 203 additions & 24 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Tracepoint definitions for the s390 zcrypt device driver
3+
*
4+
* Copyright IBM Corp. 2016
5+
* Author(s): Harald Freudenberger <freude@de.ibm.com>
6+
*
7+
* Currently there are two tracepoint events defined here.
8+
* An s390_zcrypt_req request event occurs as soon as the request is
9+
* recognized by the zcrypt ioctl function. This event may act as some kind
10+
* of request-processing-starts-now indication.
11+
* As late as possible within the zcrypt ioctl function there occurs the
12+
* s390_zcrypt_rep event which may act as the point in time where the
13+
* request has been processed by the kernel and the result is about to be
14+
* transferred back to userspace.
15+
* The glue which binds together request and reply event is the ptr
16+
* parameter, which is the local buffer address where the request from
17+
* userspace has been stored by the ioctl function.
18+
*
19+
* The main purpose of this zcrypt tracepoint api is to get some data for
20+
* performance measurements together with information about on which card
21+
* and queue the request has been processed. It is not an ffdc interface as
22+
* there is already code in the zcrypt device driver to serve the s390
23+
* debug feature interface.
24+
*/
25+
26+
#undef TRACE_SYSTEM
27+
#define TRACE_SYSTEM s390
28+
29+
#if !defined(_TRACE_S390_ZCRYPT_H) || defined(TRACE_HEADER_MULTI_READ)
30+
#define _TRACE_S390_ZCRYPT_H
31+
32+
#include <linux/tracepoint.h>
33+
34+
#define TP_ICARSAMODEXPO 0x0001
35+
#define TP_ICARSACRT 0x0002
36+
#define TB_ZSECSENDCPRB 0x0003
37+
#define TP_ZSENDEP11CPRB 0x0004
38+
#define TP_HWRNGCPRB 0x0005
39+
40+
#define show_zcrypt_tp_type(type) \
41+
__print_symbolic(type, \
42+
{ TP_ICARSAMODEXPO, "ICARSAMODEXPO" }, \
43+
{ TP_ICARSACRT, "ICARSACRT" }, \
44+
{ TB_ZSECSENDCPRB, "ZSECSENDCPRB" }, \
45+
{ TP_ZSENDEP11CPRB, "ZSENDEP11CPRB" }, \
46+
{ TP_HWRNGCPRB, "HWRNGCPRB" })
47+
48+
/**
49+
* trace_s390_zcrypt_req - zcrypt request tracepoint function
50+
* @ptr: Address of the local buffer where the request from userspace
51+
* is stored. Can be used as a unique id to relate together
52+
* request and reply.
53+
* @type: One of the TP_ defines above.
54+
*
55+
* Called when a request from userspace is recognised within the ioctl
56+
* function of the zcrypt device driver and may act as an entry
57+
* timestamp.
58+
*/
59+
TRACE_EVENT(s390_zcrypt_req,
60+
TP_PROTO(void *ptr, u32 type),
61+
TP_ARGS(ptr, type),
62+
TP_STRUCT__entry(
63+
__field(void *, ptr)
64+
__field(u32, type)),
65+
TP_fast_assign(
66+
__entry->ptr = ptr;
67+
__entry->type = type;),
68+
TP_printk("ptr=%p type=%s",
69+
__entry->ptr,
70+
show_zcrypt_tp_type(__entry->type))
71+
);
72+
73+
/**
74+
* trace_s390_zcrypt_rep - zcrypt reply tracepoint function
75+
* @ptr: Address of the local buffer where the request from userspace
76+
* is stored. Can be used as a unique id to match together
77+
* request and reply.
78+
* @fc: Function code.
79+
* @rc: The bare returncode as returned by the device driver ioctl
80+
* function.
81+
* @dev: The adapter nr where this request was actually processed.
82+
* @dom: Domain id of the device where this request was processed.
83+
*
84+
* Called upon recognising the reply from the crypto adapter. This
85+
* message may act as the exit timestamp for the request but also
86+
* carries some info about on which adapter the request was processed
87+
* and the returncode from the device driver.
88+
*/
89+
TRACE_EVENT(s390_zcrypt_rep,
90+
TP_PROTO(void *ptr, u32 fc, u32 rc, u16 dev, u16 dom),
91+
TP_ARGS(ptr, fc, rc, dev, dom),
92+
TP_STRUCT__entry(
93+
__field(void *, ptr)
94+
__field(u32, fc)
95+
__field(u32, rc)
96+
__field(u16, device)
97+
__field(u16, domain)),
98+
TP_fast_assign(
99+
__entry->ptr = ptr;
100+
__entry->fc = fc;
101+
__entry->rc = rc;
102+
__entry->device = dev;
103+
__entry->domain = dom;),
104+
TP_printk("ptr=%p fc=0x%04x rc=%d dev=0x%02hx domain=0x%04hx",
105+
__entry->ptr,
106+
(unsigned int) __entry->fc,
107+
(int) __entry->rc,
108+
(unsigned short) __entry->device,
109+
(unsigned short) __entry->domain)
110+
);
111+
112+
#endif /* _TRACE_S390_ZCRYPT_H */
113+
114+
/* This part must be outside protection */
115+
116+
#undef TRACE_INCLUDE_PATH
117+
#undef TRACE_INCLUDE_FILE
118+
119+
#define TRACE_INCLUDE_PATH asm/trace
120+
#define TRACE_INCLUDE_FILE zcrypt
121+
122+
#include <trace/define_trace.h>

‎drivers/s390/crypto/zcrypt_api.c‎

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include <linux/debugfs.h>
4242
#include <asm/debug.h>
4343

44+
#define CREATE_TRACE_POINTS
45+
#include <asm/trace/zcrypt.h>
46+
4447
#include "zcrypt_api.h"
4548
#include "zcrypt_debug.h"
4649

@@ -55,6 +58,12 @@ MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
5558
"Copyright IBM Corp. 2001, 2012");
5659
MODULE_LICENSE("GPL");
5760

61+
/*
62+
* zcrypt tracepoint functions
63+
*/
64+
EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_req);
65+
EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_rep);
66+
5867
static int zcrypt_hwrng_seed = 1;
5968
module_param_named(hwrng_seed, zcrypt_hwrng_seed, int, S_IRUSR|S_IRGRP);
6069
MODULE_PARM_DESC(hwrng_seed, "Turn on/off hwrng auto seed, default is 1 (on).");
@@ -224,10 +233,15 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
224233
struct zcrypt_queue *zq, *pref_zq;
225234
unsigned int weight, pref_weight;
226235
unsigned int func_code;
227-
int rc;
236+
int qid = 0, rc = -ENODEV;
237+
238+
trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO);
239+
240+
if (mex->outputdatalength < mex->inputdatalength) {
241+
rc = -EINVAL;
242+
goto out;
243+
}
228244

229-
if (mex->outputdatalength < mex->inputdatalength)
230-
return -EINVAL;
231245
/*
232246
* As long as outputdatalength is big enough, we can set the
233247
* outputdatalength equal to the inputdatalength, since that is the
@@ -237,7 +251,7 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
237251

238252
rc = get_rsa_modex_fc(mex, &func_code);
239253
if (rc)
240-
return rc;
254+
goto out;
241255

242256
pref_zc = NULL;
243257
pref_zq = NULL;
@@ -269,15 +283,21 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
269283
pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
270284
spin_unlock(&zcrypt_list_lock);
271285

272-
if (!pref_zq)
273-
return -ENODEV;
286+
if (!pref_zq) {
287+
rc = -ENODEV;
288+
goto out;
289+
}
274290

291+
qid = pref_zq->queue->qid;
275292
rc = pref_zq->ops->rsa_modexpo(pref_zq, mex);
276293

277294
spin_lock(&zcrypt_list_lock);
278295
zcrypt_drop_queue(pref_zc, pref_zq, weight);
279296
spin_unlock(&zcrypt_list_lock);
280297

298+
out:
299+
trace_s390_zcrypt_rep(mex, func_code, rc,
300+
AP_QID_CARD(qid), AP_QID_QUEUE(qid));
281301
return rc;
282302
}
283303

@@ -287,10 +307,15 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
287307
struct zcrypt_queue *zq, *pref_zq;
288308
unsigned int weight, pref_weight;
289309
unsigned int func_code;
290-
int rc;
310+
int qid = 0, rc = -ENODEV;
311+
312+
trace_s390_zcrypt_req(crt, TP_ICARSACRT);
313+
314+
if (crt->outputdatalength < crt->inputdatalength) {
315+
rc = -EINVAL;
316+
goto out;
317+
}
291318

292-
if (crt->outputdatalength < crt->inputdatalength)
293-
return -EINVAL;
294319
/*
295320
* As long as outputdatalength is big enough, we can set the
296321
* outputdatalength equal to the inputdatalength, since that is the
@@ -300,7 +325,7 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
300325

301326
rc = get_rsa_crt_fc(crt, &func_code);
302327
if (rc)
303-
return rc;
328+
goto out;
304329

305330
pref_zc = NULL;
306331
pref_zq = NULL;
@@ -332,15 +357,21 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
332357
pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
333358
spin_unlock(&zcrypt_list_lock);
334359

335-
if (!pref_zq)
336-
return -ENODEV;
360+
if (!pref_zq) {
361+
rc = -ENODEV;
362+
goto out;
363+
}
337364

365+
qid = pref_zq->queue->qid;
338366
rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt);
339367

340368
spin_lock(&zcrypt_list_lock);
341369
zcrypt_drop_queue(pref_zc, pref_zq, weight);
342370
spin_unlock(&zcrypt_list_lock);
343371

372+
out:
373+
trace_s390_zcrypt_rep(crt, func_code, rc,
374+
AP_QID_CARD(qid), AP_QID_QUEUE(qid));
344375
return rc;
345376
}
346377

@@ -352,11 +383,13 @@ static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
352383
unsigned int weight, pref_weight;
353384
unsigned int func_code;
354385
unsigned short *domain;
355-
int rc;
386+
int qid = 0, rc = -ENODEV;
387+
388+
trace_s390_zcrypt_req(xcRB, TB_ZSECSENDCPRB);
356389

357390
rc = get_cprb_fc(xcRB, &ap_msg, &func_code, &domain);
358391
if (rc)
359-
return rc;
392+
goto out;
360393

361394
pref_zc = NULL;
362395
pref_zq = NULL;
@@ -391,18 +424,25 @@ static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
391424
pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight);
392425
spin_unlock(&zcrypt_list_lock);
393426

394-
if (!pref_zq)
395-
return -ENODEV;
427+
if (!pref_zq) {
428+
rc = -ENODEV;
429+
goto out;
430+
}
396431

397432
/* in case of auto select, provide the correct domain */
433+
qid = pref_zq->queue->qid;
398434
if (*domain == (unsigned short) AUTOSELECT)
399-
*domain = AP_QID_QUEUE(pref_zq->queue->qid);
435+
*domain = AP_QID_QUEUE(qid);
400436

401437
rc = pref_zq->ops->send_cprb(pref_zq, xcRB, &ap_msg);
402438

403439
spin_lock(&zcrypt_list_lock);
404440
zcrypt_drop_queue(pref_zc, pref_zq, weight);
405441
spin_unlock(&zcrypt_list_lock);
442+
443+
out:
444+
trace_s390_zcrypt_rep(xcRB, func_code, rc,
445+
AP_QID_CARD(qid), AP_QID_QUEUE(qid));
406446
return rc;
407447
}
408448

@@ -439,7 +479,9 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
439479
unsigned int weight, pref_weight;
440480
unsigned int func_code;
441481
struct ap_message ap_msg;
442-
int rc;
482+
int qid = 0, rc = -ENODEV;
483+
484+
trace_s390_zcrypt_req(xcrb, TP_ZSENDEP11CPRB);
443485

444486
target_num = (unsigned short) xcrb->targets_num;
445487

@@ -449,13 +491,17 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
449491
struct ep11_target_dev __user *uptr;
450492

451493
targets = kcalloc(target_num, sizeof(*targets), GFP_KERNEL);
452-
if (!targets)
453-
return -ENOMEM;
494+
if (!targets) {
495+
rc = -ENOMEM;
496+
goto out;
497+
}
454498

455499
uptr = (struct ep11_target_dev __force __user *) xcrb->targets;
456500
if (copy_from_user(targets, uptr,
457-
target_num * sizeof(*targets)))
458-
return -EFAULT;
501+
target_num * sizeof(*targets))) {
502+
rc = -EFAULT;
503+
goto out;
504+
}
459505
}
460506

461507
rc = get_ep11cprb_fc(xcrb, &ap_msg, &func_code);
@@ -501,6 +547,7 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
501547
goto out_free;
502548
}
503549

550+
qid = pref_zq->queue->qid;
504551
rc = pref_zq->ops->send_ep11_cprb(pref_zq, xcrb, &ap_msg);
505552

506553
spin_lock(&zcrypt_list_lock);
@@ -509,6 +556,9 @@ static long zcrypt_send_ep11_cprb(struct ep11_urb *xcrb)
509556

510557
out_free:
511558
kfree(targets);
559+
out:
560+
trace_s390_zcrypt_rep(xcrb, func_code, rc,
561+
AP_QID_CARD(qid), AP_QID_QUEUE(qid));
512562
return rc;
513563
}
514564

@@ -520,11 +570,13 @@ static long zcrypt_rng(char *buffer)
520570
unsigned int func_code;
521571
struct ap_message ap_msg;
522572
unsigned int domain;
523-
int rc;
573+
int qid = 0, rc = -ENODEV;
574+
575+
trace_s390_zcrypt_req(buffer, TP_HWRNGCPRB);
524576

525577
rc = get_rng_fc(&ap_msg, &func_code, &domain);
526578
if (rc)
527-
return rc;
579+
goto out;
528580

529581
pref_zc = NULL;
530582
pref_zq = NULL;
@@ -555,11 +607,16 @@ static long zcrypt_rng(char *buffer)
555607
if (!pref_zq)
556608
return -ENODEV;
557609

610+
qid = pref_zq->queue->qid;
558611
rc = pref_zq->ops->rng(pref_zq, buffer, &ap_msg);
559612

560613
spin_lock(&zcrypt_list_lock);
561614
zcrypt_drop_queue(pref_zc, pref_zq, weight);
562615
spin_unlock(&zcrypt_list_lock);
616+
617+
out:
618+
trace_s390_zcrypt_rep(buffer, func_code, rc,
619+
AP_QID_CARD(qid), AP_QID_QUEUE(qid));
563620
return rc;
564621
}
565622

0 commit comments

Comments
 (0)