Skip to content

Commit d41d75f

Browse files
gcabidduherbertx
authored andcommitted
crypto: qat - fix DMA direction for compression on GEN2 devices
QAT devices perform an additional integrity check during compression by decompressing the output. Starting from QAT GEN4, this verification is done in-line by the hardware. However, on GEN2 devices, the hardware reads back the compressed output from the destination buffer and performs a decompression operation using it as the source. In the current QAT driver, destination buffers are always marked as write-only. This is incorrect for QAT GEN2 compression, where the buffer is also read during verification. Since commit 6f5dc76 ("iommu/vt-d: Restore WO permissions on second-level paging entries"), merged in v6.16-rc1, write-only permissions are strictly enforced, leading to DMAR errors when using QAT GEN2 devices for compression, if VT-d is enabled. Mark the destination buffers as DMA_BIDIRECTIONAL. This ensures compatibility with GEN2 devices, even though it is not required for QAT GEN4 and later. Signed-off-by: Giovanni Cabiddu <[email protected]> Fixes: cf5bb83 ("crypto: qat - fix DMA transfer direction") Reviewed-by: Ahsan Atta <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 4fec76b commit d41d75f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

drivers/crypto/intel/qat/qat_common/qat_bl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void qat_bl_free_bufl(struct adf_accel_dev *accel_dev,
3838
for (i = 0; i < blout->num_mapped_bufs; i++) {
3939
dma_unmap_single(dev, blout->buffers[i].addr,
4040
blout->buffers[i].len,
41-
DMA_FROM_DEVICE);
41+
DMA_BIDIRECTIONAL);
4242
}
4343
dma_unmap_single(dev, blpout, sz_out, DMA_TO_DEVICE);
4444

@@ -162,7 +162,7 @@ static int __qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev,
162162
}
163163
buffers[y].addr = dma_map_single(dev, sg_virt(sg) + left,
164164
sg->length - left,
165-
DMA_FROM_DEVICE);
165+
DMA_BIDIRECTIONAL);
166166
if (unlikely(dma_mapping_error(dev, buffers[y].addr)))
167167
goto err_out;
168168
buffers[y].len = sg->length;
@@ -204,7 +204,7 @@ static int __qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev,
204204
if (!dma_mapping_error(dev, buflout->buffers[i].addr))
205205
dma_unmap_single(dev, buflout->buffers[i].addr,
206206
buflout->buffers[i].len,
207-
DMA_FROM_DEVICE);
207+
DMA_BIDIRECTIONAL);
208208
}
209209

210210
if (!buf->sgl_dst_valid)

drivers/crypto/intel/qat/qat_common/qat_compression.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int qat_compression_alloc_dc_data(struct adf_accel_dev *accel_dev)
204204
if (!obuff)
205205
goto err;
206206

207-
obuff_p = dma_map_single(dev, obuff, ovf_buff_sz, DMA_FROM_DEVICE);
207+
obuff_p = dma_map_single(dev, obuff, ovf_buff_sz, DMA_BIDIRECTIONAL);
208208
if (unlikely(dma_mapping_error(dev, obuff_p)))
209209
goto err;
210210

@@ -232,7 +232,7 @@ static void qat_free_dc_data(struct adf_accel_dev *accel_dev)
232232
return;
233233

234234
dma_unmap_single(dev, dc_data->ovf_buff_p, dc_data->ovf_buff_sz,
235-
DMA_FROM_DEVICE);
235+
DMA_BIDIRECTIONAL);
236236
kfree_sensitive(dc_data->ovf_buff);
237237
kfree(dc_data);
238238
accel_dev->dc_data = NULL;

0 commit comments

Comments
 (0)