netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: mleitner@redhat.com, netdev@vger.kernel.org,
	linux-sctp@vger.kernel.org,
	Daniel Borkmann <daniel@iogearbox.net>,
	Vlad Yasevich <vyasevich@gmail.com>,
	Michio Honda <micchie@sfc.wide.ad.jp>
Subject: Re: [PATCH v3 1/2] sctp: rcu-ify addr_waitq
Date: Mon, 08 Jun 2015 17:37:05 +0200	[thread overview]
Message-ID: <1433777825.13489.16.camel@stressinduktion.org> (raw)
In-Reply-To: <20150608151955.GE7616@hmsreliant.think-freely.org>

On Mo, 2015-06-08 at 11:19 -0400, Neil Horman wrote:
> On Mon, Jun 08, 2015 at 04:59:18PM +0200, Hannes Frederic Sowa wrote:
> > On Mon, Jun 8, 2015, at 16:46, Hannes Frederic Sowa wrote:
> > > Hi Marcelo,
> > > 
> > > a few hints on rcuification, sorry I reviewed the code so late:
> > > 
> > > On Fri, Jun 5, 2015, at 19:08, mleitner@redhat.com wrote:
> > > > From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > > > 
> > > > That's needed for the next patch, so we break the lock 
> > > > inversion between
> > > > netns_sctp->addr_wq_lock and socket lock on
> > > > sctp_addr_wq_timeout_handler(). With this, we can traverse 
> > > > addr_waitq
> > > > without taking addr_wq_lock, taking it just for the write 
> > > > operations.
> > > > 
> > > > Signed-off-by: Marcelo Ricardo Leitner <
> > > > marcelo.leitner@gmail.com>
> > > > ---
> > > > 
> > > > Notes:
> > > >     v2->v3:
> > > >       placed break statement on sctp_free_addr_wq_entry()
> > > >       removed unnecessary spin_lock noticed by Neil
> > > > 
> > > >  include/net/netns/sctp.h |  2 +-
> > > >  net/sctp/protocol.c      | 80
> > > >  +++++++++++++++++++++++++++++-------------------
> > > >  2 files changed, 49 insertions(+), 33 deletions(-)
> > > > 
> > > > diff --git a/include/net/netns/sctp.h 
> > > > b/include/net/netns/sctp.h
> > > > index
> > > > 3573a81815ad9e0efb6ceb721eb066d3726419f0..9e53412c4ed829e8e4577
> > > > 7a6d95406d490dbaa75
> > > > 100644
> > > > --- a/include/net/netns/sctp.h
> > > > +++ b/include/net/netns/sctp.h
> > > > @@ -28,7 +28,7 @@ struct netns_sctp {
> > > >          * It is a list of sctp_sockaddr_entry.
> > > >          */
> > > >         struct list_head local_addr_list;
> > > > -       struct list_head addr_waitq;
> > > > +       struct list_head __rcu addr_waitq;
> > > >         struct timer_list addr_wq_timer;
> > > >         struct list_head auto_asconf_splist;
> > > >         spinlock_t addr_wq_lock;
> > > > diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
> > > > index
> > > > 53b7acde9aa37bf3d4029c459421564d5270f4c0..9954fb8c9a9455d5ad7a6
> > > > 27e2d7f9a1fef861fc2
> > > > 100644
> > > > --- a/net/sctp/protocol.c
> > > > +++ b/net/sctp/protocol.c
> > > > @@ -593,15 +593,47 @@ static void sctp_v4_ecn_capable(struct 
> > > > sock *sk)
> > > >         INET_ECN_xmit(sk);
> > > >  }
> > > >  
> > > > +static void sctp_free_addr_wq(struct net *net)
> > > > +{
> > > > +       struct sctp_sockaddr_entry *addrw;
> > > > +
> > > > +       spin_lock_bh(&net->sctp.addr_wq_lock);
> > > 
> > > Instead of holding spin_lock_bh you need to hold 
> > > rcu_read_lock_bh, so
> > > kfree_rcu does not call free function at once (in theory ;) ).
> > > 
> > > > +       del_timer(&net->sctp.addr_wq_timer);
> > > > +       list_for_each_entry_rcu(addrw, &net->sctp.addr_waitq, 
> > > > list) {
> > > > +               list_del_rcu(&addrw->list);
> > > > +               kfree_rcu(addrw, rcu);
> > > > +       }
> > > > +       spin_unlock_bh(&net->sctp.addr_wq_lock);
> > > > +}
> > > > +
> > > > +/* As there is no refcnt on sctp_sockaddr_entry, we must check 
> > > > inside
> > > > + * the lock if it wasn't removed from addr_waitq already, 
> > > > otherwise we
> > > > + * could double-free it.
> > > > + */
> > > > +static void sctp_free_addr_wq_entry(struct net *net,
> > > > +                                   struct sctp_sockaddr_entry 
> > > > *addrw)
> > > > +{
> > > > +       struct sctp_sockaddr_entry *temp;
> > > > +
> > > > +       spin_lock_bh(&net->sctp.addr_wq_lock);
> > > 
> > > I don't think this spin_lock operation is needed. The del_timer
> > > functions do synchronize themselves.
> > > 
> > 
> > Sorry, those above two locks are needed, they are not implied by 
> > other
> > locks.
> > 
> What makes you say that? Multiple contexts can issue mod_timer calls 
> on the
> same timer safely no, because of the internal locking?

That's true for timer handling but not to protect net->sctp.addr_waitq
list (Marcelo just explained it to me off-list). Looking at the patch
only in patchworks lost quite a lot of context you were already
discussing. ;)

