public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Myungho Jung <mhjungk@gmail.com>
To: Ilya Dryomov <idryomov@gmail.com>
Cc: "Yan, Zheng" <zyan@redhat.com>, Sage Weil <sage@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Ceph Development <ceph-devel@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] libceph: protect pending flags in ceph_con_keepalive()
Date: Mon, 14 Jan 2019 22:55:59 -0800	[thread overview]
Message-ID: <20190115065558.GA7165@myunghoj-Precision-5530> (raw)
In-Reply-To: <CAOi1vP-FC+X+DeLMBcefYuSjxzLgAsxQg+RNskaZsUvVbmXuYA@mail.gmail.com>

On Mon, Jan 14, 2019 at 09:37:25PM +0100, Ilya Dryomov wrote:
> On Thu, Jan 3, 2019 at 4:50 AM Myungho Jung <mhjungk@gmail.com> wrote:
> > I reproduced on vm using syzkaller utils and verified the fix by syzbot.
> 
> Hi Myungho,
> 
> I think this might be a better fix:
> 
> diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> index d5718284db57..c5f5313e3537 100644
> --- a/net/ceph/messenger.c
> +++ b/net/ceph/messenger.c
> @@ -3205,10 +3205,11 @@ void ceph_con_keepalive(struct ceph_connection *con)
>  {
>         dout("con_keepalive %p\n", con);
>         mutex_lock(&con->mutex);
> +       con_flag_set(con, CON_FLAG_KEEPALIVE_PENDING);
>         clear_standby(con);
>         mutex_unlock(&con->mutex);
> -       if (con_flag_test_and_set(con, CON_FLAG_KEEPALIVE_PENDING) == 0 &&
> -           con_flag_test_and_set(con, CON_FLAG_WRITE_PENDING) == 0)
> +
> +       if (con_flag_test_and_set(con, CON_FLAG_WRITE_PENDING) == 0)
>                 queue_con(con);
>  }
>  EXPORT_SYMBOL(ceph_con_keepalive);
> 
> WRITE_PENDING can be set without con->mutex held from socket callbacks.
> This is the reason we use atomic bit ops here, so testing WRITE_PENDING
> under the lock didn't make sense to me.
> 
> At the same time, KEEPALIVE_PENDING could have been a non-atomic flag.
> I spent some time trying to make sense of conditioning queue_con() call
> on the previous value of KEEPALIVE_PENDING and couldn't see any, so I'm
> setting it with con_flag_set(), making ceph_con_keepalive() symmetric
> with ceph_con_send().
> 
> Thanks,
> 
>                 Ilya

Hi Ilya,

Yes, it looks clear and makes sense to have an atomic operation in if statement
but it still triggers warning. KEEPALIVE_PENDING should be set after
clear_standby() because con_fault() can be called right before acquiring the
lock here which sets the flag in standby state. I tesed the change with syzbot
and confirmed there was no warning.

Thanks,
Myungho

  parent reply	other threads:[~2019-01-15  6:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27 19:08 [PATCH] libceph: protect pending flags in ceph_con_keepalive() Myungho Jung
2019-01-02 15:42 ` Ilya Dryomov
2019-01-03  3:50   ` Myungho Jung
2019-01-14 20:37     ` Ilya Dryomov
2019-01-14 20:37       ` Ilya Dryomov
2019-01-15  6:55       ` Myungho Jung [this message]
2019-01-15  6:55         ` Myungho Jung
2019-01-15 10:17         ` Ilya Dryomov
2019-01-15 10:17           ` Ilya Dryomov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190115065558.GA7165@myunghoj-Precision-5530 \
    --to=mhjungk@gmail.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sage@redhat.com \
    --cc=zyan@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox