]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: use debug-only asserts around fd allocation and install
authorMateusz Guzik <mjguzik@gmail.com>
Wed, 12 Mar 2025 16:19:41 +0000 (17:19 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 13 Mar 2025 08:54:15 +0000 (09:54 +0100)
This also restores the check which got removed in 52732bb9abc9ee5b
("fs/file.c: remove sanity_check and add likely/unlikely in alloc_fd()")
for performance reasons -- they no longer apply with a debug-only
variant.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://lore.kernel.org/r/20250312161941.1261615-1-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/file.c

index 44efdc8c1e27b6e49b49967501b6bef5cb695c53..c8214975e24835c17fc7e7678387ec4c9124157e 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -577,6 +577,7 @@ repeat:
 
        __set_open_fd(fd, fdt, flags & O_CLOEXEC);
        error = fd;
+       VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
 
 out:
        spin_unlock(&files->file_lock);
@@ -642,7 +643,7 @@ void fd_install(unsigned int fd, struct file *file)
                rcu_read_unlock_sched();
                spin_lock(&files->file_lock);
                fdt = files_fdtable(files);
-               WARN_ON(fdt->fd[fd] != NULL);
+               VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
                rcu_assign_pointer(fdt->fd[fd], file);
                spin_unlock(&files->file_lock);
                return;
@@ -650,7 +651,7 @@ void fd_install(unsigned int fd, struct file *file)
        /* coupled with smp_wmb() in expand_fdtable() */
        smp_rmb();
        fdt = rcu_dereference_sched(files->fdt);
-       BUG_ON(fdt->fd[fd] != NULL);
+       VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
        rcu_assign_pointer(fdt->fd[fd], file);
        rcu_read_unlock_sched();
 }