Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5097967imu; Tue, 29 Jan 2019 12:44:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN6NYxmOS7jjIJSxGeCXp8do9Y/atmRohzpIOrfmmx4FFLWLLshqFttThLvCvMmHLlf6Ixlk X-Received: by 2002:a17:902:622:: with SMTP id 31mr27020105plg.171.1548794691456; Tue, 29 Jan 2019 12:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548794691; cv=none; d=google.com; s=arc-20160816; b=IZ9ylL4M4is2LTtWevgw3J+PZq26Wk8Kp25aGdvhnrEoCAS6JZHBBcIx9AlG89+gFs 82DVNq7Gvbmk5kmhZJ0KrIFKwc8VyKqDPJpNNmIXo2H5hzFPb2/byfar9NFg7NHnK053 wWx9R55dJG7imk2tRA6eoBsAGFmlHYdp5Prw9kPJjkp0BZyKB7qY1cm6owGNKMvkdz+9 bOQe1YC5bx+tFnrok+iZ4KW0W2oSlA1HG4wbQnTLIWasXDqPjREUI4xW5k4ST/BDMXdJ tDY4Z2l3/HIPKb72Fk+XNqUxIXX9QP5o2vnY7aLzWCRzTG9H/yXTEiZyo/VTwrDmcBfb VSVg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Qm6F6LIQzbfAPKu+FJsQKTjSZW7u/O5X81/WBnpGURM=; b=UzDKgfMsBrHf725WJuMj94NYNVkypR6MMsNuneD1fjsyUXF5azMZA0gxvaqbIjAdos vb/KakhemScsXdVNlYjULZ8TetlTxZ2hYxWpN1nAEmt+0mGDuQNTOPE3wf8a9xIPlnj/ PjWKLn/cIaZWK/Mobjxbqd2LvJcg7rZM5s7uSKU93wZPqhiXwSnDkOtyP1E9WD3UVMbF vPlHnHM+iehJSEkqxXV4RM/VhuWIkJOmex1X4NECuc/+0NKDQxzO0MtsikgHO2koLoX/ 1/qbCadyvd/V2em4EYM8Y5McIrwKBhEqhlgKbJfjQ0OIgitsUb4V1ATdPfdumIx0t5gf +Ldg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si36335904pfe.159.2019.01.29.12.44.35; Tue, 29 Jan 2019 12:44:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729481AbfA2UoH (ORCPT + 99 others); Tue, 29 Jan 2019 15:44:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46970 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726945AbfA2UoG (ORCPT ); Tue, 29 Jan 2019 15:44:06 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BCDF80503; Tue, 29 Jan 2019 20:44:05 +0000 (UTC) Received: from redhat.com (ovpn-122-2.rdu2.redhat.com [10.10.122.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 598275F7C2; Tue, 29 Jan 2019 20:44:02 +0000 (UTC) Date: Tue, 29 Jan 2019 15:44:00 -0500 From: Jerome Glisse To: Jason Gunthorpe Cc: Logan Gunthorpe , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , "Rafael J . Wysocki" , Bjorn Helgaas , Christian Koenig , Felix Kuehling , "linux-pci@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Joerg Roedel , "iommu@lists.linux-foundation.org" Subject: Re: [RFC PATCH 3/5] mm/vma: add support for peer to peer to device vma Message-ID: <20190129204359.GM3176@redhat.com> References: <20190129174728.6430-1-jglisse@redhat.com> <20190129174728.6430-4-jglisse@redhat.com> <20190129191120.GE3176@redhat.com> <20190129193250.GK10108@mellanox.com> <20190129195055.GH3176@redhat.com> <20190129202429.GL10108@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190129202429.GL10108@mellanox.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 29 Jan 2019 20:44:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 29, 2019 at 08:24:36PM +0000, Jason Gunthorpe wrote: > On Tue, Jan 29, 2019 at 02:50:55PM -0500, Jerome Glisse wrote: > > > GPU driver do want more control :) GPU driver are moving things around > > all the time and they have more memory than bar space (on newer platform > > AMD GPU do resize the bar but it is not the rule for all GPUs). So > > GPU driver do actualy manage their BAR address space and they map and > > unmap thing there. They can not allow someone to just pin stuff there > > randomly or this would disrupt their regular work flow. Hence they need > > control and they might implement threshold for instance if they have > > more than N pages of bar space map for peer to peer then they can decide > > to fall back to main memory for any new peer mapping. > > But this API doesn't seem to offer any control - I thought that > control was all coming from the mm/hmm notifiers triggering p2p_unmaps? The control is within the driver implementation of those callbacks. So driver implementation can refuse to map by returning an error on p2p_map or it can decide to use main memory by migrating its object to main memory and populating the dma address array with dma_page_map() of the main memory pages. Driver like GPU can have policy on top of that for instance they will only allow p2p map to succeed for objects that have been tagged by the userspace in some way ie the userspace application is in control of what can be map to peer device. This is needed for GPU driver as we do want userspace involvement on what object are allowed to have p2p access and also so that we can report to userspace when we are running out of BAR addresses for this to work as intended (ie not falling back to main memory) so that application can take appropriate actions (like decide what to prioritize). For moving things around after a successful p2p_map yes the exporting device have to call for instance zap_vma_ptes() or something similar. This will trigger notifier call and the importing device will invalidate its mapping. Once it is invalidated then the exporting device can point new call of p2p_map (for the same range) to new memory (obviously the exporting device have to synchronize any concurrent call to p2p_map with the invalidation). > > I would think that the importing driver can assume the BAR page is > kept alive until it calls unmap (presumably triggered by notifiers)? > > ie the exporting driver sees the BAR page as pinned until unmap. The intention with this patchset is that it is not pin ie the importer device _must_ abide by all mmu notifier invalidations and they can happen at anytime. The importing device can however re-p2p_map the same range after an invalidation. I would like to restrict this to importer that can invalidate for now because i believe all the first device to use can support the invalidation. Also when using HMM private device memory we _can not_ pin virtual address to device memory as otherwise CPU access would have to SIGBUS or SEGFAULT and we do not want that. So this was also a motivation to keep thing consistent for the importer for both cases. Cheers, J?r?me