All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE
@ 2019-02-28 23:17 Eric Dumazet
  2019-02-28 23:17 ` [PATCH net-next 1/2] net: support 64bit values for setsockopt(SO_MAX_PACING_RATE) Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-02-28 23:17 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

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(-)

-- 
2.21.0.352.gf09ad66450-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] net: support 64bit values for setsockopt(SO_MAX_PACING_RATE)
  2019-02-28 23:17 [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE Eric Dumazet
@ 2019-02-28 23:17 ` Eric Dumazet
  2019-02-28 23:17 ` [PATCH net-next 2/2] net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE) Eric Dumazet
  2019-03-02  7:08 ` [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-02-28 23:17 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

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.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/sock.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index f5d82f3fa474deb204257972d4f1492de4c161d4..23aa02ffd6b811a294e232af0bd25f84d3c848cc 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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;
-- 
2.21.0.352.gf09ad66450-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE)
  2019-02-28 23:17 [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE Eric Dumazet
  2019-02-28 23:17 ` [PATCH net-next 1/2] net: support 64bit values for setsockopt(SO_MAX_PACING_RATE) Eric Dumazet
@ 2019-02-28 23:17 ` Eric Dumazet
  2019-03-02  7:08 ` [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-02-28 23:17 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, 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.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/sock.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 23aa02ffd6b811a294e232af0bd25f84d3c848cc..782343bb925b643348cc906a70b97caa0388178d 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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:
-- 
2.21.0.352.gf09ad66450-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE
  2019-02-28 23:17 [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE Eric Dumazet
  2019-02-28 23:17 ` [PATCH net-next 1/2] net: support 64bit values for setsockopt(SO_MAX_PACING_RATE) Eric Dumazet
  2019-02-28 23:17 ` [PATCH net-next 2/2] net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE) Eric Dumazet
@ 2019-03-02  7:08 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-03-02  7:08 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet

From: Eric Dumazet <edumazet@google.com>
Date: Thu, 28 Feb 2019 15:17:26 -0800

> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-02  7:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-28 23:17 [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE Eric Dumazet
2019-02-28 23:17 ` [PATCH net-next 1/2] net: support 64bit values for setsockopt(SO_MAX_PACING_RATE) Eric Dumazet
2019-02-28 23:17 ` [PATCH net-next 2/2] net: support 64bit rates for getsockopt(SO_MAX_PACING_RATE) Eric Dumazet
2019-03-02  7:08 ` [PATCH net-next 0/2] net: 64bit support for SO_MAX_PACING_RATE David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.