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=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 B38E2CA9ECF for ; Mon, 4 Nov 2019 21:15:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89D8F20659 for ; Mon, 4 Nov 2019 21:15:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cdIurt3F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729651AbfKDVP2 (ORCPT ); Mon, 4 Nov 2019 16:15:28 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43000 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729654AbfKDVP1 (ORCPT ); Mon, 4 Nov 2019 16:15:27 -0500 Received: by mail-qt1-f193.google.com with SMTP id t20so10510919qtn.9 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=p+sy3RLrguO/iAy0loO8Fk7G+6uPFXU4ejMf1bB5olUZDoKfY+fD75GgIs8DzV7jTD VY0CvJqtRn6aNqxqy/1yq7J+sfrYqYJCbPxo5bzisBo99ZFY0cFLJBXq+DmSUlncqGW4 1535tqOORffQgNgJ9g4GqD0J/QptQjEw4YEnyquJVJMLT+hu4EeTJgZvkxEqMHBXw3Lw 7AmyyKYRKarrZH6NUjRdRhj2ElKuVxLIbaSgL6TVuT19MVz8vPHeJVRYVdTcSP0D3Xmz qjdlNT/69CcsnOLD9jHheDGqbEnvClpTpzC8G38gr/YEuwbHoOPXplOpr1+j/qpcQfNU 66KA== X-Gm-Message-State: APjAAAU2kYQA7Ar8eEbqkdhcsXLADAf01LoFGSHOqepdFJKD5spe4oAJ v1arn6LADlQ8G9PhxHEMXKJo6w== X-Google-Smtp-Source: APXvYqzMR4jCE1PYixsxB/Gjs6m+eeNvSRexU+WyF4DsIRWaOdmeothP674vqn/aB1paP5wRwlCCGw== 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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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