Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp605796imw; Mon, 4 Jul 2022 16:05:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZLy3dDVZPxjYrwBbYxUG/BEevnFSxW0Dr//hXAvCud5ZjtZJ7xwBP4yKp+hGJjGhcCUEV X-Received: by 2002:a17:90b:30c4:b0:1ef:8d1b:f9bf with SMTP id hi4-20020a17090b30c400b001ef8d1bf9bfmr6410181pjb.158.1656975949035; Mon, 04 Jul 2022 16:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656975949; cv=none; d=google.com; s=arc-20160816; b=OhWau22unpLvt5uQjDoT8PXiLhDfZdVPV1Zl7U5V7aOkmXoiO6NrfZvhzLkO5nYTSf zTpUoQDpUL26yv61Bq1xXbpvWd3wHRKWwxoSSFt/5g+C/Vptf/ERoonlb915fzCmpQSB aRduaOoXoJjJQgKTnLlzFTiB4eqWm084TpxY3lq3DQX65LOnX9yIhJiOdTQgz5Hn6xSo VjNpnyaJoNjnBv+fGy6EbVYqw0NGxsxVXzKNNqnnbIL2k06yaHnfpsUgHw4siHknU6a8 dpyPg31wQ6iTcVtZ2ObZCzl9bJ0IG8Q/hQwae00bo0xDQF5HGkz2pALFJpd35iB1N3hK A5TA== 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=sUbozc6DPFXWX3yM6BQRoEaA/gFPeH6jdbfYocM2fFU=; b=es4Hx3abz/Y91k+2RIEhuo+cdD5dAqIciGL+7gDy9Zi+4wadaFerMSkCLY6gtGguxP pkjqXNH9iHBqnoviS6MN/HLmXnjfw3WdWqf1ds5OvdKuKGF/cTiZhB/EMt9t9JmfCrNA im6I/dN31vZMigqgNzIJ4ttw03EVwcQNyV+L31xxOh2rrIxCy4MZNCOK3HFpwpvMtTNO BV7i5zIeXf2CpXv7h+2y1dmE2Ewo2yg2tilCKbAkqGLPqBRNAReaE7aSWd9JqSZNi7GQ siIGoboeV248cDXcXrymJONkq3j43Xj2FOLzVtr8hWmjx1MoUeHjMBwHsQTT78mkN4x2 lyaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TIETcXt5; 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 f129-20020a636a87000000b003fca31afbc1si37061771pgc.564.2022.07.04.16.05.37; Mon, 04 Jul 2022 16:05:49 -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=TIETcXt5; 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 S233178AbiGDWo2 (ORCPT + 99 others); Mon, 4 Jul 2022 18:44:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiGDWo1 (ORCPT ); Mon, 4 Jul 2022 18:44:27 -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 76843B52; Mon, 4 Jul 2022 15:44:26 -0700 (PDT) Received: from [192.168.2.145] (109-252-119-232.nat.spd-mgts.ru [109.252.119.232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8554E660199E; Mon, 4 Jul 2022 23:44:22 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1656974665; bh=GphHsd4+TzSAb7tj4o+YMEvu0hP9uR9DEZi//JxrDEU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=TIETcXt54Z6zAdCbC52DXacxsnFDzGdC3JpBIsizmA7N//ZHlPueCwy+HM8YdAAb2 HUI9viWT++O6etVqrNckxFUgP9ozk1r55Cb+PUEXrb9WRcAzHpJE00AbqEgjt9blxt RLJPB3XA3/+NfDsNwvjz2N41JPYRlCQxI6JAKkkmyIz1E91Q4VSjNoW8LqOHM8EB8q BQtx36ekmIe1Jt7JJZIQ79AGm28biDD4zfoAXWLmsCdqmX/9y9h9W6jOIDRVw65pq1 TNelVxwhjBX9if0FXgHlKZ/rVDPcxkXat5eT5ZTW/eMhrDqRk/HMeHceHosUPvp2Bo sroGV1SbIfvsw== Message-ID: <3e9fbf88-c1bd-d336-b0e0-86fb208a952e@collabora.com> Date: Tue, 5 Jul 2022 01:44:20 +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: [Linaro-mm-sig] 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?Christian_K=c3=b6nig?= , =?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 , 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 <"emil.l.veli kov"@gmail.com>, Robin Murphy , Qiang Yu , Sumit Semwal , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , 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> <467a1cee-ba8c-98f3-0398-2a7a5a90b5c3@collabora.com> <0335814b-dc11-4a54-9f24-bb4e9dbef35c@amd.com> From: Dmitry Osipenko In-Reply-To: <0335814b-dc11-4a54-9f24-bb4e9dbef35c@amd.com> 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 7/4/22 15:33, Christian König wrote: > Am 30.06.22 um 01:06 schrieb Dmitry Osipenko: >> On 6/29/22 11:43, Thomas Hellström (Intel) wrote: >>> On 6/29/22 10:22, Dmitry Osipenko wrote: >>>> 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. >>> Sure, but nothing prohibits user-space to ignore the syncing thinking >>> "It works anyway", testing those drivers where the syncing is a NOP. And >>> when a driver that finally needs syncing is tested it's too late to fix >>> all broken user-space. >>> >>>>    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. >>>> >>> Then I'd vote for prohibiting it, at least for now. And for the future >>> moving forward we could perhaps revisit the dma-buf need for syncing, >>> requiring those drivers that actually need it to implement emulated >>> coherent memory which can be done not too inefficiently (vmwgfx being >>> one example). >> Alright, I'll change it to prohibit the mapping. This indeed should be a >> better option. > > Oh, yes please. But I would expect that some people start screaming. > > Over time I've got tons of TTM patches because people illegally tried to > mmap() imported DMA-bufs in their driver. > > Anyway this is probably the right thing to do and we can work on fixing > the fallout later on. I already sent out the patch [1] that prohibits the mapping. Would be great if you all could take a look and give a r-b, thanks in advance. [1] https://patchwork.freedesktop.org/patch/492148/ -- Best regards, Dmitry