Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp508139lqp; Mon, 10 Jun 2024 10:26:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwZom5epNXl4IC41nsnKbi5A812wlVpTdq9z6q1CHDLrOSUmtlYSs9F3ra2Odqs4nL9goOSN5ZDbiJwSbuj1bEXhwEcEfNqmiT4jWwKA== X-Google-Smtp-Source: AGHT+IG/ujcqEyXfbdmpkCkTv/WakUG68uS5JeqyaHctMTKW2b7jsA/vjp2Vm/TBLZg0xMMorZpr X-Received: by 2002:a05:6a00:1993:b0:704:3aca:7833 with SMTP id d2e1a72fcca58-7043aca87f6mr5362817b3a.31.1718040400561; Mon, 10 Jun 2024 10:26:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718040400; cv=pass; d=google.com; s=arc-20160816; b=LHZvglCaMmYzbz6olYjHDyrV7wN0oX0by2XPm5s7J+byb079+m9qW6fb1eOqkD9HqB c7guuk6OJh9LYYFYAoAGnaiZyuokU5lVmWpVCToPsI+Yt2sEyMJcCgW5lcVYVTgPOveM YD3hTJ1u7/StgT7foJYSQOcDr5U2pRgHJrQrR/ii5SlF0fm/zWK3ujfyovL7v54AT91J Lxp9L9BssNx9lzNJgkhIdT6HtSIZX9/QfUzJfBI0r0UhJlJLoLrCp1CYGH7caVXs6iEs s/M6r8huKWryiinE6XTkKwyCahTf2s97CjlEE6zK1CEKmsKmFx6UZscE/5QhDwzbjLb+ mXfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=RIInviEgVz+BvUxJyZo2yuM0Ys8NWIcWoXCI4X06Uos=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=T0O2nvau4CfD1rAqqRoNFoVNNTd2/e74hu9BG/voBOFf+YB9tfRGgjeBowBmzFUtd1 tlOVLqUkbdkinBc5Do6sen7SKW5LDXO9L8/1hVZIkkNbtfra08knlNQGydT08jiNMkL6 j9NCYqMG/YOqUc7FNq5uQWRQ+eub+cytUF8B66PsA4GZdgKc7DMk4sa5VcGam28ZYoVg RKIeaU98AgULp5FxH/Pxcrb9PM4ZPyFhaqHuUiZG5qI3qbt4sP0HwIUgwou8z7ajg1LJ IOkKlRAGFBUgh9aTLEW/9xEcbnE7DfFyX9rbWKZRNaWET+rOHWtSFEEYBwKMWIroOnQe z3zA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kzYYJiRU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rNxdn8zN; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208600-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e93a3db9e6si3758754a12.642.2024.06.10.10.26.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 10:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kzYYJiRU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rNxdn8zN; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208600-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208600-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0A3F3B2986B for ; Mon, 10 Jun 2024 16:50:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FC8C1581E8; Mon, 10 Jun 2024 16:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kzYYJiRU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rNxdn8zN" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 615F8157499 for ; Mon, 10 Jun 2024 16:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037773; cv=none; b=mF2RM+UwEUhqBxKsnlbP/SAG0H4rL/NgVGnlMuWNj6Gvn0dwCGnzoXFcf34TifSYwSm4MTHbCglbRU590zeyHNv/TuG7Hzxns0dMTS9QeCK35CU4aSGX1NjVs3cD7AX/fQ0OVrUeLsaMsUEZT07yAqMhtD1L4wq1QdGxSTknTNI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037773; c=relaxed/simple; bh=189exjZEUItQ6zpVS/Cs7Gleaem5nfeA9wEfKXDkURg=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=EawG/kyzi7xQ8HBvH6N2t8lIZFAGkWB6DSQn9m1KVbOK+oPexybYXmT9zKGj+y8nNmKQJV/28wA5iwPfeEdkjRrBk6QGUKt0fuyHtJ/Znbbwv6vOUE4VyXHqlXtWbASE0HMwKX0g+R1ldhXiuesZdbZlTqKuO/xkWIhUBfbMc6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kzYYJiRU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rNxdn8zN; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240610164027.790855258@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037771; 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=RIInviEgVz+BvUxJyZo2yuM0Ys8NWIcWoXCI4X06Uos=; b=kzYYJiRUHYneLHxU4yVu7jk3zyjkdzM9cQnC0fAvTWzV1TleUOAJ0LCzJnxjPJEV0PLksm GurYLFhLM+gcxEYXAL7OX9kBCnz+kOgK0xrjvNiuXxvGrRIKMTlF7vZukeWMqDElj25Sx0 S750UabkqwiPzIPmFHZoeS53EGzDaI6HuyZE28ujNW2OiEA2e8Cb1uvm5oVq6WMrObeisP I2j0r+D0T1gw6NVAhBwgoOhKJoNCA9pLNqE8Zw+mwKj/RVs393I3kLSayYYwCQun0vtzv3 iCXvgblnbwBJgu6LFHmmmuZ9+sHvzerF6gqaIJ7GVbb6YMPFcb1A3OWPNR1uGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037771; 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=RIInviEgVz+BvUxJyZo2yuM0Ys8NWIcWoXCI4X06Uos=; b=rNxdn8zNpFOcZoFpC3GkZkEeDPnjsjWSI7Ou0wG3/CHUPxPLYeSMyi6tIUkk77M7MVPybu 5+sjFfzZpzrCELBA== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V3 37/51] signal: Split up __sigqueue_alloc() References: <20240610163452.591699700@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 10 Jun 2024 18:42:50 +0200 (CEST) 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 @@ -396,16 +396,9 @@ void task_join_group_stop(struct task_st task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING); } -/* - * allocate a new signal queue record - * - this may be called without locks if and only if t == current, otherwise 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 = NULL; struct ucounts *ucounts; long sigpending; @@ -424,19 +417,44 @@ static struct sigqueue * if (!sigpending) return NULL; - if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) { - q = kmem_cache_alloc(sigqueue_cachep, gfp_flags); - } else { + if (unlikely(!override_rlimit && sigpending > task_rlimit(t, RLIMIT_SIGPENDING))) { + dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); print_dropped_signal(sig); + return NULL; } - if (unlikely(q == 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 = sigqueue_flags; + q->ucounts = ucounts; +} + +/* + * allocate a new signal queue record + * - this may be called without locks if and only if t == current, otherwise 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) +{ + struct ucounts *ucounts = sig_get_ucounts(t, sig, override_rlimit); + struct sigqueue *q; + + if (!ucounts) + return NULL; + + q = 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 = sigqueue_flags; - q->ucounts = ucounts; + return NULL; } + + __sigqueue_init(q, ucounts, sigqueue_flags); return q; }