Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1756234imw; Tue, 5 Jul 2022 15:03:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sj7+pMnCGUF99HvkCP8F9qBzI62NriLCAkqzJYeMrdwOirhn3Mugk9dr3Nk3a+Udos1Mpk X-Received: by 2002:a17:906:6c82:b0:709:f868:97f6 with SMTP id s2-20020a1709066c8200b00709f86897f6mr36350071ejr.555.1657058635499; Tue, 05 Jul 2022 15:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657058635; cv=none; d=google.com; s=arc-20160816; b=vo7iA/z9bsW+/1qVdPC/MCpDdb17BAFje9vqMpTPg3kZ9gIs8y2rzw+P8ujpIZOd/W HYSPxLKY8eU3Dj3EFGaPOQQUQ8sZ3TZAZgXbVtP+ZWOxDDzxiqx/J4r+4ZsawJrTKqKI 9rJoMzKa0tuzvOI4L80vTXZj436c8Hdae4ZryX6NwfzWifZVwN3Fte5HuIjdvbP/9+Nq 1v2zIDcLuc6n3IrNT/ndYrU6Mlc8oULX4awD8RwPY8r0Q9nhcKCG4WRQc8F0oTpdpg7x PxX46ixU8/hiUgUMtXYuNbZy4ycosH8v4/NeZG8/BI9xzKOohhtpA5/DDUX/PbjqEuX8 42lg== 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=PU7Lk/8Sax5XmlQiaVaA1dEst+rO/Dc76xfk8EMg5rU=; b=XjVf3rwc67iifECs5NY//pTHXFQogRvErHRwOFgzrv1dIPXI56Tt8E4Jz+66bmC5pT 04i8jgYcPQnaaVrSeiHMg5NJK0WslIEV1CHn7l89wAlxGYMWLLf2rfzKToeD9QikK32W KEmhw+I7vh7Qc6axeE9QK8LOQePhJoWGN9SKZ1Qc+DHA+KmpeHYF+Qkyubfs2Q75sFv8 WxGdUmUF9IBKVauKwH7JoMeFe1YHd8oG802PXoi3SWGfxjK39NUGpRWWsQ21TGuY1MNy lQl3UXFuoDT+A2hPVRhlptNsBTwMLs84Wcov/DvCU/lugGc3CX0JEswUHDL6kYlLGUDA 1o9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VWKoc1vT; 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 sb4-20020a1709076d8400b0072ad31f5bfcsi8071507ejc.250.2022.07.05.15.03.30; Tue, 05 Jul 2022 15:03: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=VWKoc1vT; 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 S232543AbiGEVs0 (ORCPT + 99 others); Tue, 5 Jul 2022 17:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbiGEVsZ (ORCPT ); Tue, 5 Jul 2022 17:48:25 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DECE510AF; Tue, 5 Jul 2022 14:48:23 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so8080069wme.0; Tue, 05 Jul 2022 14:48:23 -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=PU7Lk/8Sax5XmlQiaVaA1dEst+rO/Dc76xfk8EMg5rU=; b=VWKoc1vTC7dmodEJ7AnbFDZ5fs/4+Nq8GI6aDF//zH1sFJE8ous9N8DVmhCdNBDu7J TEV0OZ7bot7bTz3H4yd56ZRrkwxGIFMbiNXyMqyxTYq3VKR1u9rg6rHhTYMEXhscqSPb Ccm6AxwWMhv1d8/+zxJYMjbHjFhlhaXe+b5fXKLXVU2U8ZbZY80EwHbaMEMkj/MpnXbt Uw0LZyDNux3g8GLLZXWynLp0GUTzkeUfRCaJubH+VuWeVBLJXqR6LPAfYZV768F05DkS 81qT5rHG43qh7gdNNw7b8ZC4JsCyyDamnVIJ9F70HPL12MxnnMZIoo1SVum0jci5LIaF DoNw== 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=PU7Lk/8Sax5XmlQiaVaA1dEst+rO/Dc76xfk8EMg5rU=; b=BHzZCVcA51KikK3eBRptwRhimizcV57bdkg3j6/yveqmvKVagPPEm57yggJ7Tb6Pe+ 3bYms8OlDHFtsAXmCXow2ZUGd2I5f3H/kPmpg/05vS47G1HT8Cret2dNAuiN1a++RzVa +hip0s3OrQBIc+wdUs9xmwMynRw5roYwHmZUdiQaZNbom+KlbPnuV7vMYS7Ry6YZCHDa Y7tEJLZsTsrjfdTVeJfHEceE8T9C7p2WJR/PsUJPxSzreV4BkhDFQ4TCyY04/ayrucNB LltIbXXREfC6oT9wfEor8wQNsY2vHmB3z8UKK0o4qBT8Fz0XQCukNSAODgSGmtU8cPwq AcVw== X-Gm-Message-State: AJIora8HdXQsxChXq21vzeItZKuOuiNfAyEh5PVdI1zUT8CTcbBd2fUS Ef44s7uhA2+CMDexJOSlbQvsvQ7GXRjbEUS3sOQ= X-Received: by 2002:a05:600c:4f83:b0:3a1:7310:62e7 with SMTP id n3-20020a05600c4f8300b003a1731062e7mr36978255wmq.84.1657057702289; Tue, 05 Jul 2022 14:48:22 -0700 (PDT) MIME-Version: 1.0 References: <20220701090240.1896131-1-dmitry.osipenko@collabora.com> <20220701090240.1896131-3-dmitry.osipenko@collabora.com> <2bb95e80-b60a-36c0-76c8-a06833032c77@amd.com> In-Reply-To: <2bb95e80-b60a-36c0-76c8-a06833032c77@amd.com> From: Rob Clark Date: Tue, 5 Jul 2022 14:48:34 -0700 Message-ID: Subject: Re: [PATCH v8 2/2] drm/gem: Don't map imported GEMs To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Emil Velikov , =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , Linux Kernel Mailing List , dri-devel , "open list:VIRTIO GPU DRIVER" , linux-tegra@vger.kernel.org, Dmitry Osipenko , kernel@collabora.com 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 Tue, Jul 5, 2022 at 4:51 AM Christian K=C3=B6nig wrote: > > Am 01.07.22 um 11:02 schrieb Dmitry Osipenko: > > Drivers that use drm_gem_mmap() and drm_gem_mmap_obj() helpers don't > > handle imported dma-bufs properly, which results in mapping of somethin= g > > else than the imported dma-buf. On NVIDIA Tegra we get a hard lockup wh= en > > userspace writes to the memory mapping of a dma-buf that was imported i= nto > > Tegra's DRM GEM. > > > > Majority of DRM drivers prohibit mapping of the imported GEM objects. > > Mapping of imported GEMs require special care from userspace since it > > should sync dma-buf because mapping coherency of the exporter device ma= y > > not match the DRM device. Let's prohibit the mapping for all DRM driver= s > > for consistency. > > > > Suggested-by: Thomas Hellstr=C3=B6m > > Signed-off-by: Dmitry Osipenko > > I'm pretty sure that this is the right approach, but it's certainly more > than possible that somebody abused this already. I suspect that this is abused if you run deqp cts on android.. ie. all winsys buffers are dma-buf imports from gralloc. And then when you hit readpix... You might only hit this in scenarios with separate gpu and display (or dGPU+iGPU) because self-imports are handled differently in drm_gem_prime_import_dev().. and maybe not in cases where you end up with a blit from tiled/compressed to linear.. maybe that narrows the scope enough to just fix it in userspace? BR, -R > Anyway patch is Reviewed-by: Christian K=C3=B6nig > since you are really fixing a major stability problem here. > > Regards, > Christian. > > > --- > > drivers/gpu/drm/drm_gem.c | 4 ++++ > > drivers/gpu/drm/drm_gem_shmem_helper.c | 9 --------- > > 2 files changed, 4 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > > index 86d670c71286..fc9ec42fa0ab 100644 > > --- a/drivers/gpu/drm/drm_gem.c > > +++ b/drivers/gpu/drm/drm_gem.c > > @@ -1034,6 +1034,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj,= unsigned long obj_size, > > { > > int ret; > > > > + /* Don't allow imported objects to be mapped */ > > + if (obj->import_attach) > > + return -EINVAL; > > + > > /* Check for valid size. */ > > if (obj_size < vma->vm_end - vma->vm_start) > > return -EINVAL; > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/d= rm_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 =3D &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 =3D NULL; > > - > > - return dma_buf_mmap(obj->dma_buf, vma, 0); > > - } > > - > > ret =3D drm_gem_shmem_get_pages(shmem); > > if (ret) { > > drm_gem_vm_close(vma); >