From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794760589; b=hOxLhVHUONgPnZ77x9G3hva+0RTcTUQqzOUDwipPbmYnaOakw7j1wTOo+UxQDXaCeRD+ QUby5pdzMW2nVK4/CRoED9RJ0OtaShTsuvnWbtST1mWcoYVLnkKVqPBdHfDLK83DBRnBM sLM5Xosg0/JhOL57+Mlm/9PMfttIi60RqsyqG0r/XwCRaXhHw1uIXHBqQ8bVSitmG9fdE l0o7qeimarVRA5/flVgV38XvTbh6vLZwINxLObC6Rx2sLfbuDNyLMuyVWE3Z7s1UCiHhR oN919csqRbexCkyJlvk1TRaTKjvayQ8cSCmpcQMEMPm9I1HwlmZ47K1iQu9BmVzboDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794760589; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=tmP0MrFrcAmuuhTA1131QnIkXEUazkJUfQgIKsBWJ2w=; b=QFcYa2g7hAwlLmgeZQv72gT6q3axJALIfEoqHnWspBspB9TvYlNTqXjN26rR5XZ/55V6 4CyIYea7xKU3PFJFrh9F0FPbF4L12i9GhWdvPPar/xRl5ddyjANRYKqzm0I04WLB/5GK+ farlzVbCVD5nk2Fz1TpMfMmJsGP2a+9Ts5juI7oystWSx+0UPfNWHp7ynM9DhR2ld12q2 UiBI/V9wK1h3zO2OdyRj0Kwzf0WpNxnOhnk97PsG3YQoQKE3KASn/LzcFfBxUhJeOn/ql TzPSYTl8UmhJZSbApXg1NXeBaV25Y9fBmelq70bF+gWObppuxH7CnN2N4O15YCL3CFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JlrNgr19; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF1B6606A31F for ; Sun, 15 Nov 2026 16:36:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF1B6606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JlrNgr19 Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b3ada81853so2324065c88.0 for ; Sun, 15 Nov 2026 08:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794760588; x=1795365388; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tmP0MrFrcAmuuhTA1131QnIkXEUazkJUfQgIKsBWJ2w=; b=JlrNgr19qouTdtB1fx8LtqYf5Rts+F8e6aG6lxQP1cD2O1n2YYUWEcW1kszo/Cw3fK V5NkbOkZ38vr0E/2v2t8tXY9wALoKMgJQSDLoTQHXECefXkgOClfLL0j2TA1+hhY+cY9 Fxw0YOLcW4sfpoUQIApBTitHY9L0ZePiuDF4kxOvLDVJlrqagOC/LleIAn348/hFyKg8 LKIza/HMGRv3gmBGOv+CIuo9FCaIZ/iMDuLdeb1AXBH0kt6T4+66DJYakhQnSLeIH5xo qlK4qfRtCki02eK2L2K/+VOWxkaS/snckBp+g2FNsINI/SH8YR50tWrMX+Gu2F4Sd+ep iLeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794760588; x=1795365388; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=tmP0MrFrcAmuuhTA1131QnIkXEUazkJUfQgIKsBWJ2w=; b=nMj7poqRAIYxtVVDIuHB+o0WsvBaizAPbBrRC9ByQzygmi8phPUJVtbr92A/tQTheT 9piJ6PCfF1LJa4Kjue20H9gfoLRDTrA3ZYRzkQa2NzyEZA2CVKWoYqIVv1NOzOJk3LyB dD3XY0mx/baZShEDw7BQXfHPiedy2rLnazInIS5Y5/P5roeWIdRGnqauoeH+wdacMBZn chQ+4HuQ0MmyGMEfJg2PsYPClMNk0Fl5ci/Naae+RB/BTLOJjl+A9KHu9z9T+YktQR8i KPvhTlwdTNmqn60PRrz8planYNdegXThQRR3eppy5ZXZDZlZpZ8PnsghTTEwxPu9hBTt Z27g== X-Forwarded-Encrypted: i=1; AL+hErEKW5k09fpsvyA2G3P8Rc0kwnsAep36rpxFww+H+PV2yib5pToaI+rxJBHWujLSt2tEDc5xC06P7ergwQM=@vger.kernel.org X-Gm-Message-State: APuU4Z+TOWO4fsHhcgdQvTzvtUuh6had5qlOOixFvsNwiqPFFJK5GIon X+I8awIM8YH/Qd575mDLdaXbVZpZpIP/FyCi8/YWGIAL7p5lds7fr8sBM3xO6kXP0Bw= X-Gm-Gg: AYBFou347ev0j+I6jAbjWIS8cyS5yLIyhyR0F1QGSQD3GOXpy/QSSk3Fpg0QuU/GMEv sOtywIpB+9T2YN+GAoIx2Ujcr7VEEzVfJ4fPWqw/LpELHUsxDi9PLNLQ0A/cAQH7ZFeDQ8byW/h z8iMFipuYT6QPdHfJTy3q1mmOL0yPoE6bgmORlS/1a75wnmfLzrgo5DoIrOMehy65OU4z5QJYlQ lsBMihwLASDZCkWEGwBBGNyF88aiEVISQ8p2UXpt+WnSboLpwbodFXfPSfb2pdzxmpuPgyRYYDY iSO+ZAAWaQwojkL/Pb/AzzS9frnz32CA5yPzJ70mXSglxaz6tsdbBO4UH465zYD2RKBKNRWMVYX 1kof+8uIlbA2QJJHEeoYGp1pL1JNYmfuCWDO9qA6f89zH/ee0Na10r3NMXfF8jNugTfGEG8IJhX AoUlKcMXi3oO7Z6+zVeBYFu+yINw04fOjzmMqyaHHm/qMU+78ff0nAli3zthZOIb5i57yj+Nl34 aDywqrVe1G+l1Sn53Aa8R2vKWJBqODEBZLDR08K+0hLGh4mAo2EvxIqHB0yhLle+Xvg28NGyz/7 muiH0xVOiCVK8BbfsbkL+g7XS4MAOQ/XgPh+H/wUoyS7ktKKq4nuJhYsuvRpxAqovkZo X-Received: by 2002:a05:7022:7f0f:b0:176:a225:e364 with SMTP id a92af1059eb24-1b50312eb89mr7083533c88.35.1794760587827; Sun, 15 Nov 2026 08:36:27 -0800 (PST) Received: from youngkk-vm.localdomain (67.216.200.102.16clouds.com. [67.216.200.102]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5031468b7sm29298232c88.5.2026.11.15.08.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2026 08:36:27 -0800 (PST) From: Cheng Yongkang To: Alexander Viro , Christian Brauner Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [BUG] devpts: lookup racing with devpts_pty_new() can return ENOENT Date: Sun, 15 Nov 2026 08:36:20 -0800 Message-Id: <20261115163620.225761-1-teel4res@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Al, Christian, I hit a narrow race in devpts. It needs a lookup of /dev/pts/N at the same moment pty N is created, and the result is a short-lived ENOENT, so it may not matter much in practice. bacdf1d70bbe ("primitives for maintaining persisitency") says that d_make_persistent() "is always called in strong locking environment (parent held exclusive, or, in some cases, dentry coming from d_alloc_name())". devpts_pty_new() is the d_alloc_name() case, but it does not hold the parent, and the d_alloc_name() dentry never goes through the in-lookup hash or i_dir_seq. A lookup of the same name that missed the dcache just before can then finish in simple_lookup() and add a negative dentry: lookup devpts_pty_new() d_alloc_parallel(root, "N") miss d_alloc_name(root, "N") d_make_persistent() -> positive simple_lookup() d_splice_alias(NULL) -> negative, same name Both dentries are hashed under the same name, the negative one first, so stat() or open() of the new pty returns ENOENT until that lookup drops it. As far as I can tell, the old d_add() code before b4a76faf9d96 ("convert devpts") had the same window. On v7.3 I ran one thread that opens ptmx and immediately stats the new /dev/pts/N, and 16 threads that stat the same path. In 120 seconds the opening thread got ENOENT for its own pty 13 times, and the other threads saw ENOENT for a pty that existed before and after the call 26,372 times out of 6.5 million lookups. __d_add() and d_alloc_parallel() have changed since v7.3, but the same window is still there in next-20261113. The same commit message says what d_make_persistent() would need if it were ever used with the parent held shared and a dentry from d_alloc_parallel(): the in-lookup logic of __d_add(). I tried that direction for devpts: devpts_pty_new() takes its dentry from d_alloc_parallel(), and d_make_persistent() does start_dir_add(), __d_lookup_unhash(), end_dir_add() and wakes the waiters when the dentry is in-lookup. It takes no parent lock at all, which is weaker than what the commit message assumes. With it both counts went to zero, and basic pty tests still passed. You may prefer a different fix, for example creating the dentry with simple_start_creating() as mknod_ptmx() does, which I have not tried. I can send my version as a patch if you want it. Thanks, Cheng Yongkang