Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp66904lqg; Wed, 10 Apr 2024 15:54:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU65vEqQ/1z0ts8vgAYS0gqrdYUtUvJFG/tNS6WSuvxr2wBxCuzZQvKAqOHTro//6MJGnrumrbuYgnAQrYI93ZCFbD/bkTDFGXXqMfjTw== X-Google-Smtp-Source: AGHT+IHMZosW+wLM1//UWOJMQOq2KJkUg3/58muUfjact/BtVC3eI82HFyBkQhIjAnyLmp20fn3P X-Received: by 2002:a2e:a9a7:0:b0:2d8:6467:1a13 with SMTP id x39-20020a2ea9a7000000b002d864671a13mr3294900ljq.30.1712789650575; Wed, 10 Apr 2024 15:54:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712789650; cv=pass; d=google.com; s=arc-20160816; b=XGpafhS1wXayCGJfEHsUULPIRLX9TT7Ur+Wl+bbEnbP95BTm6sDCwh7rHF+Xj97fn7 UcJn51pvKRMbdCi9/2Zx0D6KAULrDNpjwKnFTbaFhNW4LIngHr0NrDJWcGc9DSOUkPJ0 Na4aSS0O4isjuNSwEt8basfNu8qUDSF7rQ22vZmtT2TnUPIowYWg98b3P4lqxp6VKsyH /sn0TaGUm76cvu4CRnBdTMdkfwKQN21YafXg9qiYtG4za0VSk3VLL6aub0MLUnGT6Lol 4sW9NBlJxOsqW/b+BSPn1CdARjWQhMtQnLxvLCOOiqkQB4/ob2TYG001qgxhQCBHhtY6 lDog== 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=X+sgo/pegewmMwlKAed9rpe2mNxQ3lHG0OIw/GhM7C8TkBEYWQfTJSGZYz2XSFU6+K 9Oil9eznDibqMh3CgFBbYKaullokhIUwfP9VZDxmVK0Aopab1XS5IIa3nh4r0ntkFQ0e SlErxWVvXqgUMJ3z/qN3FYu8xVEWZrnhxjRwgnvF4d4P7EvMa4Wb9eda4aw31VYII/Pr 33E1wnTm1MtxQA/weWkl9otLJvq7Qk5f+zviNkj0pgcQWs8k1PpECB93sY7SMt8VsQRt g84d0L6yGjJUsxTp8oF/50vaDom4soSkOwo1EA9QnJe5Clav3EDGVIRzGulHX37qLAXL 1YrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q8l4ehUr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=oJFJvzUl; 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-139489-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139489-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ek25-20020a056402371900b0056fde6e1b0dsi104962edb.33.2024.04.10.15.54.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 15:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139489-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q8l4ehUr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=oJFJvzUl; 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-139489-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139489-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4EA2B1F29330 for ; Wed, 10 Apr 2024 22:54:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEA9712FB38; Wed, 10 Apr 2024 22:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q8l4ehUr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oJFJvzUl" 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 7B56812D20C for ; Wed, 10 Apr 2024 22:47:17 +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=1712789238; cv=none; b=sYs59iZwtsiWJS40UmB7ksFVM3tewpK76chez0GG1dNmNVQ+Fv33311QCAY8VVcXG+9hjwjMjj2YFrjcX9MRh6tWrrDqrZlTmnr0YbMwxzT5ayRt/sZgCeAv3aQ5nM1c0AO/GfGRKL1rsMFKIiTiamqnQ54Bber3On/rpLaMLOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789238; c=relaxed/simple; bh=189exjZEUItQ6zpVS/Cs7Gleaem5nfeA9wEfKXDkURg=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=lg6Off/1q6Z5QXcFjE9gSNgrbNsgMbIWMElBdOIT500sZgbh6ubBtShzxSBfgvFOhVkMQrjIkOkN34E4SnIVKPKfhgqJVBQUCnSSh9Z2PeojRHe0rlK7m5zZriuyvkM75kKVdnNUaGc2eKCfYkl0/G1s/Cx6sCpBrEl1SLjcQq8= 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=Q8l4ehUr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oJFJvzUl; 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: <20240410165553.202164808@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712789236; 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=Q8l4ehUrSY8KNwdv2J4h50yWeOBPg/t5S95UirgpyEtbLiQf70zxze+YPRs7z0vBr7gofS SwAg2uqbiWoyACVKT+Y6iB6sX6baAIo+5ldlpiH26k9u7VUjhii13BO8oSL9+bjr/s3NRT I1v3eVHw28IiO4HUgEGPrVgrGa0VnB0O+7n552T6r+D7Kkud7gp4HkK6VymTb1gz4agUGQ ks7dlxv52LLS/BCf9sC7gZV5aojZJ4e91YYuVtFR8yBtldM4VbAjCQ4796pfQmNtxwUqGI aR11GnO8/W8RedtPmK/6boDOJTGfDGI9fDfSsk6wah/WWfksem+t0vS1oI3ZeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712789236; 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=oJFJvzUlOldq1VWiahteWWiYoFSg7iBQZkGSUPqTzvJH74Ccx8EKZoGUxdv7Yun9zcOpek +a1FihEDfDBziDAA== 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 V2 36/50] signal: Split up __sigqueue_alloc() References: <20240410164558.316665885@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: Thu, 11 Apr 2024 00:47:15 +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; }