Skip to contentSkip to conversation

virtio-net: correctly enable callback during start_xmit

PATCH Superseded Jason Wang 2 participants 8 messages Dec 15, 2022 – Jan 4, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v2 1/1 virtio-net: correctly enable callback during start_xmit

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
	} while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 86e52454b5b5..dcf3a536d78a 100644
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
-		if (!use_napi &&
+		if ((!use_napi || !kick) &&
 		    unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
 			/* More just got used, free them then recheck. */
 			free_old_xmit_skbs(sq, false);
Signature · 6 lines
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
	} while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
 	 */
 	if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
 		netif_stop_subqueue(dev, qnum);
-		if (!use_napi &&
+		if ((!use_napi || !kick) &&
 		    unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
 			/* More just got used, free them then recheck. */
 			free_old_xmit_skbs(sq, false);

This will work but the following lines are:

                       if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                netif_start_subqueue(dev, qnum);
                                virtqueue_disable_cb(sq->vq);
                        }

and I thought we are supposed to keep callbacks enabled with napi? One of the ideas of napi is to free on napi callback, not here immediately.

I think it is easier to just do a separate branch here. Along the lines of:

		if (use_napi) {
			if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
				virtqueue_napi_schedule(napi, vq);
		} else {
			... old code ...
		}

also reduces chances of regressions on !napi (which is not well tested) and keeps callbacks off while we free skbs.

No?

Quoted 2 lines
Signature · 1 line
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#2 lore raw
Quoted 44 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
      } while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
       */
      if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
              netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                  unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                      /* More just got used, free them then recheck. */
                      free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                       if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                netif_start_subqueue(dev, qnum);
                                virtqueue_disable_cb(sq->vq);
                        }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

My undersatnding is that it tries to disable callbacks on TX.

Quoted 9 lines

One of the ideas of napi is to free on napi callback, not here immediately.

I think it is easier to just do a separate branch here. Along the lines of:

                if (use_napi) {
                        if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
                                virtqueue_napi_schedule(napi, vq);

This seems to be a new logic and it causes some delay in processing TX (unnecessary NAPI).

Quoted 6 lines
                } else {
                        ... old code ...
                }

also reduces chances of regressions on !napi (which is not well tested) and keeps callbacks off while we free skbs.

I think my patch doesn't change the logic of !napi? (It checks !napi || kick).

Thanks

Quoted 7 lines

No?

Quoted 2 lines

--
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw
Quoted 58 lines · Jason Wang
Quoted 44 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
      } while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
       */
      if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
              netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                  unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                      /* More just got used, free them then recheck. */
                      free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                       if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                netif_start_subqueue(dev, qnum);
                                virtqueue_disable_cb(sq->vq);
                        }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

Quoted 8 lines

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

My undersatnding is that it tries to disable callbacks on TX.

I think we want to disable callbacks while polling, yes. here we are not polling, and I think we want a callback because otherwise nothing will orphan skbs and a socket can be blocked, not transmitting anything - a deadlock.

Quoted 6 lines
Quoted 6 lines

One of the ideas of napi is to free on napi callback, not here immediately.

I think it is easier to just do a separate branch here. Along the lines of:

Quoted 6 lines
Quoted 3 lines
                if (use_napi) {
                        if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
                                virtqueue_napi_schedule(napi, vq);

This seems to be a new logic and it causes some delay in processing TX (unnecessary NAPI).

That's good, we overloaded the queue so we are already going too fast, deferring tx so queue has chance to drain will allow better batching in the qdisc.

Quoted 10 lines
Quoted 6 lines
                } else {
                        ... old code ...
                }

also reduces chances of regressions on !napi (which is not well tested) and keeps callbacks off while we free skbs.

I think my patch doesn't change the logic of !napi? (It checks !napi || kick).

Thanks

I agree it doesn't seem to as written.

Quoted 7 lines
Quoted 7 lines

No?

Quoted 2 lines

--
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#4 lore raw
Quoted 67 lines · Michael S. Tsirkin
Quoted 65 lines · Jason Wang
Quoted 44 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
      } while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
       */
      if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
              netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                  unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                      /* More just got used, free them then recheck. */
                      free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                       if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                netif_start_subqueue(dev, qnum);
                                virtqueue_disable_cb(sq->vq);
                        }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

