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>
This commit is contained in:
parent
e0332629e3
commit
3730f5300b
|
@ -635,6 +635,7 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
|
|||
{
|
||||
struct zcrypt_card *zc, *pref_zc;
|
||||
struct zcrypt_queue *zq, *pref_zq;
|
||||
struct ap_message ap_msg;
|
||||
unsigned int wgt = 0, pref_wgt = 0;
|
||||
unsigned int func_code;
|
||||
int cpen, qpen, qid = 0, rc = -ENODEV;
|
||||
|
@ -642,6 +643,8 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
|
|||
|
||||
trace_s390_zcrypt_req(mex, TP_ICARSAMODEXPO);
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
|
||||
if (mex->outputdatalength < mex->inputdatalength) {
|
||||
func_code = 0;
|
||||
rc = -EINVAL;
|
||||
|
@ -712,13 +715,14 @@ static long zcrypt_rsa_modexpo(struct ap_perms *perms,
|
|||
}
|
||||
|
||||
qid = pref_zq->queue->qid;
|
||||
rc = pref_zq->ops->rsa_modexpo(pref_zq, mex);
|
||||
rc = pref_zq->ops->rsa_modexpo(pref_zq, mex, &ap_msg);
|
||||
|
||||
spin_lock(&zcrypt_list_lock);
|
||||
zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
|
||||
spin_unlock(&zcrypt_list_lock);
|
||||
|
||||
out:
|
||||
ap_release_message(&ap_msg);
|
||||
if (tr) {
|
||||
tr->last_rc = rc;
|
||||
tr->last_qid = qid;
|
||||
|
@ -734,6 +738,7 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
|
|||
{
|
||||
struct zcrypt_card *zc, *pref_zc;
|
||||
struct zcrypt_queue *zq, *pref_zq;
|
||||
struct ap_message ap_msg;
|
||||
unsigned int wgt = 0, pref_wgt = 0;
|
||||
unsigned int func_code;
|
||||
int cpen, qpen, qid = 0, rc = -ENODEV;
|
||||
|
@ -741,6 +746,8 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
|
|||
|
||||
trace_s390_zcrypt_req(crt, TP_ICARSACRT);
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
|
||||
if (crt->outputdatalength < crt->inputdatalength) {
|
||||
func_code = 0;
|
||||
rc = -EINVAL;
|
||||
|
@ -811,13 +818,14 @@ static long zcrypt_rsa_crt(struct ap_perms *perms,
|
|||
}
|
||||
|
||||
qid = pref_zq->queue->qid;
|
||||
rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt);
|
||||
rc = pref_zq->ops->rsa_modexpo_crt(pref_zq, crt, &ap_msg);
|
||||
|
||||
spin_lock(&zcrypt_list_lock);
|
||||
zcrypt_drop_queue(pref_zc, pref_zq, mod, wgt);
|
||||
spin_unlock(&zcrypt_list_lock);
|
||||
|
||||
out:
|
||||
ap_release_message(&ap_msg);
|
||||
if (tr) {
|
||||
tr->last_rc = rc;
|
||||
tr->last_qid = qid;
|
||||
|
|
|
@ -68,9 +68,11 @@ struct zcrypt_track {
|
|||
#define TRACK_AGAIN_QUEUE_WEIGHT_PENALTY 10000
|
||||
|
||||
struct zcrypt_ops {
|
||||
long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
|
||||
long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *,
|
||||
struct ap_message *);
|
||||
long (*rsa_modexpo_crt)(struct zcrypt_queue *,
|
||||
struct ica_rsa_modexpo_crt *);
|
||||
struct ica_rsa_modexpo_crt *,
|
||||
struct ap_message *);
|
||||
long (*send_cprb)(bool userspace, struct zcrypt_queue *, struct ica_xcRB *,
|
||||
struct ap_message *);
|
||||
long (*send_ep11_cprb)(bool userspace, struct zcrypt_queue *, struct ep11_urb *,
|
||||
|
|
|
@ -450,42 +450,41 @@ static atomic_t zcrypt_step = ATOMIC_INIT(0);
|
|||
* @mex: pointer to the modexpo request buffer
|
||||
*/
|
||||
static long zcrypt_cex2a_modexpo(struct zcrypt_queue *zq,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
struct ica_rsa_modexpo *mex,
|
||||
struct ap_message *ap_msg)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct completion work;
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
if (zq->zcard->user_space_type == ZCRYPT_CEX2A)
|
||||
ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
else
|
||||
ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.msg)
|
||||
ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg->msg)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_cex2a_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
ap_msg->receive = zcrypt_cex2a_receive;
|
||||
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICAMEX_msg_to_type50MEX_msg(zq, &ap_msg, mex);
|
||||
ap_msg->private = &work;
|
||||
rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
goto out;
|
||||
init_completion(&work);
|
||||
rc = ap_queue_message(zq->queue, &ap_msg);
|
||||
rc = ap_queue_message(zq->queue, ap_msg);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
goto out;
|
||||
rc = wait_for_completion_interruptible(&work);
|
||||
if (rc == 0) {
|
||||
rc = ap_msg.rc;
|
||||
rc = ap_msg->rc;
|
||||
if (rc == 0)
|
||||
rc = convert_response_cex2a(zq, &ap_msg,
|
||||
rc = convert_response_cex2a(zq, ap_msg,
|
||||
mex->outputdata,
|
||||
mex->outputdatalength);
|
||||
} else
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zq->queue, &ap_msg);
|
||||
out_free:
|
||||
kfree(ap_msg.msg);
|
||||
ap_cancel_message(zq->queue, ap_msg);
|
||||
out:
|
||||
ap_msg->private = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -497,42 +496,41 @@ out_free:
|
|||
* @crt: pointer to the modexpoc_crt request buffer
|
||||
*/
|
||||
static long zcrypt_cex2a_modexpo_crt(struct zcrypt_queue *zq,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
struct ica_rsa_modexpo_crt *crt,
|
||||
struct ap_message *ap_msg)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct completion work;
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
if (zq->zcard->user_space_type == ZCRYPT_CEX2A)
|
||||
ap_msg.msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
ap_msg->msg = kmalloc(MSGTYPE50_CRB2_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
else
|
||||
ap_msg.msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.msg)
|
||||
ap_msg->msg = kmalloc(MSGTYPE50_CRB3_MAX_MSG_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg->msg)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_cex2a_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
ap_msg->receive = zcrypt_cex2a_receive;
|
||||
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICACRT_msg_to_type50CRT_msg(zq, &ap_msg, crt);
|
||||
ap_msg->private = &work;
|
||||
rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
goto out;
|
||||
init_completion(&work);
|
||||
rc = ap_queue_message(zq->queue, &ap_msg);
|
||||
rc = ap_queue_message(zq->queue, ap_msg);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
goto out;
|
||||
rc = wait_for_completion_interruptible(&work);
|
||||
if (rc == 0) {
|
||||
rc = ap_msg.rc;
|
||||
rc = ap_msg->rc;
|
||||
if (rc == 0)
|
||||
rc = convert_response_cex2a(zq, &ap_msg,
|
||||
rc = convert_response_cex2a(zq, ap_msg,
|
||||
crt->outputdata,
|
||||
crt->outputdatalength);
|
||||
} else
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zq->queue, &ap_msg);
|
||||
out_free:
|
||||
kfree(ap_msg.msg);
|
||||
ap_cancel_message(zq->queue, ap_msg);
|
||||
out:
|
||||
ap_msg->private = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -1007,41 +1007,42 @@ static atomic_t zcrypt_step = ATOMIC_INIT(0);
|
|||
* @mex: pointer to the modexpo request buffer
|
||||
*/
|
||||
static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
struct ica_rsa_modexpo *mex,
|
||||
struct ap_message *ap_msg)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct response_type resp_type = {
|
||||
.type = CEXXC_RESPONSE_TYPE_ICA,
|
||||
};
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg.msg)
|
||||
ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg->msg)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_msgtype6_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
ap_msg->receive = zcrypt_msgtype6_receive;
|
||||
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &resp_type;
|
||||
rc = ICAMEX_msg_to_type6MEX_msgX(zq, &ap_msg, mex);
|
||||
ap_msg->private = &resp_type;
|
||||
rc = ICAMEX_msg_to_type6MEX_msgX(zq, ap_msg, mex);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
init_completion(&resp_type.work);
|
||||
rc = ap_queue_message(zq->queue, &ap_msg);
|
||||
rc = ap_queue_message(zq->queue, ap_msg);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
rc = wait_for_completion_interruptible(&resp_type.work);
|
||||
if (rc == 0) {
|
||||
rc = ap_msg.rc;
|
||||
rc = ap_msg->rc;
|
||||
if (rc == 0)
|
||||
rc = convert_response_ica(zq, &ap_msg,
|
||||
rc = convert_response_ica(zq, ap_msg,
|
||||
mex->outputdata,
|
||||
mex->outputdatalength);
|
||||
} else
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zq->queue, &ap_msg);
|
||||
ap_cancel_message(zq->queue, ap_msg);
|
||||
out_free:
|
||||
free_page((unsigned long) ap_msg.msg);
|
||||
free_page((unsigned long) ap_msg->msg);
|
||||
ap_msg->private = NULL;
|
||||
ap_msg->msg = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -1053,42 +1054,43 @@ out_free:
|
|||
* @crt: pointer to the modexpoc_crt request buffer
|
||||
*/
|
||||
static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
struct ica_rsa_modexpo_crt *crt,
|
||||
struct ap_message *ap_msg)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct response_type resp_type = {
|
||||
.type = CEXXC_RESPONSE_TYPE_ICA,
|
||||
};
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
ap_msg.msg = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg.msg)
|
||||
ap_msg->msg = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg->msg)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_msgtype6_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
ap_msg->receive = zcrypt_msgtype6_receive;
|
||||
ap_msg->psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &resp_type;
|
||||
rc = ICACRT_msg_to_type6CRT_msgX(zq, &ap_msg, crt);
|
||||
ap_msg->private = &resp_type;
|
||||
rc = ICACRT_msg_to_type6CRT_msgX(zq, ap_msg, crt);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
init_completion(&resp_type.work);
|
||||
rc = ap_queue_message(zq->queue, &ap_msg);
|
||||
rc = ap_queue_message(zq->queue, ap_msg);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
rc = wait_for_completion_interruptible(&resp_type.work);
|
||||
if (rc == 0) {
|
||||
rc = ap_msg.rc;
|
||||
rc = ap_msg->rc;
|
||||
if (rc == 0)
|
||||
rc = convert_response_ica(zq, &ap_msg,
|
||||
rc = convert_response_ica(zq, ap_msg,
|
||||
crt->outputdata,
|
||||
crt->outputdatalength);
|
||||
} else {
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zq->queue, &ap_msg);
|
||||
ap_cancel_message(zq->queue, ap_msg);
|
||||
}
|
||||
out_free:
|
||||
free_page((unsigned long) ap_msg.msg);
|
||||
free_page((unsigned long) ap_msg->msg);
|
||||
ap_msg->private = NULL;
|
||||
ap_msg->msg = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue