Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp320627rdb; Fri, 5 Jan 2024 10:53:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAY5w4IakBdyCSoEBxjxIKYqN5IEBFoHQxa4A3TRfpgRwrDJTKVWiKIQcGhP8t1U0qleon X-Received: by 2002:a17:907:845:b0:a27:f950:4575 with SMTP id ww5-20020a170907084500b00a27f9504575mr3210493ejb.12.1704480785292; Fri, 05 Jan 2024 10:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480785; cv=none; d=google.com; s=arc-20160816; b=wAGEgKZkRjDAZnLcask6vo5jTlKi2M+66KzO6WKRpKBonWCa8K3cuZPpIbJnxKBMJZ GsoVjQLqu44Q4wd0dyoCJHzhxC3Grue9YPFjgc+7xpuxUQfma1iPD3WC4obIfb0ghbER 48ALt/WVwMH4+rN9tntoNsZ8YJUt3QEISV1Ro8/+wRKbvTX5YqeKxmgNtC8Y7kLNy8up ymEGVVlYxkvaok86t0YAzKCLBha2lls5UPZthu24HNpl7k4rvZWuEh3Bezxo4BhXFmF7 iUiw7lDQqs/Aw8dKHcXQ9woSmp4GMYWBaHdjcxmSUmk/7tXCh16jthL+SiC56q9RaME5 f3Kg== 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=WkDVJRo3kCdmEo0wBEcQ2vQNZN1Vw/Tb2tnQ+0ISayw=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=ioAfmmD0frcFEMbj+vUTZhgtZALEixuNG860nNZZxEiPbOKxiI5zSJW8W56p0DepOJ 8TC18SmPVMqcPLwXSZL4Ubuil5ncgz+Q84GuKjA89o7uYEkaVGLTZ0mwl8Ld5jiNIWqp o6Y76vDWZNmlRvIQ/QoSRJ7lqyBgp+Cl3o4GfrGrHfZ7v/jvbVC0VE/KAUBqVGNnvRa/ Qt6KV2dmoYm48s69GeUsznTEyV8phin5N0KH8uw3MwMkd3UEkxkpTBRybjMuhXPlPJci wElehX0o9UxQ98/qgRBtE+/Vc9aMy81KzmBPKxryjxNiiBQak873c1GEpmn4iPnqd2mE +mnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=RGppGiad; spf=pass (google.com: domain of linux-kernel+bounces-18262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lf11-20020a170906ae4b00b00a1b7f7c8118si796223ejb.177.2024.01.05.10.53.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=RGppGiad; spf=pass (google.com: domain of linux-kernel+bounces-18262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18262-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0E72B1F246B5 for ; Fri, 5 Jan 2024 18:53:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC5BA3B297; Fri, 5 Jan 2024 18:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="RGppGiad" 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 D12443A8F8 for ; Fri, 5 Jan 2024 18:47:24 +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=1704480443; bh=0EkorB7mGPNDlGWHg99Nm8EGClX4jIfjE4CRLhc0fAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGppGiadlpknVJqbMhfDp1lvlPAp9TkSEX0q/EJ0Huh2rNnWwCelriirktxoBJab+ OBxtKcS0p3Gl7+D9rSBxsnCAe3o6FuTyICpXTIEOkx7RYZbo27iW3nR4ciLz1gbbef yt1/BSGQKTWNuZj88DDNbTo8LgaJ8kcv3Mdy57S/d5EAy423YIjpE8ow69Ha9dj3kE VfBSnwK7CzGE6GJEf8pQV1/EGfsRtvGrn+n7VEa3M/oGgM7bJZwmmEIGSaoFFDXN34 j1dBqf20ce5nEqbVS2CcL7gU4BhHY1s65YTl1XCXZ26RAK5t7JVQt8egKqT6kHj6kZ 20zdOgB7Zt3BQ== 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 AA0D53782067; Fri, 5 Jan 2024 18:47:21 +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 24/30] drm/shmem-helper: Optimize unlocked get_pages_sgt() Date: Fri, 5 Jan 2024 21:46:18 +0300 Message-ID: <20240105184624.508603-25-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 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 --- 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); -- 2.43.0