Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1655219rdb; Thu, 25 Jan 2024 02:07:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt7gRfX8Ex2U6FP7pTyEuCWP/IvF4YN/NmTMrqoL0s7OHTS2NUjdpbNUFIQbox7xsjw4g5 X-Received: by 2002:a17:902:d342:b0:1d7:6800:3e63 with SMTP id l2-20020a170902d34200b001d768003e63mr598569plk.138.1706177220184; Thu, 25 Jan 2024 02:07:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706177220; cv=pass; d=google.com; s=arc-20160816; b=1IZfQjM/LEPjw3MUBAPsq16FrB1ePvpCFQoCt9Vo4f+ws03Jyq+FWZXPmsA32HaxtP 09YnikSOLcTEYkn1y0eqsEEPmrZu132KmvaZali9RCMUdmw0+Vwl7q8uVwiDgkY3LyQX 0OI2cC4N51fGQEkkMdk4w4TeMOjyx/klumZ3/2FFaqkaVOwCI10e1YZNL2aUbfnLc+Pa 3aLW6mOYcgylUpf7cmWWpGmpL4DzociT89fv9vI5wDEZDxY+d+HtipTC7s+i82wBdXZN 0bPRF9v1pUytcc2652G++ZuGCZFLgZGsZnTSUcclPPj4ULTsjA/aYEm3Sfo+N2bq2NxF b8Bw== 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=KgwnvTs6zlqZuknxVAS5A5U3nZ4c2cRgjAzJeKYuLG8=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=YQA3KyeiWIG5lTAWFsRRs5y17XWTOey9mBaWLuIIbQaWks2zpmyHfthlszPRA1FRGN ih4e4dCxqxcSAsCy4TP5JAWIK7mZqnEYRepiLSgX7wUWNJqzonlOqR5GtBVD0jmPSF+L FLmw4e/zFv4UeWwe2kEJrdVgeVNUlmk8gVmo1tIlcc/noJiwZxa3M+j0J7IuJPmLlL1L 7YG4PiU+8kehx85dvuhiAJvGe/1Zl0iL24xUOoCyYYlvmsIBhRsE1TAFPduSDFf4PRvR Th6JZraHujpKM1AIX/0vaWH/4ppGtBNHN/EbKcudhB8LBcv7lyG7tHbuEV4PhDaE4ntE o87Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NrDb1FaB; 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-38265-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38265-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 l12-20020a170902eb0c00b001d7215e9760si10673896plb.261.2024.01.25.02.06.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 02:07:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38265-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=NrDb1FaB; 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-38265-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38265-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 E6467B2DD3A for ; Thu, 25 Jan 2024 09:31:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 101931D53D; Thu, 25 Jan 2024 09:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="NrDb1FaB" 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 BB44E1CAA4 for ; Thu, 25 Jan 2024 09:29:03 +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=1706174945; cv=none; b=Jre9SppWHXQUMIkh0Xlqc7eE4vL4pz2Z1pCvpiY3zDCqXcs+MVkQ1ZfBhyVUqx3UcBzrDz8v4LXKRUIlCTJoc0xVEnwtm7ZN0nB3HeRCtFZLyvDqC5GeLTfo9wrndgMUHf3KsCTHQY6UjNIljv7QByGHC7WVWseK9igeZPMWuW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706174945; c=relaxed/simple; bh=MuHOFFDvhunWa09yCKieBQeofTJm5hUil4z2V5RP7/c=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qDj9uu5Zr6JxUSdsDRWEAgUErRj06Pi6Ky7MFYcLHAV13aNnO0Wd98q1psyg2F+gh9NjYcY/tG3KXGIvALRSL/uAEh7sN/7tlQ/2wleHPcAB0JYlQGaZrc42cZZvQkEojqqglvQXZOBhGdTYWn5Icc7X4CR/q61d+q28svKP4Yk= 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=NrDb1FaB; 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=1706174941; bh=MuHOFFDvhunWa09yCKieBQeofTJm5hUil4z2V5RP7/c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NrDb1FaBaq13ye++Lhg9rKsUJUXv0CRes27oB17iSRjJI+f260kZqghxxIZiHPzKF yG6w09yncfIcrwFhoeCGYZ/UGRPOvZj+BlKCoxh0Kbrzd/cMl51zO7QWS4loE7xDkx R8JmJ/OZjwElQbafLdkoQovcnyaDjPRBNW5oDS+E7/hS0AKI10hMKA1rvqLulArOiC /gg8mIL23r6i4JVwuVbbfG5bPGMGvlO5PRxPX3vXd/g/7vPtHw838An9VQnD8DfxH8 vXnkf3u1PESFA9piBvV8wC2PNTy0r3VVjSEBCViVMZWseP6/oklRc8Ydq8iLOdBE1v tbEsIRBp4/X9w== 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 E09AB378000B; Thu, 25 Jan 2024 09:29:00 +0000 (UTC) Date: Thu, 25 Jan 2024 10:28:59 +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 24/30] drm/shmem-helper: Optimize unlocked get_pages_sgt() Message-ID: <20240125102859.6d8a864f@collabora.com> In-Reply-To: <20240105184624.508603-25-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-25-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:18 +0300 Dmitry Osipenko wrote: > SGT isn't refcounted. Once SGT pointer has been obtained, it remains the > same for both locked and unlocked get_pages_sgt(). Return cached SGT > directly without taking a potentially expensive lock. > > Signed-off-by: Dmitry Osipenko Reviewed-by: Boris Brezillon but I'm wondering if we should have made this change directly in 'drm/shmem-helper: Change sgt allocation policy'. > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 8fd7851c088b..e6e6e693ab95 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -962,6 +962,18 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem) > drm_WARN_ON(obj->dev, drm_gem_shmem_is_purgeable(shmem))) > return ERR_PTR(-EBUSY); > > + /* > + * Drivers that use shrinker should take into account that shrinker > + * may relocate BO, thus invalidating the returned SGT pointer. > + * Such drivers should pin GEM while they use SGT. > + * > + * Drivers that don't use shrinker should take into account that > + * SGT is released together with the GEM pages. Pages should be kept > + * alive while SGT is used. > + */ > + if (shmem->sgt) > + return shmem->sgt; > + > ret = dma_resv_lock_interruptible(shmem->base.resv, NULL); > if (ret) > return ERR_PTR(ret);