Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4650448yba; Tue, 30 Apr 2019 01:58:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQiy7Y5hsyD1u69hvcFLIjJXfRv+7E5CL2Yyn97eESOjhblmgnaIX6SnqtFmrk2PjCl0sD X-Received: by 2002:a62:ed16:: with SMTP id u22mr68006076pfh.47.1556614701338; Tue, 30 Apr 2019 01:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556614701; cv=none; d=google.com; s=arc-20160816; b=MvLeKPuQMy9I3P+oNj1bsUvA4cbfOUbgIYJg4FRqmsvL51fXn70gCajYinpY+aCFsx Em97rnwaZXaIJCyMwwQmWaKmj3Z+qSl5bHdCq0JRlw514olwXCAJPGbV/zQ608kCqwwF Hwa4ZO0xQfdDpqXymHf4kj4CFPcmyZBx+m0kRB50YRAh+kuS5Laf07fgkmhUieFfG9Cb c0MKOLHw+Z/Qix1gG+FFUGhldr0sM8efF5aKNEK6unVNtnN9H7/eeJ92u3ciJXd5LKK3 Hwh1QDdLJ6eH1Umkold8FH0tYzhggSdO54ukGa6+Y8rstofvoKd/nCswJ2JGBHaIxPUM jR6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=LukcHgUQaGJXh28ZEJOz1zFynhdWtgCfC8B+x85eEdo=; b=URGUOtnGggVagsbIiWaqcZXE7i9KJtXS6XQIhccL3h+lNJxQ9uI4BfuQ6ySl5yanCZ aXSBIFCH7XCKtKyD8DLq4+6R1CXpE+WU33JpzANU9rjBeurtV0pA5LeWtnAlARvhVDw3 7SAxEp4CwIBENHZ9tloQSQqvWnlxlL9ZKRC19lA/W3ifT0ZDyKZozP+80YW0rNfE9MZx PO9ejHMMvC0MjWeDHXJtG5U1T+XNKg3Tg8i2vFv3Tx2rO4S37tCaf7Z2KdDhV5t0O0ar UpAurIBX5rk/Q/N86Xo38jH4b47PTF3FT+LYRar8yJSz40/tGmHnZYn0edbBUA2XejVM 2V9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cj4si12620840plb.66.2019.04.30.01.58.06; Tue, 30 Apr 2019 01:58:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbfD3I4C (ORCPT + 99 others); Tue, 30 Apr 2019 04:56:02 -0400 Received: from relay.sw.ru ([185.231.240.75]:38312 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbfD3I4B (ORCPT ); Tue, 30 Apr 2019 04:56:01 -0400 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hLOYF-0007NC-34; Tue, 30 Apr 2019 11:55:47 +0300 Subject: Re: [PATCH 3/3] prctl_set_mm: downgrade mmap_sem to read lock To: =?UTF-8?Q?Michal_Koutn=c3=bd?= , gorcunov@gmail.com Cc: akpm@linux-foundation.org, arunks@codeaurora.org, brgl@bgdev.pl, geert+renesas@glider.be, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mguzik@redhat.com, mhocko@kernel.org, rppt@linux.ibm.com, vbabka@suse.cz References: <20190418182321.GJ3040@uranus.lan> <20190430081844.22597-1-mkoutny@suse.com> <20190430081844.22597-4-mkoutny@suse.com> From: Kirill Tkhai Message-ID: Date: Tue, 30 Apr 2019 11:55:45 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190430081844.22597-4-mkoutny@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30.04.2019 11:18, Michal Koutný wrote: > Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect > arg_start|end and env_start|end in mm_struct") we use arg_lock for > boundaries modifications. Synchronize prctl_set_mm with this lock and > keep mmap_sem for reading only (analogous to what we already do in > prctl_set_mm_map). > > v2: call find_vma without arg_lock held > > CC: Cyrill Gorcunov > CC: Laurent Dufour > Signed-off-by: Michal Koutný > --- > kernel/sys.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/kernel/sys.c b/kernel/sys.c > index e1acb444d7b0..641fda756575 100644 > --- a/kernel/sys.c > +++ b/kernel/sys.c > @@ -2123,9 +2123,14 @@ static int prctl_set_mm(int opt, unsigned long addr, > > error = -EINVAL; > > - down_write(&mm->mmap_sem); > + /* > + * arg_lock protects concurent updates of arg boundaries, we need mmap_sem for > + * a) concurrent sys_brk, b) finding VMA for addr validation. > + */ > + down_read(&mm->mmap_sem); > vma = find_vma(mm, addr); > > + spin_lock(&mm->arg_lock); > prctl_map.start_code = mm->start_code; > prctl_map.end_code = mm->end_code; > prctl_map.start_data = mm->start_data; > @@ -2213,7 +2218,8 @@ static int prctl_set_mm(int opt, unsigned long addr, > > error = 0; > out: > - up_write(&mm->mmap_sem); > + spin_unlock(&mm->arg_lock); > + up_read(&mm->mmap_sem); > return error; Hm, shouldn't spin_lock()/spin_unlock() pair go as a fixup to existing code in a separate patch? Without them, the existing code has a problem at least in get_mm_cmdline().