0008-vhost-fix-skb-leak-in-handle_rx.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From 8ddb7f99e8c2ad80dbe3f9de01e8af5c310ae52d Mon Sep 17 00:00:00 2001
  2. From: Wei Xu <[email protected]>
  3. Date: Fri, 1 Dec 2017 05:10:36 -0500
  4. Subject: [PATCH 008/242] vhost: fix skb leak in handle_rx()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Matthew found a roughly 40% tcp throughput regression with commit
  9. c67df11f(vhost_net: try batch dequing from skb array) as discussed
  10. in the following thread:
  11. https://www.mail-archive.com/[email protected]/msg187936.html
  12. Eventually we figured out that it was a skb leak in handle_rx()
  13. when sending packets to the VM. This usually happens when a guest
  14. can not drain out vq as fast as vhost fills in, afterwards it sets
  15. off the traffic jam and leaks skb(s) which occurs as no headcount
  16. to send on the vq from vhost side.
  17. This can be avoided by making sure we have got enough headcount
  18. before actually consuming a skb from the batched rx array while
  19. transmitting, which is simply done by moving checking the zero
  20. headcount a bit ahead.
  21. Signed-off-by: Wei Xu <[email protected]>
  22. Reported-by: Matthew Rosato <[email protected]>
  23. Signed-off-by: Fabian Grünbichler <[email protected]>
  24. ---
  25. drivers/vhost/net.c | 20 ++++++++++----------
  26. 1 file changed, 10 insertions(+), 10 deletions(-)
  27. diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
  28. index 1c75572f5a3f..010253847022 100644
  29. --- a/drivers/vhost/net.c
  30. +++ b/drivers/vhost/net.c
  31. @@ -781,16 +781,6 @@ static void handle_rx(struct vhost_net *net)
  32. /* On error, stop handling until the next kick. */
  33. if (unlikely(headcount < 0))
  34. goto out;
  35. - if (nvq->rx_array)
  36. - msg.msg_control = vhost_net_buf_consume(&nvq->rxq);
  37. - /* On overrun, truncate and discard */
  38. - if (unlikely(headcount > UIO_MAXIOV)) {
  39. - iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1);
  40. - err = sock->ops->recvmsg(sock, &msg,
  41. - 1, MSG_DONTWAIT | MSG_TRUNC);
  42. - pr_debug("Discarded rx packet: len %zd\n", sock_len);
  43. - continue;
  44. - }
  45. /* OK, now we need to know about added descriptors. */
  46. if (!headcount) {
  47. if (unlikely(vhost_enable_notify(&net->dev, vq))) {
  48. @@ -803,6 +793,16 @@ static void handle_rx(struct vhost_net *net)
  49. * they refilled. */
  50. goto out;
  51. }
  52. + if (nvq->rx_array)
  53. + msg.msg_control = vhost_net_buf_consume(&nvq->rxq);
  54. + /* On overrun, truncate and discard */
  55. + if (unlikely(headcount > UIO_MAXIOV)) {
  56. + iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1);
  57. + err = sock->ops->recvmsg(sock, &msg,
  58. + 1, MSG_DONTWAIT | MSG_TRUNC);
  59. + pr_debug("Discarded rx packet: len %zd\n", sock_len);
  60. + continue;
  61. + }
  62. /* We don't need to be notified again. */
  63. iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len);
  64. fixup = msg.msg_iter;
  65. --
  66. 2.14.2