Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1634812rdb; Thu, 25 Jan 2024 01:17:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrw5Cu65i7e2qvVo5Fe+74S/cNA3nw2xo/PskY4MtxYapDucNfyHxoBIRESf5oIaBNFUCQ X-Received: by 2002:a17:903:22cb:b0:1d5:4dbf:6045 with SMTP id y11-20020a17090322cb00b001d54dbf6045mr798930plg.86.1706174251822; Thu, 25 Jan 2024 01:17:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706174251; cv=pass; d=google.com; s=arc-20160816; b=D5lnex/8Bm3s5I8lbkqwyHmZXKa6CcUst4t8BTsuFOLFjKd+eMER4DGK4zVnVb8vln B/lYSCk49wAxmCWfS0NDVQWpGPcpAK5gbqisy3i+LPdO2Cv0g68dGfIVvUpGCYYxl5oC zs6rmR478ZEzb5K6q48dtJg+JTRfcpmNno9nm7h8kEncd+a+IX8Dci/Gt/dvW1qwonJx njgS2pZnI+yK6ZJWkvlxndsGfB5SW/XYL2TooeqIGItjHfKXsz2pG2B8wQTHqYmi6UxH VdsHEGJ2+JNiTG90nYDUymY8GPLtckYhRXiM76h/9IL1TnCJmcBQJp0XojtvEy66/EjH uSwg== 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=pbS5zyn169jv1b3aTt+opPO4XtmnNqoSlMxHAnt+iUk=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=jIpCG8fO+LZ+oVbLzgkFLnQBybTELgnhaTimEdDU5b5LSiw2Jkg5U2RuiRcvqpCIAd Xd7kCofd0taAxgd/bDCtv56dRTzg5ceOurrnFUUd18CyCNLfnExTuIUW0LW/F9gM5Tgw iVJgv3X70dN/e0FE5FPL7EFgklQPAjVzSdeLtNs9t80BFftOYlwHlAtxLCQuWcz5oXdJ ZOpM2l7dBnvNISqDWIjho3/ukcR2l/pT9uBeA4eWgpAtZTUKqzxnwg3LroHt4cXYg7IF jhFmEOrVbuUpUrJyKVOl9AaprWkK5Ntia3AfByVPY9uy0yLp9+bgaAg7tS+82qqwxeG/ OYAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=K0ZTZHJe; 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-38238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id be3-20020a170902aa0300b001d76677be13si5025619plb.584.2024.01.25.01.17.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 01:17:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=K0ZTZHJe; 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-38238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38238-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EEF41292E69 for ; Thu, 25 Jan 2024 09:11:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D9C51BC40; Thu, 25 Jan 2024 09:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="K0ZTZHJe" 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 AE6581B97C for ; Thu, 25 Jan 2024 09:09:57 +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=1706173800; cv=none; b=aExH7gRJpYmGwQMr+lLwW9n5U8ra5Y9xooVGEOEaMYg1/rS4RHulzizItywcEfdRsqIBXc1hSOf85J+WWaLNnbwHgeQ0BzE+9OUbPuXkAQsmZJ5WnxSJeBz+bjVGx1fPjMD+ixv+EuBYgkGfwrvl0+8FEeZjoCHHF6McdMPxEx4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706173800; c=relaxed/simple; bh=NHDMTimolpsRG953VM4h8IMbAP81NqnGQx5H5gz6gU4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qc6brChNaF7Hrkd4dxTyPgr42qocg0371pD4d0KC8FS8HZTybp9bm4KSbKdU0QtWn7/ItPCz4Abb+B0WnQwSV7WYtESwnZH+0fNmucdkacrIl7d8Q/dPDvdMuH/9FQYuLS9QZevBkEbg6H6sT4Cc/YNqoRggIL85Ow8eMhSxgUY= 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=K0ZTZHJe; 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=1706173795; bh=NHDMTimolpsRG953VM4h8IMbAP81NqnGQx5H5gz6gU4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=K0ZTZHJe5DZ9eZa4kY8kwa5c00th4E7Z2PjeeRbHuwJy+8xK/N6CC4lfGXky/r0OS Ihti4C3jApFsg/nNsItAAgnCZVanT3LBCNg2G1sFAy51jNUrvge1o6Uwk5w6/oiK/z x1YmGTJBGb7WpMkpwXmLkQtfGeMHxptiY+aPjYksvCVR5E9zFb9OZd13mHYsvnXwrF gXt0zN7eYiCnXuUPVM3ZFmPRITxlhSAaclIA0JKi7W8W3qi6YSYvWwXufIkmmDQdj+ PUuRzQeWW1/1mxvg7r9NOM34GUFf7XYV2PARmb4wSE72XJpZhIXWU0JMvNviujWGvL SOBFRw/I5nb8Q== 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 A788237813C4; Thu, 25 Jan 2024 09:09:54 +0000 (UTC) Date: Thu, 25 Jan 2024 10:09:53 +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 23/30] drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() Message-ID: <20240125100953.34340d4f@collabora.com> In-Reply-To: <20240105184624.508603-24-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-24-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:17 +0300 Dmitry Osipenko wrote: > Export drm_gem_shmem_get_pages_sgt_locked() that will be used by virtio-gpu > shrinker during GEM swap-in operation done under the held reservation lock. > Nit: I'd move that patch before "drm/shmem-helper: Add common memory shrinker", because you'll need to call drm_gem_shmem_get_pages_locked() and drm_gem_shmem_get_pages_sgt_locked() if you want to repopulate the MMU page table after when an eviction happened (see my comment on patch 22). > Reviewed-by: Boris Brezillon > Signed-off-by: Dmitry Osipenko > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 22 +++++++++++++++++++++- > include/drm/drm_gem_shmem_helper.h | 1 + > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 59cebd1e35af..8fd7851c088b 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -875,12 +875,31 @@ struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem) > } > EXPORT_SYMBOL_GPL(drm_gem_shmem_get_sg_table); > > -static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem) > +/** > + * drm_gem_shmem_get_pages_sgt_locked - Provide a scatter/gather table of pinned > + * pages for a shmem GEM object > + * @shmem: shmem GEM object > + * > + * This is a locked version of @drm_gem_shmem_get_sg_table that exports a > + * scatter/gather table suitable for PRIME usage by calling the standard > + * DMA mapping API. > + * > + * Drivers must hold GEM's reservation lock when using this function. > + * > + * Drivers who need to acquire an scatter/gather table for objects need to call > + * drm_gem_shmem_get_pages_sgt() instead. > + * > + * Returns: > + * A pointer to the scatter/gather table of pinned pages or error pointer on failure. > + */ > +struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem) > { > struct drm_gem_object *obj = &shmem->base; > int ret; > struct sg_table *sgt; > > + dma_resv_assert_held(shmem->base.resv); > + > if (shmem->sgt) > return shmem->sgt; > > @@ -904,6 +923,7 @@ static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_ > kfree(sgt); > return ERR_PTR(ret); > } > +EXPORT_SYMBOL_GPL(drm_gem_shmem_get_pages_sgt_locked); > > /** > * drm_gem_shmem_get_pages_sgt - Pin pages, dma map them, and return a > diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h > index df97c11fc99a..167f00f089de 100644 > --- a/include/drm/drm_gem_shmem_helper.h > +++ b/include/drm/drm_gem_shmem_helper.h > @@ -149,6 +149,7 @@ void drm_gem_shmem_purge_locked(struct drm_gem_shmem_object *shmem); > > struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem); > struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem); > +struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_object *shmem); > > void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem, > struct drm_printer *p, unsigned int indent);