Received: by 10.213.65.68 with SMTP id h4csp1680021imn; Mon, 26 Mar 2018 12:22:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELugLJSpe54jvL4c3MS6cg2y1wAw7BPsT0oTT6n/3e4Kv21db8g6AXKwPghYpOJ7L1UcBNSv X-Received: by 2002:a17:902:8602:: with SMTP id f2-v6mr41425985plo.6.1522092169231; Mon, 26 Mar 2018 12:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522092169; cv=none; d=google.com; s=arc-20160816; b=bFmgoOOUxp6YTlZWjFfDab1A12ipoSeskHUQJM4KK9B4OYPNSxYlmGxgzaKVsJM7Cp MtzP4cz6MVpDI+7aaDITbUFvMnzn7AZy/O+EXFJTstOjmZvaP+gB2ES8T/3biw2pWy6G sSdLVLTcif6k3Xhv831HaKnfP7LzqSEPtHVRGoCRtGSDMi7rw0IOgfZaZ570wxZ/ZM8k I4YBa4MCcZW/IVUbMEZR2xIxVjD8MNrygL3+5oHN3A4fuPOaTQHu01QkXUFFVLjfPknc B+/aZeke4VmnO9bdUN8v4nYJNnbmlKPwF8LJHLasSmUar7QjlHg111RNE1ddI5cw/YQC N4+g== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=kVU3zuqXjd+W/WXnhX72J3wtxRJse4rKzxrK5E41yjs=; b=XELEj4i1uljfOzYLG04BwFwX516iuYrhdlft8pgLshOwV/IDduy4tTBcByhH3ghqaz 52ts0tyHlg4XJM6xcwKMW/Ki6q3SgXdO6NpV9AO3I8wMpfk+97siwMziwQhtr97sTJQp KJ1gmue4JJzmFPiqtn0TiX+vHS+umBFMkgVOuSTgW5ez+6e56OofhdSR7UvsIMYWNbFH t3fN70xrQtrZPrkDVDvqTefyCF85qLmsJVZ4MD0HzAV8PU7TPPRrtfkZLBIiIGKgR4Yr LAMr2sR5h4Hzl8Bz6t0uIN0YCIDt6/5KEI4mdGX4E0pOXdgd/F4oouppQtN/uNp3ipAi 3AJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ng8icWhn; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1-v6si5873364pld.267.2018.03.26.12.22.34; Mon, 26 Mar 2018 12:22:49 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ng8icWhn; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752188AbeCZTVg (ORCPT + 99 others); Mon, 26 Mar 2018 15:21:36 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:34265 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbeCZTVf (ORCPT ); Mon, 26 Mar 2018 15:21:35 -0400 Received: by mail-lf0-f68.google.com with SMTP id c78-v6so25134351lfh.1 for ; Mon, 26 Mar 2018 12:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=kVU3zuqXjd+W/WXnhX72J3wtxRJse4rKzxrK5E41yjs=; b=ng8icWhn/MN2KVWkQAmgiTqpzPlYcH+qz2jfShkdQJNrwA2SYiowagBYgNj2n7HjlK k10QKGmM6SvX0CILftqw7ZcfiVdsLMO2QvbDHw3DtVBYPWfjmPc5Y88C48SrmiVEOQnz M6pLeJY4fIWH9dp2rSbAiMkhMnhX/5b5alC3afZQtFj5xnweS4v7cKFg9yqSa3v1Q3hh dMUqrq0QxmzkagXxc/oriFcS0EwFYaUMKQiSoBEjGA0YPIheHW9kpsT5WMgpZijGRtiW AUUT/Fx2e/3uDfi8UWCihP/Hi5TwGm1G9xHdjTcvm82MehFI5RIxw0aTL7i3DpO/vLeH B6TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kVU3zuqXjd+W/WXnhX72J3wtxRJse4rKzxrK5E41yjs=; b=MU1A/nE+HSflsAW3W/R1nl4Sd0zhZSp1B4JPaARrSY2kP/jOzPiXaovbBhfE3BK+kO tAKFUnKx/nvB0BB83EiFwCqYO2pLfLR/hEEcTNF9AgT1mJEsbXhFC5Cemo8p+uUi3xA2 oLzO+rZDDRTaWpkq8D1WMf7QsOUotWnq1XE63kY/ZjEHQKOaqOcyrQYUpKw/NVvZ9zUv raJXlWY52OHEDhsmChOXkTS2vv2D5WPUHsQeQCRmOtkXwqStKojZ1J8B1LQB1G1lKQMB b14o9tb0xILg6DAvahbuAvCpjslkdw3LDgeQCXKaTSCruf1zqjV07LemFJflM/MDcAj/ Q/Bw== X-Gm-Message-State: AElRT7Hl7RIkGEk4JwRSGp4Mz5T92aEbS4m7K7GH3WDr4GDmIetomNUC 8z79NcX97dzUP53qoyu9qB4= X-Received: by 10.46.145.4 with SMTP id m4mr11983171ljg.73.1522092093669; Mon, 26 Mar 2018 12:21:33 -0700 (PDT) Received: from uranus.localdomain ([5.18.102.224]) by smtp.gmail.com with ESMTPSA id o25sm1032973lji.14.2018.03.26.12.21.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Mar 2018 12:21:32 -0700 (PDT) Received: by uranus.localdomain (Postfix, from userid 1000) id 59A0D460893; Mon, 26 Mar 2018 22:21:32 +0300 (MSK) Date: Mon, 26 Mar 2018 22:21:32 +0300 From: Cyrill Gorcunov To: Matthew Wilcox Cc: Yang Shi , adobriyan@gmail.com, mhocko@kernel.org, mguzik@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [v2 PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct Message-ID: <20180326192132.GE2236@uranus> References: <1522088439-105930-1-git-send-email-yang.shi@linux.alibaba.com> <20180326183725.GB27373@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180326183725.GB27373@bombadil.infradead.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 11:37:25AM -0700, Matthew Wilcox wrote: > On Tue, Mar 27, 2018 at 02:20:39AM +0800, Yang Shi wrote: > > +++ b/kernel/sys.c > > @@ -1959,7 +1959,7 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data > > return error; > > } > > > > - down_write(&mm->mmap_sem); > > + down_read(&mm->mmap_sem); > > > > /* > > * We don't validate if these members are pointing to > > @@ -1980,10 +1980,13 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data > > mm->start_brk = prctl_map.start_brk; > > mm->brk = prctl_map.brk; > > mm->start_stack = prctl_map.start_stack; > > + > > + spin_lock(&mm->arg_lock); > > mm->arg_start = prctl_map.arg_start; > > mm->arg_end = prctl_map.arg_end; > > mm->env_start = prctl_map.env_start; > > mm->env_end = prctl_map.env_end; > > + spin_unlock(&mm->arg_lock); > > > > /* > > * Note this update of @saved_auxv is lockless thus > > I see the argument for the change to a write lock was because of a BUG > validating arg_start and arg_end, but more generally, we are updating these > values, so a write-lock is probably a good idea, and this is a very rare > operation to do, so we don't care about making this more parallel. I would > not make this change (but if other more knowledgable people in this area > disagree with me, I will withdraw my objection to this part). Say we've two syscalls running prctl_set_mm_map in parallel, and imagine one have @start_brk = 20 @brk = 10 and second caller has @start_brk = 30 and @brk = 20. Since now the call is guarded by _read_ the both calls unlocked and due to OO engine it may happen then when both finish we have @start_brk = 30 and @brk = 10. In turn "write" semaphore has been take to have consistent data on exit, either you have [20;10] or [30;20] assigned not something mixed. That said I think using read-lock here would be a bug. Cyrill