Blame SOURCES/0007-Fix-definitions-of-SOCKET_MAX-TCP_MAX_CONNS.patch

f07426
From 44d35498a98da3d3234b0084033f6dcd6450e22b Mon Sep 17 00:00:00 2001
f07426
From: Stefano Brivio <sbrivio@redhat.com>
f07426
Date: Mon, 27 Feb 2023 03:30:01 +0100
f07426
Subject: [PATCH 07/20] Fix definitions of SOCKET_MAX, TCP_MAX_CONNS
f07426
f07426
...and, given that I keep getting this wrong, add a convenience
f07426
macro, MAX_FROM_BITS().
f07426
f07426
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
f07426
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
f07426
(cherry picked from commit 26a0e4d6ee17fa174a401d8e8d9a4c189f11f258)
f07426
---
f07426
 passt.h    | 4 ++--
f07426
 tcp.h      | 4 ++--
f07426
 tcp_conn.h | 2 +-
f07426
 util.h     | 2 ++
f07426
 4 files changed, 7 insertions(+), 5 deletions(-)
f07426
f07426
diff --git a/passt.h b/passt.h
f07426
index 3d7e567..e0383eb 100644
f07426
--- a/passt.h
f07426
+++ b/passt.h
f07426
@@ -42,7 +42,7 @@ union epoll_ref;
f07426
 /**
f07426
  * union epoll_ref - Breakdown of reference for epoll socket bookkeeping
f07426
  * @proto:	IP protocol number
f07426
- * @s:		Socket number (implies 2^24 limit on number of descriptors)
f07426
+ * @s:		Socket number (implies 2^24-1 limit on number of descriptors)
f07426
  * @tcp:	TCP-specific reference part
f07426
  * @udp:	UDP-specific reference part
f07426
  * @icmp:	ICMP-specific reference part
f07426
@@ -53,7 +53,7 @@ union epoll_ref {
f07426
 	struct {
f07426
 		int32_t		proto:8,
f07426
 #define SOCKET_REF_BITS		24
f07426
-#define SOCKET_MAX		(1 << SOCKET_REF_BITS)
f07426
+#define SOCKET_MAX		MAX_FROM_BITS(SOCKET_REF_BITS)
f07426
 				s:SOCKET_REF_BITS;
f07426
 		union {
f07426
 			union tcp_epoll_ref tcp;
f07426
diff --git a/tcp.h b/tcp.h
f07426
index 5527c5b..36e5391 100644
f07426
--- a/tcp.h
f07426
+++ b/tcp.h
f07426
@@ -8,8 +8,8 @@
f07426
 
f07426
 #define TCP_TIMER_INTERVAL		1000	/* ms */
f07426
 
f07426
-#define TCP_CONN_INDEX_BITS		17	/* 128k */
f07426
-#define TCP_MAX_CONNS			(1 << TCP_CONN_INDEX_BITS)
f07426
+#define TCP_CONN_INDEX_BITS		17	/* 128k - 1 */
f07426
+#define TCP_MAX_CONNS			MAX_FROM_BITS(TCP_CONN_INDEX_BITS)
f07426
 
f07426
 struct ctx;
f07426
 
f07426
diff --git a/tcp_conn.h b/tcp_conn.h
f07426
index a499f34..c22632b 100644
f07426
--- a/tcp_conn.h
f07426
+++ b/tcp_conn.h
f07426
@@ -54,7 +54,7 @@ struct tcp_tap_conn {
f07426
 
f07426
 #define TCP_RETRANS_BITS		3
f07426
 	unsigned int	retrans		:TCP_RETRANS_BITS;
f07426
-#define TCP_MAX_RETRANS			((1U << TCP_RETRANS_BITS) - 1)
f07426
+#define TCP_MAX_RETRANS			MAX_FROM_BITS(TCP_RETRANS_BITS)
f07426
 
f07426
 #define TCP_WS_BITS			4	/* RFC 7323 */
f07426
 #define TCP_WS_MAX			14
f07426
diff --git a/util.h b/util.h
f07426
index 6303c17..570094c 100644
f07426
--- a/util.h
f07426
+++ b/util.h
f07426
@@ -40,6 +40,8 @@
f07426
 #define ROUND_DOWN(x, y)	((x) & ~((y) - 1))
f07426
 #define ROUND_UP(x, y)		(((x) + (y) - 1) & ~((y) - 1))
f07426
 
f07426
+#define MAX_FROM_BITS(n)	((int)((1U << (n)) - 1))
f07426
+
f07426
 #define BIT(n)			(1UL << (n))
f07426
 #define BITMAP_BIT(n)		(BIT((n) % (sizeof(long) * 8)))
f07426
 #define BITMAP_WORD(n)		(n / (sizeof(long) * 8))
f07426
-- 
f07426
2.39.2
f07426