Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp655338yba; Thu, 18 Apr 2019 07:29:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTeeBpjJUsn5X1TLr8+NPnpC7vvDRcMDuPoy2+/QBVmO5RS1EvTo8Nsw7ouQgaFw4h+bhW X-Received: by 2002:a62:304:: with SMTP id 4mr94723986pfd.99.1555597785990; Thu, 18 Apr 2019 07:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555597785; cv=none; d=google.com; s=arc-20160816; b=iH0Xq0TylCc86DS7/kaJE2DlKmQ4MMcvj1RL6sqUmxSVTZlXdjDLzRLegE/QG4B27h kJjmmHsg+7sr5OgbsT2iLZi4duB8qPZAJMNWweNr8b+uU6uYFbIes1S77lOlPfmh95MG kB9aiUnsEBsOg5oTpytelBzkrgFyblu/0cQEYQoAlhh6l3eZI7YPogV4SL3OPmNZjpB9 5HJexpLHgODQPDXW1FuBozLaqNEgDhtYeab3GIANhhLr2C0Cj6ZuTnESMR5CpUH6vJ+7 LvBuj5bPGhrCy35zBERqA+mE92D0lcDBmmzy4vEkiYtFLBR7dcXp8c+qODUL+Y64hkRv Arrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=v2J1mL+BBR5vVrjvIXBxi3ajx5DlHtaXwlO12NucBWw=; b=t+akVwe2rizez9Hnq6SpYQsBTjYPNod9xifI2ttkIUICyN/nSOtKvZeRCc+TwjUCwe 9sMZ8KUc21gjZzIGGpHmOXvmHCkSn0sQqnwfFmwT4Dn2T2CpJ9cWUEhRnNFKtkk50KMv 6MWJEKDoN0GXIlONgnQjVY7xcSJ4ogBjQmO3ZrazDlWdbpJ347iRTyMQ5t9ojTLFkUM6 UFgPAQ10mElRWIVHzWC4jkMDX1REmUdpqxBxKq4RLAINzR/beC921J7pyoQ/E4sNpz/W N0ZXzuVaCI2j0Pjp2II//aLVXDYjdjlJYwyklyaqvJ2IuYGz7/Vu7z2zfnHlL3Zm1qtR ulvA== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si1950840pgt.371.2019.04.18.07.29.30; Thu, 18 Apr 2019 07:29:45 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389371AbfDRO2F (ORCPT + 99 others); Thu, 18 Apr 2019 10:28:05 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35188 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389146AbfDRO2E (ORCPT ); Thu, 18 Apr 2019 10:28:04 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3IEJ2rS040587 for ; Thu, 18 Apr 2019 10:28:03 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rxqjs1ye1-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 18 Apr 2019 10:28:02 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Apr 2019 15:28:00 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 18 Apr 2019 15:27:56 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3IERteW53149868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 14:27:55 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91AC611C06E; Thu, 18 Apr 2019 14:27:55 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C83311C058; Thu, 18 Apr 2019 14:27:54 +0000 (GMT) Received: from [9.145.32.15] (unknown [9.145.32.15]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 18 Apr 2019 14:27:54 +0000 (GMT) Subject: Re: [PATCH] prctl_set_mm: downgrade mmap_sem to read lock To: =?UTF-8?Q?Michal_Koutn=c3=bd?= , Cyrill Gorcunov Cc: mhocko@kernel.org, akpm@linux-foundation.org, arunks@codeaurora.org, brgl@bgdev.pl, geert+renesas@glider.be, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mguzik@redhat.com, rppt@linux.ibm.com, vbabka@suse.cz References: <20190417145548.GN5878@dhcp22.suse.cz> <20190418135039.19987-1-mkoutny@suse.com> From: Laurent Dufour Date: Thu, 18 Apr 2019 16:27:53 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190418135039.19987-1-mkoutny@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19041814-4275-0000-0000-000003294817 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041814-4276-0000-0000-0000383881C8 Message-Id: <27defd37-7e4e-f919-fe0c-64e1efdafdcf@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-18_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904180098 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 18/04/2019 à 15:50, Michal Koutný a écrit : > I learnt, it's, alas, too late to drop the non PRCTL_SET_MM_MAP calls > [1], so at least downgrade the write acquisition of mmap_sem as in the > patch below (that should be stacked on the previous one or squashed). > > Cyrill, you mentioned lock changes in [1] but the link seems empty. Is > it supposed to be [2]? That could be an alternative to this patch after > some refreshments and clarifications. > > > [1] https://lore.kernel.org/lkml/20190417165632.GC3040@uranus.lan/ > [2] https://lore.kernel.org/lkml/20180507075606.870903028@gmail.com/ > > ======== > > 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). > > Also, save few cycles by looking up VMA only after performing basic > arguments validation. > > Signed-off-by: Michal Koutný > --- > kernel/sys.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/kernel/sys.c b/kernel/sys.c > index 12df0e5434b8..bbce0f26d707 100644 > --- a/kernel/sys.c > +++ b/kernel/sys.c > @@ -2125,8 +2125,12 @@ static int prctl_set_mm(int opt, unsigned long addr, > > error = -EINVAL; > > - down_write(&mm->mmap_sem); > - vma = find_vma(mm, addr); > + /* > + * 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); > + spin_lock(&mm->arg_lock); > > prctl_map.start_code = mm->start_code; > prctl_map.end_code = mm->end_code; > @@ -2185,6 +2189,7 @@ static int prctl_set_mm(int opt, unsigned long addr, > if (error) > goto out; > > + vma = find_vma(mm, addr); Why is find_vma() called while holding the arg_lock ? To limit the time the spinlock is held, would it be better to read_lock(mmap_sem) find_vma() spin_lock(arg_lock) .. out: spin_unlock() up_read(mmap_sem) Not sure this would change a lot the performance anyway. > switch (opt) { > /* > * If command line arguments and environment > @@ -2218,7 +2223,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; > } > >