Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4531051ybc; Fri, 15 Nov 2019 06:13:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwMBez6R02llcMs0Ei/DiacdM40v5fK8xmF6fIcjAT+CyayPxnE6LwNq6EczRXfusosDLFI X-Received: by 2002:a1c:7d95:: with SMTP id y143mr15527491wmc.143.1573827207351; Fri, 15 Nov 2019 06:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573827207; cv=none; d=google.com; s=arc-20160816; b=CIbXbKWavtlLx2EAVcobTleJEKj0vLtGxEPwj5qDj66RocxWnWGD2KIW/X37muKm+A qb51rY/A7i2DmoXS48n582LOCQhZPV5RWK+ZkyiF2JnSnvEClwWKULcUQRHSZPMbvN53 HV9P/vc/9kzlg+L1W42sFpA5353tIjNHKoE5koTi7KgExQIBNkZb4PgGmKn6jD8b4MB3 kAPUa9EwVLp3KvIqofPH223Szc5wtvYpGOCG08gCJn8OOTh4sRMwSo6b7RjkH/mChpPv 3kJbF2LAtzSdsMqFRB5FoPmdr6ZWGdyRIuLciVFzXmVg1mfp6rmbFPfgBZ6D7bLED7Jf Ko1Q== 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; bh=8ZGdiHZxf3ZHqX3I8ydxFdLkSWkpE5WrCI0dICjPpHU=; b=cxP2Tmasyj8x9EYleUIBxLOALhyqyRlgVS8WZskylncNc7Hz8A0tZPp/aEsoipRo8u M7yd04WvFvqSmUPCLU1bZqKF1JCpHAxr8YT0Y1TlhKgtdqa1Vzrao0BxkZB4L8QKqisV 9XukDqMvUOuyubhhCnxykl3HhgiSb8H0nBIYOTbrVDGJkxhTXrjon0yHWMHw8/y8JtsE 3PZ5EYE62yQK7gXLn6lBbLsH8fJ4ftsSaXTF9noYm62SNjNCyOhOlPAgSGzxeXjOqnad E51s5FGq2xiabpWLTV6oJn4iEqgE/JSq8iubO/vJsu0K2Ad1XK/ScL/175vOa4bcYi+r CRlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=i+UlYqHp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si996825edd.241.2019.11.15.06.13.01; Fri, 15 Nov 2019 06:13:27 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b=i+UlYqHp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727492AbfKOOIt (ORCPT + 99 others); Fri, 15 Nov 2019 09:08:49 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:39686 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbfKOOIo (ORCPT ); Fri, 15 Nov 2019 09:08:44 -0500 Received: by mail-qt1-f196.google.com with SMTP id t8so10922217qtc.6 for ; Fri, 15 Nov 2019 06:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8ZGdiHZxf3ZHqX3I8ydxFdLkSWkpE5WrCI0dICjPpHU=; b=i+UlYqHpSoy9hrCL3gQPMJUhUw3RKIgDls07tcBvdNTrD4jl5OTOMJfNN1MASvpOc/ n/RUaDL07zMYWDhclWHPDZnaqTZ6YdpZfzuTyA+HrehI2Ydc75hfkUNiRgV5KLUhGbZ5 hwJR6j62hBrGSzy1DyO8h1zN9TlzptjO0LEx4CpgETqR3CBgJNCsKnZKRcbg5KwHic/q pEIdohRRBLTVk18YHW5Vi8NX67r/lGgj0cpRlIJEz6SaDVQBInMFNoQa60kFdiQzPjma xgI2yhuOWu+cTXk9NFpI3of3yS1+C6h76JgFDhrvoDw5piCzGcHI/ud3iOPSS57DuCxF BfMw== 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=8ZGdiHZxf3ZHqX3I8ydxFdLkSWkpE5WrCI0dICjPpHU=; b=aQvUKKT45vOTZaOhLfOnhxD/t75CUNUaKNy89aeR3X0I1QCuQMyFDyEMBIhFsWtENz BVSS17veE3rXT0Y/mT9LWbIgRWSjmC1yYJl8NiLOD31c5aXkiw9Ot5pBTQDVzEX09STc Xs9mtMNJhhdToNDpgnIpAlLPowWBe6RAOjlBAqpCU6E43WO6heb08P6YbZI3IfH75dkR LvMY3cV5iJl6A6hHffzeDnLKqkNnWjeiBjLl2hYRndHTCPUZbxgPYq+9w7Eyyy6dLy93 fysbub3vZT+Zat4HUk5SHxWxYHuRpRqNaKM2GJfHVwKCkFUpTbkSMHywapm0x4eP4rPo J7Fg== X-Gm-Message-State: APjAAAUgHEw6+NP9QuxS1PnRMx5uSjrQfDRrek0lLw7EvJ/hjWHIX2Hg cJSI7T7K718zh2NK1fi4pBHWmg== X-Received: by 2002:ac8:661a:: with SMTP id c26mr13620771qtp.317.1573826923526; Fri, 15 Nov 2019 06:08:43 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-113-180.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.180]) by smtp.gmail.com with ESMTPSA id s21sm5382292qtc.12.2019.11.15.06.08.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2019 06:08:42 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iVcHC-0002xg-A8; Fri, 15 Nov 2019 10:08:42 -0400 Date: Fri, 15 Nov 2019 10:08:42 -0400 From: Jason Gunthorpe To: John Hubbard Cc: Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jens Axboe , Jonathan Corbet , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko , Mike Kravetz , Paul Mackerras , Shuah Khan , Vlastimil Babka , bpf@vger.kernel.org, dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, linux-rdma@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, linux-mm@kvack.org, LKML Subject: Re: [PATCH v5 09/24] vfio, mm: fix get_user_pages_remote() and FOLL_LONGTERM Message-ID: <20191115140842.GA4055@ziepe.ca> References: <20191115055340.1825745-1-jhubbard@nvidia.com> <20191115055340.1825745-10-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191115055340.1825745-10-jhubbard@nvidia.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 14, 2019 at 09:53:25PM -0800, John Hubbard wrote: > As it says in the updated comment in gup.c: current FOLL_LONGTERM > behavior is incompatible with FAULT_FLAG_ALLOW_RETRY because of the > FS DAX check requirement on vmas. > > However, the corresponding restriction in get_user_pages_remote() was > slightly stricter than is actually required: it forbade all > FOLL_LONGTERM callers, but we can actually allow FOLL_LONGTERM callers > that do not set the "locked" arg. > > Update the code and comments accordingly, and update the VFIO caller > to take advantage of this, fixing a bug as a result: the VFIO caller > is logically a FOLL_LONGTERM user. > > Also, remove an unnessary pair of calls that were releasing and > reacquiring the mmap_sem. There is no need to avoid holding mmap_sem > just in order to call page_to_pfn(). > > Also, move the DAX check ("if a VMA is DAX, don't allow long term > pinning") from the VFIO call site, all the way into the internals > of get_user_pages_remote() and __gup_longterm_locked(). That is: > get_user_pages_remote() calls __gup_longterm_locked(), which in turn > calls check_dax_vmas(). It's lightly explained in the comments as well. > > Thanks to Jason Gunthorpe for pointing out a clean way to fix this, > and to Dan Williams for helping clarify the DAX refactoring. > > Suggested-by: Jason Gunthorpe > Cc: Dan Williams > Cc: Jerome Glisse > Cc: Ira Weiny > Signed-off-by: John Hubbard > --- > drivers/vfio/vfio_iommu_type1.c | 30 +++++------------------------- > mm/gup.c | 27 ++++++++++++++++++++++----- > 2 files changed, 27 insertions(+), 30 deletions(-) Looks OK now Reviewed-by: Jason Gunthorpe