Skip to contentSkip to conversation

rds: Fix semantic annotations

PATCH Applied Ujwal Kundur 3 participants 10 messages Aug 20, 2025 – Aug 22, 2025

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

v2 cover rds: Fix semantic annotations

This patchset addresses all semantic warnings flagged by Sparse for net/rds.

v1:
- https://lore.kernel.org/all/[email protected]/

Ujwal Kundur (4):
rds: Replace POLLERR with EPOLLERR
rds: Fix endianness annotation of jhash wrappers
rds: Fix endianness annotation for RDS_MPATH_HASH
rds: Fix endianness annotations for RDS extension headers

 net/rds/af_rds.c     | 2 +-
 net/rds/connection.c | 9 +++++----
 net/rds/message.c    | 4 ++--
 net/rds/rds.h        | 2 +-
 net/rds/recv.c       | 4 ++--
 net/rds/send.c       | 4 ++--
 6 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/4 rds: Replace POLLERR with EPOLLERR

Both constants are 1<<3, but EPOLLERR uses the correct annotations.

Flagged by Sparse.

---
 net/rds/af_rds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/af_rds.c +1 -1
index 086a13170e09..4a7217fbeab6 100644
@@ -242,7 +242,7 @@ static __poll_t rds_poll(struct file *file, struct socket *sock,
 	if (rs->rs_snd_bytes < rds_sk_sndbuf(rs))
 		mask |= (EPOLLOUT | EPOLLWRNORM);
 	if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
-		mask |= POLLERR;
+		mask |= EPOLLERR;
 	read_unlock_irqrestore(&rs->rs_recv_lock, flags);
 
 	/* clear state any time we wake a seen-congested socket */
Signature · 1 line
2.30.2
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH net-next v2 1/4] rds: Replace POLLERR with EPOLLERR

Quoted 14 lines · Ujwal Kundur

Both constants are 1<<3, but EPOLLERR uses the correct annotations.

Flagged by Sparse.

---
 net/rds/af_rds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/af_rds.c +0 -0
index 086a13170e09..4a7217fbeab6 100644

net/rds/af_rds.c static __poll_t rds_poll(struct file *file, struct socket *sock, · line 248

Quoted 8 lines
net/rds/af_rds.c +1 -1
@@ -242,7 +242,7 @@ static __poll_t rds_poll(struct file *file, struct socket *sock,
 	if (rs->rs_snd_bytes < rds_sk_sndbuf(rs))
 		mask |= (EPOLLOUT | EPOLLWRNORM);
 	if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
-		mask |= POLLERR;
+		mask |= EPOLLERR;
 	read_unlock_irqrestore(&rs->rs_recv_lock, flags);
 
 	/* clear state any time we wake a seen-congested socket */

This looks better. Thank you for the clean up!

#3 lore raw

PATCH v2 2/4 rds: Fix endianness annotation of jhash wrappers

In reply to Ujwal Kundur

__ipv6_addr_jhash (wrapper around jhash2()) and __inet_ehashfn (wrapper around jhash_3words()) work with u32 (host endian) values but accept big endian inputs. Declare the local variables as big endian to avoid unnecessary casts.

Flagged by Sparse.

---
 net/rds/connection.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
net/rds/connection.c +5 -4
index d62f486ab29f..ba6fb87647ac 100644
@@ -57,16 +57,17 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
 	static u32 rds6_hash_secret __read_mostly;
 	static u32 rds_hash_secret __read_mostly;
 
-	u32 lhash, fhash, hash;
+	u32 hash;
+	__be32 lhash, fhash;
 
 	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
 	net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));
 
-	lhash = (__force u32)laddr->s6_addr32[3];
+	lhash = laddr->s6_addr32[3];
 #if IS_ENABLED(CONFIG_IPV6)
-	fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
+	fhash = (__force __be32)__ipv6_addr_jhash(faddr, rds6_hash_secret);
 #else
-	fhash = (__force u32)faddr->s6_addr32[3];
+	fhash = faddr->s6_addr32[3];
 #endif
 	hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
 
Signature · 1 line
2.30.2
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH net-next v2 2/4] rds: Fix endianness annotation of jhash wrappers

Quoted 8 lines · Ujwal Kundur

__ipv6_addr_jhash (wrapper around jhash2()) and __inet_ehashfn (wrapper around jhash_3words()) work with u32 (host endian) values but accept big endian inputs. Declare the local variables as big endian to avoid unnecessary casts.

Flagged by Sparse.

This looks ok now. Thank you!

Quoted 30 lines
---
 net/rds/connection.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
net/rds/connection.c +5 -4
index d62f486ab29f..ba6fb87647ac 100644
@@ -57,16 +57,17 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
 	static u32 rds6_hash_secret __read_mostly;
 	static u32 rds_hash_secret __read_mostly;
 
-	u32 lhash, fhash, hash;
+	u32 hash;
+	__be32 lhash, fhash;
 
 	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
 	net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));
 
