From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: jonathan.cavitt@intel.com, alex.zuo@intel.com,
saurabhg.gupta@intel.com, kamil.konieczny@linux.intel.com,
sai.gowtham.ch@intel.com
Subject: [PATCH v2] lib/xe/xe_gt: Repair xe_gt_stats_get_count function
Date: Thu, 5 Dec 2024 15:27:06 +0000 [thread overview]
Message-ID: <20241205152706.5216-1-jonathan.cavitt@intel.com> (raw)
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.
v2: fclose (Kamil)
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@intel.com>
Suggested-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
CC: Sai Gowtham Ch <sai.gowtham.ch@intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.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..1f4b42ed9c 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;
}
}
+
+ fclose(f);
+
return count;
}
--
2.43.0
next reply other threads:[~2024-12-05 15:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 15:27 Jonathan Cavitt [this message]
2024-12-06 4:24 ` ✓ i915.CI.BAT: success for lib/xe/xe_gt: Repair xe_gt_stats_get_count function (rev2) Patchwork
2024-12-06 4:40 ` ✗ Xe.CI.BAT: failure " Patchwork
2024-12-06 19:45 ` Cavitt, Jonathan
2024-12-06 5:30 ` ✗ i915.CI.Full: " Patchwork
2024-12-06 19:44 ` Cavitt, Jonathan
2024-12-06 8:31 ` ✗ Xe.CI.Full: " Patchwork
2024-12-06 19:45 ` Cavitt, Jonathan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241205152706.5216-1-jonathan.cavitt@intel.com \
--to=jonathan.cavitt@intel.com \
--cc=alex.zuo@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=sai.gowtham.ch@intel.com \
--cc=saurabhg.gupta@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox