netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Kelly <martin@martingkelly.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: Question about synchronize_net() in AF_PACKET close()
Date: Wed, 10 Sep 2014 14:37:41 -0700	[thread overview]
Message-ID: <CAN8CM3xEnQXVgrLpV0rfAJoZ75v6Xv64pAGJ-9SAPACAT8WJ_w@mail.gmail.com> (raw)
In-Reply-To: <20140909.150000.1647602729214485795.davem@davemloft.net>

> The synchronize_net() is also there to protect against the prot hook
> which can run asynchronously from the core packet input path on any
> cpu.
>

Yes, understood. What I'm not clear about is whether it is safe to do
the following:

unregister_prot_hook(sk, false);
sock_orphan(sk);
sock->sk = NULL;
call_rcu(...);
close socket, return to userspace

instead of

unregister_prot_hook(sk, false);
synchronize_net();
sock_orphan(sk);
sock->sk = NULL;
close socket, return to userspace

If you don't call synchronize_net() immediately, then other readers
could see the protocol hook in the protocol list and try to use it.
They could call into prot_hook.func. However, it appears that  such
functions ( e.g. packet_rcv() ) touch the socket buffer but not the
socket itself, so orphaning the socket before all RCUs have been
processed is safe. In addition, no new packets will come in after
packet_release() and touch the socket because the socket fd will be
removed from the process fd list.

>From my testing, I'm not seeing any obvious issues, but I could be
missing something. Is orphaning the socket before all RCUs have
finished unsafe?

  parent reply	other threads:[~2014-09-10 21:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09 21:44 Question about synchronize_net() in AF_PACKET close() Martin Kelly
2014-09-09 22:00 ` David Miller
2014-09-10 13:19   ` Marcelo Ricardo Leitner
2014-09-10 21:39     ` Martin Kelly
2014-09-10 21:37   ` Martin Kelly [this message]
2014-09-17 14:29     ` Martin Kelly
2014-09-17 14:54       ` Eric Dumazet
2014-09-17 17:04         ` Martin Kelly
2014-09-17 17:52           ` Eric Dumazet
2014-09-17 18:58             ` Martin Kelly

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=CAN8CM3xEnQXVgrLpV0rfAJoZ75v6Xv64pAGJ-9SAPACAT8WJ_w@mail.gmail.com \
    --to=martin@martingkelly.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=stephen@networkplumber.org \
    /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).