-	lhash = (__force u32)laddr->s6_addr32[3];
+	lhash = laddr->s6_addr32[3];
 #if IS_ENABLED(CONFIG_IPV6)
-	fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
+	fhash = (__force __be32)__ipv6_addr_jhash(faddr, rds6_hash_secret);
 #else
-	fhash = (__force u32)faddr->s6_addr32[3];
+	fhash = faddr->s6_addr32[3];
 #endif
 	hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
 
#5 lore raw

PATCH v2 3/4 rds: Fix endianness annotation for RDS_MPATH_HASH

In reply to Ujwal Kundur

jhash_1word accepts host endian inputs while rs_bound_port is a be16 value (sockaddr_in6.sin6_port). Use ntohs() for consistency.

Flagged by Sparse.

---
 net/rds/rds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/rds.h +1 -1
index dc360252c515..5b1c072e2e7f 100644
@@ -93,7 +93,7 @@ enum {
 
 /* Max number of multipaths per RDS connection. Must be a power of 2 */
 #define	RDS_MPATH_WORKERS	8
-#define	RDS_MPATH_HASH(rs, n) (jhash_1word((rs)->rs_bound_port, \
+#define	RDS_MPATH_HASH(rs, n) (jhash_1word(ntohs((rs)->rs_bound_port), \
 			       (rs)->rs_hash_initval) & ((n) - 1))
 
 #define IS_CANONICAL(laddr, faddr) (htonl(laddr) < htonl(faddr))
Signature · 1 line
2.30.2
Reviewed-by on v2 3/4
#6 lore raw

Re: [PATCH net-next v2 3/4] rds: Fix endianness annotation for RDS_MPATH_HASH

Quoted 6 lines · Ujwal Kundur

jhash_1word accepts host endian inputs while rs_bound_port is a be16 value (sockaddr_in6.sin6_port). Use ntohs() for consistency.

Flagged by Sparse.

This looks fine. Thank you!

Quoted 17 lines
---
 net/rds/rds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/rds.h +1 -1
index dc360252c515..5b1c072e2e7f 100644
@@ -93,7 +93,7 @@ enum {
 
 /* Max number of multipaths per RDS connection. Must be a power of 2 */
 #define	RDS_MPATH_WORKERS	8
-#define	RDS_MPATH_HASH(rs, n) (jhash_1word((rs)->rs_bound_port, \
+#define	RDS_MPATH_HASH(rs, n) (jhash_1word(ntohs((rs)->rs_bound_port), \
 			       (rs)->rs_hash_initval) & ((n) - 1))
 
 #define IS_CANONICAL(laddr, faddr) (htonl(laddr) < htonl(faddr))
#7 lore raw

PATCH v2 4/4 rds: Fix endianness annotations for RDS extension headers

In reply to Ujwal Kundur

Per the RDS 3.1 spec [1], RDS extension headers EXTHDR_NPATHS and EXTHDR_GEN_NUM are be16 and be32 values respectively, exchanged during normal operations over-the-wire (RDS Ping/Pong). This contrasts their declarations as host endian unsigned ints.

Fix the annotations across occurrences. Flagged by Sparse.

[1] https://oss.oracle.com/projects/rds/dist/documentation/rds-3.1-spec.html

---
 net/rds/message.c | 4 ++--
 net/rds/recv.c    | 4 ++--
 net/rds/send.c    | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
net/rds/message.c +2 -2
index 7af59d2443e5..199a899a43e9 100644
@@ -44,8 +44,8 @@ static unsigned int	rds_exthdr_size[__RDS_EXTHDR_MAX] = {
 [RDS_EXTHDR_VERSION]	= sizeof(struct rds_ext_header_version),
 [RDS_EXTHDR_RDMA]	= sizeof(struct rds_ext_header_rdma),
 [RDS_EXTHDR_RDMA_DEST]	= sizeof(struct rds_ext_header_rdma_dest),
-[RDS_EXTHDR_NPATHS]	= sizeof(u16),
-[RDS_EXTHDR_GEN_NUM]	= sizeof(u32),
+[RDS_EXTHDR_NPATHS]	= sizeof(__be16),
+[RDS_EXTHDR_GEN_NUM]	= sizeof(__be32),
 };
 
 void rds_message_addref(struct rds_message *rm)
net/rds/recv.c +2 -2
index 5627f80013f8..66205d6924bf 100644
@@ -202,8 +202,8 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,
 	unsigned int pos = 0, type, len;
 	union {
 		struct rds_ext_header_version version;
-		u16 rds_npaths;
-		u32 rds_gen_num;
+		__be16 rds_npaths;
+		__be32 rds_gen_num;
 	} buffer;
 	u32 new_peer_gen_num = 0;
 
