lkml.org 
[lkml]   [2023]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5] mm/gup: disallow GUP writing to file-backed mappings by default
On Sat 29-04-23 02:43:32, Kirill A . Shutemov wrote:
> I think I found relevant snippet of code that solves similar issue.
> get_futex_key() uses RCU to stabilize page->mapping after GUP_fast:
>
>
> /*
> * The associated futex object in this case is the inode and
> * the page->mapping must be traversed. Ordinarily this should
> * be stabilised under page lock but it's not strictly
> * necessary in this case as we just want to pin the inode, not
> * update the radix tree or anything like that.
> *
> * The RCU read lock is taken as the inode is finally freed
> * under RCU. If the mapping still matches expectations then the
> * mapping->host can be safely accessed as being a valid inode.
> */
> rcu_read_lock();
>
> if (READ_ONCE(page->mapping) != mapping) {
> rcu_read_unlock();
> put_page(page);
>
> goto again;
> }
>
> inode = READ_ONCE(mapping->host);
> if (!inode) {
> rcu_read_unlock();
> put_page(page);
>
> goto again;
> }
>
> I think something similar can be used inside GUP_fast too.

Yeah, inodes (and thus struct address_space) is RCU protected these days so
grabbing RCU lock in gup_fast() will get you enough protection for checking
aops if you are careful (like the futex code is).

Honza

--
Jan Kara <jack@suse.com>
SUSE Labs, CR

\
 
 \ /
  Last update: 2023-05-02 10:01    [W:0.126 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site