Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6772298rwb; Tue, 22 Nov 2022 19:21:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4M7eqcUvxYU/NW9mbY4Rx8/mvmGapmbG/Kd4v7Wve833ZmxGKg57KJJPgv5n3ak7gGexfy X-Received: by 2002:a17:902:da89:b0:189:8b2:b069 with SMTP id j9-20020a170902da8900b0018908b2b069mr7815692plx.13.1669173676321; Tue, 22 Nov 2022 19:21:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669173676; cv=none; d=google.com; s=arc-20160816; b=WejfkBwOL7Ec24jUfO8m2VnkXTx0T0Dg+heK90Xjwp4cM+aBq8tKcm0/0LfRkhG3nY GKgVbUz3lobWAXjaDFpRqn35jtGz4JzcJoqz5pbWN0W4PnFHhWZyM4gNP7Zp1qq6DiRM FQKUYz/UBuU9w3nxBzvxakcAjSPdfVTaLJGMVvZVxMxHFpE3I5KLM/ak/CGdZq4BSj4c k3YrRwmdlYJ3zraWWojsHCSGQtAD3uZK4HnC00+3H1o6QyUYvChDd6N2MjafDlK22nL0 ERSmfJgiYO9Fs+kiA6ikco/x8ArGFQbY5klyqb+cZhpGviAqbvFNMQCQK3ciEpDwfIv/ 2oUA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a170902c40900b00186748fd1a9si19582682plk.170.2022.11.22.19.21.05; Tue, 22 Nov 2022 19:21:16 -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 + 89 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=20K=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 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,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 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); -- 2.38.1