We are currently checking if the double iteration can be avoided by
splicing addr_waitq on the local stack while holding the spin_lock and
later on notifying the sockets.

Bye,
Hannes

  reply	other threads:[~2015-06-08 15:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28  0:52 [PATCH] sctp: fix ASCONF list handling mleitner
2015-05-28 10:15 ` Neil Horman
2015-05-28 11:17   ` Marcelo Ricardo Leitner
2015-05-28 13:27     ` Marcelo Ricardo Leitner
2015-05-28 14:31       ` Neil Horman
2015-05-28 14:46       ` Marcelo Ricardo Leitner
2015-05-29 13:17         ` Neil Horman
2015-05-29 16:50           ` Marcelo Ricardo Leitner
2015-06-01 14:00             ` Neil Horman
2015-06-01 22:28               ` Marcelo Ricardo Leitner
2015-06-02 13:48                 ` Neil Horman
2015-06-03 16:54                   ` [PATCH v2 1/2] sctp: rcu-ify addr_waitq mleitner
2015-06-03 17:19                     ` Marcelo Ricardo Leitner
2015-06-04 14:27                     ` Neil Horman
2015-06-05 14:18                       ` Marcelo Ricardo Leitner
2015-06-05 17:08                       ` [PATCH v3 " mleitner
2015-06-08 13:58                         ` Neil Horman
2015-06-08 14:46                         ` Hannes Frederic Sowa
2015-06-08 14:59                           ` Hannes Frederic Sowa
2015-06-08 15:19                             ` Neil Horman
2015-06-08 15:37                               ` Hannes Frederic Sowa [this message]
2015-06-09 11:36                                 ` Neil Horman
2015-06-09 19:32                                   ` Marcelo Ricardo Leitner
2015-06-10 13:31                                     ` Marcelo Ricardo Leitner
2015-06-10 19:14                                       ` Neil Horman
2015-06-11 14:30                                         ` [PATCH v4] sctp: fix ASCONF list handling mleitner
2015-06-11 23:31                                           ` David Miller
2015-06-12 13:16                                             ` [PATCH v5] " marcelo.leitner
2015-06-14 19:56                                               ` David Miller
2015-06-05 17:08                       ` [PATCH v3 2/2] " mleitner
2015-06-08 20:09                         ` Hannes Frederic Sowa
2015-06-09 15:37                           ` Marcelo Ricardo Leitner
2015-06-09 17:04                             ` Neil Horman
2015-06-03 16:54                   ` [PATCH v2 " mleitner

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=1433777825.13489.16.camel@stressinduktion.org \
    --to=hannes@stressinduktion.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=micchie@sfc.wide.ad.jp \
    --cc=mleitner@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=vyasevich@gmail.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;
as well as URLs for NNTP newsgroup(s).