Skip to content

Commit 7c4e91c

Browse files
hfreudeVasily Gorbik
authored andcommitted
s390/zcrypt: new sysfs attributes serialnr and mkvps
This patch extends the sysfs interface with two new attributes for the CEX4, CEX5 and CEX6 crypto cards/queues in coprocessor ('CCA') mode: /sys/devices/ap/cardxx/serialnr /sys/devices/ap/cardxx/xx.yyyy/mkvps The serialnr attribute is card based and shows the 8 character ASCII serial number string which should unique identify the card. The mkvps is queue based and displays 3 lines of information about the new, current and old master key register: AES NEW: <new_aes_mk_state> <new_aes_mk_mkvp> AES CUR: <cur_aes_mk_state> <cur_aes_mk_mkvp> AES OLD: <old_aes_mk_state> <old_aes_mk_mkvp> with <new_aes_mk_state>: 'empty' or 'partial' or 'full' <cur_aes_mk_state>: 'valid' or 'invalid' <old_aes_mk_state>: 'valid' or 'invalid' <new_aes_mk_mkvp>, <cur_aes_mk_mkvp>, <old_aes_mk_mkvp> 8 byte hex string with leading 0x MKVP means Master Key Verification Pattern and is a folded hash over the key value. Only the states 'full' and 'valid' result in displaying a useful mkvp, otherwise a mkvp of all bytes zero is shown. If for any reason the FQ fails and the (cached) information is not available, the state '-' will be shown with the mkvp value also '-'. The values shown here are the very same as the cca panel tools displays. As of now only the AES master keys states and verification patterns are shown. A CCA APQN also has similar master key registers for DES, RSA and ECC. So the content of this attribute may get extended. Reading the sysfs attribute automatically triggers an FQ CPRB to be sent to the queue as long as the queue is (soft-) online. For the serialnr attribute the queue with the default domain id is addressed (if available and valid). This is reasonable as it is assumed that this sysfs interface is not performance critical and on the other side a master key change should be visiable as soon as possible. When a queue is (soft-) offline however, the cached values are displayed. If no cached values are available, the serial number string will be empty and the mkvp lines will show state '-' and mkvp value '-'. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 94bbd34 commit 7c4e91c

3 files changed

Lines changed: 141 additions & 14 deletions

File tree

‎drivers/s390/crypto/zcrypt_ccamisc.c‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@
3333
/* Size of vardata block used for some of the cca requests/replies */
3434
#define VARDATASIZE 4096
3535

