Commit 3c67ce06 authored by Umesh Nerlige Ramappa's avatar Umesh Nerlige Ramappa

drm/i915/perf: Handle non-power-of-2 reports

Some of the newer OA formats are not powers of 2. For those formats,
adjust the hw_tail accordingly when checking for new reports.

v2: (Ashutosh)
- Switch to OA_TAKEN for diff calculation
- Use OA_BUFFER_SIZE instead of the vma size
- Update comments
Signed-off-by: default avatarUmesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: default avatarAshutosh Dixit <ashutosh.dixit@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230323225901.3743681-8-umesh.nerlige.ramappa@intel.com
parent dbc9a5fb
...@@ -534,6 +534,7 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream) ...@@ -534,6 +534,7 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
bool pollin; bool pollin;
u32 hw_tail; u32 hw_tail;
u64 now; u64 now;
u32 partial_report_size;
/* We have to consider the (unlikely) possibility that read() errors /* We have to consider the (unlikely) possibility that read() errors
* could result in an OA buffer reset which might reset the head and * could result in an OA buffer reset which might reset the head and
...@@ -543,10 +544,15 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream) ...@@ -543,10 +544,15 @@ static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
hw_tail = stream->perf->ops.oa_hw_tail_read(stream); hw_tail = stream->perf->ops.oa_hw_tail_read(stream);
/* The tail pointer increases in 64 byte increments, /* The tail pointer increases in 64 byte increments, not in report_size
* not in report_size steps... * steps. Also the report size may not be a power of 2. Compute
* potentially partially landed report in the OA buffer
*/ */
hw_tail &= ~(report_size - 1); partial_report_size = OA_TAKEN(hw_tail, stream->oa_buffer.tail);
partial_report_size %= report_size;
/* Subtract partial amount off the tail */
hw_tail = gtt_offset + OA_TAKEN(hw_tail, partial_report_size);
now = ktime_get_mono_fast_ns(); now = ktime_get_mono_fast_ns();
...@@ -669,6 +675,8 @@ static int append_oa_sample(struct i915_perf_stream *stream, ...@@ -669,6 +675,8 @@ static int append_oa_sample(struct i915_perf_stream *stream,
{ {
int report_size = stream->oa_buffer.format->size; int report_size = stream->oa_buffer.format->size;
struct drm_i915_perf_record_header header; struct drm_i915_perf_record_header header;
int report_size_partial;
u8 *oa_buf_end;
header.type = DRM_I915_PERF_RECORD_SAMPLE; header.type = DRM_I915_PERF_RECORD_SAMPLE;
header.pad = 0; header.pad = 0;
...@@ -682,8 +690,20 @@ static int append_oa_sample(struct i915_perf_stream *stream, ...@@ -682,8 +690,20 @@ static int append_oa_sample(struct i915_perf_stream *stream,
return -EFAULT; return -EFAULT;
buf += sizeof(header); buf += sizeof(header);
if (copy_to_user(buf, report, report_size)) oa_buf_end = stream->oa_buffer.vaddr + OA_BUFFER_SIZE;
report_size_partial = oa_buf_end - report;
if (report_size_partial < report_size) {
if (copy_to_user(buf, report, report_size_partial))
return -EFAULT;
buf += report_size_partial;
if (copy_to_user(buf, stream->oa_buffer.vaddr,
report_size - report_size_partial))
return -EFAULT;
} else if (copy_to_user(buf, report, report_size)) {
return -EFAULT; return -EFAULT;
}
(*offset) += header.size; (*offset) += header.size;
...@@ -747,12 +767,11 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream, ...@@ -747,12 +767,11 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream,
* An out of bounds or misaligned head or tail pointer implies a driver * An out of bounds or misaligned head or tail pointer implies a driver
* bug since we validate + align the tail pointers we read from the * bug since we validate + align the tail pointers we read from the
* hardware and we are in full control of the head pointer which should * hardware and we are in full control of the head pointer which should
* only be incremented by multiples of the report size (notably also * only be incremented by multiples of the report size.
* all a power of two).
*/ */
if (drm_WARN_ONCE(&uncore->i915->drm, if (drm_WARN_ONCE(&uncore->i915->drm,
head > OA_BUFFER_SIZE || head % report_size || head > OA_BUFFER_SIZE ||
tail > OA_BUFFER_SIZE || tail % report_size, tail > OA_BUFFER_SIZE,
"Inconsistent OA buffer pointers: head = %u, tail = %u\n", "Inconsistent OA buffer pointers: head = %u, tail = %u\n",
head, tail)) head, tail))
return -EIO; return -EIO;
...@@ -766,22 +785,6 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream, ...@@ -766,22 +785,6 @@ static int gen8_append_oa_reports(struct i915_perf_stream *stream,
u32 ctx_id; u32 ctx_id;
u64 reason; u64 reason;
/*
* All the report sizes factor neatly into the buffer
* size so we never expect to see a report split
* between the beginning and end of the buffer.
*
* Given the initial alignment check a misalignment
* here would imply a driver bug that would result
* in an overrun.
*/
if (drm_WARN_ON(&uncore->i915->drm,
(OA_BUFFER_SIZE - head) < report_size)) {
drm_err(&uncore->i915->drm,
"Spurious OA head ptr: non-integral report offset\n");
break;
}
/* /*
* The reason field includes flags identifying what * The reason field includes flags identifying what
* triggered this specific report (mostly timer * triggered this specific report (mostly timer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment