Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp3099241rwl; Sat, 5 Nov 2022 17:19:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JH7Rb7PO6HuJxD8DkS30QvYE7bD0gRBlaT04B9kms95tf4gstwY41ATuykxm/hDNqncMX X-Received: by 2002:a05:6402:2681:b0:461:cbda:fe4b with SMTP id w1-20020a056402268100b00461cbdafe4bmr43146435edd.124.1667693978492; Sat, 05 Nov 2022 17:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667693978; cv=none; d=google.com; s=arc-20160816; b=wadURHRUuhb1QZkS0QF1FeR43KlhdJVd0estxoAv5FX4MCCBZnOLXaJAyClH817W4N ftFXiBibURSbm2OuwoiLWfcjdRJwnfLvrPnzSzuSFr/6EsehAieXjSGfgRMY23Bbz3GH P+es7pZuplGdJnwL2p9baLimzqzuNkDPzIvMWjeD1LJoZxNaVCXDCtGX3k2xEq7MwrsN eOMGH5YnZ2VoBlczQHnJswNrN3NTWnsLy1RukVI/V5339owcEEMZtvf0IDiGc5bHS95y /2forIoE0M9bLSmD+UDe5hFts36J3dpqRpgNgjd8YtOsTsaTbp4qheY5LACZHwTQoX2g UHtQ== 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=DluU854ZnxneK1QWX0R5nMllOdQA043Sdm/djW69pbA=; b=RVoBd+3pRyPup42bdNITVK6RUftN25TR8OE0ycn/1eWDIOoMTmLzjmrxqRfUKT1J3m 6HjUomHRKzzLXVWi9eucDc8X/Ms0+6gq7SssGEjjpLUi2drLIBXcEfRBb/Msv1XEsVEM 464gxynN7lKf/7x6MllYLhh9DDjubwjWuMOuLEfyYvrCTCe1YoWjdLOHBmnMHCkUqNRt 5PIZ3DiqA7Z7Ew18spykrLOz4VO/Gth72ekXKM08xvE58Qn6NfycuYlKtBulrgr23Cqz OvLoMrOd8iiaXTvRkgj7rmE/e1Jl6NO3Ej6VK+0y1nqna2HF3+yLZD/+GGuxG1Z5xiob 29Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=leFFo47H; 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 q11-20020a170906770b00b0077e04f856a2si2971203ejm.541.2022.11.05.17.19.14; Sat, 05 Nov 2022 17:19:38 -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=leFFo47H; 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 S230122AbiKEX3L (ORCPT + 96 others); Sat, 5 Nov 2022 19:29:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230085AbiKEX3H (ORCPT ); Sat, 5 Nov 2022 19:29:07 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179EE10B5A for ; Sat, 5 Nov 2022 16:29:07 -0700 (PDT) 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 EEDB166023A1; Sat, 5 Nov 2022 23:29:03 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667690945; bh=1aIGzcCvjyLUUVPxDDM1tAwba0BQ54V9K/SYg0wiQNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=leFFo47HkJIgbtrWrmcnTgMUs+UwjwiYQCkRLE1ntyfolcM9JjRMhmt2y47Rao6m5 0GJN0ktUNpI+T47qdp+rok+f9Iv0crKZz3hAj9F0YyzwAcEeZFo3CgNt6MUddlg7Zo a8T8HOQ/Uf3/dpuSnpT1Fa1Vk1EI+n14ksrIMh2xw+VCu0qG/VPRlVyPWyf4g1hDMn mJchSjZpeNDUu4ilHzgPxA0mhuiPOprbFiEMSD4yFAmkwLNu0NGB7Uav6uhucuFLXz zsoxW/G8bJ+uQyaVauhN8nSforYrqrf/egcmC9cEaqnJTEbHslGxwXoE092rOQJHKx fN9Co0bgtjvIQ== 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, Dmitry Osipenko , kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v8 2/7] drm/shmem-helper: Don't use vmap_use_count for dma-bufs Date: Sun, 6 Nov 2022 02:27:14 +0300 Message-Id: <20221105232719.302619-3-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221105232719.302619-1-dmitry.osipenko@collabora.com> References: <20221105232719.302619-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 35138f8a375c..801033b48893 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -293,24 +293,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 (WARN_ON(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; @@ -376,15 +374,15 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem, { struct drm_gem_object *obj = &shmem->base; - if (WARN_ON_ONCE(!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 (WARN_ON_ONCE(!shmem->vmap_use_count)) + return; + + if (--shmem->vmap_use_count > 0) + return; + vunmap(shmem->vaddr); drm_gem_shmem_put_pages(shmem); } @@ -646,7 +644,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.37.3