Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp607832ybt; Fri, 19 Jun 2020 09:13:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwax1d1Dd8wLkpvsw6DbFG57vmBq8YYYnp17FGLyxE3t+LqTJgWS9BdTepWvaY0XoP52FjS X-Received: by 2002:a50:ce45:: with SMTP id k5mr4205518edj.80.1592583237905; Fri, 19 Jun 2020 09:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592583237; cv=none; d=google.com; s=arc-20160816; b=UnPtKSZqIhZQtKVhcR5CAkriT/TvbKdel0+sgtS0PvfAAo89ejF5oo1CDO42wWnio0 KABnPyKIOag06Jb0/DwXNtb3oAY+pciAlPYpNlrzaoclZM6OcXxmVo6qspVHy8VKE+Qu IxKNctdgZTKqs2qXVlYC+Gap51WTxu6u5p++GZMMDUadlhJ1DBa9bRiAcvR5eNsn8FNU cWjuTN2LK/w2UB+hobcoMoaRWaEYjl2IHyp8oTBhlFe7F+XMEB8Y8pylqK+zFIbCFpHQ N8Q+b6JeuQyUYfTXrT4+kFJ5BpvP1FAGR9NBY6LWIB16vIbB98qv0/23qdbjbrBop1zl Ni+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=l5bPDp6tSQ6UB25Tmr+FxCYVIvJPeZJlOAF1u+aQ9Rs=; b=hbkPczmZx/pVOgnsm3NQW92CLUF+anr76y1T/0RNBOS8Us3raoEotCXE1JKUXFedzW y9Ee4t81e51FIgCqVjUGxtAFalB3YJemWbCSHA0ZcaSA9lnSVMjGk1sI+k3VDJL3tB21 xPaMpRK5oZ3WFZ2ML58EzA5gL6uyclfGWf6aTWCXiDCHrTXJ8BmavbCjmJ3eHB6K3eRp Sp3U3dqam93u2CRJH/UxhD/jzhi4ThrflsHHIjPEMIaRyXSzafSFCGoEqAmsh89j0+BZ Croi2iYX87aL/5cIcBfZ3slXZ97oHe1GJs3CLi3niPGr/OX9ouonloFb5Nt6BQUDQSXT +3tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=V1jFXKxH; 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 u22si4185094eds.253.2020.06.19.09.13.34; Fri, 19 Jun 2020 09:13:57 -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=@ffwll.ch header.s=google header.b=V1jFXKxH; 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 S2391398AbgFSPGW (ORCPT + 99 others); Fri, 19 Jun 2020 11:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391420AbgFSPGS (ORCPT ); Fri, 19 Jun 2020 11:06:18 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFF5C0613EE for ; Fri, 19 Jun 2020 08:06:17 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id j189so8688938oih.10 for ; Fri, 19 Jun 2020 08:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=l5bPDp6tSQ6UB25Tmr+FxCYVIvJPeZJlOAF1u+aQ9Rs=; b=V1jFXKxH9JLOzMoiPIzD5AaSDKHq7RFlO6xezDKhJyRYz93hCrYjWgdK7OEyodFwM2 kDzGATay8IHh8e80+mnVWhb8ejljyl7TC9nAm9rnfWCRB2CH7Y5/uH3a16+C1ds/YG6W L2ObS2Ab5ArSWEXfmwsNABGkjrImJGIKuRrck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=l5bPDp6tSQ6UB25Tmr+FxCYVIvJPeZJlOAF1u+aQ9Rs=; b=dRPuXgYB8mI0Ar1uESYOSHf5xC1tdv2/DdEZM+5XZcAFenBcj3GbJrWv/BXgWGJNtZ fXnpUBt/SC1ytfyPEcgAzOrqr2AmQjMhyszo/yAKf8KMTMlo8LISh1BvXSWoTJiqyAcm JMHR/2BbS0SJJfvkP+dtIEP51dmZmRRshNNmBvpNEQNAJDE0BhAXyR3Zza0yH1mDorBT ++yIAigaw9LjLj/Eqd4aE6snQSaE3nw4RSuTcYbvEmgt5D9bhY3syDfQaYXBkjO/83Qp ja6rt4lGWTg7IEzPE/X2OTED13lZGhvdGnjjWOH84Sfy0Qpjqqpwhdg87wGMDWy/JG0a arkg== X-Gm-Message-State: AOAM533FV5xUv82wRqx56EJj9i7ADnDcT080UrO41G2yQCxbkJYP2kFu NTVNK0sKsNSAFJjctgaibQJFHhZw5MGw4XvfuOdLIA== X-Received: by 2002:aca:aaca:: with SMTP id t193mr3427302oie.14.1592579176624; Fri, 19 Jun 2020 08:06:16 -0700 (PDT) MIME-Version: 1.0 References: <20200604081224.863494-5-daniel.vetter@ffwll.ch> <20200611083430.GD20149@phenom.ffwll.local> <20200611141515.GW6578@ziepe.ca> <20200616120719.GL20149@phenom.ffwll.local> <20200617152835.GF6578@ziepe.ca> <20200618150051.GS20149@phenom.ffwll.local> <20200618172338.GM6578@ziepe.ca> <20200619113934.GN6578@ziepe.ca> In-Reply-To: <20200619113934.GN6578@ziepe.ca> From: Daniel Vetter Date: Fri, 19 Jun 2020 17:06:04 +0200 Message-ID: Subject: Re: [Linaro-mm-sig] [PATCH 04/18] dma-fence: prime lockdep annotations To: Jason Gunthorpe Cc: =?UTF-8?Q?Thomas_Hellstr=C3=B6m_=28Intel=29?= , DRI Development , linux-rdma , Intel Graphics Development , Maarten Lankhorst , LKML , amd-gfx list , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Thomas Hellstrom , Daniel Vetter , "open list:DMA BUFFER SHARING FRAMEWORK" , =?UTF-8?Q?Christian_K=C3=B6nig?= , Mika Kuoppala Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 19, 2020 at 1:39 PM Jason Gunthorpe wrote: > > On Fri, Jun 19, 2020 at 09:22:09AM +0200, Daniel Vetter wrote: > > > As I've understood GPU that means you need to show that the commands > > > associated with the buffer have completed. This is all local stuff > > > within the driver, right? Why use fence (other than it already exists= ) > > > > Because that's the end-of-dma thing. And it's cross-driver for the > > above reasons, e.g. > > - device A renders some stuff. Userspace gets dma_fence A out of that > > (well sync_file or one of the other uapi interfaces, but you get the > > idea) > > - userspace (across process or just different driver) issues more > > rendering for device B, which depends upon the rendering done on > > device A. So dma_fence A is an dependency and will block this dma > > operation. Userspace (and the kernel) gets dma_fence B out of this > > - because unfortunate reasons, the same rendering on device B also > > needs a userptr buffer, which means that dma_fence B is also the one > > that the mmu_range_notifier needs to wait on before it can tell core > > mm that it can go ahead and release those pages > > I was afraid you'd say this - this is complete madness for other DMA > devices to borrow the notifier hook of the first device! The first device might not even have a notifier. This is the 2nd device, waiting on a dma_fence of its own, but which happens to be queued up as a dma operation behind something else. > What if the first device is a page faulting device and doesn't call > dma_fence?? Not sure what you mean with this ... even if it does page-faulting for some other reasons, it'll emit a dma_fence which the 2nd device can consume as a dependency. > It you are going to treat things this way then the mmu notifier really > needs to be part of the some core DMA buf, and not randomly sprinkled > in drivers So maybe again unclear, we don't allow such userptr dma-buf to even be shared. They're just for slurping in stuff in the local device (general from file io or something the cpu has done or similar). There have been attempts to use it as the general backing storage, but that didn't go down too well because way too many complications. Generally most memory the gpu operates on isn't stuff that's mmu_notifier'ed. And also, the device with userptr support only waits for its own dma_fence (because well you can't share this stuff, we disallow that). The problem is that there's piles of other dependencies for a dma job. GPU doesn't just consume a single buffer each time, it consumes entire lists of buffers and mixes them all up in funny ways. Some of these buffers are userptr, entirely local to the device. Other buffers are just normal device driver allocations (and managed with some shrinker to keep them in check). And then there's the actually shared dma-buf with other devices. The trouble is that they're all bundled up together. Now we probably should have some helper code for userptr so that all drivers do this roughly the same, but that's just not there yet. But it can't be a dma-buf exporter behind the dma-buf interfaces, because even just pinned get_user_pages would be too different semantics compared to normal shared dma-buf objects, that's all very tightly tied into the specific driver. > But really this is what page pinning is supposed to be used for, the > MM behavior when it blocks on a pinned page is less invasive than if > it stalls inside a mmu notifier. > > You can mix it, use mmu notififers to keep track if the buffer is > still live, but when you want to trigger DMA then pin the pages and > keep them pinned until DMA is done. The pin protects things (well, > fork is still a problem) Hm I thought amdgpu had that (or drm/radeon as the previous incarnation of that stack), and was unhappy about the issues. Would need Christian K=C3=B6nig to chime in. > Do not need to wait on dma_fence in notifiers. Maybe :-) The goal of this series is more to document current rules and make them more consistent. Fixing them if we don't like them might be a follow-up task, but that would likely be a pile more work. First we need to know what the exact shape of the problem even is. -Daniel --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch