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 538E5374E55 for ; Tue, 28 Jul 2026 09:50:37 +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=1785232239; cv=none; b=LWH/koS26g1pzN4UGcb8cmOGAnxWpSNG6axG7KcQSWcEcNnde9trLfCf2XPQ3HNHK12aEImusZVk+eoWnbORFurlNlEMErdf1toDvQKTG157fyjRhN7E0BVf+Loa4jUQnWl6ocpDbYHOVDfuDoSErPTj5aUjf7P70aj4nVrr5NE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785232239; c=relaxed/simple; bh=iKkwr8V1PuRndsb7cgQEaiCzyGc93W31tew9oyt9XRA=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=c/tD9poIvPyziccFhFXVjzBvBo53pgjc3jSFywIhcd6GUr4+p2yb0yB15EM3V+it3JHTAyEh1N+PqtDcgbi8spQxla3Vl3FlHh8gMQgQch9r/lvYuXAKfThHPLjU7CLilJ5aJa7pdkkKG7QIYPPoQQv3q8uR4sRryBORKNRODu0= 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=hkAHMNdr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=k+8oujNo; 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="hkAHMNdr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="k+8oujNo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785232236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+dMiX263jf+8Bae1dw+OAYWda9quJsqvCsepo8Mcbw=; b=hkAHMNdrV9zgEmveMpYrAQupu9xOzctunByLSbuccbnq5jRM03bMopUtJQJQ6FnAnGRlas LUzU7gS5waLsujpkCyHcmsGgQTin6SyhqTLbp7F4fWZ6esyQDTI2uW0JgP+kNGNwQIbj50 5ER5KZa2cL4+v5WMqrGVMerkVDUrWlc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-E6lA8NLDPUuKHlhIkVcGwA-1; Tue, 28 Jul 2026 05:50:34 -0400 X-MC-Unique: E6lA8NLDPUuKHlhIkVcGwA-1 X-Mimecast-MFC-AGG-ID: E6lA8NLDPUuKHlhIkVcGwA_1785232233 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49571407d1dso27145725e9.0 for ; Tue, 28 Jul 2026 02:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785232233; x=1785837033; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=4+dMiX263jf+8Bae1dw+OAYWda9quJsqvCsepo8Mcbw=; b=k+8oujNoLEROoaRR3jBfX3MR01Ht/jvp4grpYKdNO8Sp36kr/bhixjr08vZIu0VdUS Y4WOj1Lf4TZfZn4AJbTfb2hScQTaE99ef1PaQbvyQ0bIRLTtzpz9rEtZGy+2wtzD9P11 HU5qPPalJp/LtYY7qjyU+ulpHfIOcHR5XGht2ImsVnmBEFjR/za2NAt7WQFvUfgaj+N+ kvVU6jGHLMhxL1NdBgQ67bUfzW1AvyoRL3i34NpcXxVOeErU8UgvwxFyOTvqnxuza9FT qCQDT0+fVtUA6qOmEOKVq7mB22v1YqmgAJgiusR97NTQqrNpyKvvY3M3aq/MtVm/qNrW fznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785232233; x=1785837033; h=content-transfer-encoding:content-type:in-reply-to:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=4+dMiX263jf+8Bae1dw+OAYWda9quJsqvCsepo8Mcbw=; b=GQvJ63UeZiWVgPCYjaPs/XqNdSobJ31Mld1/91AblcpqakaoPQk8nhG19soYL/MtqA T9ddPTcOy2QgGyVM0AqhioE7SBNKIxc38UgregQrIWf9eLYyrTWHvCYlqycu9iClgfFV Bb9BI9Vwxwymbrg5GKsv60ncbvsSlivKRuGQd/c5xzOu+Y9OP0SXNOUxZs5GJry9b0Is JHxLiPGMgojZF6oK/8vXsbm4DIMPmKQcCSJZrwQvKwriMb7vKmgylIAD+f9bdBgk+lCA on4ahCEOC+7djeHo3m84e2w/3ua6F2XoqOq5h61EhXiuRpcTKdkFQW/ZPhyZNYsp3ZfE 2mZA== X-Forwarded-Encrypted: i=1; AHgh+RpwHppyr9eDqW7ID9KaXNQrBp9intSjaGrWkr+rpq8izErHz/mM71DpWpN53xjFevUxtNah7DlC9b367SM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw03Ma4FGs/8n5swJ+keKXY4boyNQ09Enzx1olwXDg3TCsB919x LDwRXMrGqtf7TVKas02iufYMAtcrbVxefrf2rmaXF/mx25/tKhxNoqhkti0+Gm5iEPPfjv3vu5k 5PMDUzWhhDDlFauG+46cEO65znW/hJADR+6iJoabymFmFDuEo/OydWx7mFAflEmgW/A== X-Gm-Gg: AR+sD12r/jXSAi7DfpSR7pLCCpKJhZGBlTX2hjxe1WSE3KwhZhCcSpcsfzKzFhoXFh8 fTXC0BMckohonJDWfexzToQT16OaJlOtMk50VS87VR8QlepZOVVqlVJyLgM7mKEQ2WbSNL/X485 p0jhJMaPfjY8KL82rhk+tOFYBOiool4YRUcjK3Tgc1LWklm31u8rLccT3QKsyn0BagtpQ6tN05Q qjCoE91Xz1A7d4BhiQMPIhRkcHT8e6lAahlpxY7bZ1ZbgiqxWEpyH6QkGKeoPIj4pxBCFOUht4R Rk1MrQU5GhqfXSPjeaWYnHP27KkEeIqO3i6pwXM4+/32h5NIhFWlH0V9tfZKZrpZv3/8hIE3z3O LLf4A6zJ7COUlw4UtOQ2rpXF94ypDIGxiBR0k3069PuBtg6kYNlUTQWb1GOe62Z/KG2N4x/YlxA 0fnQ== X-Received: by 2002:a05:600c:8214:b0:495:5cda:52ec with SMTP id 5b1f17b1804b1-496c643b0f5mr17224545e9.16.1785232233387; Tue, 28 Jul 2026 02:50:33 -0700 (PDT) X-Received: by 2002:a05:600c:8214:b0:495:5cda:52ec with SMTP id 5b1f17b1804b1-496c643b0f5mr17224185e9.16.1785232232921; Tue, 28 Jul 2026 02:50:32 -0700 (PDT) Received: from ?IPV6:2a0d:3344:5521:6b10:58fd:68f:7756:389d? ([2a0d:3344:5521:6b10:58fd:68f:7756:389d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c531afsm63156402f8f.24.2026.07.28.02.50.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jul 2026 02:50:32 -0700 (PDT) Message-ID: Date: Tue, 28 Jul 2026 11:50:31 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v3 1/3] af_unix: Schedule the garbage collector at task exit To: Nam Cao , Kuniyuki Iwashima , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev References: From: Paolo Abeni Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/22/26 11:31 AM, Nam Cao wrote: > When a task exits while still having dead cyclic reference AF_UNIX sockets, > those sockets stay behind indefinitely until the garbage collector gets > scheduled by an unrelated reason. This can be observed with the program > below. > > Resolve this issue by scheduling the garbage collector during task exit, > after the task's file descriptors have been closed. > > #include > #include > #include > #include > > #include > #include > #include > #include > #include > #include > > static int send_fd(int unix_fd, int fd) > { > struct msghdr msgh; > struct cmsghdr *cmsg; > char buf[CMSG_SPACE(sizeof(fd))]; > > memset(&msgh, 0, sizeof(msgh)); > > memset(buf, 0, sizeof(buf)); > msgh.msg_control = buf; > msgh.msg_controllen = sizeof(buf); > > cmsg = CMSG_FIRSTHDR(&msgh); > cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); > cmsg->cmsg_level = SOL_SOCKET; > cmsg->cmsg_type = SCM_RIGHTS; > > msgh.msg_controllen = cmsg->cmsg_len; > > memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); > return sendmsg(unix_fd, &msgh, 0); > } > > int main(int argc, char *argv[]) > { > int fd[2]; > int i; > > for (int n = 0; n < 100; ++n) { > if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fd) == -1) > goto out_error; > > for (i = 0; i < 100; ++i) { > if (send_fd(fd[0], fd[0]) == -1) > goto out_error; > > if (send_fd(fd[1], fd[1]) == -1) > goto out_error; > } > } > > return 0; > > out_error: > fprintf(stderr, "error: %s\n", strerror(errno)); > } > > Signed-off-by: Nam Cao > --- > include/net/af_unix.h | 5 +++++ > kernel/exit.c | 7 +++++++ > net/unix/af_unix.h | 1 - > 3 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/include/net/af_unix.h b/include/net/af_unix.h > index 34f53dde65ce..686f6f1d1c21 100644 > --- a/include/net/af_unix.h > +++ b/include/net/af_unix.h > @@ -14,11 +14,16 @@ > > #if IS_ENABLED(CONFIG_UNIX) > struct unix_sock *unix_get_socket(struct file *filp); > +void unix_schedule_gc(struct user_struct *user); > #else > static inline struct unix_sock *unix_get_socket(struct file *filp) > { > return NULL; > } > + > +static inline void unix_schedule_gc(struct user_struct *user) > +{ > +} > #endif > > struct unix_address { > diff --git a/kernel/exit.c b/kernel/exit.c > index 2c0b1c02920f..593ac4b0105f 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -71,6 +71,7 @@ > #include > #include > #include > +#include > > #include > > @@ -1009,6 +1010,12 @@ void __noreturn do_exit(long code) > exit_task_work(tsk); > exit_thread(tsk); > > + /* > + * Must be after exit_files() and exit_task_work(tsk) to ensure that > + * the task's AF_UNIX sockets have all been closed. > + */ > + unix_schedule_gc(NULL); Sashiko noted this can cause relevant regressions: https://sashiko.dev/#/patchset/cover.1784712370.git.namcao%40linutronix.de Generally speaking hooking the unix GC at task exit time does not feel right (layering violation). Perhaps scheduling the GC with a reasonable timeout in unix_update_graph() would be better? /P