Skip to contentSkip to conversation

Memory hotplug fix

PATCH Superseded Danylo Vodopianov 4 participants 16 messages May 29, 2025 – Oct 14, 2025

lore
Share & tools
lore
#0 lore raw

cover Memory hotplug fix

Hi everyone.
We detected an issue with the memory hotplug feature and virtio devices while working with vitrio in DPDK.In general, the issue is around the user request VHOST_USER_SET_MEM_TABLE and locking queues for this request
(https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512)
When the vhost_user receives the request VHOST_USER_SET_MEM_TABLE, it locks queues only when the flag lock_all_qps is true(it is always true), AND the flag VIRTIO_DEV_VDPA_CONFIGURED is not set.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3181
In the case of a memory hot plug, the flag VIRTIO_DEV_VDPA_CONFIGURED is always set, and due to this, the queues are never locked while they are expected to be locked.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512.
The quick solution is to add the check for request type and do lock queues always if we have request VHOST_USER_SET_MEM_TABLE. Something like this, in general
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3179

if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) || request == VHOST_USER_SET_MEM_TABLE) {
...

Danylo Vodopianov (1):
vhost: handle virtqueue locking for memory hotplug

 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.5
#1 lore raw

PATCH 1/1 vhost: handle virtqueue locking for memory hotplug

For vDPA devices, virtqueues are not locked once the device has been configured.
In the commit 5e8fcc60b59d
("vhost: enhance virtqueue access lock asserts"),
the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

---
 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +7 -1
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* Lock all queue pairs if the device is not configured for vDPA,
+		 * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+		 * This ensures proper queue locking for memory table updates and guest
+		 * memory hotplug.
+		 */
+		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+			request == VHOST_USER_SET_MEM_TABLE) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
 		}
Signature · 1 line
2.43.5
#2 lore raw

PATCH v2 1/1 vhost: handle virtqueue locking for memory hotplug

For vDPA devices, virtqueues are not locked once the device has been configured. In the commit
5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

---
 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +7 -1
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* Lock all queue pairs if the device is not configured for vDPA,
+		 * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+		 * This ensures proper queue locking for memory table updates and guest
+		 * memory hotplug.
+		 */
+		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+			request == VHOST_USER_SET_MEM_TABLE) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
 		}
Signature · 1 line
2.47.1
#3 lore raw

v3 cover Memory hotplug fix

Hi everyone.
We detected an issue with the memory hotplug feature and virtio devices while working with vitrio in DPDK.In general, the issue is around the user request VHOST_USER_SET_MEM_TABLE and locking queues for this request
(https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512)
When the vhost_user receives the request VHOST_USER_SET_MEM_TABLE, it locks queues only when the flag lock_all_qps is true(it is always true), AND the flag VIRTIO_DEV_VDPA_CONFIGURED is not set.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3181
In the case of a memory hot plug, the flag VIRTIO_DEV_VDPA_CONFIGURED is always set, and due to this, the queues are never locked while they are expected to be locked.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512.
The quick solution is to add the check for request type and do lock queues always if we have request VHOST_USER_SET_MEM_TABLE. Something like this, in general
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3179

if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) || request == VHOST_USER_SET_MEM_TABLE) {
...

Danylo Vodopianov (1):
vhost: handle virtqueue locking for memory hotplug

 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.1
#4 lore raw

PATCH v3 1/1 vhost: handle virtqueue locking for memory hotplug

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

---
 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +7 -1
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* Lock all queue pairs if the device is not configured for vDPA,
+		 * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+		 * This ensures proper queue locking for memory table updates and guest
+		 * memory hotplug.
+		 */
+		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+			request == VHOST_USER_SET_MEM_TABLE) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
 		}
Signature · 1 line
2.47.1
#5 lore raw

v4 cover Memory hotplug fix

Hi everyone.
We detected an issue with the memory hotplug feature and virtio devices while working with vitrio in DPDK.In general, the issue is around the user request VHOST_USER_SET_MEM_TABLE and locking queues for this request
(https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512)
When the vhost_user receives the request VHOST_USER_SET_MEM_TABLE, it locks queues only when the flag lock_all_qps is true(it is always true), AND the flag VIRTIO_DEV_VDPA_CONFIGURED is not set.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3181
In the case of a memory hot plug, the flag VIRTIO_DEV_VDPA_CONFIGURED is always set, and due to this, the queues are never locked while they are expected to be locked.
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n1512.
The quick solution is to add the check for request type and do lock queues always if we have request VHOST_USER_SET_MEM_TABLE. Something like this, in general
https://git.dpdk.org/dpdk-stable/tree/lib/vhost/vhost_user.c#n3179

if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) || request == VHOST_USER_SET_MEM_TABLE) {
...

Danylo Vodopianov (1):
vhost: handle virtqueue locking for memory hotplug

 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.1
#6 lore raw

PATCH v4 1/1 vhost: handle virtqueue locking for memory hotplug

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

---
 lib/vhost/vhost_user.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +7 -1
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* Lock all queue pairs if the device is not configured for vDPA,
+		 * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+		 * This ensures proper queue locking for memory table updates and guest
+		 * memory hotplug.
+		 */
+		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+			request == VHOST_USER_SET_MEM_TABLE) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
 		}
Signature · 1 line
2.47.1
#7 lore raw

Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hello Danylo,

Quoted 22 lines · Danylo Vodopianov

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

Quoted 5 lines

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

s/using/use/

It needs a fixes tag, and [email protected] should be cc'ed, so that it gets backported to LTS branches.

Quoted 12 lines
---
  lib/vhost/vhost_user.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
  	 * would cause a dead lock.

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3187

Quoted 10 lines
lib/vhost/vhost_user.c +7 -1
  	 */
  	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+		/* Lock all queue pairs if the device is not configured for vDPA,
+		 * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+		 * This ensures proper queue locking for memory table updates and guest
+		 * memory hotplug.
+		 */
+		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+			request == VHOST_USER_SET_MEM_TABLE) {

It looks like a workaround, and I'm afraid it could cause regression
with some vDPA devices, or that it would not be enough and we would have to add other requests as exception.

Wouldn't it better to modify VHOST_USER_ASSERT_LOCK() so that it takes into account the VIRTIO_DEV_VDPA_CONFIGURED flag?

Thanks,
Maxime

Quoted 3 lines
lib/vhost/vhost_user.c +0 -0
  			vhost_user_lock_all_queue_pairs(dev);
  			unlock_required = 1;
  		}
#8 lore raw

RE: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hello, Maxime

Thank you for your review.
If I understand correctly, you propose modifying the VHOST_USER_ASSERT_LOCK() macro so that a VHOST_USER_SET_MEM_TABLE request does not trigger an assertion.
However, I believe such modification would not be appropriate, as it would revert the logic introduced in commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"). With this approach, we would be performing memory hotplug without queue locking, which could lead to unintended consequences. Regarding VDPA device regression. We faced with this issue when we request the number of lcores that the default amount of memory on the socket cannot handle it.
So, regression occurred during the startup part, during device configuration when it creates pkt mbuf pool.

Let me know your thoughts regarding this.

________________________________
От: Maxime Coquelin <[email protected]>
Отправлено: 3 июня 2025 г. 15:30
Кому: Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> Копия: [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]>
Тема: Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hello Danylo,

Quoted 22 lines · Danylo Vodopianov

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

Quoted 5 lines

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

s/using/use/

It needs a fixes tag, and [email protected] should be cc'ed, so that it gets backported to LTS branches.

Quoted 12 lines
---
  lib/vhost/vhost_user.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
        * would cause a dead lock.

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3187

Quoted 10 lines
lib/vhost/vhost_user.c +7 -1
        */
       if (msg_handler != NULL && msg_handler->lock_all_qps) {
-             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+             /* Lock all queue pairs if the device is not configured for vDPA,
+              * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+              * This ensures proper queue locking for memory table updates and guest
+              * memory hotplug.
+              */
+             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+                     request == VHOST_USER_SET_MEM_TABLE) {

It looks like a workaround, and I'm afraid it could cause regression with some vDPA devices, or that it would not be enough and we would have to add other requests as exception.

Wouldn't it better to modify VHOST_USER_ASSERT_LOCK() so that it takes into account the VIRTIO_DEV_VDPA_CONFIGURED flag?

Thanks,
Maxime

Quoted 3 lines
lib/vhost/vhost_user.c +0 -0
                       vhost_user_lock_all_queue_pairs(dev);
                       unlock_required = 1;
               }
#9 lore raw

Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hi Danylo,

Quoted 10 lines · Danylo Vodopianov

Hello, Maxime

