Skip to content

Commit 443b21d

Browse files
jsarhalgirdwood
authored andcommitted
dma-trace: Fix potential race issue by using blocking DMA copy
It is possible that that in trace_work() sof_ipc_dma_trace_posn ipc message reaches host side sof driver before the dma_copy_to_host_nowait() is finished. Change the dma_copy_to_host_nowait() implementation to dma_copy_to_host() by adding DMA_COPY_BLOCKING flag to dma_copy() command. The flag is already there on the !defined(CONFIG_DMA_GW) version of the function and the old name of the function was a bit misleading. This commit changes also probe.c probe_task() so that it also uses the new blocking DMA copy. I could not see any justification to use nowait version there either. Signed-off-by: Jyri Sarha <jyri.sarha@intel.com>
1 parent 5afc494 commit 443b21d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/include/sof/lib/dma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ int dma_copy_from_host_nowait(struct dma_copy *dc,
541541
int32_t size);
542542

543543
/* DMA copy data from DSP to host */
544-
int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
545-
int32_t host_offset, void *local_ptr, int32_t size);
544+
int dma_copy_to_host(struct dma_copy *dc, struct dma_sg_config *host_sg,
545+
int32_t host_offset, void *local_ptr, int32_t size);
546546

547547
int dma_copy_set_stream_tag(struct dma_copy *dc, uint32_t stream_tag);
548548

src/ipc/dma-copy.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ static struct dma_sg_elem *sg_get_elem_at(struct dma_sg_config *host_sg,
5959
*/
6060
#if CONFIG_DMA_GW
6161

62-
int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
63-
int32_t host_offset, void *local_ptr, int32_t size)
62+
int dma_copy_to_host(struct dma_copy *dc, struct dma_sg_config *host_sg,
63+
int32_t host_offset, void *local_ptr, int32_t size)
6464
{
6565
int ret;
6666

6767
/* tell gateway to copy */
68-
ret = dma_copy(dc->chan, size, 0);
68+
ret = dma_copy(dc->chan, size, DMA_COPY_BLOCKING);
6969
if (ret < 0)
7070
return ret;
7171

@@ -75,8 +75,8 @@ int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
7575

7676
#else /* CONFIG_DMA_GW */
7777

78-
int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
79-
int32_t host_offset, void *local_ptr, int32_t size)
78+
int dma_copy_to_host(struct dma_copy *dc, struct dma_sg_config *host_sg,
79+
int32_t host_offset, void *local_ptr, int32_t size)
8080
{
8181
struct dma_sg_config config;
8282
struct dma_sg_elem *host_sg_elem;

src/probe/probe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ static enum task_state probe_task(void *data)
201201
int err;
202202

203203
if (_probe->ext_dma.dmapb.avail > 0)
204-
err = dma_copy_to_host_nowait(&_probe->ext_dma.dc,
205-
&_probe->ext_dma.config, 0,
206-
(void *)_probe->ext_dma.dmapb.r_ptr,
207-
_probe->ext_dma.dmapb.avail);
204+
err = dma_copy_to_host(&_probe->ext_dma.dc,
205+
&_probe->ext_dma.config, 0,
206+
(void *)_probe->ext_dma.dmapb.r_ptr,
207+
_probe->ext_dma.dmapb.avail);
208208
else
209209
return SOF_TASK_STATE_RESCHEDULE;
210210

211211
if (err < 0) {
212-
tr_err(&pr_tr, "probe_task(): dma_copy_to_host_nowait() failed.");
212+
tr_err(&pr_tr, "probe_task(): dma_copy_to_host() failed.");
213213
return err;
214214
}
215215

src/trace/dma-trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static enum task_state trace_work(void *data)
8383
d->copy_in_progress = 1;
8484

8585
/* copy this section to host */
86-
size = dma_copy_to_host_nowait(&d->dc, config, d->posn.host_offset,
87-
buffer->r_ptr, size);
86+
size = dma_copy_to_host(&d->dc, config, d->posn.host_offset,
87+
buffer->r_ptr, size);
8888
if (size < 0) {
89-
tr_err(&dt_tr, "trace_work(): dma_copy_to_host_nowait() failed");
89+
tr_err(&dt_tr, "trace_work(): dma_copy_to_host() failed");
9090
goto out;
9191
}
9292

0 commit comments

Comments
 (0)