Skip to content

Commit aab174f

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs update from Al Viro: - big one - consolidation of descriptor-related logics; almost all of that is moved to fs/file.c (BTW, I'm seriously tempted to rename the result to fd.c. As it is, we have a situation when file_table.c is about handling of struct file and file.c is about handling of descriptor tables; the reasons are historical - file_table.c used to be about a static array of struct file we used to have way back). A lot of stray ends got cleaned up and converted to saner primitives, disgusting mess in android/binder.c is still disgusting, but at least doesn't poke so much in descriptor table guts anymore. A bunch of relatively minor races got fixed in process, plus an ext4 struct file leak. - related thing - fget_light() partially unuglified; see fdget() in there (and yes, it generates the code as good as we used to have). - also related - bits of Cyrill's procfs stuff that got entangled into that work; _not_ all of it, just the initial move to fs/proc/fd.c and switch of fdinfo to seq_file. - Alex's fs/coredump.c spiltoff - the same story, had been easier to take that commit than mess with conflicts. The rest is a separate pile, this was just a mechanical code movement. - a few misc patches all over the place. Not all for this cycle, there'll be more (and quite a few currently sit in akpm's tree)." Fix up trivial conflicts in the android binder driver, and some fairly simple conflicts due to two different changes to the sock_alloc_file() interface ("take descriptor handling from sock_alloc_file() to callers" vs "net: Providing protocol type via system.sockprotoname xattr of /proc/PID/fd entries" adding a dentry name to the socket) * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (72 commits) MAX_LFS_FILESIZE should be a loff_t compat: fs: Generic compat_sys_sendfile implementation fs: push rcu_barrier() from deactivate_locked_super() to filesystems btrfs: reada_extent doesn't need kref for refcount coredump: move core dump functionality into its own file coredump: prevent double-free on an error path in core dumper usb/gadget: fix misannotations fcntl: fix misannotations ceph: don't abuse d_delete() on failure exits hypfs: ->d_parent is never NULL or negative vfs: delete surplus inode NULL check switch simple cases of fget_light to fdget new helpers: fdget()/fdput() switch o2hb_region_dev_write() to fget_light() proc_map_files_readdir(): don't bother with grabbing files make get_file() return its argument vhost_set_vring(): turn pollstart/pollstop into bool switch prctl_set_mm_exe_file() to fget_light() switch xfs_find_handle() to fget_light() switch xfs_swapext() to fget_light() ...
2 parents ca41cc9 + 2bd2c19 commit aab174f

142 files changed

Lines changed: 2915 additions & 2877 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,24 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
145145
long __user *, basep)
146146
{
147147
int error;
148-
struct file *file;
148+
struct fd arg = fdget(fd);
149149
struct osf_dirent_callback buf;
150150

151-
error = -EBADF;
152-
file = fget(fd);
153-
if (!file)
154-
goto out;
151+
if (!arg.file)
152+
return -EBADF;
155153

156154
buf.dirent = dirent;
157155
buf.basep = basep;
158156
buf.count = count;
159157
buf.error = 0;
160158

161-
error = vfs_readdir(file, osf_filldir, &buf);
159+
error = vfs_readdir(arg.file, osf_filldir, &buf);
162160
if (error >= 0)
163161
error = buf.error;
164162
if (count != buf.count)
165163
error = count - buf.count;
166164

167-
fput(file);
168-
out:
165+
fdput(arg);
169166
return error;
170167
}
171168

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
23062306
* partially initialize the vma for the sampling buffer
23072307
*/
23082308
vma->vm_mm = mm;
2309-
vma->vm_file = filp;
2309+
vma->vm_file = get_file(filp);
23102310
vma->vm_flags = VM_READ| VM_MAYREAD |VM_RESERVED;
23112311
vma->vm_page_prot = PAGE_READONLY; /* XXX may need to change */
23122312

@@ -2345,8 +2345,6 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
23452345
goto error;
23462346
}
23472347

