Skip to content

Commit 2845ad7

Browse files
hfreudehcahca
authored andcommitted
s390/zcrypt: Remove CCA and EP11 card and domain info caches
Remove the caching of the CCA and EP11 card and domain info. In nearly all places where the card or domain info is fetched the verify param was enabled and thus the cache was bypassed. The only real place where info from the cache was used was in the sysfs pseudo files in cases where the card/queue was switched to "offline". All other callers insisted on getting fresh info and thus a communication to the card was enforced. 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-13-freude@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 02383ef commit 2845ad7

6 files changed

Lines changed: 47 additions & 232 deletions

File tree

drivers/s390/crypto/pkey_cca.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int cca_apqns4key(const u8 *key, u32 keylen, u32 flags,
109109
}
110110
rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF,
111111
minhwtype, AES_MK_SET,
112-
cur_mkvp, old_mkvp, 1);
112+
cur_mkvp, old_mkvp);
113113
if (rc)
114114
goto out;
115115

@@ -128,7 +128,7 @@ static int cca_apqns4key(const u8 *key, u32 keylen, u32 flags,
128128
}
129129
rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF,
130130
ZCRYPT_CEX7, APKA_MK_SET,
131-
cur_mkvp, old_mkvp, 1);
131+
cur_mkvp, old_mkvp);
132132
if (rc)
133133
goto out;
134134

@@ -173,7 +173,7 @@ static int cca_apqns4type(enum pkey_key_type ktype,
173173
minhwtype = ZCRYPT_CEX6;
174174
rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF,
175175
minhwtype, AES_MK_SET,
176-
cur_mkvp, old_mkvp, 1);
176+
cur_mkvp, old_mkvp);
177177
if (rc)
178178
goto out;
179179

@@ -186,7 +186,7 @@ static int cca_apqns4type(enum pkey_key_type ktype,
186186
old_mkvp = *((u64 *)alt_mkvp);
187187
rc = cca_findcard2(&_apqns, &_nr_apqns, 0xFFFF, 0xFFFF,
188188
ZCRYPT_CEX7, APKA_MK_SET,
189-
cur_mkvp, old_mkvp, 1);
189+
cur_mkvp, old_mkvp);
190190
if (rc)
191191
goto out;
192192

@@ -480,13 +480,13 @@ static int cca_verifykey(const u8 *key, u32 keylen,
480480
*keybitsize = t->bitsize;
481481
rc = cca_findcard2(&apqns, &nr_apqns, *card, *dom,
482482
ZCRYPT_CEX3C, AES_MK_SET,
483-
t->mkvp, 0, 1);
483+
t->mkvp, 0);
484484
if (!rc)
485485
*flags = PKEY_FLAGS_MATCH_CUR_MKVP;
486486
if (rc == -ENODEV) {
487487
rc = cca_findcard2(&apqns, &nr_apqns, *card, *dom,
488488
ZCRYPT_CEX3C, AES_MK_SET,
489-
0, t->mkvp, 1);
489+
0, t->mkvp);
490490
if (!rc)
491491
*flags = PKEY_FLAGS_MATCH_ALT_MKVP;
492492
}
@@ -513,13 +513,13 @@ static int cca_verifykey(const u8 *key, u32 keylen,
513513
*keybitsize = PKEY_SIZE_AES_256;
514514
rc = cca_findcard2(&apqns, &nr_apqns, *card, *dom,
515515
ZCRYPT_CEX6, AES_MK_SET,
516-
t->mkvp0, 0, 1);
516+
t->mkvp0, 0);
517517
if (!rc)
518518
*flags = PKEY_FLAGS_MATCH_CUR_MKVP;
519519
if (rc == -ENODEV) {
520520
rc = cca_findcard2(&apqns, &nr_apqns, *card, *dom,
521521
ZCRYPT_CEX6, AES_MK_SET,
522-
0, t->mkvp0, 1);
522+
0, t->mkvp0);
523523
if (!rc)
524524
*flags = PKEY_FLAGS_MATCH_ALT_MKVP;
525525
}

