Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp319830rdb; Fri, 5 Jan 2024 10:51:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVyPCGKL8QrXyCfPDF24tNArkyQk2B+pFxb78a6XtjZ83+ZEp7kMjxAj55n25FisjoXJsS X-Received: by 2002:a05:622a:512:b0:427:96be:c46 with SMTP id l18-20020a05622a051200b0042796be0c46mr2620370qtx.50.1704480666665; Fri, 05 Jan 2024 10:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480666; cv=none; d=google.com; s=arc-20160816; b=UR5i+BFBHwNo2ozUP8Ki3czjrb2DQbXiA7MAqHHg44911X12AfHJW4c+IG1j3Hm+n7 nUKkKRV3La4IbmQVDaq4qPDdBwCrqICRpIjKn6j4d9n2Fg0zI9DG1o9/BA+Ai/aRsJ7w 6+zFMVhC0IpOwGAK8BUGrD5QbGNcdab04RsuIT93NJJx+FV170lz4i5oP7Zkhhiogvph fUsu6y5nzkRzPpn/afP3aGJ3jm87On6LRZK4g6mBe9cn19juxFoTnrWQ3WmHvyDrf2dE fCritlrakDSivGehjyzbxlcEX+UmzoSMIHNlY8koQpS3spxE2QG4/LX2AL7gGaGkGp0k 2nfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ASQ6y4kxcG8k+ULy0KmTtSiJ6MG5BWbnNbfIPOZzdFg=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=Zwqszj6ZaIn2fWjxLjZ9Zw3GyPAln6r5Y10PhFM/Hwn+9rW9/wIVe4qfWNPa6Uzj7q w9bSYbJKjnqyQKAF+TkXqRVh9r/jnUS8Lx5zdn/9YAoqF86uhn56Jy3GEVaLwyprN7K6 B37gACB4YpubAF7LZ702GVyVcotf6XqlySnjZbrNDuYpUObBh+fT1ldJyEAtlxRFuwZf /jV9hLZ32RQ5i09bnVVOBOxLv/Hc5Z/Me78WxsxS0EiCS42UioQMjBrftvcrPoLwQ8YV DGRlhyjHzXsIhMRj8j1Quq7dZ1sYKybFimKvx1BssQEnitI/KZ/HU2GEW/jlg0wcuPPn 55uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=2u20bBo2; spf=pass (google.com: domain of linux-kernel+bounces-18254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m8-20020a05622a118800b0042819013c79si2456106qtk.605.2024.01.05.10.51.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:51:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=2u20bBo2; spf=pass (google.com: domain of linux-kernel+bounces-18254-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D9F11C23928 for ; Fri, 5 Jan 2024 18:51:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC30E39AEA; Fri, 5 Jan 2024 18:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="2u20bBo2" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3A883986D for ; Fri, 5 Jan 2024 18:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1704480430; bh=QuYX1ZbeqzzlgphkIZfy751IRqx3iZbH6NUvd1ayS2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2u20bBo2hSpc1THMfYB6JNEoJgDpKys+lBggfjoSpFj7t7nm01B0QgElOM1/8apZk heSFvZSGfDyeK4oBTragO5Jjg+1pj8WfjyW8MoP37fsgqcday1bN7HTIiNY4yMWiGU ZmyV2Nse5W+lS1k8OnULetaokn82kfZ5YFD+TOPSmeglq/8xrE3F/PKfT5kOSQ7c/R Lp9LXu9NfDcabVPGgHe2KFeTjP2Xhp90zai1qmWDVmRzsSY5VSLj4QWduFvGDSviGB kgj6RFK7hUo+V22r6Mo/tJ0FaVHmWQjXa5AYICEd+hCH+vl1ksPleUzeqf7Bg33VrR 3mrt5q4QwCrFg== Received: from workpc.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id C4A6F3782046; Fri, 5 Jan 2024 18:47:08 +0000 (UTC) From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Boris Brezillon , Emma Anholt , Melissa Wen Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v19 16/30] drm/lima: Explicitly get and put drm-shmem pages Date: Fri, 5 Jan 2024 21:46:10 +0300 Message-ID: <20240105184624.508603-17-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105184624.508603-1-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To simplify the drm-shmem refcnt handling, we're moving away from the implicit get_pages() that is used by get_pages_sgt(). From now on drivers will have to pin pages while they use sgt. Lima driver doesn't have shrinker, hence pages are pinned and sgt is valid as long as pages' use-count > 0. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/lima/lima_gem.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c index 2a97aa85416b..9c3e34a7fbed 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -115,6 +115,7 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, return PTR_ERR(shmem); obj = &shmem->base; + bo = to_lima_bo(obj); /* Mali Utgard GPU can only support 32bit address space */ mask = mapping_gfp_mask(obj->filp->f_mapping); @@ -123,13 +124,17 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, mapping_set_gfp_mask(obj->filp->f_mapping, mask); if (is_heap) { - bo = to_lima_bo(obj); err = lima_heap_alloc(bo, NULL); if (err) goto out; } else { - struct sg_table *sgt = drm_gem_shmem_get_pages_sgt(shmem); + struct sg_table *sgt; + err = drm_gem_shmem_get_pages(shmem); + if (err) + goto out; + + sgt = drm_gem_shmem_get_pages_sgt(shmem); if (IS_ERR(sgt)) { err = PTR_ERR(sgt); goto out; @@ -139,6 +144,9 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, err = drm_gem_handle_create(file, obj, handle); out: + if (err && refcount_read(&bo->base.pages_use_count)) + drm_gem_shmem_put_pages(shmem); + /* drop reference from allocate - handle holds it now */ drm_gem_object_put(obj); @@ -152,6 +160,9 @@ static void lima_gem_free_object(struct drm_gem_object *obj) if (!list_empty(&bo->va)) dev_err(obj->dev->dev, "lima gem free bo still has va\n"); + if (refcount_read(&bo->base.pages_use_count)) + drm_gem_shmem_put_pages(&bo->base); + drm_gem_shmem_free(&bo->base); } -- 2.43.0