Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Umesh Nerlige Ramappa" <umesh.nerlige.ramappa@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user
Date: Fri, 21 Aug 2026 22:37:49 +0000	[thread overview]
Message-ID: <20260821223749.B74EE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260821222338.1053887-8-umesh.nerlige.ramappa@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The newly introduced 32-report lag reduces the maximum possible available reports, but `wait_num_reports` validation still allows values up to full buffer capacity, causing a permanent hang and `-EIO` on overflow.

Pre-existing issues:
- [High] Readers blocked in `read()` or `poll()` will hang indefinitely when the OA stream is disabled due to conditional wakeups and incomplete wait conditions.
--

--- Patch [3]: [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user ---
commit 73d1f6a4433c8e56a02c188bad978ed299d6d4b6
Author: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

drm/xe/xe_oa: Add a lag to the reports that is exported to user

This commit adds a 32-report lag to the OA stream reports exposed to the user.
It updates the buffer check logic to ensure the software tail stays behind the
hardware tail unless the stream is disabled, in which case all remaining reports
can be read.

> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index 020b27c642268..a025e6c2753f2 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
[ ... ]
> @@ -234,17 +234,23 @@ static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream)
>  	hw_tail -= gtt_offset;
>  
>  	/*
> -	 * The tail pointer increases in 64 byte (cacheline size), not in report_size
> +	 * The hw_tail pointer increases in 64 byte (cacheline size), not in report_size
>  	 * increments. Also report size may not be a power of 2. Compute potential
>  	 * partially landed report in OA buffer.
>  	 */
>  	partial_report_size = xe_oa_circ_diff(stream, hw_tail, stream->oa_buffer.tail);
>  	partial_report_size %= report_size;
>  
> -	/* Subtract partial amount off the tail */
> +	/* Subtract partial amount off the hw_tail */
>  	hw_tail = xe_oa_circ_diff(stream, hw_tail, partial_report_size);
>  
> -	stream->oa_buffer.tail = hw_tail;
> +#define LAG_REPORTS 32
> +	lag = xe_oa_circ_diff(stream, hw_tail, stream->oa_buffer.tail);
> +	if (!stream->enabled)
> +		stream->oa_buffer.tail = hw_tail;
> +	else if (lag > LAG_REPORTS * report_size)
> +		stream->oa_buffer.tail = xe_oa_circ_diff(stream, hw_tail,
> +							 LAG_REPORTS * report_size);

[Severity: High]
Does this logic effectively reduce the maximum number of available reports
in the buffer by 32?

If so, userspace could now specify a wait_num_reports in
xe_oa_stream_open_ioctl() that is impossible to satisfy. The ioctl validation
still allows values up to the full buffer capacity:

drivers/gpu/drm/xe/xe_oa.c:xe_oa_stream_open_ioctl() {
    if (param.wait_num_reports > param.oa_buffer_size / f->size) {
        ...
        ret = -EINVAL;
    }
}

If userspace requests a wait amount greater than (capacity - 32),
the available amount will never reach wait_num_reports. The hardware
tail will wrap around and overwrite unread data, causing read() or poll()
to hang indefinitely until the overflow is processed and returns -EIO.

Should the validation limit in xe_oa_stream_open_ioctl() be updated to
subtract LAG_REPORTS?

>  
>  	available = xe_oa_circ_diff(stream, stream->oa_buffer.tail, stream->oa_buffer.head);
>  	stream->pollin = available >= stream->wait_num_reports * report_size;
[ ... ]
> @@ -1490,6 +1492,11 @@ static int xe_oa_disable_locked(struct xe_oa_stream *stream)
>  		ret = xe_oa_enable_preempt_timeslice(stream);
>  
>  	stream->enabled = false;
> +
> +	/* Update stream->oa_buffer.tail to allow any final reports to be read */
> +	if (xe_oa_buffer_check_unlocked(stream))
> +		wake_up(&stream->poll_wq);
> +

[Severity: High]
This is a pre-existing issue, but can readers blocked in read() or poll() hang
indefinitely when the OA stream is disabled here?

Because xe_oa_buffer_check_unlocked() returns true only when
available >= wait_num_reports, the wakeup is skipped entirely if there are
fewer pending reports than the wait threshold.

Furthermore, looking at xe_oa_wait_unlocked(), it doesn't check
!stream->enabled in its wait condition:

drivers/gpu/drm/xe/xe_oa.c:xe_oa_wait_unlocked() {
    return wait_event_interruptible(stream->poll_wq,
                                    xe_oa_buffer_check_unlocked(stream));
}

Even if an unconditional wakeup was performed here, wouldn't the thread
re-evaluate the condition and go back to sleep forever since the hardware
is stopped and timers are canceled?

>  	return ret;
>  }
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260821222338.1053887-5-umesh.nerlige.ramappa@intel.com?part=3

  reply	other threads:[~2026-08-21 22:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 22:23 [PATCH 0/3] Modify the SW tail logic in OA Umesh Nerlige Ramappa
2026-08-21 22:23 ` [PATCH 1/3] drm/xe/xe_oa: Clear status only if relevant bits are set Umesh Nerlige Ramappa
2026-08-21 22:23 ` [PATCH 2/3] drm/xe/xe_oa: Avoid checking and setting fields in the OA report Umesh Nerlige Ramappa
2026-08-21 22:34   ` sashiko-bot
2026-08-24 15:39   ` Dixit, Ashutosh
2026-08-26 23:30     ` Umesh Nerlige Ramappa
2026-08-26 23:44       ` Dixit, Ashutosh
2026-08-21 22:23 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa
2026-08-21 22:37   ` sashiko-bot [this message]
2026-08-24 15:57   ` Dixit, Ashutosh
2026-08-21 22:30 ` ✓ CI.KUnit: success for Modify the SW tail logic in OA Patchwork
2026-08-21 23:25 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-22  0:33 ` ✓ Xe.CI.FULL: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-08-21 20:07 [PATCH 0/3] " Umesh Nerlige Ramappa
2026-08-21 20:07 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa
2026-08-21 20:21   ` sashiko-bot
2026-08-06 22:47 [PATCH 0/3] Modify the SW tail logic in OA Umesh Nerlige Ramappa
2026-08-06 22:47 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa
2026-08-14 15:42   ` Dixit, Ashutosh
2026-08-14 19:01     ` Umesh Nerlige Ramappa
2026-08-18  4:38       ` Dixit, Ashutosh
2026-07-30 23:35 [PATCH 0/3] Modify the SW tail logic in OA Umesh Nerlige Ramappa
2026-07-30 23:35 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa
2026-07-22 21:54 [PATCH 0/3] Modify the SW tail logic in OA Umesh Nerlige Ramappa
2026-07-22 21:54 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa
2026-07-21 23:48 [PATCH 0/3] Modify the SW tail logic in OA Umesh Nerlige Ramappa
2026-07-21 23:48 ` [PATCH 3/3] drm/xe/xe_oa: Add a lag to the reports that is exported to user Umesh Nerlige Ramappa

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=20260821223749.B74EE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=umesh.nerlige.ramappa@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