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=-5.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,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 7F87AC432C0 for ; Thu, 21 Nov 2019 21:54:51 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2DADC2068E for ; Thu, 21 Nov 2019 21:54:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="KYGZRjKv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DADC2068E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47JtdP4n2szDr72 for ; Fri, 22 Nov 2019 08:54:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nvidia.com (client-ip=216.228.121.143; helo=hqemgate14.nvidia.com; envelope-from=jhubbard@nvidia.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nvidia.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nvidia.com header.i=@nvidia.com header.b="KYGZRjKv"; dkim-atps=neutral Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com [216.228.121.143]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47JtZq4Jf2zDr69 for ; Fri, 22 Nov 2019 08:52:35 +1100 (AEDT) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 21 Nov 2019 13:52:33 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 21 Nov 2019 13:52:30 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 21 Nov 2019 13:52:30 -0800 Received: from [10.2.168.213] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 21 Nov 2019 21:52:28 +0000 Subject: Re: [PATCH v7 09/24] vfio, mm: fix get_user_pages_remote() and FOLL_LONGTERM To: Alex Williamson References: <20191121071354.456618-1-jhubbard@nvidia.com> <20191121071354.456618-10-jhubbard@nvidia.com> <20191121143525.50deb72f@x1.home> From: John Hubbard X-Nvconfidentiality: public Message-ID: Date: Thu, 21 Nov 2019 13:49:40 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191121143525.50deb72f@x1.home> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1574373153; bh=oGhbv3cXo8o4GZ8PnxP5Ux4y8AE3jGJR4EeVDVjoVEc=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=KYGZRjKvtxip9P6ifb3Te8PpgvFSTRruWhwxOgXb0S114oVSZskeO+iOWdCneQvB4 NA5CKwViDqqMCzmcEtuXOzx5kWlGm/CdhdbD7x7k9Kx6Vh5kQFWAggEn8hm5nSetjo GsuEs2bguAasb3kn7+569g/s+OYwxg2N/laFgRqUcYIkUaXO+dKZ1vX7QBvKE7iuhN xdX8E7mSGSvk8taZzTl3l1tHACe5K5QgYBxfNvJAXLPet5p3Tx/OKYiHGukBzXFPA8 pg/kE+aDZRuWuc8KSGeIQ8zVRFi/6q/Cd2RICjjhHLzCf4ZbZMZG9XJoZELTlTOned 7+K+fSUD3HTWw== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Jan Kara , kvm@vger.kernel.org, linux-doc@vger.kernel.org, David Airlie , Dave Chinner , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Paul Mackerras , linux-kselftest@vger.kernel.org, Ira Weiny , Jonathan Corbet , linux-rdma@vger.kernel.org, Christoph Hellwig , Jason Gunthorpe , Jason Gunthorpe , Vlastimil Babka , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , linux-media@vger.kernel.org, Shuah Khan , linux-block@vger.kernel.org, =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Al Viro , Dan Williams , Mauro Carvalho Chehab , bpf@vger.kernel.org, Magnus Karlsson , Jens Axboe , netdev@vger.kernel.org, LKML , Daniel Vetter , linux-fsdevel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S . Miller" , Mike Kravetz Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 11/21/19 1:35 PM, Alex Williamson wrote: > On Wed, 20 Nov 2019 23:13:39 -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. >> >> Reviewed-by: Jason Gunthorpe >> Reviewed-by: Ira Weiny >> Suggested-by: Jason Gunthorpe >> Cc: Dan Williams >> Cc: Jerome Glisse >> Signed-off-by: John Hubbard >> --- >> drivers/vfio/vfio_iommu_type1.c | 30 +++++------------------------- >> mm/gup.c | 27 ++++++++++++++++++++++----- >> 2 files changed, 27 insertions(+), 30 deletions(-) > > Tested with device assignment and Intel mdev vGPU assignment with QEMU > userspace: > > Tested-by: Alex Williamson > Acked-by: Alex Williamson > > Feel free to include for 19/24 as well. Thanks, > > Alex Great! Thanks for the testing and ack on those. I'm about to repackage (and split up as CH requested) for 5.5, and will keep you on CC, of course. thanks, -- John Hubbard NVIDIA