From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9350CC433E3 for ; Sun, 2 Aug 2020 11:07:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5E4A52075B for ; Sun, 2 Aug 2020 11:07:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E4A52075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.page Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D07AA8D00AF; Sun, 2 Aug 2020 07:07:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBCD68D00AA; Sun, 2 Aug 2020 07:07:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCE6B8D00AF; Sun, 2 Aug 2020 07:07:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id A8B068D00AA for ; Sun, 2 Aug 2020 07:07:52 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6C220180AD807 for ; Sun, 2 Aug 2020 11:07:52 +0000 (UTC) X-FDA: 77105353584.10.tax49_3007f4226f94 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 3BAC116A069 for ; Sun, 2 Aug 2020 11:07:52 +0000 (UTC) X-HE-Tag: tax49_3007f4226f94 X-Filterd-Recvd-Size: 3689 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Sun, 2 Aug 2020 11:07:51 +0000 (UTC) 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 X-Rspamd-Queue-Id: 3BAC116A069 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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