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 B3348C83000 for ; Tue, 28 Apr 2020 19:22:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 686E82070B for ; Tue, 28 Apr 2020 19:22:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="IaqMz7fb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 686E82070B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F296D8E0007; Tue, 28 Apr 2020 15:22:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDA8C8E0001; Tue, 28 Apr 2020 15:22:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9778E0007; Tue, 28 Apr 2020 15:22:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id C24DD8E0001 for ; Tue, 28 Apr 2020 15:22:54 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 81175180AD807 for ; Tue, 28 Apr 2020 19:22:54 +0000 (UTC) X-FDA: 76758236268.23.group38_709f42312bc43 X-HE-Tag: group38_709f42312bc43 X-Filterd-Recvd-Size: 6778 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Apr 2020 19:22:53 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id c23so17773236qtp.11 for ; Tue, 28 Apr 2020 12:22:53 -0700 (PDT) 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=PYh9xmPfS312gCXfdzhUhHbtCQqRUOprLrWe8CN4KOQ=; b=IaqMz7fb472+OlDu/UtAPP5H+bEwqwBkv7FKc1L94GjxtlTO3HofyKc3+k1PZRn2CE u5u0gaOk6CTvlgtWoV7WkcLyMMWDDByJBX4+NBa/Ai+qIDx7ptplcsoNv6n0RXW5cKHJ BpT/G6Ytr6MOwdAqTxCSknBOIuGx2K1nQzIu/26RuQIn2q2CixGKNAQWHO9HC+kIJ6en DjH++ipC58RYznVw+z6+Qeo6pojXT67RWJXt/q/mlHe+2BYA+Hgz5SAqDwMVQW6yvgmw 1EZWfWjkNAHYJpyVl8SMlzBYUVyidDpy+cz9e/t0fQiAVMVH+LsFkfRWZ/6+W/TPuCGL mdNg== 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=PYh9xmPfS312gCXfdzhUhHbtCQqRUOprLrWe8CN4KOQ=; b=lXxWbhrwa31ki/DNpZjYjRacdZl/YZ5Dof/LTqq5ASw7r2ZrxjJed4N8bLOJMSD6EF NHEdznKYRAsa7rY2C+d+P+7B6PJ/TddsF/bWDpgjqwWct+vCPyLHKT1ruyLu3wV0wRTO GISBFYD9vDQvJ125BKqIiI03mXbrPHekXL5Il/puZez7xKxx/aDrI8XHUe3jZNP62qYo wj1vIMNscx6by3ImS6IsTUuOWLXGO4nMK2mC2lQqfrA9wOyvIFL71vbL7M1syNGVX0/G SwUATDfvoQ0NsOnGEXh6W2F7tv0T9/X3XbJ+2MSgTenCMeO+sMcZ57iP4BWPeEfeVxJQ JIpw== X-Gm-Message-State: AGi0PuZrjwPqNNpDBe3BU+S3F8AG0Q9Wa6+E4G6YqzA+g3WKIi9XckCK 8ouc4e3Vx8BvLYodcHwLyBoOeA== X-Google-Smtp-Source: APiQypIm2iy0fehpUXGvgzCJ3YVuZRDehWEKh6i0g/stChUO8xvKnvqB7LdZZZ9J+nCT5SrC5sQ09A== X-Received: by 2002:ac8:2fda:: with SMTP id m26mr29942561qta.80.1588101773137; Tue, 28 Apr 2020 12:22:53 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id j92sm14236451qtd.58.2020.04.28.12.22.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Apr 2020 12:22:52 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jTVoh-00070x-RA; Tue, 28 Apr 2020 16:22:51 -0300 Date: Tue, 28 Apr 2020 16:22:51 -0300 From: Jason Gunthorpe To: Alex Williamson Cc: John Hubbard , LKML , Andrew Morton , Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jonathan Corbet , =?utf-8?B?SsOpcsO0bWU=?= Glisse , "Kirill A . Shutemov" , Michal Hocko , Mike Kravetz , Shuah Khan , Vlastimil Babka , Matthew Wilcox , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rdma@vger.kernel.org, linux-mm@kvack.org, "Kirill A . Shutemov" Subject: Re: [regression?] Re: [PATCH v6 06/12] mm/gup: track FOLL_PIN pages Message-ID: <20200428192251.GW26002@ziepe.ca> References: <20200211001536.1027652-1-jhubbard@nvidia.com> <20200211001536.1027652-7-jhubbard@nvidia.com> <20200424121846.5ee2685f@w520.home> <5b901542-d949-8d7e-89c7-f8d5ee20f6e9@nvidia.com> <20200424141548.5afdd2bb@w520.home> <665ffb48-d498-90f4-f945-997a922fc370@nvidia.com> <20200428105455.30343fb4@w520.home> <20200428174957.GV26002@ziepe.ca> <20200428130752.75c153bd@w520.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200428130752.75c153bd@w520.home> User-Agent: Mutt/1.9.4 (2018-02-28) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Apr 28, 2020 at 01:07:52PM -0600, Alex Williamson wrote: > On Tue, 28 Apr 2020 14:49:57 -0300 > Jason Gunthorpe wrote: > > > On Tue, Apr 28, 2020 at 10:54:55AM -0600, Alex Williamson wrote: > > > static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) > > > { > > > struct vfio_pci_device *vdev = device_data; > > > @@ -1253,8 +1323,14 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) > > > vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); > > > vma->vm_pgoff = (pci_resource_start(pdev, index) >> PAGE_SHIFT) + pgoff; > > > > > > + vma->vm_ops = &vfio_pci_mmap_ops; > > > + > > > +#if 1 > > > + return 0; > > > +#else > > > return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, > > > - req_len, vma->vm_page_prot); > > > + vma->vm_end - vma->vm_start, vma->vm_page_prot); > > > > The remap_pfn_range here is what tells get_user_pages this is a > > non-struct page mapping: > > > > vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; > > > > Which has to be set when the VMA is created, they shouldn't be > > modified during fault. > > Aha, thanks Jason! So fundamentally, pin_user_pages_remote() should > never have been faulting in this vma since the pages are non-struct > page backed. gup should not try to pin them.. I think the VM will still call fault though, not sure from memory? > Maybe I was just getting lucky before this commit. For a > VM_PFNMAP, vaddr_get_pfn() only needs pin_user_pages_remote() to return > error and the vma information that we setup in vfio_pci_mmap(). I've written on this before, vfio should not be passing pages to the iommu that it cannot pin eg it should not touch VM_PFNMAP vma's in the first place. It is a use-after-free security issue the way it is.. > only need the fault handler to trigger for user access, which is what I > see with this change. That should work for me. > > > Also the vma code above looked a little strange to me, if you do send > > something like this cc me and I can look at it. I did some work like > > this for rdma a while ago.. > > Cool, I'll do that. I'd like to be able to zap the vmas from user > access at a later point and I have doubts that I'm holding the > refs/locks that I need to for that. Thanks, Check rdma_umap_ops, it does what you described (actually it replaces them with 0 page, but along the way it zaps too). Jason