Skip to content

Commit b136225

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmc: Handle overflow cases where the num_samples range is higher
In amd_pmc_stb_debugfs_open_v2(), the stb buffer is created based on the num_samples and the read/write pointer offset. This holds good when the num_samples reported by PMFW is less than S2D_TELEMETRY_BYTES_MAX; where the stb buffer gets filled from 0th position until S2D_TELEMETRY_BYTES_MAX - 1 based on the read/write pointer offset. But when the num_samples exceeds the S2D_TELEMETRY_BYTES_MAX, the current code does not handle it well as it does not account for the cases where the stb buffer has to filled up as a circular buffer. Handle this scenario into two cases, where first memcpy will have the samples from location: (num_samples % S2D_TELEMETRY_BYTES_MAX) - (S2D_TELEMETRY_BYTES_MAX - 1) and next memcpy will have the newest ones i.e. 0 - (num_samples % S2D_TELEMETRY_BYTES_MAX - 1) Suggested-by: Hans de Goede <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Sanket Goswami <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ij: renamed flex_arr -> stb_data_arr] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent d9f421d commit b136225

File tree

1 file changed

+13
-6
lines changed
  • drivers/platform/x86/amd/pmc

1 file changed

+13
-6
lines changed

drivers/platform/x86/amd/pmc/pmc.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,23 @@ static int amd_pmc_stb_debugfs_open_v2(struct inode *inode, struct file *filp)
276276

277277
stb_data_arr->size = fsize;
278278

279-
/* Start capturing data from the last push location */
279+
/*
280+
* Start capturing data from the last push location.
281+
* This is for general cases, where the stb limits
282+
* are meant for standard usage.
283+
*/
280284
if (num_samples > S2D_TELEMETRY_BYTES_MAX) {
281-
fsize = S2D_TELEMETRY_BYTES_MAX;
282-
stb_rdptr_offset = num_samples - fsize;
285+
/* First read oldest data starting 1 behind last write till end of ringbuffer */
286+
stb_rdptr_offset = num_samples % S2D_TELEMETRY_BYTES_MAX;
287+
fsize = S2D_TELEMETRY_BYTES_MAX - stb_rdptr_offset;
288+
289+
memcpy_fromio(stb_data_arr->data, dev->stb_virt_addr + stb_rdptr_offset, fsize);
290+
/* Second copy the newer samples from offset 0 - last write */
291+
memcpy_fromio(stb_data_arr->data + fsize, dev->stb_virt_addr, stb_rdptr_offset);
283292
} else {
284-
fsize = num_samples;
285-
stb_rdptr_offset = 0;
293+
memcpy_fromio(stb_data_arr->data, dev->stb_virt_addr, fsize);
286294
}
287295

288-
memcpy_fromio(stb_data_arr->data, dev->stb_virt_addr + stb_rdptr_offset, fsize);
289296
filp->private_data = stb_data_arr;
290297

291298
return 0;

0 commit comments

Comments
 (0)