[PATCH] KEYS: dispatch key_gc_work to system_wq.
Jarkko Sakkinen
jarkko at kernel.org
Mon Oct 26 03:12:18 UTC 2026
schedule_work() dispatches key_gc_work on the per-CPU system_wq, which can
choke the queue:
BUG: workqueue lockup - pool cpus=0 node=0 flags=0x2 nice=0 stuck for 30s!
Queue the work on system_dfl_long_wq instead, which is an unbounded wq for
long-running tasks i.e., it has the WQ_BOUND flag set and thus cannot hog
the CPU core.
Link: https://lore.kernel.org/keyrings/20261024042944.52493-1-hackerowskiy@gmail.com/
Reported-by: syzbot+c15de43f1e7fffbb7b9b at syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6ad35b60.7952420f.283480.0360.GAE@google.com/T/
Signed-off-by: Jarkko Sakkinen <jarkko at kernel.org>
---
I sanity checked with perf that scheduler latency improved clearly as it
should, and used large keyrings that I expired, as the test payload.
It was ad-hoc testing but I can scrape from transcripts a test script
if wanted.
security/keys/gc.c | 8 ++++----
security/keys/key.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/security/keys/gc.c b/security/keys/gc.c
index eda445f815d4..2337d39722e4 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -57,7 +57,7 @@ void key_schedule_gc(time64_t gc_at)
if (gc_at <= now || test_bit(KEY_GC_REAP_KEYTYPE, &key_gc_flags)) {
kdebug("IMMEDIATE");
- schedule_work(&key_gc_work);
+ queue_work(system_dfl_long_wq, &key_gc_work);
} else if (gc_at < key_gc_next_run) {
kdebug("DEFERRED");
key_gc_next_run = gc_at;
@@ -85,7 +85,7 @@ void key_set_expiry(struct key *key, time64_t expiry)
void key_schedule_gc_links(void)
{
set_bit(KEY_GC_KEY_EXPIRED, &key_gc_flags);
- schedule_work(&key_gc_work);
+ queue_work(system_dfl_long_wq, &key_gc_work);
}
/*
@@ -119,7 +119,7 @@ void key_gc_keytype(struct key_type *ktype)
set_bit(KEY_GC_REAP_KEYTYPE, &key_gc_flags);
kdebug("schedule");
- schedule_work(&key_gc_work);
+ queue_work(system_dfl_long_wq, &key_gc_work);
kdebug("sleep");
wait_on_bit(&key_gc_flags, KEY_GC_REAPING_KEYTYPE,
@@ -322,7 +322,7 @@ static void key_garbage_collector(struct work_struct *work)
}
if (gc_state & KEY_GC_REAP_AGAIN)
- schedule_work(&key_gc_work);
+ queue_work(system_dfl_long_wq, &key_gc_work);
kleave(" [end %x]", gc_state);
return;
diff --git a/security/keys/key.c b/security/keys/key.c
index 6ebb8691551f..599626c897b2 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -668,7 +668,7 @@ void key_put(struct key *key)
}
/* Mark key as safe for GC after key->user done. */
clear_bit_unlock(KEY_FLAG_USER_ALIVE, &key->flags);
- schedule_work(&key_gc_work);
+ queue_work(system_dfl_long_wq, &key_gc_work);
}
}
}
--
2.47.3
More information about the Linux-security-module-archive
mailing list