36-
/* struct to hold cached info for each CCA card/domain */
37-
struct cca_info {
38-
char new_mk_state; /* '1' Empty, '2' Partially full, '3' Full */
39-
char cur_mk_state; /* '1' Invalid, '2' Valid */
40-
char old_mk_state; /* '1' Invalid, '2' Valid */
41-
u64 new_mkvp; /* truncated sha256 hash of new master key */
42-
u64 cur_mkvp; /* truncated sha256 hash of current master key */
43-
u64 old_mkvp; /* truncated sha256 hash of old master key */
44-
char serial[9];
45-
};
46-
4736
struct cca_info_list_entry {
4837
struct list_head list;
4938
u16 cardnr;
@@ -164,9 +153,9 @@ static inline void prep_xcrb(struct ica_xcRB *pxcrb,
164153
pxcrb->user_defined = (cardnr == 0xFFFF ? AUTOSELECT : cardnr);
165154
pxcrb->request_control_blk_length =
166155
preqcblk->cprb_len + preqcblk->req_parml;
167-
pxcrb->request_control_blk_addr = (void *) preqcblk;
156+
pxcrb->request_control_blk_addr = (void __user *) preqcblk;
168157
pxcrb->reply_control_blk_length = preqcblk->rpl_msgbl;
169-
pxcrb->reply_control_blk_addr = (void *) prepcblk;
158+
pxcrb->reply_control_blk_addr = (void __user *) prepcblk;
170159
}
171160

172161
/*
@@ -820,6 +809,24 @@ static int fetch_cca_info(u16 cardnr, u16 domain, struct cca_info *ci)
820809
return found ? 0 : -ENOENT;
821810
}
822811

812+
/*
813+
* Fetch cca information about a CCA queue.
814+
*/
815+
int cca_get_info(u16 card, u16 dom, struct cca_info *ci, int verify)
816+
{
817+
int rc;
818+
819+
rc = cca_info_cache_fetch(card, dom, ci);
820+
if (rc || verify) {
821+
rc = fetch_cca_info(card, dom, ci);
822+
if (rc == 0)
823+
cca_info_cache_update(card, dom, ci);
824+
}
825+
826+
return rc;
827+
}
828+
EXPORT_SYMBOL(cca_get_info);
829+
823830
/*
824831
* Search for a matching crypto card based on the Master Key
825832
* Verification Pattern provided inside a secure key.

‎drivers/s390/crypto/zcrypt_ccamisc.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ int cca_query_crypto_facility(u16 cardnr, u16 domain,
9090
*/
9191
int cca_findcard(const u8 *seckey, u16 *pcardnr, u16 *pdomain, int verify);
9292

93+
/* struct to hold info for each CCA queue */
94+
struct cca_info {
95+
char new_mk_state; /* '1' empty, '2' partially full, '3' full */
96+
char cur_mk_state; /* '1' invalid, '2' valid */
97+
char old_mk_state; /* '1' invalid, '2' valid */
98+
u64 new_mkvp; /* truncated sha256 hash of new master key */
99+
u64 cur_mkvp; /* truncated sha256 hash of current master key */
100+
u64 old_mkvp; /* truncated sha256 hash of old master key */
101+
char serial[9]; /* serial number string (8 ascii numbers + 0x00) */
102+
};
103+
104+
/*
105+
* Fetch cca information about an CCA queue.
106+
*/
107+
int cca_get_info(u16 card, u16 dom, struct cca_info *ci, int verify);
108+
93109
void zcrypt_ccamisc_exit(void);
94110

95111
#endif /* _ZCRYPT_CCAMISC_H_ */

‎drivers/s390/crypto/zcrypt_cex4.c‎

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "zcrypt_msgtype50.h"
1919
#include "zcrypt_error.h"
2020
#include "zcrypt_cex4.h"
21+
#include "zcrypt_ccamisc.h"
2122

2223
#define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
2324
#define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
@@ -65,6 +66,85 @@ static struct ap_device_id zcrypt_cex4_queue_ids[] = {
6566

6667
MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
6768

69+
/*
70+
* CCA card addditional device attributes
71+
*/
72+
static ssize_t serialnr_show(struct device *dev,
73+
struct device_attribute *attr,
74+
char *buf)
75+
{
76+
struct cca_info ci;
77+
struct ap_card *ac = to_ap_card(dev);
78+
struct zcrypt_card *zc = ac->private;
79+
80+
memset(&ci, 0, sizeof(ci));
81+
82+
if (ap_domain_index >= 0)
83+
cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
84+
85+
return snprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
86+
}
87+
static DEVICE_ATTR_RO(serialnr);
88+
89+
static struct attribute *cca_card_attrs[] = {
90+
&dev_attr_serialnr.attr,
91+
NULL,
92+
};
93+
94+
static const struct attribute_group cca_card_attr_group = {
95+
.attrs = cca_card_attrs,
96+
};
97+
98+
/*
99+
* CCA queue addditional device attributes
100+
*/
101+
static ssize_t mkvps_show(struct device *dev,
102+
struct device_attribute *attr,
103+
char *buf)
104+
{
105+
int n = 0;
106+
struct cca_info ci;
107+
struct zcrypt_queue *zq = to_ap_queue(dev)->private;
108+
static const char * const cao_state[] = { "invalid", "valid" };
109+
static const char * const new_state[] = { "empty", "partial", "full" };
110+
111+
memset(&ci, 0, sizeof(ci));
112+
113+
cca_get_info(AP_QID_CARD(zq->queue->qid),
114+
AP_QID_QUEUE(zq->queue->qid),
115+
&ci, zq->online);
116+
117+
if (ci.new_mk_state >= '1' && ci.new_mk_state <= '3')
118+
n = snprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n",
119+
new_state[ci.new_mk_state - '1'], ci.new_mkvp);
120+
else
121+
n = snprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
122+
123+
if (ci.cur_mk_state >= '1' && ci.cur_mk_state <= '2')
124+
n += snprintf(buf + n, PAGE_SIZE - n, "AES CUR: %s 0x%016llx\n",
125+
cao_state[ci.cur_mk_state - '1'], ci.cur_mkvp);
126+
else
127+
n += snprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
128+
129+
if (ci.old_mk_state >= '1' && ci.old_mk_state <= '2')
130+
n += snprintf(buf + n, PAGE_SIZE - n, "AES OLD: %s 0x%016llx\n",
131+
cao_state[ci.old_mk_state - '1'], ci.old_mkvp);
132+
else
133+
n += snprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
134+
135+
return n;
136+
}
137+
static DEVICE_ATTR_RO(mkvps);
138+
139+
static struct attribute *cca_queue_attrs[] = {
140+
&dev_attr_mkvps.attr,
141+
NULL,
142+
};
143+
144+
static const struct attribute_group cca_queue_attr_group = {
145+
.attrs = cca_queue_attrs,
146+
};
147+
68148
/**
69149
* Probe function for CEX4/CEX5/CEX6 card device. It always
70150
* accepts the AP device since the bus_match already checked
@@ -194,8 +274,17 @@ static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
194274
if (rc) {
195275
ac->private = NULL;
196276
zcrypt_card_free(zc);
277+
goto out;
197278
}
198279

280+
if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
281+
rc = sysfs_create_group(&ap_dev->device.kobj,
282+
&cca_card_attr_group);
283+
if (rc)
284+
zcrypt_card_unregister(zc);
285+
}
286+
287+
out:
199288
return rc;
200289
}
201290

@@ -205,8 +294,11 @@ static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
205294
*/
206295
static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
207296
{
208-
struct zcrypt_card *zc = to_ap_card(&ap_dev->device)->private;
297+
struct ap_card *ac = to_ap_card(&ap_dev->device);
298+
struct zcrypt_card *zc = ac->private;
209299

300+
if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
301+
sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_group);
210302
if (zc)
211303
zcrypt_card_unregister(zc);
212304
}
@@ -251,6 +343,7 @@ static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
251343
} else {
252344
return -ENODEV;
253345
}
346+
254347
zq->queue = aq;
255348
zq->online = 1;
256349
atomic_set(&zq->load, 0);
@@ -261,8 +354,17 @@ static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
261354
if (rc) {
262355
aq->private = NULL;
263356
zcrypt_queue_free(zq);
357+
goto out;
358+
}
359+
360+
if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
361+
rc = sysfs_create_group(&ap_dev->device.kobj,
362+
&cca_queue_attr_group);
363+
if (rc)
364+
zcrypt_queue_unregister(zq);
264365
}
265366

367+
out:
266368
return rc;
267369
}
268370

@@ -275,6 +377,8 @@ static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
275377
struct ap_queue *aq = to_ap_queue(&ap_dev->device);
276378
struct zcrypt_queue *zq = aq->private;
277379

380+
if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
381+
sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_group);
278382
if (zq)
279383
zcrypt_queue_unregister(zq);
280384
}

0 commit comments

Comments
 (0)