[PATCH] lib/xe/xe_gt: Repair xe_gt_stats_get_count function

Kamil Konieczny kamil.konieczny at linux.intel.com
Thu Dec 5 14:49:49 UTC 2024


Hi Jonathan,
On 2024-12-04 at 15:46:50 +0000, Jonathan Cavitt wrote:
> Resolve the following issues:
> 
> - The target directory for the fopen does not take into consideration
>   the dri subdirectory and assumes the correct path is dri/0.  This
>   might not be the case.  Use the "minor" function and fstat to
>   generate the correct subdirectory.
> 
> - The fopen may fail and return a NULL pointer, causing the subsequent
>   fgets to generate a SIGSEGV.  Assert the file opened correctly.
> 
> - The file opened by fopen is never closed.  Close it.
> 
> Fixes: 10cefd82 ("tests/intel/xe_tlb: Add test to check TLB invalidation")
> Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/3212
> Signed-off-by: Jonathan Cavitt <jonathan.cavitt at intel.com>
> Suggested-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
> CC: Sai Gowtham Ch <sai.gowtham.ch at intel.com>
> ---
>  lib/xe/xe_gt.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/xe/xe_gt.c b/lib/xe/xe_gt.c
> index cee892af96..493bf9793f 100644
> --- a/lib/xe/xe_gt.c
> +++ b/lib/xe/xe_gt.c
> @@ -152,18 +152,28 @@ void xe_post_hang_ring(int fd, igt_hang_t arg)
>  int xe_gt_stats_get_count(int fd, int gt, const char *stat)
>  {
>  	FILE *f;
> +	struct stat st;
>  	char tlb_path[4096];
>  	char path[256];
>  	int count;
>  
> -	sprintf(path, "/sys/kernel/debug/dri/0/gt%d/stats", gt);
> +	igt_assert_eq(fstat(fd, &st), 0);
> +
> +	sprintf(path, "/sys/kernel/debug/dri/%d/gt%d/stats",
> +		minor(st.st_rdev), gt);
>  	f = fopen(path, "r");
>  
> +	igt_assert_f(f, "Failed to open /sys/kernel/debug/dri/%d/gt%d/stats",
> +		     minor(st.st_rdev), gt);
> +
>  	while (fgets(tlb_path, sizeof(tlb_path), f)) {
>  		if (strstr(tlb_path, stat) != NULL) {
>  			sscanf(tlb_path, "%*[^:]: %d", &count);
>  			break;
>  		}
>  	}
> +
> +	close(f);

I missed this, it should be fclose()
My r-b still holds,

Regards,
Kamil

> +
>  	return count;
>  }
> -- 
> 2.43.0
> 


More information about the igt-dev mailing list