s390/zcrypt: use kvmalloc instead of kmalloc for 256k alloc
authorHarald Freudenberger <freude@linux.ibm.com>
Mon, 23 Mar 2020 13:32:04 +0000 (14:32 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Fri, 27 Mar 2020 09:22:47 +0000 (10:22 +0100)
Tests showed that it may happen that a 256k kmalloc may fail
due to a temporary shortage on 256k slab entries.

The find functions for cca and ep11 use a 256k array to fetch the
states of all possible crypto cards and their domains in one
piece. With the patch now kvmalloc is used to allocate this
temporary memory as there is no need to have this memory area
physical continuously.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
drivers/s390/crypto/zcrypt_ccamisc.c
drivers/s390/crypto/zcrypt_ep11misc.c

index e6899107c586bd9c9a13cc53c2094f360020a7db..1b835398feec3081ef39e7fcd9bc348cd277a572 100644 (file)
@@ -1569,9 +1569,9 @@ static int findcard(u64 mkvp, u16 *pcardnr, u16 *pdomain,
                return -EINVAL;
 
        /* fetch status of all crypto cards */
-       device_status = kmalloc_array(MAX_ZDEV_ENTRIES_EXT,
-                                     sizeof(struct zcrypt_device_status_ext),
-                                     GFP_KERNEL);
+       device_status = kvmalloc_array(MAX_ZDEV_ENTRIES_EXT,
+                                      sizeof(struct zcrypt_device_status_ext),
+                                      GFP_KERNEL);
        if (!device_status)
                return -ENOMEM;
        zcrypt_device_status_mask_ext(device_status);
@@ -1641,7 +1641,7 @@ static int findcard(u64 mkvp, u16 *pcardnr, u16 *pdomain,
        } else
                rc = -ENODEV;
 
-       kfree(device_status);
+       kvfree(device_status);
        return rc;
 }
 
index d4caf46ff9df155963bf7d01a431212e70fd53d1..7dd987afcd555f72b3e848a3a4c8497993f77753 100644 (file)
@@ -1217,9 +1217,9 @@ int ep11_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
        struct ep11_card_info eci;
 
        /* fetch status of all crypto cards */
-       device_status = kmalloc_array(MAX_ZDEV_ENTRIES_EXT,
-                                     sizeof(struct zcrypt_device_status_ext),
-                                     GFP_KERNEL);
+       device_status = kvmalloc_array(MAX_ZDEV_ENTRIES_EXT,
+                                      sizeof(struct zcrypt_device_status_ext),
+                                      GFP_KERNEL);
        if (!device_status)
                return -ENOMEM;
        zcrypt_device_status_mask_ext(device_status);
@@ -1227,7 +1227,7 @@ int ep11_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
        /* allocate 1k space for up to 256 apqns */
        _apqns = kmalloc_array(256, sizeof(u32), GFP_KERNEL);
        if (!_apqns) {
-               kfree(device_status);
+               kvfree(device_status);
                return -ENOMEM;
        }
 
@@ -1282,7 +1282,7 @@ int ep11_findcard2(u32 **apqns, u32 *nr_apqns, u16 cardnr, u16 domain,
                rc = 0;
        }
 
-       kfree(device_status);
+       kvfree(device_status);
        return rc;
 }
 EXPORT_SYMBOL(ep11_findcard2);