Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3552719rwl; Sun, 2 Apr 2023 09:52:17 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7iYG8jpDn7eiHVpHsLq0Cm7gknE4h09tRGxARGwMMyQFTdBw3Gx9q5SO0z4ror9N1covP X-Received: by 2002:a17:906:41:b0:934:286:f9 with SMTP id 1-20020a170906004100b00934028600f9mr16000981ejg.27.1680454337606; Sun, 02 Apr 2023 09:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680454337; cv=none; d=google.com; s=arc-20160816; b=KT78N8jg1291EDeVKhfL23pXIWKbmhNY4LYS33Crrk39JaOfYNVRSUopiVcHelCPST gkZf0CAmu2+4rlnbKqMO8eZF0PK6fudCCQOrTGtGKg3STnuRJ1iQsavJnfJ2YJHLPdvj hS6/teDB57YQYPNLYEiYUCJLP6WjXhAnRBrTX9b8oL9iJdrLI9MgrStBKLh0DWtcDaYJ DOrgoHe9KJWfz5lUI+ZMzZAZpoaPwlmGAwB1T8b3BoIRAdS+b9juVaR5gFfxVnbcKcxt meZyNnHLFyLvTpqBTC6LGvYw8piqFvs/ijvLgEMGB/TL+Ksja5Qtfj1SFznQdPEG3ZlX ATwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KLB+SUE2xts4mlGYEeSfWvhTtJbb/KaeOMmq6JcmlDc=; b=rJHfzLZuujMC/rBAcH/xrucp6kSf+74HZDQNOH4QJcY6hdt6ER6XDi987zkeZ4/Nxr s9H0oOX9A0a+YBFPeY2it8FqaTipUy4uYw+7+BFb1H0NREe8mHQK3RA/d9e8bWMTukk7 vW9C/o4ST8mImTDdWsAKPU00kErnu+161T95ACWatT3qnQL9WIi/qxdvKT3jWlb/9RJ7 KZFary83YsDR5aYXPXePtZlxE7UPTBwGAXOxl6HWlg7V8BSrHresuTWb1te4Atr3FQsA X4dsK1bRwK+jdHDEIpNl+nrNBNigi0CctE8OuviJC62Ypi4nscvjzQu3P2OrnHgc3rwz Kodw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MtoftGVE; 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=QUARANTINE sp=QUARANTINE 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 d19-20020a50fb13000000b0050277bdc0f8si4779045edq.463.2023.04.02.09.51.52; Sun, 02 Apr 2023 09:52:17 -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=MtoftGVE; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbjDBQtx (ORCPT + 99 others); Sun, 2 Apr 2023 12:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231308AbjDBQte (ORCPT ); Sun, 2 Apr 2023 12:49:34 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A97311C1F7; Sun, 2 Apr 2023 09:49:28 -0700 (PDT) Received: from workpc.. (109-252-124-32.nat.spd-mgts.ru [109.252.124.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 B442566030F1; Sun, 2 Apr 2023 17:49:24 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680454167; bh=2Pyh5yKSK7/Mnl4/9/fKShVmz/dQjnpKIAeujBIUlw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtoftGVEqSTmaLH2pgVAyiSV8xbi2Fo0KUKdcqrsOUXDtbVLo8mtyURsR0+foN7zF w+kw0cnDGlcKeBAkCnbOafTc5oXwOdgBleELJV+3FZzMoyA9xrfQS0SDLPg0ZAeGFb /FkZfdo/W3Ao/JJknf7bjwRITSTEhwqwLrNsh4JIH/rh8+qi3LQDfMHZI20urlZq3Y m++IxCiKh0GVYFYPZTVzN8SeS1ujqg3X/O9Q876KnhuK5CShPK2NFQF1ewB+EmYIdZ ruDjasGX9T8iIiRMThlAo1L3pSPCO7wP73ZN53d07G6D3m8wTwKRMChu8w/hOIjOaC isX/LX6QuIj+A== From: Dmitry Osipenko To: Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Benjamin Gaignard , Liam Mark , Brian Starkey , John Stultz , Gerd Hoffmann , Daniel Vetter , Jani Nikula , Arnd Bergmann , Greg Kroah-Hartman , Thomas Zimmermann , Tomi Valkeinen , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Srinivas Kandagatla , Amol Maheshwari Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 6/7] dma-buf: Change locking policy for mmap() Date: Sun, 2 Apr 2023 19:48:25 +0300 Message-Id: <20230402164826.752842-7-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230402164826.752842-1-dmitry.osipenko@collabora.com> References: <20230402164826.752842-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Change locking policy of mmap() callback, making exporters responsible for handling dma-buf reservation locking. Previous locking policy stated that dma-buf is locked for both importers and exporters by the dma-buf core, which caused a deadlock problem for DRM drivers in a case of self-imported dma-bufs which required to take the lock from the DRM exporter side. Signed-off-by: Dmitry Osipenko --- drivers/dma-buf/dma-buf.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index aa4ea8530cb3..21916bba77d5 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -131,7 +131,6 @@ static struct file_system_type dma_buf_fs_type = { static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) { struct dma_buf *dmabuf; - int ret; if (!is_dma_buf_file(file)) return -EINVAL; @@ -147,11 +146,7 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT) return -EINVAL; - dma_resv_lock(dmabuf->resv, NULL); - ret = dmabuf->ops->mmap(dmabuf, vma); - dma_resv_unlock(dmabuf->resv); - - return ret; + return dmabuf->ops->mmap(dmabuf, vma); } static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence) @@ -850,6 +845,7 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach, * - &dma_buf_ops.release() * - &dma_buf_ops.begin_cpu_access() * - &dma_buf_ops.end_cpu_access() + * - &dma_buf_ops.mmap() * * 2. These &dma_buf_ops callbacks are invoked with locked dma-buf * reservation and exporter can't take the lock: @@ -858,7 +854,6 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach, * - &dma_buf_ops.unpin() * - &dma_buf_ops.map_dma_buf() * - &dma_buf_ops.unmap_dma_buf() - * - &dma_buf_ops.mmap() * - &dma_buf_ops.vmap() * - &dma_buf_ops.vunmap() * @@ -1463,8 +1458,6 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_end_cpu_access, DMA_BUF); int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, unsigned long pgoff) { - int ret; - if (WARN_ON(!dmabuf || !vma)) return -EINVAL; @@ -1485,11 +1478,7 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, vma_set_file(vma, dmabuf->file); vma->vm_pgoff = pgoff; - dma_resv_lock(dmabuf->resv, NULL); - ret = dmabuf->ops->mmap(dmabuf, vma); - dma_resv_unlock(dmabuf->resv); - - return ret; + return dmabuf->ops->mmap(dmabuf, vma); } EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, DMA_BUF); -- 2.39.2