Skip to content

Commit 0b030f5

Browse files
davejiangvinodkoul
authored andcommitted
dmaengine: idxd: make submit failure path consistent on desc freeing
The submission path for dmaengine API does not do descriptor freeing on failure. Also, with the abort mechanism, the freeing of descriptor happens when the abort callback is completed. Therefore free descriptor on all error paths for submission call to make things consistent. Also remove the double free that would happen on abort in idxd_dma_tx_submit() call. Fixes: 6b4b87f ("dmaengine: idxd: fix submission race window") Signed-off-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/162827146072.3459011.10255348500504659810.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Vinod Koul <[email protected]>
1 parent 9760383 commit 0b030f5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

drivers/dma/idxd/dma.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ static dma_cookie_t idxd_dma_tx_submit(struct dma_async_tx_descriptor *tx)
149149
cookie = dma_cookie_assign(tx);
150150

151151
rc = idxd_submit_desc(wq, desc);
152-
if (rc < 0) {
153-
idxd_free_desc(wq, desc);
152+
if (rc < 0)
154153
return rc;
155-
}
156154

157155
return cookie;
158156
}

drivers/dma/idxd/submit.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
139139
void __iomem *portal;
140140
int rc;
141141

142-
if (idxd->state != IDXD_DEV_ENABLED)
142+
if (idxd->state != IDXD_DEV_ENABLED) {
143+
idxd_free_desc(wq, desc);
143144
return -EIO;
145+
}
144146

145-
if (!percpu_ref_tryget_live(&wq->wq_active))
147+
if (!percpu_ref_tryget_live(&wq->wq_active)) {
148+
idxd_free_desc(wq, desc);
146149
return -ENXIO;
150+
}
147151

148152
portal = idxd_wq_portal_addr(wq);
149153

@@ -175,8 +179,11 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
175179
rc = enqcmds(portal, desc->hw);
176180
if (rc < 0) {
177181
percpu_ref_put(&wq->wq_active);
182+
/* abort operation frees the descriptor */
178183
if (ie)
179184
llist_abort_desc(wq, ie, desc);
185+
else
186+
idxd_free_desc(wq, desc);
180187
return rc;
181188
}
182189
}

0 commit comments

Comments
 (0)