mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Holger Dengler <dengler@linux.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Heiko Carstens <hca@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Harald Freudenberger <freude@linux.ibm.com>,
	Vineeth Vijayan <vneethv@linux.ibm.com>,
	Peter Oberparleiter <oberpar@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Date: Fri, 31 Jul 2026 09:44:57 +0200	[thread overview]
Message-ID: <18c36e42-8f96-479c-8152-2da3f5034f04@linux.ibm.com> (raw)
In-Reply-To: <20260730124819.GA776954@noisy.programming.kicks-ass.net>

On 7/30/26 14:48, Peter Zijlstra wrote:
> On Thu, Jul 30, 2026 at 01:34:31PM +0200, Holger Dengler wrote:
>> Peter,
>>
>> On 7/30/26 12:11, Peter Zijlstra wrote:
>>> On Thu, Jul 30, 2026 at 07:29:04AM +0200, Heiko Carstens wrote:
>>>> With [1] cond_resched() is always compiled away and becomes a no-op.
>>>>
>>>> The comments for all cond_resched() calls in crypto code however indicate
>>>> that the current process should be scheduled away to avoid instant
>>>> re-invocation of a callback. This is not what cond_resched() would do or
>>>> did.
>>>>
>>>> Instead of just removing the cond_resched() calls, replace them with
>>>> msleep() calls, as suggested by Holger Dengler. This forces the current
>>>> task to be scheduled away (sleeps) like originally intended.
>>>>
>>>> [1] commit 7dadeaa6e851 ("sched: Further restrict the preemption modes")
>>>>
>>>> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
>>>> ---
>>>>  arch/s390/crypto/paes_s390.c  | 8 ++++----
>>>>  arch/s390/crypto/phmac_s390.c | 4 ++--
>>>>  2 files changed, 6 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/arch/s390/crypto/paes_s390.c b/arch/s390/crypto/paes_s390.c
>>>> index 8cfe6166c193..511cb6105436 100644
>>>> --- a/arch/s390/crypto/paes_s390.c
>>>> +++ b/arch/s390/crypto/paes_s390.c
>>>> @@ -555,7 +555,7 @@ static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq)
>>>>  		 * To avoid immediately re-invocation of this callback,
>>>>  		 * tell the scheduler to voluntarily give up the CPU here.
>>>>  		 */
>>>> -		cond_resched();
>>>> +		msleep(1);
>>>>  		pr_debug("rescheduling request\n");
>>>>  		return -ENOSPC;
>>>>  	} else if (rc) {
>>>
>>> I am somewhat conflicted on this. It will add a 'random' delay to this
>>> crypto user (which might be real-time task) that is not related to the
>>> actual event this is waiting for.
>>>
>>> That is, it could be that this key expiration thing is sorted way faster
>>> than this one milisecond.
>>>
>>> Is there nothing the crypto layer can do that is more clever; like a
>>> condition variable on the key update when -ENOSPC is returned or
>>> something.
>>
>> Let me give a bit of background here: The protected key can only get
>> invalid, if the linux instance (z/VM or KVM guest) is moved to another
>> hypervisor on a different machine (aka life guest relocation). In such a
>> case, the crypto accelerator card and the host has to exchange the "real
>> key", which is wrapped by the host and handed back to the guest as the
>> re-newed protected key. Unfortunately there is no asynchronous trigger
>> on completion, you have to re-try (and maybe get another "in progress"
>> return).
>>
>> And as if that weren't bad enough, if this key exchange between card and
>> host is the first one, card and host has to instanciate a secure
>> communication channel (including a key exchange for the transport layer).
>>
>> I agree, this sounds rally bad for real-time tasks. But we're talking
>> about 2nd-level virtualization (with non-real-time hypervisors below)
>> and about cases, which can only happen right after a guest relocation to
>> another machine. Would the current solution be acceptable under these
>> circumstances?
> 
> Yes, guest migration is very likely far more disruptive than most
> anything else. Perhaps clarify the code comment to include some of this
> explanation?

I agree, the comment is not telling all main key points. What about the
following?

/*
 * Protected key expired due to relocation to another
 * host. The long runnning re-wrap has no asynchronous
 * completion notification, so polling is required.
 * Trigger a re-schedule of this request by returning
 * -ENOSPC ("hardware queue full") to the crypto engine.
 * To avoid immediately re-invocation of this callback,
 * tell scheduler to voluntarily give up the CPU here.
 */

(I would leave it up to Heiko to merge the comment in his series, or let
Harald/me do it in a separate patch)

-- 
Mit freundlichen Grüßen / Kind regards
Holger Dengler


  reply	other threads:[~2026-07-31  7:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  5:29 [PATCH v3 0/4] s390: Remove or replace cond_resched() calls Heiko Carstens
2026-07-30  5:29 ` [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1) Heiko Carstens
2026-07-30  7:47   ` Holger Dengler
2026-07-30 10:11   ` Peter Zijlstra
2026-07-30 11:34     ` Holger Dengler
2026-07-30 12:48       ` Peter Zijlstra
2026-07-31  7:44         ` Holger Dengler [this message]
2026-07-31  8:40           ` Peter Zijlstra
2026-07-31 11:56             ` Heiko Carstens
2026-07-30  5:29 ` [PATCH v3 2/4] KVM: s390: Remove cond_resched() calls Heiko Carstens
2026-07-30  8:51   ` Claudio Imbrenda
2026-07-30  5:29 ` [PATCH v3 3/4] " Heiko Carstens
2026-07-30  5:29 ` [PATCH v3 4/4] s390/cio: " Heiko Carstens

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=18c36e42-8f96-479c-8152-2da3f5034f04@linux.ibm.com \
    --to=dengler@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=imbrenda@linux.ibm.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=oberpar@linux.ibm.com \
    --cc=peterz@infradead.org \
    --cc=svens@linux.ibm.com \
    --cc=vneethv@linux.ibm.com \
    /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

all inboxes | Powered by JetHome®