From nobody Thu Jan 30 17:34:42 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 AE9E714A4E1; Thu, 23 Jan 2025 22:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672866; cv=pass; b=SnMyWFIVqWDlmQz1ntW7qLcn/TDoFdL6zruWSPRZ04S8wTDfHbfcFRJ9i/pFAJgpc6Hr2JN0jjFUjILxLw331SOlTkeViWOzQ/peia7uhZSEOk7Y8eDGI89etSM3fUHW5PaIpcveEQkFxysP01wWquL69Sos89XAEZABinvP2Wo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672866; c=relaxed/simple; bh=1HAcPuBDpSLwG4zt1gIEj18I/4Inntxrv5UL7A4fAow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ou2Ms3SdryawhTs8Ygpe/hOloCOkRg23YTcraK2I/oyUj1iemvIRoQwT9HalWBbQ3q3JgBOtJUXwNg6RZHZh1kTmnFlgMl5MwRyajTwREmCRDUK2BhbfTWE5tOr0rxKrOaFFts/Cu9oPzFcP3s0NVqzqDnddSFH2qlP3qd6C1/Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=CSwFRLle; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="CSwFRLle" ARC-Seal: i=1; a=rsa-sha256; t=1737672836; cv=none; d=zohomail.com; s=zohoarc; b=RrvFipjO8WRJ5qrEobVXcCt1+poXZM1VauP7CH5IckhWlIVZg/dEBhmtDgYeWztQf0+qrWEjTr7crQfGcXwu3ZzpjPvyxV2CM8b43mEjMAl4kNxh4FciZnV7N/09d08lTy4f3D4Me6r9o0k01e3q21AUKfGKCl2lgdwFV4WKZdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737672836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=P7YSgOBT4ZEydHi6CBZLDANUBg1ODh9pUPQasV9rKe4=; b=P3sq+tp8W1iD38Z9QHugqyH1NGY4Z/lwF/83DVG2zK9pHrNMmZVYPgi3z8I8v49jok2ozFM6XTXRs4cNJwuCGQzEgGa5J/Qlal15TiTBSvcKv3ANAOmNbKDxnTDt46KLobJOuO5zY+BEt0tyyujqQRQMkfB+C/DO097SOwagnT4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1737672836; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=P7YSgOBT4ZEydHi6CBZLDANUBg1ODh9pUPQasV9rKe4=; b=CSwFRLleudBtmmIgvIWZZjmpY2QRGEP9OFbfHIJIbhGbNVquYk8sFPt01KVQD/zl lvvB7tGA3F/6gwFx0eZVycSRHuonUO128n+l1V76YnvGhgG2lmnVhuPo2zgdcCf5vfj 78S8FN6IkD9rN4cEnJrLj0Y9SoB1iX/Wb+UX6qhc= Received: by mx.zohomail.com with SMTPS id 1737672830663713.3510044597829; Thu, 23 Jan 2025 14:53:50 -0800 (PST) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Boris Brezillon , Steven Price , Liviu Dudau Cc: kernel@collabora.com, Tvrtko Ursulin , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= Subject: [PATCH v9 1/5] Documentation/gpu: Clarify format of driver-specific fidnfo keys Date: Thu, 23 Jan 2025 22:52:58 +0000 Message-ID: <20250123225325.3271764-2-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123225325.3271764-1-adrian.larumbe@collabora.com> References: <20250123225325.3271764-1-adrian.larumbe@collabora.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable This change reflects de facto usage by amdgpu, as exemplified by commit d6530c33a978 ("drm/amdgpu: expose more memory stats in fdinfo"). Signed-off-by: Adri=C3=A1n Larumbe Cc: Tvrtko Ursulin Acked-by: Tvrtko Ursulin --- Documentation/gpu/drm-usage-stats.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/gpu/drm-usage-stats.rst b/Documentation/gpu/drm-= usage-stats.rst index 2717cb2a597e..2b5393ed7692 100644 --- a/Documentation/gpu/drm-usage-stats.rst +++ b/Documentation/gpu/drm-usage-stats.rst @@ -21,7 +21,10 @@ File format specification =20 - File shall contain one key value pair per one line of text. - Colon character (`:`) must be used to delimit keys and values. -- All keys shall be prefixed with `drm-`. +- All standardised keys shall be prefixed with `drm-`. +- Driver-specific keys shall be prefixed with `driver_name-`, where + driver_name should ideally be the same as the `name` field in + `struct drm_driver`, although this is not mandatory. - Whitespace between the delimiter and first non-whitespace character shal= l be ignored when parsing. - Keys are not allowed to contain whitespace characters. --=20 2.47.1 From nobody Thu Jan 30 17:34:42 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 CD5C31D5AB9; Thu, 23 Jan 2025 22:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672868; cv=pass; b=OghkLh1YXBqtNajoeKa8YZi0YCdSCnZNvVcBK7ZKt0sdyPslidIR7wBS51eJUYuhkjbRYaIfmWehhSrZeLry2i6yLFPVkzCxDe1BSG0ozOf90UxmxzPjuPc7zHwQzX+AwcsgZSEXcxMqY980sXUrqnlluZfeVhgsTONWcH+0/1Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672868; c=relaxed/simple; bh=7Iaw0Q3yfjikZsdb4D4NSwZv5asi4vxfkqwsPAx3gnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dzkroa9OfCKELII58Z0cgEjCu/9C2rVT/cNuPyGpjIZx/MrshlP5uHOgmu2NKpkHk2ENbQPxm2in/AsIdXDnlHInFss6e4lMDNDwfqyT3zyh66WoxufhUnKptQCXRjHh8xhgXn+VoX7ZQQbTL0+4MzFRlCMA4GE0HTDl+Rk/t/U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=dg9kK+RD; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="dg9kK+RD" ARC-Seal: i=1; a=rsa-sha256; t=1737672839; cv=none; d=zohomail.com; s=zohoarc; b=OIKsIW1T5TCnyUsqTHVCjnxgp8hXeUQdnWTS6sg+igKiE3QgJxsAZDzAmkWfHIOGTK9WmpZvHcQZ8JpF7Zo3SoT+p2hv9DYPcCFCo+Ffbp2wdd+U9SKmLwagceA4V6wUxyfAWjZoifrhXHJModHyH2PxIBI7l3zAXpvMW557dwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737672839; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=5B2acTEKnWj2iTXPsUJ8KYfflSwtBpaFyWuQX+dPJzY=; b=P2WfsRK5tuKMTJr4KSPZlmFox4c2/4YClLY0SgFoKu78vidhOMwx6qzCz3Jgc55xDirAd8jl/DvQN42OccfqqjhCXcu1LJZvx91mv2MqxORbrRzI/owSXh5sj4axdsGmabkUKgAFjpBU/akI1KMWWJ6f0BSgAX7KTW6DUCn4giU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1737672839; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=5B2acTEKnWj2iTXPsUJ8KYfflSwtBpaFyWuQX+dPJzY=; b=dg9kK+RDDrAI9xt333y5yYrZx9pZbQu0JwKGFVr/pzo8sk42wYkzJcCUjLccEH8l iou6Ds7A3NqnJ9kSaxAVP1L6j52eD9Nua1NgRa042CXFL6S6ztKIbpoFGeI10v6+eHx YDnK7CfOR+qjRyqOo20D67vGwg7MXGYYlVvOoDlo= Received: by mx.zohomail.com with SMTPS id 17376728351061015.34983545301; Thu, 23 Jan 2025 14:53:55 -0800 (PST) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Boris Brezillon , Steven Price , Liviu Dudau Cc: kernel@collabora.com, Tvrtko Ursulin , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= Subject: [PATCH v9 2/5] drm/file: Add fdinfo helper for printing regions with prefix Date: Thu, 23 Jan 2025 22:52:59 +0000 Message-ID: <20250123225325.3271764-3-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123225325.3271764-1-adrian.larumbe@collabora.com> References: <20250123225325.3271764-1-adrian.larumbe@collabora.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable This is motivated by the desire of some drivers (eg. Panthor) to print the size of internal memory regions with a prefix that reflects the driver name, as suggested in the previous documentation commit. That means adding a new argument to print_size and making it available for DRM users. Signed-off-by: Adri=C3=A1n Larumbe Cc: Tvrtko Ursulin --- drivers/gpu/drm/drm_file.c | 27 +++++++++++++++++++-------- include/drm/drm_file.h | 5 +++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index cb5f22f5bbb6..f584abcd13cb 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -830,8 +830,12 @@ void drm_send_event(struct drm_device *dev, struct drm= _pending_event *e) } EXPORT_SYMBOL(drm_send_event); =20 -static void print_size(struct drm_printer *p, const char *stat, - const char *region, u64 sz) + +void drm_fdinfo_print_size(struct drm_printer *p, + const char *prefix, + const char *stat, + const char *region, + u64 sz) { const char *units[] =3D {"", " KiB", " MiB"}; unsigned u; @@ -842,8 +846,10 @@ static void print_size(struct drm_printer *p, const ch= ar *stat, sz =3D div_u64(sz, SZ_1K); } =20 - drm_printf(p, "drm-%s-%s:\t%llu%s\n", stat, region, sz, units[u]); + drm_printf(p, "%s-%s-%s:\t%llu%s\n", + prefix, stat, region, sz, units[u]); } +EXPORT_SYMBOL(drm_fdinfo_print_size); =20 /** * drm_print_memory_stats - A helper to print memory stats @@ -858,15 +864,20 @@ void drm_print_memory_stats(struct drm_printer *p, enum drm_gem_object_status supported_status, const char *region) { - print_size(p, "total", region, stats->private + stats->shared); - print_size(p, "shared", region, stats->shared); - print_size(p, "active", region, stats->active); + const char *prefix =3D "drm"; + + drm_fdinfo_print_size(p, prefix, "total", region, + stats->private + stats->shared); + drm_fdinfo_print_size(p, prefix, "shared", region, stats->shared); + drm_fdinfo_print_size(p, prefix, "active", region, stats->active); =20 if (supported_status & DRM_GEM_OBJECT_RESIDENT) - print_size(p, "resident", region, stats->resident); + drm_fdinfo_print_size(p, prefix, "resident", region, + stats->resident); =20 if (supported_status & DRM_GEM_OBJECT_PURGEABLE) - print_size(p, "purgeable", region, stats->purgeable); + drm_fdinfo_print_size(p, prefix, "purgeable", region, + stats->purgeable); } EXPORT_SYMBOL(drm_print_memory_stats); =20 diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index f0ef32e9fa5e..001ae553e8c3 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -494,6 +494,11 @@ struct drm_memory_stats { =20 enum drm_gem_object_status; =20 +void drm_fdinfo_print_size(struct drm_printer *p, + const char *prefix, + const char *stat, + const char *region, + u64 sz); void drm_print_memory_stats(struct drm_printer *p, const struct drm_memory_stats *stats, enum drm_gem_object_status supported_status, --=20 2.47.1 From nobody Thu Jan 30 17:34:42 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 8A6581E0B91; Thu, 23 Jan 2025 22:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672872; cv=pass; b=C6Ry8oAZos5xNYVq2e7+T61oiGK0hZqzoIYr4E9Ejn90caY/odw+G3OORX1Azfcm389YGxQYXWTluVBxIsSgpRRXJdETmiPyaPNWUz8uHQFO/gnQ4bKl0CGPUDXWR8pjJaj/iZXy7JVlABCq9EVOeUHFp8MbLWedVZkKT3WOXIU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672872; c=relaxed/simple; bh=qhLPQrPjCb63bWSxcdtX/+opkGTy0oHWAlQ/x43Blvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r7nTZjISD3iiVr3lAvRoGnyT2PP/i3a2asaga/VaBd8Qs6PGkF3e7SWzRFwij+KVOsz1biJ0DIZe+U4hW4JkO/VsiDC/CZPepE1AAtalbuiiGjKAWA7u4oTOuRT0my16+OLcI96//qSHlj1T4eddvZ3P6Zyj9vkHZNJgdbvTUnE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=VXKDLoIJ; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="VXKDLoIJ" ARC-Seal: i=1; a=rsa-sha256; t=1737672843; cv=none; d=zohomail.com; s=zohoarc; b=EMMlfx7/xH+PEH3f08jCMzorGzG+Tb6HDODWX9XN5+TnAMTwj6dtJ7NdLBkAeEPMtEOLX2222nlg6m9+b28lbT+buqS8m4wM2FLeonEm0aqy3HkLRLHP8Gp235SdwECBBXYK02liTa3KIEEFAdaS96g9T/pWzqeCmcJyI6mFayg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737672843; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=KFOUw++dizLGwK/6QWFx9YW7apnArTlQh1uIfAIlvD8=; b=Z/bIC/fzGGWmlJGqhcHGEjpH7t55uw9oynY/9cTjsCfZTSJsZZKjHQtG06hHQzWSKnron28nSQwsa9+HY8fQp7cnDNkLW1AMq3ehDGwYoop9AMNogOMFJkdOtgMKHQSMq+3CaYDQ0DtDGbsNCPpXSVAfhHelK0UwdoeFemZJ/GM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1737672843; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=KFOUw++dizLGwK/6QWFx9YW7apnArTlQh1uIfAIlvD8=; b=VXKDLoIJ7yyAXb9pJ8tCYuwINClMAOFE8jxBHHYMXqtBPppWiCMNqI+RY2PsJL3A T5Do2XMZePsGOjP5LcIBM91jYXHmWVvSeaU8PDkM5ralppu6XMGptbhILVvhe7vq45B 2gUFAZ3iPtYNOGfQcMuXPT1UZpGsWRFjOiPePexI= Received: by mx.zohomail.com with SMTPS id 1737672839518335.73426000744485; Thu, 23 Jan 2025 14:53:59 -0800 (PST) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Boris Brezillon , Steven Price , Liviu Dudau Cc: kernel@collabora.com, Tvrtko Ursulin , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= , Mihail Atanassov Subject: [PATCH v9 3/5] drm/panthor: Expose size of driver internal BO's over fdinfo Date: Thu, 23 Jan 2025 22:53:00 +0000 Message-ID: <20250123225325.3271764-4-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123225325.3271764-1-adrian.larumbe@collabora.com> References: <20250123225325.3271764-1-adrian.larumbe@collabora.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable This will display the sizes of kenrel BO's bound to an open file, which are otherwise not exposed to UM through a handle. The sizes recorded are as follows: - Per group: suspend buffer, protm-suspend buffer, syncobjcs - Per queue: ringbuffer, profiling slots, firmware interface - For all heaps in all heap pools across all VM's bound to an open file, record size of all heap chuks, and for each pool the gpu_context BO too. This does not record the size of FW regions, as these aren't bound to a specific open file and remain active through the whole life of the driver. Reviewed-by: Liviu Dudau Reviewed-by: Mihail Atanassov Reviewed-by: Steven Price Signed-off-by: Adri=C3=A1n Larumbe Reviewed-by: Boris Brezillon --- drivers/gpu/drm/panthor/panthor_drv.c | 14 +++++++ drivers/gpu/drm/panthor/panthor_heap.c | 26 ++++++++++++ drivers/gpu/drm/panthor/panthor_heap.h | 2 + drivers/gpu/drm/panthor/panthor_mmu.c | 36 ++++++++++++++++ drivers/gpu/drm/panthor/panthor_mmu.h | 3 ++ drivers/gpu/drm/panthor/panthor_sched.c | 56 ++++++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_sched.h | 3 ++ 7 files changed, 139 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index ac7e53f6e3f0..d5f98598d8d7 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -1457,12 +1457,26 @@ static void panthor_gpu_show_fdinfo(struct panthor_= device *ptdev, drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); } =20 +static void panthor_show_internal_memory_stats(struct drm_printer *p, stru= ct drm_file *file) +{ + char *drv_name =3D file->minor->dev->driver->name; + struct panthor_file *pfile =3D file->driver_priv; + struct drm_memory_stats stats =3D {0}; + + panthor_fdinfo_gather_group_mem_info(pfile, &stats); + panthor_vm_heaps_sizes(pfile, &stats); + + drm_fdinfo_print_size(p, drv_name, "resident", "memory", stats.resident); + drm_fdinfo_print_size(p, drv_name, "active", "memory", stats.active); +} + static void panthor_show_fdinfo(struct drm_printer *p, struct drm_file *fi= le) { struct drm_device *dev =3D file->minor->dev; struct panthor_device *ptdev =3D container_of(dev, struct panthor_device,= base); =20 panthor_gpu_show_fdinfo(ptdev, file->driver_priv, p); + panthor_show_internal_memory_stats(p, file); =20 drm_show_memory_stats(p, file); } diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panth= or/panthor_heap.c index 3796a9eb22af..db0285ce5812 100644 --- a/drivers/gpu/drm/panthor/panthor_heap.c +++ b/drivers/gpu/drm/panthor/panthor_heap.c @@ -603,3 +603,29 @@ void panthor_heap_pool_destroy(struct panthor_heap_poo= l *pool) =20 panthor_heap_pool_put(pool); } + +/** + * panthor_heap_pool_size() - Calculate size of all chunks across all heap= s in a pool + * @pool: Pool whose total chunk size to calculate. + * + * This function adds the size of all heap chunks across all heaps in the + * argument pool. It also adds the size of the gpu contexts kernel bo. + * It is meant to be used by fdinfo for displaying the size of internal + * driver BO's that aren't exposed to userspace through a GEM handle. + * + */ +size_t panthor_heap_pool_size(struct panthor_heap_pool *pool) +{ + struct panthor_heap *heap; + unsigned long i; + size_t size =3D 0; + + down_read(&pool->lock); + xa_for_each(&pool->xa, i, heap) + size +=3D heap->chunk_size * heap->chunk_count; + up_read(&pool->lock); + + size +=3D pool->gpu_contexts->obj->size; + + return size; +} diff --git a/drivers/gpu/drm/panthor/panthor_heap.h b/drivers/gpu/drm/panth= or/panthor_heap.h index 25a5f2bba445..e3358d4e8edb 100644 --- a/drivers/gpu/drm/panthor/panthor_heap.h +++ b/drivers/gpu/drm/panthor/panthor_heap.h @@ -27,6 +27,8 @@ struct panthor_heap_pool * panthor_heap_pool_get(struct panthor_heap_pool *pool); void panthor_heap_pool_put(struct panthor_heap_pool *pool); =20 +size_t panthor_heap_pool_size(struct panthor_heap_pool *pool); + int panthor_heap_grow(struct panthor_heap_pool *pool, u64 heap_gpu_va, u32 renderpasses_in_flight, diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/pantho= r/panthor_mmu.c index c3f0b0225cf9..762ebf46f71a 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -1941,6 +1941,42 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(s= truct panthor_vm *vm, bool c return pool; } =20 +/** + * panthor_vm_heaps_sizes() - Calculate size of all heap chunks across all + * heaps over all the heap pools in a VM + * @pfile: File. + * @stats: Memory stats to be updated. + * + * Calculate all heap chunk sizes in all heap pools bound to a VM. If the = VM + * is active, record the size as active as well. + */ +void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_= stats *stats) +{ + struct panthor_vm *vm; + unsigned long i; + + if (!pfile->vms) + return; + + xa_lock(&pfile->vms->xa); + xa_for_each(&pfile->vms->xa, i, vm) { + size_t size; + + mutex_lock(&vm->heaps.lock); + if (!vm->heaps.pool) { + mutex_unlock(&vm->heaps.lock); + continue; + } + size =3D panthor_heap_pool_size(vm->heaps.pool); + mutex_unlock(&vm->heaps.lock); + + stats->resident +=3D size; + if (vm->as.id >=3D 0) + stats->active +=3D size; + } + xa_unlock(&pfile->vms->xa); +} + static u64 mair_to_memattr(u64 mair, bool coherent) { u64 memattr =3D 0; diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/pantho= r/panthor_mmu.h index 8d21e83d8aba..fc274637114e 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.h +++ b/drivers/gpu/drm/panthor/panthor_mmu.h @@ -9,6 +9,7 @@ =20 struct drm_exec; struct drm_sched_job; +struct drm_memory_stats; struct panthor_gem_object; struct panthor_heap_pool; struct panthor_vm; @@ -37,6 +38,8 @@ int panthor_vm_flush_all(struct panthor_vm *vm); struct panthor_heap_pool * panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create); =20 +void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_= stats *stats); + struct panthor_vm *panthor_vm_get(struct panthor_vm *vm); void panthor_vm_put(struct panthor_vm *vm); struct panthor_vm *panthor_vm_create(struct panthor_device *ptdev, bool fo= r_mcu, diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index ef4bec7ff9c7..e6c08a694e41 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -618,7 +618,7 @@ struct panthor_group { */ struct panthor_kernel_bo *syncobjs; =20 - /** @fdinfo: Per-file total cycle and timestamp values reference. */ + /** @fdinfo: Per-file info exposed through /proc//fdinfo */ struct { /** @data: Total sampled values for jobs in queues from this group. */ struct panthor_gpu_usage data; @@ -628,6 +628,9 @@ struct panthor_group { * and job post-completion processing function */ struct mutex lock; + + /** @fdinfo.kbo_sizes: Aggregate size of private kernel BO's held by the= group. */ + size_t kbo_sizes; } fdinfo; =20 /** @state: Group state. */ @@ -3365,6 +3368,29 @@ group_create_queue(struct panthor_group *group, return ERR_PTR(ret); } =20 +static void add_group_kbo_sizes(struct panthor_device *ptdev, + struct panthor_group *group) +{ + struct panthor_queue *queue; + int i; + + if (drm_WARN_ON(&ptdev->base, IS_ERR_OR_NULL(group))) + return; + if (drm_WARN_ON(&ptdev->base, ptdev !=3D group->ptdev)) + return; + + group->fdinfo.kbo_sizes +=3D group->suspend_buf->obj->size; + group->fdinfo.kbo_sizes +=3D group->protm_suspend_buf->obj->size; + group->fdinfo.kbo_sizes +=3D group->syncobjs->obj->size; + + for (i =3D 0; i < group->queue_count; i++) { + queue =3D group->queues[i]; + group->fdinfo.kbo_sizes +=3D queue->ringbuf->obj->size; + group->fdinfo.kbo_sizes +=3D queue->iface.mem->obj->size; + group->fdinfo.kbo_sizes +=3D queue->profiling.slots->obj->size; + } +} + #define MAX_GROUPS_PER_POOL 128 =20 int panthor_group_create(struct panthor_file *pfile, @@ -3489,6 +3515,7 @@ int panthor_group_create(struct panthor_file *pfile, } mutex_unlock(&sched->reset.lock); =20 + add_group_kbo_sizes(group->ptdev, group); mutex_init(&group->fdinfo.lock); =20 return gid; @@ -3606,6 +3633,33 @@ void panthor_group_pool_destroy(struct panthor_file = *pfile) pfile->groups =3D NULL; } =20 +/** + * panthor_group_kbo_sizes() - Retrieve aggregate size of all private kern= el BO's + * belonging to all the groups owned by an open Panthor file + * @pfile: File. + * @stats: Memory statistics to be updated. + * + */ +void +panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile, + struct drm_memory_stats *stats) +{ + struct panthor_group_pool *gpool =3D pfile->groups; + struct panthor_group *group; + unsigned long i; + + if (IS_ERR_OR_NULL(gpool)) + return; + + xa_lock(&gpool->xa); + xa_for_each(&gpool->xa, i, group) { + stats->resident +=3D group->fdinfo.kbo_sizes; + if (group->csg_id >=3D 0) + stats->active +=3D group->fdinfo.kbo_sizes; + } + xa_unlock(&gpool->xa); +} + static void job_release(struct kref *ref) { struct panthor_job *job =3D container_of(ref, struct panthor_job, refcoun= t); diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/pant= hor/panthor_sched.h index 5ae6b4bde7c5..e650a445cf50 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.h +++ b/drivers/gpu/drm/panthor/panthor_sched.h @@ -9,6 +9,7 @@ struct dma_fence; struct drm_file; struct drm_gem_object; struct drm_sched_job; +struct drm_memory_stats; struct drm_panthor_group_create; struct drm_panthor_queue_create; struct drm_panthor_group_get_state; @@ -36,6 +37,8 @@ void panthor_job_update_resvs(struct drm_exec *exec, stru= ct drm_sched_job *job); =20 int panthor_group_pool_create(struct panthor_file *pfile); void panthor_group_pool_destroy(struct panthor_file *pfile); +void panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile, + struct drm_memory_stats *stats); =20 int panthor_sched_init(struct panthor_device *ptdev); void panthor_sched_unplug(struct panthor_device *ptdev); --=20 2.47.1 From nobody Thu Jan 30 17:34:42 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 0456A1D5CDE; Thu, 23 Jan 2025 22:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672894; cv=pass; b=jLAoDX7iWAJPZ9nDje0rhiE2ch5owhyii5b020kOGCmqQkUQtIOZrDMsZXKIHyeDSnNy01yjI0eua0QvSrT6tlLCnlgNH0n37iF0rkYYJfr9gHuOC01mES8V+1WYTS6HZzYtiWIv7cKdE1rfnoqCMrjp4TVvg8W1wPjjCQSi9c8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672894; c=relaxed/simple; bh=+ytlbxanqKXQoq654hT86yilOdoDjjJKwJIt1kbMwPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OsXsRfcWZ5HipA/+aRHxEYkFokyzWwS/PRj/KFlOCYn0Nl725cyGPzB6q8lCyndVabyqpjLp37gjydaFqjecNBlIhnTl/anN/46ni/qPzppMhjkSJ0CQE6NI6asebF0Z9aUlsh/97WyoaQl/6tHZ8PYpjnhCgMA0LFxueQjdf1w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=OnUKJ5gO; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="OnUKJ5gO" ARC-Seal: i=1; a=rsa-sha256; t=1737672866; cv=none; d=zohomail.com; s=zohoarc; b=EgxBKy6VlMxQpqkbL/NBkwhaa210n/xjKDIFHCqyIAJYmnaKajJPai9bfwEntxQE67NW3oVWqfjozTvFB3qkJmxPciK156XzJFyO7oUvb8eBCBpFhXjXf912d0ke1pl3XOlbRDtsRg7oCb16sndNepj1xCV7MUY0rK9CmnLqsS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737672866; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=0WA6J/EhS4KkqUnGdo0KmY73cb+vgz8J3JE8d3pK9ns=; b=hZzPYEMRYTe9HBPQN9+bMdLi9mxjT7VXmnrhvJ3OGRL0FlVUb0hZ9wYmmOckgxAt5T/qtA1MhmtEyzfdh2tzZRc8vLb19sjwECMz7JdMdssYL/oazO38Ro1SPOqTSEmDES0zh4QW0BkmrkdfYBAQ2gqX+4P0rqlzu3Ar7vv1RZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1737672866; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=0WA6J/EhS4KkqUnGdo0KmY73cb+vgz8J3JE8d3pK9ns=; b=OnUKJ5gO41GZOsaD0yPVzClsk6KH1jDftfbUwtFX1AdjyNXMPa0Dmzu8LBEsptWd BImKk3VevVhx+m4iVstP4jqOOVodgY79Kp0yn8oTeeC3ItQK7kO98l/TmNOtgXyJm4k CwNKs9I/P3Y3Rl0kFV82lD5R4vg38yn6r6r2biIU= Received: by mx.zohomail.com with SMTPS id 1737672844149522.6050164964226; Thu, 23 Jan 2025 14:54:04 -0800 (PST) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Boris Brezillon , Steven Price , Liviu Dudau Cc: kernel@collabora.com, Tvrtko Ursulin , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= , Mihail Atanassov Subject: [PATCH v9 4/5] Documentation/gpu: Add fdinfo meanings of panthor-*-memory tags Date: Thu, 23 Jan 2025 22:53:01 +0000 Message-ID: <20250123225325.3271764-5-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123225325.3271764-1-adrian.larumbe@collabora.com> References: <20250123225325.3271764-1-adrian.larumbe@collabora.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable A previous commit enabled display of driver-internal kernel BO sizes through the device file's fdinfo interface. Expand the description of the relevant driver-specific key:value pairs with the definitions of the new panthor-*-memory ones. Reviewed-by: Mihail Atanassov Reviewed-by: Liviu Dudau Reviewed-by: Steven Price Signed-off-by: Adri=C3=A1n Larumbe --- Documentation/gpu/panthor.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/gpu/panthor.rst b/Documentation/gpu/panthor.rst index 3f8979fa2b86..7a841741278f 100644 --- a/Documentation/gpu/panthor.rst +++ b/Documentation/gpu/panthor.rst @@ -26,6 +26,8 @@ the currently possible format options: drm-cycles-panthor: 94439687187 drm-maxfreq-panthor: 1000000000 Hz drm-curfreq-panthor: 1000000000 Hz + panthor-resident-memory: 10396 KiB + panthor-active-memory: 10396 KiB drm-total-memory: 16480 KiB drm-shared-memory: 0 drm-active-memory: 16200 KiB @@ -44,3 +46,11 @@ driver by writing into the appropriate sysfs node:: =20 Where `N` is a bit mask where cycle and timestamp sampling are respectively enabled by the first and second bits. + +Possible `panthor-*-memory` keys are: `active` and `resident`. +These values convey the sizes of the internal driver-owned shmem BO's that +aren't exposed to user-space through a DRM handle, like queue ring buffers, +sync object arrays and heap chunks. Because they are all allocated and pin= ned +at creation time, only `panthor-resident-memory` is necessary to tell us t= heir +size. `panthor-active-memory` shows the size of kernel BO's associated with +VM's and groups currently being scheduled for execution by the GPU. --=20 2.47.1 From nobody Thu Jan 30 17:34:42 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 044921D47AE; Thu, 23 Jan 2025 22:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672882; cv=pass; b=JLyj4eWqxmxJlhKa60nQpqVPJXakhgGTdV5angLfAUh1Faa9NsS8LlnNZnc10RDNs0kDaDruCuX1bx+aUZoyeJKNSwFBOrfSSRxjzysSGD6q0L3VPcDxqTa1+4/V5GR7XonunLmqwXXJAYav5XJBOzWQGtpq8kezNhG6ziyo0e0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672882; c=relaxed/simple; bh=Yy9M+ZRa4k5li+1MHclf9l98angTplnxLRipnAzZqPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FjPu0WCtFFPD8myOQV3r28b4HGDzaINddkS0kB7u8MNpPrqQ5cbA79ozvlXEOTOHtERyCRPOmU+ord2Mo+zYvZDw0gyyhQghNhnlvgFHW9Vvd/IH+PSgVKtwFQn28LCKPqIoIdFm+Vw1uxkJW/SPEEi9kxzprVtPL7BOHnWxHlU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b=a2TBWf4I; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.larumbe@collabora.com header.b="a2TBWf4I" ARC-Seal: i=1; a=rsa-sha256; t=1737672853; cv=none; d=zohomail.com; s=zohoarc; b=Gi13GXaRLRU9maRWP86+GFXOTgMCviEs00iZbWy3TCqNSAK8sriqMlWCuCya1eI/4l0puh2A3EAzf1Ke+VZWHhbsRffM8qxVx0fEjQRVQyDdA48BNhEOKUr+3SEyewVp9zmG9lizLTEpy0IcNHa8zuRJraHR0/p9h5mNW1E1/aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737672853; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=SD1qJSXUTw4kumBr+488Guiyeg2rLONe4Exc4Pgmzw8=; b=YaaKbKigMC4fNgWniugVlzLkoB/ebOAYIQTFawhjO9LiRWCYcWikvAvqDQKo6n3w3YU29SAkrpp8QNOwYk6AFRuCbT6r2g0bHoURsu3ev6E5twpwbMksZvxPqYjAr6UETsvOXUEyzmT9LmZBBL7dO7dmHop2LdNlAZk/x6Wb7vg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.larumbe@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1737672853; s=zohomail; d=collabora.com; i=adrian.larumbe@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=SD1qJSXUTw4kumBr+488Guiyeg2rLONe4Exc4Pgmzw8=; b=a2TBWf4Igvgr6FUPCtcoJsnj0DpccKq3sJgIjUN7sr9IO5xDn4t0JBYz8mOUy8Rp WAlrJgFEZZ/5ncsIoYB2t4mLAFjS4k403zgUG+IbXB0RElZ16XHtb26UlvR0zPR2uOy Hr8aUgqe5OVT/hR9tSIktgzKjfe8d1DIi1Kshv9M= Received: by mx.zohomail.com with SMTPS id 1737672848684325.30265129996076; Thu, 23 Jan 2025 14:54:08 -0800 (PST) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Boris Brezillon , Steven Price , Liviu Dudau Cc: kernel@collabora.com, Tvrtko Ursulin , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= Subject: [PATCH v9 5/5] drm/panthor: Fix race condition when gathering fdinfo group samples Date: Thu, 23 Jan 2025 22:53:02 +0000 Message-ID: <20250123225325.3271764-6-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123225325.3271764-1-adrian.larumbe@collabora.com> References: <20250123225325.3271764-1-adrian.larumbe@collabora.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable Commit e16635d88fa0 ("drm/panthor: add DRM fdinfo support") failed to protect access to groups with an xarray lock, which could lead to use-after-free errors. Signed-off-by: Adri=C3=A1n Larumbe Fixes: e16635d88fa0 ("drm/panthor: add DRM fdinfo support") Reviewed-by: Boris Brezillon Reviewed-by: Steven Price --- drivers/gpu/drm/panthor/panthor_sched.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index e6c08a694e41..1d283b4bab86 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -2865,6 +2865,7 @@ void panthor_fdinfo_gather_group_samples(struct panth= or_file *pfile) if (IS_ERR_OR_NULL(gpool)) return; =20 + xa_lock(&gpool->xa); xa_for_each(&gpool->xa, i, group) { mutex_lock(&group->fdinfo.lock); pfile->stats.cycles +=3D group->fdinfo.data.cycles; @@ -2873,6 +2874,7 @@ void panthor_fdinfo_gather_group_samples(struct panth= or_file *pfile) group->fdinfo.data.time =3D 0; mutex_unlock(&group->fdinfo.lock); } + xa_unlock(&gpool->xa); } =20 static void group_sync_upd_work(struct work_struct *work) --=20 2.47.1