* [patch] fs: remove local variable copy of f_pos to enable thread-safe updates
@ 2008-05-02 9:14 Matti Linnanvuori
2008-05-02 9:33 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Matti Linnanvuori @ 2008-05-02 9:14 UTC (permalink / raw)
To: viro, linux-fsdevel; +Cc: linux-kernel
From: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
Remove local variable copy of f_pos to enable thread-safe updates in
implementation functions of system calls read, readv, write and writev.
Signed-off-by: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
---
--- linux-next/fs/fs-read_write.c 2008-05-02 11:54:04.715996700 +0300
+++ linux-2.6/fs/fs-read_write.c 2008-05-02 11:57:17.011641000 +0300
@@ -348,16 +348,6 @@ ssize_t vfs_write(struct file *file, con
EXPORT_SYMBOL(vfs_write);
-static inline loff_t file_pos_read(struct file *file)
-{
- return file->f_pos;
-}
-
-static inline void file_pos_write(struct file *file, loff_t pos)
-{
- file->f_pos = pos;
-}
-
asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
{
struct file *file;
@@ -366,10 +356,8 @@ asmlinkage ssize_t sys_read(unsigned int
file = fget_light(fd, &fput_needed);
if (file) {
- loff_t pos = file_pos_read(file);
trace_mark(fs_read, "fd %u count %zu", fd, count);
- ret = vfs_read(file, buf, count, &pos);
- file_pos_write(file, pos);
+ ret = vfs_read(file, buf, count, &file->f_pos);
fput_light(file, fput_needed);
}
@@ -384,10 +372,8 @@ asmlinkage ssize_t sys_write(unsigned in
file = fget_light(fd, &fput_needed);
if (file) {
- loff_t pos = file_pos_read(file);
trace_mark(fs_write, "fd %u count %zu", fd, count);
- ret = vfs_write(file, buf, count, &pos);
- file_pos_write(file, pos);
+ ret = vfs_write(file, buf, count, &file->f_pos);
fput_light(file, fput_needed);
}
@@ -679,10 +665,8 @@ sys_readv(unsigned long fd, const struct
file = fget_light(fd, &fput_needed);
if (file) {
- loff_t pos = file_pos_read(file);
trace_mark(fs_readv, "fd %lu vlen %lu", fd, vlen);
- ret = vfs_readv(file, vec, vlen, &pos);
- file_pos_write(file, pos);
+ ret = vfs_readv(file, vec, vlen, &file->f_pos);
fput_light(file, fput_needed);
}
@@ -701,10 +685,8 @@ sys_writev(unsigned long fd, const struc
file = fget_light(fd, &fput_needed);
if (file) {
- loff_t pos = file_pos_read(file);
trace_mark(fs_writev, "fd %lu vlen %lu", fd, vlen);
- ret = vfs_writev(file, vec, vlen, &pos);
- file_pos_write(file, pos);
+ ret = vfs_writev(file, vec, vlen, &file->f_pos);
fput_light(file, fput_needed);
}
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] fs: remove local variable copy of f_pos to enable thread-safe updates
2008-05-02 9:14 Matti Linnanvuori
@ 2008-05-02 9:33 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2008-05-02 9:33 UTC (permalink / raw)
To: Matti Linnanvuori; +Cc: linux-fsdevel, linux-kernel
On Fri, May 02, 2008 at 02:14:25AM -0700, Matti Linnanvuori wrote:
> From: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
>
> Remove local variable copy of f_pos to enable thread-safe updates in
> implementation functions of system calls read, readv, write and writev.
... and we are back to square one with racy instances of ->read() that
will use *pos twice, leaving a window for e.g. lseek() to invalidate
e.g. wraparound tests. Not that deciding what to do at the end of
e.g. read() with lseek() happening in the middle would be fun anyway -
esp. since you don't remember the kind of seek it had been.
Go argue that with Linus.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] fs: remove local variable copy of f_pos to enable thread-safe updates
@ 2008-05-02 15:33 Matti Linnanvuori
2008-05-02 15:41 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Matti Linnanvuori @ 2008-05-02 15:33 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, linux-kernel
----- Original Message ----
> From: Al Viro <viro@ZenIV.linux.org.uk>
> To: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
> Cc: linux-fsdevel@vger.kernel.org; linux-kernel@vger.kernel.org
> Sent: Friday, May 2, 2008 12:33:02 PM
> Subject: Re: [patch] fs: remove local variable copy of f_pos to enable thread-safe updates
>
> On Fri, May 02, 2008 at 02:14:25AM -0700, Matti Linnanvuori wrote:
> > From: Matti Linnanvuori
> >
> > Remove local variable copy of f_pos to enable thread-safe updates in
> > implementation functions of system calls read, readv, write and writev.
>
> ... and we are back to square one with racy instances of ->read() that
> will use *pos twice, leaving a window for e.g. lseek() to invalidate
> e.g. wraparound tests. Not that deciding what to do at the end of
> e.g. read() with lseek() happening in the middle would be fun anyway -
> esp. since you don't remember the kind of seek it had been.
File systems can be written so that implementations of read, lseek etc.
acquire a lock before using *pos, which precludes races. That was the
idea behind my patch. So, my patch does not necessarily cause races.
read instances can be racy in Linux now because there is no lock to
serialize read etc. system calls.
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] fs: remove local variable copy of f_pos to enable thread-safe updates
2008-05-02 15:33 [patch] fs: remove local variable copy of f_pos to enable thread-safe updates Matti Linnanvuori
@ 2008-05-02 15:41 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2008-05-02 15:41 UTC (permalink / raw)
To: Matti Linnanvuori; +Cc: linux-fsdevel, linux-kernel
On Fri, May 02, 2008 at 08:33:50AM -0700, Matti Linnanvuori wrote:
> File systems can be written so that implementations of read, lseek etc.
> acquire a lock before using *pos, which precludes races. That was the
> idea behind my patch. So, my patch does not necessarily cause races.
> read instances can be racy in Linux now because there is no lock to
> serialize read etc. system calls.
Oh, yes it does - current tree guarantees that variable passed to ->read()
will not change under it, so any code that relied on that got broken.
And no, modifying every driver's ->read() is not going to be fun - it's
not just filesystems.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-02 15:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-02 15:33 [patch] fs: remove local variable copy of f_pos to enable thread-safe updates Matti Linnanvuori
2008-05-02 15:41 ` Al Viro
-- strict thread matches above, loose matches on Subject: below --
2008-05-02 9:14 Matti Linnanvuori
2008-05-02 9:33 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).