Received: by 2002:a17:90a:728b:0:0:0:0 with SMTP id e11csp8885345pjg; Fri, 8 May 2020 05:11:17 -0700 (PDT) X-Google-Smtp-Source: APiQypJQnBuAX09DWTcnXHNxlpL06WwgTEQnRosZWIPeTCG8txIcpQNR8tDmsnSHs5B/ZhNzkiHO X-Received: by 2002:a17:906:4903:: with SMTP id b3mr1553777ejq.80.1588939877198; Fri, 08 May 2020 05:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588939877; cv=none; d=google.com; s=arc-20160816; b=oc7AOSZhmp7lQ8z3PoQ9CSAQUry6bEx1QUVIDG33BKr1TompjpbKzuwruHLVMQxkFf i7wo6rXLzvL/ir5/EBWXyLwetjQWY/BRTXEnNoTcIv2RI1p8WQOaGl2APz4ccNTyVDOg UCuUpOG/uWg8JCqybeqzabyvBXCuSFyadDuYOmUFUZi4T7uvHYvdmRX5D8oLR8D1JORm J5VuHgMpTZeAmLms/ToAn7dSJsckGJWP3v7vpqfE9iTuH2f6n3+NFCcQz2yJVQGvdzm/ Lv9LnGRM4zISra99xS4Q19UncP17kBKmjhVP0axFzeaVgrsiUBVMnY60AbaoHbeMp8Ra DMLw== 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=jNcOJdj0FMsiZ/cz6XctSErT2eXavWVo0wmEW9tkg9M=; b=0Cpy3+UjhOHS5gB40+mFR6JCltT+YXz855j/zltZSyiLdO9pMhS/1uk2irbQCAs+hk A5ahaqgpn29MByRmHE/8mwnVLgn17kz/GmWWkR++k5zknOXvU/i+r4lNGVLrd0H3eF8B ziqhKn8qr+BvOs3jhw/aR4OPWHqiaMji9IWi9l6OKjgIynSSDSahVR95SwpurlEPM+B1 Dxc5KJp0x/kp6HGq63axvHFYQZVphE/+Yu6TybrTXhF+GDgJTyZOWUUUDoTwU36qwxFE 6wULSJHriDvr6hKRjmx5aSvKz8zSOrvIcJYyKMZd8J4iJiZNzDtNsaLmg2Md98ixjos/ ZwlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=fOMZJstT; 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 f17si871296ejx.11.2020.05.08.05.10.53; Fri, 08 May 2020 05:11:17 -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=fOMZJstT; 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 S1727119AbgEHMIE (ORCPT + 99 others); Fri, 8 May 2020 08:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726701AbgEHMID (ORCPT ); Fri, 8 May 2020 08:08:03 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70780C05BD09 for ; Fri, 8 May 2020 05:08:03 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id h26so979021qtu.8 for ; Fri, 08 May 2020 05:08:03 -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=jNcOJdj0FMsiZ/cz6XctSErT2eXavWVo0wmEW9tkg9M=; b=fOMZJstT2RX/AhoKfmsee3tP8RBwx6fgcky3Oxy2XCpR2wyYS1EN/nFjW0Tl68c4TD nNIwZs4awDPpb4PDBSsopqtK3+4peg+9piOjTodwwsZdQVFEe6M2yK1bop1RQdHisLOg JmENbj6q6f/y1kBXv9XnsnqCNgg0gI8itmOmk7PWYcbIOi/aJgH3qlf3btCcNLQOOZeB OLeLiJiB6KzK0nmW82mL9ijXOtXT1i+RHQ9fn1hhR61LtwFSLKUasqzYwrQk0CaCyt5r oWr9CozcTpX0YZzrmJkCD1X0r28l/mRCuXPzS555GQLfctnJfsZBRc0hl8chhDph7Kaj z2vA== 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=jNcOJdj0FMsiZ/cz6XctSErT2eXavWVo0wmEW9tkg9M=; b=iQbv6HNOLTfcDClXMwPdf/+5+smLOpkvHu+jKvhdQ0xtCez9BoCOW4Yi0H6Sys8Wf6 6SxeezLiuzioeql7Y836sWzY93poQVgDKmvYarhkrtL/LCVP0LfTujf/ld8JP9PeFuU4 tAxVpxS3Z9oYbVaoJlbWw6LLec5Gp7+IDjvOiaxIe5OPTaB5nL4EskfU8tEP81d3g5Vg L3Y9+2GP+6Ak+fZtXDQiBr5HCqU0PY4vdzxdQcaMUtDK+GgSj2xeOZ041m7JCTZ0YBAP L0EvU9U94Fg6J1+1cSvn5NCKk2r/Kr8KGjuDL1lHGGjc2Mfv+B/8Vtgu4Nw2PREdeXVK GWpQ== X-Gm-Message-State: AGi0PuZWBqCZFYexFIJqS1rFjlyRx4yILQ2ljUABcxd7dsVT1NJQhN/q 1P0GCqN2r0lBasbZ6PTaiMOF4A== X-Received: by 2002:ac8:7942:: with SMTP id r2mr2764437qtt.288.1588939682425; Fri, 08 May 2020 05:08:02 -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 x19sm965232qkb.136.2020.05.08.05.08.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 May 2020 05:08:01 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jX1nN-0003Yl-5m; Fri, 08 May 2020 09:08:01 -0300 Date: Fri, 8 May 2020 09:08:01 -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 2/3] vfio-pci: Fault mmaps to enable vma tracking Message-ID: <20200508120801.GN26002@ziepe.ca> References: <158871401328.15589.17598154478222071285.stgit@gimli.home> <158871569380.15589.16950418949340311053.stgit@gimli.home> <20200507214744.GP228260@xz-x1> <20200507160334.4c029518@x1.home> <20200507222223.GR228260@xz-x1> <20200507235633.GL26002@ziepe.ca> <20200508021656.GS228260@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200508021656.GS228260@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:16:56PM -0400, Peter Xu wrote: > On Thu, May 07, 2020 at 08:56:33PM -0300, Jason Gunthorpe wrote: > > On Thu, May 07, 2020 at 06:22:23PM -0400, Peter Xu wrote: > > > On Thu, May 07, 2020 at 04:03:34PM -0600, Alex Williamson wrote: > > > > On Thu, 7 May 2020 17:47:44 -0400 > > > > Peter Xu wrote: > > > > > > > > > Hi, Alex, > > > > > > > > > > On Tue, May 05, 2020 at 03:54:53PM -0600, Alex Williamson wrote: > > > > > > +/* > > > > > > + * Zap mmaps on open so that we can fault them in on access and therefore > > > > > > + * our vma_list only tracks mappings accessed since last zap. > > > > > > + */ > > > > > > +static void vfio_pci_mmap_open(struct vm_area_struct *vma) > > > > > > +{ > > > > > > + zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); > > > > > > > > > > A pure question: is this only a safety-belt or it is required in some known > > > > > scenarios? > > > > > > > > It's not required. I originally did this so that I'm not allocating a > > > > vma_list entry in a path where I can't return error, but as Jason > > > > suggested I could zap here only in the case that I do encounter that > > > > allocation fault. However I still like consolidating the vma_list > > > > handling to the vm_ops .fault and .close callbacks and potentially we > > > > reduce the zap latency by keeping the vma_list to actual users, which > > > > we'll get to eventually anyway in the VM case as memory BARs are sized > > > > and assigned addresses. > > > > > > Yes, I don't see much problem either on doing the vma_list maintainance only in > > > .fault() and .close(). My understandingg is that the worst case is the perf > > > critical applications (e.g. DPDK) could pre-fault these MMIO region easily > > > during setup if they want. My question was majorly about whether the vma > > > should be guaranteed to have no mapping at all when .open() is called. But I > > > agree with you that it's always good to have that as safety-belt anyways. > > > > If the VMA has a mapping then that specific VMA has to be in the > > linked list. > > > > So if the zap is skipped then the you have to allocate something and > > add to the linked list to track the VMA with mapping. > > > > It is not a 'safety belt' > > But shouldn't open() only be called when the VMA is created for a memory range? > If so, does it also mean that the address range must have not been mapped yet? open is called whenever a VMA is copied, I don't think it is called when the VMA is first created? Jason