Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4434546ybx; Mon, 4 Nov 2019 13:19:29 -0800 (PST) X-Google-Smtp-Source: APXvYqxpCCu5ZiwbcCYwKvhqJP96XG8hvpN+Ps21A7lds6Gtg17xdj7mk5ZUcl85i6qUC6ygEmN0 X-Received: by 2002:a17:906:3458:: with SMTP id d24mr11407207ejb.271.1572902368923; Mon, 04 Nov 2019 13:19:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572902368; cv=none; d=google.com; s=arc-20160816; b=iNuFMNzGgNPlLidytJbTe+YhFDg4Q/o0/09mEhhF4bx67VC8Pm7Cs+nJBmVxOnc3RA 9XR3oyjwH5Uiuz2NC7A70h0VfhitZ2LiOgJLdCgf/DAjgXCyvLfxUHWH5RbNJFydcf3d lpjm8tedNTmeYoEMc34FUmx7j1VHEHmVNkCalIYGHmTsPx3ccy7bxFJC81N8/hD71HxK CqEjrHVh+LuN4X8C7DttTRBRGgl6Gpnylt4dQpUdtr7GXkJg0sjy/OqLRqlkEo2jVn0q XkIiHKpRnbIBtvyTHhox4KHRQrPfNDF9cM5TT8sVFaYNKgJ3VzPM2PILeQdDz0PHmPKF W9Tw== 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=pyXNiCRfNtBczIIqZ12Au+Ud6Z68623cr8kr//yYcys=; b=BBL3oPFWmWNbdtLkaOnT9/BE5TFKLZjaoES5DgNnlacjUlI5i2DkftRh3eUVfWw+/G GoofCi2NM8kmG1jy1BoZsHPJdFGo605zEHuOk6OGiSu5lyyfe08l3DjPx343bDsuBcld xqA5gLJ7YRchIrQu69krpi86w9RwxmNHHPZ73f3Jb4TfPcn0BNXKrj9SseOmKPXgYZ3o 0TvrEE/ejBO1sMY3TPv4Cep/s1EKEAeBoCiHn26EFnVkN2vCk6EB/E/88R6zDeo5zTIT Tsj0BTSn6BlYNe3fcmUfRhoOwQS2HxDQrFoineSagme1xy73B6/huuzOTqrM1s8Af+4p FBRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=cdIurt3F; 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 m45si8276085edc.153.2019.11.04.13.19.05; Mon, 04 Nov 2019 13:19:28 -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=cdIurt3F; 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 S1729690AbfKDVP2 (ORCPT + 99 others); Mon, 4 Nov 2019 16:15:28 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:34965 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbfKDVP1 (ORCPT ); Mon, 4 Nov 2019 16:15:27 -0500 Received: by mail-qt1-f194.google.com with SMTP id r22so16092511qtt.2 for ; Mon, 04 Nov 2019 13:15:26 -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=pyXNiCRfNtBczIIqZ12Au+Ud6Z68623cr8kr//yYcys=; b=cdIurt3FoLPTZlK0pRWkw6/vK5VskqT2SbrzmEIJH+tJ6Ws9V4Lsgf9USo2+e2ozUc YRC+b39mpReZt55//saai5UbNMBA3eXwOqYLQtfunIkTwkfTlIfn1eXp2VeIe1/orkPr PDVNDgKxGvEW8/cTzBHwWhOs6aaLwvdAp8wwJznhpYiyIH9szefozZKp8Gp400JqPNGU fTr/7Xjau32owsZ9g3acr0XI1ZTN6RVvcZ58S7ZMFunV92cxFdu7JBWTybRQM5KPfcgD VnxEWZzKOSsxfKO36w3EM6M1OhrZPi8fZFAK54K+pX7TtJSCqY3tKZTOVsHNgsvdV+dl 4NyA== 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=pyXNiCRfNtBczIIqZ12Au+Ud6Z68623cr8kr//yYcys=; b=rxYHH1eutE+/D1ma/g0cFKbeyBPhKGjCw3zCeioz4OMhYec3Af+EO715xN7hdYaXoA 0w+/Qi+m1z7ui1mpNOUzk65Jt0UKzDh9S3/Hxe6XkGcTYd43OwCVfPmm16WY0IHyG53p zsb93D58B1sx18q8v5uhjoQ9MxO+WxiiT0DqCBNA49RMIXnGYAoYepAx7jesEpZVI9GP ph3T2LzkWsjWGyxDSwpTJ/GhxTmXFlUsCcyg68jy380PrAAt9pg9ifTgqD2eBRxFB+VG Ug/9ox+vAmnL+Bxj3St/5/SH6nr/ApECdUdF9comdES5FTzl/eFr6KAcu9IlXPHctYq6 9sJw== X-Gm-Message-State: APjAAAXikDHlLzQ8GzYgEu4eotxOENobrIHMu28QCfdgv/UsQp6GAe+y DtSTOa+P0YBC4RZNueIF+j72ng== X-Received: by 2002:ac8:3a21:: with SMTP id w30mr14733201qte.299.1572902126035; Mon, 04 Nov 2019 13:15:26 -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 q1sm6459892qti.46.2019.11.04.13.15.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Nov 2019 13:15:25 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iRjh7-0000mG-3H; Mon, 04 Nov 2019 17:15:25 -0400 Date: Mon, 4 Nov 2019 17:15:25 -0400 From: Jason Gunthorpe To: John Hubbard Cc: Jerome Glisse , 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 , 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 v2 05/18] mm/gup: introduce pin_user_pages*() and FOLL_PIN Message-ID: <20191104211525.GJ30938@ziepe.ca> References: <20191103211813.213227-6-jhubbard@nvidia.com> <20191104173325.GD5134@redhat.com> <20191104191811.GI5134@redhat.com> <20191104195248.GA7731@redhat.com> <25ec4bc0-caaa-2a01-2ae7-2d79663a40e1@nvidia.com> <20191104203153.GB7731@redhat.com> <20191104203702.GG30938@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon, Nov 04, 2019 at 12:57:59PM -0800, John Hubbard wrote: > On 11/4/19 12:37 PM, Jason Gunthorpe wrote: > > On Mon, Nov 04, 2019 at 03:31:53PM -0500, Jerome Glisse wrote: > >>> Note for Jason: the (a) or (b) items are talking about the vfio case, which is > >>> one of the two call sites that now use pin_longterm_pages_remote(), and the > >>> other one is infiniband: > >>> > >>> drivers/infiniband/core/umem_odp.c:646: npages = pin_longterm_pages_remote(owning_process, owning_mm, > >>> drivers/vfio/vfio_iommu_type1.c:353: ret = pin_longterm_pages_remote(NULL, mm, vaddr, 1, > >> > >> vfio should be reverted until it can be properly implemented. > >> The issue is that when you fix the implementation you might > >> break vfio existing user and thus regress the kernel from user > >> point of view. So i rather have the change to vfio reverted, > >> i believe it was not well understood when it got upstream, > >> between in my 5.4 tree it is still gup_remote not longterm. > > > > It is clearly a bug, vfio must use LONGTERM, and does right above this > > remote call: > > > > 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); > > > > > > I'm not even sure that it really makes any sense to build a 'if' like > > that, surely just always call remote?? > > > > > Right, and I thought about this when converting, and realized that the above > code is working around the current gup.c limitations, which are "cannot support > gup remote with FOLL_LONGTERM". But AFAICT it doesn't have a problem, the protection test is just too strict, and I guess the control flow needs a bit of fixing.. The issue is this: static __always_inline long __get_user_pages_locked(): { if (locked) { /* if VM_FAULT_RETRY can be returned, vmas become invalid */ BUG_ON(vmas); /* check caller initialized locked */ BUG_ON(*locked != 1); } so remote could be written as: if (gup_flags & FOLL_LONGTERM) { if (WARN_ON_ONCE(locked)) return -EINVAL; return __gup_longterm_locked(...) } return __get_user_pages_locked(...) ?? Jason