Bug 238478 - TCP Cubic code bug in cubic_ack_received
Summary: TCP Cubic code bug in cubic_ack_received
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Richard Scheffenegger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-10 22:21 UTC by Vidhi Goel
Modified: 2020-09-01 00:44 UTC (History)
3 users (show)

See Also:
koobs: mfc-stable12+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vidhi Goel 2019-06-10 22:21:09 UTC
I am not sure if this is the right way to file a code audit issue. Recently I was referring to TCP Cubic source code and found one problem in function  cubic_ack_received.
1. The first condition checks whether the computed cubic window is less than TCP friendly window and sets accordingly
2. Else, it checks whether the current cwnd is less than the computed cubic window. This is the concave region but the freebsd code considers this as concave or convex.
This is incorrect as it would fail to set cwnd when (cwnd > w_cubic_next)

According to the draft, cwnd should be set to (W_cubic_next - cwnd)/cwnd in both concave and convex region. So the code should look like this:


if (w_cubic_next < w_tf) {
    set cwnd <- w_tf
} else if (cwnd < w_cubic_next) {
// This is concave region
    set cwnd <- (W_cubic_next - cwnd)/cwnd
} else {
// This is convex region
    set cwnd <- (W_cubic_next - cwnd)/cwnd
}


Or

if (w_cubic_next < w_tf) {
    set cwnd <- w_tf
} else {
    set cwnd <- (W_cubic_next - cwnd)/cwnd
}
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2019-06-10 23:51:09 UTC
Yes, this is the correct way to file a code audit issue.  Thanks.
Comment 2 Richard Scheffenegger freebsd_committer freebsd_triage 2020-05-01 20:56:18 UTC
Since having fixed numerous cubic related bugs, looking further into this.
Comment 3 Richard Scheffenegger freebsd_committer freebsd_triage 2020-05-24 18:18:22 UTC
Currently working to validate the fix in D24657
Comment 4 Richard Scheffenegger freebsd_committer freebsd_triage 2020-07-21 16:14:07 UTC
Actually, concave and convex regions are defined with respect to the previous cwnd (max_cwnd in the code), not the currently used cwnd.

The conditional in that space is there to prevent cwnd from shrinking, should
it have outgrown the currently calculated w_cubic_next value (e.g. during slow-start).

So, after a close inspection, showing the cwnd to follow both convex and concave trajectories properly, I believe the current code is correct. As there are some style issues, and the comment could be expanded around this, will commit a patch against this PR nevertheless.
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-07-21 16:22:47 UTC
A commit references this bug:

Author: rscheff
Date: Tue Jul 21 16:21:53 UTC 2020
New revision: 363397
URL: https://svnweb.freebsd.org/changeset/base/363397

Log:
  Fix style and comment around concave/convex regions in TCP cubic.

  In cubic, the concave region is when snd_cwnd starts growing slower
  towards max_cwnd (cwnd at the time of the congestion event), and
  the convex region is when snd_cwnd starts to grow faster and
  eventually appearing like slow-start like growth.

  PR:		238478
  Reviewed by:	tuexen (mentor), rgrimes (mentor)
  Approved by:	tuexen (mentor), rgrimes (mentor)
  MFC after:	2 weeks
  Sponsored by:	NetApp, Inc.
  Differential Revision:	https://reviews.freebsd.org/D24657

Changes:
  head/sys/netinet/cc/cc_cubic.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2020-08-19 10:40:46 UTC
A commit references this bug:

Author: rscheff
Date: Wed Aug 19 10:40:03 UTC 2020
New revision: 364378
URL: https://svnweb.freebsd.org/changeset/base/364378

Log:
  MFC r363397: Fix style and comment around concave/convex regions in TCP cubic.

  In cubic, the concave region is when snd_cwnd starts growing slower
  towards max_cwnd (cwnd at the time of the congestion event), and
  the convex region is when snd_cwnd starts to grow faster and
  eventually appearing like slow-start like growth.

  PR:		238478
  Reviewed by:	tuexen (mentor), rgrimes (mentor)
  Sponsored by:	NetApp, Inc.
  Differential Revision:	https://reviews.freebsd.org/D24657

Changes:
_U  stable/12/
  stable/12/sys/netinet/cc/cc_cubic.c