From patchwork Thu Mar 2 14:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Ser X-Patchwork-Id: 13157364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A0F7C6FA8E for ; Thu, 2 Mar 2023 14:35:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F34F710E4F5; Thu, 2 Mar 2023 14:35:25 +0000 (UTC) Received: from mail-40136.proton.ch (mail-40136.proton.ch [185.70.40.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id F072710E4F5 for ; Thu, 2 Mar 2023 14:35:23 +0000 (UTC) Date: Thu, 02 Mar 2023 14:35:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail; t=1677767721; x=1678026921; bh=mfeN7cWG+xdpjLBhz8gTnkGojBY2WsOui4CA+tBC+7Q=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=H05m1+gh9UN3C/7UIrrBS+2f/8EmtyyTzLWIThnynaTO2ATIlI9XImVIBf+PuLFzs gSQTz1xm+uXn/e4SajJpQ8ykdrIOmaZ/NlMeJNmO4ZWWUBeB7blPrA6BOZyooULORw i/w9Rc+U3peVGl3LIIgZ/6XhLzCSGI0QwIQ2R/2h5pu9i/P5y6dPA0BQeKbE221h/+ sE0iTxkIp9E/hYXi0AgCVEtivG+Rjk2gYqFwRBxYthVSOeDZfosKNMzRNadrfqX9mt BUINAqT9V0dWv3ZnMmB//ut+dx1m859/Q2+k4zKDoUHhGScooSr0hOEB0onGoMYu6a 571a3bSmkFfsw== To: dri-devel@lists.freedesktop.org From: Simon Ser Subject: [PATCH v2 1/2] drm/prime: reject DMA-BUF attach when get_sg_table is missing Message-ID: <20230302143502.500661-1-contact@emersion.fr> Feedback-ID: 1358184:user:proton MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Hans de Goede , Maxime Ripard , Thomas Zimmermann , Tian Tao , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm_gem_map_dma_buf() requires drm_gem_object_funcs.get_sg_table to be implemented, or else WARNs. Allow drivers to leave this hook unimplemented to implement purely local DMA-BUFs (ie, DMA-BUFs which cannot be imported anywhere else but the device which allocated them). In that case, reject imports to other devices in drm_gem_map_attach(). v2: new patch Signed-off-by: Simon Ser Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Tian Tao Cc: Maxime Ripard Cc: Christian König Cc: Hans de Goede Acked-by: Thomas Zimmermann --- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index f924b8b4ab6b..ab1d21d63a03 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -544,7 +544,8 @@ int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data, * Optional pinning of buffers is handled at dma-buf attach and detach time in * drm_gem_map_attach() and drm_gem_map_detach(). Backing storage itself is * handled by drm_gem_map_dma_buf() and drm_gem_unmap_dma_buf(), which relies on - * &drm_gem_object_funcs.get_sg_table. + * &drm_gem_object_funcs.get_sg_table. If &drm_gem_object_funcs.get_sg_table is + * unimplemented, exports into another device are rejected. * * For kernel-internal access there's drm_gem_dmabuf_vmap() and * drm_gem_dmabuf_vunmap(). Userspace mmap support is provided by @@ -583,6 +584,9 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, { struct drm_gem_object *obj = dma_buf->priv; + if (!obj->funcs->get_sg_table) + return -EOPNOTSUPP; + return drm_gem_pin(obj); } EXPORT_SYMBOL(drm_gem_map_attach);