Thank you for your review.
If I understand correctly, you propose modifying the | VHOST_USER_ASSERT_LOCK()| macro so that a |VHOST_USER_SET_MEM_TABLE|
 request does not trigger an assertion.
However, I believe such modification would not be appropriate, as it would revert the logic introduced in commit |5e8fcc60b59d| ("vhost: enhance virtqueue access lock asserts"). With this approach, we would be performing memory hotplug without queue locking, which could lead to unintended consequences. Regarding VDPA device regression. We faced with this issue when we request the number of lcores that the default amount of memory on the socket cannot handle it.
So, regression occurred during the startup part, during device configuration when it creates pkt mbuf pool.

Let me know your thoughts regarding this.

No, my point was to modify VHOST_USER_ASSERT_LOCK() to no trigger an assertion in case vDPA is configured, as we don't want to lock in this case.

Regards,
Maxime

Quoted 80 lines

------------------------------------------------------------------------
*От:* Maxime Coquelin <[email protected]>
*Отправлено:* 3 июня 2025 г. 15:30
*Кому:* Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> *Копия:* [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]>
*Тема:* Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug
Hello Danylo,

Quoted 22 lines · Danylo Vodopianov

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

Quoted 5 lines

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

s/using/use/

It needs a fixes tag, and [email protected] should be cc'ed, so that it gets backported to LTS branches.

Quoted 12 lines

---
   lib/vhost/vhost_user.c | 8 +++++++-

   1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
          * would cause a dead lock.

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3187

Quoted 10 lines
lib/vhost/vhost_user.c +7 -1
          */
         if (msg_handler != NULL && msg_handler->lock_all_qps) {
-             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+             /* Lock all queue pairs if the device is not configured for vDPA,
+              * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+              * This ensures proper queue locking for memory table updates and guest
+              * memory hotplug.
+              */
+             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+                     request == VHOST_USER_SET_MEM_TABLE) {

It looks like a workaround, and I'm afraid it could cause regression with some vDPA devices, or that it would not be enough and we would have to add other requests as exception.

Wouldn't it better to modify VHOST_USER_ASSERT_LOCK() so that it takes into account the VIRTIO_DEV_VDPA_CONFIGURED flag?

Thanks,
Maxime

Quoted 3 lines
lib/vhost/vhost_user.c +0 -0
                         vhost_user_lock_all_queue_pairs(dev);
                         unlock_required = 1;
                 }
#10 lore raw

RE: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hi, Maxime

I understand your point. However we coould have a situation like this, could resize twice:
VHOST_CONFIG: (/usr/local/var/run/stdvio4) read message VHOST_USER_SET_MEM_TABLE
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest memory region size: 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest physical addr: 0x140000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest virtual addr: 0x140000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) host virtual addr: 0x7fde00000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap addr : 0x7fde00000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap size : 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap align: 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap off : 0x0
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest memory region size: 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest physical addr: 0x11c0000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest virtual addr: 0x11c0000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) host virtual addr: 0x7fddc0000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap addr : 0x7fddc0000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap size : 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap align: 0x40000000
VHOST_CONFIG: (/usr/local/var/run/stdvio4) mmap off : 0x0

When we set memory region twice. After first iteration VIRTIO_DEV_VDPA_CONFIGURED flag will be unset here: https://github.com/DPDK/dpdk/blob/main/lib/vhost/vhost_user.c#L1425 On the second iteration, this leads to an rte_panic, as queues are accessed without a lock.

So we should check vhost message id ( VHOST_USER_SET_MEM_TABLE ).

However, extend VHOST_USER_ASSERT_LOCK macros with additional check if we work with this message VHOST_USER_SET_MEM_TABLE not handle this case, therefore translate_ring_addresses function calls q_assert_lock directly, without macros wrapper. In this function is check access_lock vhost_virtqueue and this case should be handle.

To address the described issue, we need to make the following changes:

1. Extend VHOST_USER_ASSERT_LOCK macro:
* Add a check for the VHOST_USER_SET_MEM_TABLE message ID.
* Skip rte_panic if the message ID matches VHOST_USER_SET_MEM_TABLE.
2. Modify translate_ring_addresses function:
* Extend its signature to include the id parameter (message ID).
* Add logic to skip vq_assert_lock if the message ID matches VHOST_USER_SET_MEM_TABLE.

1.
Extend VHOST_USER_ASSERT_LOCK Macro:

