Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp231433pxk; Thu, 17 Sep 2020 01:11:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHFKYIsFAGKLq9+TSiAy8z8NF4MIwtqCqP17UiTvmtaOVBKQUhznmtoVWgf1rpqk7IA3R/ X-Received: by 2002:a17:906:7248:: with SMTP id n8mr29182540ejk.160.1600330302786; Thu, 17 Sep 2020 01:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600330302; cv=none; d=google.com; s=arc-20160816; b=i2Xus8P1G/NWL6DfqCh0NpzI/CgEZ7ZVDaFDxcxVn9Xoetfl4O9mm4N67dbc1qEutm 2vMGLjPC1pYWW4QJHII89kjwyF3tKi3b/nmPADE5tkSghe/xXp4aLcvQ58pun5OTL8RI xPvtR4qZBLv5hiXtoM01maHZmqvE0IUBc9ROowafyDob/3uR0c51bw6UPUvYZnhR0Bva RdWEsQFChAzF62grA5rnDs73kJKE//rf32/k9g30MOTo7VXEXu+XQSrRdOrOGe8di1Gh 69E2Gi6NlXxScjEc32ZpMzN5gzZxCjM1522aGTCGITAIZ6P9ONMkuyJFPmk/qKFO4Mry gCoA== 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=hj748MDWz3uGjap8dFpsmQR43oB5FdmeE3PU5X76VV0=; b=F/aDettR4j4vrxIjxui+kh181cqxRMG4CkHLukbKAXTYh5x+bJ+Spw3gsrZjDEXKvS WrzvXpwYZuqWw8kHz2CX9yz5PPiI7NJ9q5q94nWp2v1wD1g3qitHwbq9EkTaAvaxAXeL 51blgNpctw+B0DtHQ4B2hYL5n3injE1I4tY0BwqHGS0NjdnegbGVGxaIz+2Vo3SPVD5Y O0DTaLrDTt29obhcSzKc0EaxeDF4xmbZniTUq6AKcCgdNQRNtJfXIY2xLv8Q9MGn3/vQ 3+qrcINq48sRry+YJ7WQ0H8zenUgCO3F1tSIXDutRWQtqClzp9elWk6L0QCEJIEe8KCN pCdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=LiGHVTAZ; 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 w12si15471404edi.441.2020.09.17.01.11.19; Thu, 17 Sep 2020 01:11:42 -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=LiGHVTAZ; 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 S1726476AbgIQIJ7 (ORCPT + 99 others); Thu, 17 Sep 2020 04:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgIQIJo (ORCPT ); Thu, 17 Sep 2020 04:09:44 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8D35C06174A for ; Thu, 17 Sep 2020 01:09:23 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id c13so1494540oiy.6 for ; Thu, 17 Sep 2020 01:09:23 -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=hj748MDWz3uGjap8dFpsmQR43oB5FdmeE3PU5X76VV0=; b=LiGHVTAZBlNXFMLULoLuA7sDuYos0oM5OblFb/GVLUevRmNfmxziUxmN5o1oE1+kmU Rj3uVZ8GFXSdl/JIHrwHGB9TM+RPKb1uNIqL0MqOn18aam/SH8w9FTYGAPGf5TzhNpRe Pe+BiT0Mhqg6d1HSV5qM409pE0CFaTHo+UOd0= 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=hj748MDWz3uGjap8dFpsmQR43oB5FdmeE3PU5X76VV0=; b=fNfzfJJYlim62IIu77H/RgtubfieWD1TxsPr0uYjE6Hu2JItdSrXamkZt2GQQDTRaE nc/QMgbwq+/QA+l7/5BvQoyrFgzJFnRmODmRZkNghmQxdpayWTD/JPFLoqc52ScntSq/ KT85SYC81vAYAgI6oW67bKni+uRgQv8slv0vaf+bkSC/i+w5so2vXVJOZam5S+uv0TgY Q7c1kv6eUVqhYP1hQ65b7rB3agutivdk2LW0QCVAU+R7VGlgl3OE+SJM5mHpHUsI4jNH WZOssIWr4uKr968UySqjOVstYyqQamvWpXOxcHqqfZfCUFKCb/Q1v8BeJG0Cr8QBAwky 5w5w== X-Gm-Message-State: AOAM5304bIM73NcBVIXcTVrgafrJOCNI791W60hZUVMJnPP9xwdVntVp 3deu3Hew+YnvnWqjQSm48RqsVaNYOU130vTObxvA4A== X-Received: by 2002:aca:de41:: with SMTP id v62mr5615790oig.128.1600330163116; Thu, 17 Sep 2020 01:09:23 -0700 (PDT) MIME-Version: 1.0 References: <20200914132920.59183-1-christian.koenig@amd.com> <40cd26ae-b855-4627-5a13-4dcea5d622f6@gmail.com> <20200914140632.GD1221970@ziepe.ca> <9302e4e0-0ff0-8b00-ada1-85feefb49e88@gmail.com> <20200916095359.GD438822@phenom.ffwll.local> <20200916140710.GA8409@ziepe.ca> <8db2474f-ecb7-0e17-5f5b-145708fe44d5@amd.com> <8d8693db-a3f0-4f5f-3e32-57d23ca620f8@amd.com> In-Reply-To: <8d8693db-a3f0-4f5f-3e32-57d23ca620f8@amd.com> From: Daniel Vetter Date: Thu, 17 Sep 2020 10:09:12 +0200 Message-ID: Subject: Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap() To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Linux MM , Linux Kernel Mailing List , dri-devel , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Jason Gunthorpe , 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 9:11 AM Christian K=C3=B6nig wrote: > > Am 17.09.20 um 08:23 schrieb Daniel Vetter: > > On Wed, Sep 16, 2020 at 5:31 PM Christian K=C3=B6nig > > wrote: > >> Am 16.09.20 um 17:24 schrieb Daniel Vetter: > >>> On Wed, Sep 16, 2020 at 4:14 PM Christian K=C3=B6nig > >>> wrote: > >>>> Am 16.09.20 um 16:07 schrieb Jason Gunthorpe: > >>>>> On Wed, Sep 16, 2020 at 11:53:59AM +0200, Daniel Vetter wrote: > >>>>> > >>>>>> But within the driver, we generally need thousands of these, and t= hat > >>>>>> tends to bring fd exhaustion problems with it. That's why all the = private > >>>>>> buffer objects which aren't shared with other process or other dri= vers are > >>>>>> handles only valid for a specific fd instance of the drm chardev (= each > >>>>>> open gets their own namespace), and only for ioctls done on that c= hardev. > >>>>>> And for mmap we assign fake (but unique across all open fd on it) = offsets > >>>>>> within the overall chardev. Hence all the pgoff mangling and re-ma= ngling. > >>>>> Are they still unique struct files? Just without a fdno? > >>>> Yes, exactly. > >>> Not entirely, since dma-buf happened after drm chardev, so for that > >>> historical reason the underlying struct file is shared, since it's th= e > >>> drm chardev. But since that's per-device we don't have a problem in > >>> practice with different vm_ops, since those are also per-device. But > >>> yeah we could fish out some entirely hidden per-object struct file if > >>> that's required for some mm internal reasons. > >> Hui? Ok that is just the handling in i915, isn't it? > >> > >> As far as I know we create an unique struct file for each DMA-buf. > > Yes dma-buf, but that gets forwarded to the original drm chardev which > > originally exported the buffer. It's only there where the forwarding > > chain stops. The other thing is that iirc we have a singleton > > anon_inode behind all the dma-buf, so they'd share all the same > > address_space and so would all alias for unmap_mapping_range (I think > > at least). > > Amdgpu works by using the address_space of the drm chardev into the > struct file of DMA-buf instead. > > I think that this is cleaner, but only by a little bit :) Yeah, but it doesn't work when forwarding from the drm chardev to the dma-buf on the importer side, since you'd need a ton of different 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 reverse map is toast and unmap_mapping_range doesn't work correctly for our needs. > Anyway I'm a bit concerned that we have so many different approaches for > the same problem. Yeah, I think if we can standardize this then that would be really good. -Daniel > > Christian. > > > -Daniel > > > >> Regards, > >> Christian. > >> > >> > >>> -Daniel > >>> > >>>>>> Hence why we'd like to be able to forward aliasing mappings and ad= just the > >>>>>> file and pgoff, while hopefully everything keeps working. I though= t this > >>>>>> would work, but Christian noticed it doesn't really. > >>>>> It seems reasonable to me that the dma buf should be the owner of t= he > >>>>> VMA, otherwise like you say, there is a big mess attaching the cust= om > >>>>> vma ops and what not to the proper dma buf. > >>>>> > >>>>> I don't see anything obviously against this in mmap_region() - why = did > >>>>> Chritian notice it doesn't really work? > >>>> To clarify I think this might work. > >>>> > >>>> I just had the same "Is that legal?", "What about security?", etc.. > >>>> questions you raised as well. > >>>> > >>>> It seems like a source of trouble so I thought better ask somebody m= ore > >>>> familiar with that. > >>>> > >>>> Christian. > >>>> > >>>>> Jason > >>>> _______________________________________________ > >>>> dri-devel mailing list > >>>> dri-devel@lists.freedesktop.org > >>>> https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2F= lists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=3D02%7C01%7= Cchristian.koenig%40amd.com%7Cf725d2eb6a5a49bd533f08d85ad23308%7C3dd8961fe4= 884e608e11a82d994e183d%7C0%7C0%7C637359206142262941&sdata=3DqcLsl9R1gP%= 2FGY39ctsQkIzI99Bn%2F840YS17F4xudrAE%3D&reserved=3D0 > >>> > > > --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch