[v3] vhost/crypto: fix build with GCC 12
Checks
Commit Message
GCC 12 raises the following warning:
In file included from ../lib/mempool/rte_mempool.h:46,
from ../lib/mbuf/rte_mbuf.h:38,
from ../lib/vhost/vhost_crypto.c:7:
../lib/vhost/vhost_crypto.c: In function ‘rte_vhost_crypto_fetch_requests’:
../lib/eal/x86/include/rte_memcpy.h:371:9: warning: array subscript 1 is
outside array bounds of ‘struct virtio_crypto_op_data_req[1]’
[-Warray-bounds]
371 | rte_mov32((uint8_t *)dst + 3 * 32, (const uint8_t *)src + 3 * 32);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/vhost/vhost_crypto.c:1178:42: note: while referencing ‘req’
1178 | struct virtio_crypto_op_data_req req;
| ^~~
Split this function and separate the per descriptor copy.
This makes the code clearer, and the compiler happier.
Note: logs for errors have been moved to callers to avoid duplicates.
Fixes: 3c79609fda7c ("vhost/crypto: handle virtually non-contiguous buffers")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v2:
- fixed 32-bits build,
Changes since v1:
- refactored copy function,
---
lib/vhost/vhost_crypto.c | 123 +++++++++++++++------------------------
1 file changed, 46 insertions(+), 77 deletions(-)
Comments
On 6/16/22 16:46, David Marchand wrote:
> GCC 12 raises the following warning:
>
> In file included from ../lib/mempool/rte_mempool.h:46,
> from ../lib/mbuf/rte_mbuf.h:38,
> from ../lib/vhost/vhost_crypto.c:7:
> ../lib/vhost/vhost_crypto.c: In function ‘rte_vhost_crypto_fetch_requests’:
> ../lib/eal/x86/include/rte_memcpy.h:371:9: warning: array subscript 1 is
> outside array bounds of ‘struct virtio_crypto_op_data_req[1]’
> [-Warray-bounds]
> 371 | rte_mov32((uint8_t *)dst + 3 * 32, (const uint8_t *)src + 3 * 32);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../lib/vhost/vhost_crypto.c:1178:42: note: while referencing ‘req’
> 1178 | struct virtio_crypto_op_data_req req;
> | ^~~
>
> Split this function and separate the per descriptor copy.
> This makes the code clearer, and the compiler happier.
>
> Note: logs for errors have been moved to callers to avoid duplicates.
>
> Fixes: 3c79609fda7c ("vhost/crypto: handle virtually non-contiguous buffers")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> Changes since v2:
> - fixed 32-bits build,
>
> Changes since v1:
> - refactored copy function,
>
> ---
> lib/vhost/vhost_crypto.c | 123 +++++++++++++++------------------------
> 1 file changed, 46 insertions(+), 77 deletions(-)
>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
I'll wait until tuesday to apply it to my tree to let some time for testing
Thanks,
Maxime
On 6/16/22 16:46, David Marchand wrote:
> GCC 12 raises the following warning:
>
> In file included from ../lib/mempool/rte_mempool.h:46,
> from ../lib/mbuf/rte_mbuf.h:38,
> from ../lib/vhost/vhost_crypto.c:7:
> ../lib/vhost/vhost_crypto.c: In function ‘rte_vhost_crypto_fetch_requests’:
> ../lib/eal/x86/include/rte_memcpy.h:371:9: warning: array subscript 1 is
> outside array bounds of ‘struct virtio_crypto_op_data_req[1]’
> [-Warray-bounds]
> 371 | rte_mov32((uint8_t *)dst + 3 * 32, (const uint8_t *)src + 3 * 32);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../lib/vhost/vhost_crypto.c:1178:42: note: while referencing ‘req’
> 1178 | struct virtio_crypto_op_data_req req;
> | ^~~
>
> Split this function and separate the per descriptor copy.
> This makes the code clearer, and the compiler happier.
>
> Note: logs for errors have been moved to callers to avoid duplicates.
>
> Fixes: 3c79609fda7c ("vhost/crypto: handle virtually non-contiguous buffers")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> Changes since v2:
> - fixed 32-bits build,
>
> Changes since v1:
> - refactored copy function,
>
> ---
> lib/vhost/vhost_crypto.c | 123 +++++++++++++++------------------------
> 1 file changed, 46 insertions(+), 77 deletions(-)
>
Applied to dpdk-next-virtio/main.
Thanks,
Maxime
Hey everyone,
When running a Virtio performance test on a VM using VHost with this patch applied,
VHost gives the following error message:
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_FEATURES
> VHOST_CONFIG: (/tmp/vhost) negotiated Virtio features: 0x0
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_MEM_TABLE
> VHOST_CONFIG: (/tmp/vhost) guest memory region size: 0x80000000
> VHOST_CONFIG: (/tmp/vhost) guest physical addr: 0x0
> VHOST_CONFIG: (/tmp/vhost) guest virtual addr: 0x7f17c0000000
> VHOST_CONFIG: (/tmp/vhost) host virtual addr: 0x7f94c0000000
> VHOST_CONFIG: (/tmp/vhost) mmap addr : 0x7f94c0000000
> VHOST_CONFIG: (/tmp/vhost) mmap size : 0x80000000
> VHOST_CONFIG: (/tmp/vhost) mmap align: 0x40000000
> VHOST_CONFIG: (/tmp/vhost) mmap off : 0x0
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_NUM
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_BASE
> VHOST_CONFIG: (/tmp/vhost) vring base idx:0 last_used_idx:0 last_avail_idx:0.
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_ADDR
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_KICK
> VHOST_CONFIG: (/tmp/vhost) vring kick idx:0 file:37
> VHOST_CONFIG: (/tmp/vhost) reallocated virtqueue on node 1
> VHOST_CONFIG: (/tmp/vhost) reallocated device on node 1
> VHOST_CONFIG: (/tmp/vhost) virtio is now ready for processing.
> USER1: New Vhost-crypto Device /tmp/vhost, Device ID 0
> VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_CALL
> VHOST_CONFIG: (/tmp/vhost) vring call idx:0 file:38
> USER1: [VHOST-Crypto]: Session 1 created for vdev 0.
> USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> USER1: [VHOST-Crypto]: Failed to process sym request
> USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> USER1: [VHOST-Crypto]: Failed to process sym request
Due to this, performance test hangs and never finishes.
Kind Regards,
Jakub Poczatek
-----Original Message-----
From: Maxime Coquelin <maxime.coquelin@redhat.com>
Sent: Tuesday 21 June 2022 10:31
To: David Marchand <david.marchand@redhat.com>; dev@dpdk.org
Cc: stable@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Zhang, Roy Fan <roy.fan.zhang@intel.com>
Subject: Re: [PATCH v3] vhost/crypto: fix build with GCC 12
On 6/16/22 16:46, David Marchand wrote:
> GCC 12 raises the following warning:
>
> In file included from ../lib/mempool/rte_mempool.h:46,
> from ../lib/mbuf/rte_mbuf.h:38,
> from ../lib/vhost/vhost_crypto.c:7:
> ../lib/vhost/vhost_crypto.c: In function ‘rte_vhost_crypto_fetch_requests’:
> ../lib/eal/x86/include/rte_memcpy.h:371:9: warning: array subscript 1 is
> outside array bounds of ‘struct virtio_crypto_op_data_req[1]’
> [-Warray-bounds]
> 371 | rte_mov32((uint8_t *)dst + 3 * 32, (const uint8_t *)src + 3 * 32);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../lib/vhost/vhost_crypto.c:1178:42: note: while referencing ‘req’
> 1178 | struct virtio_crypto_op_data_req req;
> | ^~~
>
> Split this function and separate the per descriptor copy.
> This makes the code clearer, and the compiler happier.
>
> Note: logs for errors have been moved to callers to avoid duplicates.
>
> Fixes: 3c79609fda7c ("vhost/crypto: handle virtually non-contiguous buffers")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> Changes since v2:
> - fixed 32-bits build,
>
> Changes since v1:
> - refactored copy function,
>
> ---
> lib/vhost/vhost_crypto.c | 123 +++++++++++++++------------------------
> 1 file changed, 46 insertions(+), 77 deletions(-)
>
Applied to dpdk-next-virtio/main.
Thanks,
Maxime
Hi Maxime,
I know it is over Tuesday so we understand you merged the patch already.
But any suggestions? Should we raise a Bugzilla for this problem?
BTW we reverted the patch and the test finished no problem.
Regards,
Fan
> -----Original Message-----
> From: Poczatek, Jakub <jakub.poczatek@intel.com>
> Sent: Wednesday, June 22, 2022 10:02 AM
> To: Maxime Coquelin <maxime.coquelin@redhat.com>; David Marchand
> <david.marchand@redhat.com>; dev@dpdk.org
> Cc: stable@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>
> Subject: RE: [PATCH v3] vhost/crypto: fix build with GCC 12
>
> Hey everyone,
>
> When running a Virtio performance test on a VM using VHost with this patch
> applied,
> VHost gives the following error message:
>
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_FEATURES
> > VHOST_CONFIG: (/tmp/vhost) negotiated Virtio features: 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_MEM_TABLE
> > VHOST_CONFIG: (/tmp/vhost) guest memory region size: 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) guest physical addr: 0x0
> > VHOST_CONFIG: (/tmp/vhost) guest virtual addr: 0x7f17c0000000
> > VHOST_CONFIG: (/tmp/vhost) host virtual addr: 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap addr : 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap size : 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) mmap align: 0x40000000
> > VHOST_CONFIG: (/tmp/vhost) mmap off : 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_NUM
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_BASE
> > VHOST_CONFIG: (/tmp/vhost) vring base idx:0 last_used_idx:0
> last_avail_idx:0.
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_ADDR
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_KICK
> > VHOST_CONFIG: (/tmp/vhost) vring kick idx:0 file:37
> > VHOST_CONFIG: (/tmp/vhost) reallocated virtqueue on node 1
> > VHOST_CONFIG: (/tmp/vhost) reallocated device on node 1
> > VHOST_CONFIG: (/tmp/vhost) virtio is now ready for processing.
> > USER1: New Vhost-crypto Device /tmp/vhost, Device ID 0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_CALL
> > VHOST_CONFIG: (/tmp/vhost) vring call idx:0 file:38
> > USER1: [VHOST-Crypto]: Session 1 created for vdev 0.
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
>
> Due to this, performance test hangs and never finishes.
>
> Kind Regards,
> Jakub Poczatek
>
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday 21 June 2022 10:31
> To: David Marchand <david.marchand@redhat.com>; dev@dpdk.org
> Cc: stable@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>
> Subject: Re: [PATCH v3] vhost/crypto: fix build with GCC 12
>
>
>
> On 6/16/22 16:46, David Marchand wrote:
> > GCC 12 raises the following warning:
> >
> > In file included from ../lib/mempool/rte_mempool.h:46,
> > from ../lib/mbuf/rte_mbuf.h:38,
> > from ../lib/vhost/vhost_crypto.c:7:
> > ../lib/vhost/vhost_crypto.c: In function ‘rte_vhost_crypto_fetch_requests’:
> > ../lib/eal/x86/include/rte_memcpy.h:371:9: warning: array subscript 1 is
> > outside array bounds of ‘struct virtio_crypto_op_data_req[1]’
> > [-Warray-bounds]
> > 371 | rte_mov32((uint8_t *)dst + 3 * 32, (const uint8_t *)src + 3 * 32);
> > |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../lib/vhost/vhost_crypto.c:1178:42: note: while referencing ‘req’
> > 1178 | struct virtio_crypto_op_data_req req;
> > | ^~~
> >
> > Split this function and separate the per descriptor copy.
> > This makes the code clearer, and the compiler happier.
> >
> > Note: logs for errors have been moved to callers to avoid duplicates.
> >
> > Fixes: 3c79609fda7c ("vhost/crypto: handle virtually non-contiguous buffers")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> > Changes since v2:
> > - fixed 32-bits build,
> >
> > Changes since v1:
> > - refactored copy function,
> >
> > ---
> > lib/vhost/vhost_crypto.c | 123 +++++++++++++++------------------------
> > 1 file changed, 46 insertions(+), 77 deletions(-)
> >
>
> Applied to dpdk-next-virtio/main.
>
> Thanks,
> Maxime
Hello Jakub, Roy,
On Wed, Jun 22, 2022 at 11:01 AM Poczatek, Jakub
<jakub.poczatek@intel.com> wrote:
> When running a Virtio performance test on a VM using VHost with this patch applied,
> VHost gives the following error message:
>
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_FEATURES
> > VHOST_CONFIG: (/tmp/vhost) negotiated Virtio features: 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_MEM_TABLE
> > VHOST_CONFIG: (/tmp/vhost) guest memory region size: 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) guest physical addr: 0x0
> > VHOST_CONFIG: (/tmp/vhost) guest virtual addr: 0x7f17c0000000
> > VHOST_CONFIG: (/tmp/vhost) host virtual addr: 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap addr : 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap size : 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) mmap align: 0x40000000
> > VHOST_CONFIG: (/tmp/vhost) mmap off : 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_NUM
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_BASE
> > VHOST_CONFIG: (/tmp/vhost) vring base idx:0 last_used_idx:0 last_avail_idx:0.
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_ADDR
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_KICK
> > VHOST_CONFIG: (/tmp/vhost) vring kick idx:0 file:37
> > VHOST_CONFIG: (/tmp/vhost) reallocated virtqueue on node 1
> > VHOST_CONFIG: (/tmp/vhost) reallocated device on node 1
> > VHOST_CONFIG: (/tmp/vhost) virtio is now ready for processing.
> > USER1: New Vhost-crypto Device /tmp/vhost, Device ID 0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_CALL
> > VHOST_CONFIG: (/tmp/vhost) vring call idx:0 file:38
> > USER1: [VHOST-Crypto]: Session 1 created for vdev 0.
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
Could you test with the following snippet:
diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
index 96ffb82a5d..54946f46d9 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -610,8 +610,7 @@ copy_data(void *data, struct vhost_crypto_data_req *vc_req,
return -1;
left -= copied;
data = RTE_PTR_ADD(data, copied);
- desc++;
- } while (desc < head + max_n_descs && left != 0);
+ } while (left != 0 && ++desc < head + max_n_descs);
if (unlikely(left != 0))
return -1;
Hey David,
The code change fixes the errors and the performance test completes.
Kind Regards,
Jakub Poczatek
-----Original Message-----
From: David Marchand <david.marchand@redhat.com>
Sent: Wednesday 22 June 2022 15:08
To: Poczatek, Jakub <jakub.poczatek@intel.com>; Zhang, Roy Fan <roy.fan.zhang@intel.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; dev@dpdk.org; stable@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>
Subject: Re: [PATCH v3] vhost/crypto: fix build with GCC 12
Hello Jakub, Roy,
On Wed, Jun 22, 2022 at 11:01 AM Poczatek, Jakub <jakub.poczatek@intel.com> wrote:
> When running a Virtio performance test on a VM using VHost with this
> patch applied, VHost gives the following error message:
>
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_FEATURES
> > VHOST_CONFIG: (/tmp/vhost) negotiated Virtio features: 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_MEM_TABLE
> > VHOST_CONFIG: (/tmp/vhost) guest memory region size: 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) guest physical addr: 0x0
> > VHOST_CONFIG: (/tmp/vhost) guest virtual addr: 0x7f17c0000000
> > VHOST_CONFIG: (/tmp/vhost) host virtual addr: 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap addr : 0x7f94c0000000
> > VHOST_CONFIG: (/tmp/vhost) mmap size : 0x80000000
> > VHOST_CONFIG: (/tmp/vhost) mmap align: 0x40000000
> > VHOST_CONFIG: (/tmp/vhost) mmap off : 0x0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_NUM
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_BASE
> > VHOST_CONFIG: (/tmp/vhost) vring base idx:0 last_used_idx:0 last_avail_idx:0.
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_ADDR
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_KICK
> > VHOST_CONFIG: (/tmp/vhost) vring kick idx:0 file:37
> > VHOST_CONFIG: (/tmp/vhost) reallocated virtqueue on node 1
> > VHOST_CONFIG: (/tmp/vhost) reallocated device on node 1
> > VHOST_CONFIG: (/tmp/vhost) virtio is now ready for processing.
> > USER1: New Vhost-crypto Device /tmp/vhost, Device ID 0
> > VHOST_CONFIG: (/tmp/vhost) read message VHOST_USER_SET_VRING_CALL
> > VHOST_CONFIG: (/tmp/vhost) vring call idx:0 file:38
> > USER1: [VHOST-Crypto]: Session 1 created for vdev 0.
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
> > USER1: [VHOST-Crypto]: Incorrect virtio descriptor
> > USER1: [VHOST-Crypto]: Failed to process sym request
Could you test with the following snippet:
diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c index 96ffb82a5d..54946f46d9 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -610,8 +610,7 @@ copy_data(void *data, struct vhost_crypto_data_req *vc_req,
return -1;
left -= copied;
data = RTE_PTR_ADD(data, copied);
- desc++;
- } while (desc < head + max_n_descs && left != 0);
+ } while (left != 0 && ++desc < head + max_n_descs);
if (unlikely(left != 0))
return -1;
--
David Marchand
On Wed, Jun 22, 2022 at 5:22 PM Poczatek, Jakub
<jakub.poczatek@intel.com> wrote:
>
> Hey David,
>
> The code change fixes the errors and the performance test completes.
I posted this fix against (not yet pulled into main) next-virtio repo.
@@ -565,94 +565,58 @@ get_data_ptr(struct vhost_crypto_data_req *vc_req,
return data;
}
-static __rte_always_inline int
-copy_data(void *dst_data, struct vhost_crypto_data_req *vc_req,
- struct vhost_crypto_desc *head,
- struct vhost_crypto_desc **cur_desc,
- uint32_t size, uint32_t max_n_descs)
+static __rte_always_inline uint32_t
+copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req,
+ struct vhost_crypto_desc *desc, uint32_t size)
{
- struct vhost_crypto_desc *desc = *cur_desc;
- uint64_t remain, addr, dlen, len;
- uint32_t to_copy;
- uint8_t *data = dst_data;
- uint8_t *src;
- int left = size;
-
- to_copy = RTE_MIN(desc->len, (uint32_t)left);
- dlen = to_copy;
- src = IOVA_TO_VVA(uint8_t *, vc_req, desc->addr, &dlen,
- VHOST_ACCESS_RO);
- if (unlikely(!src || !dlen))
- return -1;
+ uint64_t remain;
+ uint64_t addr;
+
+ remain = RTE_MIN(desc->len, size);
+ addr = desc->addr;
+ do {
+ uint64_t len;
+ void *src;
+
+ len = remain;
+ src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO);
+ if (unlikely(src == NULL || len == 0))
+ return 0;
- rte_memcpy((uint8_t *)data, src, dlen);
- data += dlen;
+ rte_memcpy(dst, src, len);
+ remain -= len;
+ /* cast is needed for 32-bit architecture */
+ dst = RTE_PTR_ADD(dst, (size_t)len);
+ addr += len;
+ } while (unlikely(remain != 0));
- if (unlikely(dlen < to_copy)) {
- remain = to_copy - dlen;
- addr = desc->addr + dlen;
+ return RTE_MIN(desc->len, size);
+}
- while (remain) {
- len = remain;
- src = IOVA_TO_VVA(uint8_t *, vc_req, addr, &len,
- VHOST_ACCESS_RO);
- if (unlikely(!src || !len)) {
- VC_LOG_ERR("Failed to map descriptor");
- return -1;
- }
- rte_memcpy(data, src, len);
- addr += len;
- remain -= len;
- data += len;
- }
- }
+static __rte_always_inline int
+copy_data(void *data, struct vhost_crypto_data_req *vc_req,
+ struct vhost_crypto_desc *head, struct vhost_crypto_desc **cur_desc,
+ uint32_t size, uint32_t max_n_descs)
+{
+ struct vhost_crypto_desc *desc = *cur_desc;
+ uint32_t left = size;
- left -= to_copy;
+ do {
+ uint32_t copied;
- while (desc >= head && desc - head < (int)max_n_descs && left) {
- desc++;
- to_copy = RTE_MIN(desc->len, (uint32_t)left);
- dlen = to_copy;
- src = IOVA_TO_VVA(uint8_t *, vc_req, desc->addr, &dlen,
- VHOST_ACCESS_RO);
- if (unlikely(!src || !dlen)) {
- VC_LOG_ERR("Failed to map descriptor");
+ copied = copy_data_from_desc(data, vc_req, desc, left);
+ if (copied == 0)
return -1;
- }
-
- rte_memcpy(data, src, dlen);
- data += dlen;
-
- if (unlikely(dlen < to_copy)) {
- remain = to_copy - dlen;
- addr = desc->addr + dlen;
-
- while (remain) {
- len = remain;
- src = IOVA_TO_VVA(uint8_t *, vc_req, addr, &len,
- VHOST_ACCESS_RO);
- if (unlikely(!src || !len)) {
- VC_LOG_ERR("Failed to map descriptor");
- return -1;
- }
-
- rte_memcpy(data, src, len);
- addr += len;
- remain -= len;
- data += len;
- }
- }
-
- left -= to_copy;
- }
+ left -= copied;
+ data = RTE_PTR_ADD(data, copied);
+ desc++;
+ } while (desc < head + max_n_descs && left != 0);
- if (unlikely(left > 0)) {
- VC_LOG_ERR("Incorrect virtio descriptor");
+ if (unlikely(left != 0))
return -1;
- }
- if (unlikely(desc - head == (int)max_n_descs))
+ if (unlikely(desc == head + max_n_descs))
*cur_desc = NULL;
else
*cur_desc = desc + 1;
@@ -852,6 +816,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
/* iv */
if (unlikely(copy_data(iv_data, vc_req, head, &desc,
cipher->para.iv_len, max_n_descs))) {
+ VC_LOG_ERR("Incorrect virtio descriptor");
ret = VIRTIO_CRYPTO_BADMSG;
goto error_exit;
}
@@ -883,6 +848,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
if (unlikely(copy_data(rte_pktmbuf_mtod(m_src, uint8_t *),
vc_req, head, &desc, cipher->para.src_data_len,
max_n_descs) < 0)) {
+ VC_LOG_ERR("Incorrect virtio descriptor");
ret = VIRTIO_CRYPTO_BADMSG;
goto error_exit;
}
@@ -1006,6 +972,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
/* iv */
if (unlikely(copy_data(iv_data, vc_req, head, &desc,
chain->para.iv_len, max_n_descs) < 0)) {
+ VC_LOG_ERR("Incorrect virtio descriptor");
ret = VIRTIO_CRYPTO_BADMSG;
goto error_exit;
}
@@ -1037,6 +1004,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
if (unlikely(copy_data(rte_pktmbuf_mtod(m_src, uint8_t *),
vc_req, head, &desc, chain->para.src_data_len,
max_n_descs) < 0)) {
+ VC_LOG_ERR("Incorrect virtio descriptor");
ret = VIRTIO_CRYPTO_BADMSG;
goto error_exit;
}
@@ -1121,6 +1089,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,
if (unlikely(copy_data(digest_addr, vc_req, head, &digest_desc,
chain->para.hash_result_len,
max_n_descs) < 0)) {
+ VC_LOG_ERR("Incorrect virtio descriptor");
ret = VIRTIO_CRYPTO_BADMSG;
goto error_exit;
}