Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp70988lqg; Wed, 10 Apr 2024 16:04:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpJ1H8Kn8qvJ6+mxzCZgbsbJWFVPSPtuA+9oKxP6Xgbi82hTMfZaL7pnTeMybHH6GSWue96ylj3q4UW6QHRA8OMN0G/fYhTS6iNP9Wpg== X-Google-Smtp-Source: AGHT+IHsq356KrAIhh6K8uDZLEetjvPPtfxV0IUgtTwhi9PHdS1xYY+eGUz6ipRfErhRVYim5vGt X-Received: by 2002:a17:906:18b2:b0:a51:b228:9282 with SMTP id c18-20020a17090618b200b00a51b2289282mr2330269ejf.44.1712790241947; Wed, 10 Apr 2024 16:04:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712790241; cv=pass; d=google.com; s=arc-20160816; b=UYu0rhnQuExyaJn13fs9b5SVLExIKUICQ8P7icb8faIgZyU+ETy38/Dad3IXvl0rra nFxQOsd/8nkyBSFRpgCvxaBbUrsAeX/mJphB6KBNCpRdZE3s8oYjrqHUWQXkk+cZbita WFV6uUidxBRSxWz7PBXXwq0Ln9yerAD75oKoHgYGgDmhZ0/m2IxfJlT/B6bYCcHfWmGm +m5JdMHqViNyiGNOs82soArkF3+6zON+WbFln2Xo7Z1HiZk34WC87uyCpdE1M6emyrBq HtwuAhyRnitAFi6BxJVDFOy9kLLWAEpgx7ty0P9KhA7zSGvvnnq36cEFJ5yVTT82/9i0 H5Og== 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=h6hDrXB0chXNrUH4sCnb+tErkyrDv3iJrXtwT3bPMl8=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=WAaZ5hcbkdQ9h+UZ/h5qS7VxYCQt6TFDd6uR4xBS+zw5camlJkZIFGKPzdJqn/Q0pd Iev13031Xzy+uuwRBfywXoSWuJHfWkoLKzjmCf8bLQooCt8a4fTfKNreBBaIdSGiMv74 owVCSjcgq0E5CrcnciAQeRcgxB/xYgzCkvTr7KlkUkMxAL0z0LNrYtd8S83niH534NzY 3o8QAXvZi9Dh2R6bwDG6TTpvaHRY+QD4f9iY0sn7zUjgnr5yS9hcOt0v5EOYe06s9Du9 clcLAKnGfZbGgPy2iqMNxVd3uHFWBGYMVh+JM3Qb4GxgvdGIzgwfASz2eTYgNfmaZJMQ RdDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=V9lct4Gz; 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-139499-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139499-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f7-20020a170906560700b00a51d069001bsi108281ejq.878.2024.04.10.16.04.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 16:04:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139499-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=V9lct4Gz; 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-139499-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139499-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 CACE01F2963D for ; Wed, 10 Apr 2024 22:56:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D62B136E2C; Wed, 10 Apr 2024 22:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="V9lct4Gz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="N/o6o6fS" 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 A862E13664C for ; Wed, 10 Apr 2024 22:47:33 +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=1712789255; cv=none; b=k7QWF4dx9nrgHPp/RrkiFAY+CnvpbxXnhy/VQpWmXaRft3Zeykc6Ss+tPEFnLMkmNMODsXKBJLHD6UBqK2s4gyVI1yCghew1jtMuKdO6ZGrhvoZl2Nu7q515Xaafg9tSx9Y5jXdmhRinHneSfuvSrPKWYT+eJAsQpPsxsyTD7BE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789255; c=relaxed/simple; bh=S6JUDkyUPN6u68oQn5OUPewj7arp5+lzXuIlS/xwEHU=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=KRm5m8Pa6hX02+cjQM6neVxa9vKSQoTdKKOSoPDIK5+AA3Foa6m5bvwNSRJYLUcOhRBGsSpEbnRfSCYaFM1Vt0+UtJI9DbG7emy7j+iygn89WOxD1AV5r8aIVgLeXKHASz1ezjmfiybnpIAy01JcQkOGO+18pqpnp1R3gdiULuI= 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=V9lct4Gz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=N/o6o6fS; 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.760259947@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712789251; 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=h6hDrXB0chXNrUH4sCnb+tErkyrDv3iJrXtwT3bPMl8=; b=V9lct4GzHZn49a1TrhvBCi/6RZvlkGjiUqQfEuE5lNaZvghRTrpIzvenCiD7ig0kKM3WfC k1dZcsPXInjzXGnhKR7qe5JYm8xcT0jvFX4Llt0HMLzjqT4LreIP+T7ERDAOvoO4OhwW7R YeivbXxQcO480iQNRn72IfVtPtzTT2Qi86jPyH77Zc8wI4Cc2wGqtctekvsryjC765djG9 13jd2kkk/L5MAosfOiLJt+v9SuimmAdqPfrhmDZtrMLjPCM1CTr5jroYGMfck9IBG3PmO2 xvKxaWeDu903OKKoW3UlnfoFHwpxJ3GAIIUVySK27cIzuiXAPK+2qzL0yWt23A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712789251; 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=h6hDrXB0chXNrUH4sCnb+tErkyrDv3iJrXtwT3bPMl8=; b=N/o6o6fSPXwuZzN6JKYJYD+vNEglvin24m4COI1zmV4PdYMYn2m1NhCYkmQSy781u4qMbZ pJrEW2hqqEqs0CDA== 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 45/50] posix-timers: Handle ignored list on delete and exit 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:31 +0200 (CEST) To handle posix timer signals on sigaction(SIG_IGN) properly, the timers will be queued on a separate ignored list. Add the necessary cleanup code for timer_delete() and exit_itimers(). Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 4 +++- kernel/time/posix-timers.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -151,7 +151,8 @@ static inline void posix_cputimers_init_ /** * struct k_itimer - POSIX.1b interval timer structure. - * @list: List head for binding the timer to signals->posix_timers + * @list: List node for binding the timer to tsk::signal::posix_timers + * @ignored_list: List node for tracking ignored timers in tsk::signal::ignored_posix_timers * @t_hash: Entry in the posix timer hash table * @it_lock: Lock protecting the timer * @kclock: Pointer to the k_clock struct handling this timer @@ -174,6 +175,7 @@ static inline void posix_cputimers_init_ */ struct k_itimer { struct hlist_node list; + struct hlist_node ignored_list; struct hlist_node t_hash; spinlock_t it_lock; const struct k_clock *kclock; --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1036,6 +1036,18 @@ int common_timer_del(struct k_itimer *ti return 0; } +/* + * If the deleted timer is on the ignored list, remove it and + * drop the associated reference. + */ +static inline void posix_timer_cleanup_ignored(struct k_itimer *tmr) +{ + if (!hlist_unhashed(&tmr->ignored_list)) { + hlist_del_init(&tmr->ignored_list); + posixtimer_putref(tmr); + } +} + static inline int timer_delete_hook(struct k_itimer *timer) { const struct k_clock *kc = timer->kclock; @@ -1068,6 +1080,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t spin_lock(¤t->sighand->siglock); hlist_del(&timer->list); + posix_timer_cleanup_ignored(timer); spin_unlock(¤t->sighand->siglock); /* * A concurrent lookup could check timer::it_signal lockless. It @@ -1119,6 +1132,8 @@ static void itimer_delete(struct k_itime } hlist_del(&timer->list); + posix_timer_cleanup_ignored(timer); + /* * Setting timer::it_signal to NULL is technically not required * here as nothing can access the timer anymore legitimately via @@ -1151,6 +1166,11 @@ void exit_itimers(struct task_struct *ts /* The timers are not longer accessible via tsk::signal */ while (!hlist_empty(&timers)) itimer_delete(hlist_entry(timers.first, struct k_itimer, list)); + + /* Mop up timers which are on the ignored list */ + hlist_move_list(&tsk->signal->ignored_posix_timers, &timers); + while (!hlist_empty(&timers)) + posix_timer_cleanup_ignored(hlist_entry(timers.first, struct k_itimer, list)); } SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,