drivers/s390/crypto/zcrypt_ccamisc.c

Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@
3030
/* Size of vardata block used for some of the cca requests/replies */
3131
#define VARDATASIZE 4096
3232

33-
struct cca_info_list_entry {
34-
struct list_head list;
35-
u16 cardnr;
36-
u16 domain;
37-
struct cca_info info;
38-
};
39-
40-
/* a list with cca_info_list_entry entries */
41-
static LIST_HEAD(cca_info_list);
42-
static DEFINE_SPINLOCK(cca_info_list_lock);
43-
4433
/*
4534
* Cprb memory pool held for urgent cases where no memory
4635
* can be allocated via kmalloc. This pool is only used
@@ -1633,69 +1622,11 @@ int cca_query_crypto_facility(u16 cardnr, u16 domain,
16331622
}
16341623
EXPORT_SYMBOL(cca_query_crypto_facility);
16351624

1636-
static int cca_info_cache_fetch(u16 cardnr, u16 domain, struct cca_info *ci)
1637-
{
1638-
int rc = -ENOENT;
1639-
struct cca_info_list_entry *ptr;
1640-
1641-
spin_lock_bh(&cca_info_list_lock);
1642-
list_for_each_entry(ptr, &cca_info_list, list) {
1643-
if (ptr->cardnr == cardnr && ptr->domain == domain) {
1644-
memcpy(ci, &ptr->info, sizeof(*ci));
1645-
rc = 0;
1646-
break;
1647-
}
1648-
}
1649-
spin_unlock_bh(&cca_info_list_lock);
1650-
1651-
return rc;
1652-
}
1653-
1654-
static void cca_info_cache_update(u16 cardnr, u16 domain,
1655-
const struct cca_info *ci)
1656-
{
1657-
int found = 0;
1658-
struct cca_info_list_entry *ptr;
1659-
1660-
spin_lock_bh(&cca_info_list_lock);
1661-
list_for_each_entry(ptr, &cca_info_list, list) {
1662-
if (ptr->cardnr == cardnr &&
1663-
ptr->domain == domain) {
1664-
memcpy(&ptr->info, ci, sizeof(*ci));
1665-
found = 1;
1666-
break;
1667-
}
1668-
}
1669-
if (!found) {
1670-
ptr = kmalloc(sizeof(*ptr), GFP_ATOMIC);
1671-
if (!ptr) {
1672-
spin_unlock_bh(&cca_info_list_lock);
1673-
return;
1674-
}
1675-
ptr->cardnr = cardnr;
1676-
ptr->domain = domain;
1677-
memcpy(&ptr->info, ci, sizeof(*ci));
1678-
list_add(&ptr->list, &cca_info_list);
1679-
}
1680-
spin_unlock_bh(&cca_info_list_lock);
1681-
}
1682-
1683-
static void __exit mkvp_cache_free(void)
1684-
{
1685-
struct cca_info_list_entry *ptr, *pnext;
1686-
1687-
spin_lock_bh(&cca_info_list_lock);
1688-
list_for_each_entry_safe(ptr, pnext, &cca_info_list, list) {
1689-
list_del(&ptr->list);
1690-
kfree(ptr);
1691-
}
1692-
spin_unlock_bh(&cca_info_list_lock);
1693-
}
1694-
16951625
/*
1696-
* Fetch cca_info values via query_crypto_facility from adapter.
1626+
* Fetch cca_info values about a CCA queue via
1627+
* query_crypto_facility from adapter.
16971628
*/
1698-
static int fetch_cca_info(u16 cardnr, u16 domain, struct cca_info *ci)
1629+
int cca_get_info(u16 cardnr, u16 domain, struct cca_info *ci)
16991630
{
17001631
int rc, found = 0;
17011632
size_t rlen, vlen;
@@ -1765,28 +1696,10 @@ static int fetch_cca_info(u16 cardnr, u16 domain, struct cca_info *ci)
17651696
free_page((unsigned long)pg);
17661697
return found == 2 ? 0 : -ENOENT;
17671698
}
1768-
1769-
/*
1770-
* Fetch cca information about a CCA queue.
1771-
*/
1772-
int cca_get_info(u16 card, u16 dom, struct cca_info *ci, int verify)
1773-
{
1774-
int rc;
1775-
1776-
rc = cca_info_cache_fetch(card, dom, ci);
1777-
if (rc || verify) {
1778-
rc = fetch_cca_info(card, dom, ci);
1779-
if (rc == 0)
1780-
cca_info_cache_update(card, dom, ci);
1781-
}
1782-
1783-
return rc;
1784-
}
17851699
EXPORT_SYMBOL(cca_get_info);
17861700