#define VHOST_USER_ASSERT_LOCK(dev, vq, id) \
    do { \
        if ((id) == VHOST_USER_SET_MEM_TABLE) \
            break; \
        if (!(vq)->access_ok) \
            rte_panic("Virtqueue access lock not held\n"); \
    } while (0

1.
Modify translate_ring_addresses Function:

static int
translate_ring_addresses(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t id)

{
    if (id != VHOST_USER_SET_MEM_TABLE)
        vq_assert_lock(dev, vq);

    // Existing logic for translating ring addresses...
    // ...existing code...
    return 0;
}

This approach requires extending more functions with conditional checks to handle cases where queue locking should be ignored when the memory table is impacted.

Do you have any thoughts about this? Or I should rework my patchset according to this described solution above ?

________________________________
От: Maxime Coquelin <[email protected]>
Отправлено: 12 июня 2025 г. 14:38
Кому: Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> Копия: [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]>
Тема: Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hi Danylo,

Quoted 17 lines · Danylo Vodopianov

Hello, Maxime

Thank you for your review.
If I understand correctly, you propose modifying the | VHOST_USER_ASSERT_LOCK()| macro so that a |VHOST_USER_SET_MEM_TABLE|
request does not trigger an assertion.
However, I believe such modification would not be appropriate, as it would revert the logic introduced in commit |5e8fcc60b59d| ("vhost:
enhance virtqueue access lock asserts"). With this approach, we would be performing memory hotplug without queue locking, which could lead to unintended consequences.
Regarding VDPA device regression. We faced with this issue when we request the number of lcores that the default amount of memory on the socket cannot handle it.
So, regression occurred during the startup part, during device configuration when it creates pkt mbuf pool.

Quoted 1 line

Let me know your thoughts regarding this.

No, my point was to modify VHOST_USER_ASSERT_LOCK() to no trigger an assertion in case vDPA is configured, as we don't want to lock in this case.

Regards,
Maxime

Quoted 89 lines

------------------------------------------------------------------------
*От:* Maxime Coquelin <[email protected]> *Отправлено:* 3 июня 2025 г. 15:30
*Кому:* Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> *Копия:* [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]> *Тема:* Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug
Hello Danylo,

Quoted 22 lines · Danylo Vodopianov

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

Quoted 5 lines

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

s/using/use/

It needs a fixes tag, and [email protected] should be cc'ed, so that it gets backported to LTS branches.

Quoted 12 lines
---
  lib/vhost/vhost_user.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
        * would cause a dead lock.

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3187

Quoted 10 lines
lib/vhost/vhost_user.c +7 -1
        */
       if (msg_handler != NULL && msg_handler->lock_all_qps) {
-             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+             /* Lock all queue pairs if the device is not configured for vDPA,
+              * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+              * This ensures proper queue locking for memory table updates and guest
+              * memory hotplug.
+              */
+             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+                     request == VHOST_USER_SET_MEM_TABLE) {

It looks like a workaround, and I'm afraid it could cause regression with some vDPA devices, or that it would not be enough and we would have to add other requests as exception.

Wouldn't it better to modify VHOST_USER_ASSERT_LOCK() so that it takes into account the VIRTIO_DEV_VDPA_CONFIGURED flag?

Thanks,
Maxime

Quoted 3 lines
lib/vhost/vhost_user.c +0 -0
                       vhost_user_lock_all_queue_pairs(dev);
                       unlock_required = 1;
               }
#11 lore raw

Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug

Hi,

Quoted 81 lines · Danylo Vodopianov

Hi, Maxime

I understand your point. However we coould have a situation like this, could resize twice:

    VHOST_CONFIG: (/usr/local/var/run/stdvio4) read message
    VHOST_USER_SET_MEM_TABLE
    VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest memory region size:
    0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  guest physical addr:
    0x140000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  guest virtual  addr:
    0x140000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  host  virtual  addr:
    0x7fde00000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap addr : 0x7fde00000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap size : 0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap align: 0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap off  : 0x0
    VHOST_CONFIG: (/usr/local/var/run/stdvio4) guest memory region size:
    0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  guest physical addr:
    0x11c0000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  guest virtual  addr:
    0x11c0000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  host  virtual  addr:
    0x7fddc0000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap addr : 0x7fddc0000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap size : 0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap align: 0x40000000
    VHOST_CONFIG: (/usr/local/var/run/stdvio4)  mmap off  : 0x0

When we set memory region twice. After first iteration VIRTIO_DEV_VDPA_CONFIGURED flag will be unset here: https://github.com/ DPDK/dpdk/blob/main/lib/vhost/vhost_user.c#L1425 <https://github.com/ DPDK/dpdk/blob/main/lib/vhost/vhost_user.c#L1425> On the second iteration, this leads to an rte_panic, as queues are accessed without a lock.

So we should check vhost message id ( VHOST_USER_SET_MEM_TABLE ).

However, extend VHOST_USER_ASSERT_LOCK macros with additional check if we work with this message VHOST_USER_SET_MEM_TABLE not handle this case, therefore translate_ring_addresses function calls q_assert_lock directly, without macros wrapper. In this function is check access_lock vhost_virtqueue and this case should be handle.

To address the described issue, we need to make the following changes:

1. *Extend VHOST_USER_ASSERT_LOCK macro*:
* Add a check for the VHOST_USER_SET_MEM_TABLE message ID.
* Skip rte_panic if the message ID matches VHOST_USER_SET_MEM_TABLE.
2. *Modify translate_ring_addresses function*:
* Extend its signature to include the id parameter (message ID).
* Add logic to skip vq_assert_lock if the message ID matches VHOST_USER_SET_MEM_TABLE.

1.

    Extend *VHOST_USER_ASSERT_LOCK* Macro:


    #define VHOST_USER_ASSERT_LOCK(dev, vq, id) \
         do { \
             if ((id) == VHOST_USER_SET_MEM_TABLE) \
                 break; \
             if (!(vq)->access_ok) \
                 rte_panic("Virtqueue access lock not held\n"); \
         } while (0

2.

    Modify *translate_ring_addresses* Function:


    static int
    translate_ring_addresses(struct virtio_net *dev,
    struct vhost_virtqueue *vq, uint32_t id)
    {
         if (id != VHOST_USER_SET_MEM_TABLE)
             vq_assert_lock(dev, vq);

         // Existing logic for translating ring addresses...
         // ...existing code...
         return 0;
    }
Quoted 3 lines

This approach requires extending more functions with conditional checks to handle cases where queue locking should be ignored when the memory table is impacted.

Do you have any thoughts about this? Or I should rework my patchset according to this described solution above ?

And if instead of relying on the VIRTIO_DEV_VDPA_CONFIGURED flag as I suggested, we rely on the vdpa_dev being set?

Quoted 109 lines

------------------------------------------------------------------------
*От:* Maxime Coquelin <[email protected]>
*Отправлено:* 12 июня 2025 г. 14:38
*Кому:* Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> *Копия:* [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]>
*Тема:* Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug
Hi Danylo,

Quoted 9 lines · Danylo Vodopianov

Hello, Maxime

Thank you for your review.
If I understand correctly, you propose modifying the | VHOST_USER_ASSERT_LOCK()| macro so that a |VHOST_USER_SET_MEM_TABLE|    request does not trigger an assertion.
However, I believe such modification would not be appropriate, as it would revert the logic introduced in commit |5e8fcc60b59d| ("vhost: enhance virtqueue access lock asserts"). With this approach, we would be performing memory hotplug without queue locking, which could lead to unintended consequences. Regarding VDPA device regression. We faced with this issue when we request the number of lcores that the default amount of memory on the socket cannot handle it.
So, regression occurred during the startup part, during device configuration when it creates pkt mbuf pool.

Let me know your thoughts regarding this.

No, my point was to modify VHOST_USER_ASSERT_LOCK() to no trigger an assertion in case vDPA is configured, as we don't want to lock in this case.

Regards,
Maxime

Quoted 80 lines

------------------------------------------------------------------------
*От:* Maxime Coquelin <[email protected]>
*Отправлено:* 3 июня 2025 г. 15:30
*Кому:* Danylo Vodopianov <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Christian Koue Muf <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Mykola Kostenok <[email protected]>; Serhii Iliushyk <[email protected]> *Копия:* [email protected] <[email protected]>; [email protected] <[email protected]>; Chenbo Xia <[email protected]>
*Тема:* Re: [PATCH v4 1/1] vhost: handle virtqueue locking for memory hotplug
Hello Danylo,

Quoted 22 lines · Danylo Vodopianov

For vDPA devices, virtqueues are not locked once the device has been configured. In the
commit 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts"), the asserts were enhanced to trigger rte_panic functionality, preventing access to virtqueues without locking. However, this change introduced an issue where the memory hotplug mechanism, added in the commit 127f9c6f7b78 ("vhost: handle memory hotplug with vDPA devices"), no longer works. Since it expects for all queues are locked.

During the initialization of a vDPA device, the driver sets the VIRTIO_DEV_VDPA_CONFIGURED flag, which prevents the vhost_user_lock_all_queue_pairs function from locking the virtqueues. This leads to the error: the VIRTIO_DEV_VDPA_CONFIGURED flag allows the use of the hotplug mechanism, but it fails because the virtqueues are not locked, while it expects to be locked for VHOST_USER_SET_MEM_TABLE in the table VHOST_MESSAGE_HANDLERS.

This patch addresses the issue by enhancing the conditional statement to include a new condition. Specifically, when the device receives the VHOST_USER_SET_MEM_TABLE request, the virtqueues are locked to update the basic configurations and hotplug the guest memory.

Quoted 5 lines

This fix does not impact access lock when vDPA driver is configured for other unnecessary message handlers.

Manual memory configuring with "--socket-mem" option allows to avoid hotplug mechanism using.

s/using/use/

It needs a fixes tag, and [email protected] should be cc'ed, so that it gets backported to LTS branches.

Quoted 12 lines

---
   lib/vhost/vhost_user.c | 8 +++++++-

   1 file changed, 7 insertions(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index ec950acf97..16d03e1033 100644
@@ -3178,7 +3178,13 @@ vhost_user_msg_handler(int vid, int fd)
          * would cause a dead lock.

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3187

Quoted 10 lines
lib/vhost/vhost_user.c +7 -1
          */
         if (msg_handler != NULL && msg_handler->lock_all_qps) {
-             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
+             /* Lock all queue pairs if the device is not configured for vDPA,
+              * or if it is configured for vDPA but the request is VHOST_USER_SET_MEM_TABLE.
+              * This ensures proper queue locking for memory table updates and guest
+              * memory hotplug.
+              */
+             if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) ||
+                     request == VHOST_USER_SET_MEM_TABLE) {

It looks like a workaround, and I'm afraid it could cause regression with some vDPA devices, or that it would not be enough and we would have to add other requests as exception.

Wouldn't it better to modify VHOST_USER_ASSERT_LOCK() so that it takes into account the VIRTIO_DEV_VDPA_CONFIGURED flag?

Thanks,
Maxime

Quoted 3 lines
lib/vhost/vhost_user.c +0 -0
                         vhost_user_lock_all_queue_pairs(dev);
                         unlock_required = 1;
                 }
#12 lore raw

PATCH 1/1 vhost: always lock all qp if handlers request it

The check for VIRTIO_DEV_VDPA_CONFIGURED flag is not neede since each handler has its own lock_all_qps flag to indicate whether it needs all queue pairs.

Checking the VIRTIO_DEV_VDPA_CONFIGURED flag caused certain handlers (for example SET_MEM_TABLE for memory hot plug) to run without holding the per-vq access_lock and trigger vq_assert_lock failures.

---
 lib/vhost/vhost_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/vhost/vhost_user.c +2 -4
index 4bfb13fb98..9288da9322 100644
@@ -3171,10 +3171,8 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
-			vhost_user_lock_all_queue_pairs(dev);
-			unlock_required = 1;
-		}
+		vhost_user_lock_all_queue_pairs(dev);
+		unlock_required = 1;
 	}
 
 	handled = false;
Signature · 1 line
2.47.3
#13 lore raw

PATCH v2 1/1 vhost: always lock all QPs if handlers request it

The check for the VIRTIO_DEV_VDPA_CONFIGURED flag is not needed since each handler has its own lock_all_qps flag
to indicate whether it needs all queue pairs.

Checking the VIRTIO_DEV_VDPA_CONFIGURED flag caused certain handlers (for example, SET_MEM_TABLE for memory hot plug) to run without holding the per-vq access_lock and trigger vq_assert_lock failures.

---
v2
* fix typo in commit message

---
 lib/vhost/vhost_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/vhost/vhost_user.c +2 -4
index 4bfb13fb98..9288da9322 100644
@@ -3171,10 +3171,8 @@ vhost_user_msg_handler(int vid, int fd)
 	 * would cause a dead lock.
 	 */
 	if (msg_handler != NULL && msg_handler->lock_all_qps) {
-		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
-			vhost_user_lock_all_queue_pairs(dev);
-			unlock_required = 1;
-		}
+		vhost_user_lock_all_queue_pairs(dev);
+		unlock_required = 1;
 	}
 
 	handled = false;
