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.133.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 3C45340B0E2 for ; Mon, 24 Aug 2026 11:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787572483; cv=none; b=tfWRGf6vYsGndn5Xr27IjbzfC1hbzUksdCHismqcMdbkUMz91pSn2UzplXBWXswOlS2jvDYBcCu5NynH8NWk7c+tFSXAvT7itdiY3ZlrYPCTTd1s6qcyowrpFEW9JAcTUGG0kGAgOexPv+eH9WWSp5IAXKhJpINjjS3pRB/wQa0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787572483; c=relaxed/simple; bh=aXTU4O974YqVU55CteRCGvsy5JYDTaVTMwfMi0kcvMk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C1ZceigjnFPvzx56zEkCVy4cWGoQNGiHDKv1jIygMKDc1WuynQVrSbsF+2zMSfz9PQtjZdsz+dtyILKh24tYEo/X8hJVzOBOBZcI/PkdH0u9B+H1VbFARx6BJC3roPZmVB3Se1SzPQjH9wH4Z21IxzCDIiCb3XT7FtmBZePcg4A= 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=JQltJt1r; arc=none smtp.client-ip=170.10.133.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="JQltJt1r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787572479; 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=3/c4cafZtplnHwS+Pl5bFdWnHsJoTRrTzSIYf4uztbY=; b=JQltJt1rfUqJslcSY7baeTiksn/CS77/w6WnCmNBP4KqFD1nAcI8/B+ht9on0F4QcB5NSb oz2TPC1Mr6f4yXcLb8wPrcRg9uh1FO28KeCorw9bhtp+UvyEb8W4wEDKyLHGoWSRt21Iet o8cs6ngCFNJpkC9555x2j+p18pvxSaA= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-HHM9aix9PESBgdenGPVaVA-1; Mon, 24 Aug 2026 07:54:33 -0400 X-MC-Unique: HHM9aix9PESBgdenGPVaVA-1 X-Mimecast-MFC-AGG-ID: HHM9aix9PESBgdenGPVaVA_1787572472 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D7E08185FCE7; Mon, 24 Aug 2026 11:54:31 +0000 (UTC) Received: from fedora (unknown [10.44.32.9]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id D522618005AD; Mon, 24 Aug 2026 11:54:28 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 24 Aug 2026 13:54:31 +0200 (CEST) Date: Mon, 24 Aug 2026 13:54:26 +0200 From: Oleg Nesterov To: Thomas Gleixner Cc: Hyunwoo Kim , frederic@kernel.org, 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> 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: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 08/24, Oleg Nesterov wrote: > > On 08/24, Thomas Gleixner wrote: > > > > --- a/fs/exec.c > > +++ b/fs/exec.c > > @@ -983,6 +983,18 @@ static int de_thread(struct task_struct > > } > > > > /* > > + * Ensure that POSIX timer SIGEV_THREAD_ID signals pending for > > + * the former leader are removed under sighand::siglock _before_ > > + * taking over the leader's TID. Otherwise the lockless cleanup > > + * in release_task() can race against a concurrent signal > > + * delivery to the new leader. The former leader has PF_EXITING > > + * set which prevents queueing of SIGEV_THREAD_ID signals up to > > + * the point where it's sighand gets cleared. > > + */ > > + scoped_guard(spinlock_irq, lock) > > + flush_sigqueue(&leader->pending); scoped_guard(spinlock_irq) is not right. This needs scoped_guard(spinlock), the code runs with irqs disabled. > Hmm, at first glance... If we change de_thread() to do this _after_ transfer_pid's > (before release_task(leader)), then posixtimer_send_sigqueue() doesn't need any > changes, no? IOW. Unless I am totally confused, we only need to flush the SIGQUEUE_PREALLOC sigqueue's which were sent to the (old) leader before it changed its pid. So we can do this diff --git a/fs/exec.c b/fs/exec.c index a14f28b15607..550367e7fe6c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1029,6 +1029,9 @@ static int de_thread(struct task_struct *tsk) write_unlock_irq(&tasklist_lock); cgroup_threadgroup_change_end(tsk); + scoped_guard(spinlock_irq, lock) + flush_sigqueue(&leader->pending); + release_task(leader); } outside of tasklist_lock. We do not care if another sigqueue (SIGQUEUE_PREALLOC or not) comes to leader->pending after that. No? Either way, this means that flush_sigqueue() is called again with irqs disabled... Not a real problem, but can the change below work? Yes, more fragile and probably "fixes symptom"... 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); } /*