pipe: use file_update_time() when hold i_mutex
PATCH 1/1 pipe: use file_update_time() when hold i_mutex
file_update_time() should be called with i_mutex held, move it before mutex_unlock().
---
fs/pipe.c +3 -2
@@ -602,13 +602,14 @@ redo2: pipe->waiting_writers--; } out: +if (ret >0 ) +file_update_time (filp); +mutex_unlock (&inode->i_mutex);if (do_wakeup) {wake_up_interruptible_sync (&pipe->wait);kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); } -if (ret >0 ) -file_update_time (filp);return ret; }
Quoted 4 lines · On Mon, 6 Jul 2009 01:35:30 -0400 Amerigo Wang <[email protected]> wrote:
file_update_time()should be called withi_mutexheld, move it beforemutex_unlock().
Why do you believe that file_update_time() needs i_mutex?
Quoted 11 lines · Andrew Morton
Quoted 4 lines · On Mon, 6 Jul 2009 01:35:30 -0400 Amerigo Wang <[email protected]> wrote:
file_update_time()should be called withi_mutexheld, move it beforemutex_unlock().Why do you believe that
file_update_time()needsi_mutex?
file_update_time() modifies inode, no? :)
Quoted 5 lines · Amerigo Wang
Quoted 4 lines · Andrew Morton
On Mon, 6 Jul 2009 01:35:30 -0400
Amerigo Wang <[email protected]> wrote:
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
file_update_time()should be called withi_mutexheld, move it beforemutex_unlock().Why do you believe that
file_update_time()needsi_mutex?
file_update_time()modifies inode, no? :)
So does touch_atime(), yet neither needs i_mutex.
But calling file_update_time() within the locked region in pipe_write() might make sense regardless: that way a task waiting for data would be guaranteed to see the time change after receiving a POLLIN event for example.
Thanks,
Miklos
Quoted 14 lines · Miklos Szeredi
Quoted 12 lines · Amerigo Wang
Quoted 10 lines · Andrew Morton
Quoted 5 lines · On Mon, 6 Jul 2009 01:35:30 -0400 Amerigo Wang <[email protected]> wrote:
file_update_time()should be called withi_mutexheld, move it beforemutex_unlock().
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Why do you believe that
file_update_time()needsi_mutex?
file_update_time()modifies inode, no? :)So does
touch_atime(), yet neither needsi_mutex.
Yes?
Then how the inode is protected when file_update_time() modifies it?
Thanks.
Quoted 21 lines · Amerigo Wang
Quoted 20 lines · Miklos Szeredi
Quoted 17 lines · Amerigo Wang
Quoted 5 lines · Andrew Morton
On Mon, 6 Jul 2009 01:35:30 -0400
Amerigo Wang <[email protected]> wrote:Quoted 8 lines
Quoted 5 lines
file_update_time()should be called withi_mutexheld, move it beforemutex_unlock().Why do you believe that
file_update_time()needsi_mutex?
file_update_time()modifies inode, no? :)
Quoted 6 lines
Quoted 2 lines
So does
touch_atime(), yet neither needsi_mutex.Yes?
Then how the inode is protected when
file_update_time()modifies it?
Protected against what?
For example the inode isn't protected against concurrent access by stat(2), since that doesn't take i_mutex.
And indeed it looks like there are races there, since set/get operations are not atomic on the timestamp, so stat could return a garbled value if it races with file_update_time() or touch_atime().
Possibly worth fixing, but I'm not sure how to do that without affecting the scalability of stat and friends and without adding too much complexity.
Thanks,
Miklos