From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 BCA901C84A2 for ; Thu, 20 Nov 2025 00:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763599103; cv=none; b=dXjImqhNYwDqvYTHkNQnUTE2egY1gL2z6S/KsvahhZEmMaVX5tJZgDnk2zA7iZAodUMTpkS1xBnDau8EDeGIVbSi/2qaX/ASa/fYRl+RASisuRLhFDtV9pdD929yYpY2YLkULe6jefo/FpfdaYXT/fJkFcllhDSRBO2O1B3KREA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763599103; c=relaxed/simple; bh=kUWAYx6zSILh8SSAIikd4TkrHPiAO/7RGiLykZsVOWs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sOYgrxAzVvwidoMmGi4DSmOv/aUUygU57I7IldK52WMcoxzWKNFnjw1MsDD+KdGUAqCg5OlKHz57yIeyh/gjGXeXN9hbAJvcL/I72NYozHjWa80yWu5zSrFUJE+gpvijVZMUzkg/DW4+riI8A50LRMJ2nbO/6/xLyN8UP6o3IeY= 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=RO3UVNiz; arc=none smtp.client-ip=209.85.221.43 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="RO3UVNiz" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-42bb288c17bso196000f8f.2 for ; Wed, 19 Nov 2025 16:38:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763599100; x=1764203900; 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=KdAuQPMlMqnLA814W2ruOeTYaPbQYBkcVQoSYWqQY/8=; b=RO3UVNizZ0MfaMlC7TbZ+m3+XGPqJX28D7Hq4SOos7vuTQ+Adi7oxRGjf11QDKsFVd nyg3sptQ/xB85VlC1cioKk8lcbUsAG42ddOZ52vIgGiZgq84qh2uXVAMNaOZn3bt7MKi MnDsgIY+kE/bediXvs35xB9ApIq1OaF1DhA1rGWuWMV1vByrM10njZ1G12Wl+oMrSFxu 7FDIMNGk7SijhfShVbHklET9976OcJxgjlekoemLI+ch5rR/Gzta96Bui6S1R5Wpomai 9oH5r99gMABrZOBl41L/AVb12MTtKhj1sj6apB+WaJC3kUyMRXiIkYMscNTkXSesvErh FahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763599100; x=1764203900; 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=KdAuQPMlMqnLA814W2ruOeTYaPbQYBkcVQoSYWqQY/8=; b=GuiKS9TFKoAhdmHO8XYNUECG70xVNnYiMXdMcNYjCkIzK1IUf8A4PeDwDv/hxCOKbV XIbcoutzhUVDLqSxPAyZ38yRWpBUknG8cGb3DDzGpsc7uR7K6BUtlfMFrsP9V81NmBXG ltASCI9MNghkb+lBvnJvY64OGMmbANwDPgARXHPOsy6jdu+l+mgvq7QUaQ5e65Vamu6g H24AZsYsn/TZIwTcliFtdAtX1YzsHCk07yW3bERE4OeFMYQCOzxc3AaTPBLiV6kVvGgN f49dMK+6nJyZmfJ0vx98IdbCPD0scd+H3Ex/j/s2Wog7JLCz55nG8WenNTutf4gdrGBD 5/fw== X-Forwarded-Encrypted: i=1; AJvYcCWE0LgtGqPcctY2eyRiLdoYiI4UIw56hpG65vlBJVZ8/W72svj7e6oe7BwrR3MIsoDtyHU8PS0z95tTKZo=@vger.kernel.org X-Gm-Message-State: AOJu0YyJAyOoVzutaT4fRIzhFWQ3jA3WcVPXWz1LqyJ80MxaFByLXqb0 MTh27rgc1PJ72BmCBuFgzbnVhroNt/eUQ0RCB0pinSqGCfGyQMlivwowTkrm1g== X-Gm-Gg: ASbGncu9ry+GfQOUeEk/xJdS+r+8nB35uiXFplTaD+A5OGqmTq+dsh5IfqE8pnl2tEA YCf3fo6Rp66oymtqNXL/GITxAD/ofOXZ20jd5MHsrvD7RMceiXniXhfAnaWqYOFriQdMyJodkzI w0Fa5el/DRJNjBv0fIq8MhKdTiKgic1fobEi951oewuUE778Eb1PVy3pJTVXdO4/0gur3G4NtvO N65Qm2hAVfpbrdd0I70IKBsLDaq8Db1MvJvlow10WBX+1pq8Sy8vuTdu6MHLG36o41i9gSEnM08 wYQ0iIsR4rs4OQHVzGo6jSicnbClN4+gfmADIsoznW0bt95+7CScnabfpwpSzZ6CasMuyDPkpv5 27Rd4DT+rO3MgyuRN7hO29Ckz9Nhi2rNeJi5tKh7qXqVjVhXMzyByeBG0XpCwIhETD7j0rglJfX VipWGj/yRhb+MvNsx8ESEci4EWxlur+XXzplkSHiInPWOiHaa3CVvs7nc2xt8x00bBRGf6rA== X-Google-Smtp-Source: AGHT+IFAwRjVawIG5s2kzHv/D7vBSiH4VLWTHAmEMoNYwk1EFfoGrLoJLaH9uGe7hX8U9UOUL/mVWg== X-Received: by 2002:a05:6000:18a6:b0:427:8c85:a4ac with SMTP id ffacd0b85a97d-42cb9a647dfmr547948f8f.47.1763599099823; Wed, 19 Nov 2025 16:38:19 -0800 (PST) Received: from f.. (cst-prg-14-82.cust.vodafone.cz. [46.135.14.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7f2e581sm1902407f8f.8.2025.11.19.16.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 16:38:18 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org, viro@zeniv.linux.org.uk Cc: jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 1/2] fs: tidy up step_into() & friends before inlining Date: Thu, 20 Nov 2025 01:38:02 +0100 Message-ID: <20251120003803.2979978-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: 8bit Symlink handling is already marked as unlikely and pushing out some of it into pick_link() reduces register spillage on entry to step_into() with gcc 14.2. The compiler needed additional convincing that handle_mounts() is unlikely to fail. At the same time neither clang nor gcc could be convinced to tail-call into pick_link(). While pick_link() takes an address of stack-based object as an argument (which definitely prevents the optimization), splitting it into separate tuple did not help. The issue persists even when compiled without stack protector. As such nothing was done about this for the time being to not grow the diff. Signed-off-by: Mateusz Guzik --- v2: - split out from the original diff - fixup copy-pasted commentary to tell where the inode in pick_link came from fs/namei.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1d1f864ad6ad..8777637ef939 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1672,13 +1672,15 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, path->dentry = dentry; if (nd->flags & LOOKUP_RCU) { unsigned int seq = nd->next_seq; + if (likely(!d_managed(dentry))) + return 0; if (likely(__follow_mount_rcu(nd, path))) return 0; // *path and nd->next_seq might've been clobbered path->mnt = nd->path.mnt; path->dentry = dentry; nd->next_seq = seq; - if (!try_to_unlazy_next(nd, dentry)) + if (unlikely(!try_to_unlazy_next(nd, dentry))) return -ECHILD; } ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags); @@ -1941,13 +1943,23 @@ static int reserve_stack(struct nameidata *nd, struct path *link) enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4}; -static const char *pick_link(struct nameidata *nd, struct path *link, +static noinline const char *pick_link(struct nameidata *nd, struct path *link, struct inode *inode, int flags) { struct saved *last; const char *res; - int error = reserve_stack(nd, link); + int error; + + if (nd->flags & LOOKUP_RCU) { + /* make sure that d_is_symlink from step_into() matches the inode */ + if (read_seqcount_retry(&link->dentry->d_seq, nd->next_seq)) + return ERR_PTR(-ECHILD); + } else { + if (link->mnt == nd->path.mnt) + mntget(link->mnt); + } + error = reserve_stack(nd, link); if (unlikely(error)) { if (!(nd->flags & LOOKUP_RCU)) path_put(link); @@ -2026,9 +2038,10 @@ static const char *step_into(struct nameidata *nd, int flags, { struct path path; struct inode *inode; - int err = handle_mounts(nd, dentry, &path); + int err; - if (err < 0) + err = handle_mounts(nd, dentry, &path); + if (unlikely(err < 0)) return ERR_PTR(err); inode = path.dentry->d_inode; if (likely(!d_is_symlink(path.dentry)) || @@ -2050,14 +2063,6 @@ static const char *step_into(struct nameidata *nd, int flags, nd->seq = nd->next_seq; return NULL; } - if (nd->flags & LOOKUP_RCU) { - /* make sure that d_is_symlink above matches inode */ - if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) - return ERR_PTR(-ECHILD); - } else { - if (path.mnt == nd->path.mnt) - mntget(path.mnt); - } return pick_link(nd, &path, inode, flags); } -- 2.48.1