2348-
get_file(filp);
2349-
23502348
/*
23512349
* now insert the vma in the vm list for the process, must be
23522350
* done with mmap lock held
@@ -4782,7 +4780,7 @@ pfm_check_task_state(pfm_context_t *ctx, int cmd, unsigned long flags)
47824780
asmlinkage long
47834781
sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
47844782
{
4785-
struct file *file = NULL;
4783+
struct fd f = {NULL, 0};
47864784
pfm_context_t *ctx = NULL;
47874785
unsigned long flags = 0UL;
47884786
void *args_k = NULL;
@@ -4879,17 +4877,17 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
48794877

48804878
ret = -EBADF;
48814879

4882-
file = fget(fd);
4883-
if (unlikely(file == NULL)) {
4880+
f = fdget(fd);
4881+
if (unlikely(f.file == NULL)) {
48844882
DPRINT(("invalid fd %d\n", fd));
48854883
goto error_args;
48864884
}
4887-
if (unlikely(PFM_IS_FILE(file) == 0)) {
4885+
if (unlikely(PFM_IS_FILE(f.file) == 0)) {
48884886
DPRINT(("fd %d not related to perfmon\n", fd));
48894887
goto error_args;
48904888
}
48914889

4892-
ctx = file->private_data;
4890+
ctx = f.file->private_data;
48934891
if (unlikely(ctx == NULL)) {
48944892
DPRINT(("no context for fd %d\n", fd));
48954893
goto error_args;
@@ -4919,8 +4917,8 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
49194917
if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT;
49204918

49214919
error_args:
4922-
if (file)
4923-
fput(file);
4920+
if (f.file)
4921+
fdput(f);
49244922

49254923
kfree(args_k);
49264924

‎arch/parisc/hpux/fs.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,32 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
109109

110110
int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned int count)
111111
{
112-
struct file * file;
112+
struct fd arg;
113113
struct hpux_dirent __user * lastdirent;
114114
struct getdents_callback buf;
115-
int error = -EBADF;
115+
int error;
116116

117-
file = fget(fd);
118-
if (!file)
119-
goto out;
117+
arg = fdget(fd);
118+
if (!arg.file)
119+
return -EBADF;
120120

121121
buf.current_dir = dirent;
122122
buf.previous = NULL;
123123
buf.count = count;
124124
buf.error = 0;
125125

126-
error = vfs_readdir(file, filldir, &buf);
126+
error = vfs_readdir(arg.file, filldir, &buf);
127127
if (error >= 0)
128128
error = buf.error;
129129
lastdirent = buf.previous;
130130
if (lastdirent) {
131-
if (put_user(file->f_pos, &lastdirent->d_off))
131+
if (put_user(arg.file->f_pos, &lastdirent->d_off))
132132
error = -EFAULT;
133133
else
134134
error = count - buf.count;
135135
}
136136

137-
fput(file);
138-
out:
137+
fdput(arg);
139138
return error;
140139
}
141140

‎arch/powerpc/include/asm/systbl.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ SYSCALL_SPU(getcwd)
189189
SYSCALL_SPU(capget)
190190
SYSCALL_SPU(capset)
191191
COMPAT_SYS(sigaltstack)
192-
SYSX_SPU(sys_sendfile64,compat_sys_sendfile,sys_sendfile)
192+
SYSX_SPU(sys_sendfile,compat_sys_sendfile_wrapper,sys_sendfile)
193193
SYSCALL(ni_syscall)
194194
SYSCALL(ni_syscall)
195195
PPC_SYS(vfork)
@@ -229,7 +229,7 @@ COMPAT_SYS_SPU(sched_setaffinity)
229229
COMPAT_SYS_SPU(sched_getaffinity)
230230
SYSCALL(ni_syscall)
231231
SYSCALL(ni_syscall)
232-
SYS32ONLY(sendfile64)
232+
SYSX(sys_ni_syscall,compat_sys_sendfile64_wrapper,sys_sendfile64)
233233
COMPAT_SYS_SPU(io_setup)
234234
SYSCALL_SPU(io_destroy)
235235
COMPAT_SYS_SPU(io_getevents)

‎arch/powerpc/include/asm/unistd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@
419419
#define __ARCH_WANT_COMPAT_SYS_TIME
420420
#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
421421
#define __ARCH_WANT_SYS_NEWFSTATAT
422+
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
422423
#endif
423424

424425
/*

‎arch/powerpc/kernel/sys_ppc32.c‎

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,17 @@ long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t pt
143143
* proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
144144
* and the register representation of a signed int (msr in 64-bit mode) is performed.
145145
*/
146-
asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
146+
asmlinkage long compat_sys_sendfile_wrapper(u32 out_fd, u32 in_fd,
147+
compat_off_t __user *offset, u32 count)
147148
{
148-
mm_segment_t old_fs = get_fs();
149-
int ret;
150-
off_t of;
151-
off_t __user *up;
152-
153-
if (offset && get_user(of, offset))
154-
return -EFAULT;
155-
156-
/* The __user pointer cast is valid because of the set_fs() */
157-
set_fs(KERNEL_DS);
158-
up = offset ? (off_t __user *) &of : NULL;
159-
ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
160-
set_fs(old_fs);
161-
162-
if (offset && put_user(of, offset))
163-
return -EFAULT;
164-
165-
return ret;
149+
return compat_sys_sendfile((int)out_fd, (int)in_fd, offset, count);
166150
}
167151

168-
asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
152+
asmlinkage long compat_sys_sendfile64_wrapper(u32 out_fd, u32 in_fd,
153+
compat_loff_t __user *offset, u32 count)
169154
{
170-
mm_segment_t old_fs = get_fs();
171-
int ret;
172-
loff_t lof;
173-
loff_t __user *up;
174-
175-
if (offset && get_user(lof, offset))
176-
return -EFAULT;
177-
178-
/* The __user pointer cast is valid because of the set_fs() */
179-
set_fs(KERNEL_DS);
180-
up = offset ? (loff_t __user *) &lof : NULL;
181-
ret = sys_sendfile64(out_fd, in_fd, up, count);
182-
set_fs(old_fs);
183-
184-
if (offset && put_user(lof, offset))
185-
return -EFAULT;
186-
187-
return ret;
155+
return sys_sendfile((int)out_fd, (int)in_fd,
156+
(off_t __user *)offset, count);
188157
}
189158