Signature · 1 line
2.47.3
#14 lore raw

Re: [PATCH v2] vhost: always lock all QPs if handlers request it

Hi Serghii,

Quoted 4 lines · Serhii Iliushyk

The check for the VIRTIO_DEV_VDPA_CONFIGURED flag is not needed since each handler has its own lock_all_qps flag
to indicate whether it needs all queue pairs.

Hmm, I think this is needed because lock_all_qps is only effective with the SW datapath.
With vDPA, once the device is configured, we would end-up with virtqueues modifications
without the HW being stopped or even notified.

Quoted 3 lines

Checking the VIRTIO_DEV_VDPA_CONFIGURED flag caused certain handlers (for example, SET_MEM_TABLE for memory hot plug) to run without holding the per-vq access_lock and trigger vq_assert_lock failures.

In this specific memory hotplug case, we do the right thing in the handler:

    if (dev->mem) {
        if (dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) {
            struct rte_vdpa_device *vdpa_dev = dev->vdpa_dev;

            if (vdpa_dev && vdpa_dev->ops->dev_close)
                vdpa_dev->ops->dev_close(dev->vid);
            dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED;
        }

Maybe we should also lock all the queue pairs once the vDPA is closed. The problem is to handle the unlock properly.

Maxime

Quoted 28 lines

---
v2
* fix typo in commit message

---
 lib/vhost/vhost_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/vhost/vhost_user.c +2 -5
index 4bfb13fb98..9288da9322 100644
@@ -3171,10 +3171,8 @@ vhost_user_msg_handler(int vid, int fd)
         * would cause a dead lock.
         */
        if (msg_handler != NULL && msg_handler->lock_all_qps) {
-               if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
-                       vhost_user_lock_all_queue_pairs(dev);
-                       unlock_required = 1;
-               }
+               vhost_user_lock_all_queue_pairs(dev);
+               unlock_required = 1;
        }
 
        handled = false;
