Received: by 2002:a17:90a:728b:0:0:0:0 with SMTP id e11csp8887005pjg; Fri, 8 May 2020 05:12:58 -0700 (PDT) X-Google-Smtp-Source: APiQypIXYgvfyqwejf3ZY++XtFCp583AB0LjTmUJvmlPbgHiZ9Dp95GQIAVy5lFdmhdJxgz14wWq X-Received: by 2002:aa7:d3cb:: with SMTP id o11mr1788157edr.194.1588939978743; Fri, 08 May 2020 05:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588939978; cv=none; d=google.com; s=arc-20160816; b=gUFRVhcjTUYx+TpxlSg3RDc/z0EhvFdpDe3maXE4Rj5vg6D/krYwubnvlB+g01zTqU mdBWaogxQx7t0rtw5SqRjz6V2QjbO7sXJ5dXugyi2SZWciOsgWLZadd0lS8JiC7/x/+q yqYucU5Rajg7Fj/ISlDB58uTAhUfSOEQOZPq1p/IscgVUALj+xTyTkM2YxeVe5d/hMJ1 F+V3GnwbayCIVjaI6rzBIktfDC27Z+G6nymmIQz09cDFYPeAF0WcwDdD5BpZedxCmJjR 1SZigFVIPMxO+8t5dukbRyAvc/FNwFzZO04XLsWaByMEhZDc1QmEATZ6qj0ZZhcIqBnX 2GVw== 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=T0bwJhmZX5+Xfje3cc7GfqzOVet+PwPBaosSI1LQ/BM=; b=B4kjE9cTYTw4eZxpzo58d4wmVJ/ZgPkzj7cBPG4+y2vjHZ0MGYyYtrhqMreT54J+/t V6TbEuqt8kVGGDs3FWlZX1bQyv7j8/ZO3HseAnP4CcdxNvjwwjcCMItr5Du3E6iReOpU EpaYw/3bPJ3Pc8q/4Vz0ru/sVVCCFfdBdcMGaPrCJ8pSNId1iDSfXbs31HzeTRgnBR4k dolJtKM25w1zPrKyTE6Ab4/zhP+cX0AxUrAq1WYxSxkpMNTkoGWBuC/2j6LFuFEC5+Ly +I4j4ahQKIpECYkmmMkSCjWZDLi73HCL5tm/5CO9RSiU34KwdyPQuuCyAr//gGdLJnfy rUIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=NpVIIqpQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n23si856110edt.420.2020.05.08.05.12.35; Fri, 08 May 2020 05:12:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=NpVIIqpQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbgEHMKQ (ORCPT + 99 others); Fri, 8 May 2020 08:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726767AbgEHMKP (ORCPT ); Fri, 8 May 2020 08:10:15 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66AE6C05BD09 for ; Fri, 8 May 2020 05:10:15 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id c64so1210060qkf.12 for ; Fri, 08 May 2020 05:10:15 -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=T0bwJhmZX5+Xfje3cc7GfqzOVet+PwPBaosSI1LQ/BM=; b=NpVIIqpQIkTIDP4ctgUVLKD/ijmn0VwlHZQutY6d1NaCdjKgqUgZ7epptypxj8UDGq QFGHVukpOl/TDiUhlPgUf5aGx9imCMdwoH2Szuilbt4Tz/byRKkq7okhvL7tXW+wDoGc t9f5GfPEaRxjv70Sl+LHF85Yt6UQTVzd9pK9d5AxfVJ2/M3NR6P/f0+N5ZdeNkuZXtCY +FuVpvcB/Pc1G8TgMsUuugqdxEYBIyTUm2vsvzuO46qw+ksMPUvuC9LYITItdPRTi+tg ZomDEHo/EG3K/4vo4ODKZWTlQ+qxr+2bbQNqGcOJpAU4X8P/50R6hm4qr5uBn2RzMczx RUgA== 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=T0bwJhmZX5+Xfje3cc7GfqzOVet+PwPBaosSI1LQ/BM=; b=Tie3i9/hiaUiUj6xnU1g4UVpNyq20VSe5u2aHvzHcG5ZvZEaAaHlOSgrAy7UOQphWM fGmcugK25g9czwLVWIfdgVcY+Y5iPC5WjlSZ0kNvjvs+wSfc60QH3QUwcA2r/f0LFTzM NGgQnUH6Hdm2LPvQWZ2h8l9sc/8/Ag8YO2wgMiXE8hYsqCBPeX6ii5le3Ue0puJ8Ib6Q gwA8kVFqeuWi/Na+tptcZPBau0NRVZCFiCYIoNi+pNg2/MzFNjrisVFRqByjNk9IuCrJ tQMN98ODntDKtaSgKi0cRechHuCe7oRAmHtCt6AS/l0L8SjotXx+cO3VjeI32Iyyy//T 21pg== X-Gm-Message-State: AGi0PubygMf5lwHCOw4vZV6XNRdWeav4ipGqIC5U/JhF7hSVhhZWmyy1 YUCU0D1K6jpo+dXJi0ASN/WlRQ== X-Received: by 2002:a37:9ec4:: with SMTP id h187mr2479331qke.72.1588939814279; Fri, 08 May 2020 05:10:14 -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 q32sm1311548qta.13.2020.05.08.05.10.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 May 2020 05:10:13 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jX1pV-0003a7-5Z; Fri, 08 May 2020 09:10:13 -0300 Date: Fri, 8 May 2020 09:10:13 -0300 From: Jason Gunthorpe To: Peter Xu Cc: Alex Williamson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, cohuck@redhat.com Subject: Re: [PATCH v2 1/3] vfio/type1: Support faulting PFNMAP vmas Message-ID: <20200508121013.GO26002@ziepe.ca> References: <158871401328.15589.17598154478222071285.stgit@gimli.home> <158871568480.15589.17339878308143043906.stgit@gimli.home> <20200507212443.GO228260@xz-x1> <20200507235421.GK26002@ziepe.ca> <20200508021939.GT228260@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200508021939.GT228260@xz-x1> 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 Thu, May 07, 2020 at 10:19:39PM -0400, Peter Xu wrote: > On Thu, May 07, 2020 at 08:54:21PM -0300, Jason Gunthorpe wrote: > > On Thu, May 07, 2020 at 05:24:43PM -0400, Peter Xu wrote: > > > On Tue, May 05, 2020 at 03:54:44PM -0600, Alex Williamson wrote: > > > > With conversion to follow_pfn(), DMA mapping a PFNMAP range depends on > > > > the range being faulted into the vma. Add support to manually provide > > > > that, in the same way as done on KVM with hva_to_pfn_remapped(). > > > > > > > > Signed-off-by: Alex Williamson > > > > drivers/vfio/vfio_iommu_type1.c | 36 +++++++++++++++++++++++++++++++++--- > > > > 1 file changed, 33 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > > > > index cc1d64765ce7..4a4cb7cd86b2 100644 > > > > +++ b/drivers/vfio/vfio_iommu_type1.c > > > > @@ -317,6 +317,32 @@ static int put_pfn(unsigned long pfn, int prot) > > > > return 0; > > > > } > > > > > > > > +static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, > > > > + unsigned long vaddr, unsigned long *pfn, > > > > + bool write_fault) > > > > +{ > > > > + int ret; > > > > + > > > > + ret = follow_pfn(vma, vaddr, pfn); > > > > + if (ret) { > > > > + bool unlocked = false; > > > > + > > > > + ret = fixup_user_fault(NULL, mm, vaddr, > > > > + FAULT_FLAG_REMOTE | > > > > + (write_fault ? FAULT_FLAG_WRITE : 0), > > > > + &unlocked); > > > > + if (unlocked) > > > > + return -EAGAIN; > > > > > > Hi, Alex, > > > > > > IIUC this retry is not needed too because fixup_user_fault() will guarantee the > > > fault-in is done correctly with the valid PTE as long as ret==0, even if > > > unlocked==true. > > > > It is true, and today it is fine, but be careful when reworking this > > to use notifiers as unlocked also means things like the vma pointer > > are invalidated. > > Oh right, thanks for noticing that. Then we should probably still keep the > retry logic... because otherwise the latter follow_pfn() could be referencing > an invalid vma already... I looked briefly and thought this flow used the vma only once? Jason