Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3477969imm; Mon, 13 Aug 2018 12:24:40 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyBC6XifDZttAwZ5Ut4QwFzIA/Bv6T8OncLmSSNmc8jkreOjTsV+W/c+IJFV1WrwxQI/SFa X-Received: by 2002:a62:201b:: with SMTP id g27-v6mr20290822pfg.253.1534188280866; Mon, 13 Aug 2018 12:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534188280; cv=none; d=google.com; s=arc-20160816; b=QXhCsOBJ/L3R0dIVcn+adU1Ctj/IYRMfbkJVottO19SZaWoNbnZjJAFCCUcL7vIRoD X/Nel4ZZAcsd4njGRRXQswACLmCs9mtBm+Qte7dEH6hqCgCmYfgtjdm7+HiRP/VQYMXi Ibh4lTuee1L84WEb5G3Wx/xEfrLkwNcN3xgEsrFzbCdlAwB4QSK5H7QLMWBzx9MyUCOf ip2Kv2BoA7saLu5ry3rg+++lNs0ldMMiid+EOpQTcqGSZLL9DL/n2a/O5dapTOjsxMfo S/Op+73va3S8dVRDy8FA0afLgbYswHzbabtyubKZ7TtXG5VCwst2rDI46l2QXmU/MSoN hvww== 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 :arc-authentication-results; bh=v46Nw/zygPf6Uwhg/JqJbLU40os2wPCLloBuNf8xFy8=; b=0HRvaKTQv3lOsez5Hiu1xqRNtHvp3X8NAL/N1JOaXtfGe4I3NBsrT/Ji1H/K8f8MP3 Kmfc4azvDSseBz20uJya+XiDuCEbUZuT2oS1gxHmon3pLj0dDHGAJ2BSEp1PC7xR6JKm Ms5BgG7+fJIBotVzwG8KYmB0KQhHZ8xCZZ9g3B11gQ2eZ2DdozjA5pbZgoG1bkuz7Si+ NjjfPuO2ECiN1Jw+3yIgyHZJ8Jw8iTO8WnykjbChhHcR/K0IipZANKPv/NczdIVzE6XT EU48bLRYd59vrPRqH9WdPdtyHRm4NBeXyVKaMS98lOYYOJRypwANED7/PvOWorglrtML b+eA== 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 s198-v6si14841340pgc.381.2018.08.13.12.24.25; Mon, 13 Aug 2018 12:24:40 -0700 (PDT) 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 S1730688AbeHMWGl (ORCPT + 99 others); Mon, 13 Aug 2018 18:06:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:32996 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729245AbeHMWGl (ORCPT ); Mon, 13 Aug 2018 18:06:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D0A14023461; Mon, 13 Aug 2018 19:23:05 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.215]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20D072156712; Mon, 13 Aug 2018 19:23:03 +0000 (UTC) Date: Mon, 13 Aug 2018 15:23:01 -0400 From: Jerome Glisse To: Kenneth Lee Cc: Kenneth Lee , Jean-Philippe Brucker , Herbert Xu , "kvm@vger.kernel.org" , Jonathan Corbet , Greg Kroah-Hartman , Zaibo Xu , "linux-doc@vger.kernel.org" , "Kumar, Sanjay K" , "Tian, Kevin" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "linuxarm@huawei.com" , Alex Williamson , "linux-crypto@vger.kernel.org" , Philippe Ombredanne , Thomas Gleixner , Hao Fang , "David S . Miller" , "linux-accelerators@lists.ozlabs.org" Subject: Re: [RFC PATCH 0/7] A General Accelerator Framework, WarpDrive Message-ID: <20180813192301.GC3451@redhat.com> References: <20180806031252.GG91035@Turing-Arch-b> <20180806153257.GB6002@redhat.com> <11bace0e-dc14-5d2c-f65c-25b852f4e9ca@gmail.com> <20180808151835.GA3429@redhat.com> <20180809080352.GI91035@Turing-Arch-b> <20180809144613.GB3386@redhat.com> <20180810033913.GK91035@Turing-Arch-b> <0f6bac9b-8381-1874-9367-46b5f4cef56e@arm.com> <6ea4dcfd-d539-93e4-acf1-d09ea35f0ddc@gmail.com> <20180813092931.GL91035@Turing-Arch-b> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180813092931.GL91035@Turing-Arch-b> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 13 Aug 2018 19:23:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 13 Aug 2018 19:23:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jglisse@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 13, 2018 at 05:29:31PM +0800, Kenneth Lee wrote: > > I made a quick change basing on the RFCv1 here: > > https://github.com/Kenneth-Lee/linux-kernel-warpdrive/commits/warpdrive-v0.6 > > I just made it compilable and not test it yet. But it shows how the idea is > going to be. > > The Pros is: most of the virtual device stuff can be removed. Resource > management is on the openned files only. > > The Cons is: as Jean said, we have to redo something that has been done by VFIO. > These mainly are: > > 1. Track the dma operation and remove them on resource releasing > 2. Pin the memory with gup and do accounting > > It not going to be easy to make a decision... > Maybe it would be good to list things you want do. Looking at your tree it seems you are re-inventing what dma-buf is already doing. So here is what i understand for SVM/SVA: (1) allow userspace to create a command buffer for a device and bind it to its address space (PASID) (2) allow userspace to directly schedule commands on its command buffer No need to do tracking here as SVM/SVA which rely on PASID and something like PCIE ATS (address translation service). Userspace can shoot itself in the foot but nothing harmful can happen. Non SVM/SVA: (3) allow userspace to wrap a region of its memory into an object so that it can be DMA map (ie GUP + dma_map_page()) (4) Have userspace schedule command referencing object created in (3) using an ioctl. We need to keep track of object usage by the hardware so that we know when it is safe to release resources (dma_unmap_page()). The dma-buf provides everything you want for (3) and (4). With dma-buf you create object and each time it is use by a device you associate a fence with it. When fence is signaled it means that the hardware is done using that object. Fence also allow proper synchronization between multiple devices. For instance making sure that the second device wait for the first device before starting doing its thing. dma-buf documentations is much more thorough explaining all this. Now from implementation point of view, maybe it would be a good idea to create something like the virtual gem driver. It is a virtual device that allow to create GEM object. So maybe we want a virtual device that allow to create dma-buf object from process memory and allow sharing of those dma-buf between multiple devices. Userspace would only have to talk to this virtual device to create object and wrap its memory around, then it could use this object against many actual devices. This decouples the memory management, that can be share between all devices, from the actual device driver, which is obviously specific to every single device. Note that dma-buf use file so that once all file reference are gone the resource can be free and cleanup can happen (dma_unmap_page() ...). This properly handle the resource lifetime issue you seem to worried about. Cheers, J?r?me