Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp640570yba; Thu, 18 Apr 2019 07:16:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyimezHmx6aJj9fHjaGhAbH5a+/ibg84CbCJTNBkTEVHznC4XBtK+ifM/MHpn3knWeTZkH6 X-Received: by 2002:a62:4649:: with SMTP id t70mr97003238pfa.100.1555596984208; Thu, 18 Apr 2019 07:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555596984; cv=none; d=google.com; s=arc-20160816; b=lxHM2FVwgUR9QP1nioD/oJa600fyf72Pz9INT7KGmyvPq7LsmpzgT2kGNDqYyipiny d31ZxWvqnHTiXye7K35T8NFvTMh1U47nlpmnMSNegDU1oYwFTLtjJ05B+Hh0GAi/zV9X a/D7uxjV5FsOAORo4Heg/+epLj4N/2C30ZrYb4+jYElF+95eNJA6V3wgqDF51zKEXbVV 2z3KC2UpwHgwP7qwXTNFoSdJcPkOYnbu4UVrX4lGKBx9xGXn59r4pQiIVJt9oW4oFLdz pflDzNGIoOUhdFNHl7a3D3NV+lXIv+HLqz/PrBiPO+rx0ATzc4MRq62U/1gSbQGaO4X9 7GHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qbUqGLSVDkxfqCdCwcVWFnMgG8JKZytKZPFSCBedmGQ=; b=lcg7dIF2aiRweJvpULz/QD3QGzdPqMcKgOAgs7yK98NJe2phtjUkVf10C8QkfiiGB7 ayDgEyzg5BCIfG6t1B576TtNn697NRj6/fh3xTmbzL69hxhATdh9me6bLvV9cW7R3WCu VOjdHVvw/F96auNDqnXmctT5cSAlRiWxs1OAcQxSf9Z5hkXxEuzyvyeBAg9oyTcmqaUl aWODNY+oe8CPkiY4l9hsB8LCrnMNhobbEClXO+S8deBqSD9YjSHszzVhitT0VOtIvdNo 73STzXhO3gxICm1Io3XnNtN4Jbd+5iwPR/KAQeQ0qofFRPpFu2dfd7+/bIEQFuWT6di8 2HLA== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u193si2015576pgc.410.2019.04.18.07.16.09; Thu, 18 Apr 2019 07:16:24 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389153AbfDROPK (ORCPT + 99 others); Thu, 18 Apr 2019 10:15:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:51194 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388346AbfDROPK (ORCPT ); Thu, 18 Apr 2019 10:15:10 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D8DD0B16E; Thu, 18 Apr 2019 14:15:08 +0000 (UTC) Date: Thu, 18 Apr 2019 16:15:07 +0200 From: Michal Hocko To: Michal =?iso-8859-1?Q?Koutn=FD?= Cc: Cyrill Gorcunov , 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, Laurent Dufour Subject: Re: [PATCH] prctl_set_mm: downgrade mmap_sem to read lock Message-ID: <20190418141507.GO6567@dhcp22.suse.cz> References: <20190417145548.GN5878@dhcp22.suse.cz> <20190418135039.19987-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190418135039.19987-1-mkoutny@suse.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 18-04-19 15:50:39, Michal Koutny wrote: > 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? Looks good to me. Please send both patches in one series once you get a review feedback from other people. > --- > 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); > 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; > } > > -- > 2.16.4 -- Michal Hocko SUSE Labs