Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Harald Freudenberger and committed by
Martin Schwidefsky
13b251bd cccd85bf

+203 -24
+122
arch/s390/include/asm/trace/zcrypt.h
··· 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>
+81 -24
drivers/s390/crypto/zcrypt_api.c
··· 41 41 #include <linux/debugfs.h> 42 42 #include <asm/debug.h> 43 43 44 + #define CREATE_TRACE_POINTS 45 + #include <asm/trace/zcrypt.h> 46 + 44 47 #include "zcrypt_api.h" 45 48 #include "zcrypt_debug.h" 46 49 ··· 57 54 MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \ 58 55 "Copyright IBM Corp. 2001, 2012"); 59 56 MODULE_LICENSE("GPL"); 57 + 58 + /* 59 + * zcrypt tracepoint functions 60 + */ 61 + EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_req); 62 + EXPORT_TRACEPOINT_SYMBOL(s390_zcrypt_rep); 60 63 61 64 static int zcrypt_hwrng_seed = 1; 62 65 module_param_named(hwrng_seed, zcrypt_hwrng_seed, int, S_IRUSR|S_IRGRP); ··· 233 224 struct zcrypt_queue *zq, *pref_zq; 234 225 unsigned int weight, pref_weight; 235 226 unsigned int func_code; 236 - int rc; 227 + int qid = 0, rc = -ENODEV; 237 228 238 - if (mex->outputdatalength < mex->inputdatalength) 239 - return -EINVAL; 229 + trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO); 230 + 231 + if (mex->outputdatalength < mex->inputdatalength) { 232 + rc = -EINVAL; 233 + goto out; 234 + } 235 + 240 236 /* 241 237 * As long as outputdatalength is big enough, we can set the 242 238 * outputdatalength equal to the inputdatalength, since that is the ··· 251 237 252 238 rc = get_rsa_modex_fc(mex, &func_code); 253 239 if (rc) 254 - return rc; 240 + goto out; 255 241 256 242 pref_zc = NULL; 257 243 pref_zq = NULL; ··· 283 269 pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight); 284 270 spin_unlock(&zcrypt_list_lock); 285 271 286 - if (!pref_zq) 287 - return -ENODEV; 272 + if (!pref_zq) { 273 + rc = -ENODEV; 274 + goto out; 275 + } 288 276 277 + qid = pref_zq->queue->qid; 289 278 rc = pref_zq->ops->rsa_modexpo(pref_zq, mex); 290 279 291 280 spin_lock(&zcrypt_list_lock); 292 281 zcrypt_drop_queue(pref_zc, pref_zq, weight); 293 282 spin_unlock(&zcrypt_list_lock); 294 283 284 + out: 285 + trace_s390_zcrypt_rep(mex, func_code, rc, 286 + AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 295 287 return rc; 296 288 } 297 289 ··· 307 287 struct zcrypt_queue *zq, *pref_zq; 308 288 unsigned int weight, pref_weight; 309 289 unsigned int func_code; 310 - int rc; 290 + int qid = 0, rc = -ENODEV; 311 291 312 - if (crt->outputdatalength < crt->inputdatalength) 313 - return -EINVAL; 292 + trace_s390_zcrypt_req(crt, TP_ICARSACRT); 293 + 294 + if (crt->outputdatalength < crt->inputdatalength) { 295 + rc = -EINVAL; 296 + goto out; 297 + } 298 + 314 299 /* 315 300 * As long as outputdatalength is big enough, we can set the 316 301 * outputdatalength equal to the inputdatalength, since that is the ··· 325 300 326 301 rc = get_rsa_crt_fc(crt, &func_code); 327 302 if (rc) 328 - return rc; 303 + goto out; 329 304 330 305 pref_zc = NULL; 331 306 pref_zq = NULL; ··· 357 332 pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight); 358 333 spin_unlock(&zcrypt_list_lock); 359 334 360 - if (!pref_zq) 361 - return -ENODEV; 335 + if (!pref_zq) { 336 + rc = -ENODEV; 337 + goto out; 338 + } 362 339 340 + qid = pref_zq->queue->qid; 363 341 rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt); 364 342 365 343 spin_lock(&zcrypt_list_lock); 366 344 zcrypt_drop_queue(pref_zc, pref_zq, weight); 367 345 spin_unlock(&zcrypt_list_lock); 368 346 347 + out: 348 + trace_s390_zcrypt_rep(crt, func_code, rc, 349 + AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 369 350 return rc; 370 351 } 371 352 ··· 383 352 unsigned int weight, pref_weight; 384 353 unsigned int func_code; 385 354 unsigned short *domain; 386 - int rc; 355 + int qid = 0, rc = -ENODEV; 356 + 357 + trace_s390_zcrypt_req(xcRB, TB_ZSECSENDCPRB); 387 358 388 359 rc = get_cprb_fc(xcRB, &ap_msg, &func_code, &domain); 389 360 if (rc) 390 - return rc; 361 + goto out; 391 362 392 363 pref_zc = NULL; 393 364 pref_zq = NULL; ··· 424 391 pref_zq = zcrypt_pick_queue(pref_zc, pref_zq, weight); 425 392 spin_unlock(&zcrypt_list_lock); 426 393 427 - if (!pref_zq) 428 - return -ENODEV; 394 + if (!pref_zq) { 395 + rc = -ENODEV; 396 + goto out; 397 + } 429 398 430 399 /* in case of auto select, provide the correct domain */ 400 + qid = pref_zq->queue->qid; 431 401 if (*domain == (unsigned short) AUTOSELECT) 432 - *domain = AP_QID_QUEUE(pref_zq->queue->qid); 402 + *domain = AP_QID_QUEUE(qid); 433 403 434 404 rc = pref_zq->ops->send_cprb(pref_zq, xcRB, &ap_msg); 435 405 436 406 spin_lock(&zcrypt_list_lock); 437 407 zcrypt_drop_queue(pref_zc, pref_zq, weight); 438 408 spin_unlock(&zcrypt_list_lock); 409 + 410 + out: 411 + trace_s390_zcrypt_rep(xcRB, func_code, rc, 412 + AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 439 413 return rc; 440 414 } 441 415 ··· 479 439 unsigned int weight, pref_weight; 480 440 unsigned int func_code; 481 441 struct ap_message ap_msg; 482 - int rc; 442 + int qid = 0, rc = -ENODEV; 443 + 444 + trace_s390_zcrypt_req(xcrb, TP_ZSENDEP11CPRB); 483 445 484 446 target_num = (unsigned short) xcrb->targets_num; 485 447 ··· 491 449 struct ep11_target_dev __user *uptr; 492 450 493 451 targets = kcalloc(target_num, sizeof(*targets), GFP_KERNEL); 494 - if (!targets) 495 - return -ENOMEM; 452 + if (!targets) { 453 + rc = -ENOMEM; 454 + goto out; 455 + } 496 456 497 457 uptr = (struct ep11_target_dev __force __user *) xcrb->targets; 498 458 if (copy_from_user(targets, uptr, 499 - target_num * sizeof(*targets))) 500 - return -EFAULT; 459 + target_num * sizeof(*targets))) { 460 + rc = -EFAULT; 461 + goto out; 462 + } 501 463 } 502 464 503 465 rc = get_ep11cprb_fc(xcrb, &ap_msg, &func_code); ··· 547 501 goto out_free; 548 502 } 549 503 504 + qid = pref_zq->queue->qid; 550 505 rc = pref_zq->ops->send_ep11_cprb(pref_zq, xcrb, &ap_msg); 551 506 552 507 spin_lock(&zcrypt_list_lock); ··· 556 509 557 510 out_free: 558 511 kfree(targets); 512 + out: 513 + trace_s390_zcrypt_rep(xcrb, func_code, rc, 514 + AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 559 515 return rc; 560 516 } 561 517 ··· 570 520 unsigned int func_code; 571 521 struct ap_message ap_msg; 572 522 unsigned int domain; 573 - int rc; 523 + int qid = 0, rc = -ENODEV; 524 + 525 + trace_s390_zcrypt_req(buffer, TP_HWRNGCPRB); 574 526 575 527 rc = get_rng_fc(&ap_msg, &func_code, &domain); 576 528 if (rc) 577 - return rc; 529 + goto out; 578 530 579 531 pref_zc = NULL; 580 532 pref_zq = NULL; ··· 607 555 if (!pref_zq) 608 556 return -ENODEV; 609 557 558 + qid = pref_zq->queue->qid; 610 559 rc = pref_zq->ops->rng(pref_zq, buffer, &ap_msg); 611 560 612 561 spin_lock(&zcrypt_list_lock); 613 562 zcrypt_drop_queue(pref_zc, pref_zq, weight); 614 563 spin_unlock(&zcrypt_list_lock); 564 + 565 + out: 566 + trace_s390_zcrypt_rep(buffer, func_code, rc, 567 + AP_QID_CARD(qid), AP_QID_QUEUE(qid)); 615 568 return rc; 616 569 } 617 570