vhost: add sanity check for resubmiting reqs in split ring
PATCH 1/1 vhost: add sanity check for resubmiting reqs in split ring
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
lib/vhost/vhost_user.c +8 -2
@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num); + }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; }
Signature · 1 line
2.31.1
ping...
BTW, how could I retrigger the failure CI? The failure is not about this patch.
Thanks,
Feng Li
Quoted 33 lines · Li Feng <[email protected]> 于2021年8月27日周五 下午1:16写道:
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +8
-3@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num); + }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; } --2.31.1
Quoted 33 lines · Li Feng <[email protected]> 于2021年8月27日周五 下午1:16写道:
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +8
-3@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num); + }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; } --2.31.1
Hi Li,
Adding Jin Yu who introduced this function.
Quoted 2 lines · Li Feng
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
Quoted 10 lines
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +0
-0
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1829
Quoted 9 lines
lib/vhost/vhost_user.c +4
-2@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num);
If such error happens, shouldn't we return RTE_VHOST_MSG_RESULT_ERR instead of just logging an error?
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1836
Quoted 8 lines
lib/vhost/vhost_user.c +4
-0+ }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; }
Regards,
Maxime
Quoted 3 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Looks like Jin Yu has left Intel, Chenbo, could you find someone from the Intel SPDK team to look at it?
Quoted 41 lines · Li Feng
Quoted 2 lines
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
Quoted 17 lines
Signed-off-by Li Feng <[email protected]>---
lib/vhost/vhost_user.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +2
-2@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(structvirtio_net *dev, last_io = inflight_split->last_inflight_io; if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight = 0; - rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + if (unlikely(last_io >= inflight_split->desc_num)) { + VHOST_LOG_CONFIG(ERR, "last_inflight_io '%"PRIu16"'Quoted 3 lines
exceeds inflight "
+ "queue size (%"PRIu16").\n",last_io, +inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?Quoted 7 lines
+ } else {
+ inflight_split->desc[last_io].inflight = 0; +rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + }
inflight_split->used_idx=used->idx; }Regards,
Maxime
Hi Changpeng,
Quoted 10 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, October 14, 2021 4:26 PM
To: Li Feng <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v1] vhost: add sanity check for resubmiting reqs in split ring
Quoted 7 lines
Quoted 3 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Looks like Jin Yu has left Intel, Chenbo, could you find someone from the Intel SPDK team to look at it?
Could you or your team member help check this?
Thanks,
Chenbo
Quoted 42 lines
Quoted 42 lines · Li Feng
Quoted 2 lines
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
Quoted 17 lines
Signed-off-by Li Feng <[email protected]>---
lib/vhost/vhost_user.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +2
-2@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(structvirtio_net *dev, last_io = inflight_split->last_inflight_io; if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight = 0; - rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + if (unlikely(last_io >= inflight_split->desc_num)) { + VHOST_LOG_CONFIG(ERR, "last_inflight_io '%"PRIu16"'Quoted 3 lines
exceeds inflight "
+ "queue size (%"PRIu16").\n",last_io, +inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?Quoted 7 lines
+ } else {
+ inflight_split->desc[last_io].inflight = 0; +rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + }
inflight_split->used_idx=used->idx; }Regards,
Maxime
I agree with Maxime, just add an error log doesn't help anything, there might be something wrong in other places, I don't have the context for this issue, if this can be reproduced in SPDK, I suggest to submit an issue to SPDK first.
Quoted 75 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Thursday, October 14, 2021 4:28 PM
To: Maxime Coquelin <[email protected]>; Li Feng <[email protected]>; Liu, Changpeng <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v1] vhost: add sanity check for resubmiting reqs in split ringHi Changpeng,
Quoted 10 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, October 14, 2021 4:26 PM
To: Li Feng <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v1] vhost: add sanity check for resubmiting reqs in split ringQuoted 7 lines
Quoted 3 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Looks like Jin Yu has left Intel, Chenbo, could you find someone from the Intel SPDK team to look at it?
Could you or your team member help check this?
Thanks,
ChenboQuoted 42 lines
Quoted 42 lines · Li Feng
Quoted 2 lines
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
Quoted 17 lines
Signed-off-by Li Feng <[email protected]>---
lib/vhost/vhost_user.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +2
-2@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(structvirtio_net *dev, last_io = inflight_split->last_inflight_io; if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight = 0; - rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + if (unlikely(last_io >= inflight_split->desc_num)) { + VHOST_LOG_CONFIG(ERR, "last_inflight_io '%"PRIu16"'Quoted 3 lines
exceeds inflight "
+ "queue size (%"PRIu16").\n",last_io, +inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?Quoted 7 lines
+ } else {
+ inflight_split->desc[last_io].inflight = 0; +rte_atomic_thread_fence(__ATOMIC_SEQ_CST); + }
inflight_split->used_idx=used->idx; }Regards,
Maxime
Thank you for your response.
Quoted 11 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Quoted 2 lines · Li Feng
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
OK, I will send the v2 version.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +0
-0@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;
Quoted 10 lines
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1829
Quoted 7 lines
lib/vhost/vhost_user.c +4
-2if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?
I think ignoring the error is ok. No one could handle this error correctly. At this time the guest virtio driver of this virtqueue may be in an incorrect state.
Quoted 13 lines
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1836
Quoted 9 lines
lib/vhost/vhost_user.c +4
-0+ }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; }Regards,
Maxime
Quoted 40 lines · Li Feng
Thank you for your response.
Quoted 11 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Quoted 2 lines · Li Feng
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
OK, I will send the v2 version.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +0
-0@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;Quoted 10 lines
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1829
Quoted 7 lines
lib/vhost/vhost_user.c +4
-2if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?
Quoted 3 lines
I think ignoring the error is ok. No one could handle this error correctly. At this time the guest virtio driver of this virtqueue may be in an incorrect state.
Not sure to understand how it can happen.
But I see that last_io is actually vq->inflight_split->last_inflight_io, which is set only by rte_vhost_set_last_inflight_io_split() API.
Shouldn't there be a sanity check there to ensure that last_inflight_io is smaller than desc_num value set by the frontend?
Returning an error is the right thing to do anyway.
Quoted 14 lines
Quoted 13 lines
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1836
Quoted 9 lines
lib/vhost/vhost_user.c +4
-0+ }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; }Regards,
Maxime
Quoted 44 lines · Maxime Coquelin
Quoted 40 lines · Li Feng
Thank you for your response.
Quoted 11 lines · Maxime Coquelin
Hi Li,
Adding Jin Yu who introduced this function.
Quoted 2 lines · Li Feng
When getting reqs from the avail ring, the id may exceed inflight queue size. Then the dpdk will crash forever.
You need to add Fixes tag and Cc [email protected] so that it can be backported.
OK, I will send the v2 version.
Quoted 23 lines
Quoted 11 lines
Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/vhost/vhost_user.c +0
-0lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1829
Quoted 9 lines
lib/vhost/vhost_user.c +4
-2@@ -1823,8 +1823,14 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, last_io = inflight_split->last_inflight_io;if (inflight_split->used_idx != used->idx) { - inflight_split->desc[last_io].inflight =0 ; -rte_atomic_thread_fence (__ATOMIC_SEQ_CST); +if (unlikely (last_io >= inflight_split->desc_num)) { +VHOST_LOG_CONFIG (ERR ,"last_inflight_io '%" PRIu16"' exceeds inflight " +"queue size (%" PRIu16").\n" , last_io, + inflight_split->desc_num);If such error happens, shouldn't we return
RTE_VHOST_MSG_RESULT_ERRinstead of just logging an error?
Quoted 7 lines
Quoted 3 lines
I think ignoring the error is ok. No one could handle this error correctly. At this time the guest virtio driver of this virtqueue may be in an incorrect state.
Not sure to understand how it can happen.
But I see thatlast_iois actuallyvq->inflight_split->last_inflight_io, which is set only byrte_vhost_set_last_inflight_io_split()API.
The polluted value is from the frontend driver.
My environment occurs this issue, and a VM is hang, so I guess this bad value comes from it.
Quoted 3 lines
Shouldn't there be a sanity check there to ensure that
last_inflight_iois smaller thandesc_numvalue set by the frontend?
Yes, putting a check in rte_vhost_set_last_inflight_io_split is also ok. I will send the v2 version that includes this.
Thanks.
Quoted 2 lines
Returning an error is the right thing to do anyway.
OK.
Quoted 16 lines
Quoted 15 lines
Quoted 14 lines
lib/vhost/vhost_user.c vhost_check_queue_inflights_split(struct virtio_net *dev, · line 1836
Quoted 10 lines
lib/vhost/vhost_user.c +4
-0+ }else { + inflight_split->desc[last_io].inflight =0 ; +rte_atomic_thread_fence (__ATOMIC_SEQ_CST); + } inflight_split->used_idx = used->idx; }Regards,
Maxime
PATCH v2 1/1 vhost: add sanity check when operating the split ring
In reply to Li FengThe idx in rte_vhost_set_last_inflight_io_split is from the frontend driver, check if it's in the virtqueue range.
--- lib/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+)
lib/vhost/vhost.c +3 -0
@@ -1226,6 +1226,9 @@ rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx,if (unlikely (!vq->inflight_split))return -1 ; +if (unlikely (idx >= vq->size)) +return -1 ; + vq->inflight_split->last_inflight_io = idx;return 0 ; }
Signature · 1 line
2.31.1
Re: [dpdk-dev] [PATCH v2] vhost: add sanity check when operating the split ring
The title is too vague, I would put something like:
vhost: add sanity check on inflight last index
Quoted 1 line · Li Feng
The idx in
rte_vhost_set_last_inflight_io_splitis from the frontend
s/idx/index/
Quoted 16 lines
driver, check if it's in the virtqueue range.
Fixes bb0c2de9602b ("vhost: add APIs to operate inflight ring")Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/vhost.c +0
-0
lib/vhost/vhost.c rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, · line 1234
Quoted 9 lines
lib/vhost/vhost.c +3
-0@@ -1226,6 +1226,9 @@ rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx,if (unlikely (!vq->inflight_split))return -1 ; +if (unlikely (idx >= vq->size)) +return -1 ; + vq->inflight_split->last_inflight_io = idx;return 0 ; }
Other than that, this is fine to me:
If my suggestions are fine for you, I can fix while applying.
Thanks,
Maxime
Re: [dpdk-dev] [PATCH v2] vhost: add sanity check when operating the split ring
Quoted 38 lines · Maxime Coquelin
The title is too vague, I would put something like:
vhost: add sanity check on inflight last index
Quoted 1 line · Li Feng
The idx in
rte_vhost_set_last_inflight_io_splitis from the frontends/idx/index/
Quoted 16 lines
driver, check if it's in the virtqueue range.
Fixes bb0c2de9602b ("vhost: add APIs to operate inflight ring")Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/vhost.c +0
-0lib/vhost/vhost.c rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, · line 1234
Quoted 9 lines
lib/vhost/vhost.c +3
-0@@ -1226,6 +1226,9 @@ rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx,if (unlikely (!vq->inflight_split))return -1 ; +if (unlikely (idx >= vq->size)) +return -1 ; + vq->inflight_split->last_inflight_io = idx;return 0 ; }Other than that, this is fine to me:
Quoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>If my suggestions are fine for you, I can fix while applying.
It's fine.
Quoted 3 lines
Thanks,
Maxime
Maxime Coquelin
AppliedRe: [dpdk-dev] [PATCH v2] vhost: add sanity check when operating the split ring
Quoted 40 lines · Li Feng
Quoted 38 lines · Maxime Coquelin
The title is too vague, I would put something like:
vhost: add sanity check on inflight last index
Quoted 1 line · Li Feng
The idx in
rte_vhost_set_last_inflight_io_splitis from the frontends/idx/index/
Quoted 16 lines
driver, check if it's in the virtqueue range.
Fixes bb0c2de9602b ("vhost: add APIs to operate inflight ring")Signed-off-by Li Feng <[email protected]>--- lib/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/vhost.c +0
-0lib/vhost/vhost.c rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, · line 1234
Quoted 9 lines
lib/vhost/vhost.c +3
-0@@ -1226,6 +1226,9 @@ rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx,if (unlikely (!vq->inflight_split))return -1 ; +if (unlikely (idx >= vq->size)) +return -1 ; + vq->inflight_split->last_inflight_io = idx;return 0 ; }Other than that, this is fine to me:
Quoted 10 lines
Quoted 4 lines
Reviewed-by Maxime Coquelin <[email protected]>If my suggestions are fine for you, I can fix while applying.
It's fine.
Quoted 3 lines
Thanks,
Maxime
Applied to dpdk-next-virtio/main.
Thanks,
Maxime