|
|
Subscribe / Log in / New account

A virtual filesystem locking surprise

A virtual filesystem locking surprise

Posted Jul 31, 2023 17:10 UTC (Mon) by wsy (subscriber, #121706)
Parent article: A virtual filesystem locking surprise

> if (file_count(file) > 1)
> mutex_lock(&file->f_pos_lock);

What happens if the refrence count changed between the check and the lock?


to post comments

A virtual filesystem locking surprise

Posted Jul 31, 2023 19:03 UTC (Mon) by stevie-oh (subscriber, #130795) [Link]

My understanding is that this is (well, *was*) ostensibly impossible, because the requirement is twofold: there is only one reference to this file descriptor, _and_ the process that has that reference is single-threaded.

The logic goes like this:
1. Only one reference exists to this file descriptor
2. The reference belongs to a process with only one thread
3. Therefore, right now, there is only one thread that can access or manipulate this file descriptor
4. Right now, that thread is busy running executing this function, which means it can't conflict with anything.

The problem, then, is that io_uring and pidfd_getfd violate the validity of the leap from 2->3. pidfd_getfd would do what you mentioned: it allows the reference count to be incremented by a thread from another process. io_uring, on the other hand, seems to do work on threads that don't get "counted" for #2.

A virtual filesystem locking surprise

Posted Jul 31, 2023 21:13 UTC (Mon) by pbonzini (subscriber, #60935) [Link]

Functions such as fdget_pos() return a bunch of flags for later use in fdput() and fdput_pos(). One such flag is FDPUT_POS_UNLOCK, which directs fdput_pos() to release the mutex.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds