Blob Blame History Raw
From: Jeff Layton <jlayton@kernel.org>
Date: Wed, 16 Nov 2022 08:44:25 -0500
Subject: ceph: use locks_inode_context helper
Git-commit: d4e78663f6bc83db44041f224e58e0940662a912
Patch-mainline: v6.2-rc1
References: jsc#SES-1880

ceph currently doesn't access i_flctx safely. This requires a
smp_load_acquire, as the pointer is set via cmpxchg (a release
operation).

Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
[since we don't have 401a8b8fd5ac ("filelock: add a new locks_inode_context
accessor function"), use smp_load_acquire() instead of locks_inode_context()]
Acked-by: Luis Henriques <lhenriques@suse.de>
---
 fs/ceph/locks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 3e2843e86e27..f3b461c708a8 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -364,7 +364,7 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
 	*fcntl_count = 0;
 	*flock_count = 0;
 
-	ctx = inode->i_flctx;
+	ctx = smp_load_acquire(&inode->i_flctx);
 	if (ctx) {
 		spin_lock(&ctx->flc_lock);
 		list_for_each_entry(lock, &ctx->flc_posix, fl_list)
@@ -418,7 +418,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
 				int num_fcntl_locks, int num_flock_locks)
 {
 	struct file_lock *lock;
-	struct file_lock_context *ctx = inode->i_flctx;
+	struct file_lock_context *ctx = smp_load_acquire(&inode->i_flctx);
 	int err = 0;
 	int seen_fcntl = 0;
 	int seen_flock = 0;