Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Raag Jadav <raag.jadav@intel.com>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v3 8/8] drm/xe/gt_throttle: Avoid TOCTOU when monitoring reasons
Date: Thu, 30 Oct 2025 11:47:03 -0400	[thread overview]
Message-ID: <aQOIdza-zd3ES9xw@intel.com> (raw)
In-Reply-To: <jnuis4h4uq7he4yq52rsb7ee6jffgclyf4skvftu3m3gsnk7xy@vhtbsgchkvyx>

On Thu, Oct 30, 2025 at 09:55:30AM -0500, Lucas De Marchi wrote:
> On Thu, Oct 30, 2025 at 10:53:36AM +0100, Raag Jadav wrote:
> > On Wed, Oct 29, 2025 at 04:45:10PM -0700, Lucas De Marchi wrote:
> > > It's currently not possible to safely monitor if there's throttling
> > > happening and what are the reasons. The approach of reading the status
> > > and then reading the reasons is not reliable as by the time sysadmin
> > > reads the reason, the throttling could not be happening anymore.
> > > 
> > > Previous tentative to fix that[1] was breaking the ABI and potentially
> > > sysadmin's scripts. This takes a different approach of adding and
> > > documenting the additional attribute. It's still valuable, though
> > > redundant, to provide the simpler 0/1 interface.
> > > 
> > > In order to avoid userspace knowledge on the bitmask meaning and to be
> > > able to maintain the kernel side in sync with possible changes in
> > > future, just walk the attribute group and check what are the masks that
> > > match the value read.
> > > 
> > > [1] https://lore.kernel.org/intel-xe/20241025092238.167042-1-raag.jadav@intel.com/
> > 
> > ...
> > 
> > > +static const struct attribute_group *get_platform_throttle_group(struct xe_device *xe);
> > > +
> > > +static ssize_t status_reasons_show(struct kobject *kobj,
> > > +				   struct kobj_attribute *attr, char *buff)
> > > +{
> > > +	struct xe_gt *gt = throttle_to_gt(kobj);
> > > +	struct xe_device *xe = gt_to_xe(gt);
> > > +	const struct attribute_group *group;
> > > +	struct attribute **pother;
> > > +	ssize_t ret = 0;
> > > +	u32 reasons;
> > > +
> > > +	reasons = xe_gt_throttle_get_limit_reasons(gt);
> > > +	group = get_platform_throttle_group(xe);
> > > +
> > > +	for (pother = group->attrs; *pother; pother++) {
> > > +		struct kobj_attribute *kattr = container_of(*pother, struct kobj_attribute, attr);
> > > +		struct throttle_attribute *other_ta = kobj_attribute_to_throttle(kattr);
> > > +
> > > +		if (other_ta->mask != U32_MAX && reasons & other_ta->mask)
> > > +			ret += sysfs_emit_at(buff, ret, "%s ", (*pother)->name);
> > 
> > Much better.
> > 
> > > +	}
> > > +
> > > +	/* Drop extra space from last iteration above */
> > > +	if (ret)
> > > +		ret--;
> > > +
> > > +	ret += sysfs_emit_at(buff, ret, "\n");
> > 
> > I went through the documentation again and I couldn't find any rules
> > related to empty files or whether it is allowed (just thinking out
> > loud about no throttling cases).
> 
> do you mean if "empty" files are allowed in sysfs? I don't think there's
> any problem with that. It's also not empty, it has a newline there ;)

alternatively we could print the entire reg in hex format?
But I prefer the text line in this patch.

Nothing against the 'empty' file with or without the new-line,
but perhaps we could consider to track that in the loop
and if none is add we print

if (ret)
	ret--;
else
	sysfs_emit_at(buff, ret, "none");

and document that above...

> 
> Lucas De Marchi
> 
> > 
> > Thoughts?
> > 
> > Raag

  reply	other threads:[~2025-10-30 15:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 23:45 [PATCH v3 0/8] drm/xe: CRI support in gt_throttle + refactors Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 1/8] drm/xe/cri: Add new performance limit reasons bits Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 2/8] drm/xe/gt_throttle: Tidy up perf reasons reading Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 3/8] drm/xe/gt_throttle: Always read and mask Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 4/8] drm/xe/gt_throttle: Add throttle_to_gt() Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 5/8] drm/xe/gt_throttle: Tidy up attribute definition Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 6/8] drm/xe: Improve freq and throttle documentation Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 7/8] drm/xe/gt_throttle: Drop individual show functions Lucas De Marchi
2025-10-29 23:45 ` [PATCH v3 8/8] drm/xe/gt_throttle: Avoid TOCTOU when monitoring reasons Lucas De Marchi
2025-10-30  9:53   ` Raag Jadav
2025-10-30 14:55     ` Lucas De Marchi
2025-10-30 15:47       ` Rodrigo Vivi [this message]
2025-10-30 16:06         ` Raag Jadav
2025-10-30 18:43           ` Lucas De Marchi
2025-10-30 19:54             ` Vivi, Rodrigo
2025-10-31  6:08               ` Raag Jadav
2025-10-30 15:42   ` Rodrigo Vivi

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=aQOIdza-zd3ES9xw@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=raag.jadav@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