Skip to content

Conversation

@ujfalusi
Copy link
Collaborator

Hi,

The READ_ONCE(sdev->host_offset) alone does nothing to prevent any race regarding to host_offset change race prevention.
Introduce a new helper to do this in a correct way and while at it, print out the new offset for us to see where we are.

Additional debug prints can be added to track what is copied to user space with a simple change:

diff --git a/sound/soc/sof/trace.c b/sound/soc/sof/trace.c
index 76c763da5804..32c3c0d8a75e 100644
--- a/sound/soc/sof/trace.c
+++ b/sound/soc/sof/trace.c
@@ -334,8 +334,10 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
 	}
 
 	/* no new trace data */
-	if (!avail)
+	if (!avail) {
+		dev_dbg(sdev->dev, "trace: nothing to copy\n");
 		return 0;
+	}
 
 	/* make sure count is <= avail */
 	if (count > avail)
@@ -349,6 +351,8 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
 	 */
 	snd_dma_buffer_sync(&sdev->dmatb, SNDRV_DMA_SYNC_CPU);
 	/* copy available trace data to debugfs */
+	dev_dbg(sdev->dev, "trace: copy to user from offset : %#llx, count: %#zx\n",
+		lpos, count);
 	rem = copy_to_user(buffer, ((u8 *)(dfse->buf) + lpos), count);
 	if (rem)
 		return -EFAULT;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this super-verbose? I wonder if this is going to fill the console with too many logs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the debug is enabled we are printing the IPC messages (two per message). With this change it will look like this:

ipc rx: 0x90020000: GLB_TRACE_MSG: DMA_POSITION
trace: new host_offset: 0x7920
ipc rx done: 0x90020000: GLB_TRACE_MSG: DMA_POSITION

Instead of an empty indication that the position is updated we will know the value as well.
Then we have another print when the host_offset is reset to 0 (either because of closing the trace file or restart), but it is still one additional message.

It is not going to fill the console, but I always wondered what is the content behind the dtrace position update.

I can drop this print if you think we should not have it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a draft PR on top of this to print the trace file reads as well in hope that we can catch the empty trace with that and have some clue on what is going on.

@ujfalusi ujfalusi force-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 07ccf0d to 6651821 Compare April 5, 2022 08:02
@ujfalusi ujfalusi force-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 6651821 to 508e431 Compare April 5, 2022 08:55
@ujfalusi
Copy link
Collaborator Author

ujfalusi commented Apr 5, 2022

Changes since v1:

  • Rebased on sof-dev (ipc3-dtrace introduction)

bardliao
bardliao previously approved these changes Apr 6, 2022
@ujfalusi ujfalusi force-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 508e431 to 75096db Compare May 4, 2022 07:01
@ujfalusi
Copy link
Collaborator Author

ujfalusi commented May 4, 2022

Changes since v2:

  • rebased on topic/sof-dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this? I don't know what problem this tries to fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certainly, this is needed for one of my DUTs, otherwise the dmesg is flooded with this message for some reason and I keep forgetting to drop this when I'm done testing before sending the PR.

I should have a hook to blow up when I try to push this patch to other branch than my wip...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is going to conflict with your very own PR #3662 changes, specifically 024c2eb

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm aware of that, they are of different topic and I don't want to mix them. I'm fine with fixing up either when the time comes.

@plbossart
Copy link
Member

@ujfalusi rebase needed.

@ujfalusi ujfalusi force-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from 75096db to debd209 Compare May 10, 2022 11:51
@ujfalusi
Copy link
Collaborator Author

Changes since v3:

plbossart
plbossart previously approved these changes May 10, 2022
@plbossart
Copy link
Member

Any other review? @dbaluta @bardliao @ranj063 @marc-hb

bardliao
bardliao previously approved these changes May 19, 2022
@plbossart
Copy link
Member

@ujfalusi conflict?

@ujfalusi
Copy link
Collaborator Author

@ujfalusi conflict?

Yes, I know, I'll update it tomorrow.

ujfalusi added 2 commits May 19, 2022 21:56
…offset

We are using the READ_ONCE() on the debugfs read path for accessing
sdev->host_offset, but the set is not atomic or protected in any way.

Add a small helper to do the host_offset update and be really paranoid
about the a possible race in update

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…ta available

If no new trace data is available then return immediately, there is no
need to continue with the execution of the trace_read() function.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi ujfalusi dismissed stale reviews from bardliao and plbossart via 9c037af May 19, 2022 18:57
@ujfalusi ujfalusi force-pushed the peter/sof/pr/dtrace_print_offsets_01 branch from debd209 to 9c037af Compare May 19, 2022 18:57
@ujfalusi
Copy link
Collaborator Author

Changes since v4:

  • rebased on sof-dev to resolve conflict.

@plbossart plbossart merged commit 8a9e909 into thesofproject:topic/sof-dev May 20, 2022
@ujfalusi ujfalusi deleted the peter/sof/pr/dtrace_print_offsets_01 branch November 18, 2022 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants