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=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 72B29C17441 for ; Tue, 12 Nov 2019 20:43:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29355214E0 for ; Tue, 12 Nov 2019 20:43:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Ia/Hl3Z1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29355214E0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AA4AF6B0276; Tue, 12 Nov 2019 15:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A54596B0278; Tue, 12 Nov 2019 15:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 943BE6B0279; Tue, 12 Nov 2019 15:43:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 7ED236B0276 for ; Tue, 12 Nov 2019 15:43:41 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 424C28249980 for ; Tue, 12 Nov 2019 20:43:41 +0000 (UTC) X-FDA: 76148801442.26.cakes92_3d2d51f8f6c36 X-HE-Tag: cakes92_3d2d51f8f6c36 X-Filterd-Recvd-Size: 7492 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Nov 2019 20:43:40 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id n4so16686555qte.2 for ; Tue, 12 Nov 2019 12:43:40 -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=kGcjnenI+EnnAHWMcItB24mxm55INky4C94Ykv4geg4=; b=Ia/Hl3Z1HOGYiq6KoluUd9uZCGKzwQBgBr5JQ7I5KyZEUZP07fiLx9egiGiglXV9yp zwduhp53vyEcd290QPaERf3wZ21mOf61BVNQbg6GVzWjLkWaYtjFFrAZ/kB/sX/TsV0O Cqh6vZK9nd1Vig8r0syQpzeADiWtdjhU8C1qoZqr93PSItmh35/j4piNjOHcIgDaKDz3 2BaPDGhVa8atEOsvR55GHtOxdcr+RnZlO25xW0gJoiJutB0sYZDed0fX6gxPxoxhf5Zl 1FXBtMQo3iHNaStug4eqwxrgV4Z4sqg89JFN5ijz+6oI5UdbjHNjva//V05ajuQKORqi pELA== 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=kGcjnenI+EnnAHWMcItB24mxm55INky4C94Ykv4geg4=; b=lPw6UGuG8k5awBGMPxqOOtIZqfVI4Qd+Lx+FCHqTgbFROqd604O+LI0XRK6mZ564Ug BS6gVJcLhZFgPArQeSDkB9/BjzYTblGGJN2v3faIKu7ChkVtC4sicsUIhIKKzMGZIWXF oBOxhF9WKHSe6w1VWpm3oqpGHvyyDYezXABQ+ec5sMIcAacSuqF/KQhVYKkLrDVDVqs0 XT+8ijxOmOURaSGz3Y26wCJLYtUbvOLuo63rC/P9GSh09g58ISZMDpDj7sI1Vlp9tYxF W5IRWRpbA0YHsvD8tz1Kfb8u9ZEzbdxZKbdNNgWsuGpXes0g5W5AY+bWNvRXj/E32qva o4cg== X-Gm-Message-State: APjAAAWrrtsQBRGgwZx+P2n1r92d/EATdNHXQqjEWr92Qb5vTOeNQpis NcsgDvYbLs7LwIl0dsb6UyAK0w== X-Google-Smtp-Source: APXvYqyV99P4cYBxqwR0yk0Vl7NSO/G/hGYwr7orI5pSazTDzznvIwLj5yKe4F2N3m9e7NI6fV/HBQ== X-Received: by 2002:ac8:1ba5:: with SMTP id z34mr33733259qtj.162.1573591419675; Tue, 12 Nov 2019 12:43:39 -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 u22sm10020470qtb.59.2019.11.12.12.43.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Nov 2019 12:43:39 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iUd0k-00046s-Fb; Tue, 12 Nov 2019 16:43:38 -0400 Date: Tue, 12 Nov 2019 16:43:38 -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 v3 08/23] vfio, mm: fix get_user_pages_remote() and FOLL_LONGTERM Message-ID: <20191112204338.GE5584@ziepe.ca> References: <20191112000700.3455038-1-jhubbard@nvidia.com> <20191112000700.3455038-9-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191112000700.3455038-9-jhubbard@nvidia.com> User-Agent: Mutt/1.9.4 (2018-02-28) 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 Mon, Nov 11, 2019 at 04:06:45PM -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. > > Thanks to Jason Gunthorpe for pointing out a clean way to fix this. > > Suggested-by: Jason Gunthorpe > Cc: Jerome Glisse > Cc: Ira Weiny > Signed-off-by: John Hubbard > --- > drivers/vfio/vfio_iommu_type1.c | 30 +++++++++++++----------------- > mm/gup.c | 13 ++++++++----- > 2 files changed, 21 insertions(+), 22 deletions(-) This matches what I thought, but I think DanW should check it too, and the vfio users should test.. > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index d864277ea16f..017689b7c32b 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -348,24 +348,20 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, > flags |= FOLL_WRITE; > > down_read(&mm->mmap_sem); > - if (mm == current->mm) { > - ret = get_user_pages(vaddr, 1, flags | FOLL_LONGTERM, page, > - vmas); > - } else { > - ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags, page, > - vmas, NULL); > - /* > - * The lifetime of a vaddr_get_pfn() page pin is > - * userspace-controlled. In the fs-dax case this could > - * lead to indefinite stalls in filesystem operations. > - * Disallow attempts to pin fs-dax pages via this > - * interface. > - */ > - if (ret > 0 && vma_is_fsdax(vmas[0])) { > - ret = -EOPNOTSUPP; > - put_page(page[0]); > - } > + ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags | FOLL_LONGTERM, > + page, vmas, NULL); > + /* > + * The lifetime of a vaddr_get_pfn() page pin is > + * userspace-controlled. In the fs-dax case this could > + * lead to indefinite stalls in filesystem operations. > + * Disallow attempts to pin fs-dax pages via this > + * interface. > + */ > + if (ret > 0 && vma_is_fsdax(vmas[0])) { > + ret = -EOPNOTSUPP; > + put_page(page[0]); > } AFAIK this chunk is redundant now as it is some hack to emulate FOLL_LONGTERM? So vmas can be deleted too. Also unclear why this function has this: up_read(&mm->mmap_sem); if (ret == 1) { *pfn = page_to_pfn(page[0]); return 0; } down_read(&mm->mmap_sem); Jason