Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp518765pxk; Thu, 17 Sep 2020 08:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyjVAjI20VGxoGqgSuzUOjKMUz4fZ8PiDlo212C8zEuPagxodUDejxGl9RX1WYOzf5I027 X-Received: by 2002:aa7:d458:: with SMTP id q24mr34387066edr.23.1600358374856; Thu, 17 Sep 2020 08:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600358374; cv=none; d=google.com; s=arc-20160816; b=i6q9smJC0k7ppHf0020YNjJZCDrWBVYnoGfVEjPKqTf5iKIFNn+A/erA428almJaTp vH2DE9eR/lItDrrHtuGESmS9ePi4D5nDjzSFgHH0TDl/d2Dmfys1AExvcBweTso8s2NZ uH5xQKvq6wfJtx4hXj7fA6W/PGerUXmJnAyFAwQcBzKa4ld8hT7+wIEgVR1LTkyhgVjV ByFh/3RFZ1eZXvQWUGl/owcicDJz36blyCNlLvhAV+daEuAzANZY4ChhQh7Z2ruyjc2k 8To6ZfrOew4dEf8hmeT1RPc2FfMkQmdU16or5hdy9S41Fn7QPztZrjRhyS3bZJYQDj90 oK8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZKdwGNTuB7raHchRws1uZpYC5kiBgIgkW7sRbNdes8U=; b=wsKI/PNdEZD851gzAcagvXUaz4w3IJHjV24RO/2bW/hHC0AZY/mScL5UxKFXkfrshv SxZ2j//l9Cy4wQUtTfoP7+uJszMfFrx8XuLklagQ1k1f1xA5YTZSZIKrOoP1gSlANdgm 4exo/jBSYvsgDDxwu0xHPTQUnsq/YBP2rJLiFHXhCyLpH9jp9jX29T+Lt5wOjWv0kAfy oG8B9kdwYqP2ees3Va1KMLTX7Fa1ZRV/51iL1cJugmOHEM3QawIHmk1q90XEcURv5yN6 pLAhMwYlOVfJFuBZADIDXjGFa7dOkUTJ/n2Q+MLxQrD6906PFiGayUZTu5GUf6GqToiq MTyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=ISCJ5Tw6; 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 w6si54438edu.88.2020.09.17.08.59.04; Thu, 17 Sep 2020 08:59:34 -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=ISCJ5Tw6; 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 S1728163AbgIQPux (ORCPT + 99 others); Thu, 17 Sep 2020 11:50:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbgIQPsh (ORCPT ); Thu, 17 Sep 2020 11:48:37 -0400 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8966FC06178B for ; Thu, 17 Sep 2020 08:37:14 -0700 (PDT) Received: by mail-ot1-x344.google.com with SMTP id e23so2292736otk.7 for ; Thu, 17 Sep 2020 08:37:14 -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=ZKdwGNTuB7raHchRws1uZpYC5kiBgIgkW7sRbNdes8U=; b=ISCJ5Tw66UvgaeWJoGMvoGpBgdi+Pvh73WzxPCKZycvbr4Kw5zYOwmcCQjHLfF+3da CYy+53x/nyxrzX0KXw6ljYFdDcKO3M9i08qHW5NqtLtlz6ZhbasQ8xieyUjx4qmoUfzZ Zbi23eh19F5Vb4GtV/XcziMcnv0MJy1iuV014= 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=ZKdwGNTuB7raHchRws1uZpYC5kiBgIgkW7sRbNdes8U=; b=M+N685D++tgNcaPpzg0i+zqoIOhYnVebo7HO5ucZb+Jw72sdvnp8VBMH812yLZsY0e yvhGPi6YN7+EwMPtSEAx4QmiTYwz+TKmt4TZYDP0WXh0IiBht/uFiACfhOzDDN6oCfHQ 5HooJCN1X84GXwiiCa1yxdpu+UgT9MDKSz9UEh/8dXLw6grn9XfmnZizCigT4JBPbApv WhMRRi0+Ptj0jWcwqZDF3DTIIsyhq4GwzpcbxtoFsxih42jZ6xp1IUSn7VU4jpb/qgsI 49iMovMjm8J5vhFWbuuOif/6B+OKJgVIcmhV0tu56ef2Q6o1d72Qj+4RGPhr4nOcRsiF 3/Zw== X-Gm-Message-State: AOAM531IgHNtuyPW28GrnDDEyQy8IuH/Wzgo6DztfcXySctWc6z+VqvC l/bXcdTzTAIBNbXCz76FIybm3xdacG722HkfIncfAxbUFflg6g== X-Received: by 2002:a05:6830:14d9:: with SMTP id t25mr21146655otq.188.1600357033519; Thu, 17 Sep 2020 08:37:13 -0700 (PDT) MIME-Version: 1.0 References: <8d8693db-a3f0-4f5f-3e32-57d23ca620f8@amd.com> <20200917113110.GE8409@ziepe.ca> <6fd74b84-959c-8b3b-c27b-e9fbf66396c7@gmail.com> <20200917121858.GF8409@ziepe.ca> <20200917143551.GG8409@ziepe.ca> <5b330920-c789-fac7-e9b1-49f3bc1097a8@gmail.com> <20200917152456.GH8409@ziepe.ca> In-Reply-To: <20200917152456.GH8409@ziepe.ca> From: Daniel Vetter Date: Thu, 17 Sep 2020 17:37:01 +0200 Message-ID: Subject: Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap() To: Jason Gunthorpe Cc: =?UTF-8?Q?Christian_K=C3=B6nig?= , Linux Kernel Mailing List , dri-devel , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Linux MM , Andrew Morton , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 17, 2020 at 5:24 PM Jason Gunthorpe wrote: > > On Thu, Sep 17, 2020 at 04:54:44PM +0200, Christian K=C3=B6nig wrote: > > Am 17.09.20 um 16:35 schrieb Jason Gunthorpe: > > > On Thu, Sep 17, 2020 at 02:24:29PM +0200, Christian K=C3=B6nig wrote: > > > > Am 17.09.20 um 14:18 schrieb Jason Gunthorpe: > > > > > On Thu, Sep 17, 2020 at 02:03:48PM +0200, Christian K=C3=B6nig wr= ote: > > > > > > Am 17.09.20 um 13:31 schrieb Jason Gunthorpe: > > > > > > > On Thu, Sep 17, 2020 at 10:09:12AM +0200, Daniel Vetter wrote= : > > > > > > > > > > > > > > > Yeah, but it doesn't work when forwarding from the drm char= dev to the > > > > > > > > dma-buf on the importer side, since you'd need a ton of dif= ferent > > > > > > > > address spaces. And you still rely on the core code picking= up your > > > > > > > > pgoff mangling, which feels about as risky to me as the vma= file > > > > > > > > pointer wrangling - if it's not consistently applied the re= verse map > > > > > > > > is toast and unmap_mapping_range doesn't work correctly for= our needs. > > > > > > > I would think the pgoff has to be translated at the same time= the > > > > > > > vm->vm_file is changed? > > > > > > > > > > > > > > The owner of the dma_buf should have one virtual address spac= e and FD, > > > > > > > all its dma bufs should be linked to it, and all pgoffs trans= lated to > > > > > > > that space. > > > > > > Yeah, that is exactly like amdgpu is doing it. > > > > > > > > > > > > Going to document that somehow when I'm done with TTM cleanups. > > > > > BTW, while people are looking at this, is there a way to go from = a VMA > > > > > to a dma_buf that owns it? > > > > Only a driver specific one. > > > Sounds OK > > > > > > > For TTM drivers vma->vm_private_data points to the buffer object. N= ot sure > > > > about the drivers using GEM only. > > > Why are drivers in control of the vma? I would think dma_buf should b= e > > > the vma owner. IIRC module lifetime correctness essentially hings on > > > the module owner of the struct file > > > > Because the page fault handling is completely driver specific. > > > > We could install some DMA-buf vmops, but that would just be another lay= er of > > redirection. Uh geez I didn't know amdgpu was doing that :-/ Since this is on, I guess the inverse of trying to convert a userptr into a dma-buf is properly rejected? > If it is already taking a page fault I'm not sure the extra function > call indirection is going to be a big deal. Having a uniform VMA > sounds saner than every driver custom rolling something. > > When I unwound a similar mess in RDMA all the custom VMA stuff in the > drivers turned out to be generally buggy, at least. > > Is vma->vm_file->private_data universally a dma_buf pointer at least? Nope. I think if you want this without some large scale rewrite of a lot of code we'd need a vmops->get_dmabuf or similar. Not pretty, but would get the job done. > > > So, user VA -> find_vma -> dma_buf object -> dma_buf operations on th= e > > > memory it represents > > > > Ah, yes we are already doing this in amdgpu as well. But only for DMA-b= ufs > > or more generally buffers which are mmaped by this driver instance. > > So there is no general dma_buf service? That is a real bummer Mostly historical reasons and "it's complicated". One problem is that dma-buf isn't a powerful enough interface that drivers could use it for all their native objects, e.g. userptr doesn't pass through it, and clever cache flushing tricks aren't allowed and a bunch of other things. So there's some serious roadblocks before we could have a common allocator (or set of allocators) behind dma-buf. -Daniel --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch