Skip to content

Commit 3730f53

Browse files
hfreudeVasily Gorbik
authored andcommitted
s390/zcrypt: move ap_msg param one level up the call chain
Move the creating and disposal of the struct ap_message one level up the call chain. The ap message was constructed in the calling functions in msgtype50 and msgtype6 but only for the ica rsa messages. For CCA and EP11 CPRBs the ap message struct is created in the zcrypt api functions. This patch moves the construction of the ap message struct into the functions zcrypt_rsa_modexpo and zcrypt_rsa_crt. So now all the 4 zcrypt api functions zcrypt_rsa_modexpo, zcrypt_rsa_crt, zcrypt_send_cprb and zcrypt_send_ep11_cprb appear and act similar. There are no functional changes coming with this patch. However, the availability of the ap_message struct has advantages which will be needed by a follow up patch. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent e033262 commit 3730f53

4 files changed

Lines changed: 82 additions & 72 deletions

File tree

drivers/s390/crypto/zcrypt_api.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,16 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
635635
{
636636
struct zcrypt_card *zc, *pref_zc;
637637
struct zcrypt_queue *zq, *pref_zq;
638+
struct ap_message ap_msg;
638639
unsigned int wgt = 0, pref_wgt = 0;
639640
unsigned int func_code;
640641
int cpen, qpen, qid = 0, rc = -ENODEV;
641642
struct module *mod;
642643

643644
trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO);
644645

646+
ap_init_message(&ap_msg);
647+
645648
if (mex->outputdatalength < mex->inputdatalength) {
646649
func_code = 0;
647650
rc = -EINVAL;
@@ -712,13 +715,14 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
712715
}
713716

714717
qid = pref_zq->queue->qid;
715-
rc = pref_zq->ops->rsa_modexpo(pref_zq, mex);
718+
rc = pref_zq->ops->rsa_modexpo(pref_zq, mex, &ap_msg);
716719

717720
spin_lock(&zcrypt_list_lock);
718721
zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
719722
spin_unlock(&zcrypt_list_lock);
720723

721724
out:
725+
ap_release_message(&ap_msg);
722726
if (tr) {
723727
tr->last_rc = rc;
724728
tr->last_qid = qid;
@@ -734,13 +738,16 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
734738
{
735739
struct zcrypt_card *zc, *pref_zc;
736740
struct zcrypt_queue *zq, *pref_zq;
741+
struct ap_message ap_msg;
737742
unsigned int wgt = 0, pref_wgt = 0;
738743
unsigned int func_code;
739744
int cpen, qpen, qid = 0, rc = -ENODEV;
740745
struct module *mod;
741746

742747
trace_s390_zcrypt_req(crt, TP_ICARSACRT);
743748

749+
ap_init_message(&ap_msg);
750+
744751
if (crt->outputdatalength < crt->inputdatalength) {
745752
func_code = 0;
746753
rc = -EINVAL;
@@ -811,13 +818,14 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
811818
}
812819

813820
qid = pref_zq->queue->qid;
814-
rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt);
821+
rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt, &ap_msg);
815822

816823
spin_lock(&zcrypt_list_lock);
817824
zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
818825
spin_unlock(&zcrypt_list_lock);
819826

