Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4203552imj; Tue, 12 Feb 2019 11:34:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ/6YlNjsgd/4jKGnRFTEj8rjWPxZH3rw87wV7B15TcNLA4hE26/BbOz1ugq+inLKhsjhiD X-Received: by 2002:a65:4807:: with SMTP id h7mr4980807pgs.15.1550000092784; Tue, 12 Feb 2019 11:34:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550000092; cv=none; d=google.com; s=arc-20160816; b=iT95kbUPWbT0G17gdxuhk2hYwOBsIsBr0+/VQGAA4YEUgcDQc1AihPjp1r529jDYR9 spJhIuNVuqXT85qK1M9i9zkYiVu1UD6zrvl79HGn8ZXDMO8dfJiBqBtVtV2M5Brn5PsL LxMoLcndccFCLoNhvahy7OgxyZ/BTZ6SlW8kYpk3tT8ZLReu0A2wOekNuh29yJ/6b6QP RD5XioQqrBorediGBbMXEuIKanVBAjBUHC59E/FnsUIpqzvAErQ+yibE/tZexWhPUije BJ4bXD6moMVeMukCAwX9xdPmhoRKOqg966yqeG6PORr/BHfibnDHIUf4cCEjQ/zN3YqL wb2A== 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=/AU2PS2waBBBHfOuEsk+KdrvieceqHVwvbvBZ65cUqM=; b=HEvMvexbAR5dC1Y+xmfGYCOczG7qk83L+0/zf8o/hYJ4TA2UwhJkPnRLxpLb4KZ5tl YTKEyEBERYHJupLCKOmcmrnMrLQBtpka96Ar1ZEdsfHEk3pE8yKA2xUac3vPPLnYLYZB KZ6zLb2tbgvPG3I3eSwFuXQPoiaZ9j6oowUuA09AEJ12RkQzWx10QSqZiEYoWpBBBs7E C0zYB0toroNUZsIk0fbOSN+5l+Ww6gbdxbcu9+ZW9QhjuL0Yc0ODo3bZBWX9wrXNNlGr L5Orr/ZcQYjfW5vKbPIuRor2iMKHG08hBZTRDdYPL1q6lOPHjNBQTHxKvNme092+7ys8 NGlQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si12803996pgi.480.2019.02.12.11.34.35; Tue, 12 Feb 2019 11:34:52 -0800 (PST) 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730963AbfBLSlN (ORCPT + 99 others); Tue, 12 Feb 2019 13:41:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59674 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfBLSlN (ORCPT ); Tue, 12 Feb 2019 13:41:13 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5D75E6A7D; Tue, 12 Feb 2019 18:41:12 +0000 (UTC) Received: from w520.home (ovpn-116-24.phx2.redhat.com [10.3.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B1275D973; Tue, 12 Feb 2019 18:41:11 +0000 (UTC) Date: Tue, 12 Feb 2019 11:41:10 -0700 From: Alex Williamson To: Daniel Jordan Cc: Jason Gunthorpe , akpm@linux-foundation.org, dave@stgolabs.net, jack@suse.cz, cl@linux.com, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, hao.wu@intel.com, atull@kernel.org, mdf@kernel.org, aik@ozlabs.ru Subject: Re: [PATCH 1/5] vfio/type1: use pinned_vm instead of locked_vm to account pinned pages Message-ID: <20190212114110.17bc8a14@w520.home> In-Reply-To: <20190211231152.qflff6g2asmkb6hr@ca-dmjordan1.us.oracle.com> References: <20190211224437.25267-1-daniel.m.jordan@oracle.com> <20190211224437.25267-2-daniel.m.jordan@oracle.com> <20190211225620.GO24692@ziepe.ca> <20190211231152.qflff6g2asmkb6hr@ca-dmjordan1.us.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 12 Feb 2019 18:41:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 Feb 2019 18:11:53 -0500 Daniel Jordan wrote: > On Mon, Feb 11, 2019 at 03:56:20PM -0700, Jason Gunthorpe wrote: > > On Mon, Feb 11, 2019 at 05:44:33PM -0500, Daniel Jordan wrote: > > > @@ -266,24 +267,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) > > > if (!mm) > > > return -ESRCH; /* process exited */ > > > > > > - ret = down_write_killable(&mm->mmap_sem); > > > - if (!ret) { > > > - if (npage > 0) { > > > - if (!dma->lock_cap) { > > > - unsigned long limit; > > > - > > > - limit = task_rlimit(dma->task, > > > - RLIMIT_MEMLOCK) >> PAGE_SHIFT; > > > + pinned_vm = atomic64_add_return(npage, &mm->pinned_vm); > > > > > > - if (mm->locked_vm + npage > limit) > > > - ret = -ENOMEM; > > > - } > > > + if (npage > 0 && !dma->lock_cap) { > > > + unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >> > > > + > > > - PAGE_SHIFT; > > > > I haven't looked at this super closely, but how does this stuff work? > > > > do_mlock doesn't touch pinned_vm, and this doesn't touch locked_vm... > > > > Shouldn't all this be 'if (locked_vm + pinned_vm < RLIMIT_MEMLOCK)' ? > > > > Otherwise MEMLOCK is really doubled.. > > So this has been a problem for some time, but it's not as easy as adding them > together, see [1][2] for a start. > > The locked_vm/pinned_vm issue definitely needs fixing, but all this series is > trying to do is account to the right counter. This still makes me nervous because we have userspace dependencies on setting process locked memory. There's a user visible difference if we account for them in the same bucket vs separate. Perhaps we're counting in the wrong bucket now, but if we "fix" that and userspace adapts, how do we ever go back to accounting both mlocked and pinned memory combined against rlimit? Thanks, Alex