190159
long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,

‎arch/powerpc/platforms/cell/spu_syscalls.c‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
6969
umode_t, mode, int, neighbor_fd)
7070
{
7171
long ret;
72-
struct file *neighbor;
73-
int fput_needed;
7472
struct spufs_calls *calls;
7573

7674
calls = spufs_calls_get();
7775
if (!calls)
7876
return -ENOSYS;
7977

8078
if (flags & SPU_CREATE_AFFINITY_SPU) {
79+
struct fd neighbor = fdget(neighbor_fd);
8180
ret = -EBADF;
82-
neighbor = fget_light(neighbor_fd, &fput_needed);
83-
if (neighbor) {
84-
ret = calls->create_thread(name, flags, mode, neighbor);
85-
fput_light(neighbor, fput_needed);
81+
if (neighbor.file) {
82+
ret = calls->create_thread(name, flags, mode, neighbor.file);
83+
fdput(neighbor);
8684
}
8785
} else
8886
ret = calls->create_thread(name, flags, mode, NULL);
@@ -94,19 +92,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
9492
asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
9593
{
9694
long ret;
97-
struct file *filp;
98-
int fput_needed;
95+
struct fd arg;
9996
struct spufs_calls *calls;
10097

10198
calls = spufs_calls_get();
10299
if (!calls)
103100
return -ENOSYS;
104101

105102
ret = -EBADF;
106-
filp = fget_light(fd, &fput_needed);
107-
if (filp) {
108-
ret = calls->spu_run(filp, unpc, ustatus);
109-
fput_light(filp, fput_needed);
103+
arg = fdget(fd);
104+
if (arg.file) {
105+
ret = calls->spu_run(arg.file, unpc, ustatus);
106+
fdput(arg);
110107
}
111108

112109
spufs_calls_put(calls);

‎arch/powerpc/platforms/cell/spufs/coredump.c‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ static int spufs_ctx_note_size(struct spu_context *ctx, int dfd)
106106
return total;
107107
}
108108

109+
static int match_context(const void *v, struct file *file, unsigned fd)
110+
{
111+
struct spu_context *ctx;
112+
if (file->f_op != &spufs_context_fops)
113+
return 0;
114+
ctx = SPUFS_I(file->f_dentry->d_inode)->i_ctx;
115+
if (ctx->flags & SPU_CREATE_NOSCHED)
116+
return 0;
117+
return fd + 1;
118+
}
119+
109120
/*
110121
* The additional architecture-specific notes for Cell are various
111122
* context files in the spu context.
@@ -115,29 +126,18 @@ static int spufs_ctx_note_size(struct spu_context *ctx, int dfd)
115126
* internal functionality to dump them without needing to actually
116127
* open the files.
117128
*/
129+
/*
130+
* descriptor table is not shared, so files can't change or go away.
131+
*/
118132
static struct spu_context *coredump_next_context(int *fd)
119133
{
120-
struct fdtable *fdt = files_fdtable(current->files);
121134
struct file *file;
122-
struct spu_context *ctx = NULL;
123-
124-
for (; *fd < fdt->max_fds; (*fd)++) {
125-
if (!fd_is_open(*fd, fdt))
126-
continue;
127-
128-
file = fcheck(*fd);
129-
130-
if (!file || file->f_op != &spufs_context_fops)
131-
continue;
132-
133-
ctx = SPUFS_I(file->f_dentry->d_inode)->i_ctx;
134-
if (ctx->flags & SPU_CREATE_NOSCHED)
135-
continue;
136-
137-
break;
138-
}
139-
140-
return ctx;
135+
int n = iterate_fd(current->files, *fd, match_context, NULL);
136+
if (!n)
137+
return NULL;
138+
*fd = n - 1;
139+
file = fcheck(*fd);
140+
return SPUFS_I(file->f_dentry->d_inode)->i_ctx;
141141
}
142142

143143
int spufs_coredump_extra_notes_size(void)

‎arch/s390/hypfs/inode.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ static void hypfs_remove(struct dentry *dentry)
7272
struct dentry *parent;
7373

7474
parent = dentry->d_parent;
75-
if (!parent || !parent->d_inode)
76-
return;
7775
mutex_lock(&parent->d_inode->i_mutex);
7876
if (hypfs_positive(dentry)) {
7977
if (S_ISDIR(dentry->d_inode->i_mode))

‎arch/sparc/include/asm/unistd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@
447447
#else
448448
#define __ARCH_WANT_COMPAT_SYS_TIME
449449
#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
450+
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
450451
#endif
451452

452453
/*

0 commit comments

Comments
 (0)