Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Sousa <gustavo.sousa@intel.com>
To: Matt Roper <matthew.d.roper@intel.com>
Cc: <igt-dev@lists.freedesktop.org>,
	Kamil Konieczny <kamil.konieczny@linux.intel.com>
Subject: Re: [PATCH i-g-t 02/10] lib/xe: Use stricter line-equality check when checking for workarounds
Date: Wed, 19 Aug 2026 18:36:40 -0300	[thread overview]
Message-ID: <875x15bxnb.fsf@intel.com> (raw)
In-Reply-To: <20260819205513.GR8279@mdroper-desk1.amr.corp.intel.com>

Matt Roper <matthew.d.roper@intel.com> writes:

> On Wed, Aug 19, 2026 at 04:32:04PM -0300, Gustavo Sousa wrote:
>> Gustavo Sousa <gustavo.sousa@intel.com> writes:
>> 
>> > Matt Roper <matthew.d.roper@intel.com> writes:
>> >
>> >> On Tue, Jul 21, 2026 at 03:59:55PM -0300, Gustavo Sousa wrote:
>> >>> Currently debugfs_file_has_wa() uses strstr() to check if a workaround
>> >>> name is present in the debugfs dump.  Using strstr() would match the
>> >>> workaround name anywhere in the dump buffer and with that we risk
>> >>> producing unexpected results if the checked workaround name happens to
>> >>> be a substring of another workaround present in the dump.
>> >>> 
>> >>> Fix that by making sure we match the workaround name with the full
>> >>> line from the dump.
>> >>
>> >> There are other parts of IGT that use regular expressions from either
>> >> POSIX (regcomp / regexec) or Glib (g_regex_new / g_regex_match).  Would
>> >> it be possible to use one of those here instead of opencoding a match
>> >> function?
>> >
>> > Yeah.  That could make this function more readable and easier to extend.
>> > I'll take a look at those options.
>> 
>> This new version of debugfs_file_has_wa() misses the fact that some
>> lines will contain multiple workarounds separated by comma.  So I
>> decided to implement a more robust version.  I have two versions, one
>> that is still not using regular expressions and another that uses POSIX
>> regcomp/regexec functions.  I have a slight preference for the former,
>> but if you prefer, we can go with the latter.  IMO, both versions are
>> more readable than the one currently proposed in this patch.
>> 
>> I would like your opinion before sending v2 of this series. :-)
>
> It might be best to ping the IGT maintainers and see what they think.
> Today IGT has a mix of open-coded string matching and two different
> styles of regular expressions.  It seems like the kind of thing they may
> want to set a standard direction for with new code.  I don't have much
> of a personal opinion.

Kamil, do you have a direction here? Feel free to add other maintainers
as well.

--
Gustavo Sousa

