From a73d090612ca0700a9011bacc81b70cf7b47be82 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 10 Apr 2019 13:21:14 -0700 Subject: [PATCH] vfs: use READ_ONCE() to access ->i_link Use 'READ_ONCE(inode->i_link)' to explicitly support filesystems caching the symlink target in ->i_link later if it was unavailable at iget() time, or wasn't easily available. I'll be doing this in fscrypt, to improve the performance of encrypted symlinks on ext4, f2fs, and ubifs. ->i_link will start NULL and may later be set to a non-NULL value by a smp_store_release() or cmpxchg_release(). READ_ONCE() is needed on the read side. smp_load_acquire() is unnecessary because only a data dependency barrier is required. (Thanks to Al for pointing this out.) Acked-by: Al Viro Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o --- fs/namei.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 62a0db6e6725..16535040af11 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1039,7 +1039,7 @@ const char *get_link(struct nameidata *nd) return ERR_PTR(error); nd->last_type = LAST_BIND; - res = inode->i_link; + res = READ_ONCE(inode->i_link); if (!res) { const char * (*get)(struct dentry *, struct inode *, struct delayed_call *); @@ -4674,9 +4674,11 @@ static int generic_readlink(struct dentry *dentry, char __user *buffer, { DEFINE_DELAYED_CALL(done); struct inode *inode = d_inode(dentry); - const char *link = inode->i_link; + const char *link; int res; + link = READ_ONCE(inode->i_link); + if (!link) { link = inode->i_op->get_link(dentry, inode, &done); if (IS_ERR(link))