Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp509062lqp; Mon, 10 Jun 2024 10:28:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKVwHpH2hnGZ3dIGqwN3tU1R4EdxkUo6/+EaEHJ7zAmgTu+in2Qjnos9ZrMzlA/IcPlrrdLPhGbpA+JiW1HWhYUIbHh+fUEy4IOpVr6Q== X-Google-Smtp-Source: AGHT+IHxGJuum5+9alXa4D/efVaWUbclwJ5KdqhpINXtRgm2qBGv9YhM2QQsulSt6z4ZzO+9Mbh9 X-Received: by 2002:a05:6a20:914a:b0:1b6:bb61:3782 with SMTP id adf61e73a8af0-1b6bb613a5amr5224047637.39.1718040522345; Mon, 10 Jun 2024 10:28:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718040522; cv=pass; d=google.com; s=arc-20160816; b=DxMQRlNUEQbq/GCFlKCm0eUAjKA0eFv1ENroXT3nYSHaSaZ+Xd4jX73eGVPj5rdUe6 rkqccDw3aEYH8g5GQcdLOety6R5BtSGQCbhzUnh4TzKkFijF6X09eqaAhY3NYpvF4ZIs Byq71jmPGbiYlmHYNSCOHcHNW9rCRON18UXRaWg2tFIayBwbc0OB+ieNuS71T0HXCmEI JQQgH/BYOSUFhUTjPrXxTRZqyUZ5L+c8hm8W1BVHxzP8k11Gt7vuWTTcQHOfd2Vuf2b7 bqAJemsCVm6rJzqHuUjdh01phuSZSsiiPUcasbjwUBvGjmiAQGMsq8naegOrurtLzmvY 3u7g== 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=bzEboz8AUjwt0LmBupDNjtajHSCekoKcw08hOKXcNgs=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=Z+w4fTn37xWm3MrwgwAxo+eJTifQ5IABcOwtM/dLTV+3I1RpcTOSwvU3Q4SnAiT5ee I7ZOmGJp5n/eUOwgDfQ0jVTVt5fZ/X+P2l3BBRpyx4z4D4KT0Hq31Uo3LnVNg6dTzqkU WmjArPBroD/J6kEnIDC4Mmyw7Sc0IdwfxoXW3vz+ucgs6Sz7h4wTDsLeBf720AXglbke mnmma1hrF5Ootc5z5jThilL5nUhICaYO+EAjN053S1tjxOlHNvuy9UkggV998ucPqS// nj3OjHtxm/9+IaMS+hlzqxTSYA14rXyekERUpuwJVxJTUKGpO7UIJrFoccz3qWahriE6 bM/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JHBGxA2z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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-208612-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208612-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-6e583975afesi5237406a12.346.2024.06.10.10.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 10:28:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208612-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=JHBGxA2z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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-208612-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208612-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 D4DBDB22A7C for ; Mon, 10 Jun 2024 16:53:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FCC51591F8; Mon, 10 Jun 2024 16:43:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JHBGxA2z"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9sue7UHJ" 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 EFC49158D92 for ; Mon, 10 Jun 2024 16:43:05 +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=1718037787; cv=none; b=g/6eHqr8sxDcJ5tNwuN3Ke9yD5VPhBKftiMFcyX7B4c/sFWI+mHf+7HscF4SytV2psjoGNqtAelFpdc7XDKXHQowGpY0u++4ZWdVSM/tEDP8imxJzz6l/EZN6NfNXOCbAp2SWJTithT5fWz8v5q8u4HSzQdrGi2ZbyuQMBOzZzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037787; c=relaxed/simple; bh=ojSHAmzDSUCtV20tG0Eic6qt8OMUSGLWdNQCp73/DO0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=E/Vkqk6zXOVHElUuIqiZKg02I0/UZgbsnOuITCifjRablf+/ZxH7VOlwaWFxNP/CfpCjlv7muCnyq7V3KQ0aykEzYb6T0ZaPK8JoYL8DDGALotnbxgdmz7uGEzJhm+sdXZvdYFHn6ffFJMzg1PmdTCs08Vduq/EeMXephfRWPrs= 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=JHBGxA2z; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9sue7UHJ; 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: <20240610164028.472552548@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037784; 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=bzEboz8AUjwt0LmBupDNjtajHSCekoKcw08hOKXcNgs=; b=JHBGxA2zo3ckjoiV+jfcQFRkEegNH5I7sEkHaNRQSFyeYMnVXEo/+80EV3Jn4SLb+mLdyv uV6cuxCfGeg3EJS3gt/22aqX5qpuzwCtpWqqPSp5mKqEfVTRDIqv3gIc+lp++4g6zVEAOU Rqj3k9gBP5idUKSCv6j1vy4EcZ+yP99Ph9Wt9J9nMC6ojAu4V+RIioMFHwVH8LYZc5N7jm jXAIXgKbn1jfQ7nrdb2sq2KkpM+QLtY3M0+EtYCmcWmwjyJbDUsgoBqh27/A6PLj6PQPPd osFyDV2mbp9YK0IuDwwnauy3Zp9g6gI9J2BhB2++izRXT9tU4P21FXTvQoN/cA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037784; 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=bzEboz8AUjwt0LmBupDNjtajHSCekoKcw08hOKXcNgs=; b=9sue7UHJ0fM9lfxdYR+ucFA4iFErDrsi1NyiT0OsKC01vB+6fbz6IUP3AhMzjFaG7sRFFN mO+lkdzMXcw2glDA== 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 48/51] signal: Queue ignored posixtimers on ignore list 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:43:04 +0200 (CEST) Queue posixtimers which have their signal ignored on the ignored list: 1) When the timer fires and the signal has SIG_IGN set 2) When SIG_IGN is installed via sigaction() and a timer signal is queued This completes the SIG_IGN handling and such timers are not longer self rearmed which avoids pointless wakeups. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -722,6 +722,16 @@ void signal_wake_up_state(struct task_st kick_process(t); } +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q); + +static void sigqueue_free_ignored(struct task_struct *ptmr_tsk, struct sigqueue *q) +{ + if (likely(!ptmr_tsk || q->info.si_code != SI_TIMER)) + __sigqueue_free(q); + else + posixtimer_sig_ignore(ptmr_tsk, q); +} + /* * Remove signals in mask from the pending set and queue. * @@ -740,7 +750,7 @@ static void flush_sigqueue_mask(sigset_t list_for_each_entry_safe(q, n, &s->list, list) { if (sigismember(mask, q->info.si_signo)) { list_del_init(&q->list); - __sigqueue_free(q); + sigqueue_free_ignored(ptmr_tsk, q); } } } @@ -1964,9 +1974,8 @@ int posixtimer_send_sigqueue(struct k_it int sig = q->info.si_signo; struct task_struct *t; unsigned long flags; - int ret, result; + int result; - ret = -1; rcu_read_lock(); t = posixtimer_get_target(tmr); @@ -2012,13 +2021,24 @@ int posixtimer_send_sigqueue(struct k_it */ q->info.si_overrun = 0; - ret = 1; /* the signal is ignored */ if (!prepare_signal(sig, t, false)) { result = TRACE_SIGNAL_IGNORED; + + /* Paranoia check. Try to survive. */ + if (WARN_ON_ONCE(!list_empty(&q->list))) + goto out; + + if (hlist_unhashed(&tmr->ignored_list)) { + hlist_add_head(&tmr->ignored_list, &t->signal->ignored_posix_timers); + posixtimer_sigqueue_getref(q); + } goto out; } - ret = 0; + /* This should never happen and leaks a reference count */ + if (WARN_ON_ONCE(!hlist_unhashed(&tmr->ignored_list))) + hlist_del_init(&tmr->ignored_list); + if (unlikely(!list_empty(&q->list))) { /* This holds a reference count already */ result = TRACE_SIGNAL_ALREADY_PENDING; @@ -2033,7 +2053,14 @@ int posixtimer_send_sigqueue(struct k_it unlock_task_sighand(t, &flags); ret: rcu_read_unlock(); - return ret; + return 0; +} + +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q) +{ + struct k_itimer *tmr = container_of(q, struct k_itimer, sigq); + + hlist_add_head(&tmr->ignored_list, &tsk->signal->ignored_posix_timers); } static void posixtimer_sig_unignore(struct task_struct *tsk, int sig) @@ -2082,6 +2109,7 @@ static void posixtimer_sig_unignore(stru } } #else /* CONFIG_POSIX_TIMERS */ +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q) { } static inline void posixtimer_sig_unignore(struct task_struct *tsk, int sig) { } #endif /* !CONFIG_POSIX_TIMERS */ @@ -4272,9 +4300,9 @@ int do_sigaction(int sig, struct k_sigac if (sig_handler_ignored(sig_handler(p, sig), sig)) { sigemptyset(&mask); sigaddset(&mask, sig); - flush_sigqueue_mask(&mask, &p->signal->shared_pending, NULL); + flush_sigqueue_mask(&mask, &p->signal->shared_pending, p); for_each_thread(p, t) - flush_sigqueue_mask(&mask, &t->pending, NULL); + flush_sigqueue_mask(&mask, &t->pending, p); } else if (was_ignored) { posixtimer_sig_unignore(p, sig); }