820827
out:
828+
ap_release_message(&ap_msg);
821829
if (tr) {
822830
tr->last_rc = rc;
823831
tr->last_qid = qid;

drivers/s390/crypto/zcrypt_api.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ struct zcrypt_track {
6868
#define TRACK_AGAIN_QUEUE_WEIGHT_PENALTY 10000
6969

7070
struct zcrypt_ops {
71-
long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
71+
long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *,
72+
struct ap_message *);
7273
long (*rsa_modexpo_crt)(struct zcrypt_queue *,
73-
struct ica_rsa_modexpo_crt *);
74+
struct ica_rsa_modexpo_crt *,
75+
struct ap_message *);
7476
long (*send_cprb)(bool userspace, struct zcrypt_queue *, struct ica_xcRB *,
7577
struct ap_message *);
7678
long (*send_ep11_cprb)(bool userspace, struct zcrypt_queue *, struct ep11_urb *,

drivers/s390/crypto/zcrypt_msgtype50.c

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -450,42 +450,41 @@ static atomic_t zcrypt_step = ATOMIC_INIT(0);
450450
* @mex: pointer to the modexpo request buffer
451451
*/
452452
static long zcrypt_cex2a_modexpo(struct zcrypt_queue *zq,
453-
struct ica_rsa_modexpo *mex)
453+
struct ica_rsa_modexpo *mex,
454+
struct ap_message *ap_msg)
454455
{
455-
struct ap_message ap_msg;
456456
struct completion work;
457457
int rc;
458458

459-
ap_init_message(&ap_msg);
460459
if (zq->zcard->user_space_type == ZCRYPT_CEX2A)
461-
ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
460+
ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
462461
else
463-
ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
464-
if (!ap_msg.msg)
462+
ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
463+
if (!ap_msg->msg)
465464
return -ENOMEM;
466-
ap_msg.receive = zcrypt_cex2a_receive;
467-
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
468-
atomic_inc_return(&zcrypt_step);
469-
ap_msg.private = &work;
470-
rc = ICAMEX_msg_to_type50MEX_msg(zq, &ap_msg, mex);
465+
ap_msg->receive = zcrypt_cex2a_receive;
466+
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
467+
atomic_inc_return(&zcrypt_step);
468+
ap_msg->private = &work;
469+
rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex);
471470
if (rc)
472-
goto out_free;
471+
goto out;
473472
init_completion(&work);
474-
rc = ap_queue_message(zq->queue, &ap_msg);
473+
rc = ap_queue_message(zq->queue, ap_msg);
475474
if (rc)
476-
goto out_free;
475+
goto out;
477476
rc = wait_for_completion_interruptible(&work);
478477
if (rc == 0) {
479-
rc = ap_msg.rc;
478+
rc = ap_msg->rc;
480479
if (rc == 0)
481-
rc = convert_response_cex2a(zq, &ap_msg,
480+
rc = convert_response_cex2a(zq, ap_msg,
482481
mex->outputdata,
483482
mex->outputdatalength);
484483
} else
485484
/* Signal pending. */
486-
ap_cancel_message(zq->queue, &ap_msg);
487-
out_free:
488-
kfree(ap_msg.msg);
485+
ap_cancel_message(zq->queue, ap_msg);
486+
out:
487+
ap_msg->private = NULL;
489488
return rc;
490489
}
491490

@@ -497,42 +496,41 @@ static long zcrypt_cex2a_modexpo(struct zcrypt_queue *zq,
497496
* @crt: pointer to the modexpoc_crt request buffer
498497
*/
499498
static long zcrypt_cex2a_modexpo_crt(struct zcrypt_queue *zq,
500-
struct ica_rsa_modexpo_crt *crt)
499+
struct ica_rsa_modexpo_crt *crt,
500+
struct ap_message *ap_msg)
501501
{
502-
struct ap_message ap_msg;
503502
struct completion work;
504503
int rc;
505504

506-
ap_init_message(&ap_msg);
507505
if (zq->zcard->user_space_type == ZCRYPT_CEX2A)
508-
ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
506+
ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
509507
else
510-
ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
511-
if (!ap_msg.msg)
508+
ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
509+
if (!ap_msg->msg)
512510
return -ENOMEM;
513-
ap_msg.receive = zcrypt_cex2a_receive;
514-
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
515-
atomic_inc_return(&zcrypt_step);
516-
ap_msg.private = &work;
517-
rc = ICACRT_msg_to_type50CRT_msg(zq, &ap_msg, crt);
511+
ap_msg->receive = zcrypt_cex2a_receive;
512+
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
513+
atomic_inc_return(&zcrypt_step);
514+
ap_msg->private = &work;
515+
rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt);
518516
if (rc)
519-
goto out_free;
517+
goto out;
520518
init_completion(&work);
521-
rc = ap_queue_message(zq->queue, &ap_msg);
519+
rc = ap_queue_message(zq->queue, ap_msg);
522520
if (rc)
523-
goto out_free;
521+
goto out;
524522
rc = wait_for_completion_interruptible(&work);
525523
if (rc == 0) {
526-
rc = ap_msg.rc;
524+
rc = ap_msg->rc;
527525
if (rc == 0)
528-
rc = convert_response_cex2a(zq, &ap_msg,
526+
rc = convert_response_cex2a(zq, ap_msg,
529527
crt->outputdata,
530528
crt->outputdatalength);
531529
} else
532530
/* Signal pending. */
533-
ap_cancel_message(zq->queue, &ap_msg);
534-
out_free:
535-
kfree(ap_msg.msg);
531+
ap_cancel_message(zq->queue, ap_msg);
532+
out:
533+
ap_msg->private = NULL;
536534
return rc;
537535
}
538536

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,41 +1007,42 @@ static atomic_t zcrypt_step = ATOMIC_INIT(0);
10071007
* @mex: pointer to the modexpo request buffer
10081008
*/
10091009
static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
1010-
struct ica_rsa_modexpo *mex)
1010+
struct ica_rsa_modexpo *mex,
1011+
struct ap_message *ap_msg)
10111012
{
1012-
struct ap_message ap_msg;
10131013
struct response_type resp_type = {
10141014
.type = CEXXC_RESPONSE_TYPE_ICA,
10151015
};
10161016
int rc;
10171017

1018-
ap_init_message(&ap_msg);
1019-
ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL);
1020-
if (!ap_msg.msg)
1018+
ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL);
1019+
if (!ap_msg->msg)
10211020
return -ENOMEM;
1022-
ap_msg.receive = zcrypt_msgtype6_receive;
1023-
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
1024-
atomic_inc_return(&zcrypt_step);
1025-
ap_msg.private = &resp_type;
1026-
rc = ICAMEX_msg_to_type6MEX_msgX(zq, &ap_msg, mex);
1021+
ap_msg->receive = zcrypt_msgtype6_receive;
1022+
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
1023+
atomic_inc_return(&zcrypt_step);
1024+
ap_msg->private = &resp_type;
1025+
rc = ICAMEX_msg_to_type6MEX_msgX(zq, ap_msg, mex);
10271026
if (rc)
10281027
goto out_free;
10291028
init_completion(&resp_type.work);
1030-
rc = ap_queue_message(zq->queue, &ap_msg);
1029+
rc = ap_queue_message(zq->queue, ap_msg);
10311030
if (rc)
10321031
goto out_free;
10331032
rc = wait_for_completion_interruptible(&resp_type.work);
10341033
if (rc == 0) {
1035-
rc = ap_msg.rc;
1034+
rc = ap_msg->rc;
10361035
if (rc == 0)
1037-
rc = convert_response_ica(zq, &ap_msg,
1036+
rc = convert_response_ica(zq, ap_msg,
10381037
mex->outputdata,
10391038
mex->outputdatalength);
10401039
} else
10411040
/* Signal pending. */
1042-
ap_cancel_message(zq->queue, &ap_msg);
1041+
ap_cancel_message(zq->queue, ap_msg);
10431042
out_free:
1044-
free_page((unsigned long) ap_msg.msg);
1043+
free_page((unsigned long) ap_msg->msg);
1044+
ap_msg->private = NULL;
1045+
ap_msg->msg = NULL;
10451046
return rc;
10461047
}
10471048

