From nobody Tue Feb 10 02:59:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD6BAC77B7A for ; Tue, 6 Jun 2023 14:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238384AbjFFOlR (ORCPT ); Tue, 6 Jun 2023 10:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238454AbjFFOkL (ORCPT ); Tue, 6 Jun 2023 10:40:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4FBA2127 for ; Tue, 6 Jun 2023 07:38:54 -0700 (PDT) Message-ID: <20230606142032.826604145@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=wHuT7Hr0NdOKLI1EunOgn59lsnWIJRlvleS26aoiaoA=; b=tl52fd+obPeHQXAjdOtL/sLgOTRfX+FOkkGpvpvRPKOjZH6KoaVfGmKYfD/ixurZHJq2aO p9b15raE24WnbUgpqOWt49PpPr4S/Xj91olySxUAnLLT19vCBUZTrzFOy1JsVMM3C0gMCV Kj78hiY2NhIhJNP+6kxOiRArkqZt1Q71wFNmm5TmA/vCbaG9vstMsUjbu9/tNxUa1ULaLJ OPHNxDm+w9CZgFwXjrPDFEpzQ4QoqCZIKzYHfQKCwXaQj2mYwbGIZkhKdgyJ95SWWbFxCI 7mSNxPw0qqixkzC26R8FNCjKgDwECT/6KhlSIuXysweXwKUEKeckVCddnfKK7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=wHuT7Hr0NdOKLI1EunOgn59lsnWIJRlvleS26aoiaoA=; b=tKLxhZYkjMhy1U7P7k4zoE3Aq3+VKrKcHWCwEdcwwhgUinWe88yTvqhy/x4nyfdjb1Q9GJ E1Zgn7CDIDpelQCg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 32/45] signal: Split up __sigqueue_alloc() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:09 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To cure the SIG_IGN handling for posix interval timers, the preallocated sigqueue needs to be embedded into struct k_itimer to prevent life time races of all sorts. Reorganize __sigqueue_alloc() so the ucounts retrieval and the initialization can be used independently. No functional change. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -403,16 +403,9 @@ void task_join_group_stop(struct task_st task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING); } =20 -/* - * allocate a new signal queue record - * - this may be called without locks if and only if t =3D=3D current, oth= erwise an - * appropriate lock must be held to stop the target task from exiting - */ -static struct sigqueue * -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags, - int override_rlimit, const unsigned int sigqueue_flags) +static struct ucounts *sig_get_ucounts(struct task_struct *t, int sig, + int override_rlimit) { - struct sigqueue *q =3D NULL; struct ucounts *ucounts =3D NULL; long sigpending; =20 @@ -431,19 +424,44 @@ static struct sigqueue * if (!sigpending) return NULL; =20 - if (override_rlimit || likely(sigpending <=3D task_rlimit(t, RLIMIT_SIGPE= NDING))) { - q =3D kmem_cache_alloc(sigqueue_cachep, gfp_flags); - } else { + if (unlikely(!override_rlimit && sigpending > task_rlimit(t, RLIMIT_SIGPE= NDING))) { + dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); print_dropped_signal(sig); + return NULL; } =20 - if (unlikely(q =3D=3D NULL)) { + return ucounts; +} + +static void __sigqueue_init(struct sigqueue *q, struct ucounts *ucounts, + const unsigned int sigqueue_flags) +{ + INIT_LIST_HEAD(&q->list); + q->flags =3D sigqueue_flags; + q->ucounts =3D ucounts; +} + +/* + * allocate a new signal queue record + * - this may be called without locks if and only if t =3D=3D current, oth= erwise an + * appropriate lock must be held to stop the target task from exiting + */ +static struct sigqueue *__sigqueue_alloc(int sig, struct task_struct *t, g= fp_t gfp_flags, + int override_rlimit, const unsigned int sigqueue_flags) +{ + struct ucounts *ucounts =3D sig_get_ucounts(t, sig, override_rlimit); + struct sigqueue *q; + + if (!ucounts) + return NULL; + + q =3D kmem_cache_alloc(sigqueue_cachep, gfp_flags); + if (!q) { dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); - } else { - INIT_LIST_HEAD(&q->list); - q->flags =3D sigqueue_flags; - q->ucounts =3D ucounts; + return NULL; } + + __sigqueue_init(q, ucounts, sigqueue_flags); return q; }