From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965299AbbI2TNO (ORCPT ); Tue, 29 Sep 2015 15:13:14 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:36480 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964956AbbI2TNI (ORCPT ); Tue, 29 Sep 2015 15:13:08 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Oleg Nesterov Cc: Konstantin Khlebnikov , linux-api@vger.kernel.org, containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Roman Gushchin , Serge Hallyn , Chen Fan , Andrew Morton , Linus Torvalds , =?utf-8?Q?St=C3=A9phane?= Graber References: <20150925135246.27620.97496.stgit@buzz> <20150925175654.GA12504@redhat.com> <871tdi8pqj.fsf@x220.int.ebiederm.org> <20150929164315.GA16734@redhat.com> <874mid16bk.fsf@x220.int.ebiederm.org> <20150929183833.GA21875@redhat.com> Date: Tue, 29 Sep 2015 14:05:42 -0500 In-Reply-To: <20150929183833.GA21875@redhat.com> (Oleg Nesterov's message of "Tue, 29 Sep 2015 20:38:33 +0200") Message-ID: <87si5xxczd.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-AID: U2FsdGVkX1/k8HJZJJbXyraaMT3YS1TUI9jjdCuFcn4= X-SA-Exim-Connect-IP: 67.3.201.231 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.5 XMGappySubj_01 Very gappy subject * 1.0 XMGappySubj_02 Gappier still * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4953] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 281 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 4.1 (1.5%), b_tie_ro: 2.9 (1.0%), parse: 1.40 (0.5%), extract_message_metadata: 4.8 (1.7%), get_uri_detail_list: 2.2 (0.8%), tests_pri_-1000: 4.3 (1.5%), tests_pri_-950: 1.43 (0.5%), tests_pri_-900: 1.19 (0.4%), tests_pri_-400: 22 (7.9%), check_bayes: 21 (7.5%), b_tokenize: 6 (2.2%), b_tok_get_all: 7 (2.6%), b_comp_prob: 2.2 (0.8%), b_tok_touch_all: 2.7 (1.0%), b_finish: 0.75 (0.3%), tests_pri_0: 226 (80.2%), tests_pri_500: 4.2 (1.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 0/1] ns: introduce proc_get_ns_by_fd() X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oleg Nesterov writes: > On 09/29, Eric W. Biederman wrote: >> >> Oleg Nesterov writes: >> >> > OK, I won't insist, this too looks better to me than proc_ns_fdget(&fd_ref). >> > >> > And in any case fcheck_files() makes more sense than fdget(), somehow I did >> > not think about this when I sent 1/1. >> > >> > Hmm. and after the quick look at cleanup_net() I can't understand whether >> > get_net_ns_by_fd() can use ns_by_fd_rcu() + maybe_get_net(to_net_ns()) or >> > not... Can it? >> >> Some of those places need a reference that allows them to sleep, and the >> code is shared with the legacy pid case so with an addition of get_net >> we can use ns_by_fd_rcu(). There are cases like setns that could >> use ns_by_fd_rcu() with code reording. >> >> We can implement get_net_ns_by_fd as: >> struct net *get_net_ns_by_fd(int fd) >> { >> struct net *net; >> >> rcu_read_lock(); >> net = net_ns_by_fd_rcu(fd); >> if (!IS_ERR(net)) >> get_net(net); >> rcu_read_unlock(); >> >> return net; >> } >> >> Which means we can achieve code sharing with the pure rcu version >> as a base. > > Yes, this is what I meant... but don't we need maybe_get_net() ? Let me see. The call chain is a little interesting so let's trace it. thread1 thread2 net = net_ns_by_fd_rcu(fd); fput(file) get_net(net); ____fput __fput dput dentry_kill __dentry_kill dentry_iput iput iput_final evict ->evict_inode (nsfs_evict) netns_put put_net __put_net queue_work(net_cleanup_work) ... cleanup_net synchronize_rcu. Given that someone in another thread can put the file descriptor and I don't see anything explicitly waiting until after the rcu critical section ends to put the network namespace I guess we do need maybe_get_net. In practice I think the delay logic in fput will act as an rcu barrier, but that is not guaranteed so we had better not count on it. Sigh. Anyway this is a long ways from a syscall to translate pids. Eric