net/rds/send.c +2 -2
index 42d991bc8543..0b3d0ef2f008 100644
@@ -1454,8 +1454,8 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport,
 
 	if (RDS_HS_PROBE(be16_to_cpu(sport), be16_to_cpu(dport)) &&
 	    cp->cp_conn->c_trans->t_mp_capable) {
-		u16 npaths = cpu_to_be16(RDS_MPATH_WORKERS);
-		u32 my_gen_num = cpu_to_be32(cp->cp_conn->c_my_gen_num);
+		__be16 npaths = cpu_to_be16(RDS_MPATH_WORKERS);
+		__be32 my_gen_num = cpu_to_be32(cp->cp_conn->c_my_gen_num);
 
 		rds_message_add_extension(&rm->m_inc.i_hdr,
 					  RDS_EXTHDR_NPATHS, &npaths,
Signature · 1 line
2.30.2
Reviewed-by on v2 4/4
#8 lore raw

Re: [PATCH net-next v2 4/4] rds: Fix endianness annotations for RDS extension headers

Quoted 10 lines · Ujwal Kundur

Per the RDS 3.1 spec [1], RDS extension headers EXTHDR_NPATHS and EXTHDR_GEN_NUM are be16 and be32 values respectively, exchanged during normal operations over-the-wire (RDS Ping/Pong). This contrasts their declarations as host endian unsigned ints.

Fix the annotations across occurrences. Flagged by Sparse.

[1] https://oss.oracle.com/projects/rds/dist/documentation/rds-3.1-spec.html

This looks much better now. Thank you!

Quoted 51 lines
---
 net/rds/message.c | 4 ++--
 net/rds/recv.c    | 4 ++--
 net/rds/send.c    | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
net/rds/message.c +2 -2
index 7af59d2443e5..199a899a43e9 100644
@@ -44,8 +44,8 @@ static unsigned int	rds_exthdr_size[__RDS_EXTHDR_MAX] = {
 [RDS_EXTHDR_VERSION]	= sizeof(struct rds_ext_header_version),
 [RDS_EXTHDR_RDMA]	= sizeof(struct rds_ext_header_rdma),
 [RDS_EXTHDR_RDMA_DEST]	= sizeof(struct rds_ext_header_rdma_dest),
-[RDS_EXTHDR_NPATHS]	= sizeof(u16),
-[RDS_EXTHDR_GEN_NUM]	= sizeof(u32),
+[RDS_EXTHDR_NPATHS]	= sizeof(__be16),
+[RDS_EXTHDR_GEN_NUM]	= sizeof(__be32),
 };
 
 void rds_message_addref(struct rds_message *rm)
net/rds/recv.c +2 -2
index 5627f80013f8..66205d6924bf 100644
@@ -202,8 +202,8 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,
 	unsigned int pos = 0, type, len;
 	union {
 		struct rds_ext_header_version version;
-		u16 rds_npaths;
-		u32 rds_gen_num;
+		__be16 rds_npaths;
+		__be32 rds_gen_num;
 	} buffer;
 	u32 new_peer_gen_num = 0;
 
net/rds/send.c +2 -2
index 42d991bc8543..0b3d0ef2f008 100644
@@ -1454,8 +1454,8 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport,
 
 	if (RDS_HS_PROBE(be16_to_cpu(sport), be16_to_cpu(dport)) &&
 	    cp->cp_conn->c_trans->t_mp_capable) {
-		u16 npaths = cpu_to_be16(RDS_MPATH_WORKERS);
-		u32 my_gen_num = cpu_to_be32(cp->cp_conn->c_my_gen_num);
+		__be16 npaths = cpu_to_be16(RDS_MPATH_WORKERS);
+		__be32 my_gen_num = cpu_to_be32(cp->cp_conn->c_my_gen_num);
 
 		rds_message_add_extension(&rm->m_inc.i_hdr,
 					  RDS_EXTHDR_NPATHS, &npaths,
#9 lore raw
In reply to Ujwal Kundur
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Wed, 20 Aug 2025 23:25:46 +0530 you wrote:

This patchset addresses all semantic warnings flagged by Sparse for net/rds.

v1:
- https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

Ujwal Kundur (4):
rds: Replace POLLERR with EPOLLERR
rds: Fix endianness annotation of jhash wrappers
rds: Fix endianness annotation for RDS_MPATH_HASH
rds: Fix endianness annotations for RDS extension headers

[...]

Here is the summary with links:
- [net-next,v2,1/4] rds: Replace POLLERR with EPOLLERR

    https://git.kernel.org/netdev/net-next/c/9308987803bb
  - [net-next,v2,2/4] rds: Fix endianness annotation of jhash wrappers
    https://git.kernel.org/netdev/net-next/c/92b925297a2f
  - [net-next,v2,3/4] rds: Fix endianness annotation for RDS_MPATH_HASH
    https://git.kernel.org/netdev/net-next/c/77907a068717
  - [net-next,v2,4/4] rds: Fix endianness annotations for RDS extension headers
    https://git.kernel.org/netdev/net-next/c/bcb28bee987a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html