From 3966e0bf2e4719d144c7be1350d6c1db6be5a447 Mon Sep 17 00:00:00 2001 From: paul luse Date: Tue, 13 Aug 2019 18:12:28 -0400 Subject: [PATCH] bdev/crypto: assert that a QAT DMA never crosses a 2MB boundary Because required alignment is already set to block size and by design the crypto module does one crypto operation per block (it uses the LBA as the initialization vector) it should not be possible to get a physical address that spans however adding an assert just in case. Change-Id: I1dc844d0a32395f9ed4869429368f60b919703a4 Signed-off-by: paul luse Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/465107 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/bdev/crypto/vbdev_crypto.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/bdev/crypto/vbdev_crypto.c b/lib/bdev/crypto/vbdev_crypto.c index fddcf86b8..d037f386d 100644 --- a/lib/bdev/crypto/vbdev_crypto.c +++ b/lib/bdev/crypto/vbdev_crypto.c @@ -598,7 +598,7 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation uint32_t allocated = 0; uint8_t *current_iov = NULL; uint64_t total_remaining = 0; - uint64_t current_iov_remaining = 0; + uint64_t updated_length, current_iov_remaining = 0; int completed = 0; int crypto_index = 0; uint32_t en_offset = 0; @@ -688,8 +688,9 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation /* Set the mbuf elements address and length. Null out the next pointer. */ src_mbufs[crypto_index]->buf_addr = current_iov; - src_mbufs[crypto_index]->buf_iova = spdk_vtophys((void *)current_iov, NULL); - src_mbufs[crypto_index]->data_len = crypto_len; + src_mbufs[crypto_index]->data_len = updated_length = crypto_len; + src_mbufs[crypto_index]->buf_iova = spdk_vtophys((void *)current_iov, &updated_length); + assert(updated_length == crypto_len); src_mbufs[crypto_index]->next = NULL; /* Store context in every mbuf as we don't know anything about completion order */ src_mbufs[crypto_index]->userdata = bdev_io; @@ -721,9 +722,10 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation /* Set the relevant destination en_mbuf elements. */ dst_mbufs[crypto_index]->buf_addr = io_ctx->cry_iov.iov_base + en_offset; + dst_mbufs[crypto_index]->data_len = updated_length = crypto_len; dst_mbufs[crypto_index]->buf_iova = spdk_vtophys(dst_mbufs[crypto_index]->buf_addr, - NULL); - dst_mbufs[crypto_index]->data_len = crypto_len; + &updated_length); + assert(updated_length == crypto_len); crypto_ops[crypto_index]->sym->m_dst = dst_mbufs[crypto_index]; en_offset += crypto_len; dst_mbufs[crypto_index]->next = NULL;