netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: martin@martingkelly.com
Cc: netdev@vger.kernel.org, paulmck@linux.vnet.ibm.com,
	stephen@networkplumber.org
Subject: Re: Question about synchronize_net() in AF_PACKET close()
Date: Tue, 09 Sep 2014 15:00:00 -0700 (PDT)	[thread overview]
Message-ID: <20140909.150000.1647602729214485795.davem@davemloft.net> (raw)
In-Reply-To: <CAN8CM3zo3bMxZV_UvywCPNjJrMwMA2-+POfY8cR429iodHRc+A@mail.gmail.com>

From: Martin Kelly <martin@martingkelly.com>
Date: Tue, 9 Sep 2014 14:44:56 -0700

> In net/packet/af_packet.c, I noticed the following few lines within
> packet_release:
> 
>          synchronize_net();
>          /*
>           *      Now the socket is dead. No more input will appear.
>           */
>          sock_orphan(sk);
>          sock->sk = NULL;
> 
> From testing and code analysis, I have found that it appears to be safe
> to move sock_orphan and sock->sk = NULL before the synchronize_net()
> call like so:
> 
>          /*
>           *      Now the socket is dead. No more input will appear.
>           */
>          sock_orphan(sk);
>          sock->sk = NULL;
>          synchronize_net();
> 
> Could some RCU and/or networking experts chime in about whether this a
> safe operation? For all I know, there is some deep, fundamental reason
> why those lines are in the order they are. On the other hand, perhaps
> there is not.

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.

You probably want to reference commit:

commit 808f5114a9206fee855117d416440e1071ab375c
Author: stephen hemminger <shemminger@vyatta.com>
Date:   Mon Feb 22 07:57:18 2010 +0000

    packet: convert socket list to RCU (v3)

which put the synchronize_net() there in the first place.

  reply	other threads:[~2014-09-09 22:00 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 [this message]
2014-09-10 13:19   ` Marcelo Ricardo Leitner
2014-09-10 21:39     ` Martin Kelly
2014-09-10 21:37   ` Martin Kelly
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=20140909.150000.1647602729214485795.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=martin@martingkelly.com \
    --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).