Received: by 10.213.65.68 with SMTP id h4csp64495imn; Mon, 26 Mar 2018 15:14:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx49cuPrYVqH3jMXemXGKY2uJDPWOBjQHObDQmt3EHUotrI8qJPGFQ5XrJfzRrz3U1G2wDzH4 X-Received: by 10.98.156.7 with SMTP id f7mr4661428pfe.104.1522102464081; Mon, 26 Mar 2018 15:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522102464; cv=none; d=google.com; s=arc-20160816; b=w0IBgumt5Du3vVKQUS+NoZX3bq41z16k09lPXdxaJS+qhhSDQ6JhNi0x8LJ0qGYDFp WuOivU+bE1nJHUSzLHPeLu8ESWOL2A9DKfZSTKbv5x0w8PMDVk/08JfFPKS79frbtinN OwdKo5IAlJpKYg047rM3dSZR974UvKtgJVeyPh/JrNONAx0xNd3rA2nF9NHQwBP8hWTw JUId7I6fiKbcIbIjh1AxG4E64XAwvBA/zEZhhPXeV02ehXUDTTGqkdZNSC3I0G3OME+B I0AyjqNc+uzbipakjvCy2LwINKdVTd8YPHF4wDiPZbm/qBGgmJNtuLo5UO2py06a6m+Q ZxXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=eCC8v3hajOiQkDaoW3qSEhBQ5ZPLo362dYzyuIROfpw=; b=C+Ot6qZP4+9iYpvix5QIH6eNtFiwNlYjgrPLm5HhcRqbqc/i5W3iCiYsAxJ/q4Or8K Rg3kUrmf0Rq2h6NTjgf1sO59EcTe9DXls7LPekJJ1xtWLnF4MIZuKngQn1on7l4WRqQ3 00NS58Bxnl2Cl9rEwFBO9gRAFaLwrdgf00b6hY3ZxZgPm0LhRJVBKyE6+jOQc4hn2HYq 8GkeauGIfldenera86feBRjCIyX5+3V6499GcFU4++W+b7OayfKDKa4vDD/jJb1G2Oix J+u9e3lXc68gp51G/JGp2geL2WGs5+f853b6hDgOaXdrVmjbTN7XGUF/zEQpUku2EeF5 7FBQ== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6-v6si14935479plt.62.2018.03.26.15.14.09; Mon, 26 Mar 2018 15:14: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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbeCZWNP (ORCPT + 99 others); Mon, 26 Mar 2018 18:13:15 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:51781 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751160AbeCZWNO (ORCPT ); Mon, 26 Mar 2018 18:13:14 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0T-8lX2z_1522102378; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:121.0.29.199) by smtp.aliyun-inc.com(127.0.0.1); Tue, 27 Mar 2018 06:13:06 +0800 Subject: Re: [v2 PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct To: Tetsuo Handa , gorcunov@gmail.com Cc: willy@infradead.org, adobriyan@gmail.com, mhocko@kernel.org, mguzik@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1522088439-105930-1-git-send-email-yang.shi@linux.alibaba.com> <20180326183725.GB27373@bombadil.infradead.org> <20180326192132.GE2236@uranus> <0bfa8943-a2fe-b0ab-99a2-347094a2bcec@i-love.sakura.ne.jp> <20180326212944.GF2236@uranus> <201803270700.IJB35465.HJQFSFMVLFOtOO@I-love.SAKURA.ne.jp> From: Yang Shi Message-ID: Date: Mon, 26 Mar 2018 18:12:55 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <201803270700.IJB35465.HJQFSFMVLFOtOO@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/26/18 6:00 PM, Tetsuo Handa wrote: > Cyrill Gorcunov wrote: >> On Tue, Mar 27, 2018 at 06:10:09AM +0900, Tetsuo Handa wrote: >>> On 2018/03/27 4:21, Cyrill Gorcunov wrote: >>>> That said I think using read-lock here would be a bug. >>> If I understand correctly, the caller can't set both fields atomically, for >>> prctl() does not receive both fields at one call. >>> >>> prctl(PR_SET_MM, PR_SET_MM_ARG_START xor PR_SET_MM_ARG_END xor PR_SET_MM_ENV_START xor PR_SET_MM_ENV_END, new value, 0, 0); >>> >> True, but the key moment is that two/three/four system calls can >> run simultaneously. And while previously they are ordered by "write", >> with read lock they are completely unordered and this is really >> worries me. > Yes, we need exclusive lock when updating these fields. > >> To be fair I would prefer to drop this old per-field >> interface completely. This per-field interface was rather an ugly >> solution from my side. > But this is userspace visible API and thus we cannot change. > >>> Then, I wonder whether reading arg_start|end and env_start|end atomically makes >>> sense. Just retry reading if arg_start > env_end or env_start > env_end is fine? >> Tetsuo, let me re-read this code tomorrow, maybe I miss something obvious. >> > You are not missing my point. What I thought is > > +retry: > - down_read(&mm->mmap_sem); > arg_start = mm->arg_start; > arg_end = mm->arg_end; > env_start = mm->env_start; > env_end = mm->env_end; > - up_read(&mm->mmap_sem); > > - BUG_ON(arg_start > arg_end); > - BUG_ON(env_start > env_end); > + if (unlikely(arg_start > arg_end || env_start > env_end)) { > + cond_resched(); > + goto retry; Can't it trap into dead loop if the condition is always false? > + } > > for reading these fields. > > By the way, /proc/pid/ readers are serving as a canary who tells something > mm_mmap related problem is happening. On the other hand, it is sad that > such canary cannot be terminated by signal due to use of unkillable waits. > I wish we can use killable waits. I already proposed patches (https://lkml.org/lkml/2018/2/26/1197) to do this a few weeks ago. In the review, akpm suggested mitigate the mmap_sem contention instead of using killable version workaround. Then the preliminary unmaping by section patches (https://lkml.org/lkml/2018/3/20/786) were proposed. In the discussion, we decided to eliminate the mmap_sem abuse, this is where the patch came from. Yang