From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC091C43461 for ; Thu, 17 Sep 2020 08:09:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12E8F221E3 for ; Thu, 17 Sep 2020 08:09:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LiGHVTAZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12E8F221E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EC0D8E0001; Thu, 17 Sep 2020 04:09:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 577E86B005A; Thu, 17 Sep 2020 04:09:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43D628E0001; Thu, 17 Sep 2020 04:09:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 26BDB6B0055 for ; Thu, 17 Sep 2020 04:09:25 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DC907181AEF1E for ; Thu, 17 Sep 2020 08:09:24 +0000 (UTC) X-FDA: 77271828648.04.pail08_0f011a527121 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id B3F6D800E0E1 for ; Thu, 17 Sep 2020 08:09:24 +0000 (UTC) X-HE-Tag: pail08_0f011a527121 X-Filterd-Recvd-Size: 7871 Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 08:09:23 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id 185so1472653oie.11 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=QAApaHslRKV6m98VVxUTPYc1NrXaN/BUWWHdb5j4tGmL9PmC6HKLnsbUrnHrhvZFgG zZClCBeXafOW0eM51Or9+jLd6S/YUBsG8Tk8OgcIovaMFP51vqRr4Om2p3RLagM0+9a6 1AAk3BqmMwl0Gq+4smuGuVsVufUZVufomYH/IE+0G2hv8NIMbIR5A4PaQb+ox8Koa03c 76/60OQsnSEyl060NJxcEjsjMnUQOiNr79AjCpC9VIMYNKFC2Zipxomjahs5utMEF/Hq EttXzzPdI7nFUrYzQ6G2t+RkvjYmETyD7PJp3m1mHRGZeHaV09qo6stUn2/GUPtjv5mU 3EcA== X-Gm-Message-State: AOAM530JpGxSLB/kaRqm7iSQbymy+EVVNMUtdEcmaBfSNkXp2r+do283 NG0D6Udgb0UH8bL3Ky8vtc82ZQn47kztA/FTs37reg== X-Google-Smtp-Source: ABdhPJxnhcvTWespPIz0mwDd5lfmfASbxSQp+iv4wdI3VWmLcUZDr+o6jic2DrtQ3xdcC58bSj1uv5b78VL+7UnvPaQ= 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 X-Rspamd-Queue-Id: B3F6D800E0E1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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