From nobody Mon Dec 1 22:36:57 2025 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE2D51E0B9C for ; Thu, 27 Nov 2025 13:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764249333; cv=none; b=EYSG7SgVD/dwKKzdN+NGAjluOfByF2QJDLLRifMlef4qHBegM8GmB8eGJWbOnGLCjdWyd001vZeYP+qryP7ISJa0nBK6O3j0hSF7MDsblZG63FdUZpyemodwhsbIs1zeMr5Gp/cwG8C09VjLIj9puQoIOH+rd4i+KexeedrWmvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764249333; c=relaxed/simple; bh=NhxLz/AEP33wGpx1J5GIWfydpq2C0Alpu/x1FSI4C9M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=TAV858mj1h53QRctzw6Wb/bH42r+ruIwjmq18V0sUl3ZoADfrGFZiHs0fPkUIfKgPumL2syij50DdPRr0NcuoiVl+pM0XIemfNSlqkJuhcvPBq7F9/RiV7yHIguqqqu2Jv7h+oAsUFSThHXqOtA1TLWbs+pcJSQWng/jIOggso0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ECx58Eh5; arc=none smtp.client-ip=209.85.208.48 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.b="ECx58Eh5" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-641677916b5so1712365a12.0 for ; Thu, 27 Nov 2025 05:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764249330; x=1764854130; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tRUSB+8z0GMLMvxEZa0ALdOwVMKFqCZ7bv5e3MQ2iRw=; b=ECx58Eh5wtDKUS7q3DweN0tKtuPYe0aieOwsz5hOIYSiSfqW63xq3owaTsZG6tLYcs XY+hQko94evawkQ+N8mfCLpPggBC/efE/pMGwhfdkAVwp8dPC/JVJveTq6f+4I76d5ab x4PQb4fpGdPv5GEDRbxCHHJ9mIAoZ7zugSZTbfWm944TXQVxv1PC8uHRiHMf8uj2dz54 p0r+6Nmw8sPpS+HX5H9KmquETJCoN/GS8auhcOhbG4V2txYFbda+mG/27ra63Z8Zbr9y vWgT4nwEpM3s2ijRQtp/OKaGb8/Gfg+64XwsNW9UJD5EXmAhE3p/+BdzDXw/8XLCty+b uWew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764249330; x=1764854130; h=content-transfer-encoding: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; bh=tRUSB+8z0GMLMvxEZa0ALdOwVMKFqCZ7bv5e3MQ2iRw=; b=lL533rfhqW25GBnF69wmNg4tsHoXaex1EBAoi3pLjTGVeLiJb1U7r+yvn/ZTpoJNi3 ZdvFMyEBfh0kBiqd2l+Ov/40ZTqEfmhEdyyADBJ+EU7zfuA0q76EUf42Z0KviU9jXREQ ydlUa48b7FpIyRdCjQcnFnZceRQY4SHq26WvSk5drj7sG+9m91uVvRRH4oeAAI3+E59I Xw/rup6zP2TB21MqhFzWZ4xJ8W/k9Qo2awX8lilFJA15zRuaMPk3HTZigVEdT/EQC3ts H9EcNJ1G4Eu4ipKMEcDXP6TuxnSrMIAbHqUumJDT2g1uR2bL5Dl3+bYDH5MvOKK6xAmt ZQoQ== X-Forwarded-Encrypted: i=1; AJvYcCW9QoNWMJuQ8MpGvlOhzlV05sTiizvHzC6qxXu5zpVQDHUWC898qfGosJpuOMUpYaS7U0l5Nj7p9/0HGCY=@vger.kernel.org X-Gm-Message-State: AOJu0YyBR3wyu0GldodeYnPXBarlXhPbYYeyjNnuRTkhba+9k++m5zsN 3JdNW04Kbyt5UMfRv+14KorXkvex0rEcvQy85xEAysgrwHtC/gemGi3s X-Gm-Gg: ASbGncunkudssze4ZSCAAPLKN5J22Hs2oTtZKjJay2HasOt81GBTG5lh1cEfg2ScLhA R4l7JlIf05uyhBKm96eNEu9hiZnDstn6SamP0PQlloEN7FSFshhnybtVsGE1yHsWCtsZk4B30Xx 6gtFvmfTjbyFFtjSE9Z7jSsJzYMbAMarBi72FiBsneRF7RfIKIx1hK+/RTlnpEFpCLNSxRzXe7X FwSQoFOo9JxFStLuGt9vJNVhWnZ4dVhQZwr+4X4V84Tc0arwMBMyL25uHJ/pr4J9T2UT2zCn4xD ZpEHX6wd9cjzzjpu3X/pp5f9TfXa0FTO+GFsBQxZJ5hWErmqRujsPs8E7Ic7Ka4wcXzekOszAN2 Pwi21u5BvnU0LzenvJYhgW87iUNuyc0iXqZ4cD4ayNvtjeEmWyk2Y5DWqHrQLdo0dvh8D0haww7 eSqnv+LUM9cGaVAMeXyZA0ii8KuBdRp5y2z2PcoWjG1HJL1S7AL7+1VYZZO/4= X-Google-Smtp-Source: AGHT+IHTdXZt2L4k95r0xbM3BoEPbnIX0nU85H61ECXdxu7XozaXch2P1ClAIz0ZRxfh7lXZmmJChw== X-Received: by 2002:a17:907:1b0c:b0:b76:3dbe:7bf0 with SMTP id a640c23a62f3a-b767150b850mr2128257366b.2.1764249329718; Thu, 27 Nov 2025 05:15:29 -0800 (PST) Received: from f.. (cst-prg-14-82.cust.vodafone.cz. [46.135.14.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f519e2f0sm161963966b.21.2025.11.27.05.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 05:15:29 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2] dcache: touch up predicts in __d_lookup_rcu() Date: Thu, 27 Nov 2025 14:15:26 +0100 Message-ID: <20251127131526.4137768-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rationale is that if the parent dentry is the same and the length is the same, then you have to be unlucky for the name to not match. At the same time the dentry was literally just found on the hash, so you have to be even more unlucky to determine it is unhashed. While here add commentary while d_unhashed() is necessary. It was already removed once and brought back in: 2e321806b681b192 ("Revert "vfs: remove unnecessary d_unhashed() check from = __d_lookup_rcu"") Signed-off-by: Mateusz Guzik Reviewed-by: Jan Kara --- - move and precit on d_unhashed as well - add commentary on it this obsoletes https://lore.kernel.org/linux-fsdevel/20251127122412.4131818= -1-mjguzik@gmail.com/T/#u fs/dcache.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 23d1752c29e6..dc2fff4811d1 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2342,11 +2342,20 @@ struct dentry *__d_lookup_rcu(const struct dentry *= parent, seq =3D raw_seqcount_begin(&dentry->d_seq); if (dentry->d_parent !=3D parent) continue; - if (d_unhashed(dentry)) - continue; if (dentry->d_name.hash_len !=3D hashlen) continue; - if (dentry_cmp(dentry, str, hashlen_len(hashlen)) !=3D 0) + if (unlikely(dentry_cmp(dentry, str, hashlen_len(hashlen)) !=3D 0)) + continue; + /* + * Check for the dentry being unhashed. + * + * As tempting as it is, we *can't* skip it because of a race window + * between us finding the dentry before it gets unhashed and loading + * the sequence counter after unhashing is finished. + * + * We can at least predict on it. + */ + if (unlikely(d_unhashed(dentry))) continue; *seqp =3D seq; return dentry; --=20 2.34.1