Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4043955ioo; Mon, 30 May 2022 16:31:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9A0yu40VeJM8XL4d+wKraBsGqSvlF8PS2Xg8ywO91rBWddA/kfenfNBdLDjjrNHzZ1u7v X-Received: by 2002:a17:903:18b:b0:162:3dfd:adb1 with SMTP id z11-20020a170903018b00b001623dfdadb1mr34936085plg.122.1653953455345; Mon, 30 May 2022 16:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653953455; cv=none; d=google.com; s=arc-20160816; b=HpqDDbe571TnIFP97kbdaL7fnXS645Z3IuPOuIbV/31DXyMKihATqh36E7NPlS6qdU WeiukSt5uQVDJeZsU2Jq9mj31sT8dp2cmcbmEB6Fize2JJA9/c0oeTC2Nz8F0+tpZRN4 FEC4J9NPcl0PrJ9aN282ESCq3GzHsX1WrflKQ4bg3C/n7Ves4XgTf/ltS0eyFLC1xYmG JZdin6WcOUjeTqxcfyzaVxcDBYtwFNf8UF05AaMxTxsy9SikWOPFblpyuR1pNtpFi6xh 1g6bLC4NF0jFXg2Up3KJy26/vgF7yIE9GDdyPTpQGqeEMgHBl5T6OehCKTAmPEXzlCp/ 1IWA== 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=HVYE9hD3JrlMP+VW+LXUcgvWsAPOc0+ADO1o4rrMIPE=; b=zImv9j/n47VpyoNmHzQSKfXMIYerijPj73qLctQvEm4uc/1hK7o6Mt4iw4i8KKB5+U An//5JwxgIRCyuUZpEL3VF23CVDirMnZi12HcwVe0lXhTp/PFRen/BUcXs/qi7fgL4Lb OZCeX2mx/G6ZPEzbDQE9hS7RxXAgKm1651KSp1lXH1BtHJckW7Gt8yvxMKGY3urJMpGt 8E2rnc9+Q4dCCGdXN8lY2ya92De/J828Jya7BRDTPrPC6n9aGEKHkllFnBrzrwNicG7y qt72/y5YLzwsV58i/K5UHJkrJTGhAz9DpWEwFAiLbfSj2VnoqD/pSswTv3Xe9OMgetll +ZIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="cOfon/AQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gl16-20020a17090b121000b001e31c998929si770016pjb.26.2022.05.30.16.30.44; Mon, 30 May 2022 16:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="cOfon/AQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239874AbiE3P4H (ORCPT + 99 others); Mon, 30 May 2022 11:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238912AbiE3Pz4 (ORCPT ); Mon, 30 May 2022 11:55:56 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12E13F33B7; Mon, 30 May 2022 08:41:09 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id s24so7853413wrb.10; Mon, 30 May 2022 08:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=HVYE9hD3JrlMP+VW+LXUcgvWsAPOc0+ADO1o4rrMIPE=; b=cOfon/AQdRZHUtaWUXSrjOLVbe/SaIrsAT1iSjEE4S2pJaqFJrshFUwG7CuV8zJNBE YjxmI7Z3mPwwK4lp3hdexT3bc0rF6YjTKT87FQZsXEyYd0fJ/8Q/TsNxV0cTPPGA76pZ nHewp/PRdVsYuBvd70KIDsjutHnHc10KAtPkI0wY1EzigLuqLSNoeNkxXcODBbrbD0Ha Pk+Im4A+VrBL5j49XDhHZICFI3ZuHCP0+11fTJXS+eUUcwTjVEepR4g9YZkv8WvGTUcU O6U+aB3ugr4S0gMR2kam5UEAjXrQ4bFO5XgrX9K2VRJSWWTTVGwvGTe5RMdc5mJOaZrW K8Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=HVYE9hD3JrlMP+VW+LXUcgvWsAPOc0+ADO1o4rrMIPE=; b=1MmJnFxMQP8laI9OBr8SizNBFXw1/EoXB8oxkwb3nj//RkcGGkHhjuiTS/CciXQv3o hsHz/1yofahPSEZ6hxELEnjzXi8wcV/CESIuGsaJjrnRYRR3nhRGAR3qvHFpPP2mrbSe uN0h+bPueETQQ3CZMh3FIVS5jiVarkNwccDzOjlT6ZGW7YkJkAK7v4WxhPSX1nhGPgyH UnFNoWknpkyLmKn3atVjt8gHHN544nTdW0XSJ664BrMUJFc4ZDaalecCQdy2zQIlWkXy PQOzR58ZcMAHLRSpHfMcEA2nvr11xgABha/6+6zw1CTnpQfnwZvMLr8qulzm3JepOl+o 5kVQ== X-Gm-Message-State: AOAM531DHQbWIyrWul+doUzN6ycDNQHxs4XQBQcIHuvmO2C3eRcDx9Rr 1uCyd/OoO/N0Bbg5Nw3Lu9I7lCJ0L957Nqw+nj0= X-Received: by 2002:adf:f645:0:b0:20e:652d:2a4e with SMTP id x5-20020adff645000000b0020e652d2a4emr47995950wrp.344.1653925267454; Mon, 30 May 2022 08:41:07 -0700 (PDT) MIME-Version: 1.0 References: <20220529162936.2539901-1-robdclark@gmail.com> <0bf230f4-c888-b9c9-f061-7450406baa4a@suse.de> In-Reply-To: From: Rob Clark Date: Mon, 30 May 2022 08:41:09 -0700 Message-ID: Subject: Re: [PATCH] drm/prime: Ensure mmap offset is initialized To: Daniel Vetter Cc: Thomas Zimmermann , Rob Clark , David Airlie , linux-arm-msm , open list , dri-devel , Gerd Hoffmann , freedreno Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 30, 2022 at 7:49 AM Daniel Vetter wrote: > > On Mon, 30 May 2022 at 15:54, Rob Clark wrote: > > > > On Mon, May 30, 2022 at 12:26 AM Thomas Zimmermann wrote: > > > > > > Hi > > > > > > Am 29.05.22 um 18:29 schrieb Rob Clark: > > > > From: Rob Clark > > > > > > > > If a GEM object is allocated, and then exported as a dma-buf fd whi= ch is > > > > mmap'd before or without the GEM buffer being directly mmap'd, the > > > > vma_node could be unitialized. This leads to a situation where the= CPU > > > > mapping is not correctly torn down in drm_vma_node_unmap(). > > > > > > Which drivers are affected by this problem? > > > > > > I checked several drivers and most appear to be initializing the offs= et > > > during object construction, such as GEM SHMEM. [1] TTM-based drivers > > > also seem unaffected. [2] > > > > > > From a quick grep, only etnaviv, msm and omapdrm appear to be affect= ed? > > > They only seem to run drm_gem_create_mmap_offset() from their > > > ioctl-handling code. > > > > > > If so, I'd say it's preferable to fix these drivers and put a > > > drm_WARN_ONCE() into drm_gem_prime_mmap(). > > > > That is good if fewer drivers are affected, however I disagree with > > your proposal. At least for freedreno userspace, a lot of bo's never > > get mmap'd (either directly of via dmabuf), so we should not be > > allocating a mmap offset unnecessarily. > > Does this actually matter in the grand scheme of things? We originally > allocated mmap offset only on demand because userspace only had 32bit > loff_t support and so simply couldn't mmap anything if the offset > ended up above 32bit (even if there was still va space available). > > But those days are long gone (about 10 years or so) and the allocation > overhead for an mmap offset is tiny. So I think unless you can > benchmark an impact allocating it at bo alloc seems like the simplest > design overall, and hence what we should be doing. And if the vma > offset allocation every gets too slow due to fragmentation we can lift > the hole tree from i915 into drm_mm and the job should be done. At > that point we could also allocate the offset unconditionally in the > gem_init function and be done with it. > > Iow I concur with Thomas here, unless there's hard data contrary > simplicity imo trumps here. 32b userspace is still alive and well, at least on arm chromebooks ;-) BR, -R > -Daniel > > > > > BR, > > -R > > > > > Best regards > > > Thomas > > > > > > [1] > > > https://elixir.bootlin.com/linux/v5.18/source/drivers/gpu/drm/drm_gem= _shmem_helper.c#L85 > > > [2] > > > https://elixir.bootlin.com/linux/v5.18/source/drivers/gpu/drm/ttm/ttm= _bo.c#L1002 > > > > > > > > > > > Fixes: e5516553999f ("drm: call drm_gem_object_funcs.mmap with fake= offset") > > > > Signed-off-by: Rob Clark > > > > --- > > > > Note, it's possible the issue existed in some related form prior to= the > > > > commit tagged with Fixes. > > > > > > > > drivers/gpu/drm/drm_prime.c | 5 +++++ > > > > 1 file changed, 5 insertions(+) > > > > > > > > diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prim= e.c > > > > index e3f09f18110c..849eea154dfc 100644 > > > > --- a/drivers/gpu/drm/drm_prime.c > > > > +++ b/drivers/gpu/drm/drm_prime.c > > > > @@ -716,6 +716,11 @@ int drm_gem_prime_mmap(struct drm_gem_object *= obj, struct vm_area_struct *vma) > > > > struct file *fil; > > > > int ret; > > > > > > > > + /* Ensure that the vma_node is initialized: */ > > > > + ret =3D drm_gem_create_mmap_offset(obj); > > > > + if (ret) > > > > + return ret; > > > > + > > > > /* Add the fake offset */ > > > > vma->vm_pgoff +=3D drm_vma_node_start(&obj->vma_node); > > > > > > > > > > -- > > > Thomas Zimmermann > > > Graphics Driver Developer > > > SUSE Software Solutions Germany GmbH > > > Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany > > > (HRB 36809, AG N=C3=BCrnberg) > > > Gesch=C3=A4ftsf=C3=BChrer: Ivo Totev > > > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch