Skip to content

Commit 4343549

Browse files
hfreudehcahca
authored andcommitted
s390/ap: Move response_type struct into ap_msg struct
Move the very small response_type struct into struct ap_msg. So there is no need to kmalloc this tiny struct with each ap message preparation. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Link: https://lore.kernel.org/r/20250424133619.16495-2-freude@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 7cf5888 commit 4343549

3 files changed

Lines changed: 37 additions & 61 deletions

File tree

drivers/s390/crypto/ap_bus.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ struct ap_queue {
214214

215215
typedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue);
216216

217+
struct ap_response_type {
218+
struct completion work;
219+
int type;
220+
};
221+
217222
struct ap_message {
218223
struct list_head list; /* Request queueing. */
219224
unsigned long psmid; /* Message id. */
@@ -222,7 +227,7 @@ struct ap_message {
222227
size_t bufsize; /* allocated msg buffer size */
223228
u16 flags; /* Flags, see AP_MSG_FLAG_xxx */
224229
int rc; /* Return code for this message */
225-
void *private; /* ap driver private pointer. */
230+
struct ap_response_type response;
226231
/* receive is called from tasklet context */
227232
void (*receive)(struct ap_queue *, struct ap_message *,
228233
struct ap_message *);
@@ -250,7 +255,6 @@ static inline void ap_init_message(struct ap_message *ap_msg)
250255
static inline void ap_release_message(struct ap_message *ap_msg)
251256
{
252257
kfree_sensitive(ap_msg->msg);
253-
kfree_sensitive(ap_msg->private);
254258
}
255259

256260
enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event);

drivers/s390/crypto/zcrypt_msgtype50.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void zcrypt_msgtype50_receive(struct ap_queue *aq,
438438
msg->len = sizeof(error_reply);
439439
}
440440
out:
441-
complete((struct completion *)msg->private);
441+
complete(&msg->response.work);
442442
}
443443

