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=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 A5160C17441 for ; Tue, 12 Nov 2019 22:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7587E21872 for ; Tue, 12 Nov 2019 22:43:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="Jq7Ptqpe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727121AbfKLWn3 (ORCPT ); Tue, 12 Nov 2019 17:43:29 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:33062 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfKLWn0 (ORCPT ); Tue, 12 Nov 2019 17:43:26 -0500 Received: by mail-oi1-f196.google.com with SMTP id m193so16443231oig.0 for ; Tue, 12 Nov 2019 14:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SwaaHNLQ6Cwcgbew071VEYLmiCBwwXoXuuoAi+2uA2o=; b=Jq7Ptqpebw7UGAIdEQ/unEBsB7QbaXVZNTWXCanS5nvK3elyglZtGcUaQ89X7Thh8h IAM86ORfnzN6917rhUVFsUy3UD57DPR+XlrbhhZ/NXNnmHMPvg4XpzzSKBe4NqErKRUy bZxd+tm9M+MwB7qsXrtdhh4D3/L98cHAZWd0Ns8kuwxv1QWg3yEpu0lT5cnjJPtGKrYR anyG20BRg0b0DeF7mLr0STZrxT4BCOm+zZEBDW3gpHBI3V/JOgKkFou2F3URCWxql04L MQNOT/7KMRt8tV9Ump9WAqJ7q3xqWRAJd3iDm6wl8QcfVduDF9h8k23QxQ9DnzN60j3u /xqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SwaaHNLQ6Cwcgbew071VEYLmiCBwwXoXuuoAi+2uA2o=; b=SG0KcBo/eiZsdviL2KwwK3rTaA12FHtzKTAnl/pxnEqNcF0YmMkhAs8w+Fw93z6jRB FWGMBEQ5pLIALWHqAZL7YZjjgVw0w5cHMROujV4gH1SOh7KRA4LAbBAV3FbJKIHruIuM pJ8dN0VkTKGxmG2AsPb0ad9k6oq/FggWYCZ8MfDX1lVik2SiNWhMjhnvR/+mutpZN9QT M700IN4BAWAlJXKiRSJwwIzzaUownyg9OfFJiSWyDQb9Nhf2J01ZESXBStiwccBMYgFb SStWZNFaC20FSvulZEyvKvJwAXBOZH8Qf67SFb7a4qYGBTeO15A/wYut52XGEfrI82JY bAHw== X-Gm-Message-State: APjAAAWlUe7VzEtYAhl7yTom3Y2XLMch69LT+n8kuZ9O7Xlybk0XR4mc ivjOL+VOc9/4McV1q2SuWzS752TeqmaWNRHIgN11GQ== X-Google-Smtp-Source: APXvYqxLBopeTTnZkVho8CVk6N+hGkn5uHiE62zpra+sAfITZV3BdLQKTEc55Ljq6ZrLX2Tr24PR9eCQkyGplH1DN48= X-Received: by 2002:aca:ead7:: with SMTP id i206mr135827oih.0.1573598604957; Tue, 12 Nov 2019 14:43:24 -0800 (PST) MIME-Version: 1.0 References: <20191112000700.3455038-1-jhubbard@nvidia.com> <20191112000700.3455038-9-jhubbard@nvidia.com> <471e513c-833f-2f8b-60db-5d9c56a8f766@nvidia.com> In-Reply-To: <471e513c-833f-2f8b-60db-5d9c56a8f766@nvidia.com> From: Dan Williams Date: Tue, 12 Nov 2019 14:43:14 -0800 Message-ID: Subject: Re: [PATCH v3 08/23] vfio, mm: fix get_user_pages_remote() and FOLL_LONGTERM To: John Hubbard Cc: Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Christoph Hellwig , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jonathan Corbet , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko , Mike Kravetz , Paul Mackerras , Shuah Khan , Vlastimil Babka , bpf@vger.kernel.org, Maling list - DRI developers , KVM list , linux-block@vger.kernel.org, Linux Doc Mailing List , linux-fsdevel , linux-kselftest@vger.kernel.org, "Linux-media@vger.kernel.org" , linux-rdma , linuxppc-dev , Netdev , Linux MM , LKML , "Aneesh Kumar K.V" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 12, 2019 at 2:24 PM John Hubbard wrote: > > On 11/12/19 1:57 PM, Dan Williams wrote: > ... > >> 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); > > > > Hmm, what's the point of passing FOLL_LONGTERM to > > get_user_pages_remote() if get_user_pages_remote() is not going to > > check the vma? I think we got to this code state because the > > FOLL_LONGTERM is short-lived in this location, because patch 23 > ("mm/gup: remove support for gup(FOLL_LONGTERM)") removes it, after > callers are changed over to pin_longterm_pages*(). > > So FOLL_LONGTERM is not doing much now, but it is basically a marker for > "change gup(FOLL_LONGTERM) to pin_longterm_pages()", and patch 18 > actually makes that change. > > And then pin_longterm_pages*() is, in turn, a way to mark all the > places that need file system and/or user space interactions (layout > leases, etc), as per "Case 2: RDMA" in the new > Documentation/vm/pin_user_pages.rst. Ah, sorry. This was the first time I had looked at this series and jumped in without reading the background. Your patch as is looks ok, I assume you've removed the FOLL_LONGTERM warning in get_user_pages_remote in another patch? > > > get_user_pages() vs get_user_pages_remote() split predated the > > introduction of FOLL_LONGTERM. > > Yes. And I do want clean this up as I go, so we don't end up with > stale concepts lingering in gup.c... > > > > > I think check_vma_flags() should do the ((FOLL_LONGTERM | FOLL_GET) && > > vma_is_fsdax()) check and that would also remove the need for > > __gup_longterm_locked. > > > > Good idea, but there is still the call to check_and_migrate_cma_pages(), > inside __gup_longterm_locked(). So it's a little more involved and > we can't trivially delete __gup_longterm_locked() yet, right? [ add Aneesh ] Yes, you're right. I had overlooked that had snuck in there. That to me similarly needs to be pushed down into the core with its own FOLL flag, or it needs to be an explicit fixup that each caller does after get_user_pages. The fact that migration silently happens as a side effect of gup is too magical for my taste.