17871701
int cca_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
1788-
int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp,
1789-
int verify)
1702+
int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp)
17901703
{
17911704
struct zcrypt_device_status_ext *device_status;
17921705
u32 *_apqns = NULL, _nr_apqns = 0;
@@ -1827,7 +1740,7 @@ int cca_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
18271740
if (domain != 0xFFFF && dom != domain)
18281741
continue;
18291742
/* get cca info on this apqn */
1830-
if (cca_get_info(card, dom, &ci, verify))
1743+
if (cca_get_info(card, dom, &ci))
18311744
continue;
18321745
/* current master key needs to be valid */
18331746
if (mktype == AES_MK_SET && ci.cur_aes_mk_state != '2')
@@ -1900,7 +1813,6 @@ int __init zcrypt_ccamisc_init(void)
19001813

19011814
void zcrypt_ccamisc_exit(void)
19021815
{
1903-
mkvp_cache_free();
19041816
mutex_lock(&dev_status_mem_mutex);
19051817
kvfree(dev_status_mem);
19061818
mutex_unlock(&dev_status_mem_mutex);

drivers/s390/crypto/zcrypt_ccamisc.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ int cca_query_crypto_facility(u16 cardnr, u16 domain,
215215
* - if minhwtype > 0 only apqns with hwtype >= minhwtype
216216
* - if cur_mkvp != 0 only apqns where cur_mkvp == mkvp
217217
* - if old_mkvp != 0 only apqns where old_mkvp == mkvp
218-
* - if verify is enabled and a cur_mkvp and/or old_mkvp
219-
* value is given, then refetch the cca_info and make sure the current
220-
* cur_mkvp or old_mkvp values of the apqn are used.
221218
* The mktype determines which set of master keys to use:
222219
* 0 = AES_MK_SET - AES MK set, 1 = APKA MK_SET - APKA MK set
223220
* The array of apqn entries is allocated with kmalloc and returned in *apqns;
@@ -228,8 +225,7 @@ int cca_query_crypto_facility(u16 cardnr, u16 domain,
228225
* -ENODEV is returned.
229226
*/
230227
int cca_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
231-
int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp,
232-
int verify);
228+
int minhwtype, int mktype, u64 cur_mkvp, u64 old_mkvp);
233229

234230
#define AES_MK_SET 0
235231
#define APKA_MK_SET 1
@@ -261,7 +257,7 @@ struct cca_info {
261257
/*
262258
* Fetch cca information about an CCA queue.
263259
*/
264-
int cca_get_info(u16 card, u16 dom, struct cca_info *ci, int verify);
260+
int cca_get_info(u16 card, u16 dom, struct cca_info *ci);
265261

266262
int zcrypt_ccamisc_init(void);
267263
void zcrypt_ccamisc_exit(void);

drivers/s390/crypto/zcrypt_cex4.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,13 @@ static ssize_t cca_serialnr_show(struct device *dev,
7979
struct device_attribute *attr,
8080
char *buf)
8181
{
82-
struct zcrypt_card *zc = dev_get_drvdata(dev);
83-
struct cca_info ci;
8482
struct ap_card *ac = to_ap_card(dev);
83+
struct cca_info ci;
8584

8685
memset(&ci, 0, sizeof(ci));
8786

8887
if (ap_domain_index >= 0)
89-
cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
88+
cca_get_info(ac->id, ap_domain_index, &ci);
9089

9190
return sysfs_emit(buf, "%s\n", ci.serial);
9291
}
@@ -110,17 +109,17 @@ static ssize_t cca_mkvps_show(struct device *dev,
110109
struct device_attribute *attr,
111110
char *buf)
112111
{
112+
static const char * const new_state[] = { "empty", "partial", "full" };
113+
static const char * const cao_state[] = { "invalid", "valid" };
113114
struct zcrypt_queue *zq = dev_get_drvdata(dev);
114-
int n = 0;
115115
struct cca_info ci;
116-
static const char * const cao_state[] = { "invalid", "valid" };
117-
static const char * const new_state[] = { "empty", "partial", "full" };
116+
int n = 0;
118117

119118
memset(&ci, 0, sizeof(ci));
120119

121120
cca_get_info(AP_QID_CARD(zq->queue->qid),
122121
AP_QID_QUEUE(zq->queue->qid),
123-
&ci, zq->online);
122+
&ci);
124123

125124
if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3')
126125
n += sysfs_emit_at(buf, n, "AES NEW: %s 0x%016llx\n",
@@ -210,13 +209,12 @@ static ssize_t ep11_api_ordinalnr_show(struct device *dev,
210209
struct device_attribute *attr,
211210
char *buf)
212211
{
213-
struct zcrypt_card *zc = dev_get_drvdata(dev);
214-
struct ep11_card_info ci;
215212
struct ap_card *ac = to_ap_card(dev);
213+
struct ep11_card_info ci;
216214

217215
memset(&ci, 0, sizeof(ci));
218216

219-
ep11_get_card_info(ac->id, &ci, zc->online);
217+
ep11_get_card_info(ac->id, &ci);
220218

221219
if (ci.API_ord_nr > 0)
222220
return sysfs_emit(buf, "%u\n", ci.API_ord_nr);
@@ -231,13 +229,12 @@ static ssize_t ep11_fw_version_show(struct device *dev,
231229
struct device_attribute *attr,
232230
char *buf)
233231
{
234-
struct zcrypt_card *zc = dev_get_drvdata(dev);
235-
struct ep11_card_info ci;
236232
struct ap_card *ac = to_ap_card(dev);
233+
struct ep11_card_info ci;
237234

238235
memset(&ci, 0, sizeof(ci));
239236

240-
ep11_get_card_info(ac->id, &ci, zc->online);
237+
ep11_get_card_info(ac->id, &ci);
241238

242239
if (ci.FW_version > 0)
243240
return sysfs_emit(buf, "%d.%d\n",
@@ -254,13 +251,12 @@ static ssize_t ep11_serialnr_show(struct device *dev,
254251
struct device_attribute *attr,
255252
char *buf)
256253
{
257-
struct zcrypt_card *zc = dev_get_drvdata(dev);
258-
struct ep11_card_info ci;
259254
struct ap_card *ac = to_ap_card(dev);
255+
struct ep11_card_info ci;
260256

261257
memset(&ci, 0, sizeof(ci));
262258

263-
ep11_get_card_info(ac->id, &ci, zc->online);
259+
ep11_get_card_info(ac->id, &ci);
264260

265261
if (ci.serial[0])
266262
return sysfs_emit(buf, "%16.16s\n", ci.serial);
@@ -291,14 +287,13 @@ static ssize_t ep11_card_op_modes_show(struct device *dev,
291287
struct device_attribute *attr,
292288
char *buf)
293289
{
294-
struct zcrypt_card *zc = dev_get_drvdata(dev);
295-
int i, n = 0;
296-
struct ep11_card_info ci;
297290
struct ap_card *ac = to_ap_card(dev);
291+
struct ep11_card_info ci;
292+
int i, n = 0;
298293

299294
memset(&ci, 0, sizeof(ci));
300295

301-
ep11_get_card_info(ac->id, &ci, zc->online);
296+
ep11_get_card_info(ac->id, &ci);
302297

303298
for (i = 0; ep11_op_modes[i].mode_txt; i++) {
304299
if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {

0 commit comments

Comments
 (0)