Skip to content

Commit e2c6d91

Browse files
hfreudeVasily Gorbik
authored andcommitted
s390/zcrypt: Rework domain processing within zcrypt device driver
Slight rework of the domain handling within the zcrypt dd: Remove this curious construct to give a pointer to the domain field within the CPRB struct to the zcrypt API and later fill in the target domain via this pointer. Now the domain is filled in with the send function when the ready constructed AP message is about to be pushed down into the software queue for AP queue processing. So now the domain handling for CCA, EP11 and (internal) rng CPRBs is the same. With this comes a slight reshuffle of the code related to domain processing in the zcrypt API and the message type 60 protocol implementation code. Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Acked-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 23a4757 commit e2c6d91

3 files changed

Lines changed: 29 additions & 31 deletions

File tree

drivers/s390/crypto/zcrypt_api.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,12 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,
854854
struct ica_xcRB *xcrb)
855855
{
856856
bool userspace = xflags & ZCRYPT_XFLAG_USERSPACE;
857-
struct zcrypt_card *zc, *pref_zc;
858-
struct zcrypt_queue *zq, *pref_zq;
859-
struct ap_message ap_msg;
857+
unsigned int domain, func_code = 0;
860858
unsigned int wgt = 0, pref_wgt = 0;
861-
unsigned int func_code = 0;
862-
unsigned short *domain, tdom;
859+
struct zcrypt_queue *zq, *pref_zq;
860+
struct zcrypt_card *zc, *pref_zc;
863861
int cpen, qpen, qid = 0, rc;
862+
struct ap_message ap_msg;
864863
struct module *mod;
865864

866865
trace_s390_zcrypt_req(xcrb, TB_ZSECSENDCPRB);
@@ -878,10 +877,9 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,
878877
print_hex_dump_debug("ccareq: ", DUMP_PREFIX_ADDRESS, 16, 1,
879878
ap_msg.msg, ap_msg.len, false);
880879

881-
tdom = *domain;
882-
if (perms != &ap_perms && tdom < AP_DOMAINS) {
880+
if (perms != &ap_perms && domain < AP_DOMAINS) {
883881
if (ap_msg.flags & AP_MSG_FLAG_ADMIN) {
884-
if (!test_bit_inv(tdom, perms->adm)) {
882+
if (!test_bit_inv(domain, perms->adm)) {
885883
rc = -ENODEV;
886884
goto out;
887885
}
@@ -894,10 +892,10 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,
894892
* If a valid target domain is set and this domain is NOT a usage
895893
* domain but a control only domain, autoselect target domain.
896894
*/
897-
if (tdom < AP_DOMAINS &&
898-
!ap_test_config_usage_domain(tdom) &&
899-
ap_test_config_ctrl_domain(tdom))
900-
tdom = AUTOSEL_DOM;
895+
if (domain < AP_DOMAINS &&
896+
!ap_test_config_usage_domain(domain) &&
897+
ap_test_config_ctrl_domain(domain))
898+
domain = AUTOSEL_DOM;
901899

902900
pref_zc = NULL;
903901
pref_zq = NULL;
@@ -929,8 +927,8 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,
929927
/* check for device usable and eligible */
930928
if (!zq->online || !zq->ops->send_cprb ||
931929
!ap_queue_usable(zq->queue) ||
932-
(tdom != AUTOSEL_DOM &&
933-
tdom != AP_QID_QUEUE(zq->queue->qid)))
930+
(domain != AUTOSEL_DOM &&
931+
domain != AP_QID_QUEUE(zq->queue->qid)))
934932
continue;
935933
/* check if device node has admission for this queue */
936934
if (!zcrypt_check_queue(perms,
@@ -953,16 +951,11 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,
953951

954952
if (!pref_zq) {
955953
pr_debug("no match for address %02x.%04x => ENODEV\n",
956-
xcrb->user_defined, *domain);
954+
xcrb->user_defined, domain);
957955
rc = -ENODEV;
958956
goto out;
959957
}
960958

961-
/* in case of auto select, provide the correct domain */
962-
qid = pref_zq->queue->qid;
963-
if (*domain == AUTOSEL_DOM)
964-
*domain = AP_QID_QUEUE(qid);
965-
966959
rc = pref_zq->ops->send_cprb(userspace, pref_zq, xcrb, &ap_msg);
967960
if (!rc) {
968961
print_hex_dump_debug("ccarpl: ", DUMP_PREFIX_ADDRESS, 16, 1,
@@ -1220,7 +1213,6 @@ static long zcrypt_rng(char *buffer)
12201213
unsigned int wgt = 0, pref_wgt = 0;
12211214
unsigned int func_code = 0;
12221215
struct ap_message ap_msg;
1223-
unsigned int domain;
12241216
int qid = 0, rc = -ENODEV;
12251217
struct module *mod;
12261218

@@ -1229,7 +1221,7 @@ static long zcrypt_rng(char *buffer)
12291221
rc = ap_init_apmsg(&ap_msg, 0);
12301222
if (rc)
12311223
goto out;
1232-
rc = prep_rng_ap_msg(&ap_msg, &func_code, &domain);
1224+
rc = prep_rng_ap_msg(&ap_msg, &func_code, NULL);
12331225
if (rc)
12341226
goto out;
12351227

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ struct type86_fmt2_msg {
328328
static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
329329
struct ica_xcRB *xcrb,
330330
unsigned int *fcode,
331-
unsigned short **dom)
331+
unsigned int *domain)
332332
{
333333
static struct type6_hdr static_type6_hdrX = {
334334
.type = 0x06,
@@ -412,7 +412,8 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
412412
sizeof(msg->hdr.function_code));
413413

414414
*fcode = (msg->hdr.function_code[0] << 8) | msg->hdr.function_code[1];
415-
*dom = (unsigned short *)&msg->cprbx.domain;
415+
if (domain)
416+
*domain = msg->cprbx.domain;
416417

417418
/* check subfunction, US and AU need special flag with NQAP */
418419
if (memcmp(function_code, "US", 2) == 0 ||
@@ -529,7 +530,8 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
529530
else
530531
ap_msg->flags |= AP_MSG_FLAG_USAGE;
531532

532-
*domain = msg->cprbx.target_id;
533+
if (domain)
534+
*domain = msg->cprbx.target_id;
533535

534536
return 0;
535537
}
@@ -1056,15 +1058,16 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10561058
*/
10571059
int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb,
10581060
struct ap_message *ap_msg,
1059-
unsigned int *func_code, unsigned short **dom)
1061+
unsigned int *func_code, unsigned int *domain)
10601062
{
10611063
struct ap_response_type *resp_type = &ap_msg->response;
10621064

10631065
ap_msg->receive = zcrypt_msgtype6_receive;
10641066
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
10651067
atomic_inc_return(&zcrypt_step);
10661068
resp_type->type = CEXXC_RESPONSE_TYPE_XCRB;
1067-
return xcrb_msg_to_type6cprb_msgx(userspace, ap_msg, xcrb, func_code, dom);
1069+
return xcrb_msg_to_type6cprb_msgx(userspace, ap_msg,
1070+
xcrb, func_code, domain);
10681071
}
10691072

10701073
/*
@@ -1109,6 +1112,9 @@ static long zcrypt_msgtype6_send_cprb(bool userspace, struct zcrypt_queue *zq,
11091112
msg->hdr.fromcardlen1 -= delta;
11101113
}
11111114

1115+
/* update domain field within the CPRB struct */
1116+
msg->cprbx.domain = AP_QID_QUEUE(zq->queue->qid);
1117+
11121118
init_completion(&resp_type->work);
11131119
rc = ap_queue_message(zq->queue, ap_msg);
11141120
if (rc)
@@ -1214,8 +1220,7 @@ static long zcrypt_msgtype6_send_ep11_cprb(bool userspace, struct zcrypt_queue *
12141220
lfmt = 1; /* length format #1 */
12151221
}
12161222
payload_hdr = (struct pld_hdr *)((&msg->pld_lenfmt) + lfmt);
1217-
payload_hdr->dom_val = (unsigned int)
1218-
AP_QID_QUEUE(zq->queue->qid);
1223+
payload_hdr->dom_val = AP_QID_QUEUE(zq->queue->qid);
12191224
}
12201225

12211226
/*
@@ -1296,7 +1301,8 @@ static inline void rng_type6cprb_msgx(struct ap_message *ap_msg,
12961301
msg->verb_length = 0x02;
12971302
msg->key_length = 0x02;
12981303
ap_msg->len = sizeof(*msg);
1299-
*domain = (unsigned short)msg->cprbx.domain;
1304+
if (domain)
1305+
*domain = msg->cprbx.domain;
13001306
}
13011307

13021308
/*

drivers/s390/crypto/zcrypt_msgtype6.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct type86_fmt2_ext {
9696

9797
int prep_cca_ap_msg(bool userspace, struct ica_xcRB *xcrb,
9898
struct ap_message *ap_msg,
99-
unsigned int *fc, unsigned short **dom);
99+
unsigned int *fc, unsigned int *dom);
100100
int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb,
101101
struct ap_message *ap_msg,
102102
unsigned int *fc, unsigned int *dom);

0 commit comments

Comments
 (0)