Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Pravin Shelar <pshelar@nicira.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net-next v6 1/8] vxlan: Restructure vxlan socket apis.
Date: Mon, 5 Aug 2013 11:10:21 -0700	[thread overview]
Message-ID: <20130805111021.62430fc5@nehalam.linuxnetplumber.net> (raw)
In-Reply-To: <CALnjE+oZkX6FkVaaJeYz2C9SgY0hcRi6xKjxsSh+5Q=PoH7qFQ@mail.gmail.com>

On Mon, 5 Aug 2013 08:49:36 -0700
Pravin Shelar <pshelar@nicira.com> wrote:

> On Sun, Aug 4, 2013 at 2:42 PM, Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> > On Thu,  1 Aug 2013 11:44:40 -0700
> > Pravin B Shelar <pshelar@nicira.com> wrote:
> >
> >> @@ -1642,59 +1651,56 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port)
> >>                        &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc);
> >>               sk_release_kernel(sk);
> >>               kfree(vs);
> >> -             return ERR_PTR(rc);
> >> +             return;
> >>       }
> >> +     atomic_set(&vs->refcnt, 0);
> >>
> >>       /* Disable multicast loopback */
> >>       inet_sk(sk)->mc_loop = 0;
> >> +     spin_lock(&vn->sock_lock);
> >> +     hlist_add_head_rcu(&vs->hlist, vs_head(net, port));
> >> +     spin_unlock(&vn->sock_lock);
> >
> > Overall I am fine with this set, except for this.
> > The change causes a socket to be put into the hash list with a ref count
> > of 0 and then you increment the ref count. If some other thread
> > finds the socket and then decrements the ref count, it would go
> > below zero and might leak, crash or delete it prematurely.
> >
> > This concerns me.
> 
> There is no code path which decrements ref-cnt after lookup. Therefore
> above case is not possible.
> But I agree this does not look good, so I will change it so not to
> have refcnt zero vs on hash-table.

I was concerned about:

CPU 0:
   vxlan_socket_create
     Make a vs structure with refcnt == 0
     Add it to hlist

     <preempt or other long IRQ>
                                         CPU 1: Another vxlan being setup (batch script?)
                                                vxlan_init
                                                     vxlan_find_port finds that vs
                                                     atomic_inc(refcnt) now 1
                                          <close or error>
                                                vxlan_uninit
                                                  vxlan_sock_release
                                                     atomic_dec_and_test (now 0)
                                                       delete from hlist
                                                       queue work for deletion

     now decides to continue with vs
     Either vs is already freed, or it exists
     in limbo

                                                       

  reply	other threads:[~2013-08-05 18:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01 18:44 [PATCH net-next v6 1/8] vxlan: Restructure vxlan socket apis Pravin B Shelar
2013-08-04 21:42 ` Stephen Hemminger
2013-08-05 15:49   ` Pravin Shelar
2013-08-05 18:10     ` Stephen Hemminger [this message]
2013-08-05 18:24       ` Pravin Shelar

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=20130805111021.62430fc5@nehalam.linuxnetplumber.net \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    --cc=pshelar@nicira.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