Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1334785pxa; Sun, 2 Aug 2020 04:09:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ7hPg98pbIExoiHXdgIUHjRJvW/PlE57bSXFc+hMD1h3s0wKqV+glaHCMYaGs7UbtdBSa X-Received: by 2002:a17:906:3b83:: with SMTP id u3mr11743649ejf.55.1596366572941; Sun, 02 Aug 2020 04:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596366572; cv=none; d=google.com; s=arc-20160816; b=sMupX00Z0UGcnEt37AQZwmJV4+0TbRcRvEzFXPMkup3LXuPtduxlOeVwzYh0E77x9u 2NcyejV24TcasQil6Eh0iB5YrLr7EHiSHAGx4LoooyKTFRd0iVX1hAxbbBBa8QcvKHyr QeCy98quU2QE2gYR9z+GFZGUYRjDCTl+nbDQMdo+qNRWEOZp/WgOBwbcFlRvts2BhaNi jeB1fm6+hVL1aLxCvXJEcRcT9SBMJaFFbaldLSYAvzgynES1Bz+UkXeO48nW3g5lKytG p2GdLkZ3F7M2a66E3Oj9T9Q9FowaDx8vq7LRifIkZlvGW+a/ZRXi+Mc+VYQIG2uJhWNP X68A== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=mDbdrpul3P0oQ8cJ/HnyPK9nRzlNnLOkGXnAcnH2KrE=; b=BYXhtTkoQrm4e4r1R8/SHqqb1V3H+R8netowN9aAtoLAc1O/S0abMy7xD/nncIFByR O7r3oZfMy05sCKrvBKfZn47k6alTqkV+xD7w30iYwGTQreb7YfXLfBI5+KLzBkEauu6M cZXWfaj5AiBR7B3NSrdOdhw3iWZ9Voo5hLCMbjIEl7kgaJsbtQNRzBE+sbPLas75ItoS HgxlPxu8mU2QbMnV0miIqc4/LVW9D5ESqpAPUaJ9gSsXI80UCO+Tqi0Z8YLJScDSgns3 rq0h2tEoIcQOmov7MKQaJ2jVuiwH20Rc88UM72+ducdau7UvTSeG/HlImgraQq/oY+aj pYwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z20si8210191ejm.732.2020.08.02.04.09.10; Sun, 02 Aug 2020 04:09:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbgHBLHw (ORCPT + 99 others); Sun, 2 Aug 2020 07:07:52 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:34241 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbgHBLHv (ORCPT ); Sun, 2 Aug 2020 07:07:51 -0400 X-Originating-IP: 180.110.142.179 Received: from localhost (unknown [180.110.142.179]) (Authenticated sender: fly@kernel.page) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 5F47260002; Sun, 2 Aug 2020 11:07:34 +0000 (UTC) Date: Sun, 2 Aug 2020 19:07:24 +0800 From: Pengfei Li To: Hugh Dickins Cc: akpm@linux-foundation.org, bmt@zurich.ibm.com, dledford@redhat.com, willy@infradead.org, vbabka@suse.cz, kirill.shutemov@linux.intel.com, jgg@ziepe.ca, alex.williamson@redhat.com, cohuck@redhat.com, daniel.m.jordan@oracle.com, dbueso@suse.de, jglisse@redhat.com, jhubbard@nvidia.com, ldufour@linux.ibm.com, Liam.Howlett@oracle.com, peterz@infradead.org, cl@linux.com, jack@suse.cz, rientjes@google.com, walken@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, fly@kernel.page Subject: Re: [PATCH 2/2] mm, util: account_locked_vm() does not hold mmap_lock Message-ID: <20200802190724.493304b6.fly@kernel.page> In-Reply-To: References: <20200726080224.205470-1-fly@kernel.page> <20200726080224.205470-2-fly@kernel.page> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Jul 2020 12:21:11 -0700 (PDT) Hugh Dickins wrote: Sorry for the late reply. > On Sun, 26 Jul 2020, Pengfei Li wrote: > > > Since mm->locked_vm is already an atomic counter, > > account_locked_vm() does not need to hold mmap_lock. > > I am worried that this patch, already added to mmotm, along with its > 1/2 making locked_vm an atomic64, might be rushed into v5.9 with just > that two-line commit description, and no discussion at all. > > locked_vm belongs fundamentally to mm/mlock.c, and the lock to guard > it is mmap_lock; and mlock() has some complicated stuff to do under > that lock while it decides how to adjust locked_vm. > > It is very easy to convert an unsigned long to an atomic64_t, but > "atomic read, check limit and do stuff, atomic add" does not give > the same guarantee as holding the right lock around it all. > > (At the very least, __account_locked_vm() in 1/2 should be changed to > replace its atomic64_add by an atomic64_cmpxchg, to enforce the limit > that it just checked. But that will be no more than lipstick on a > pig, when the right lock that everyone else agrees upon is not being > held.) > Thank you for your detailed comment. You are right, I should use atomic64_cmpxchg to guarantee the limit of RLIMIT_MEMLOCK. > Now, it can be argued that our locked_vm and pinned_vm maintenance > is so random and deficient, and too difficult to keep right across > a sprawl of drivers, that we should just be grateful for those that > do volunteer to subject themselves to RLIMIT_MEMLOCK limitation, > and never mind if it's a little racy. > > And it may well be that all those who have made considerable efforts > in the past to improve the situation, have more interesting things to > devote their time to, and would prefer not to get dragged back here. > > But let's at least give this a little more visibility, and hope > to hear opinions one way or the other from those who care. Thank you. My patch should be more thoughtful. I will send an email to Stephen soon asking to remove these two patches from -mm tree. -- Pengfei