Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp358033iog; Wed, 29 Jun 2022 01:26:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tBjxyowBmGIbGn4Ue/W7FfOXsQJsQguNxmN33rmFEpnr2cq6l3leGKQh2jTd3C6kLzdcWD X-Received: by 2002:a05:6402:238c:b0:435:8eb8:48dd with SMTP id j12-20020a056402238c00b004358eb848ddmr2568484eda.301.1656491184557; Wed, 29 Jun 2022 01:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656491184; cv=none; d=google.com; s=arc-20160816; b=cknvcSrPoO4cMmPhe1St/GvAo087NYe1hPG2YerUseBSuCCMHFqO+pBl3ijCxy7bGw IX8xowuLAzyLUP0sZgFVs31nOyO3VCCZv01qjGN32sH5QG2rBHb9DnRO7JPyN6/B7Hu2 WvZM+FTMDYnoEWY9YIYlHtlQNzJtjLJ1yXC5bSa1MXGqXbtYB0pADuvRJqZupZJKztph vXDqE8LzQ5So+6NK/DrPKEZwjEYypcROt4r8nutMnihD0Qmt91xb9xrKKAR9T9dTx3cW 1VJhXPNxUpqun9Tibz4T8JPEDhZyTo73xa888AfKYK0Cdwin6QesLHaU1yVR/Yz22b1n yG/w== 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=Gc2/0Ke20wDLatbh4gOyEJjVtJnGldMeBNgBf84xj78=; b=VocYQ+i7vYMRk5I5KLSm5ba+wDuBKARx7yzy/DdeKTFbaUs1Og23Tko3Hfq8E1nbgc qVpc+HIcXVvLdo/JEFa3Ux7rSEs4zkhqAHkftnM0mphwa+ZTuRwsZlBwGsjpaCMM14RH Rke2KVA0ad4w15zMFABoxTktfFtHU51tzWNtSaQbbFeY9mUww/eR/yupKp/kPkSY2M4X QIFN3/RHW9tWVol6sLMh+YexsFT7sVZG7c8n1SwHBVPX9hfciR6p0hP61k4/tCwGyi7c 6ofe2u4N3sminI0Vr7EAYune9Uz7s9lfMDqkkl7IR0ukdir/w7SZmmyD2K90hqGBS5D4 qnQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XDA5Kxe1; 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=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js8-20020a17090797c800b00726d0685281si6707593ejc.440.2022.06.29.01.25.58; Wed, 29 Jun 2022 01:26:24 -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=@collabora.com header.s=mail header.b=XDA5Kxe1; 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=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiF2IWO (ORCPT + 99 others); Wed, 29 Jun 2022 04:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbiF2IWL (ORCPT ); Wed, 29 Jun 2022 04:22:11 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F083BBDC; Wed, 29 Jun 2022 01:22:10 -0700 (PDT) Received: from [192.168.2.145] (unknown [109.252.118.164]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 96AF966018F1; Wed, 29 Jun 2022 09:22:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1656490928; bh=XVQSgsxJcmy7E9dO6ydXkj4ChuEFXc7MVQ+QygUQC8s=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XDA5Kxe1tQjVWoYM/BGtNXeKxwfzbPWBe/P8pqnkFIaP99Cob4KetSZp2mOV5ryP3 u7HvrxECrEmyBllUyLM9aJt9NxlBWJIjI1vH3F6cyKv3t6zcOoQ5eEnHwrBxui1qxj dhHHwgtCyjFiz0GVKfGTNTYY/r/P8cU6ccDNK3YajGTlvfcYzw3D0HBZvWZG99gBdw g3iqha1unBFwIZIh55U+Qs/ChxM3VgIRVZFM+pX3989oy8OqosWoTMbE+652VhJgHQ FAJaw4N5wVvjKnuA74fSOiQp7M9aReCv8cXtUS2LQKv6/MwDyHx8fBx07oNXwQjIzB fo3DQeZjKtWZw== Message-ID: Date: Wed, 29 Jun 2022 11:22:02 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.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: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28Intel=29?= 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, 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 References: <20220526235040.678984-1-dmitry.osipenko@collabora.com> <20220526235040.678984-3-dmitry.osipenko@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 6/29/22 09:40, Thomas Hellström (Intel) wrote: > > 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. Since it's a userspace who does the mapping, then it should be a responsibility of userspace to do all the necessary syncing. I'm not sure whether anyone in userspace really needs to map imported dma-bufs in practice. Nevertheless, this use-case is broken and should be fixed by either allowing to do the mapping or prohibiting it. -- Best regards, Dmitry