public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: VFS locking: f_pos thread-safe ?
@ 2004-02-06  9:09 Matt
  2004-02-06  9:16 ` Andrew Morton
  0 siblings, 1 reply; 24+ messages in thread
From: Matt @ 2004-02-06  9:09 UTC (permalink / raw)
  To: Andrew Morton, Linux Kernel Mailing List

> Werner Almesberger <wa@almesberger.net> wrote:
>>
>> "[...] read( ) [...] shall be atomic with respect to each other
>>   in the effects specified in IEEE Std. 1003.1-200x when they
>>   operate on regular files. If two threads each call one of these
>>   functions, each call shall either see all of the specified
>>   effects of the other call, or none of them."

> Whichever thread finishes its read last gets to update f_pos.

> I'm struggling a bit to understand what they're calling for there.  If
> thread A enters a read and then shortly afterwards thread B enters the
> read, does thread B see an f_pos which starts out at the beginning of A's
> read, or the end of it?

> Similar questions apply as the threads exit their read()s.

> Either way, there's no way in which we should serialise concurrent readers.
> That would really suck for sensible apps which are using pread64().

Surely, we can just serialise read() (and related) calls that modify f_pos?
Since pread() doesn't modify f_pos we shouldn't need to serialise those calls
no? Also doesn't spec make the same claims about other calls that modify
f_pos such as write()?

	Matt






^ permalink raw reply	[flat|nested] 24+ messages in thread
* VFS locking: f_pos thread-safe ?
@ 2004-02-06  7:12 Werner Almesberger
  2004-02-06  7:55 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Werner Almesberger @ 2004-02-06  7:12 UTC (permalink / raw)
  To: linux-kernel

I'm trying to figure out how all the locking in VFS and friends
works, and I can't quite explain to myself how f_pos is kept
consistent with concurrent readers.

In fact, there might be a violation of atomicity requirements:
e.g. if we take the route sys_read -> vfs_read ->
generic_file_read -> __generic_file_aio_read ->
do_generic_file_read -> do_generic_mapping_read, we don't seem
to be holding any locks. So if I have two threads that start
reading the same fd at the same time, they could retrieve the
same data.

Section 2.9.7 of the "Austin" draft of IEEE Std. 1003.1-200x,
28-JUL-2000, says:

"[...] read( ) [...] shall be atomic with respect to each other
 in the effects specified in IEEE Std. 1003.1-200x when they
 operate on regular files. If two threads each call one of these
 functions, each call shall either see all of the specified
 effects of the other call, or none of them."

I've written a little test program with concurrent readers that
seems to support this observation, i.e. given the following
pseudo-code:

static void *reader(...)
{
    while (read(0,buffer,PAGE_SIZE));
    ...
}

...
    for (...)
	pthread_create(...,reader...);
...

More than one reader may obtain a given page.
The full test program is at
http://www.almesberger.net/misc/tt.tar.gz

Is this a real bug or am I just confused ?

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2004-02-23 13:23 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-06  9:09 VFS locking: f_pos thread-safe ? Matt
2004-02-06  9:16 ` Andrew Morton
2004-02-06  9:26   ` Matt
2004-02-06  9:35     ` Andrew Morton
2004-02-06 10:19       ` Matthias Urlichs
2004-02-06 11:18         ` viro
2004-02-06 18:59           ` Matthias Urlichs
2004-02-06 19:54             ` Werner Almesberger
2004-02-08 15:58             ` Kai Henningsen
2004-02-19 15:14               ` Pavel Machek
     [not found]         ` <20040206101941.4cd9c882.shemminger@osdl.org>
2004-02-06 18:47           ` Matthias Urlichs
2004-02-06 13:50       ` Werner Almesberger
2004-02-06 13:56         ` viro
2004-02-06 14:24           ` Werner Almesberger
  -- strict thread matches above, loose matches on Subject: below --
2004-02-06  7:12 Werner Almesberger
2004-02-06  7:55 ` Andrew Morton
2004-02-06 18:37 ` Joel Becker
2004-02-06 19:05   ` Matthias Urlichs
2004-02-07  1:35     ` Joel Becker
2004-02-06 20:09   ` Werner Almesberger
2004-02-06 20:56     ` Valdis.Kletnieks
2004-02-07  0:55       ` Werner Almesberger
2004-02-06 20:54 ` Andries Brouwer
2004-02-07 23:45   ` Werner Almesberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox