From nobody Thu Apr 16 12:24:54 2026 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (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 A9A5C47A0A6 for ; Fri, 27 Feb 2026 21:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772226913; cv=none; b=SldhHrHcDzKsulKiZfFvPC/ZnLc3/0C0gACkH2+2unGKi+sI5a1WWdUehiNclT8tyrecUMExGhmGskRp++mA8VSrwyz5OJKaCtKccvuheKyhzVzS79MrzKYnKe5ktAzs6yb6RcraXUdNddmxxbiA89B58KyL0XNUNOrnaMSw1MY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772226913; c=relaxed/simple; bh=LnVjx3sJuLTuMbVOtLUm99eribvNM8AdnMRRtkiN6a8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dyACn9Ch+nlbCX52KBGRxiR9uOKKebt7D1Xqde8BuJnOEv+Rsi52/e2TDmZNYjO9rTTQ9+tTUToXlKgYdZ+UcTBLuqjTreKpDzS0J2AX1FqZbNA1VknByxRqXfbvGe5Hr8F69T/tmgxgn9Mj9WWCY3n/F+mB/pWVhxr4Ns66l7E= 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=g+jaBZ/W; arc=none smtp.client-ip=74.125.224.41 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="g+jaBZ/W" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-64c9c8f8783so2758025d50.1 for ; Fri, 27 Feb 2026 13:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772226911; x=1772831711; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ekna4DOdfEq37ibiDykxyhlVIkUX5bjTHdf7smxfKqI=; b=g+jaBZ/WM77+88IJT/OU6QuqEb6+1SqEbsVGH9z7ZubMgCQr461rVzrgaz8C3I8Uoh mOXa3NF1G5yvI94JZBDTxGVQ25NFySA48F0c9Tc/vhVQR53Xdxayc3anqagLY+9dgRgT 7IkBBgX236U2P4Bipv4p3D9by4nQqEis6OwhtCTJR1M0PR3RpkXkZTa0QOKjUiyMVwMc Q+d/4y219lNUfGfos3FmK7B9BlKLzZdqB3BRSSNgN6oUpUuV6l/P/ZGcxjCmmdGxRnPk wFmkaGhPeNa1FtwEkyNFhS958mgUjCGOaKou1k5+LfUQoLFLdX/f9L5PClb/hQ0UKNsX 7KGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772226911; x=1772831711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ekna4DOdfEq37ibiDykxyhlVIkUX5bjTHdf7smxfKqI=; b=Di3kVsfgHdagfz4W+XOniaw2leqh6eDe88Rj8d4ZOpmM/2jc+paQZp58DgFtv8a68g i4xrpSyd/6rvpNFX6DhL2Fd5zOcK8GYxuffJEwqPy5eldQdZJ5MjnL0+711spTxn4KBG gptRODlDe4K5BCePVA+BIYVqj/82HpzSGx3vtJ8smI1zhBtOgdvKfUuZ32wNcwSxqkC8 kjA4ijMqw27q/h21PtLx1Pds8IBQc7p84QdNPjxuD8wcjD9yYXF6JYwdIlrLuMfSvZ5l ow/cU/4hEqPgBqBbk9OqmZGdVVPCDXzAxwBzdh8w7G++hEomFsYxENJuekjsrvPurcTo k1zA== X-Forwarded-Encrypted: i=1; AJvYcCVHD8l71CnLVqkOyGXHPrp6zgIfyoqCLF0zRgfk8JF+fwDcq+AspicO29rx3Nztqzc8LMrd6eQz9Io6BeQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yyzsv2HyuTib1mc+zFwEwMMLN+SvlWVYId4rHIKeLrmE8UrWrfJ B8mMnJKS8IDwTKUI+VOXgfObCqOMd8q8MN9wGUt1rVAF31Rv3674uqDx X-Gm-Gg: ATEYQzyIs5er06+ZInskFjrExOuZZDuHtXwJKKP0y0UeATcDemB3oL0znWhAMGo3pRX EqsAd0dKN/JJVSBiEzjpUhcAYrZN0u2ioes/uIAy+FQG/r9Nxf4JDQgL/pe4xtF9pJTi6Ynj1eM F7GgvyRoxEuEvYdQvH2FfDipIP1BM1mKZDJ+FMiEcltkKYWp66+LtP/r8vgZ2/crUyU1hIbPd1p e665Rd2A92Ki8j5p3iZAXUBtRXoeM+yh8QuJjRX0GzfzybmUt1oviwonwMobUjojoPbMoRL6DFD RAPTXQhk7HaELviZrbIKw2M0seZ/0hYft2KOGKQSAi1L3QvqHQQ8xa+jDTuURwrszEaFNdNRhBE g56HYfol1pyFFj9QGUqtS+dQ0nz0K80vggV63MUX/uBvpcBGqgSu6YvIh4O9SFuM/rQNxCmSrXQ KrAYQ2XRHTxZ3zXfnJVMu4SmC+kRfPhinooK4= X-Received: by 2002:a05:690e:44a5:b0:649:cff9:de4 with SMTP id 956f58d0204a3-64cc3050faamr2315443d50.41.1772226910602; Fri, 27 Feb 2026 13:15:10 -0800 (PST) Received: from ubuntu ([76.38.17.53]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64cb7627432sm2763297d50.12.2026.02.27.13.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 13:15:10 -0800 (PST) From: AnishMulay To: rostedt@goodmis.org, viro@zeniv.linux.org.uk Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, AnishMulay Subject: [PATCH v2] tracefs: Use dentry name snapshots instead of heap allocation Date: Fri, 27 Feb 2026 16:15:05 -0500 Message-ID: <20260227211505.226643-1-anishm7030@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260227154210.5bd19a45@gandalf.local.home> References: <20260227154210.5bd19a45@gandalf.local.home> 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" In fs/tracefs/inode.c, tracefs_syscall_mkdir() and tracefs_syscall_rmdir() previously used a local helper, get_dname(), which allocated a temporary buffer on the heap via kmalloc() to hold the dentry name. This introduced unnecessary overhead, an ENOMEM failure path, and required manual memory cleanup via kfree(). As suggested by Al Viro, replace this heap allocation with the VFS dentry name snapshot API. By stack-allocating a `struct name_snapshot` and using take_dentry_name_snapshot() and release_dentry_name_snapshot(), we safely capture the dentry name locklessly, eliminate the heap allocation entirely, and remove the now-obsolete error handling paths. The get_dname() helper is completely removed. Testing: Booted a custom kernel natively in virtme-ng (ARM64). Triggered tracefs inode and dentry allocation by creating and removing a custom directory under a temporary tracefs mount. Verified that the instance is created successfully and that no memory errors or warnings are emitted in dmesg. Signed-off-by: AnishMulay --- fs/tracefs/inode.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 86ba8dc25aaef..ad322e8f9e2ad 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -94,23 +94,14 @@ static struct tracefs_dir_ops { int (*rmdir)(const char *name); } tracefs_ops __ro_after_init; =20 -static char *get_dname(struct dentry *dentry) -{ - return kmemdup_nul(dentry->d_name.name, dentry->d_name.len, GFP_KERNEL); -} - static struct dentry *tracefs_syscall_mkdir(struct mnt_idmap *idmap, struct inode *inode, struct dentry *dentry, umode_t mode) { struct tracefs_inode *ti; - char *name; + struct name_snapshot name; int ret; =20 - name =3D get_dname(dentry); - if (!name) - return ERR_PTR(-ENOMEM); - /* * This is a new directory that does not take the default of * the rootfs. It becomes the default permissions for all the @@ -125,24 +116,20 @@ static struct dentry *tracefs_syscall_mkdir(struct mn= t_idmap *idmap, * the files within the tracefs system. It is up to the individual * mkdir routine to handle races. */ + take_dentry_name_snapshot(&name, dentry); inode_unlock(inode); - ret =3D tracefs_ops.mkdir(name); + ret =3D tracefs_ops.mkdir(name.name.name); inode_lock(inode); - - kfree(name); + release_dentry_name_snapshot(&name); =20 return ERR_PTR(ret); } =20 static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentr= y) { - char *name; + struct name_snapshot name; int ret; =20 - name =3D get_dname(dentry); - if (!name) - return -ENOMEM; - /* * The rmdir call can call the generic functions that create * the files within the tracefs system. It is up to the individual @@ -150,15 +137,15 @@ static int tracefs_syscall_rmdir(struct inode *inode,= struct dentry *dentry) * This time we need to unlock not only the parent (inode) but * also the directory that is being deleted. */ + take_dentry_name_snapshot(&name, dentry); inode_unlock(inode); inode_unlock(d_inode(dentry)); =20 - ret =3D tracefs_ops.rmdir(name); + ret =3D tracefs_ops.rmdir(name.name.name); =20 inode_lock_nested(inode, I_MUTEX_PARENT); inode_lock(d_inode(dentry)); - - kfree(name); + release_dentry_name_snapshot(&name); =20 return ret; } --=20 2.51.0