Quoted 6 lines
Quoted 1 line

My undersatnding is that it tries to disable callbacks on TX.

I think we want to disable callbacks while polling, yes. here we are not polling, and I think we want a callback because otherwise nothing will orphan skbs and a socket can be blocked, not transmitting anything - a deadlock.

I'm not sure how I got here, did you mean a partial revert of a7766ef18b33 (the part that disables TX callbacks on start_xmit)?

Btw, I plan to remove non NAPI mode completely, since it was disabled by default for years and we don't see any complaint, then we may have modern features like BQL and better TCP performance. In that sense we may simply keep tx callback open as most of modern NIC did.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

One of the ideas of napi is to free on napi callback, not here immediately.

I think it is easier to just do a separate branch here. Along the lines of:

                if (use_napi) {
                        if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
                                virtqueue_napi_schedule(napi, vq);
Quoted 6 lines
Quoted 2 lines

This seems to be a new logic and it causes some delay in processing TX (unnecessary NAPI).

That's good, we overloaded the queue so we are already going too fast, deferring tx so queue has chance to drain will allow better batching in the qdisc.

I meant, compare to

1) schedule NAPI and poll TX

The current code did

2) poll TX immediately

2) seems faster?

Thanks

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
                } else {
                        ... old code ...
                }
Quoted 17 lines
Quoted 6 lines
Quoted 2 lines

also reduces chances of regressions on !napi (which is not well tested) and keeps callbacks off while we free skbs.

I think my patch doesn't change the logic of !napi? (It checks !napi || kick).

Thanks

I agree it doesn't seem to as written.

Quoted 7 lines
Quoted 7 lines

No?

Quoted 2 lines

--
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#5 lore raw
Quoted 71 lines · Jason Wang
Quoted 69 lines · Michael S. Tsirkin
Quoted 66 lines · Jason Wang
Quoted 44 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

        do {
           ......
      } while (use_napi && kick &&
               unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
       */
      if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
              netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                  unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                      /* More just got used, free them then recheck. */
                      free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                       if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                netif_start_subqueue(dev, qnum);
                                virtqueue_disable_cb(sq->vq);
                        }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

My undersatnding is that it tries to disable callbacks on TX.

Quoted 7 lines
Quoted 4 lines

I think we want to disable callbacks while polling, yes. here we are not polling, and I think we want a callback because otherwise nothing will orphan skbs and a socket can be blocked, not transmitting anything - a deadlock.

I'm not sure how I got here, did you mean a partial revert of a7766ef18b33 (the part that disables TX callbacks on start_xmit)?

Michael, any idea on this?

Thanks

Quoted 28 lines

Btw, I plan to remove non NAPI mode completely, since it was disabled by default for years and we don't see any complaint, then we may have modern features like BQL and better TCP performance. In that sense we may simply keep tx callback open as most of modern NIC did.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

One of the ideas of napi is to free on napi callback, not here immediately.

I think it is easier to just do a separate branch here. Along the lines of:

                if (use_napi) {
                        if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
                                virtqueue_napi_schedule(napi, vq);
Quoted 6 lines
Quoted 2 lines

This seems to be a new logic and it causes some delay in processing TX (unnecessary NAPI).

That's good, we overloaded the queue so we are already going too fast, deferring tx so queue has chance to drain will allow better batching in the qdisc.

I meant, compare to

1) schedule NAPI and poll TX

Quoted 30 lines

The current code did

2) poll TX immediately

2) seems faster?

Thanks

Quoted 22 lines
Quoted 11 lines
Quoted 7 lines
                } else {
                        ... old code ...
                }

also reduces chances of regressions on !napi (which is not well tested) and keeps callbacks off while we free skbs.

I think my patch doesn't change the logic of !napi? (It checks !napi || kick).

Thanks

I agree it doesn't seem to as written.

Quoted 7 lines
Quoted 7 lines

No?

Quoted 2 lines