>
>
> Matt
>
>> 
>> Note: I also created a separate commit adding a simple test for this
>> function in lib/tests.
>> 
>> Version without regular expressions:
>> 
>>     | static bool is_eol(char c)
>>     | {
>>     |         return !c || c == '\n';
>>     | }
>>     | 
>>     | static bool is_wa_sep(char c)
>>     | {
>>     |         return isspace(c) || c == ',';
>>     | }
>>     | 
>>     | static bool debugfs_dump_has_wa(char *dump, const char *wa)
>>     | {
>>     |         size_t wa_len = strlen(wa);
>>     | 
>>     |         while (*dump) {
>>     |                 /*
>>     |                  * Each workaround name is indented by one tab
>>     |                  * character; unindented lines are used as "section
>>     |                  * names" identifying the type of workarounds that
>>     |                  * follow (e.g. "GT Workarounds", "Engine Workarounds"
>>     |                  * etc).
>>     |                  */
>>     |                 if (*dump != '\t')
>>     |                         goto next_line;
>>     | 
>>     |                 while (!is_eol(*dump)) {
>>     |                         char *other_wa;
>>     | 
>>     |                         while (!is_eol(*dump) && is_wa_sep(*dump))
>>     |                                 dump++;
>>     | 
>>     |                         other_wa = dump;
>>     | 
>>     |                         while (!is_eol(*dump) && !is_wa_sep(*dump))
>>     |                                 dump++;
>>     | 
>>     |                         if (wa_len == dump - other_wa &&
>>     |                             !strncmp(wa, other_wa, wa_len))
>>     |                                 return true;
>>     |                 }
>>     | 
>>     |         next_line:
>>     |                 while (!is_eol(*dump))
>>     |                         dump++;
>>     | 
>>     |                 if (*dump)
>>     |                         dump++;
>>     |         }
>>     | 
>>     |         return false;
>>     | }
>> 
>> Version with POSIX regcomp/regexec:
>> 
>>     | static int debugfs_dump_has_wa(char *dump, const char *wa)
>>     | {
>>     |         size_t wa_len;
>>     |         regex_t regex;
>>     |         regmatch_t match[2];
>>     |         int ret;
>>     | 
>>     |         if (regcomp(&regex, "[ \t,]*([^ \t,]+)", REG_EXTENDED | REG_NEWLINE)) {
>>     |                 igt_critical("Failed to compile regex, workaround %s will not be checked.\n",
>>     |                              wa);
>>     | 
>>     |                 return -1;
>>     |         }
>>     | 
>>     |         wa_len = strlen(wa);
>>     |         ret = 0;
>>     | 
>>     |         while (*dump) {
>>     |                 /*
>>     |                  * Each workaround name is indented by one tab
>>     |                  * character; unindented lines are used as "section
>>     |                  * names" identifying the type of workarounds that
>>     |                  * follow (e.g. "GT Workarounds", "Engine Workarounds"
>>     |                  * etc).
>>     |                  */
>>     |                 if (*dump != '\t')
>>     |                         goto next_line;
>>     | 
>>     |                 while (*dump && regexec(&regex, dump, 2, match, 0) == 0) {
>>     |                         char *other_wa = dump + match[1].rm_so;
>>     |                         size_t other_wa_len = match[1].rm_eo - match[1].rm_so;
>>     | 
>>     |                         dump += match[0].rm_eo;
>>     | 
>>     |                         if (wa_len == other_wa_len && !strncmp(wa, other_wa, wa_len)) {
>>     |                                 ret = 1;
>>     | 
>>     |                                 goto done;
>>     |                         }
>>     |                 }
>>     | 
>>     |         next_line:
>>     |                 while (*dump && *dump != '\n')
>>     |                         dump++;
>>     | 
>>     |                 if (*dump)
>>     |                         dump++;
>>     |         }
>>     | 
>>     | done:
>>     |         regfree(&regex);
>>     | 
>>     |         return ret;
>>     | }
>> 
>> --
>> Gustavo Sousa
>> 
>> >
>> > --
>> > Gustavo Sousa
>> >
>> >>
>> >>
>> >> Matt
>> >>
>> >>> 
>> >>> Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> >>> ---
>> >>>  lib/xe/xe_wa.c | 39 ++++++++++++++++++++++++++++++++++++++-
>> >>>  1 file changed, 38 insertions(+), 1 deletion(-)
>> >>> 
>> >>> diff --git a/lib/xe/xe_wa.c b/lib/xe/xe_wa.c
>> >>> index ff5daf529831..d44431e7e61f 100644
>> >>> --- a/lib/xe/xe_wa.c
>> >>> +++ b/lib/xe/xe_wa.c
>> >>> @@ -13,6 +13,43 @@
>> >>>  #include "xe/xe_wa.h"
>> >>>  #include "xe/xe_query.h"
>> >>>  
>> >>> +static bool debugfs_dump_has_wa(char *dump, const char *wa)
>> >>> +{
>> >>> +	char *a = dump;
>> >>> +
>> >>> +	while (*a) {
>> >>> +		const char *b = wa;
>> >>> +
>> >>> +		/*
>> >>> +		 * Each workaround name is indented by one tab
>> >>> +		 * character; unindented lines are used as "section
>> >>> +		 * names" identifying the type of workarounds that
>> >>> +		 * follow (e.g. "GT Workarounds", "Engine Workarounds"
>> >>> +		 * etc).
>> >>> +		 */
>> >>> +		if (*a++ != '\t')
>> >>> +			goto next_line;
>> >>> +
>> >>> +		while (*a == *b && !(*a == '\0' || *a == '\n' || *b == '\0')) {
>> >>> +			a++;
>> >>> +			b++;
>> >>> +		}
>> >>> +
>> >>> +		if ((*a == '\0' || *a == '\n') && *b == '\0')
>> >>> +			return true;
>> >>> +
>> >>> +	next_line:
>> >>> +		/* No match for this line, advance to the next one. */
>> >>> +		while (*a != '\n' && *a != '\0')
>> >>> +			a++;
>> >>> +
>> >>> +		if (*a == '\n')
>> >>> +			a++;
>> >>> +	}
>> >>> +
>> >>> +	return false;
>> >>> +}
>> >>> +
>> >>>  static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
>> >>>  			       const char *debugfs_name, const char *wa)
>> >>>  {
>> >>> @@ -23,7 +60,7 @@ static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
>> >>>  
>> >>>  	debugfs_dump = igt_sysfs_get(debugfs_fd, debugfs_name);
>> >>>  	if (debugfs_dump) {
>> >>> -		char *has_wa = strstr(debugfs_dump, wa);
>> >>> +		bool has_wa = debugfs_dump_has_wa(debugfs_dump, wa);
>> >>>  
>> >>>  		free(debugfs_dump);
>> >>>  
>> >>> 
>> >>> -- 
>> >>> 2.55.0
>> >>> 
>> >>
>> >> -- 
>> >> Matt Roper
>> >> Graphics Software Engineer
>> >> Linux GPU Platform Enablement
>> >> Intel Corporation
>
> -- 
> Matt Roper
> Graphics Software Engineer
> Linux GPU Platform Enablement
> Intel Corporation

  reply	other threads:[~2026-08-19 21:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 18:59 [PATCH i-g-t 00/10] Implement Wa_14026539277 Gustavo Sousa
2026-07-21 18:59 ` [PATCH i-g-t 01/10] lib/xe: Move lib/intel_wa to lib/xe/xe_wa Gustavo Sousa
2026-07-29 21:04   ` Matt Roper
2026-07-29 21:09     ` Gustavo Sousa
2026-07-21 18:59 ` [PATCH i-g-t 02/10] lib/xe: Use stricter line-equality check when checking for workarounds Gustavo Sousa
2026-07-29 21:23   ` Matt Roper
2026-08-18 18:40     ` Gustavo Sousa
2026-08-19 19:32       ` Gustavo Sousa
2026-08-19 20:55         ` Matt Roper
2026-08-19 21:36           ` Gustavo Sousa [this message]
2026-07-21 18:59 ` [PATCH i-g-t 03/10] lib/xe: Gather workarounds debugfs dumps Gustavo Sousa
2026-07-29 21:39   ` Matt Roper
2026-07-21 18:59 ` [PATCH i-g-t 04/10] lib/xe: Cache workaround information in xe_device Gustavo Sousa
2026-07-29 21:58   ` Matt Roper
2026-08-18 18:02     ` Gustavo Sousa
2026-07-21 18:59 ` [PATCH i-g-t 05/10] lib/xe: Return boolean from xe_wa() Gustavo Sousa
2026-07-29 22:14   ` Matt Roper
2026-08-18 18:08     ` Gustavo Sousa
2026-08-19 20:50       ` Matt Roper
2026-08-19 21:40         ` Gustavo Sousa
2026-07-21 18:59 ` [PATCH i-g-t 06/10] tests/intel/xe_pat: Adapt pat_entry_is_wb() to Xe3p Gustavo Sousa
2026-07-29 22:16   ` Matt Roper
2026-07-21 19:00 ` [PATCH i-g-t 07/10] lib/xe: Add xe_wa_from_cache() Gustavo Sousa
2026-07-29 22:20   ` Matt Roper
2026-07-21 19:00 ` [PATCH i-g-t 08/10] lib/intel_pat: Encapsulate management of xe_device's pat_cache Gustavo Sousa
2026-07-29 22:35   ` Matt Roper
2026-08-18 18:25     ` Gustavo Sousa
2026-08-19 20:43       ` Matt Roper
2026-07-21 19:00 ` [PATCH i-g-t 09/10] lib/intel_pat: Pass xe_device to xe_get_pat_config() Gustavo Sousa
2026-07-29 22:38   ` Matt Roper
2026-07-21 19:00 ` [PATCH i-g-t 10/10] intel: Implement Wa_14026539277 Gustavo Sousa
2026-07-21 23:18 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-07-21 23:56 ` ✓ i915.CI.BAT: " Patchwork
2026-07-22 14:09 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-22 22:52 ` ✗ i915.CI.Full: failure " Patchwork

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=875x15bxnb.fsf@intel.com \
    --to=gustavo.sousa@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=matthew.d.roper@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