From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754222AbdBUTei (ORCPT ); Tue, 21 Feb 2017 14:34:38 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:56785 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753215AbdBUTe1 (ORCPT ); Tue, 21 Feb 2017 14:34:27 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Konstantin Khlebnikov Cc: Al Viro , linux-kernel@vger.kernel.org, Andrew Morton References: <20170209084016.GL13195@ZenIV.linux.org.uk> <148671210259.52694.13774349516906955456.stgit@buzz> <20170219084202.GJ29622@ZenIV.linux.org.uk> <87a89gqq0h.fsf_-_@xmission.com> <9cbf08f9-00eb-c165-fb95-bb1d2d5aa0cd@yandex-team.ru> Date: Wed, 22 Feb 2017 08:29:38 +1300 In-Reply-To: <9cbf08f9-00eb-c165-fb95-bb1d2d5aa0cd@yandex-team.ru> (Konstantin Khlebnikov's message of "Tue, 21 Feb 2017 11:40:15 +0300") Message-ID: <87mvdfnxzx.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1cgGCZ-0008Jq-Cm;;;mid=<87mvdfnxzx.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=101.100.131.232;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18XN5FgZYfl36URpUz4zdD7w5y8Ghmyy8c= X-SA-Exim-Connect-IP: 101.100.131.232 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 1.5 TR_Symld_Words too many words that have symbols inside * 0.7 XMSubLong Long Subject * 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.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.5 XM_Body_Dirty_Words Contains a dirty word * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Konstantin Khlebnikov X-Spam-Relay-Country: X-Spam-Timing: total 5784 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.3 (0.1%), b_tie_ro: 2.3 (0.0%), parse: 1.27 (0.0%), extract_message_metadata: 69 (1.2%), get_uri_detail_list: 4.0 (0.1%), tests_pri_-1000: 17 (0.3%), tests_pri_-950: 2.1 (0.0%), tests_pri_-900: 1.58 (0.0%), tests_pri_-400: 69 (1.2%), check_bayes: 67 (1.2%), b_tokenize: 26 (0.5%), b_tok_get_all: 15 (0.3%), b_comp_prob: 5.0 (0.1%), b_tok_touch_all: 14 (0.2%), b_finish: 0.85 (0.0%), tests_pri_0: 665 (11.5%), check_dkim_signature: 1.53 (0.0%), check_dkim_adsp: 9 (0.2%), tests_pri_500: 4951 (85.6%), poll_dns_idle: 4942 (85.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [REVIEW][PATCH] proc/sysctl: Don't grab i_lock under sysctl_lock. X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -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 Konstantin Khlebnikov writes: > On 21.02.2017 04:41, Eric W. Biederman wrote: >> >> Konstantin Khlebnikov writes: >>> This patch has locking problem. I've got lockdep splat under LTP. >>> >>> [ 6633.115456] ====================================================== >>> [ 6633.115502] [ INFO: possible circular locking dependency detected ] >>> [ 6633.115553] 4.9.10-debug+ #9 Tainted: G L >>> [ 6633.115584] ------------------------------------------------------- >>> [ 6633.115627] ksm02/284980 is trying to acquire lock: >>> [ 6633.115659] (&sb->s_type->i_lock_key#4){+.+...}, at: [] igrab+0x1e/0x80 >>> [ 6633.115834] but task is already holding lock: >>> [ 6633.115882] (sysctl_lock){+.+...}, at: [] unregister_sysctl_table+0x6b/0x110 >>> [ 6633.116026] which lock already depends on the new lock. >>> [ 6633.116026] >>> [ 6633.116080] >>> [ 6633.116080] the existing dependency chain (in reverse order) is: >>> [ 6633.116117] >>> -> #2 (sysctl_lock){+.+...}: >>> -> #1 (&(&dentry->d_lockref.lock)->rlock){+.+...}: >>> -> #0 (&sb->s_type->i_lock_key#4){+.+...}: >>> >>> d_lock nests inside i_lock >>> sysctl_lock nests inside d_lock in d_compare >>> >>> This patch adds i_lock nesting inside sysctl_lock. >> >> Al Viro replied: >>> Once ->unregistering is set, you can drop sysctl_lock just fine. So I'd >>> try something like this - use rcu_read_lock() in proc_sys_prune_dcache(), >>> drop sysctl_lock() before it and regain after. Make sure that no inodes >>> are added to the list ones ->unregistering has been set and use RCU list >>> primitives for modifying the inode list, with sysctl_lock still used to >>> serialize its modifications. >>> >>> Freeing struct inode is RCU-delayed (see proc_destroy_inode()), so doing >>> igrab() is safe there. Since we don't drop inode reference until after we'd >>> passed beyond it in the list, list_for_each_entry_rcu() should be fine. >> >> I agree with Al Viro's analsysis of the situtation. >> >> Fixes: 802e348c6b77 ("proc/sysctl: prune stale dentries during unregistering") >> Reported-by: Konstantin Khlebnikov >> Suggested-by: Al Viro >> Signed-off-by: "Eric W. Biederman" >> --- >> >> This is my cleaned up version of Al Viro's proposed fix. >> I have tested it and the lockdep warnings go away, and >> I have fixed a few trivial to ensure things work as intended. >> >> Unless someone sees a problem I am going to add this fix to my tree and >> then send a pull request to Linus. > > I've tested the same patch and found no problems. > > Except proc_sys_prune_dcache() is no longer called under sysctl_lock > like says comment above it. Thank you. I will add your Tested-by line to the patch. Eric