--

2.47.3

#15 lore raw

Re: [PATCH v2] vhost: always lock all QPs if handlers request it

Quoted 30 lines · Maxime Coquelin

Hi Serghii,

Quoted 4 lines · Serhii Iliushyk

The check for the VIRTIO_DEV_VDPA_CONFIGURED flag is not needed since each handler has its own lock_all_qps flag
to indicate whether it needs all queue pairs.

Hmm, I think this is needed because lock_all_qps is only effective with the SW datapath.
With vDPA, once the device is configured, we would end-up with virtqueues modifications
without the HW being stopped or even notified.

Quoted 3 lines

Checking the VIRTIO_DEV_VDPA_CONFIGURED flag caused certain handlers (for example, SET_MEM_TABLE for memory hot plug) to run without holding the per-vq access_lock and trigger vq_assert_lock failures.

In this specific memory hotplug case, we do the right thing in the handler:

    if (dev->mem) {
        if (dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) {
            struct rte_vdpa_device *vdpa_dev = dev->vdpa_dev;

            if (vdpa_dev && vdpa_dev->ops->dev_close)
                vdpa_dev->ops->dev_close(dev->vid);
            dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED;
        }
Quoted 2 lines

Maybe we should also lock all the queue pairs once the vDPA is closed. The problem is to handle the unlock properly.

Maybe a generic solution would be in vhost_user_msg_handler() to close the vDPA device,
clear CONFIGURED flag and lock all queue pairs as we do in vhost_user_set_mem_table?

I have no hardware to test, could you have a try if you think it makes sense?

Thanks,
Maxime

Quoted 30 lines

Maxime

Quoted 28 lines

---
v2
* fix typo in commit message

---
 lib/vhost/vhost_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/vhost/vhost_user.c +2 -5
index 4bfb13fb98..9288da9322 100644
@@ -3171,10 +3171,8 @@ vhost_user_msg_handler(int vid, int fd)
         * would cause a dead lock.
         */
        if (msg_handler != NULL && msg_handler->lock_all_qps) {
-               if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
-                       vhost_user_lock_all_queue_pairs(dev);
-                       unlock_required = 1;
-               }
+               vhost_user_lock_all_queue_pairs(dev);
+               unlock_required = 1;
        }
 
        handled = false;
--

2.47.3