--
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#6 lore raw
Quoted 70 lines · Jason Wang
Quoted 69 lines · Jason Wang
Quoted 68 lines · Michael S. Tsirkin
Quoted 55 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

         do {
            ......
       } while (use_napi && kick &&
                unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
  drivers/net/virtio_net.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
        */
       if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
               netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                   unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                       /* More just got used, free them then recheck. */
                       free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                        if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                 netif_start_subqueue(dev, qnum);
                                 virtqueue_disable_cb(sq->vq);
                         }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

Quoted 8 lines

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

My undersatnding is that it tries to disable callbacks on TX.

I think we want to disable callbacks while polling, yes. here we are not polling, and I think we want a callback because otherwise nothing will orphan skbs and a socket can be blocked, not transmitting anything - a deadlock.

Quoted 5 lines
Quoted 2 lines

I'm not sure how I got here, did you mean a partial revert of a7766ef18b33 (the part that disables TX callbacks on start_xmit)?

Michael, any idea on this?

Thanks

Michael, any comment?

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#7 lore raw
Quoted 74 lines · Jason Wang
Quoted 72 lines · Jason Wang
Quoted 71 lines · Jason Wang
Quoted 63 lines · Michael S. Tsirkin
Quoted 62 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 31 lines · Jason Wang

Commit a7766ef18b33("virtio_net: disable cb aggressively") enables virtqueue callback via the following statement:

         do {
            ......
       } while (use_napi && kick &&
                unlikely(!virtqueue_enable_cb_delayed(sq->vq)));

When NAPI is used and kick is false, the callback won't be enabled here. And when the virtqueue is about to be full, the tx will be disabled, but we still don't enable tx interrupt which will cause a TX hang. This could be observed when using pktgen with burst enabled.

Fixing this by trying to enable tx interrupt after we disable TX when we're not using napi or kick is false.

Fixes a7766ef18b33 ("virtio_net: disable cb aggressively")

---
The patch is needed for -stable.
Changes since V1:
- enable tx interrupt after we disable tx

---
  drivers/net/virtio_net.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 86e52454b5b5..dcf3a536d78a 100644

drivers/net/virtio_net.c static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) · line 1879

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -1873,7 +1873,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
        */
       if (sq->vq->num_free < 2+MAX_SKB_FRAGS) {
               netif_stop_subqueue(dev, qnum);
-             if (!use_napi &&
+             if ((!use_napi || !kick) &&
                   unlikely(!virtqueue_enable_cb_delayed(sq->vq))) {
                       /* More just got used, free them then recheck. */
                       free_old_xmit_skbs(sq, false);

This will work but the following lines are:

Quoted 7 lines
                        if (sq->vq->num_free >= 2+MAX_SKB_FRAGS) {
                                 netif_start_subqueue(dev, qnum);
                                 virtqueue_disable_cb(sq->vq);
                         }

and I thought we are supposed to keep callbacks enabled with napi?

This seems to be the opposite logic of commit a7766ef18b33 that disables callbacks for NAPI.

It said:

There are currently two cases where we poll TX vq not in response to a
callback: start xmit and rx napi. We currently do this with callbacks enabled which can cause extra interrupts from the card. Used not to be a big issue as we run with interrupts disabled but that is no longer the case, and in some cases the rate of spurious interrupts is so high linux detects this and actually kills the interrupt.

Quoted 5 lines
Quoted 1 line

My undersatnding is that it tries to disable callbacks on TX.

I think we want to disable callbacks while polling, yes. here we are not polling, and I think we want a callback because otherwise nothing will orphan skbs and a socket can be blocked, not transmitting anything - a deadlock.

I'm not sure how I got here, did you mean a partial revert of a7766ef18b33 (the part that disables TX callbacks on start_xmit)?

Quoted 8 lines
Quoted 3 lines

Michael, any idea on this?

Thanks

Michael, any comment?

Thanks

Sorry I don't understand the question. What does "how I got here" mean? To repeat my suggestion:

	I think it is easier to just do a separate branch here. Along the
	lines of:

			if (use_napi) {
				if (unlikely(!virtqueue_enable_cb_delayed(sq->vq)))
					virtqueue_napi_schedule(napi, vq);
			} else {
				... old code ...
			}

we can also backport this minimal safe fix, any refactorings can be done on top.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization