From patchwork Wed Nov 16 15:17:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A88C433FE for ; Wed, 16 Nov 2022 15:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233452AbiKPPRe (ORCPT ); Wed, 16 Nov 2022 10:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233424AbiKPPRc (ORCPT ); Wed, 16 Nov 2022 10:17:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4704FF8B; Wed, 16 Nov 2022 07:17:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F2CE261E83; Wed, 16 Nov 2022 15:17:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CA1EC433D7; Wed, 16 Nov 2022 15:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611850; bh=p23e5m8DB+OKwKhVmD1O6yeNHkOhWzyyqsVD65vSeBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0HQqOExoOnjBN1V8PkV04km2Y9lGdedL8CkqrITCb/VFyvbRXCXPbPhoxgJqh/G1 /48k+c/B41BxHsbc4m9N98fSkWBzEu9Eq3LDsmEyZOREfTw1PHLV6VuV2r9YoLQvxH /QHAjsu/I0r/PCrF0Z5WnvjbZtlf5WPathtxXailBPUEOIiOZS1M3ehgVpZr79WoF7 +ZN39A23hWVkcul/OO2mOh6ghaIAniyZ0gwUjj8QsQmyD46cLMsB9C1HhKOIjMWYat biLuw5WRkfVzZBGk3FsVhTUwsAGSKtKCofKdO9VEMRnrteEcSLi5xnsINyUaymcWr3 SiL554x2Bg59A== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de Subject: [PATCH 1/7] filelock: add a new locks_inode_context accessor function Date: Wed, 16 Nov 2022 10:17:20 -0500 Message-Id: <20221116151726.129217-2-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org There are a number of places in the kernel that are accessing the inode->i_flctx field without smp_load_acquire. This is required to ensure that the caller doesn't see a partially-initialized structure. Add a new accessor function for it to make this clear. Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/locks.c | 20 ++++++++++---------- include/linux/fs.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 9ccf89b6c95d..07436328dd0a 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -175,7 +175,7 @@ locks_get_lock_context(struct inode *inode, int type) struct file_lock_context *ctx; /* paired with cmpxchg() below */ - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (likely(ctx) || type == F_UNLCK) goto out; @@ -194,7 +194,7 @@ locks_get_lock_context(struct inode *inode, int type) */ if (cmpxchg(&inode->i_flctx, NULL, ctx)) { kmem_cache_free(flctx_cache, ctx); - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); } out: trace_locks_get_lock_context(inode, type, ctx); @@ -891,7 +891,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) void *owner; void (*func)(void); - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx || list_empty_careful(&ctx->flc_posix)) { fl->fl_type = F_UNLCK; return; @@ -1483,7 +1483,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) new_fl->fl_flags = type; /* typically we will check that ctx is non-NULL before calling */ - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx) { WARN_ON_ONCE(1); goto free_lock; @@ -1588,7 +1588,7 @@ void lease_get_mtime(struct inode *inode, struct timespec64 *time) struct file_lock_context *ctx; struct file_lock *fl; - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (ctx && !list_empty_careful(&ctx->flc_lease)) { spin_lock(&ctx->flc_lock); fl = list_first_entry_or_null(&ctx->flc_lease, @@ -1634,7 +1634,7 @@ int fcntl_getlease(struct file *filp) int type = F_UNLCK; LIST_HEAD(dispose); - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (ctx && !list_empty_careful(&ctx->flc_lease)) { percpu_down_read(&file_rwsem); spin_lock(&ctx->flc_lock); @@ -1823,7 +1823,7 @@ static int generic_delete_lease(struct file *filp, void *owner) struct file_lock_context *ctx; LIST_HEAD(dispose); - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx) { trace_generic_delete_lease(inode, NULL); return error; @@ -2563,7 +2563,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) * posix_lock_file(). Another process could be setting a lock on this * file at the same time, but we wouldn't remove that lock anyway. */ - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx || list_empty(&ctx->flc_posix)) return; @@ -2684,7 +2684,7 @@ bool vfs_inode_has_locks(struct inode *inode) struct file_lock_context *ctx; bool ret; - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx) return false; @@ -2865,7 +2865,7 @@ void show_fd_locks(struct seq_file *f, struct file_lock_context *ctx; int id = 0; - ctx = smp_load_acquire(&inode->i_flctx); + ctx = locks_inode_context(inode); if (!ctx) return; diff --git a/include/linux/fs.h b/include/linux/fs.h index d6cb42b7e91c..092673178e13 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1187,6 +1187,13 @@ extern void show_fd_locks(struct seq_file *f, struct file *filp, struct files_struct *files); extern bool locks_owner_has_blockers(struct file_lock_context *flctx, fl_owner_t owner); + +static inline struct file_lock_context * +locks_inode_context(const struct inode *inode) +{ + return smp_load_acquire(&inode->i_flctx); +} + #else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk(struct file *file, unsigned int cmd, struct flock __user *user) @@ -1327,6 +1334,13 @@ static inline bool locks_owner_has_blockers(struct file_lock_context *flctx, { return false; } + +static inline struct file_lock_context * +locks_inode_context(const struct inode *inode) +{ + return NULL; +} + #endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode(const struct file *f) From patchwork Wed Nov 16 15:17:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB1DBC433FE for ; Wed, 16 Nov 2022 15:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233627AbiKPPRg (ORCPT ); Wed, 16 Nov 2022 10:17:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233540AbiKPPRd (ORCPT ); Wed, 16 Nov 2022 10:17:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72B184FF99; Wed, 16 Nov 2022 07:17:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0A22E61E89; Wed, 16 Nov 2022 15:17:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A7DEC433D6; Wed, 16 Nov 2022 15:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611851; bh=TUD2k8y3eCAtEWkgfeRtEJwkTlc0W2hsoZ3J6u4H/dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MnG3wSQSHPK5lq2pp3IPQJJSnvGfebGD8gee0jYnKZ016PUOhWPdlh8qobWv5/444 iZkTjL1eQVaOyCrTXNMNS5RMekMnEY1fEBnVmOys+SJUREB/TPv7rBLoUz4TrkvwYZ 5XggxGH9DStlz6i6dZHUXPOUjVaFjw8NYlNTnUAMypw+gRq65M3eYv8z+vWRp0GRL8 QfmvC6WClOaagAbkIz9J5mR4wyU0LP8uQ8M1ljq64oVxrFVKRVKchO3k3jNNa2RmlR 4IKmnkrmVTDpUn6UWSZ5kONUiVjkA3cqXBZnO4OPAkYAHVowgCk6mimheYuGy1JjX2 eaWQK4zpn11Bg== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de, Xiubo Li Subject: [PATCH 2/7] ceph: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:21 -0500 Message-Id: <20221116151726.129217-3-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org ceph currently doesn't access i_flctx safely. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Xiubo Li Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig Reviewed-by: Xiubo Li --- 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 = locks_inode_context(inode); 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 = locks_inode_context(inode); int err = 0; int seen_fcntl = 0; int seen_flock = 0; From patchwork Wed Nov 16 15:17:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62A6CC43219 for ; Wed, 16 Nov 2022 15:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbiKPPRi (ORCPT ); Wed, 16 Nov 2022 10:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233340AbiKPPRe (ORCPT ); Wed, 16 Nov 2022 10:17:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D86A2B625; Wed, 16 Nov 2022 07:17:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2863B61E83; Wed, 16 Nov 2022 15:17:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE7B9C433C1; Wed, 16 Nov 2022 15:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611852; bh=yV8M/3emkfa0v+JOTDZ4rZGKsnEb+eyCdX2b35M2HGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GFSJEruBqD3UjsUIscezAfqvMdcvsa4Sl5KLDACMuWA/jiXclACdRl7MAwGXNgfCX ZRZ3RXGnFqrqcsUWVXmTwi8+XiN3bEZA/bs64yZMZNY3WQ/h9M9CMe8wo6RbhaCFRJ D5SxE48RrgWvuHOJjKziqn/gyrMvHtM6hWzKxCxHByE/IfL+UhHfgtbqp510ks4yRN be/726mUIC3CgM0V0qVa1TxdCFXaDVm/PrazWp6q2Bhy2S079bngjE8w5TWKL5FlhI BxVj0krDMw8KFxT4xtaDEdV5fTVfaMIf3KT/eFx33rCi/AtT6jZGMGDHsnd4d9ziZZ VclL82dby9UUA== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de, Steve French Subject: [PATCH 3/7] cifs: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:22 -0500 Message-Id: <20221116151726.129217-4-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org cifs currently doesn't access i_flctx safely. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Steve French Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/cifs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index cd9698209930..6c1431979495 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1413,7 +1413,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) struct inode *inode = d_inode(cfile->dentry); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct file_lock *flock; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); unsigned int count = 0, i; int rc = 0, xid, type; struct list_head locks_to_send, *el; From patchwork Wed Nov 16 15:17:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45883C43217 for ; Wed, 16 Nov 2022 15:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233725AbiKPPRi (ORCPT ); Wed, 16 Nov 2022 10:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233587AbiKPPRf (ORCPT ); Wed, 16 Nov 2022 10:17:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B312C4D5FD; Wed, 16 Nov 2022 07:17:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4E49661E83; Wed, 16 Nov 2022 15:17:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C25FCC433D6; Wed, 16 Nov 2022 15:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611853; bh=8KrKIuKkrzJCTsiPbPUqyZLF65iFtFpKOQstJ9arhYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCEhv/8Y/mWsgPSYs53gpC08w3XrYZJ20nGZe8Hp79eCkD5X80wAgzEnC3NfA8qr7 lYtnAqzD6AX+UK6QrRATqQPUzI2ROz0hFYo6Pom+R9EzErazlOQ4BcWe7r/dZ8U62/ iI57ksOVfMduWNBIdjzbPomvjEJgtrcQGhXA/DKUvWhGCqI9jk+dM+yJ7O+UoIyRwp NZO1uuvJaQigBjkaSMfwwoYTajtn4PtowBGK8QS1kZu/me3D5MsIStVKGcxjtE66Bk ncTlJ+HAt2gRNlqmkjWW+DimxA+11t24ePQ5KuulGPpi+6C9w4zPCS0rIzHXHcXzsy qMwhVsEvHm0wQ== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de, Namjae Jeon , Steve French Subject: [PATCH 4/7] ksmbd: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:23 -0500 Message-Id: <20221116151726.129217-5-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org ksmbd currently doesn't access i_flctx safely. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Namjae Jeon Cc: Steve French Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig Acked-by: Namjae Jeon --- fs/ksmbd/vfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ksmbd/vfs.c b/fs/ksmbd/vfs.c index 8de970d6146f..f9e85d6a160e 100644 --- a/fs/ksmbd/vfs.c +++ b/fs/ksmbd/vfs.c @@ -321,7 +321,7 @@ static int check_lock_range(struct file *filp, loff_t start, loff_t end, unsigned char type) { struct file_lock *flock; - struct file_lock_context *ctx = file_inode(filp)->i_flctx; + struct file_lock_context *ctx = locks_inode_context(file_inode(filp)); int error = 0; if (!ctx || list_empty_careful(&ctx->flc_posix)) From patchwork Wed Nov 16 15:17:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12D83C43217 for ; Wed, 16 Nov 2022 15:17:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233877AbiKPPRl (ORCPT ); Wed, 16 Nov 2022 10:17:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233697AbiKPPRi (ORCPT ); Wed, 16 Nov 2022 10:17:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 801D24FF82; Wed, 16 Nov 2022 07:17:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3C8B5B81DC0; Wed, 16 Nov 2022 15:17:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00854C43470; Wed, 16 Nov 2022 15:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611854; bh=PD+6nv8c5dN3Wkd3cLoPzM9DTqnWGjUkaCEfb0sQeK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fYfcY5d4XycDOkE9YDEPcHL4XBS6Ap8sR2ZzFJCTsummRJIZ0VwKrUh8eFbVl87qh 2li0TrJDQzcT+loUKhy4s2X8d22RLz91mNAM74RyY2Kb2dXNqhtIgz1qgxeBJ/96Cr vgpy5dhy/6GCDoRNBTZ5b2vj14wt9VfO1nV+cH7AOHSkWoC+F3R9l9keDQJACmdu5n X64sh7AVDJLaFPxbQGv41HlApD+jcgdNNQ8tovL/65iK4cqkPnGjEDqdFFkLDguLcf rg0x3xWoHqI14NweRpnljW80akrlW6OtvRt95ptLjY08S0memHVrfEEyXvh/h/zJe3 5ANR0oE7ybCBQ== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de, Trond Myklebust , Anna Schumaker Subject: [PATCH 5/7] lockd: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:24 -0500 Message-Id: <20221116151726.129217-6-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org lockd currently doesn't access i_flctx safely. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Trond Myklebust Cc: Anna Schumaker Cc: Chuck Lever Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/lockd/svcsubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index e1c4617de771..720684345817 100644 --- a/fs/lockd/svcsubs.c +++ b/fs/lockd/svcsubs.c @@ -207,7 +207,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, { struct inode *inode = nlmsvc_file_inode(file); struct file_lock *fl; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); struct nlm_host *lockhost; if (!flctx || list_empty_careful(&flctx->flc_posix)) @@ -262,7 +262,7 @@ nlm_file_inuse(struct nlm_file *file) { struct inode *inode = nlmsvc_file_inode(file); struct file_lock *fl; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares) return 1; From patchwork Wed Nov 16 15:17:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 546D8C4332F for ; Wed, 16 Nov 2022 15:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234339AbiKPPRw (ORCPT ); Wed, 16 Nov 2022 10:17:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233835AbiKPPRk (ORCPT ); Wed, 16 Nov 2022 10:17:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D1A4E422; Wed, 16 Nov 2022 07:17:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5C2E5B81DC3; Wed, 16 Nov 2022 15:17:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AA57C4347C; Wed, 16 Nov 2022 15:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611856; bh=ZcWVwR1/kYODme5i6GoYMexE29jNpM2YaaFPdn+Cywc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ3Vuq+Ctl+m/ZJRd5aS7hKmoK7xQqGGtY14xMamxm3SPj3RtNDQdHKxGvy56Nll6 G14gzQbWkIcTKEkicikhWg8W6Kxx0SQnF0UbPUqjcfSRA4tmCm2X2muDOpn45IJUcN CJGrXfa/U/MrTx1VfgLC7b9GqAniav3inXSFQci+lU8gCF2T/UZ1aMivL+tZrFSCbw AMGuPeNFmIPmaa2LrynUxImhJEVpzN654HSZN38tohHF+Fydbj9q/KY4+ey/iw+V/3 P7sVGmdNDk5yBRVr/pimN4NIZ+X+cno3C4ckSRsXuT+aEx6gHov252016Ue18fpLys +frDQJsXlgK/w== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de, Trond Myklebust , Anna Schumaker Subject: [PATCH 6/7] nfs: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:25 -0500 Message-Id: <20221116151726.129217-7-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org nfs currently doesn't access i_flctx safely. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Trond Myklebust Cc: Anna Schumaker Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/nfs/delegation.c | 2 +- fs/nfs/nfs4state.c | 2 +- fs/nfs/pagelist.c | 2 +- fs/nfs/write.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index ead8a0e06abf..cf7365581031 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -146,7 +146,7 @@ static int nfs_delegation_claim_locks(struct nfs4_state *state, const nfs4_state { struct inode *inode = state->inode; struct file_lock *fl; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); struct list_head *list; int status = 0; diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index a2d2d5d1b088..dd18344648f3 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1501,7 +1501,7 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_ struct file_lock *fl; struct nfs4_lock_state *lsp; int status = 0; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); struct list_head *list; if (flctx == NULL) diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 317cedfa52bf..16be6dae524f 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -1055,7 +1055,7 @@ static unsigned int nfs_coalesce_size(struct nfs_page *prev, if (prev) { if (!nfs_match_open_context(nfs_req_openctx(req), nfs_req_openctx(prev))) return 0; - flctx = d_inode(nfs_req_openctx(req)->dentry)->i_flctx; + flctx = locks_inode_context(d_inode(nfs_req_openctx(req)->dentry)); if (flctx != NULL && !(list_empty_careful(&flctx->flc_posix) && list_empty_careful(&flctx->flc_flock)) && diff --git a/fs/nfs/write.c b/fs/nfs/write.c index f41d24b54fd1..80c240e50952 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1185,7 +1185,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page) { struct nfs_open_context *ctx = nfs_file_open_context(file); struct nfs_lock_context *l_ctx; - struct file_lock_context *flctx = file_inode(file)->i_flctx; + struct file_lock_context *flctx = locks_inode_context(file_inode(file)); struct nfs_page *req; int do_flush, status; /* @@ -1321,7 +1321,7 @@ static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode, unsigned int pagelen) { int ret; - struct file_lock_context *flctx = inode->i_flctx; + struct file_lock_context *flctx = locks_inode_context(inode); struct file_lock *fl; if (file->f_flags & O_DSYNC) From patchwork Wed Nov 16 15:17:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13045381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF9AC4321E for ; Wed, 16 Nov 2022 15:17:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234428AbiKPPRx (ORCPT ); Wed, 16 Nov 2022 10:17:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233836AbiKPPRk (ORCPT ); Wed, 16 Nov 2022 10:17:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B81EF51C03; Wed, 16 Nov 2022 07:17:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 66532B81DC7; Wed, 16 Nov 2022 15:17:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53EA6C433C1; Wed, 16 Nov 2022 15:17:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668611857; bh=IWBPFyJfGw10+bVeE4FZLU5ReB6gH3wpytKDa6wKi9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qp2IB2VerS3UiYrnZbhW0RTGCbAxqV4oGtE77lfA2SwEE3xzClX1PiAhYQEm6lmnk 0HPhsu1tpuVFcuYFlzkvUlnuXgT/a2RNV6vmEWbwUr2ujamMpSawjKmcnxAzr5A140 Yq8/lvQl5X1OOn0CQqgrBUL00v+mvXQKZPjobW/fCSyGSD5+baxlIMTMlZIVG6BfLc teErOgyVerjMWyx8dORZR7VCsyKFs7w7WfdSxOaGiuNCkZSsqWxlroBoqw3xv3qR9X TgzVSxlFhJcB2b3plRS0qGHnotckm1wKvPTWPIDLL13HO5LTSj4CMfqA4vmmCuRfCt dL++2egxxDhsw== From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, chuck.lever@oracle.com, viro@zeniv.linux.org.uk, hch@lst.de Subject: [PATCH 7/7] nfsd: use locks_inode_context helper Date: Wed, 16 Nov 2022 10:17:26 -0500 Message-Id: <20221116151726.129217-8-jlayton@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116151726.129217-1-jlayton@kernel.org> References: <20221116151726.129217-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org nfsd currently doesn't access i_flctx safely everywhere. This requires a smp_load_acquire, as the pointer is set via cmpxchg (a release operation). Cc: Chuck Lever Signed-off-by: Jeff Layton Acked-by: Chuck Lever Reviewed-by: Christoph Hellwig --- fs/nfsd/nfs4state.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 836bd825ca4a..da8d0ea66229 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4758,7 +4758,7 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type) static bool nfsd4_deleg_present(const struct inode *inode) { - struct file_lock_context *ctx = smp_load_acquire(&inode->i_flctx); + struct file_lock_context *ctx = locks_inode_context(inode); return ctx && !list_empty_careful(&ctx->flc_lease); } @@ -5897,7 +5897,7 @@ nfs4_lockowner_has_blockers(struct nfs4_lockowner *lo) list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { nf = stp->st_stid.sc_file; - ctx = nf->fi_inode->i_flctx; + ctx = locks_inode_context(nf->fi_inode); if (!ctx) continue; if (locks_owner_has_blockers(ctx, lo)) @@ -7713,7 +7713,7 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner) } inode = locks_inode(nf->nf_file); - flctx = inode->i_flctx; + flctx = locks_inode_context(inode); if (flctx && !list_empty_careful(&flctx->flc_posix)) { spin_lock(&flctx->flc_lock);