linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harald Freudenberger <freude@linux.ibm.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	davem@davemloft.net, dengler@linux.ibm.com,
	linux-s390@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH v10 2/5] s390/crypto: New s390 specific protected key hash phmac
Date: Wed, 12 Feb 2025 12:17:46 +0100	[thread overview]
Message-ID: <9971160da17b1d18d4bdc87fc1297fda@linux.ibm.com> (raw)
In-Reply-To: <20250209163430.GB1230@sol.localdomain>

On 2025-02-09 17:34, Eric Biggers wrote:
> On Sun, Feb 09, 2025 at 04:47:57PM +0800, Herbert Xu wrote:
>> On Wed, Jan 15, 2025 at 05:22:28PM +0100, Harald Freudenberger wrote:
>> >
>> > +static int s390_phmac_init(struct ahash_request *req)
>> > +{
>> > +	struct s390_phmac_req_ctx *req_ctx = ahash_request_ctx(req);
>> > +	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
>> > +	struct s390_kmac_sha2_ctx *ctx = &req_ctx->sha2_ctx;
>> > +	int rc;
>> > +
>> > +	/*
>> > +	 * First try synchronous. If this fails for any reason
>> > +	 * schedule this request asynchronous via workqueue.
>> > +	 */
>> > +
>> > +	rc = phmac_init(tfm, ctx, false);
>> > +	if (!rc)
>> > +		goto out;
>> > +
>> > +	req_ctx->req = req;
>> > +	INIT_DELAYED_WORK(&req_ctx->work, phmac_wq_init_fn);
>> > +	schedule_delayed_work(&req_ctx->work, 0);
>> > +	rc = -EINPROGRESS;
>> 
>> This creates a resource problem because there is no limit on how
>> many requests that can be delayed in this manner for a given tfm.
>> 
>> When we hit this case, I presume this is a system-wide issue and
>> all requests would go pending? If that is the case, I suggest
>> allocating a system-wide queue through crypto_engine and using
>> that to limit how many requests that can become EINPROGRESS.
> 
> Or just make it synchronous which would be way easier, and the calling 
> code uses
> it synchronously anyway.
> 
> - Eric

A word about synchronous vs asynchronous...

As a synchronous hash (or chipher or whatever) MUST NOT sleep I can't
really implement the pkey stuff in a synchronous way:

The issue with pkey (We call it "protected key") is that it is some kind
of hardware based key. As such it needs some special preparation action
to be done upfront in the hardware/firmware to use such a pkey.
Now think about KVM live guest migration where a guest suddenly awakes
(Well the guest is not even aware of this) on a new machine with another
hardware. So out of the sudden a hardware based crypto operation fails
with an indication that the hardware/firmware can't deal with this
key object and needs re-preparation. Usually this preparation step is
some kind of asynchronous operation (write some pci registers or run
some DMA sequences or refresh the working key material via an HSM
communication...) and as such may take some time and involve even
sleeping on a mutex or completion until another kernel thread is done.
Please note this is not unique to pkey on system z but may apply
to all kinds of hardware/firmware based keys in situations like
KVM live guest migration or suspend/resume.

So for the pkey algorithms I can't guarantee that all the crypto
operations do never sleep and thus an asynchronous implementation
is the only way and makes sense to me.

There are other downsides with the asynch implementations:
They are much more complex and thus expensive and - how the hell can a
test cover all the code branches?
Next is the thing with the CRYPTO_ALG_ALLOCATES_MEMORY flag. If I
want to have a hash implementation usable for dm-integrity the alg
implementation must NOT set this flag and must not allocate any memory
during crypto operations (includung setkey()). As of now I am still not
through with the phmac code for this. And I only have a faint idea on
how to implement this on the pkey and maybe zcrypt code...

kind regards
Harald Freudenberger


  parent reply	other threads:[~2025-02-12 11:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-15 16:22 New s390 specific protected key hmac Harald Freudenberger
2025-01-15 16:22 ` [PATCH v10 1/5] s390/crypto: Add protected key hmac subfunctions for KMAC Harald Freudenberger
2025-01-15 16:22 ` [PATCH v10 2/5] s390/crypto: New s390 specific protected key hash phmac Harald Freudenberger
2025-02-09  8:47   ` Herbert Xu
2025-02-09 16:34     ` Eric Biggers
2025-02-10  7:57       ` Herbert Xu
2025-02-10 16:32         ` Eric Biggers
2025-02-10 23:14           ` Herbert Xu
2025-02-12 11:17       ` Harald Freudenberger [this message]
2025-02-12 15:20         ` Eric Biggers
2025-02-13  4:08         ` Herbert Xu
2025-02-11 12:09   ` Harald Freudenberger
2025-02-11 15:31     ` Eric Biggers
2025-02-12  3:19     ` Herbert Xu
2025-02-12  3:23       ` Herbert Xu
2025-02-12  3:32         ` Eric Biggers
2025-02-22  8:23           ` Herbert Xu
2025-01-15 16:22 ` [PATCH v10 3/5] crypto: api - Add crypto_tfm_alg_get_flags() helper inline function Harald Freudenberger
2025-01-15 16:22 ` [PATCH v10 4/5] s390/crypto: Add selftest support for phmac Harald Freudenberger
2025-01-15 16:22 ` [PATCH v10 5/5] crypto: testmgr - Enable phmac selftest Harald Freudenberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9971160da17b1d18d4bdc87fc1297fda@linux.ibm.com \
    --to=freude@linux.ibm.com \
    --cc=davem@davemloft.net \
    --cc=dengler@linux.ibm.com \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).