@@ -1053,42 +1054,43 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
10531054
* @crt: pointer to the modexpoc_crt request buffer
10541055
*/
10551056
static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
1056-
struct ica_rsa_modexpo_crt *crt)
1057+
struct ica_rsa_modexpo_crt *crt,
1058+
struct ap_message *ap_msg)
10571059
{
1058-
struct ap_message ap_msg;
10591060
struct response_type resp_type = {
10601061
.type = CEXXC_RESPONSE_TYPE_ICA,
10611062
};
10621063
int rc;
10631064

1064-
ap_init_message(&ap_msg);
1065-
ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL);
1066-
if (!ap_msg.msg)
1065+
ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL);
1066+
if (!ap_msg->msg)
10671067
return -ENOMEM;
1068-
ap_msg.receive = zcrypt_msgtype6_receive;
1069-
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
1070-
atomic_inc_return(&zcrypt_step);
1071-
ap_msg.private = &resp_type;
1072-
rc = ICACRT_msg_to_type6CRT_msgX(zq, &ap_msg, crt);
1068+
ap_msg->receive = zcrypt_msgtype6_receive;
1069+
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
1070+
atomic_inc_return(&zcrypt_step);
1071+
ap_msg->private = &resp_type;
1072+
rc = ICACRT_msg_to_type6CRT_msgX(zq, ap_msg, crt);
10731073
if (rc)
10741074
goto out_free;
10751075
init_completion(&resp_type.work);
1076-
rc = ap_queue_message(zq->queue, &ap_msg);
1076+
rc = ap_queue_message(zq->queue, ap_msg);
10771077
if (rc)
10781078
goto out_free;
10791079
rc = wait_for_completion_interruptible(&resp_type.work);
10801080
if (rc == 0) {
1081-
rc = ap_msg.rc;
1081+
rc = ap_msg->rc;
10821082
if (rc == 0)
1083-
rc = convert_response_ica(zq, &ap_msg,
1083+
rc = convert_response_ica(zq, ap_msg,
10841084
crt->outputdata,
10851085
crt->outputdatalength);
10861086
} else {
10871087
/* Signal pending. */
1088-
ap_cancel_message(zq->queue, &ap_msg);
1088+
ap_cancel_message(zq->queue, ap_msg);
10891089
}
10901090
out_free:
1091-
free_page((unsigned long) ap_msg.msg);
1091+
free_page((unsigned long) ap_msg->msg);
1092+
ap_msg->private = NULL;
1093+
ap_msg->msg = NULL;
10921094
return rc;
10931095
}
10941096

0 commit comments

Comments
 (0)