Skip to contentSkip to conversation

virtio-net: fix possible dim status unrecoverable

PATCH In review Heng Qi 2 participants 3 messages Mar 26, 2024 – Mar 29, 2024

Subsystems (4)
lore
Share & tools
lore

Heng Qi

author
#0 lore raw

PATCH v2 1/1 virtio-net: fix possible dim status unrecoverable

When the dim worker is scheduled, if it fails to acquire the lock, dim may not be able to return to the working state later.

For example, the following single queue scenario:
1. The dim worker of rxq0 is scheduled, and the dim status is

     changed to DIM_APPLY_NEW_PROFILE;
  2. The ethtool command is holding rtnl lock;
  3. Since the rtnl lock is already held, virtnet_rx_dim_work fails
     to acquire the lock and exits;

Then, even if net_dim is invoked again, it cannot work because the state is not restored to DIM_START_MEASURE.

Patch has been tested on a VM with 16 NICs, 128 queues per NIC (2kq total):
With dim enabled on all queues, there are many opportunities for contention for RTNL lock, and this patch introduces no visible hotspots. The dim performance is also stable.

Fixes 6208799553a8 ("virtio-net: support rx netdim")

---
v1->v2:
- Update commit log. No functional changes.

 drivers/net/virtio_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +3 -1
index c22d111..0ebe322 100644
@@ -3563,8 +3563,10 @@ static void virtnet_rx_dim_work(struct work_struct *work)
 	struct dim_cq_moder update_moder;
 	int i, qnum, err;
 
-	if (!rtnl_trylock())
+	if (!rtnl_trylock()) {
+		schedule_work(&dim->work);
 		return;
+	}
 
 	/* Each rxq's work is queued by "net_dim()->schedule_work()"
 	 * in response to NAPI traffic changes. Note that dim->profile_ix
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 34 lines · Heng Qi

When the dim worker is scheduled, if it fails to acquire the lock, dim may not be able to return to the working state later.

For example, the following single queue scenario:
1. The dim worker of rxq0 is scheduled, and the dim status is

     changed to DIM_APPLY_NEW_PROFILE;
  2. The ethtool command is holding rtnl lock;
  3. Since the rtnl lock is already held, virtnet_rx_dim_work fails
     to acquire the lock and exits;

Then, even if net_dim is invoked again, it cannot work because the state is not restored to DIM_START_MEASURE.

Patch has been tested on a VM with 16 NICs, 128 queues per NIC (2kq total):
With dim enabled on all queues, there are many opportunities for contention for RTNL lock, and this patch introduces no visible hotspots. The dim performance is also stable.

Fixes 6208799553a8 ("virtio-net: support rx netdim")

---
v1->v2:
- Update commit log. No functional changes.

 drivers/net/virtio_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index c22d111..0ebe322 100644

drivers/net/virtio_net.c static void virtnet_rx_dim_work(struct work_struct *work) · line 3568

Quoted 7 lines
drivers/net/virtio_net.c +2 -1
@@ -3563,8 +3563,10 @@ static void virtnet_rx_dim_work(struct work_struct *work)
 	struct dim_cq_moder update_moder;
 	int i, qnum, err;
 
-	if (!rtnl_trylock())
+	if (!rtnl_trylock()) {
+		schedule_work(&dim->work);
 		return;

I'm really scared by this change. VMs are (increasingly) used to run containers orchestration, which in turns puts a lot of pressure on the RTNL lock. Any rtnl_trylock+ reschedule may hang for a very long time. Addressing this kind of issues later becomes _extremely_ painful, see:

https://lore.kernel.org/netdev/[email protected]/

I really think a different solution is needed. What about moving virtnet_send_command() under protection of a new mutex?

I understand it will complicate future hardening works around cvq, but really rtnl_trylock()/<spin/retry> is bad for the whole system.

Cheers,

Paolo

author
#2 lore raw
Quoted 47 lines · Paolo Abeni
Quoted 34 lines · Heng Qi

When the dim worker is scheduled, if it fails to acquire the lock, dim may not be able to return to the working state later.

For example, the following single queue scenario:
1. The dim worker of rxq0 is scheduled, and the dim status is

      changed to DIM_APPLY_NEW_PROFILE;
   2. The ethtool command is holding rtnl lock;
   3. Since the rtnl lock is already held, virtnet_rx_dim_work fails
      to acquire the lock and exits;

Then, even if net_dim is invoked again, it cannot work because the state is not restored to DIM_START_MEASURE.

Patch has been tested on a VM with 16 NICs, 128 queues per NIC (2kq total):
With dim enabled on all queues, there are many opportunities for contention for RTNL lock, and this patch introduces no visible hotspots. The dim performance is also stable.

Fixes 6208799553a8 ("virtio-net: support rx netdim")

---
v1->v2:
- Update commit log. No functional changes.

  drivers/net/virtio_net.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index c22d111..0ebe322 100644

drivers/net/virtio_net.c static void virtnet_rx_dim_work(struct work_struct *work) · line 3568

Quoted 7 lines
drivers/net/virtio_net.c +2 -1
@@ -3563,8 +3563,10 @@ static void virtnet_rx_dim_work(struct work_struct *work)
  	struct dim_cq_moder update_moder;
  	int i, qnum, err;
 
-	if (!rtnl_trylock())
+	if (!rtnl_trylock()) {
+		schedule_work(&dim->work);
  		return;

I'm really scared by this change. VMs are (increasingly) used to run containers orchestration, which in turns puts a lot of pressure on the RTNL lock. Any rtnl_trylock+ reschedule may hang for a very long time. Addressing this kind of issues later becomes _extremely_ painful, see:

Quoted 4 lines

https://lore.kernel.org/netdev/[email protected]/

I really think a different solution is needed. What about moving virtnet_send_command() under protection of a new mutex?

Daniel did additional work:

https://lore.kernel.org/all/[email protected]/

Use spin lock to protect ctrlq access, therefore, rtnl lock can be removed in rx_dim_work, which will make the problem non-existent.

Thanks,
Heng

Quoted 7 lines

I understand it will complicate future hardening works around cvq, but really rtnl_trylock()/<spin/retry> is bad for the whole system.

Cheers,

Paolo