Skip to contentSkip to conversation

net: 64bit support for SO_MAX_PACING_RATE

PATCH In review Eric Dumazet 2 participants 4 messages Feb 28, 2019 – Mar 2, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: 64bit support for SO_MAX_PACING_RATE

64bit kernels adopted 64bit type for sk_max_pacing_rate in linux-4.20

We can change how we implement SO_MAX_PACING_RATE socket option to support 64bit values to/from user space as well.

Eric Dumazet (2):
net: support 64bit values for setsockopt(SO_MAX_PACING_RATE)
net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE)

 net/core/sock.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.21.0.352.gf09ad66450-goog
#1 lore raw

PATCH 1/2 net: support 64bit values for setsockopt(SO_MAX_PACING_RATE)

64bit kernels now support 64bit pacing rates.

This commit changes setsockopt() to accept 64bit
values provided by applications.

Old applications providing 32bit value are still supported, but limited to the old 34Gbit limitation.

---
 net/core/sock.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
net/core/sock.c +13 -5
index f5d82f3fa474deb204257972d4f1492de4c161d4..23aa02ffd6b811a294e232af0bd25f84d3c848cc 100644
@@ -1108,15 +1108,23 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
 #endif
 
 	case SO_MAX_PACING_RATE:
-		if (val != ~0U)
+		{
+		unsigned long ulval = (val == ~0U) ? ~0UL : val;
+
+		if (sizeof(ulval) != sizeof(val) &&
+		    optlen >= sizeof(ulval) &&
+		    get_user(ulval, (unsigned long __user *)optval)) {
+			ret = -EFAULT;
+			break;
+		}
+		if (ulval != ~0UL)
 			cmpxchg(&sk->sk_pacing_status,
 				SK_PACING_NONE,
 				SK_PACING_NEEDED);
-		sk->sk_max_pacing_rate = (val == ~0U) ? ~0UL : val;
-		sk->sk_pacing_rate = min(sk->sk_pacing_rate,
-					 sk->sk_max_pacing_rate);
+		sk->sk_max_pacing_rate = ulval;
+		sk->sk_pacing_rate = min(sk->sk_pacing_rate, ulval);
 		break;
-
+		}
 	case SO_INCOMING_CPU:
 		sk->sk_incoming_cpu = val;
 		break;
Signature · 1 line
2.21.0.352.gf09ad66450-goog
#2 lore raw

PATCH 2/2 net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE)

In reply to Eric Dumazet

For legacy applications using 32bit variable, SO_MAX_PACING_RATE has to cap the returned value to 0xFFFFFFFF, meaning that rates above 34.35 Gbit are capped.

This patch allows applications to read socket pacing rate at full resolution, if they provide a 64bit variable to store it, and the kernel is 64bit.

---
 net/core/sock.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
net/core/sock.c +8 -2
index 23aa02ffd6b811a294e232af0bd25f84d3c848cc..782343bb925b643348cc906a70b97caa0388178d 100644
@@ -1219,6 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 	union {
 		int val;
 		u64 val64;
+		unsigned long ulval;
 		struct linger ling;
 		struct old_timeval32 tm32;
 		struct __kernel_old_timeval tm;
@@ -1464,8 +1465,13 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 #endif
 
 	case SO_MAX_PACING_RATE:
-		/* 32bit version */
-		v.val = min_t(unsigned long, sk->sk_max_pacing_rate, ~0U);
+		if (sizeof(v.ulval) != sizeof(v.val) && len >= sizeof(v.ulval)) {
+			lv = sizeof(v.ulval);
+			v.ulval = sk->sk_max_pacing_rate;
+		} else {
+			/* 32bit version */
+			v.val = min_t(unsigned long, sk->sk_max_pacing_rate, ~0U);
+		}
 		break;
 
 	case SO_INCOMING_CPU:
Signature · 1 line
2.21.0.352.gf09ad66450-goog
maintainer
#3 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Thu, 28 Feb 2019 15:17:26 -0800

Quoted 4 lines

64bit kernels adopted 64bit type for sk_max_pacing_rate in linux-4.20

We can change how we implement SO_MAX_PACING_RATE socket option to support 64bit values to/from user space as well.

Series applied, thanks Eric.