Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1608222rdb; Thu, 25 Jan 2024 00:09:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqVItQmPPk76vRAWUi9Qk/Df99hnFquI/UyTlYDwTwaLeT01Xi2Wag1JF2vGW9l3ET5C5z X-Received: by 2002:a05:6a20:88a9:b0:19b:5b9d:fe93 with SMTP id d41-20020a056a2088a900b0019b5b9dfe93mr473629pzf.60.1706170141434; Thu, 25 Jan 2024 00:09:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706170141; cv=pass; d=google.com; s=arc-20160816; b=NHr5tgKiieBPinDqJVmoiEHNHNJ6Sit4hS9CKtwsF94xl30r3l7TeNfqHva1B11Es9 FLf8L+TMiDe92VN80PosTuQFMVX6P1XcqVmDQSd+b51vuXnVLxqUYCCieWWiECUnvMc8 LekwhwSr3sBNhvRwsFabI1oPbLoV1UWN8IwLHCy41Se7h5arVhs/oOdAehoQheqlk/kl n92SaTfU/VGD1M1uICoPdM0xbxb5MYDtgT0uxYdWLJPa6SRUwxlePZGa99c6wmbnmQlC 8yxEhtK/h5wy4CqwKkSnzwo7FG1PDJpZnEnQs5s91BJPTg4iZONP7CfWFLZ/gQ5JLHwQ B6Hw== ARC-Message-Signature: i=2; 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:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=QvhiVnngFc6X5KNyDSJLuzSyz01vtyvVVOACRmcHspg=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=QhKwOSF3xBrrM40Sdat/xTDBvqy5XwRxNEgCkDJ6IqLqg6/yM/ukxjBdA1kGjw8+eb YAYKUeHHI4cSkWwju7BlGf9fnSeGf3LI2JNv7zU9X1JMadtiYGknXAPqnWTjCZpmJg8y 1+k8KmbR0lYbYyyMA1LRJDkAXcXwWOsTk2mqYV/n11DUIysbWnHRLhiSpiXndkeTs6vM Z2jG2VeMvNORL90+Xc8AT7YExnrWgyM6OOuCEaUju5/ABGrl6MO8ao0oXJfxIru/jZsn ZAGrh8JEpzSTcNuyPY7sclO5DpiPq3Fig9HdBcyNoNTYx8iENL1KjKN5rVA97Z/bxYxt 2GIQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Q67nKkqQ; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-38129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f13-20020a056a00228d00b006dd9e880040si2547123pfe.249.2024.01.25.00.09.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 00:09:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Q67nKkqQ; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-38129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38129-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 26A0AB274BB for ; Thu, 25 Jan 2024 08:03:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D60A617753; Thu, 25 Jan 2024 08:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Q67nKkqQ" 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 8315013FF2 for ; Thu, 25 Jan 2024 08:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169751; cv=none; b=ZjU+QGrI2xqeG+N+8d2yO9/YJajY5xITuDFYJKXUhaaUGHq0OiTwk1j6cuuSmG9b7lqiV+PviVvQOhRQnfd8+Yn9moVQOT8qh210mu8+CKFVlg9//zM4LF3yZTbsnzLcFBPqoltVzxLzZzGL/1tZBKmV4RAiESw76Lm4VP4vFEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169751; c=relaxed/simple; bh=VCbIeEvU+Hvu9heYcu0mfFKjK9KaE6zRVAxTGdJIkZU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PJR5/fTy0X7CJqaNZWd79TjWU0ll1fSfJzw7UP02RkWSgnMq2mhd3nU3E2AwnHjfvIXrp2Y1IdprJ04LQsZYCzKkmTg3VZXGxvhugafE3q8ZDQgFzF/HL44n081xHINoGXMLHt3Zn6qH2haHvUW08I9pKMey6gYOfIDcnQKfvFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Q67nKkqQ; arc=none smtp.client-ip=46.235.227.194 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=1706169748; bh=VCbIeEvU+Hvu9heYcu0mfFKjK9KaE6zRVAxTGdJIkZU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Q67nKkqQfLucYoKDEQgXaAZ6lLe4cHno8b+SfamY1VURHam2v3QYTrx9UxEsPp2ZP yjvuyE0qNnMOsUu+u7+eZkJAOeV+jyKUPIaZw1WypsU+NxWrGptOmoXzc2M7WxtOJy ynbyBH7rxWqKGhGXQjk2N/9LJozmeviNv0nsRoyQ8GuwB67fLCBbyqTmX9sxcwvRG2 51vt3qhXgP+aHZQj52bFSjs8y3jm1GmGmUNj32HSmOhpWWloTqXO23G5feYQ4H5BCU hURhKFykXadBi2Sh4ctyvOqhGRwPbyhj1CbPrr4Fmw7jOMnypJgdtg9E0wL9KKL+dP fR7xw00ttBJNg== Received: from localhost (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: bbrezillon) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 14E2537820AF; Thu, 25 Jan 2024 08:02:27 +0000 (UTC) Date: Thu, 25 Jan 2024 09:02:26 +0100 From: Boris Brezillon To: Dmitry Osipenko Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?UTF-8?B?S8O2bmln?= , Qiang Yu , Steven Price , Emma Anholt , Melissa Wen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v19 14/30] drm/shmem-helper: Add drm_gem_shmem_put_pages() Message-ID: <20240125090226.2f7f0de5@collabora.com> In-Reply-To: <20240105184624.508603-15-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-15-dmitry.osipenko@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 5 Jan 2024 21:46:08 +0300 Dmitry Osipenko wrote: > We're going to move away from having implicit get_pages() done by > get_pages_sgt() to ease simplify refcnt handling. Drivers will manage > get/put_pages() by themselves. Add drm_gem_shmem_put_pages(). > > Signed-off-by: Dmitry Osipenko Reviewed-by: Boris Brezillon > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 20 ++++++++++++++++++++ > include/drm/drm_gem_shmem_helper.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index dc416a4bce1b..f5ed64f78648 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -218,6 +218,7 @@ static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem) > * @shmem: shmem GEM object > * > * This function decreases the use count and puts the backing pages when use drops to zero. > + * Caller must hold GEM's reservation lock. > */ > void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem) > { > @@ -228,6 +229,25 @@ void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem) > } > EXPORT_SYMBOL_GPL(drm_gem_shmem_put_pages_locked); > > +/* > + * drm_gem_shmem_put_pages - Decrease use count on the backing pages for a shmem GEM object > + * @shmem: shmem GEM object > + * > + * This function decreases the use count and puts the backing pages when use drops to zero. > + * It's unlocked version of drm_gem_shmem_put_pages_locked(), caller must not hold > + * GEM's reservation lock. > + */ > +void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) > +{ > + if (refcount_dec_not_one(&shmem->pages_use_count)) > + return; > + > + dma_resv_lock(shmem->base.resv, NULL); > + drm_gem_shmem_put_pages_locked(shmem); > + dma_resv_unlock(shmem->base.resv); > +} > +EXPORT_SYMBOL_GPL(drm_gem_shmem_put_pages); > + > /* > * drm_gem_shmem_get_pages - Increase use count on the backing pages for a shmem GEM object > * @shmem: shmem GEM object > diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h > index 6dedc0739fbc..525480488451 100644 > --- a/include/drm/drm_gem_shmem_helper.h > +++ b/include/drm/drm_gem_shmem_helper.h > @@ -111,6 +111,7 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t > void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem); > > int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem); > +void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem); > void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem); > int drm_gem_shmem_pin(struct drm_gem_shmem_object *shmem); > void drm_gem_shmem_unpin(struct drm_gem_shmem_object *shmem);