diff mbox

ceph: unlock dangling spinlock in try_flush_caps

Message ID 20171019125258.19821-1-jlayton@kernel.org (mailing list archive)
State New, archived
Headers show

Commit Message

Jeff Layton Oct. 19, 2017, 12:52 p.m. UTC
From: Jeff Layton <jlayton@redhat.com>

sparose warns:
    fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit

We need to exit this function with the lock unlocked, but a couple of
cases leave it locked.

Cc: stable@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/ceph/caps.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Yan, Zheng Oct. 19, 2017, 12:58 p.m. UTC | #1
> On 19 Oct 2017, at 20:52, Jeff Layton <jlayton@kernel.org> wrote:
> 
> From: Jeff Layton <jlayton@redhat.com>
> 
> sparose warns:
>    fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit
> 
> We need to exit this function with the lock unlocked, but a couple of
> cases leave it locked.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
> fs/ceph/caps.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 157fe59fbabe..1978a8cb1cb1 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -1991,6 +1991,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
> retry:
> 	spin_lock(&ci->i_ceph_lock);
> 	if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
> +		spin_unlock(&ci->i_ceph_lock);
> 		dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
> 		goto out;
> 	}
> @@ -2008,8 +2009,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
> 			mutex_lock(&session->s_mutex);
> 			goto retry;
> 		}
> -		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
> +		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
> +			spin_unlock(&ci->i_ceph_lock);
> 			goto out;
> +		}
> 
> 		flushing = __mark_caps_flushing(inode, session, true,
> 						&flush_tid, &oldest_flush_tid);
> -- 
> 2.13.6

good catch

Reviewed-by: "Yan, Zheng" <zyan@redhat.com>

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ilya Dryomov Oct. 20, 2017, 9:25 a.m. UTC | #2
On Thu, Oct 19, 2017 at 2:52 PM, Jeff Layton <jlayton@kernel.org> wrote:
> From: Jeff Layton <jlayton@redhat.com>
>
> sparose warns:
>     fs/ceph/caps.c:2042:9: warning: context imbalance in 'try_flush_caps' - wrong count at exit
>
> We need to exit this function with the lock unlocked, but a couple of
> cases leave it locked.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
>  fs/ceph/caps.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 157fe59fbabe..1978a8cb1cb1 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -1991,6 +1991,7 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
>  retry:
>         spin_lock(&ci->i_ceph_lock);
>         if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
> +               spin_unlock(&ci->i_ceph_lock);
>                 dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
>                 goto out;
>         }
> @@ -2008,8 +2009,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
>                         mutex_lock(&session->s_mutex);
>                         goto retry;
>                 }
> -               if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
> +               if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
> +                       spin_unlock(&ci->i_ceph_lock);
>                         goto out;
> +               }
>
>                 flushing = __mark_caps_flushing(inode, session, true,
>                                                 &flush_tid, &oldest_flush_tid);

Applied.

Thanks,

                Ilya
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 157fe59fbabe..1978a8cb1cb1 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1991,6 +1991,7 @@  static int try_flush_caps(struct inode *inode, u64 *ptid)
 retry:
 	spin_lock(&ci->i_ceph_lock);
 	if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
+		spin_unlock(&ci->i_ceph_lock);
 		dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
 		goto out;
 	}
@@ -2008,8 +2009,10 @@  static int try_flush_caps(struct inode *inode, u64 *ptid)
 			mutex_lock(&session->s_mutex);
 			goto retry;
 		}
-		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
+		if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) {
+			spin_unlock(&ci->i_ceph_lock);
 			goto out;
+		}
 
 		flushing = __mark_caps_flushing(inode, session, true,
 						&flush_tid, &oldest_flush_tid);