Re: [PATCH v4 07/24] s390/zcrypt: Introduce cprb mempool for ep11 misc functions

Harald Freudenberger
2025-04-14T14:21:24Z

On 2025-04-11 14:58, Holger Dengler wrote:
> On 09/04/2025 16:02, Harald Freudenberger wrote:
>> Introduce a cprb mempool for the zcrypt ep11 misc functions
>> (zcrypt_ep11misc.*) do some preparation rework to support
>> a do-not-allocate path through some zcrypt ep11 misc functions.
>>
>> The mempool is controlled by the zcrypt module parameter
>> "mempool_threshold" which shall control the minimal amount
>> of memory items for CCA and EP11.
>>
>> The mempool shall support "mempool_threshold" requests/replies
>> in parallel which means for EP11 to hold a send and receive
>> buffer memory per request. Each of this cprb space items is
>> limited to 8 KB. So by default the mempool consumes
>> 5 * 2 * 8KB = 80KB
>>
>> If the mempool is depleted upon one ep11 misc functions is
>> called with the ZCRYPT_XFLAG_NOMEMALLOC xflag set, the function
>> will fail with -ENOMEM and the caller is responsible for taking
>> further actions.
>>
>> This is only part of an rework to support a new xflag
>> ZCRYPT_XFLAG_NOMEMALLOC but not yet complete.
>>
>> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
>> Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
>
> With the requested changes below, you can keep my R-b.
>
>> ---
>> drivers/s390/crypto/zcrypt_api.c | 6 +
>> drivers/s390/crypto/zcrypt_ep11misc.c | 153
>> ++++++++++++++++----------
>> drivers/s390/crypto/zcrypt_ep11misc.h | 1 +
>> 3 files changed, 99 insertions(+), 61 deletions(-)
>>
> [...]
>> diff --git a/drivers/s390/crypto/zcrypt_ep11misc.c
>> b/drivers/s390/crypto/zcrypt_ep11misc.c
>> index b60e262bcaa3..00e9d141a456 100644
>> --- a/drivers/s390/crypto/zcrypt_ep11misc.c
>> +++ b/drivers/s390/crypto/zcrypt_ep11misc.c
> [...]
>> @@ -411,12 +420,19 @@ EXPORT_SYMBOL(ep11_check_aes_key);
>> /*
>> * Allocate and prepare ep11 cprb plus additional payload.
>> */
>> -static inline struct ep11_cprb *alloc_cprb(size_t payload_len)
>> +static void *alloc_cprbmem(size_t payload_len, u32 xflags)
>> {
>> size_t len = sizeof(struct ep11_cprb) + payload_len;
>> - struct ep11_cprb *cprb;
>> + struct ep11_cprb *cprb = NULL;
>>
>> - cprb = kzalloc(len, GFP_KERNEL);
>> + if (xflags & ZCRYPT_XFLAG_NOMEMALLOC) {
>> + if (cprb_mempool && len <= CPRB_MEMPOOL_ITEM_SIZE) {
>> + cprb = mempool_alloc_preallocated(cprb_mempool);
>> + memset(cprb, 0, len);
>> + }
>> + } else {
>> + cprb = kzalloc(len, GFP_KERNEL);
>> + }
>> if (!cprb)
>> return NULL;
>
> Same as in the previous patch:
> - no check for cprb_mempool != NULL
> - use kmalloc()
> - move memset() down
>
> [...]

Done