Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp313158iog; Wed, 29 Jun 2022 00:11:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sKOMt7KRGaa2hNwwf1uebdvE2AIyAyEJgVHyyXpCHJtlvW/RCrAJdF2GBJtSQsYE6+/k/Z X-Received: by 2002:a17:90b:3d0f:b0:1ed:3dd0:900d with SMTP id pt15-20020a17090b3d0f00b001ed3dd0900dmr2280039pjb.191.1656486698226; Wed, 29 Jun 2022 00:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656486698; cv=none; d=google.com; s=arc-20160816; b=MZHbszjIonC6zx3gYvobfBBsOvUNQV+uoYOXYXYFTCb8v2vs8joWd1fWOxOQBWhiJt XYjUvcn50E6BCIYcSDs0BH5k2ph/KRDM92IOt0dCvv4f/IcCHUmWqdygrx6+c0s0wOr3 SpDFUi+76Ary0yErkU38yxY3b6yR8JL1eemUuhjOKdxoCfRoH08bhXOqXZjQi5pdUhv3 MyihpMQxQWbAaPDA1xmjfeTjeFW8TB0Wuo7y6lhgXhNIDyAYlpZOxjDqBpBMeJB8dyzY ecDSbqproSbGwxH0JoAIsNCLH6M3Djr5KCBPIiKPB0GQtU1KJbcVIJ9IAafwp4EtFByk O49g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=wEs5lkXxdWsFfqf161XyWVQgxfmxVmgOyq9tSdofGcs=; b=qSc1AtzdZHSSwYIwpp0ePSAdtjP4FkJfLGWVQo+mVz+qokDOlaGpUBp5SXNWTYXai7 QH7yzdM8hj8R0taf+04QRvxQVttL69SonHH3Z++SSIdbgtxjhFdshwgth8HLUZT3t13I dNKffJ9TY4u6iYs7TNsYzao8O/jq4nSWfdgnq0r2aKdFghgnw/YtT8XAG/aVsK12jewC t1aJDhbOvElkkRplVRdaCBn72p13RexFoHdge0HVz95EMeKm54RtnFlDtRKUIfr6BUz+ 5YbxaDB7O3z3qTlHBY7BhIlv4x/VRMQsuWU61vYEhbQr8RqVOrrcUgU6dS8Q5uOd7J3i QOfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=Dk1heA72; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170902d4c300b00163ad368fe7si25236417plg.71.2022.06.29.00.11.24; Wed, 29 Jun 2022 00:11:38 -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=fail (test mode) header.i=@shipmail.org header.s=mail header.b=Dk1heA72; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231430AbiF2Gka (ORCPT + 99 others); Wed, 29 Jun 2022 02:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbiF2Gk1 (ORCPT ); Wed, 29 Jun 2022 02:40:27 -0400 Received: from ste-pvt-msa1.bahnhof.se (ste-pvt-msa1.bahnhof.se [213.80.101.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A027626AE1; Tue, 28 Jun 2022 23:40:24 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 854E940C62; Wed, 29 Jun 2022 08:40:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Score: -2.11 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Authentication-Results: ste-pvt-msa1.bahnhof.se (amavisd-new); dkim=pass (1024-bit key) header.d=shipmail.org Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pU0wAbFoBRnS; Wed, 29 Jun 2022 08:40:21 +0200 (CEST) Received: by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 936C240C41; Wed, 29 Jun 2022 08:40:18 +0200 (CEST) Received: from [192.168.0.209] (h-155-4-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id E158636016C; Wed, 29 Jun 2022 08:40:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1656484818; bh=c5X9p3SygrAeI8kAv4cnUEr14Zu67PfkDBqu5n1JZJE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Dk1heA72TzwfqFM5AthBnHTC6DdPNKvqtIGAYZbJH355/RVnt8ijwSIqu7vAttHPz WX0p2SfS1SVHlAS1p1yD4GOPcww+7e+8Exx0MOiTrCnsrz24ZGcufvDpM/Zewvu/Cr GmWw0z/B/OoxA6n6QgI6GEuF4woAkKSKa2Gz0HFU= Message-ID: Date: Wed, 29 Jun 2022 08:40:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v6 02/22] drm/gem: Move mapping of imported dma-bufs to drm_gem_mmap_obj() Content-Language: en-US To: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Rob Clark , Emil Velikov , Robin Murphy , Qiang Yu , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, linux-tegra@vger.kernel.org, Dmitry Osipenko , kernel@collabora.com, linux-media@vger.kernel.org References: <20220526235040.678984-1-dmitry.osipenko@collabora.com> <20220526235040.678984-3-dmitry.osipenko@collabora.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28Intel=29?= In-Reply-To: <20220526235040.678984-3-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 5/27/22 01:50, Dmitry Osipenko wrote: > Drivers that use drm_gem_mmap() and drm_gem_mmap_obj() helpers don't > handle imported dma-bufs properly, which results in mapping of something > else than the imported dma-buf. For example, on NVIDIA Tegra we get a hard > lockup when userspace writes to the memory mapping of a dma-buf that was > imported into Tegra's DRM GEM. > > To fix this bug, move mapping of imported dma-bufs to drm_gem_mmap_obj(). > Now mmaping of imported dma-bufs works properly for all DRM drivers. Same comment about Fixes: as in patch 1, > > Cc: stable@vger.kernel.org > Signed-off-by: Dmitry Osipenko > --- > drivers/gpu/drm/drm_gem.c | 3 +++ > drivers/gpu/drm/drm_gem_shmem_helper.c | 9 --------- > drivers/gpu/drm/tegra/gem.c | 4 ++++ > 3 files changed, 7 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 86d670c71286..7c0b025508e4 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -1038,6 +1038,9 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, > if (obj_size < vma->vm_end - vma->vm_start) > return -EINVAL; > > + if (obj->import_attach) > + return dma_buf_mmap(obj->dma_buf, vma, 0); If we start enabling mmaping of imported dma-bufs on a majority of drivers in this way, how do we ensure that user-space is not blindly using the object mmap without calling the needed DMA_BUF_IOCTL_SYNC which is needed before and after cpu access of mmap'ed dma-bufs? I was under the impression (admittedly without looking) that the few drivers that actually called into dma_buf_mmap() had some private user-mode driver code in place that ensured this happened. /Thomas > + > /* Take a ref for this mapping of the object, so that the fault > * handler can dereference the mmap offset's pointer to the object. > * This reference is cleaned up by the corresponding vm_close > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 8ad0e02991ca..6190f5018986 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -609,17 +609,8 @@ EXPORT_SYMBOL_GPL(drm_gem_shmem_vm_ops); > */ > int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct *vma) > { > - struct drm_gem_object *obj = &shmem->base; > int ret; > > - if (obj->import_attach) { > - /* Drop the reference drm_gem_mmap_obj() acquired.*/ > - drm_gem_object_put(obj); > - vma->vm_private_data = NULL; > - > - return dma_buf_mmap(obj->dma_buf, vma, 0); > - } > - > ret = drm_gem_shmem_get_pages(shmem); > if (ret) { > drm_gem_vm_close(vma); > diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c > index 7c7dd84e6db8..f92aa20d63bb 100644 > --- a/drivers/gpu/drm/tegra/gem.c > +++ b/drivers/gpu/drm/tegra/gem.c > @@ -564,6 +564,10 @@ int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma) > { > struct tegra_bo *bo = to_tegra_bo(gem); > > + /* imported dmu-buf is mapped by drm_gem_mmap_obj() */ > + if (gem->import_attach) > + return 0; > + > if (!bo->pages) { > unsigned long vm_pgoff = vma->vm_pgoff; > int err;