From patchwork Wed Nov 23 02:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 24673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2561830wrr; Tue, 22 Nov 2022 19:03:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4sfg8RNXcNPeAsUZZvBDKmBPC35XUnYLLcHE9qCbjIpKrZkB7RTZUcBCt5m8PqTOS1aYgf X-Received: by 2002:a05:6402:882:b0:469:7893:4b5a with SMTP id e2-20020a056402088200b0046978934b5amr13191529edy.328.1669172612499; Tue, 22 Nov 2022 19:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669172612; cv=none; d=google.com; s=arc-20160816; b=eif6NR8cScLeqptRPCnF2PO1ISZ7oxZl/Oi2/VTaZaoRsVjM79zb1rpc1jJdscm16S Zjz2phCjeaWjC4wSfJMNo7HJTais3Ig5ZZKHN3+jFe9tQ18B/0zOXfjLGi6QKBY7YVVG bqXgzbI7uVGFFuYOdHrp++oga13xiflak6FaSlzS25sCq7QTTQMulayq+JP+9r89rxvE 1VJwMsnKsDRYh70c3uJKJGC8VHDhGmT6OeOLJe/I3boiN02/eWI7BSbjQYL5TlKQdL+9 fawJ8eT254xxUWhNjD6oL04+k69P0f2lVEZMB4xiGjg6QusvkqQ+tXNKLt0WDmM0Pj4m 6LGg== 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=oEkZ7o+3+mcINWxBNF2ZyJJLkmCqIBh/GSCA7U3yTok=; b=BZOf/gmMcHylzmXGrirsSBeCUC0bRppBeMHUyLPM8Yl6jDfxLSdZ1OIKVFz/x946HK JMINsdDbkrKim06pVyJBh1idD/HUD9qFEPRGeER3ydKtUqFc5FXQGy2BSqGsV4HYJ5z+ k/rWsycaS8w6vosDGVQ5VrPc9ywO6XHtOjz9VgnmoLjOBMIcmjeHNKkCd0NiWQsj+YLO PbdzcSDf2lBNZZBZTnZE5I9rib71Hdy9+8KZi6QnzPlbMHelurFwxsTHKYbn6iVJJBJ8 sApo3R8GBlOfzz0u3YsZuAOyArFYEfKC2U9krrglMEXcNxWsQPIj9n0aZsP7xarFqsJy uXrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nnzjCKig; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z12-20020a05640240cc00b0046154f0f866si15651414edb.159.2022.11.22.19.03.07; Tue, 22 Nov 2022 19:03:32 -0800 (PST) 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=nnzjCKig; 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 S235573AbiKWDAw (ORCPT + 99 others); Tue, 22 Nov 2022 22:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235354AbiKWDA0 (ORCPT ); Tue, 22 Nov 2022 22:00:26 -0500 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 99426D29B9 for ; Tue, 22 Nov 2022 19:00:25 -0800 (PST) Received: from dimapc.. (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (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 941B96602AEC; Wed, 23 Nov 2022 03:00:22 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1669172424; bh=Tcyiae8fmjxfaeXdiMzjEcz2/nDyrSKq/p6Agz/qn0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnzjCKigGd8sZF7ZBgYoObi2Bodrq1n/ZRCZvvxsZguXUVfgjjvGLlbyUhswHfkE8 9R5F5Q/YiKaGX+4vEURO0LjEdcLHfX6cddOvqhL6Modgx4nzEgXRYr3Bq5uzJs121g h70paCq23o4zsSrHFEz+00Nn+EUo5Ls/FAazmA6ZMsUfi5BYVgealxmzXAEnyPOCu4 6zC+faUUt8NcalScabTElZJVyDwZssMVWhzICTUlTBZtSfSOrpBSwRUzps+ThWUd1q KFmkZT26RGJ93tGK5kBuLAoFFfof8EO1EGYHLLxGSKkfVHXVz8u6ERxyA89t0WJ0j9 JlDZQF2g8gBDw== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring , Sean Paul , Dmitry Baryshkov , Abhinav Kumar Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v9 06/11] drm/shmem-helper: Don't use vmap_use_count for dma-bufs Date: Wed, 23 Nov 2022 05:57:18 +0300 Message-Id: <20221123025723.695075-7-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123025723.695075-1-dmitry.osipenko@collabora.com> References: <20221123025723.695075-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750254341191797631?= X-GMAIL-MSGID: =?utf-8?q?1750254341191797631?= DMA-buf core has its own refcounting of vmaps, use it instead of drm-shmem counting. This change prepares drm-shmem for addition of memory shrinker support where drm-shmem will use a single dma-buf reservation lock for all operations performed over dma-bufs. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 35 +++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 5504eeb61099..ba9d9c5f1064 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -299,24 +299,22 @@ static int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, struct drm_gem_object *obj = &shmem->base; int ret = 0; - if (shmem->vmap_use_count++ > 0) { - iosys_map_set_vaddr(map, shmem->vaddr); - return 0; - } - if (obj->import_attach) { ret = dma_buf_vmap(obj->import_attach->dmabuf, map); if (!ret) { if (drm_WARN_ON(obj->dev, map->is_iomem)) { dma_buf_vunmap(obj->import_attach->dmabuf, map); - ret = -EIO; - goto err_put_pages; + return -EIO; } - shmem->vaddr = map->vaddr; } } else { pgprot_t prot = PAGE_KERNEL; + if (shmem->vmap_use_count++ > 0) { + iosys_map_set_vaddr(map, shmem->vaddr); + return 0; + } + ret = drm_gem_shmem_get_pages(shmem); if (ret) goto err_zero_use; @@ -382,15 +380,15 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem, { struct drm_gem_object *obj = &shmem->base; - if (drm_WARN_ON_ONCE(obj->dev, !shmem->vmap_use_count)) - return; - - if (--shmem->vmap_use_count > 0) - return; - if (obj->import_attach) { dma_buf_vunmap(obj->import_attach->dmabuf, map); } else { + if (drm_WARN_ON_ONCE(obj->dev, !shmem->vmap_use_count)) + return; + + if (--shmem->vmap_use_count > 0) + return; + vunmap(shmem->vaddr); drm_gem_shmem_put_pages(shmem); } @@ -652,7 +650,14 @@ void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem, struct drm_printer *p, unsigned int indent) { drm_printf_indent(p, indent, "pages_use_count=%u\n", shmem->pages_use_count); - drm_printf_indent(p, indent, "vmap_use_count=%u\n", shmem->vmap_use_count); + + if (shmem->base.import_attach) + drm_printf_indent(p, indent, "vmap_use_count=%u\n", + shmem->base.dma_buf->vmapping_counter); + else + drm_printf_indent(p, indent, "vmap_use_count=%u\n", + shmem->vmap_use_count); + drm_printf_indent(p, indent, "vaddr=%p\n", shmem->vaddr); } EXPORT_SYMBOL(drm_gem_shmem_print_info);