From patchwork Sun Jan 8 21:04:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 40570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1851757wrt; Sun, 8 Jan 2023 13:08:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXuGMJkrK+9AYt+uXCoHCTDPF/dSYW60q2o0cb7IBiQZhN75DWFWHX7yGvz5zyldPXmqNR4t X-Received: by 2002:a62:ea01:0:b0:582:bbc7:c61e with SMTP id t1-20020a62ea01000000b00582bbc7c61emr17984604pfh.11.1673212089004; Sun, 08 Jan 2023 13:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673212088; cv=none; d=google.com; s=arc-20160816; b=TnR3+bboNBa0kldogMXCmTJs+DanlrVbgf8zZegs+5oNwHLNmFytAlG7dv+xYWh3A0 x7j5xdxze3KzPUDdi/PIE9hpVWhLEpinqqCAYZ1eUKiLxM2MAXEnUG5XeU+aV3qBTgwU s2L0LQNNLg3IgtMe8CH21AJdN/kghmmy3QYhWgb6F2QqY73Q8a4ahMwwtkvKR4LHSwvI jvfPu5PUK2Js07wsbt7gBrQUykZSD7tkGyLU7lnCh59GvcFzLhlo88mpzyqlTcTFd77F svWRPLpJIJwl1DNJK4nuRDiuLV0hJ73I+7POO7FZBmbIeY2Qt3CBs7hCZ4FTvgN3HCG6 DmFg== 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=2+fwiA3kBr8j2c+YhDs0AgzDAp+Pnm/owufX+7nFPWo=; b=wrfN0dre2wdx/+6OnVqYoBm8770z3Am1ujoh8UczX5Z99yWwVq9PBuzXmCPBDftzrt Ov6qoGqm7RB5k+I9TlKOGYm7Ai8Jwac+BT0lAE+W9sYFDPk0rp2w8Y/Qh58Ddh/iEbKk 6FY54xwFmecPLOD4XSM0P7w35dA2vKAu2YW8mFSk8uTXzXxcwfY15k8Fjm4bkmcGkhBk 5lTui1EbmdelnIUKMfhDr64E5VdMDJPkYvN/zMGmXT8FlNAIXwErRYgYogv3J6MNqZi6 pwxxHAYgIKxDPdzlDtJUpysS24wOMqQRwPNLB5LYfaCsz2lqRpf8zuQlUZyQ9o21lHT9 RCVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=etqZdme+; 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 i2-20020a626d02000000b005806cbac6d1si7259943pfc.71.2023.01.08.13.07.57; Sun, 08 Jan 2023 13:08:08 -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=etqZdme+; 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 S236239AbjAHVGH (ORCPT + 99 others); Sun, 8 Jan 2023 16:06:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbjAHVFp (ORCPT ); Sun, 8 Jan 2023 16:05:45 -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 3CD8EF033 for ; Sun, 8 Jan 2023 13:05:44 -0800 (PST) Received: from workpc.. (109-252-117-89.nat.spd-mgts.ru [109.252.117.89]) (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 9DA746602D55; Sun, 8 Jan 2023 21:05:37 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673211943; bh=HRNrI13pCO0JTcaezulgWqUGzqG40+vk9lZ3RK+UUfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=etqZdme+ox9XDBYrARcBGZBYJ8Z0u6FwY2iURxLW31RKqhRUnhm4UtIwDc7/JzT2L vwvaz1FJqgK1wxrwHfVEFgGiEn5RDRLDFTQ+WKJyC6goM8QZT92C6H0FICxrgiA4rE LyTFdxHsa5wmStWbFHWsO6eGfcyE34JwFreVayP6O4yNU59V2Z4FCge/xX04drLjMn UPxDhE1X/OhBCrx9/EE6TyU7eQAvEZgSi/FWW0DK5waZVSXLZpKP7GH+afXg5aFlNQ BRPxsVSrIlxCWhhMnEBiCAJsvZ1L5UTfG1J1kH3PJR7RBcVLSSbcHuhqlIgQY480uP S75NE0GCJYXKQ== 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 v10 06/11] drm/shmem-helper: Don't use vmap_use_count for dma-bufs Date: Mon, 9 Jan 2023 00:04:40 +0300 Message-Id: <20230108210445.3948344-7-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230108210445.3948344-1-dmitry.osipenko@collabora.com> References: <20230108210445.3948344-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?1754490039449461245?= X-GMAIL-MSGID: =?utf-8?q?1754490039449461245?= 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 Reviewed-by: Thomas Zimmermann --- 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 5006f7da7f2d..1392cbd3cc02 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -301,24 +301,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; @@ -384,15 +382,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); } @@ -660,7 +658,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);