From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 64EEE348883 for ; Wed, 26 Aug 2026 09:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787736997; cv=none; b=Z13GZBiWitcvjWz4yk/kuOrsQ9/PzBi/5YoyjQNYoosvtUBTHR3RRzmPnjY1U5KmcbYuj+/NNNGcZFWZ1O9NLB/Z2aLI1UcW7Yn81Qbuan4WD4LPFRaHbskhpQOQk1bZppgcnu6603kmkDXgsO8R8O+DnakftZRKMa19+KylDE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787736997; c=relaxed/simple; bh=02IUlLhIWlDmT6OSr7bTiAxmkq3K/ugJ1permQQ7Qew=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZTEOE3srSS32EeXlUzUsJ525XOAWBh+05jItwzFhZoCY7ZVBU0NtyNsO3zS1qCvXn+zycRPwC7VYESxTqw0iqLHxGABXexs/zasWU7OdfWfGuLw6S+DnK2SX13Ubs6amoZh5EQirCAMl3LY4bh3EUwiAXUlKV8V6mVSJsPjmy0Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MCvAiwUd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MCvAiwUd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787736995; 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: in-reply-to:in-reply-to:references:references; bh=TMF58fL0GaXjj3mmPnwq9N5wS4O7IgYqLDS2Q/+Q66k=; b=MCvAiwUdoEIGpyMa/pYEhKImy52a2MqdYl4TTzLhMQ/cKkFlxgqFMsNwF3J6969LEV2ayS Yi1RDFS6LZeiRUx+7qISWu1vXW7RqDrPFN8YL3QIpmW14w6ce/5YLOG16tHk4NU3auu14U /cl9h6LM3QhnYG+4dxGDFHfsTVXNApU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-CUze_7hePU6AveaVzlfGpw-1; Wed, 26 Aug 2026 05:36:31 -0400 X-MC-Unique: CUze_7hePU6AveaVzlfGpw-1 X-Mimecast-MFC-AGG-ID: CUze_7hePU6AveaVzlfGpw_1787736990 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C646D1954ADD; Wed, 26 Aug 2026 09:36:29 +0000 (UTC) Received: from fedora (unknown [10.44.48.90]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 4AE1918005B4; Wed, 26 Aug 2026 09:36:25 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 26 Aug 2026 11:36:29 +0200 (CEST) Date: Wed, 26 Aug 2026 11:36:24 +0200 From: Oleg Nesterov To: Thomas Gleixner Cc: Frederic Weisbecker , Hyunwoo Kim , brauner@kernel.org, peterz@infradead.org, anna-maria@linutronix.de, ebiederm@xmission.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] signal: Use list_del_init_careful() in flush_sigqueue() Message-ID: References: <875x10hrkt.ffs@fw13> <8733w3j1i1.ffs@fw13> <87pkz6gms6.ffs@fw13> <87fr02gegn.ffs@fw13> 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=us-ascii Content-Disposition: inline In-Reply-To: <87fr02gegn.ffs@fw13> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 08/25, Thomas Gleixner wrote: > > On Tue, Aug 25 2026 at 20:53, Oleg Nesterov wrote: > > > > And I'd suggest to check t->exit_state instead of PF_EXITING, > > posixtimer_send_sigqueue() can't miss it if it is called after > > scoped_guard(spinlock_irq, lock). > > It neither can miss PF_EXITING which is also set under sighand lock. Yes, I didn't mean that the PF_EXITING check is wrong... nevermind. > Once begin_new_exec() sets bprm->point_of_no_return = true there is > _ZERO_ reason to queue any posix timer signal anymore. Any failure after > that point will be fatal and shut the whole process down. > > begin_new_exex() > { > ... > > bprm->point_of_no_return = true; > > scoped_guard(spinlock_irq, &me->sighand->siglock) > me->signal->flags |= SIGNAL_EXEC; We already have me->signal->group_exec_task. In mt-exec case it is always set under ->siglock, and cleared after the last thread passes __exit_signal() which takes the same lock. > de_thread(me) > ... > > // FIXME: This sequence should be cleaned up with a > // posix_timer_exec() function with a proper stub > // for CONFIG_POSIX_TIMERS=n. > > #ifdef CONFIG_POSIX_TIMERS > spin_lock_irq(&me->sighand->siglock); > posix_cpu_timers_exit(me); > spin_unlock_irq(&me->sighand->siglock); > exit_itimers(me); > flush_itimer_signals(); > #endif OK... unfortunately we can't do this CONFIG_POSIX_TIMERS sequence before de_thread()... Another not-yet-exited sub-thread can create a timer with it_pid = current->pid. Right? > and in posixtimer_send_sigqueue() > > if (!likely(lock_task_sighand(t, &flags))) > return; > > if (unlikely(t->signal->flags & (SIGNAL_EXEC))) > goto unlock; See above, I think it can check t->signal->group_exec_task. Perhaps along with SIGNAL_GROUP_EXIT. So. With this change release_task()->flush_sigqueue(&old_leader->pending) can still race with posixtimer_send_sigqueue(), but it will do nothing. But it also does "nothing" if tmr->sigq is already pending (!list_empty) so I am starting to think about the change below again... Oleg. diff --git a/kernel/signal.c b/kernel/signal.c index bbc0fd4cc4d7..4d12ebba33f9 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -477,14 +477,14 @@ static void __sigqueue_free(struct sigqueue *q) void flush_sigqueue(struct sigpending *queue) { - struct sigqueue *q; + struct sigqueue *q, *n; sigemptyset(&queue->signal); - while (!list_empty(&queue->list)) { - q = list_entry(queue->list.next, struct sigqueue , list); - list_del_init(&q->list); + + list_for_each_entry_safe(q, n, &queue->list, list) __sigqueue_free(q); - } + + INIT_LIST_HEAD(&queue->list); } /*