444444
static atomic_t zcrypt_step = ATOMIC_INIT(0);
@@ -454,7 +454,6 @@ static long zcrypt_msgtype50_modexpo(struct zcrypt_queue *zq,
454454
struct ica_rsa_modexpo *mex,
455455
struct ap_message *ap_msg)
456456
{
457-
struct completion work;
458457
int rc;
459458

460459
ap_msg->bufsize = MSGTYPE50_CRB3_MAX_MSG_SIZE;
@@ -464,15 +463,14 @@ static long zcrypt_msgtype50_modexpo(struct zcrypt_queue *zq,
464463
ap_msg->receive = zcrypt_msgtype50_receive;
465464
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
466465
atomic_inc_return(&zcrypt_step);
467-
ap_msg->private = &work;
468466
rc = ICAMEX_msg_to_type50MEX_msg(zq, ap_msg, mex);
469467
if (rc)
470468
goto out;
471-
init_completion(&work);
469+
init_completion(&ap_msg->response.work);
472470
rc = ap_queue_message(zq->queue, ap_msg);
473471
if (rc)
474472
goto out;
475-
rc = wait_for_completion_interruptible(&work);
473+
rc = wait_for_completion_interruptible(&ap_msg->response.work);
476474
if (rc == 0) {
477475
rc = ap_msg->rc;
478476
if (rc == 0)
@@ -485,7 +483,6 @@ static long zcrypt_msgtype50_modexpo(struct zcrypt_queue *zq,
485483
}
486484

487485
out:
488-
ap_msg->private = NULL;
489486
if (rc)
490487
pr_debug("send me cprb at dev=%02x.%04x rc=%d\n",
491488
AP_QID_CARD(zq->queue->qid),
@@ -504,7 +501,6 @@ static long zcrypt_msgtype50_modexpo_crt(struct zcrypt_queue *zq,
504501
struct ica_rsa_modexpo_crt *crt,
505502
struct ap_message *ap_msg)
506503
{
507-
struct completion work;
508504
int rc;
509505

510506
ap_msg->bufsize = MSGTYPE50_CRB3_MAX_MSG_SIZE;
@@ -514,15 +510,14 @@ static long zcrypt_msgtype50_modexpo_crt(struct zcrypt_queue *zq,
514510
ap_msg->receive = zcrypt_msgtype50_receive;
515511
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
516512
atomic_inc_return(&zcrypt_step);
517-
ap_msg->private = &work;
518513
rc = ICACRT_msg_to_type50CRT_msg(zq, ap_msg, crt);
519514
if (rc)
520515
goto out;
521-
init_completion(&work);
516+
init_completion(&ap_msg->response.work);
522517
rc = ap_queue_message(zq->queue, ap_msg);
523518
if (rc)
524519
goto out;
525-
rc = wait_for_completion_interruptible(&work);
520+
rc = wait_for_completion_interruptible(&ap_msg->response.work);
526521
if (rc == 0) {
527522
rc = ap_msg->rc;
528523
if (rc == 0)
@@ -535,7 +530,6 @@ static long zcrypt_msgtype50_modexpo_crt(struct zcrypt_queue *zq,
535530
}
536531

537532
out:
538-
ap_msg->private = NULL;
539533
if (rc)
540534
pr_debug("send crt cprb at dev=%02x.%04x rc=%d\n",
541535
AP_QID_CARD(zq->queue->qid),

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131

3232
#define CEIL4(x) ((((x) + 3) / 4) * 4)
3333

34-
struct response_type {
35-
struct completion work;
36-
int type;
37-
};
38-
3934
#define CEXXC_RESPONSE_TYPE_ICA 0
4035
#define CEXXC_RESPONSE_TYPE_XCRB 1
4136
#define CEXXC_RESPONSE_TYPE_EP11 2
@@ -856,7 +851,7 @@ static void zcrypt_msgtype6_receive(struct ap_queue *aq,
856851
.type = TYPE82_RSP_CODE,
857852
.reply_code = REP82_ERROR_MACHINE_FAILURE,
858853
};
859-
struct response_type *resp_type = msg->private;
854+
struct ap_response_type *resp_type = &msg->response;
860855
struct type86x_reply *t86r;
861856
int len;
862857

@@ -920,7 +915,7 @@ static void zcrypt_msgtype6_receive_ep11(struct ap_queue *aq,
920915
.type = TYPE82_RSP_CODE,
921916
.reply_code = REP82_ERROR_MACHINE_FAILURE,
922917
};
923-
struct response_type *resp_type = msg->private;
918+
struct ap_response_type *resp_type = &msg->response;
924919
struct type86_ep11_reply *t86r;
925920
int len;
926921

@@ -967,9 +962,7 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
967962
struct ica_rsa_modexpo *mex,
968963
struct ap_message *ap_msg)
969964
{
970-
struct response_type resp_type = {
971-
.type = CEXXC_RESPONSE_TYPE_ICA,
972-
};
965+
struct ap_response_type *resp_type = &ap_msg->response;
973966
int rc;
974967

975968
ap_msg->msg = (void *)get_zeroed_page(GFP_KERNEL);
@@ -979,15 +972,15 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
979972
ap_msg->receive = zcrypt_msgtype6_receive;
980973
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
981974
atomic_inc_return(&zcrypt_step);
982-
ap_msg->private = &resp_type;
983975
rc = icamex_msg_to_type6mex_msgx(zq, ap_msg, mex);
984976
if (rc)
985977
goto out_free;
986-
init_completion(&resp_type.work);
978+
resp_type->type = CEXXC_RESPONSE_TYPE_ICA;
979+
init_completion(&resp_type->work);
987980
rc = ap_queue_message(zq->queue, ap_msg);
988981
if (rc)
989982
goto out_free;
990-
rc = wait_for_completion_interruptible(&resp_type.work);
983+
rc = wait_for_completion_interruptible(&resp_type->work);
991984
if (rc == 0) {
992985
rc = ap_msg->rc;
993986
if (rc == 0)
@@ -1001,7 +994,6 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
1001994

1002995
out_free:
1003996
free_page((unsigned long)ap_msg->msg);
1004-
ap_msg->private = NULL;
1005997
ap_msg->msg = NULL;
1006998
return rc;
1007999
}
@@ -1017,9 +1009,7 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10171009
struct ica_rsa_modexpo_crt *crt,
10181010
struct ap_message *ap_msg)
10191011
{
1020-
struct response_type resp_type = {
1021-
.type = CEXXC_RESPONSE_TYPE_ICA,
1022-
};
1012+
struct ap_response_type *resp_type = &ap_msg->response;
10231013
int rc;
10241014

10251015
ap_msg->msg = (void *)get_zeroed_page(GFP_KERNEL);
@@ -1029,15 +1019,15 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10291019
ap_msg->receive = zcrypt_msgtype6_receive;
10301020
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
10311021
atomic_inc_return(&zcrypt_step);
1032-
ap_msg->private = &resp_type;
10331022
rc = icacrt_msg_to_type6crt_msgx(zq, ap_msg, crt);
10341023
if (rc)
10351024
goto out_free;
1036-
init_completion(&resp_type.work);
1025+
resp_type->type = CEXXC_RESPONSE_TYPE_ICA;
1026+
init_completion(&resp_type->work);
10371027
rc = ap_queue_message(zq->queue, ap_msg);
10381028
if (rc)
10391029
goto out_free;
1040-
rc = wait_for_completion_interruptible(&resp_type.work);
1030+
rc = wait_for_completion_interruptible(&resp_type->work);
10411031
if (rc == 0) {
10421032
rc = ap_msg->rc;
10431033
if (rc == 0)
@@ -1051,7 +1041,6 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10511041

10521042
out_free:
10531043
free_page((unsigned long)ap_msg->msg);
1054-
ap_msg->private = NULL;
10551044
ap_msg->msg = NULL;
10561045
return rc;
10571046
}
@@ -1069,9 +1058,7 @@ int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb,
10691058
struct ap_message *ap_msg,
10701059
unsigned int *func_code, unsigned short **dom)
10711060
{
1072-
struct response_type resp_type = {
1073-
.type = CEXXC_RESPONSE_TYPE_XCRB,
1074-
};
1061+
struct ap_response_type *resp_type = &ap_msg->response;
10751062

10761063
ap_msg->bufsize = atomic_read(&ap_max_msg_size);
10771064
ap_msg->msg = kmalloc(ap_msg->bufsize, GFP_KERNEL);
@@ -1080,9 +1067,7 @@ int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb,
10801067
ap_msg->receive = zcrypt_msgtype6_receive;
10811068
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
10821069
atomic_inc_return(&zcrypt_step);
1083-
ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
1084-
if (!ap_msg->private)
1085-
return -ENOMEM;
1070+
resp_type->type = CEXXC_RESPONSE_TYPE_XCRB;
10861071
return xcrb_msg_to_type6cprb_msgx(userspace, ap_msg, xcrb, func_code, dom);
10871072
}
10881073

@@ -1097,7 +1082,7 @@ static long zcrypt_msgtype6_send_cprb(bool userspace, struct zcrypt_queue *zq,
10971082
struct ica_xcRB *xcrb,
10981083
struct ap_message *ap_msg)
10991084
{
1100-
struct response_type *rtype = ap_msg->private;
1085+
struct ap_response_type *resp_type = &ap_msg->response;
11011086
struct {
11021087
struct type6_hdr hdr;
11031088
struct CPRBX cprbx;
@@ -1128,11 +1113,11 @@ static long zcrypt_msgtype6_send_cprb(bool userspace, struct zcrypt_queue *zq,
11281113
msg->hdr.fromcardlen1 -= delta;
11291114
}
11301115

1131-
init_completion(&rtype->work);
1116+
init_completion(&resp_type->work);
11321117
rc = ap_queue_message(zq->queue, ap_msg);
11331118
if (rc)
11341119
goto out;
1135-
rc = wait_for_completion_interruptible(&rtype->work);
1120+
rc = wait_for_completion_interruptible(&resp_type->work);
11361121
if (rc == 0) {
11371122
rc = ap_msg->rc;
11381123
if (rc == 0)
@@ -1166,9 +1151,7 @@ int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb,
11661151
struct ap_message *ap_msg,
11671152
unsigned int *func_code, unsigned int *domain)
11681153
{
1169-
struct response_type resp_type = {
1170-
.type = CEXXC_RESPONSE_TYPE_EP11,
1171-
};
1154+
struct ap_response_type *resp_type = &ap_msg->response;
11721155

11731156
ap_msg->bufsize = atomic_read(&ap_max_msg_size);
11741157
ap_msg->msg = kmalloc(ap_msg->bufsize, GFP_KERNEL);
@@ -1177,9 +1160,7 @@ int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb,
11771160
ap_msg->receive = zcrypt_msgtype6_receive_ep11;
11781161
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
11791162
atomic_inc_return(&zcrypt_step);
1180-
ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
1181-
if (!ap_msg->private)
1182-
return -ENOMEM;
1163+
resp_type->type = CEXXC_RESPONSE_TYPE_EP11;
11831164
return xcrb_msg_to_type6_ep11cprb_msgx(userspace, ap_msg, xcrb,
11841165
func_code, domain);
11851166
}
@@ -1197,7 +1178,7 @@ static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue *
11971178
{
11981179
int rc;
11991180
unsigned int lfmt;
1200-
struct response_type *rtype = ap_msg->private;
1181+
struct ap_response_type *resp_type = &ap_msg->response;
12011182
struct {
12021183
struct type6_hdr hdr;
12031184
struct ep11_cprb cprbx;
@@ -1251,11 +1232,11 @@ static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue *
12511232
msg->hdr.fromcardlen1 = zq->reply.bufsize -
12521233
sizeof(struct type86_hdr) - sizeof(struct type86_fmt2_ext);
12531234

1254-
init_completion(&rtype->work);
1235+
init_completion(&resp_type->work);
12551236
rc = ap_queue_message(zq->queue, ap_msg);
12561237
if (rc)
12571238
goto out;
1258-
rc = wait_for_completion_interruptible(&rtype->work);
1239+
rc = wait_for_completion_interruptible(&resp_type->work);
12591240
if (rc == 0) {
12601241
rc = ap_msg->rc;
12611242
if (rc == 0)
@@ -1279,9 +1260,7 @@ static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue *
12791260
int prep_rng_ap_msg(struct ap_message *ap_msg, int *func_code,
12801261
unsigned int *domain)
12811262
{
1282-
struct response_type resp_type = {
1283-
.type = CEXXC_RESPONSE_TYPE_XCRB,
1284-
};
1263+
struct ap_response_type *resp_type = &ap_msg->response;
12851264

12861265
ap_msg->bufsize = AP_DEFAULT_MAX_MSG_SIZE;
12871266
ap_msg->msg = kmalloc(ap_msg->bufsize, GFP_KERNEL);
@@ -1290,9 +1269,8 @@ int prep_rng_ap_msg(struct ap_message *ap_msg, int *func_code,
12901269
ap_msg->receive = zcrypt_msgtype6_receive;
12911270
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
12921271
atomic_inc_return(&zcrypt_step);
1293-
ap_msg->private = kmemdup(&resp_type, sizeof(resp_type), GFP_KERNEL);
1294-
if (!ap_msg->private)
1295-
return -ENOMEM;
1272+
1273+
resp_type->type = CEXXC_RESPONSE_TYPE_XCRB;
12961274

12971275
rng_type6cprb_msgx(ap_msg, ZCRYPT_RNG_BUFFER_SIZE, domain);
12981276

@@ -1319,16 +1297,16 @@ static long zcrypt_msgtype6_rng(struct zcrypt_queue *zq,
13191297
short int verb_length;
13201298
short int key_length;
13211299
} __packed * msg = ap_msg->msg;
1322-
struct response_type *rtype = ap_msg->private;
1300+
struct ap_response_type *resp_type = &ap_msg->response;
13231301
int rc;
13241302

13251303
msg->cprbx.domain = AP_QID_QUEUE(zq->queue->qid);
13261304

1327-
init_completion(&rtype->work);
1305+
init_completion(&resp_type->work);
13281306
rc = ap_queue_message(zq->queue, ap_msg);
13291307
if (rc)
13301308
goto out;
1331-
rc = wait_for_completion_interruptible(&rtype->work);
1309+
rc = wait_for_completion_interruptible(&resp_type->work);
13321310
if (rc == 0) {
13331311
rc = ap_msg->rc;
13341312
if (rc == 0)

0 commit comments

Comments
 (0)