Re: [PATCH v3 04/21] s390/ap/zcrypt: New xflag parameter

Heiko Carstens
2025-03-31T11:03:31Z

On Thu, Mar 27, 2025 at 03:39:24PM +0100, Harald Freudenberger wrote:
> Introduce a new flag parameter for the both cprb send functions
> zcrypt_send_cprb() and zcrypt_send_ep11_cprb(). This new
> xflags parameter ("execution flags") shall be used to provide
> execution hints and flags for this crypto request.
>
> There are two flags implemented to be used with these functions:
> * ZCRYPT_XFLAG_USERSPACE - indicates to the lower layers that
> all the ptrs address userspace. So when construction the ap msg
> copy_from_user() is to be used. If this flag is NOT set, the ptrs
> address kernel memory and thus memcpy() is to be used.
> * ZCRYPT_XFLAG_NOMEMALLOC - indicates that this task must not
> allocate memory which may be allocated with io operations.
> For the zcrypt layer this limits the number of EP11 targets
> to 16 APQNs. But as this flag is passed down the stack, it
> may induce further restrictions.

And this magic 16 APQNs is not a problem, because...?

> -static long _zcrypt_send_ep11_cprb(bool userspace, struct ap_perms *perms,
> +static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms,
> struct zcrypt_track *tr,
> struct ep11_urb *xcrb)
> {
> + bool userspace = xflags & ZCRYPT_XFLAG_USERSPACE;
> struct zcrypt_card *zc, *pref_zc;
> struct zcrypt_queue *zq, *pref_zq;
> - struct ep11_target_dev *targets;
> + struct ep11_target_dev targetbuf[16], *targets = NULL;

This "16" and the possible limitations that come this this should be
documented somewhere.

> + if (targets && targets != targetbuf)
> + kfree(targets);

Please no NULL checks for kfree:

if (targets != targetbuf)
kfree(targets);

> +/*
> + * xflags - to be used with zcrypt_send_cprb() and
> + * zcrypt_send_ep11_cprb() for the xflags parameter.
> + */
> +#define ZCRYPT_XFLAG_USERSPACE 0x0001 /* data ptrs address userspace */
> +#define ZCRYPT_XFLAG_NOMEMALLOC 0x0002 /* do not allocate fresh memory */

What is the definition of "fresh" memory?