Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1173739ybj; Thu, 7 May 2020 16:56:33 -0700 (PDT) X-Google-Smtp-Source: APiQypLwBv/DkWPEhthObNwAA1D697sTbM1t0RV30qMKuOTVUGFVnaPbKTC8OHrGD6ZmY1YSNVht X-Received: by 2002:a05:6402:3047:: with SMTP id bu7mr14439003edb.303.1588895792924; Thu, 07 May 2020 16:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588895792; cv=none; d=google.com; s=arc-20160816; b=x4c98TU5Fzqg+s98I4kvYrQvfWF0+gnrzMgaTbqJy2mQHkyBOP63qeS7oxzrTAu+tf 0Ag0o3X3AB+/0lS5wI8pg9rloEdHFzsoniVmXZstKkQBPG4Ie3W4YAE8gd189RdgfVmt u7/AHOWt9fYjcD43l3Y31DD66ptP0rtH+uaipJwspcM3J8Od7gH/An9jjwnOwhS9xa+6 wDM9hJPkY50Zg0Y1+lrlcICak2sxjtLFZ4OIZ+54kkjaIXYgzlzbjm3CVwlIgk+ttrD9 NAxjrWGCwBM7qVDHfg6J0Em8DD+7IoiR5497UiIcoedlAN0ja9XYSJtCcXIna6KsmhtU PGBQ== 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=/raYmft6nSaYLNIgpOxoChFcf5nF1Q2ACz6k5lK6B/4=; b=P2/CCQJwaU7lJp4p532/05vVpHKyIYHkHmX90jbUTy3FZmvpS3LQZf72f5r0XyAIb3 aocrH7cynYQ+0WHWF8EuVr8wum1qhPSEGzKGjN5GdZGhPZbf/GQmq24N+8YytOTc4LLe bCB6cBhLp0N3V5Yqwm2EDHyTwiuRUvOwhgoqP+lDww8Ob2jzXfaZf18duKa5obqtD5Si GQ+H4ZnfmIwYR9lhqfmjrA5rlgjvqqZ+VjNhQXZ+Qukb9pFtN6jfdsSfvzunLTrJcexS MDy97NhRod92wwg9+TsqAu2fV5BJS3w3EuRTmAWnaH5ASuqPciL7WDrXCZYxus5DuYBK Cl6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=QSBVJtiY; 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 f8si1453785edk.160.2020.05.07.16.56.09; Thu, 07 May 2020 16:56:32 -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=QSBVJtiY; 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 S1726770AbgEGXy0 (ORCPT + 99 others); Thu, 7 May 2020 19:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726476AbgEGXyZ (ORCPT ); Thu, 7 May 2020 19:54:25 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B4DC05BD43 for ; Thu, 7 May 2020 16:54:24 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id a15so307566qvt.9 for ; Thu, 07 May 2020 16:54:24 -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=/raYmft6nSaYLNIgpOxoChFcf5nF1Q2ACz6k5lK6B/4=; b=QSBVJtiYPNgCyg1Ax8MDmIonk9zKYH0IwrH/+u1j84YGMeisn3e+g5EGfpuObjJv7H wXFl0tfpZnxNnL053pF5sRWfIpTmu9eUL4M/zurqAuPqCZexdEgP1pM2dggKDOZjnEyy f6umf0+v8hfXZ4AZKWQYtiLz6vbcbQ/SZhptvHMrDLwUmI9k8+UWJ8gEEN+lNSZiuSKN rgbjcYlDgqSq19b+5VbYruXqDxWlnvU6ogiMB6YnPypcQltpT5B/nG/bL2YQfDfbt0yM FeKyBoa4zJpeEKZGnc4fSHBnCA/++Yf4pPt5kyhoPiECazyfelAm9wkjL4fNtPGd5gQE 5vUg== 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=/raYmft6nSaYLNIgpOxoChFcf5nF1Q2ACz6k5lK6B/4=; b=GqTfz5JW+jmFBhdDRX+9cgvuEqHFX7Gj1YCbvHiyhlH39a+pmLdA+5wDy9twhT2BoM 3B98aWPi1lgalFWDvUiulpom5fr8q8JpxfMCtD8XyRCYoWIOWVRwreY4w1BnzFYFlhIh GQo0RXTmiezKeq2UEcoFhK7UkbX+IhSZ+27BowduPu4Br2Ies4cF+hmg1kXonfzJiOJV HxteT0tPUBuOIKytMbWU3qmvQrd2xJLeDi+jTYc3H6e9iRc69ucvvsqSOW0xrTxKxaWS bcuLz3mmOh/h7GzNyQk2jWvT3JwrqZW+QceRNfaUY2vg4OjA9f5HA1vpS8uS1KEI5hyb q2Iw== X-Gm-Message-State: AGi0PubQ+l5n/Lm3QiTCO4zGdC+6YQis226b5td0plIaXG7Iv982ESSk 5ABZU98jzaI323N+AOohOo2ubw== X-Received: by 2002:ad4:4966:: with SMTP id p6mr61018qvy.161.1588895663160; Thu, 07 May 2020 16:54:23 -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 j11sm4877452qkk.33.2020.05.07.16.54.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 May 2020 16:54:22 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jWqLN-00070n-OS; Thu, 07 May 2020 20:54:21 -0300 Date: Thu, 7 May 2020 20:54:21 -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: <20200507235421.GK26002@ziepe.ca> References: <158871401328.15589.17598154478222071285.stgit@gimli.home> <158871568480.15589.17339878308143043906.stgit@gimli.home> <20200507212443.GO228260@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507212443.GO228260@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 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. Jason