s390: Remove or replace cond_resched() calls
Subsystems (8)
Heiko Carstens
maintainerPATCH v3 1/4 s390/crypto: Replace cond_resched() with msleep(1)
In reply to Heiko CarstensWith [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")
--- arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
arch/s390/crypto/paes_s390.c +4 -4
@@ -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) {
@@ -821,7 +821,7 @@ static int cbc_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) {
@@ -1129,7 +1129,7 @@ static int ctr_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) {
@@ -1572,7 +1572,7 @@ static int xts_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) {
arch/s390/crypto/phmac_s390.c +2 -2
@@ -895,7 +895,7 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq)* tell scheduler to voluntarily give up the CPU here. */ pr_debug ("rescheduling request\n" ); -cond_resched (); +msleep (1 );return -ENOSPC ; }else if (rc) {hwh_advance (hwh, rc);
@@ -916,7 +916,7 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq)* tell scheduler to voluntarily give up the CPU here. */ pr_debug ("rescheduling request\n" ); -cond_resched (); +msleep (1 );return -ENOSPC ; }break ;
Signature · 1 line
2.53.0
Heiko Carstens
maintainerPATCH v3 3/4 s390: Remove cond_resched() calls
In reply to Heiko CarstensSince [1] cond_resched() is a no-op on s390. Remove all calls.
[1] commit 7dadeaa6e851 ("sched: Further restrict the preemption modes")
--- arch/s390/kernel/perf_cpum_cf.c | 1 - arch/s390/mm/cmm.c | 2 -- arch/s390/mm/pageattr.c | 5 ----- arch/s390/mm/pgalloc.c | 1 - arch/s390/pci/pci.c | 4 +--- 5 files changed, 1 insertion(+), 12 deletions(-)
arch/s390/kernel/perf_cpum_cf.c +0 -1
@@ -1496,7 +1496,6 @@ static int cfset_all_copy(unsigned long arg, cpumask_t *mask) goto out; } uptr +=sizeof (struct s390_ctrset_cpudata ) + cpuhw->used; -cond_resched (); } cpus =cpumask_weight (mask);if (put_user (cpus, &ctrset_read->no_cpus))
arch/s390/mm/cmm.c +0 -2
@@ -95,7 +95,6 @@ static long cmm_alloc_pages(long nr, long *counter, (*counter)++;spin_unlock (&cmm_lock); nr--; -cond_resched (); }return nr; }
@@ -134,7 +133,6 @@ static long cmm_free_pages(long nr, long *counter, struct cmm_page_array **list) inc =__cmm_free_pages (inc, counter, list);if (inc)break ; -cond_resched (); }return nr + inc; }
arch/s390/mm/pageattr.c +0 -5
@@ -105,7 +105,6 @@ static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,pgt_set ((unsigned long *)ptep,pte_val (new), addr,CRDTE_DTT_PAGE ); ptep++; addr +=PAGE_SIZE ; -cond_resched (); }while (addr < end);return 0 ; }
@@ -194,7 +193,6 @@ static int walk_pmd_level(pud_t *pudp, unsigned long addr, unsigned long end, } pmdp++; addr = next; -cond_resched (); }while (addr < end);return rc; }
@@ -281,7 +279,6 @@ static int walk_pud_level(p4d_t *p4d, unsigned long addr, unsigned long end, } pudp++; addr = next; -cond_resched (); }while (addr < end && !rc);return rc; }
@@ -301,7 +298,6 @@ static int walk_p4d_level(pgd_t *pgd, unsigned long addr, unsigned long end, rc =walk_pud_level (p4dp, addr, next, flags); p4dp++; addr = next; -cond_resched (); }while (addr < end && !rc);return rc; }
@@ -323,7 +319,6 @@ static int change_page_attr(unsigned long addr, unsigned long end, rc =walk_p4d_level (pgdp, addr, next, flags);if (rc)break ; -cond_resched (); }while (pgdp++, addr = next, addr < end && !rc);return rc; }
arch/s390/mm/pgalloc.c +0 -1
@@ -268,7 +268,6 @@ static int base_segment_walk(unsigned long *origin, unsigned long addr,return rc;if (!alloc)base_pgt_free (table); -cond_resched (); }while (ste++, addr = next, addr < end);return 0 ; }
arch/s390/pci/pci.c +1 -3
@@ -1173,10 +1173,8 @@ int zpci_scan_devices(void)return rc;zpci_add_devices (&scan_list); -zpci_bus_for_each (zbus) { +zpci_bus_for_each (zbus)zpci_bus_scan_bus (zbus); -cond_resched (); - }return 0 ; }
Signature · 1 line
2.53.0
Heiko Carstens
maintainerv3 cover s390: Remove or replace cond_resched() calls
v3:
- Drop uv_call_sched() [Claudio Imbrenda]
v2:
- Use msleep() in crypto code (Holger Dengler)
- Add Reviewed-by tag from Peter Oberparleiter
v1:
Since [1] it is only possible to select the PREEMPT or PREEMPT_LAZY preemption models for s390. This has caused some minor problems, but everything has been addressed.
Given that for both preemption models cond_resched() is a no-op remove or replace it everywhere.
[1] commit 7dadeaa6e851 ("sched: Further restrict the preemption modes")
Heiko Carstens (4):
s390/crypto: Replace cond_resched() with msleep(1)
KVM: s390: Remove cond_resched() calls
s390: Remove cond_resched() calls s390/cio: Remove cond_resched() calls
arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- arch/s390/include/asm/uv.h | 16 ++-------------- arch/s390/kernel/perf_cpum_cf.c | 1 - arch/s390/kernel/uv.c | 2 +- arch/s390/kvm/gaccess.c | 8 ++------ arch/s390/kvm/gmap.c | 4 ---- arch/s390/kvm/kvm-s390.c | 1 - arch/s390/kvm/pv.c | 11 +++++------ arch/s390/kvm/vsie.c | 1 - arch/s390/mm/cmm.c | 2 -- arch/s390/mm/gmap_helpers.c | 1 - arch/s390/mm/pageattr.c | 5 ----- arch/s390/mm/pgalloc.c | 1 - arch/s390/pci/pci.c | 4 +--- drivers/s390/char/uvdevice.c | 6 +++--- drivers/s390/cio/css.c | 8 -------- 17 files changed, 20 insertions(+), 63 deletions(-)
Signature · 1 line
2.53.0
Heiko Carstens
maintainerPATCH v3 2/4 KVM: s390: Remove cond_resched() calls
Since [1] cond_resched() is a no-op on s390. Remove all calls.
This also entirely removes uv_call_sched() and replaces all call sites with uv_call(), since both functions are identical after the removal of cond_resched().
[1] commit 7dadeaa6e851 ("sched: Further restrict the preemption modes")
--- arch/s390/include/asm/uv.h | 16 ++-------------- arch/s390/kernel/uv.c | 2 +- arch/s390/kvm/gaccess.c | 8 ++------ arch/s390/kvm/gmap.c | 4 ---- arch/s390/kvm/kvm-s390.c | 1 - arch/s390/kvm/pv.c | 11 +++++------ arch/s390/kvm/vsie.c | 1 - arch/s390/mm/gmap_helpers.c | 1 - drivers/s390/char/uvdevice.c | 6 +++--- 9 files changed, 13 insertions(+), 37 deletions(-)
arch/s390/include/asm/uv.h +2 -14
@@ -454,18 +454,6 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } -/* Low level uv_call that avoids stalls for long running busy conditions */ -static inline int uv_call_sched (unsigned long r1,unsigned long r2) -{ -int cc; - -do { - cc =__uv_call (r1, r2); -cond_resched (); - }while (cc >1 ); -return cc; -} -/* * special variant of uv_call that only transports the cpu or guest * handle and the command, like destroy or verify.
@@ -480,7 +468,7 @@ static inline int uv_cmd_nodata(u64 handle, u16 cmd, u16 *rc, u16 *rrc)int cc;WARN (!handle,"No handle provided to Ultravisor call cmd %x\n" , cmd); - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;return cc ? -EINVAL :0 ;
@@ -518,7 +506,7 @@ static inline int uv_list_secrets(struct uv_secret_list *buf, u16 start_idx, .start_idx = start_idx, .list_addr = (u64)buf, }; -int cc =uv_call_sched (0 , (u64)&uvcb); +int cc =uv_call (0 , (u64)&uvcb);if (rc) *rc = uvcb.header.rc;
arch/s390/kernel/uv.c +1 -1
@@ -831,7 +831,7 @@ int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size) .buf_size = buf_size, }; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb);switch (uvcb.header.rc) {case UVC_RC_EXECUTED :
arch/s390/kvm/gaccess.c +2 -6
@@ -151,10 +151,8 @@ static void ipte_lock_simple(struct kvm *kvm) ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic);do { -if (old.k) { -cond_resched (); +if (old.k) goto retry; - } new = old; new.k =1 ; }while (!try_cmpxchg (&ic->val, &old.val, new.val));
@@ -189,10 +187,8 @@ static void ipte_lock_siif(struct kvm *kvm) ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { - if (old.kg) { - cond_resched(); + if (old.kg) goto retry; - } new = old; new.k = 1; new.kh++;
arch/s390/kvm/gmap.c +0 -4
@@ -941,7 +941,6 @@ void gmap_split_huge_pages(struct gmap *gmap)scoped_guard (read_lock, &gmap->kvm->mmu_lock) start = _dat_walk_gfn_range(start, asce_end(gmap->asce), gmap->asce, &ops,DAT_WALK_IGN_HOLES , gmap); -cond_resched (); }while (start); }
@@ -963,7 +962,6 @@ static int _gmap_enable_skeys(struct gmap *gmap)do {scoped_guard (write_lock, &gmap->kvm->mmu_lock) start = dat_reset_skeys(gmap->asce, start); -cond_resched (); }while (start);return 0 ; }
@@ -1019,7 +1017,6 @@ int gmap_pv_destroy_range(struct gmap *gmap, gfn_t start, gfn_t end, bool interr DAT_WALK_IGN_HOLES, NULL);if (interruptible &&fatal_signal_pending (current))return -EINTR ; -cond_resched (); }while (start && start < end);return 0 ; }
@@ -1138,7 +1135,6 @@ void _gmap_set_cmma_all(struct gmap *gmap, bool dirty) gfn =_dat_walk_gfn_range (gfn,asce_end (gmap->asce), gmap->asce, &ops,DAT_WALK_IGN_HOLES , &gmap->kvm->arch.cmma_dirty_pages); -cond_resched (); }while (gfn); }
arch/s390/kvm/kvm-s390.c +0 -1
@@ -1027,7 +1027,6 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *attdo {scoped_guard (read_lock, &kvm->mmu_lock) start_gfn = dat_reset_cmma(kvm->arch.gmap->asce, start_gfn); -cond_resched (); }while (start_gfn); ret =0 ;break ;
arch/s390/kvm/pv.c +5 -6
@@ -429,7 +429,7 @@ static int kvm_s390_pv_deinit_vm_fast(struct kvm *kvm, u16 *rc, u16 *rrc) };int cc; - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb);if (rc) *rc = uvcb.header.rc;if (rrc)
@@ -746,7 +746,7 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) }gmap_split_huge_pages (kvm->arch.gmap); - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT CREATE VM: handle %llx len %llx rc %x rrc %x flags %04x",
@@ -832,7 +832,6 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,while (offset < size) { ret =unpack_one (kvm, addr, tweak, offset, rc, rrc);if (ret == -EAGAIN ) { -cond_resched ();if (fatal_signal_pending (current))break ;continue ;
@@ -875,7 +874,7 @@ int kvm_s390_pv_dump_cpu(struct kvm_vcpu *vcpu, void *buff, u16 *rc, u16 *rrc) };int cc; - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;return cc;
@@ -959,7 +958,7 @@ int kvm_s390_pv_dump_stor_state(struct kvm *kvm, void __user *buff_user,/* We will loop until the user buffer is filled or an error occurs */ do { /* Get 1MB worth of guest storage state data */ - cc = uv_call_sched(0, (u64)&uvcb); + cc = uv_call(0, (u64)&uvcb); /* All or nothing */ if (cc) {
@@ -1037,7 +1036,7 @@ int kvm_s390_pv_dump_complete(struct kvm *kvm, void __user *buff_user,return -ENOMEM ; complete.dump_area_origin = (u64 )compl_data; - ret =uv_call_sched (0 , (u64)&complete); + ret =uv_call (0 , (u64)&complete); *rc = complete.header.rc; *rrc = complete.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT DUMP COMPLETE: rc %x rrc %x",
arch/s390/kvm/vsie.c +0 -1
@@ -1434,7 +1434,6 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) }if (sg) sg =gmap_put (sg); -cond_resched (); }if (sg) sg =gmap_put (sg);
arch/s390/mm/gmap_helpers.c +0 -1
@@ -272,7 +272,6 @@ static int __gmap_helper_unshare_zeropages(struct mm_struct *mm)* truncation. In that case, the shared zeropage would be gone * and we can simply retry and make progress. */ -cond_resched (); goto retry; }
drivers/s390/char/uvdevice.c +3 -3
@@ -224,7 +224,7 @@ static int uvio_attestation(struct uvio_ioctl_cb *uv_ioctl)if (ret) goto out; -uv_call_sched (0 , (u64 )uvcb_attest); +uv_call (0 , (u64 )uvcb_attest); uv_ioctl->uv_rc = uvcb_attest->header.rc; uv_ioctl->uv_rrc = uvcb_attest->header.rrc;
@@ -291,7 +291,7 @@ static int uvio_add_secret(struct uvio_ioctl_cb *uv_ioctl) ret =0 ; uvcb.addr = (u64 )asrcb; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb); uv_ioctl->uv_rc = uvcb.header.rc; uv_ioctl->uv_rrc = uvcb.header.rrc;
@@ -457,7 +457,7 @@ static int uvio_retr_secret(struct uvio_ioctl_cb *uv_ioctl) uvcb.buf_addr = (u64 )buf; uvcb.buf_size = buf_len; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb);if (copy_to_user ((__user void *)uv_ioctl->argument_addr, buf, buf_len)) goto err;
Signature · 1 line
2.53.0
Heiko Carstens
maintainerPATCH v3 4/4 s390/cio: Remove cond_resched() calls
In reply to Heiko CarstensSince [1] cond_resched() is a no-op on s390. Remove all calls.
[1] commit 7dadeaa6e851 ("sched: Further restrict the preemption modes")
--- drivers/s390/cio/css.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/s390/cio/css.c +0 -8
@@ -618,11 +618,6 @@ static int slow_eval_known_fn(struct subchannel *sch, void *data) rc =css_evaluate_known_subchannel (sch,1 );if (rc == -EAGAIN )css_schedule_eval (sch->schid); -/* -* The loop might take long time for platforms with lots of -* known devices. Allow scheduling here. -*/ -cond_resched (); }return 0 ; }
@@ -654,9 +649,6 @@ static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)default : rc =0 ; } -/* Allow scheduling here since the containing loop might -* take a while. */ -cond_resched (); }return rc; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/4] KVM: s390: Remove cond_resched() calls
In reply to Heiko CarstensSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Since [1]
cond_resched()is a no-op on s390. Remove all calls.This also entirely removes
uv_call_sched()and replaces all call sites withuv_call(), since both functions are identical after the removal ofcond_resched().[1] commit
7dadeaa6e851("sched: Further restrict the preemption modes")Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 4/4] s390/cio: Remove cond_resched() calls
In reply to Heiko CarstensSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Since [1]
cond_resched()is a no-op on s390. Remove all calls.[1] commit
7dadeaa6e851("sched: Further restrict the preemption modes")Reviewed-by Peter Oberparleiter <[email protected]>Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 3/4] s390: Remove cond_resched() calls
In reply to Heiko CarstensSashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Since [1]
cond_resched()is a no-op on s390. Remove all calls.[1] commit
7dadeaa6e851("sched: Further restrict the preemption modes")Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
In reply to Heiko CarstensThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free / Incorrect Backlog Handling due to improper -EBUSY check
- [High] Double completion of crypto requests on error paths leading to Use-After-Free
- [Medium] Unreachable error handling logic for -EKEYEXPIRED in phmac_do_one_request --
--- Patch [1]: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1) --- commit b1e4ce79023817dc16f19a077b044e708fcff721
Author: Heiko Carstens <[email protected]>
s390/crypto: Replace cond_resched() with msleep(1)
This patch replaces cond_resched calls in the s390 crypto code with msleep(1). This ensures that the current task is scheduled away as originally intended, since cond_resched is compiled away to a no-op under newer scheduling preemption modes.
arch/s390/crypto/paes_s390.c
Quoted 4 lines
arch/s390/crypto/paes_s390.c +0
-0
[Severity: High]
This is a pre-existing issue, but does the crypto request entry function ecb_paes_crypt() properly handle backlogged requests?
When a caller submits a request with CRYPTO_TFM_REQ_MAY_BACKLOG and the crypto engine queue is full, crypto_enqueue_request() successfully enqueues the request to the backlog and returns -EBUSY.
However, ecb_paes_crypt() appears to treat -EBUSY as an error because it only checks for rc != -EINPROGRESS:
ecb_paes_crypt() {
rc = crypto_transfer_skcipher_request_to_engine(paes_crypto_engine, req);
if (rc != -EINPROGRESS)
atomic_dec(&ctx->via_engine_ctr);
...
if (rc != -EINPROGRESS)
skcipher_walk_done(walk, rc);
}This prematurely tears down the request state while the request remains queued in the engine. When the engine eventually processes this request, could it execute with freed or zeroed structures and corrupt memory?
arch/s390/crypto/paes_s390.c static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) · line 561
Quoted 9 lines
arch/s390/crypto/paes_s390.c +1
-1@@ -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) {
[Severity: High]
This is a pre-existing issue, but does ecb_paes_do_one_request() accidentally trigger a double completion on error paths?
If ecb_paes_do_crypt() fails and returns a negative error code like -EINVAL, the code falls through and calls crypto_finalize_skcipher_request(), which completes the request.
ecb_paes_do_one_request() then returns that same negative error code back to crypto_pump_requests() in the crypto engine. When crypto_pump_requests() sees a negative return code that is not -ENOSPC, it branches to its error path and calls crypto_request_complete() a second time on the exact same request.
Could this lead to a use-after-free if the user completion callback already freed the request context during the first invocation?
[ ... ]
arch/s390/crypto/phmac_s390.c
Quoted 4 lines
arch/s390/crypto/phmac_s390.c +0
-0
[Severity: High]
This is a pre-existing issue, but does phmac_update() share the same backlog handling regression as ecb_paes_crypt()?
It also checks only for rc != -EINPROGRESS and wrongly cleans up the request via hwh_advance() on -EBUSY, even though the request was successfully enqueued to the backlog.
arch/s390/crypto/phmac_s390.c static int phmac_do_one_request(struct crypto_engine *engine, void *areq) · line 898
Quoted 6 lines
arch/s390/crypto/phmac_s390.c +1
-1@@ -895,7 +895,7 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq)* tell scheduler to voluntarily give up the CPU here. */ pr_debug ("rescheduling request\n" ); -cond_resched (); +msleep (1 );
[Severity: Medium]
This is a pre-existing issue, but is this error handling block for -EKEYEXPIRED ever actually reachable?
When phmac_kmac_update() and phmac_kmac_final() are called with maysleep set to true, they do not seem to proactively check tfm_ctx->pk_state to return -EKEYEXPIRED.
Instead, if the key is expired, they synchronously call phmac_convert_key() and retry the operation.
Because they handle conversions synchronously in this path, they never return -EKEYEXPIRED, which would make this entire error handling block dead code. Is there another path where -EKEYEXPIRED could be returned here?
arch/s390/crypto/phmac_s390.c static int phmac_do_one_request(struct crypto_engine *engine, void *areq) · line 901
Quoted 3 lines
arch/s390/crypto/phmac_s390.c +0
-0return -ENOSPC ; }else if (rc) {hwh_advance (hwh, rc);
[Severity: High]
This is a pre-existing issue, but just like ecb_paes_do_one_request(), does this hash error path also cause a double completion?
If rc is a negative error code like -EINVAL, crypto_finalize_hash_request() is called in phmac_do_one_request(), and then crypto_request_complete() is called again in the crypto engine error path.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
In reply to Heiko CarstensQuoted 7 lines · Heiko Carstens
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 whatcond_resched()would do or did.
Quoted 7 lines
Instead of just removing the
cond_resched()calls, replace them withmsleep()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 <[email protected]>
As in v2
Signature · 2 lines
Mit freundlichen Grüßen / Kind regards Holger Dengler
Re: [PATCH v3 2/4] KVM: s390: Remove cond_resched() calls
In reply to Heiko CarstensQuoted 9 lines · On Thu, 30 Jul 2026 07:29:05 +0200 Heiko Carstens <[email protected]> wrote:
Since [1]
cond_resched()is a no-op on s390. Remove all calls.This also entirely removes
uv_call_sched()and replaces all call sites withuv_call(), since both functions are identical after the removal ofcond_resched().[1] commit
7dadeaa6e851("sched: Further restrict the preemption modes")Signed-off-by Heiko Carstens <[email protected]>
Quoted 254 lines
--- arch/s390/include/asm/uv.h | 16 ++-------------- arch/s390/kernel/uv.c | 2 +- arch/s390/kvm/gaccess.c | 8 ++------ arch/s390/kvm/gmap.c | 4 ---- arch/s390/kvm/kvm-s390.c | 1 - arch/s390/kvm/pv.c | 11 +++++------ arch/s390/kvm/vsie.c | 1 - arch/s390/mm/gmap_helpers.c | 1 - drivers/s390/char/uvdevice.c | 6 +++--- 9 files changed, 13 insertions(+), 37 deletions(-)arch/s390/include/asm/uv.h +2
-14@@ -454,18 +454,6 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } -/* Low level uv_call that avoids stalls for long running busy conditions */ -static inline int uv_call_sched (unsigned long r1,unsigned long r2) -{ -int cc; - -do { - cc =__uv_call (r1, r2); -cond_resched (); - }while (cc >1 ); -return cc; -} -/* * special variant of uv_call that only transports the cpu or guest * handle and the command, like destroy or verify. @@ -480,7 +468,7 @@ static inline int uv_cmd_nodata(u64 handle, u16 cmd, u16 *rc, u16 *rrc)int cc;WARN (!handle,"No handle provided to Ultravisor call cmd %x\n" , cmd); - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;return cc ? -EINVAL :0 ;@@ -518,7 +506,7 @@ static inline int uv_list_secrets(struct uv_secret_list *buf, u16 start_idx, .start_idx = start_idx, .list_addr = (u64)buf, }; -int cc =uv_call_sched (0 , (u64)&uvcb); +int cc =uv_call (0 , (u64)&uvcb);if (rc) *rc = uvcb.header.rc;arch/s390/kernel/uv.c +1
-1@@ -831,7 +831,7 @@ int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size) .buf_size = buf_size, }; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb);switch (uvcb.header.rc) {case UVC_RC_EXECUTED :arch/s390/kvm/gaccess.c +2
-6@@ -151,10 +151,8 @@ static void ipte_lock_simple(struct kvm *kvm) ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic);do { -if (old.k) { -cond_resched (); +if (old.k) goto retry; - } new = old; new.k =1 ; }while (!try_cmpxchg (&ic->val, &old.val, new.val));@@ -189,10 +187,8 @@ static void ipte_lock_siif(struct kvm *kvm) ic = &kvm->arch.sca->ipte_control; old =READ_ONCE (*ic); do { - if (old.kg) { - cond_resched(); + if (old.kg) goto retry; - } new = old; new.k = 1; new.kh++;arch/s390/kvm/gmap.c +0
-4@@ -941,7 +941,6 @@ void gmap_split_huge_pages(struct gmap *gmap)scoped_guard (read_lock, &gmap->kvm->mmu_lock) start = _dat_walk_gfn_range(start, asce_end(gmap->asce), gmap->asce, &ops,DAT_WALK_IGN_HOLES , gmap); -cond_resched (); }while (start); }@@ -963,7 +962,6 @@ static int _gmap_enable_skeys(struct gmap *gmap)do {scoped_guard (write_lock, &gmap->kvm->mmu_lock) start = dat_reset_skeys(gmap->asce, start); -cond_resched (); }while (start);return 0 ; }@@ -1019,7 +1017,6 @@ int gmap_pv_destroy_range(struct gmap *gmap, gfn_t start, gfn_t end, bool interr DAT_WALK_IGN_HOLES, NULL);if (interruptible &&fatal_signal_pending (current))return -EINTR ; -cond_resched (); }while (start && start < end);return 0 ; }@@ -1138,7 +1135,6 @@ void _gmap_set_cmma_all(struct gmap *gmap, bool dirty) gfn =_dat_walk_gfn_range (gfn,asce_end (gmap->asce), gmap->asce, &ops,DAT_WALK_IGN_HOLES , &gmap->kvm->arch.cmma_dirty_pages); -cond_resched (); }while (gfn); }arch/s390/kvm/kvm-s390.c +0
-1@@ -1027,7 +1027,6 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *attdo {scoped_guard (read_lock, &kvm->mmu_lock) start_gfn = dat_reset_cmma(kvm->arch.gmap->asce, start_gfn); -cond_resched (); }while (start_gfn); ret =0 ;break ;arch/s390/kvm/pv.c +5
-6@@ -429,7 +429,7 @@ static int kvm_s390_pv_deinit_vm_fast(struct kvm *kvm, u16 *rc, u16 *rrc) };int cc; - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb);if (rc) *rc = uvcb.header.rc;if (rrc)@@ -746,7 +746,7 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) }gmap_split_huge_pages (kvm->arch.gmap); - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT CREATE VM: handle %llx len %llx rc %x rrc %x flags %04x",@@ -832,7 +832,6 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,while (offset < size) { ret =unpack_one (kvm, addr, tweak, offset, rc, rrc);if (ret == -EAGAIN ) { -cond_resched ();if (fatal_signal_pending (current))break ;continue ;@@ -875,7 +874,7 @@ int kvm_s390_pv_dump_cpu(struct kvm_vcpu *vcpu, void *buff, u16 *rc, u16 *rrc) };int cc; - cc =uv_call_sched (0 , (u64)&uvcb); + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;return cc;@@ -959,7 +958,7 @@ int kvm_s390_pv_dump_stor_state(struct kvm *kvm, void __user *buff_user,/* We will loop until the user buffer is filled or an error occurs */ do { /* Get 1MB worth of guest storage state data */ - cc = uv_call_sched(0, (u64)&uvcb); + cc = uv_call(0, (u64)&uvcb); /* All or nothing */ if (cc) {@@ -1037,7 +1036,7 @@ int kvm_s390_pv_dump_complete(struct kvm *kvm, void __user *buff_user,return -ENOMEM ; complete.dump_area_origin = (u64 )compl_data; - ret =uv_call_sched (0 , (u64)&complete); + ret =uv_call (0 , (u64)&complete); *rc = complete.header.rc; *rrc = complete.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT DUMP COMPLETE: rc %x rrc %x",arch/s390/kvm/vsie.c +0
-1@@ -1434,7 +1434,6 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) }if (sg) sg =gmap_put (sg); -cond_resched (); }if (sg) sg =gmap_put (sg);arch/s390/mm/gmap_helpers.c +0
-1@@ -272,7 +272,6 @@ static int __gmap_helper_unshare_zeropages(struct mm_struct *mm)* truncation. In that case, the shared zeropage would be gone * and we can simply retry and make progress. */ -cond_resched (); goto retry; }drivers/s390/char/uvdevice.c +3
-3@@ -224,7 +224,7 @@ static int uvio_attestation(struct uvio_ioctl_cb *uv_ioctl)if (ret) goto out; -uv_call_sched (0 , (u64 )uvcb_attest); +uv_call (0 , (u64 )uvcb_attest); uv_ioctl->uv_rc = uvcb_attest->header.rc; uv_ioctl->uv_rrc = uvcb_attest->header.rrc;@@ -291,7 +291,7 @@ static int uvio_add_secret(struct uvio_ioctl_cb *uv_ioctl) ret =0 ; uvcb.addr = (u64 )asrcb; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb); uv_ioctl->uv_rc = uvcb.header.rc; uv_ioctl->uv_rrc = uvcb.header.rrc;@@ -457,7 +457,7 @@ static int uvio_retr_secret(struct uvio_ioctl_cb *uv_ioctl) uvcb.buf_addr = (u64 )buf; uvcb.buf_size = buf_len; -uv_call_sched (0 , (u64)&uvcb); +uv_call (0 , (u64)&uvcb);if (copy_to_user ((__user void *)uv_ioctl->argument_addr, buf, buf_len)) goto err;
Re: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
In reply to Heiko CarstensQuoted 24 lines · Heiko Carstens
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 whatcond_resched()would do or did.Instead of just removing the
cond_resched()calls, replace them withmsleep()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 <[email protected]>--- arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)arch/s390/crypto/paes_s390.c +0
-0
arch/s390/crypto/paes_s390.c static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) · line 561
Quoted 8 lines
arch/s390/crypto/paes_s390.c +1
-1@@ -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.
This all sounds like a horrible hack one way or the other.
Holger Dengler
maintainerRe: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Peter,
Quoted 38 lines · Peter Zijlstra
Quoted 24 lines · Heiko Carstens
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 whatcond_resched()would do or did.Instead of just removing the
cond_resched()calls, replace them withmsleep()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 <[email protected]>--- arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)arch/s390/crypto/paes_s390.c +0
-0arch/s390/crypto/paes_s390.c static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) · line 561
Quoted 8 lines
arch/s390/crypto/paes_s390.c +1
-1@@ -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.
Quoted 6 lines
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
-ENOSPCis 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?
Quoted 1 line
This all sounds like a horrible hack one way or the other.
Ähh, yes... :)
Signature · 2 lines
Mit freundlichen Grüßen / Kind regards Holger Dengler
Re: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Quoted 61 lines · Holger Dengler
Peter,
Quoted 38 lines · Peter Zijlstra
Quoted 24 lines · Heiko Carstens
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 whatcond_resched()would do or did.Instead of just removing the
cond_resched()calls, replace them withmsleep()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 <[email protected]>--- arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)arch/s390/crypto/paes_s390.c +0
-0arch/s390/crypto/paes_s390.c static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) · line 561
Quoted 8 lines
arch/s390/crypto/paes_s390.c +1
-1@@ -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.
Quoted 6 lines
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
-ENOSPCis 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).
Quoted 5 lines
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?
Holger Dengler
maintainerRe: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Quoted 68 lines · Peter Zijlstra
Quoted 61 lines · Holger Dengler
Peter,
Quoted 38 lines · Peter Zijlstra
Quoted 24 lines · Heiko Carstens
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 whatcond_resched()would do or did.Instead of just removing the
cond_resched()calls, replace them withmsleep()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 <[email protected]>--- arch/s390/crypto/paes_s390.c | 8 ++++---- arch/s390/crypto/phmac_s390.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)arch/s390/crypto/paes_s390.c +0
-0arch/s390/crypto/paes_s390.c static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) · line 561
Quoted 8 lines
arch/s390/crypto/paes_s390.c +1
-1@@ -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.
Quoted 6 lines
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
-ENOSPCis 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).
Quoted 5 lines
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?
Quoted 3 lines
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)
Signature · 2 lines
Mit freundlichen Grüßen / Kind regards Holger Dengler
Re: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Quoted 17 lines · Holger Dengler
Quoted 3 lines
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. */
Quoted 2 lines
(I would leave it up to Heiko to merge the comment in his series, or let Harald/me do it in a separate patch)
Right, perhaps something like so, avoiding the endless copy/paste ?
---
arch/s390/crypto/paes_s390.c +4 -40
@@ -548,16 +548,7 @@ static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq) rc =ecb_paes_do_crypt (ctx, req_ctx, tested, true);if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* Trigger a re-schedule of this request by returning -* -ENOSPC ("hardware queue is full") to the crypto engine. -* To avoid immediately re-invocation of this callback, -* tell the scheduler to voluntarily give up the CPU here. -*/ -cond_resched (); -pr_debug ("rescheduling request\n" ); -return -ENOSPC ; +return pkey_handle_expired (); }else if (rc) {skcipher_walk_done (walk, rc); }
@@ -814,16 +805,7 @@ static int cbc_paes_do_one_request(struct crypto_engine *engine, void *areq) rc =cbc_paes_do_crypt (ctx, req_ctx, tested, true);if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* Trigger a re-schedule of this request by returning -* -ENOSPC ("hardware queue is full") to the crypto engine. -* To avoid immediately re-invocation of this callback, -* tell the scheduler to voluntarily give up the CPU here. -*/ -cond_resched (); -pr_debug ("rescheduling request\n" ); -return -ENOSPC ; +return pkey_handle_expired (); }else if (rc) {skcipher_walk_done (walk, rc); }
@@ -1122,16 +1104,7 @@ static int ctr_paes_do_one_request(struct crypto_engine *engine, void *areq) rc =ctr_paes_do_crypt (ctx, req_ctx, tested, true);if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* Trigger a re-schedule of this request by returning -* -ENOSPC ("hardware queue is full") to the crypto engine. -* To avoid immediately re-invocation of this callback, -* tell the scheduler to voluntarily give up the CPU here. -*/ -cond_resched (); -pr_debug ("rescheduling request\n" ); -return -ENOSPC ; +return pkey_handle_expired (); }else if (rc) {skcipher_walk_done (walk, rc); }
@@ -1565,16 +1538,7 @@ static int xts_paes_do_one_request(struct crypto_engine *engine, void *areq) rc =xts_paes_do_crypt (ctx, req_ctx, tested, true);if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* Trigger a re-schedule of this request by returning -* -ENOSPC ("hardware queue is full") to the crypto engine. -* To avoid immediately re-invocation of this callback, -* tell the scheduler to voluntarily give up the CPU here. -*/ -cond_resched (); -pr_debug ("rescheduling request\n" ); -return -ENOSPC ; +return pkey_handle_expired (); }else if (rc) {skcipher_walk_done (walk, rc); }
arch/s390/crypto/phmac_s390.c +3 -22
@@ -887,16 +887,7 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq)case OP_FINUP : rc =phmac_kmac_update (req, true);if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* 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. -*/ -pr_debug ("rescheduling request\n" ); -cond_resched (); -return -ENOSPC ; +return pkey_handle_expired (); }else if (rc) {hwh_advance (hwh, rc); goto out;
@@ -907,18 +898,8 @@ static int phmac_do_one_request(struct crypto_engine *engine, void *areq) fallthrough;case OP_FINAL : rc =phmac_kmac_final (req, true); -if (rc == -EKEYEXPIRED ) { -/* -* Protected key expired, conversion is in process. -* 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. -*/ -pr_debug ("rescheduling request\n" ); -cond_resched (); -return -ENOSPC ; - } +if (rc == -EKEYEXPIRED ) +return pkey_handle_expired ();break ;default :/* unknown/unsupported/unimplemented asynch op */
arch/s390/include/asm/pkey.h +17 -0
@@ -13,6 +13,7 @@#include <linux/ioctl.h> #include <linux/types.h> +#include <linux/delay.h> #include <uapi/asm/pkey.h> /*
@@ -44,4 +45,20 @@ int pkey_key2protkey(const u8 *key, u32 keylen,*/ #define PKEY_XFLAG_NOCLEARKEY 0x0002 +static inline int pkey_handle_expired (void ) +{ +/* +* 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. +*/ +msleep (1 ); +pr_debug ("rescheduling request\n" ); +return -ENOSPC ; +} +#endif /* _KAPI_PKEY_H */
Heiko Carstens
maintainerRe: [PATCH v3 1/4] s390/crypto: Replace cond_resched() with msleep(1)
Quoted 19 lines · Peter Zijlstra
Quoted 17 lines · Holger Dengler
Quoted 3 lines
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. */
Quoted 4 lines
Quoted 2 lines
(I would leave it up to Heiko to merge the comment in his series, or let Harald/me do it in a separate patch)
Right, perhaps something like so, avoiding the endless copy/paste ?
I guess there won't be any disagreement. I'll merge your patch, and add Holger's explanation to the commit message.
Thanks!