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.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 6E7BDC33C9E for ; Thu, 21 Nov 2019 21:52:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44EE42067D for ; Thu, 21 Nov 2019 21:52:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="KYGZRjKv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726546AbfKUVwb (ORCPT ); Thu, 21 Nov 2019 16:52:31 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:12745 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726297AbfKUVwb (ORCPT ); Thu, 21 Nov 2019 16:52:31 -0500 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 CC: Andrew Morton , Al Viro , Benjamin Herrenschmidt , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Christoph Hellwig , Dan Williams , 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 , , , , , , , , , , , , , LKML , Jason Gunthorpe 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== Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 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