From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
To: "Denis V. Lunev" <den-3ImXcnM4P+0@public.gmane.org>
Cc: Linux Containers
<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
"Eric W. Biederman"
<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Subject: Re: [patch 3/3][NETNS45][V2] remove timewait sockets at cleanup
Date: Thu, 27 Sep 2007 16:38:16 +0200 [thread overview]
Message-ID: <46FBC058.8020003@fr.ibm.com> (raw)
In-Reply-To: <46FBAE9B.7030707-3ImXcnM4P+0@public.gmane.org>
Denis V. Lunev wrote:
> Daniel Lezcano wrote:
>> From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
>>
>> Denis Lunev spotted that if we take a reference to the network namespace
>> with the timewait sockets, we will need to wait for their expiration to
>> have the network namespace freed. This is a waste of time, the timewait
>> sockets are for avoiding to receive a duplicate packet from the network,
>> if the network namespace is freed, the network stack is removed, so no
>> chance to receive any packets from the outside world.
>>
>> This patchset remove/destroy the timewait sockets when the
>> network namespace is freed.
>>
>> Signed-off-by: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
>> ---
>> net/ipv4/tcp.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 53 insertions(+)
>>
>
> [...]
> This place seems non-trival and broken for me :( May be I am wrong.
>> + write_lock_bh(&head->lock);
>> +
>> + sk_for_each_safe(sk, node, tmp, &head->twchain) {
>> +
>> + tw = inet_twsk(sk);
>> + if (tw->tw_net != net)
>> + continue;
>> +
>> + /* deschedule the timewait socket */
>> + spin_lock(&tcp_death_row.death_lock);
>> + if (inet_twsk_del_dead_node(tw)) {
>> + inet_twsk_put(tw);
>> + if (--tcp_death_row.tw_count == 0)
>> + del_timer(&tcp_death_row.tw_timer);
> There is a call inet_twsk_deschedule which do exactly what we need to
>
> void inet_twsk_deschedule(struct inet_timewait_sock *tw,
> struct inet_timewait_death_row *twdr)
> {
> spin_lock(&twdr->death_lock);
> if (inet_twsk_del_dead_node(tw)) {
> inet_twsk_put(tw);
> if (--twdr->tw_count == 0)
> del_timer(&twdr->tw_timer);
> }
> spin_unlock(&twdr->death_lock);
> __inet_twsk_kill(tw, twdr->hashinfo);
> }
>
> and, from my point of view, your patch [2] is even not needed. We should do
>
> restart:
> write_lock_bh(&head->lock);
> sk_for_each_safe(sk, node, tmp, &head->twchain) {
> tw = inet_twsk(sk);
> if (tw->tw_net != net)
> continue;
> sock_hold(sk);
> write_unlock_bh(&head->lock);
> inet_twsk_deschedule(tw, &tcp_death_row);
> inet_twsk_put(tw);
> goto restart;
> }
>
> This removes serious locking issue. You have introduced dependency
> between write_lock_bh(&head->lock); and
> spin_lock(&tcp_death_row.death_lock);
> This should be at least checked and documented in the headers. I am not
> sure that this is correct.
> If my approach is correct, your second patch is not needed.
>
> It will also worth to local_bh_enable() at the very beginning and remove
> _bh from write_lock.
local_bh_disable / local_bh_enable at the very beginning ?
like that ?
-------------
local_bh_disable();
/* Browse the the established hash table */
for (h = 0; h < (tcp_hashinfo.ehash_size); h++) {
struct inet_ehash_bucket *head =
inet_ehash_bucket(&tcp_hashinfo, h);
restart:
write_lock(&head->lock);
sk_for_each_safe(sk, node, tmp, &head->twchain) {
tw = inet_twsk(sk);
if (tw->tw_net != net)
continue;
sock_hold(sk);
write_unlock(&head->lock);
inet_twsk_deschedule(tw, &tcp_death_row);
inet_twsk_put(tw);
goto restart;
}
}
local_bh_enable();
-------------
next prev parent reply other threads:[~2007-09-27 14:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-27 11:04 [patch 0/3][NETNS45][V2] remove timewait sockets at namespace exit Daniel Lezcano
2007-09-27 11:04 ` [patch 1/3][NETNS45][V2] add a reference to the netns for timewait Daniel Lezcano
[not found] ` <20070927111208.092780734-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 12:34 ` Denis V. Lunev
2007-09-27 11:04 ` [patch 2/3][NETNS45][V2] make timewait unhash lock free Daniel Lezcano
[not found] ` <20070927111212.651097600-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 12:46 ` Denis V. Lunev
[not found] ` <46FBA624.2070203-3ImXcnM4P+0@public.gmane.org>
2007-09-27 13:09 ` Daniel Lezcano
[not found] ` <46FBAB6C.6010908-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-09-27 13:18 ` Denis V. Lunev
2007-09-27 11:04 ` [patch 3/3][NETNS45][V2] remove timewait sockets at cleanup Daniel Lezcano
[not found] ` <20070927111219.179053451-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 13:22 ` Denis V. Lunev
[not found] ` <46FBAE9B.7030707-3ImXcnM4P+0@public.gmane.org>
2007-09-27 14:38 ` Daniel Lezcano [this message]
[not found] ` <46FBC058.8020003-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-09-28 6:47 ` Denis V. Lunev
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=46FBC058.8020003@fr.ibm.com \
--to=dlezcano-nmtc/0zbporqt0dzr+alfa@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=den-3ImXcnM4P+0@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.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