Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5755305ioo; Wed, 1 Jun 2022 11:53:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLtFbj23JhwCL0iRPqLKHPGJhhv+Wuacn05ZBe4jybyTpEs7x8PDDLVMJGsPfw5/hEtWN+ X-Received: by 2002:a63:1209:0:b0:3fc:818e:861d with SMTP id h9-20020a631209000000b003fc818e861dmr737544pgl.62.1654109636047; Wed, 01 Jun 2022 11:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654109636; cv=none; d=google.com; s=arc-20160816; b=CeZBO0fqInnykXnQVLN5PLuYyEEZTA13/6xMFL8wsmM6nzfreyOo7EqJPOwMebNAZr iigHQW0/MmOsG5MhBICG2IHNOLMa5QqnmU8rxV7REV8D5JbLYAALBKFNscRq7P2Od3TV xWwz3R2HcE7HHkSxRGrm3sbnvSfM6zS5m0ujTMe+ID/DQ/8k9Um4BLpy+0I1z++7q0x9 UTs3C68E8URwcOVnP08XhJuoJ8wTMj4d87K4MGRRnCb7a7AduZ+2Lhi/A1gtyGklUnES QYWVVtLSVqr2K4BcV9Gh3qf1t2AZ5MOev8T3hwIe4oV8+nwvbzuW8gEVB8wPzuGReXA3 tFhg== 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=gSTJ1X2wuqX0lNp5B2IPR5UrMFLMFHeOCXzMZ0hn2b4=; b=D6rwLQzWbbPh8q9cG/gh37SFQSVBfpy8uinAGH9wAuobBBah2MSqPI5n3CTlA7DsdQ 3CRt9UPwwYW9+WNL0OJn0dRnSJ4Gn+1URMxBpdJSVy3wuCRPymVA7WQJNrN5Y3+upI5M lAKhC9UctzSPSmpwdbuPZIXww0VD3FGGBz9RB7HSVlRfPZs3Iq8yrn0lbORPdfE7b8E/ oSTyrfzBi6vjn5GsnuYFjz3RUxVxFil27ppBxwIpgh5Vo5XOP31oJXeRVP0SsoWkhQmc SnGcJIECZbUooTiCvusdfeQUFjJY3PkGC48NwbnR+BVJ6DYU5LKuqflVq1iuHhbDoRRw r8RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OsFLSUzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 66-20020a630845000000b003db60740a25si3317021pgi.35.2022.06.01.11.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OsFLSUzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 057E943AD8; Wed, 1 Jun 2022 11:42:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241973AbiE3P30 (ORCPT + 99 others); Mon, 30 May 2022 11:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242281AbiE3P3N (ORCPT ); Mon, 30 May 2022 11:29:13 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000601DE8E0; Mon, 30 May 2022 07:32:48 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id h5so6822435wrb.0; Mon, 30 May 2022 07:32:48 -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=gSTJ1X2wuqX0lNp5B2IPR5UrMFLMFHeOCXzMZ0hn2b4=; b=OsFLSUzvyABeW29XWfSvKzCGNQnyj+ADgKauQh4p9sWs1MaqIZbckKyZTwq6O9poQn C74ES4SMcuigLnfMiVRuygm6ZTO0pkcwYbkLuBBCHKMpRuYnjNsNn+GfhmqVs6U7vamO xcEdrZOejon5nwrtb5Zm07ZriInzEsvdyRNMP1UrtLa+3i8Ad+n/B0L/v7+4yddZg0eU zdJ1Yml71RFWuHRuPr5Y2IMz2pcCXbZlE8rkotGQyGj8NmCD3dJKC1Gs6eoSZCvhJp+U kLV/muHTMpSb08fAG82Yetymgk6+YNCKDvaLbnIWBRQGdkVfo+bmBzedobhJQKGhbj29 fT9A== 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=gSTJ1X2wuqX0lNp5B2IPR5UrMFLMFHeOCXzMZ0hn2b4=; b=F4cdIcbZjjk79ZUtiXII5ejbyVWPjYbP5wC4Im1K0D6GkYAHGHfj5pcESHweSmyCW8 wZpRQkwO6mpGceNS/dPeF+/jlSlrj8MTF8b4iNBWlhmIhZ3BPnvyIOI9tOeVeD6K1TEq Zp6j3P4vqrvK5m8X/cEsOkpzA51MA1FrsoSChPztLhU3MCflT5QCfRIWF7lXBndhD8wf EEsM2medxbRwSt2RwLZUxTHzroCvmd9Qbz/bTtCGpCGdLp+89QCUt4FsTHNjuO9X8iF0 G3fDRUH4ZFQwxGFih+7u8PwLjD9/92HAnXdtlFoOCOmTg2QEui7tznlyIPxPkystcpWk q4+g== X-Gm-Message-State: AOAM533446JhGnuDVY65ljTJujdrEjyX2Le9681c6MRbBRff94Ydm1Vy BEy0XdFEG7yphDeyS0MQjviiU2LIZP6KBFMwjyY= X-Received: by 2002:a05:6000:547:b0:20f:ca41:cc51 with SMTP id b7-20020a056000054700b0020fca41cc51mr36432204wrf.221.1653921166691; Mon, 30 May 2022 07:32:46 -0700 (PDT) MIME-Version: 1.0 References: <20220529162936.2539901-1-robdclark@gmail.com> <0bf230f4-c888-b9c9-f061-7450406baa4a@suse.de> <6169ea6b-7452-e8e3-f253-1329f4924a67@suse.de> In-Reply-To: <6169ea6b-7452-e8e3-f253-1329f4924a67@suse.de> From: Rob Clark Date: Mon, 30 May 2022 07:32:45 -0700 Message-ID: Subject: Re: [PATCH] drm/prime: Ensure mmap offset is initialized To: Thomas Zimmermann Cc: dri-devel , Rob Clark , David Airlie , linux-arm-msm , open list , Gerd Hoffmann , freedreno Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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:16 AM Thomas Zimmermann wro= te: > > Hi > > Am 30.05.22 um 15:47 schrieb Rob Clark: > > 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 which= 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 C= PU > >>> 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 offse= t > >> 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. > > I see. > > I the reason I'm arguing against the current patch is that the fix > appears like a workaround and 6 months from now, few will remember why > it's there. Especially since most drivers initialize the offset > correctly. (Not too long ago, I refactored the handling of these mmap > calls throughout DRM drivers and it was confusing at times.) I dispute the "correctly" part.. and that this is a workaround ;-) But I can send a v2 with the addition of a comment explaining the reason, so git-blame archeology isn't required to understand the reasoning BR, -R > So here's another suggestion: I further looked at the 3 drivers that I > mentioned. etnaviv and msm can easily wrap the call to > drm_gem_prime_mmap() and init the offset first. [1][2] omapdrm doesn't > actually use drm_gem_prime_mmap(). The offset can instead be initialized > at the top of the driver's dmabuf mmap function. [3] > > Best regards > Thomas > > [1] > https://elixir.bootlin.com/linux/v5.18/source/drivers/gpu/drm/etnaviv/etn= aviv_drv.c#L480 > [2] > https://elixir.bootlin.com/linux/v5.18/source/drivers/gpu/drm/msm/msm_drv= .c#L961 > [3] > https://elixir.bootlin.com/linux/v5.18/source/drivers/gpu/drm/omapdrm/oma= p_gem_dmabuf.c#L66 > > > > > 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 o= ffset") > >>> Signed-off-by: Rob Clark > >>> --- > >>> Note, it's possible the issue existed in some related form prior to t= he > >>> 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_prime.= 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 *ob= j, 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 > > -- > 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