From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754129AbbCXSMY (ORCPT ); Tue, 24 Mar 2015 14:12:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39134 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752228AbbCXSMW (ORCPT ); Tue, 24 Mar 2015 14:12:22 -0400 Date: Tue, 24 Mar 2015 19:10:16 +0100 From: Oleg Nesterov To: Konstantin Khlebnikov Cc: Davidlohr Bueso , linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: fix lockdep build in rcu-protected get_mm_exe_file() Message-ID: <20150324181016.GA9678@redhat.com> References: <20150320144715.24899.24547.stgit@buzz> <1427134273.2412.12.camel@stgolabs.net> <20150323191055.GA10212@redhat.com> <55119B3B.5020403@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55119B3B.5020403@yandex-team.ru> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/24, Konstantin Khlebnikov wrote: > > On 23.03.2015 22:10, Oleg Nesterov wrote: >> On 03/23, Davidlohr Bueso wrote: >>> >>> void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) >>> { >>> struct file *old_exe_file = rcu_dereference_protected(mm->exe_file, >>> - !atomic_read(&mm->mm_users) || current->in_execve || >>> - lock_is_held(&mm->mmap_sem)); >>> + !atomic_read(&mm->mm_users) || current->in_execve); >> >> Thanks, looks correct at first glance... >> >> But can't we remove the ->in_execve check above? and check >> >> atomic_read(&mm->mm_users) <= 1 >> >> instead. OK, this is subjective, I won't insist. Just current->in_execve >> looks a bit confusing, it means "I swear, the caller is flush_old_exec() >> and this mm is actualy bprm->mm". >> >> "atomic_read(&mm->mm_users) <= 1" looks a bit more "safe". But again, >> I won't insist. > > Not so safe: this will race with get_task_mm(). How? If set_mm_exe_file() can race with get_task_mm() then we have a bug. And it will be reported ;) > A lot of proc files grab temporary reference to task mm. > But this just a debug -- we can place here "true". Yeees, probably rcu_dereference_raw() would be even better. set_mm_exe_file() must be called only if nobody but us can access this mm. Oleg.