Skip to contentSkip to conversation

Fix sparse warnings for IPVS

PATCH In review Julian Anastasov 3 participants 26 messages Apr 17, 2013 – Apr 23, 2013

Subsystems (4)
lore
Share & tools
lore

Julian Anastasov

author maintainer
#0 lore raw

cover Fix sparse warnings for IPVS

Fix sparse warnings found by kbuild test robot

Julian Anastasov (6):
ipvs: properly dereference dest_dst in ip_vs_forget_dev
ipvs: fix sparse warnings for ip_vs_conn listing
ipvs: fix sparse warnings in lblc and lblcr
ipvs: fix sparse warnings for sync msg size
ipvs: fix sparse warnings for some parameters
ipvs: fix the remaining sparse warnings in ip_vs_ctl.c

 include/net/ip_vs.h              |    8 +++---
 include/uapi/linux/ip_vs.h       |    4 +-
 net/netfilter/ipvs/ip_vs_conn.c  |   14 ++++-----
 net/netfilter/ipvs/ip_vs_core.c  |    3 +-
 net/netfilter/ipvs/ip_vs_ctl.c   |   55 +++++++++++++++++++++++--------------
 net/netfilter/ipvs/ip_vs_lblc.c  |    2 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |    2 +-
 net/netfilter/ipvs/ip_vs_sync.c  |    4 +-
 8 files changed, 52 insertions(+), 40 deletions(-)
Signature · 1 line
1.7.3.4
author maintainer
#1 lore raw

PATCH 1/6 ipvs: properly dereference dest_dst in ip_vs_forget_dev

Use rcu_dereference_protected to resolve
sparse warning, found by kbuild test robot:

net/netfilter/ipvs/ip_vs_ctl.c:1464:35: warning: dereference of noderef expression

Problem from commit 026ace060dfe29
("ipvs: optimize dst usage for real server")

---
 net/netfilter/ipvs/ip_vs_ctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +4 -1
index 9e4074c..5a65444 100644
@@ -1460,8 +1460,11 @@ void ip_vs_service_net_cleanup(struct net *net)
 static inline void
 ip_vs_forget_dev(struct ip_vs_dest *dest, struct net_device *dev)
 {
+	struct ip_vs_dest_dst *dest_dst;
+
 	spin_lock_bh(&dest->dst_lock);
-	if (dest->dest_dst && dest->dest_dst->dst_cache->dev == dev) {
+	dest_dst = rcu_dereference_protected(dest->dest_dst, 1);
+	if (dest_dst && dest_dst->dst_cache->dev == dev) {
 		IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
 			      dev->name,
 			      IP_VS_DBG_ADDR(dest->af, &dest->addr),
Signature · 1 line
1.7.3.4
maintainer
#2 lore raw

Re: [PATCH net-next 1/6] ipvs: properly dereference dest_dst in ip_vs_forget_dev

Quoted 8 lines · Julian Anastasov

Use rcu_dereference_protected to resolve
sparse warning, found by kbuild test robot:

net/netfilter/ipvs/ip_vs_ctl.c:1464:35: warning: dereference of noderef expression

Problem from commit 026ace060dfe29
("ipvs: optimize dst usage for real server")

Thanks, this looks reasonable to me.
I have queued it up in ipvs-next.

BTW, Pablo asked previously for patches not to have leading spaces at the beginning of paragraph's in the changelog. I can will fix this, but it would be helpful to me if you could update your chagelog style.

Thanks

Quoted 26 lines
---
 net/netfilter/ipvs/ip_vs_ctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +4 -1
index 9e4074c..5a65444 100644
@@ -1460,8 +1460,11 @@ void ip_vs_service_net_cleanup(struct net *net)
 static inline void
 ip_vs_forget_dev(struct ip_vs_dest *dest, struct net_device *dev)
 {
+	struct ip_vs_dest_dst *dest_dst;
+
 	spin_lock_bh(&dest->dst_lock);
-	if (dest->dest_dst && dest->dest_dst->dst_cache->dev == dev) {
+	dest_dst = rcu_dereference_protected(dest->dest_dst, 1);
+	if (dest_dst && dest_dst->dst_cache->dev == dev) {
 		IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
 			      dev->name,
 			      IP_VS_DBG_ADDR(dest->af, &dest->addr),
Signature · 1 line
1.7.3.4
author maintainer
#3 lore raw

Re: [PATCH net-next 1/6] ipvs: properly dereference dest_dst in ip_vs_forget_dev

Hello,

Quoted 10 lines · Simon Horman
Quoted 8 lines · Julian Anastasov

Use rcu_dereference_protected to resolve
sparse warning, found by kbuild test robot:

net/netfilter/ipvs/ip_vs_ctl.c:1464:35: warning: dereference of noderef expression

Problem from commit 026ace060dfe29
("ipvs: optimize dst usage for real server")

Quoted 7 lines

Thanks, this looks reasonable to me.
I have queued it up in ipvs-next.

BTW, Pablo asked previously for patches not to have leading spaces at the beginning of paragraph's in the changelog. I can will fix this, but it would be helpful to me if you could update your chagelog style.

I was not aware, no problem to follow the new style :)

Quoted 20 lines

Thanks

Quoted 18 lines
---
 net/netfilter/ipvs/ip_vs_ctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +2 -1
index 9e4074c..5a65444 100644
@@ -1460,8 +1460,11 @@ void ip_vs_service_net_cleanup(struct net *net)
 static inline void
 ip_vs_forget_dev(struct ip_vs_dest *dest, struct net_device *dev)
 {
+	struct ip_vs_dest_dst *dest_dst;
+
 	spin_lock_bh(&dest->dst_lock);
-	if (dest->dest_dst && dest->dest_dst->dst_cache->dev == dev) {
Quoted 9 lines
Quoted 8 lines
net/netfilter/ipvs/ip_vs_ctl.c +2 -0
+	dest_dst = rcu_dereference_protected(dest->dest_dst, 1);
+	if (dest_dst && dest_dst->dst_cache->dev == dev) {
 		IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
 			      dev->name,
 			      IP_VS_DBG_ADDR(dest->af, &dest->addr),
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#4 lore raw

Re: [PATCH net-next 1/6] ipvs: properly dereference dest_dst in ip_vs_forget_dev

Quoted 18 lines · Julian Anastasov

Hello,

Quoted 13 lines · Simon Horman
Quoted 8 lines · Julian Anastasov

Use rcu_dereference_protected to resolve
sparse warning, found by kbuild test robot:

net/netfilter/ipvs/ip_vs_ctl.c:1464:35: warning: dereference of noderef expression

Problem from commit 026ace060dfe29
("ipvs: optimize dst usage for real server")

Thanks, this looks reasonable to me.
I have queued it up in ipvs-next.

Quoted 6 lines
Quoted 4 lines

BTW, Pablo asked previously for patches not to have leading spaces at the beginning of paragraph's in the changelog. I can will fix this, but it would be helpful to me if you could update your chagelog style.

I was not aware, no problem to follow the new style :)

Thanks.

author maintainer
#5 lore raw

PATCH 2/6 ipvs: fix sparse warnings for ip_vs_conn listing

In reply to Julian Anastasov

kbuild test robot reports for sparse warnings
in commit 088339a57d6042 ("ipvs: convert connection locking"):

net/netfilter/ipvs/ip_vs_conn.c:962:13: warning: context imbalance
in 'ip_vs_conn_array' - wrong count at exit
include/linux/rcupdate.h:326:30: warning: context imbalance in
'ip_vs_conn_seq_next' - unexpected unlock
include/linux/rcupdate.h:326:30: warning: context imbalance in
'ip_vs_conn_seq_stop' - unexpected unlock

Fix it by running ip_vs_conn_array under RCU lock
to avoid conditional locking and by adding proper RCU annotations.

---
 net/netfilter/ipvs/ip_vs_conn.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +5 -5
index de64758..a083bda 100644
@@ -966,7 +966,6 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
 	struct ip_vs_iter_state *iter = seq->private;
 
 	for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
-		rcu_read_lock();
 		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
 			/* __ip_vs_conn_get() is not needed by
 			 * ip_vs_conn_seq_show and ip_vs_conn_sync_seq_show
@@ -977,16 +976,19 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
 			}
 		}
 		rcu_read_unlock();
+		rcu_read_lock();
 	}
 
 	return NULL;
 }
 
 static void *ip_vs_conn_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(RCU)
 {
 	struct ip_vs_iter_state *iter = seq->private;
 
 	iter->l = NULL;
+	rcu_read_lock();
 	return *pos ? ip_vs_conn_array(seq, *pos - 1) :SEQ_START_TOKEN;
 }
 
@@ -1006,28 +1008,24 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 	e = rcu_dereference(hlist_next_rcu(&cp->c_list));
 	if (e)
 		return hlist_entry(e, struct ip_vs_conn, c_list);
-	rcu_read_unlock();
 
 	idx = l - ip_vs_conn_tab;
 	while (++idx < ip_vs_conn_tab_size) {
-		rcu_read_lock();
 		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
 			iter->l = &ip_vs_conn_tab[idx];
 			return cp;
 		}
 		rcu_read_unlock();
+		rcu_read_lock();
 	}
 	iter->l = NULL;
 	return NULL;
 }
 
 static void ip_vs_conn_seq_stop(struct seq_file *seq, void *v)
+	__releases(RCU)
 {
-	struct ip_vs_iter_state *iter = seq->private;
-	struct hlist_head *l = iter->l;
maintainer
#6 lore raw

Re: [PATCH net-next 2/6] ipvs: fix sparse warnings for ip_vs_conn listing

Quoted 10 lines · Julian Anastasov

kbuild test robot reports for sparse warnings
in commit 088339a57d6042 ("ipvs: convert connection locking"):

net/netfilter/ipvs/ip_vs_conn.c:962:13: warning: context imbalance
in 'ip_vs_conn_array' - wrong count at exit
include/linux/rcupdate.h:326:30: warning: context imbalance in
'ip_vs_conn_seq_next' - unexpected unlock
include/linux/rcupdate.h:326:30: warning: context imbalance in
'ip_vs_conn_seq_stop' - unexpected unlock

Quoted 3 lines

Fix it by running ip_vs_conn_array under RCU lock
to avoid conditional locking and by adding proper RCU annotations.

Thanks, this seems correct to me.
I have queued it up in ipvs-next.

Quoted 73 lines
---
 net/netfilter/ipvs/ip_vs_conn.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +6 -8
index de64758..a083bda 100644
@@ -966,7 +966,6 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
 	struct ip_vs_iter_state *iter = seq->private;
 
 	for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
-		rcu_read_lock();
 		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
 			/* __ip_vs_conn_get() is not needed by
 			 * ip_vs_conn_seq_show and ip_vs_conn_sync_seq_show
@@ -977,16 +976,19 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
 			}
 		}
 		rcu_read_unlock();
+		rcu_read_lock();
 	}
 
 	return NULL;
 }
 
 static void *ip_vs_conn_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(RCU)
 {
 	struct ip_vs_iter_state *iter = seq->private;
 
 	iter->l = NULL;
+	rcu_read_lock();
 	return *pos ? ip_vs_conn_array(seq, *pos - 1) :SEQ_START_TOKEN;
 }
 
@@ -1006,28 +1008,24 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 	e = rcu_dereference(hlist_next_rcu(&cp->c_list));
 	if (e)
 		return hlist_entry(e, struct ip_vs_conn, c_list);
-	rcu_read_unlock();
 
 	idx = l - ip_vs_conn_tab;
 	while (++idx < ip_vs_conn_tab_size) {
-		rcu_read_lock();
 		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
 			iter->l = &ip_vs_conn_tab[idx];
 			return cp;
 		}
 		rcu_read_unlock();
+		rcu_read_lock();
 	}
 	iter->l = NULL;
 	return NULL;
 }
 
 static void ip_vs_conn_seq_stop(struct seq_file *seq, void *v)
+	__releases(RCU)
 {
-	struct ip_vs_iter_state *iter = seq->private;
-	struct hlist_head *l = iter->l;
-
-	if (l)
-		rcu_read_unlock();
+	rcu_read_unlock();
 }
 
 static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
Signature · 1 line
1.7.3.4
author maintainer
#7 lore raw

PATCH 3/6 ipvs: fix sparse warnings in lblc and lblcr

In reply to Julian Anastasov

kbuild test robot reports for sparse warnings in
commits c2a4ffb70eef39 ("ipvs: convert lblc scheduler to rcu") and c5549571f975ab ("ipvs: convert lblcr scheduler to rcu").

Fix it by removing extra __rcu annotation.

---
 net/netfilter/ipvs/ip_vs_lblc.c  |    2 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +1 -1
index b2cc252..5ea26bd 100644
@@ -104,7 +104,7 @@ struct ip_vs_lblc_entry {
  */
 struct ip_vs_lblc_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
 	struct timer_list       periodic_timer; /* collect stale entries */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
net/netfilter/ipvs/ip_vs_lblcr.c +1 -1
index feb9656..50123c2 100644
@@ -284,7 +284,7 @@ struct ip_vs_lblcr_entry {
  */
 struct ip_vs_lblcr_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
 	struct timer_list       periodic_timer; /* collect stale entries */
Signature · 1 line
1.7.3.4
maintainer
#8 lore raw

Re: [PATCH net-next 3/6] ipvs: fix sparse warnings in lblc and lblcr

Quoted 5 lines · Julian Anastasov

kbuild test robot reports for sparse warnings in
commits c2a4ffb70eef39 ("ipvs: convert lblc scheduler to rcu") and c5549571f975ab ("ipvs: convert lblcr scheduler to rcu").

Fix it by removing extra __rcu annotation.

Hi Julian,

perhaps only for my benefit, but could you explain why the annotations are unnecessary?

Quoted 36 lines
---
 net/netfilter/ipvs/ip_vs_lblc.c  |    2 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +1 -1
index b2cc252..5ea26bd 100644
@@ -104,7 +104,7 @@ struct ip_vs_lblc_entry {
  */
 struct ip_vs_lblc_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
 	struct timer_list       periodic_timer; /* collect stale entries */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
net/netfilter/ipvs/ip_vs_lblcr.c +1 -1
index feb9656..50123c2 100644
@@ -284,7 +284,7 @@ struct ip_vs_lblcr_entry {
  */
 struct ip_vs_lblcr_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
 	struct timer_list       periodic_timer; /* collect stale entries */
Signature · 1 line
1.7.3.4
author maintainer
#9 lore raw

Re: [PATCH net-next 3/6] ipvs: fix sparse warnings in lblc and lblcr

Hello,

Quoted 11 lines · Simon Horman
Quoted 5 lines · Julian Anastasov

kbuild test robot reports for sparse warnings in
commits c2a4ffb70eef39 ("ipvs: convert lblc scheduler to rcu") and c5549571f975ab ("ipvs: convert lblcr scheduler to rcu").

Fix it by removing extra __rcu annotation.

Hi Julian,

perhaps only for my benefit, but could you explain why the annotations are unnecessary?

IMHO, because __rcu should be used only for
pointers, not for struct hlist_head. The *list*_rcu methods enforce __rcu internally for the pointers.

Quoted 26 lines
Quoted 26 lines
---
 net/netfilter/ipvs/ip_vs_lblc.c  |    2 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +1 -1
index b2cc252..5ea26bd 100644
@@ -104,7 +104,7 @@ struct ip_vs_lblc_entry {
  */
 struct ip_vs_lblc_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
 	struct timer_list       periodic_timer; /* collect stale entries */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
net/netfilter/ipvs/ip_vs_lblcr.c +0 -0
index feb9656..50123c2 100644
@@ -284,7 +284,7 @@ struct ip_vs_lblcr_entry {
  */
 struct ip_vs_lblcr_table {
Quoted 8 lines
Quoted 8 lines
net/netfilter/ipvs/ip_vs_lblcr.c +1 -1
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
 	struct timer_list       periodic_timer; /* collect stale entries */
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#10 lore raw

Re: [PATCH net-next 3/6] ipvs: fix sparse warnings in lblc and lblcr

Quoted 12 lines · Julian Anastasov

Hello,

Quoted 7 lines · Simon Horman
Quoted 5 lines · Julian Anastasov

kbuild test robot reports for sparse warnings in
commits c2a4ffb70eef39 ("ipvs: convert lblc scheduler to rcu") and c5549571f975ab ("ipvs: convert lblcr scheduler to rcu").

Fix it by removing extra __rcu annotation.

Quoted 8 lines
Quoted 4 lines

Hi Julian,

perhaps only for my benefit, but could you explain why the annotations are unnecessary?

IMHO, because __rcu should be used only for
pointers, not for struct hlist_head. The *list*_rcu methods enforce __rcu internally for the pointers.

Thanks, I have queued-up the change in ipvs-next.

Quoted 41 lines
Quoted 27 lines
Quoted 27 lines
---
 net/netfilter/ipvs/ip_vs_lblc.c  |    2 +-
 net/netfilter/ipvs/ip_vs_lblcr.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +1 -1
index b2cc252..5ea26bd 100644
@@ -104,7 +104,7 @@ struct ip_vs_lblc_entry {
  */
 struct ip_vs_lblc_table {
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLC_TAB_SIZE];  /* hash bucket */
 	struct timer_list       periodic_timer; /* collect stale entries */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
net/netfilter/ipvs/ip_vs_lblcr.c +0 -0
index feb9656..50123c2 100644
@@ -284,7 +284,7 @@ struct ip_vs_lblcr_entry {
  */
 struct ip_vs_lblcr_table {
Quoted 8 lines
Quoted 8 lines
net/netfilter/ipvs/ip_vs_lblcr.c +1 -1
 	struct rcu_head		rcu_head;
-	struct hlist_head __rcu bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
+	struct hlist_head	bucket[IP_VS_LBLCR_TAB_SIZE];  /* hash bucket */
 	atomic_t                entries;        /* number of entries */
 	int                     max_size;       /* maximum size of entries */
 	struct timer_list       periodic_timer; /* collect stale entries */
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

author maintainer
#11 lore raw

PATCH 4/6 ipvs: fix sparse warnings for sync msg size

In reply to Julian Anastasov

Fix sparse warnings while changing the
size between host and network order:

net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1550:19: warning: incorrect type in
assignment (different base types)
net/netfilter/ipvs/ip_vs_sync.c:1550:19: expected unsigned short
[unsigned] [usertype] size
net/netfilter/ipvs/ip_vs_sync.c:1550:19: got restricted __be16
[usertype] <noident>

---
 net/netfilter/ipvs/ip_vs_sync.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +2 -2
index 8e57077..ff7f2ad 100644
@@ -1176,7 +1176,7 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		return;
 	}
 	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
+	m2->size = ntohs((__force __be16) m2->size);
 
 	if (buflen != m2->size) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
@@ -1547,7 +1547,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	msize = msg->size;
 
 	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msg->size = (__force __u16) htons(msg->size);
 
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)
Signature · 1 line
1.7.3.4
maintainer
#12 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Quoted 14 lines · Julian Anastasov

Fix sparse warnings while changing the
size between host and network order:

net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1550:19: warning: incorrect type in
assignment (different base types)
net/netfilter/ipvs/ip_vs_sync.c:1550:19: expected unsigned short
[unsigned] [usertype] size
net/netfilter/ipvs/ip_vs_sync.c:1550:19: got restricted __be16
[usertype] <noident>

Quoted 1 line

I'm not very excited by the use of __force. Can't we change the type of the size element
of struct ip_vs_sync_mesg and use the sparse annotations to our advantage?

Quoted 29 lines
---
 net/netfilter/ipvs/ip_vs_sync.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +2 -2
index 8e57077..ff7f2ad 100644
@@ -1176,7 +1176,7 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		return;
 	}
 	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
+	m2->size = ntohs((__force __be16) m2->size);
 
 	if (buflen != m2->size) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
@@ -1547,7 +1547,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	msize = msg->size;
 
 	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msg->size = (__force __u16) htons(msg->size);
 
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)
Signature · 1 line
1.7.3.4
author maintainer
#13 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Hello,

Quoted 15 lines · Simon Horman
Quoted 14 lines · Julian Anastasov

Fix sparse warnings while changing the
size between host and network order:

net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1550:19: warning: incorrect type in
assignment (different base types)
net/netfilter/ipvs/ip_vs_sync.c:1550:19: expected unsigned short
[unsigned] [usertype] size
net/netfilter/ipvs/ip_vs_sync.c:1550:19: got restricted __be16
[usertype] <noident>

Quoted 6 lines
Quoted 1 line

I'm not very excited by the use of __force. Can't we change the type of the size element
of struct ip_vs_sync_mesg and use the sparse annotations to our advantage?

AFAIK, __force is the only way to suppress sparse
warning. Not sure what is your idea, may be you can try it.

Quoted 24 lines
Quoted 24 lines
---
 net/netfilter/ipvs/ip_vs_sync.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +2 -2
index 8e57077..ff7f2ad 100644
@@ -1176,7 +1176,7 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		return;
 	}
 	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
+	m2->size = ntohs((__force __be16) m2->size);
 
 	if (buflen != m2->size) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
@@ -1547,7 +1547,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	msize = msg->size;
 
 	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msg->size = (__force __u16) htons(msg->size);
 
Quoted 6 lines
Quoted 5 lines
net/netfilter/ipvs/ip_vs_sync.c +0 -0
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#14 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Quoted 22 lines · Julian Anastasov

Hello,

Quoted 17 lines · Simon Horman
Quoted 15 lines · Julian Anastasov

Fix sparse warnings while changing the
size between host and network order:

net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1179:20: warning: cast to restricted __be16 net/netfilter/ipvs/ip_vs_sync.c:1550:19: warning: incorrect type in
assignment (different base types)
net/netfilter/ipvs/ip_vs_sync.c:1550:19: expected unsigned short
[unsigned] [usertype] size
net/netfilter/ipvs/ip_vs_sync.c:1550:19: got restricted __be16
[usertype] <noident>

Quoted 7 lines
Quoted 4 lines

I'm not very excited by the use of __force. Can't we change the type of the size element
of struct ip_vs_sync_mesg and use the sparse annotations to our advantage?

AFAIK, __force is the only way to suppress sparse
warning. Not sure what is your idea, may be you can try it.

Sure, sorry for not explaining myself more clearly. My idea is as follows:

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg is both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---
 net/netfilter/ipvs/ip_vs_sync.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +4 -7
index 8e57077..c73778a 100644
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;
 	__u8			nr_conns;
 	__s8			version;	/* SYNC_PROTO_VER  */
 	__u16			spare;
@@ -335,7 +335,7 @@ ip_vs_sync_buff_create(struct netns_ipvs *ipvs)
 	sb->mesg->reserved = 0;  /* old nr_conns i.e. must be zero now */
 	sb->mesg->version = SYNC_PROTO_VER;
 	sb->mesg->syncid = ipvs->master_syncid;
-	sb->mesg->size = sizeof(struct ip_vs_sync_mesg);
+	sb->mesg->size = htons(sizeof(struct ip_vs_sync_mesg));
 	sb->mesg->nr_conns = 0;
 	sb->mesg->spare = 0;
 	sb->head = (unsigned char *)sb->mesg + sizeof(struct ip_vs_sync_mesg);
@@ -693,7 +693,7 @@ sloop:
 
 	p = buff->head;
 	buff->head += pad + len;
-	m->size += pad + len;
+	m->size = htons(ntohs(m->size) + pad + len);
 	/* Add ev. padding from prev. sync_conn */
 	while (pad--)
 		*(p++) = 0;
@@ -1175,10 +1175,8 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		IP_VS_DBG(2, "BACKUP, message header too short\n");
 		return;
 	}
-	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
 
-	if (buflen != m2->size) {
+	if (buflen != ntohs(m2->size)) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
 		return;
 	}
@@ -1544,10 +1542,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	int msize;
 	int ret;
 
-	msize = msg->size;
author maintainer
#15 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Hello,

Quoted 29 lines · Simon Horman

My idea is as follows:

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg is both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---
 net/netfilter/ipvs/ip_vs_sync.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +0 -0
index 8e57077..c73778a 100644

net/netfilter/ipvs/ip_vs_sync.c struct ip_vs_sync_mesg_v0 { · line 258

Quoted 5 lines
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

net/netfilter/ipvs/ip_vs_sync.c ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg) · line 1548

Quoted 12 lines
net/netfilter/ipvs/ip_vs_sync.c +1 -4
@@ -1544,10 +1542,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	int msize;
 	int ret;
 
-	msize = msg->size;
-
-	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msize = ntohs(msg->size);
 
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)

Regards

--
Julian Anastasov <[email protected]>

maintainer
#16 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Quoted 29 lines · Julian Anastasov

Hello,

Quoted 24 lines · Simon Horman

My idea is as follows:

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg is both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---
 net/netfilter/ipvs/ip_vs_sync.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
Quoted 13 lines

net/netfilter/ipvs/ip_vs_sync.c struct ip_vs_sync_mesg_v0 { · line 258

Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +1 -1
index 8e57077..c73778a 100644
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

Thanks and sorry for missing that.
How about this?

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---

v2
* As suggested by Julian Anastasov,
update struct ip_vs_sync_mesg_v0 as well as struct ip_vs_sync_mesg.

---
 net/netfilter/ipvs/ip_vs_sync.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +7 -10
index 8e57077..f6046d9 100644
@@ -246,7 +246,7 @@ struct ip_vs_sync_thread_data {
 struct ip_vs_sync_mesg_v0 {
 	__u8                    nr_conns;
 	__u8                    syncid;
-	__u16                   size;
+	__be16                  size;
 
 	/* ip_vs_sync_conn entries start here */
 };
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;
 	__u8			nr_conns;
 	__s8			version;	/* SYNC_PROTO_VER  */
 	__u16			spare;
@@ -335,7 +335,7 @@ ip_vs_sync_buff_create(struct netns_ipvs *ipvs)
 	sb->mesg->reserved = 0;  /* old nr_conns i.e. must be zero now */
 	sb->mesg->version = SYNC_PROTO_VER;
 	sb->mesg->syncid = ipvs->master_syncid;
-	sb->mesg->size = sizeof(struct ip_vs_sync_mesg);
+	sb->mesg->size = htons(sizeof(struct ip_vs_sync_mesg));
 	sb->mesg->nr_conns = 0;
 	sb->mesg->spare = 0;
 	sb->head = (unsigned char *)sb->mesg + sizeof(struct ip_vs_sync_mesg);
@@ -418,7 +418,7 @@ ip_vs_sync_buff_create_v0(struct netns_ipvs *ipvs)
 	mesg = (struct ip_vs_sync_mesg_v0 *)sb->mesg;
 	mesg->nr_conns = 0;
 	mesg->syncid = ipvs->master_syncid;
-	mesg->size = sizeof(struct ip_vs_sync_mesg_v0);
+	mesg->size = htons(sizeof(struct ip_vs_sync_mesg_v0));
 	sb->head = (unsigned char *)mesg + sizeof(struct ip_vs_sync_mesg_v0);
 	sb->end = (unsigned char *)mesg + ipvs->send_mesg_maxlen;
 	sb->firstuse = jiffies;
@@ -582,7 +582,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
 	}
 
 	m->nr_conns++;
-	m->size += len;
+	m->size = htons(ntohs(m->size) + len);
 	buff->head += len;
 
 	/* check if there is a space for next one */
@@ -693,7 +693,7 @@ sloop:
 
 	p = buff->head;
 	buff->head += pad + len;
-	m->size += pad + len;
+	m->size = htons(ntohs(m->size) + pad + len);
 	/* Add ev. padding from prev. sync_conn */
 	while (pad--)
 		*(p++) = 0;
@@ -1175,10 +1175,8 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		IP_VS_DBG(2, "BACKUP, message header too short\n");
 		return;
 	}
-	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
 
-	if (buflen != m2->size) {
+	if (buflen != ntohs(m2->size)) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
 		return;
 	}
@@ -1544,10 +1542,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	int msize;
 	int ret;
 
-	msize = msg->size;
author maintainer Acked-by
#17 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Hello,

Quoted 23 lines · Simon Horman
Quoted 2 lines

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

Thanks and sorry for missing that.
How about this?

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

Quoted 7 lines

---

v2
* As suggested by Julian Anastasov,
update struct ip_vs_sync_mesg_v0 as well as struct ip_vs_sync_mesg.

v2 looks good,

Quoted 88 lines
---
 net/netfilter/ipvs/ip_vs_sync.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +8 -13
index 8e57077..f6046d9 100644
@@ -246,7 +246,7 @@ struct ip_vs_sync_thread_data {
 struct ip_vs_sync_mesg_v0 {
 	__u8                    nr_conns;
 	__u8                    syncid;
-	__u16                   size;
+	__be16                  size;
 
 	/* ip_vs_sync_conn entries start here */
 };
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;
 	__u8			nr_conns;
 	__s8			version;	/* SYNC_PROTO_VER  */
 	__u16			spare;
@@ -335,7 +335,7 @@ ip_vs_sync_buff_create(struct netns_ipvs *ipvs)
 	sb->mesg->reserved = 0;  /* old nr_conns i.e. must be zero now */
 	sb->mesg->version = SYNC_PROTO_VER;
 	sb->mesg->syncid = ipvs->master_syncid;
-	sb->mesg->size = sizeof(struct ip_vs_sync_mesg);
+	sb->mesg->size = htons(sizeof(struct ip_vs_sync_mesg));
 	sb->mesg->nr_conns = 0;
 	sb->mesg->spare = 0;
 	sb->head = (unsigned char *)sb->mesg + sizeof(struct ip_vs_sync_mesg);
@@ -418,7 +418,7 @@ ip_vs_sync_buff_create_v0(struct netns_ipvs *ipvs)
 	mesg = (struct ip_vs_sync_mesg_v0 *)sb->mesg;
 	mesg->nr_conns = 0;
 	mesg->syncid = ipvs->master_syncid;
-	mesg->size = sizeof(struct ip_vs_sync_mesg_v0);
+	mesg->size = htons(sizeof(struct ip_vs_sync_mesg_v0));
 	sb->head = (unsigned char *)mesg + sizeof(struct ip_vs_sync_mesg_v0);
 	sb->end = (unsigned char *)mesg + ipvs->send_mesg_maxlen;
 	sb->firstuse = jiffies;
@@ -582,7 +582,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
 	}
 
 	m->nr_conns++;
-	m->size += len;
+	m->size = htons(ntohs(m->size) + len);
 	buff->head += len;
 
 	/* check if there is a space for next one */
@@ -693,7 +693,7 @@ sloop:
 
 	p = buff->head;
 	buff->head += pad + len;
-	m->size += pad + len;
+	m->size = htons(ntohs(m->size) + pad + len);
 	/* Add ev. padding from prev. sync_conn */
 	while (pad--)
 		*(p++) = 0;
@@ -1175,10 +1175,8 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		IP_VS_DBG(2, "BACKUP, message header too short\n");
 		return;
 	}
-	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
 
-	if (buflen != m2->size) {
+	if (buflen != ntohs(m2->size)) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
 		return;
 	}
@@ -1544,10 +1542,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	int msize;
 	int ret;
 
-	msize = msg->size;
-
-	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msize = ntohs(msg->size);
 
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)
Signature · 1 line
1.8.2.1

Regards

--
Julian Anastasov <[email protected]>

#18 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

In reply to Simon Horman

Hello Simon

Quoted 58 lines · Simon Horman
Quoted 29 lines · Julian Anastasov

Hello,

Quoted 24 lines · Simon Horman

My idea is as follows:

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg is both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---
 net/netfilter/ipvs/ip_vs_sync.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
Quoted 13 lines

net/netfilter/ipvs/ip_vs_sync.c struct ip_vs_sync_mesg_v0 { · line 258

Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +1 -1
index 8e57077..c73778a 100644
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

Thanks and sorry for missing that.
How about this?

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

Quoted 7 lines

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

It looks good

Quoted 91 lines

---

v2
* As suggested by Julian Anastasov,
update struct ip_vs_sync_mesg_v0 as well as struct ip_vs_sync_mesg.

---
 net/netfilter/ipvs/ip_vs_sync.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +8 -13
index 8e57077..f6046d9 100644
@@ -246,7 +246,7 @@ struct ip_vs_sync_thread_data {
 struct ip_vs_sync_mesg_v0 {
 	__u8                    nr_conns;
 	__u8                    syncid;
-	__u16                   size;
+	__be16                  size;
 
 	/* ip_vs_sync_conn entries start here */
 };
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;
 	__u8			nr_conns;
 	__s8			version;	/* SYNC_PROTO_VER  */
 	__u16			spare;
@@ -335,7 +335,7 @@ ip_vs_sync_buff_create(struct netns_ipvs *ipvs)
 	sb->mesg->reserved = 0;  /* old nr_conns i.e. must be zero now */
 	sb->mesg->version = SYNC_PROTO_VER;
 	sb->mesg->syncid = ipvs->master_syncid;
-	sb->mesg->size = sizeof(struct ip_vs_sync_mesg);
+	sb->mesg->size = htons(sizeof(struct ip_vs_sync_mesg));
 	sb->mesg->nr_conns = 0;
 	sb->mesg->spare = 0;
 	sb->head = (unsigned char *)sb->mesg + sizeof(struct ip_vs_sync_mesg);
@@ -418,7 +418,7 @@ ip_vs_sync_buff_create_v0(struct netns_ipvs *ipvs)
 	mesg = (struct ip_vs_sync_mesg_v0 *)sb->mesg;
 	mesg->nr_conns = 0;
 	mesg->syncid = ipvs->master_syncid;
-	mesg->size = sizeof(struct ip_vs_sync_mesg_v0);
+	mesg->size = htons(sizeof(struct ip_vs_sync_mesg_v0));
 	sb->head = (unsigned char *)mesg + sizeof(struct ip_vs_sync_mesg_v0);
 	sb->end = (unsigned char *)mesg + ipvs->send_mesg_maxlen;
 	sb->firstuse = jiffies;
@@ -582,7 +582,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
 	}
 
 	m->nr_conns++;
-	m->size += len;
+	m->size = htons(ntohs(m->size) + len);
 	buff->head += len;
 
 	/* check if there is a space for next one */
@@ -693,7 +693,7 @@ sloop:
 
 	p = buff->head;
 	buff->head += pad + len;
-	m->size += pad + len;
+	m->size = htons(ntohs(m->size) + pad + len);
 	/* Add ev. padding from prev. sync_conn */
 	while (pad--)
 		*(p++) = 0;
@@ -1175,10 +1175,8 @@ static void ip_vs_process_message(struct net *net, __u8 *buffer,
 		IP_VS_DBG(2, "BACKUP, message header too short\n");
 		return;
 	}
-	/* Convert size back to host byte order */
-	m2->size = ntohs(m2->size);
 
-	if (buflen != m2->size) {
+	if (buflen != ntohs(m2->size)) {
 		IP_VS_DBG(2, "BACKUP, bogus message size\n");
 		return;
 	}
@@ -1544,10 +1542,7 @@ ip_vs_send_sync_msg(struct socket *sock, struct ip_vs_sync_mesg *msg)
 	int msize;
 	int ret;
 
-	msize = msg->size;
-
-	/* Put size in network byte order */
-	msg->size = htons(msg->size);
+	msize = ntohs(msg->size);
 
 	ret = ip_vs_send_async(sock, (char *)msg, msize);
 	if (ret >= 0 || ret == -EAGAIN)
maintainer
#19 lore raw

Re: [PATCH net-next 4/6] ipvs: fix sparse warnings for sync msg size

Quoted 39 lines · Julian Anastasov

Hello,

Quoted 23 lines · Simon Horman
Quoted 2 lines

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

Thanks and sorry for missing that.
How about this?

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

Quoted 7 lines

---

v2
* As suggested by Julian Anastasov,
update struct ip_vs_sync_mesg_v0 as well as struct ip_vs_sync_mesg.

v2 looks good,

[snip]

Quoted 67 lines · Hans Schillstrom

Hello Simon

Quoted 64 lines · Simon Horman
Quoted 29 lines · Julian Anastasov

Hello,

Quoted 24 lines · Simon Horman

My idea is as follows:

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg is both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

---
 net/netfilter/ipvs/ip_vs_sync.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
Quoted 13 lines

net/netfilter/ipvs/ip_vs_sync.c struct ip_vs_sync_mesg_v0 { · line 258

Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +1 -1
index 8e57077..c73778a 100644
@@ -255,7 +255,7 @@ struct ip_vs_sync_mesg_v0 {
 struct ip_vs_sync_mesg {
 	__u8			reserved;	/* must be zero */
 	__u8			syncid;
-	__u16			size;
+	__be16			size;

It seems v0 should be changed too,
ip_vs_send_sync_msg() handles both versions in sb->mesg.

Thanks and sorry for missing that.
How about this?

From: Simon Horman <[email protected]>

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field to network byte order before sending a message on the wire and convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field as being network byte order. This seems appropriate as the structure is sent across the wire. And by consistently treating the field has network byte order it is now possible to take advantage of sparse to flag any future miss-use.

Quoted 5 lines
Quoted 1 line

It looks good

[snip]

Thanks, I have added your Acks and queued-up this this change in ipvs-next.

author maintainer
#20 lore raw

PATCH 5/6 ipvs: fix sparse warnings for some parameters

In reply to Julian Anastasov

Some service fields are in network order:

- netmask: used once in network order and also as prefix len for IPv6
- port

Other parameters are in host order:

- struct ip_vs_flags: flags and mask moved between user and kernel only
- sync state: moved between user and kernel only
- syncid: sent over network as single octet

---
 include/net/ip_vs.h             |    8 +++---
 include/uapi/linux/ip_vs.h      |    4 +-
 net/netfilter/ipvs/ip_vs_core.c |    3 +-
 net/netfilter/ipvs/ip_vs_ctl.c  |   40 +++++++++++++++++++++++---------------
 4 files changed, 32 insertions(+), 23 deletions(-)
include/net/ip_vs.h +4 -4
index f9f5b05..4c062cc 100644
@@ -678,7 +678,7 @@ struct ip_vs_service_user_kern {
 	u16			af;
 	u16			protocol;
 	union nf_inet_addr	addr;		/* virtual ip address */
-	u16			port;
+	__be16			port;
 	u32			fwmark;		/* firwall mark of service */
 
 	/* virtual service options */
@@ -686,14 +686,14 @@ struct ip_vs_service_user_kern {
 	char			*pe_name;
 	unsigned int		flags;		/* virtual service flags */
 	unsigned int		timeout;	/* persistent timeout in sec */
-	u32			netmask;	/* persistent netmask */
+	__be32			netmask;	/* persistent netmask or plen */
 };
 
 
 struct ip_vs_dest_user_kern {
 	/* destination server address */
 	union nf_inet_addr	addr;
-	u16			port;
+	__be16			port;
 
 	/* real server options */
 	unsigned int		conn_flags;	/* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
 	__u32                   fwmark;   /* firewall mark of the service */
 	unsigned int		flags;	  /* service status flags */
 	unsigned int		timeout;  /* persistent timeout in ticks */
-	__be32			netmask;  /* grouping granularity */
+	__be32			netmask;  /* grouping granularity, mask/plen */
 	struct net		*net;
 
 	struct list_head	destinations;  /* real server d-linked list */
include/uapi/linux/ip_vs.h +2 -2
index 8a2d438..a245377 100644
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
 #define IPVS_GENL_VERSION	0x1
 
 struct ip_vs_flags {
-	__be32 flags;
-	__be32 mask;
+	__u32 flags;
+	__u32 mask;
 };
 
 /* Generic Netlink command attributes */
net/netfilter/ipvs/ip_vs_core.c +2 -1
index f26fe33..a0d7bd3 100644
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 	/* Mask saddr with the netmask to adjust template granularity */
 #ifdef CONFIG_IP_VS_IPV6
 	if (svc->af == AF_INET6)
-		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask);
+		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
+				 (__force __u32) svc->netmask);
 	else
 #endif
 		snet.ip = iph->saddr.ip & svc->netmask;
net/netfilter/ipvs/ip_vs_ctl.c +24 -16
index 5a65444..68901e4 100644
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out_err;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out_err;
+		}
 	}
 #endif
 
@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 #endif
 
@@ -2890,7 +2898,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	} else {
 		if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
 		    nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
-		    nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port))
+		    nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
 			goto nla_put_failure;
 	}
 
@@ -2900,7 +2908,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
-	    nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
+	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
 		goto nla_put_failure;
 	if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
 		goto nla_put_failure;
@@ -3013,7 +3021,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 	} else {
 		usvc->protocol = nla_get_u16(nla_protocol);
 		nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
-		usvc->port = nla_get_u16(nla_port);
+		usvc->port = nla_get_be16(nla_port);
 		usvc->fwmark = 0;
 	}
 
@@ -3053,7 +3061,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 		usvc->sched_name = nla_data(nla_sched);
 		usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
 		usvc->timeout = nla_get_u32(nla_timeout);
-		usvc->netmask = nla_get_u32(nla_netmask);
+		usvc->netmask = nla_get_be32(nla_netmask);
 	}
 
 	return 0;
@@ -3079,7 +3087,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
 		return -EMSGSIZE;
 
 	if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
-	    nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
+	    nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
 	    nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
 			(atomic_read(&dest->conn_flags) &
 			 IP_VS_CONN_F_FWD_MASK)) ||
@@ -3188,7 +3196,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	memset(udest, 0, sizeof(*udest));
 
 	nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
-	udest->port = nla_get_u16(nla_port);
+	udest->port = nla_get_be16(nla_port);
 
 	/* If a full entry was requested, check for the additional fields */
 	if (full_entry) {
@@ -3213,8 +3221,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	return 0;
 }
 
-static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid)
+static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid)
 {
 	struct nlattr *nl_daemon;
 
@@ -3235,8 +3243,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
-static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid,
+static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid,
 				  struct netlink_callback *cb)
 {
 	void *hdr;
Signature · 1 line
1.7.3.4
maintainer
#21 lore raw

Re: [PATCH net-next 5/6] ipvs: fix sparse warnings for some parameters

Quoted 33 lines · Julian Anastasov

Some service fields are in network order:

- netmask: used once in network order and also as prefix len for IPv6
- port

Other parameters are in host order:

- struct ip_vs_flags: flags and mask moved between user and kernel only
- sync state: moved between user and kernel only
- syncid: sent over network as single octet

---
 include/net/ip_vs.h             |    8 +++---
 include/uapi/linux/ip_vs.h      |    4 +-
 net/netfilter/ipvs/ip_vs_core.c |    3 +-
 net/netfilter/ipvs/ip_vs_ctl.c  |   40 +++++++++++++++++++++++---------------
 4 files changed, 32 insertions(+), 23 deletions(-)
include/net/ip_vs.h +1 -1
index f9f5b05..4c062cc 100644
@@ -678,7 +678,7 @@ struct ip_vs_service_user_kern {
 	u16			af;
 	u16			protocol;
 	union nf_inet_addr	addr;		/* virtual ip address */
-	u16			port;
+	__be16			port;
 	u32			fwmark;		/* firwall mark of service */
 
 	/* virtual service options */

include/net/ip_vs.h struct ip_vs_service_user_kern { · line 689

Quoted 5 lines
include/net/ip_vs.h +1 -1
@@ -686,14 +686,14 @@ struct ip_vs_service_user_kern {
 	char			*pe_name;
 	unsigned int		flags;		/* virtual service flags */
 	unsigned int		timeout;	/* persistent timeout in sec */
-	u32			netmask;	/* persistent netmask */
+	__be32			netmask;	/* persistent netmask or plen */

Its not clear to me that netmask should be __be32 given the occurrences of (__force __u32) below.

Quoted 171 lines
include/net/ip_vs.h +2 -2
 };
 
 
 struct ip_vs_dest_user_kern {
 	/* destination server address */
 	union nf_inet_addr	addr;
-	u16			port;
+	__be16			port;
 
 	/* real server options */
 	unsigned int		conn_flags;	/* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
 	__u32                   fwmark;   /* firewall mark of the service */
 	unsigned int		flags;	  /* service status flags */
 	unsigned int		timeout;  /* persistent timeout in ticks */
-	__be32			netmask;  /* grouping granularity */
+	__be32			netmask;  /* grouping granularity, mask/plen */
 	struct net		*net;
 
 	struct list_head	destinations;  /* real server d-linked list */
include/uapi/linux/ip_vs.h +2 -2
index 8a2d438..a245377 100644
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
 #define IPVS_GENL_VERSION	0x1
 
 struct ip_vs_flags {
-	__be32 flags;
-	__be32 mask;
+	__u32 flags;
+	__u32 mask;
 };
 
 /* Generic Netlink command attributes */
net/netfilter/ipvs/ip_vs_core.c +2 -1
index f26fe33..a0d7bd3 100644
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 	/* Mask saddr with the netmask to adjust template granularity */
 #ifdef CONFIG_IP_VS_IPV6
 	if (svc->af == AF_INET6)
-		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask);
+		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
+				 (__force __u32) svc->netmask);
 	else
 #endif
 		snet.ip = iph->saddr.ip & svc->netmask;
net/netfilter/ipvs/ip_vs_ctl.c +24 -16
index 5a65444..68901e4 100644
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out_err;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out_err;
+		}
 	}
 #endif
 
@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 #endif
 
@@ -2890,7 +2898,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	} else {
 		if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
 		    nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
-		    nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port))
+		    nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
 			goto nla_put_failure;
 	}
 
@@ -2900,7 +2908,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
-	    nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
+	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
 		goto nla_put_failure;
 	if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
 		goto nla_put_failure;
@@ -3013,7 +3021,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 	} else {
 		usvc->protocol = nla_get_u16(nla_protocol);
 		nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
-		usvc->port = nla_get_u16(nla_port);
+		usvc->port = nla_get_be16(nla_port);
 		usvc->fwmark = 0;
 	}
 
@@ -3053,7 +3061,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 		usvc->sched_name = nla_data(nla_sched);
 		usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
 		usvc->timeout = nla_get_u32(nla_timeout);
-		usvc->netmask = nla_get_u32(nla_netmask);
+		usvc->netmask = nla_get_be32(nla_netmask);
 	}
 
 	return 0;
@@ -3079,7 +3087,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
 		return -EMSGSIZE;
 
 	if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
-	    nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
+	    nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
 	    nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
 			(atomic_read(&dest->conn_flags) &
 			 IP_VS_CONN_F_FWD_MASK)) ||
@@ -3188,7 +3196,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	memset(udest, 0, sizeof(*udest));
 
 	nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
-	udest->port = nla_get_u16(nla_port);
+	udest->port = nla_get_be16(nla_port);
 
 	/* If a full entry was requested, check for the additional fields */
 	if (full_entry) {
@@ -3213,8 +3221,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	return 0;
 }
 
-static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid)
+static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid)
 {
 	struct nlattr *nl_daemon;
 
@@ -3235,8 +3243,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
-static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid,
+static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid,
 				  struct netlink_callback *cb)
 {
 	void *hdr;
Signature · 6 lines
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#22 lore raw

Re: [PATCH net-next 5/6] ipvs: fix sparse warnings for some parameters

Hello,

Quoted 32 lines · Simon Horman
Quoted 31 lines · Julian Anastasov

Some service fields are in network order:

- netmask: used once in network order and also as prefix len for IPv6
- port

Other parameters are in host order:

- struct ip_vs_flags: flags and mask moved between user and kernel only
- sync state: moved between user and kernel only
- syncid: sent over network as single octet

---
 include/net/ip_vs.h             |    8 +++---
 include/uapi/linux/ip_vs.h      |    4 +-
 net/netfilter/ipvs/ip_vs_core.c |    3 +-
 net/netfilter/ipvs/ip_vs_ctl.c  |   40 +++++++++++++++++++++++---------------
 4 files changed, 32 insertions(+), 23 deletions(-)
include/net/ip_vs.h +1 -1
index f9f5b05..4c062cc 100644
@@ -678,7 +678,7 @@ struct ip_vs_service_user_kern {
 	u16			af;
 	u16			protocol;
 	union nf_inet_addr	addr;		/* virtual ip address */
-	u16			port;
+	__be16			port;
 	u32			fwmark;		/* firwall mark of service */
 
Quoted 10 lines

include/net/ip_vs.h struct ip_vs_service_user_kern { · line 689

Quoted 7 lines
include/net/ip_vs.h +1 -1
 	/* virtual service options */
@@ -686,14 +686,14 @@ struct ip_vs_service_user_kern {
 	char			*pe_name;
 	unsigned int		flags;		/* virtual service flags */
 	unsigned int		timeout;	/* persistent timeout in sec */
-	u32			netmask;	/* persistent netmask */
+	__be32			netmask;	/* persistent netmask or plen */

Its not clear to me that netmask should be __be32 given the occurrences of (__force __u32) below.

These occurances are only in this diff to
access the prefix len, there are other places that use the big-endian value.

The problem comes with the IPVS-IPv6 support:
in same attribute we provide once IPv4 netmask in big-endian order and second time a prefix length in host order. Even if we add new attribute for prefix length, we still have to support old binaries.

Quoted 156 lines
Quoted 156 lines
include/net/ip_vs.h +2 -2
 };
 
 
 struct ip_vs_dest_user_kern {
 	/* destination server address */
 	union nf_inet_addr	addr;
-	u16			port;
+	__be16			port;
 
 	/* real server options */
 	unsigned int		conn_flags;	/* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
 	__u32                   fwmark;   /* firewall mark of the service */
 	unsigned int		flags;	  /* service status flags */
 	unsigned int		timeout;  /* persistent timeout in ticks */
-	__be32			netmask;  /* grouping granularity */
+	__be32			netmask;  /* grouping granularity, mask/plen */
 	struct net		*net;
 
 	struct list_head	destinations;  /* real server d-linked list */
include/uapi/linux/ip_vs.h +2 -2
index 8a2d438..a245377 100644
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
 #define IPVS_GENL_VERSION	0x1
 
 struct ip_vs_flags {
-	__be32 flags;
-	__be32 mask;
+	__u32 flags;
+	__u32 mask;
 };
 
 /* Generic Netlink command attributes */
net/netfilter/ipvs/ip_vs_core.c +2 -1
index f26fe33..a0d7bd3 100644
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 	/* Mask saddr with the netmask to adjust template granularity */
 #ifdef CONFIG_IP_VS_IPV6
 	if (svc->af == AF_INET6)
-		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask);
+		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
+				 (__force __u32) svc->netmask);
 	else
 #endif
 		snet.ip = iph->saddr.ip & svc->netmask;
net/netfilter/ipvs/ip_vs_ctl.c +22 -14
index 5a65444..68901e4 100644
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out_err;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out_err;
+		}
 	}
 #endif
 
@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 #endif
 
@@ -2890,7 +2898,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	} else {
 		if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
 		    nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
-		    nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port))
+		    nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
 			goto nla_put_failure;
 	}
 
@@ -2900,7 +2908,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
-	    nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
+	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
 		goto nla_put_failure;
 	if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
 		goto nla_put_failure;
@@ -3013,7 +3021,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 	} else {
 		usvc->protocol = nla_get_u16(nla_protocol);
 		nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
-		usvc->port = nla_get_u16(nla_port);
+		usvc->port = nla_get_be16(nla_port);
 		usvc->fwmark = 0;
 	}
 
@@ -3053,7 +3061,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 		usvc->sched_name = nla_data(nla_sched);
 		usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
 		usvc->timeout = nla_get_u32(nla_timeout);
-		usvc->netmask = nla_get_u32(nla_netmask);
+		usvc->netmask = nla_get_be32(nla_netmask);
 	}
 
 	return 0;
@@ -3079,7 +3087,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
 		return -EMSGSIZE;
 
 	if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
-	    nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
+	    nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
 	    nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
 			(atomic_read(&dest->conn_flags) &
 			 IP_VS_CONN_F_FWD_MASK)) ||
@@ -3188,7 +3196,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	memset(udest, 0, sizeof(*udest));
 
 	nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
-	udest->port = nla_get_u16(nla_port);
+	udest->port = nla_get_be16(nla_port);
 
 	/* If a full entry was requested, check for the additional fields */
 	if (full_entry) {
@@ -3213,8 +3221,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	return 0;
 }
 
-static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid)
+static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid)
 {
 	struct nlattr *nl_daemon;
 
@@ -3235,8 +3243,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
Quoted 9 lines
Quoted 9 lines
net/netfilter/ipvs/ip_vs_ctl.c +2 -2
-static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid,
+static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid,
 				  struct netlink_callback *cb)
 {
 	void *hdr;
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#23 lore raw

Re: [PATCH net-next 5/6] ipvs: fix sparse warnings for some parameters

Quoted 52 lines · Julian Anastasov

Hello,

Quoted 32 lines · Simon Horman
Quoted 31 lines · Julian Anastasov

Some service fields are in network order:

- netmask: used once in network order and also as prefix len for IPv6
- port

Other parameters are in host order:

- struct ip_vs_flags: flags and mask moved between user and kernel only
- sync state: moved between user and kernel only
- syncid: sent over network as single octet

---
 include/net/ip_vs.h             |    8 +++---
 include/uapi/linux/ip_vs.h      |    4 +-
 net/netfilter/ipvs/ip_vs_core.c |    3 +-
 net/netfilter/ipvs/ip_vs_ctl.c  |   40 +++++++++++++++++++++++---------------
 4 files changed, 32 insertions(+), 23 deletions(-)
include/net/ip_vs.h +1 -1
index f9f5b05..4c062cc 100644
@@ -678,7 +678,7 @@ struct ip_vs_service_user_kern {
 	u16			af;
 	u16			protocol;
 	union nf_inet_addr	addr;		/* virtual ip address */
-	u16			port;
+	__be16			port;
 	u32			fwmark;		/* firwall mark of service */
 
Quoted 10 lines

include/net/ip_vs.h struct ip_vs_service_user_kern { · line 689

Quoted 7 lines
include/net/ip_vs.h +1 -1
 	/* virtual service options */
@@ -686,14 +686,14 @@ struct ip_vs_service_user_kern {
 	char			*pe_name;
 	unsigned int		flags;		/* virtual service flags */
 	unsigned int		timeout;	/* persistent timeout in sec */
-	u32			netmask;	/* persistent netmask */
+	__be32			netmask;	/* persistent netmask or plen */

Its not clear to me that netmask should be __be32 given the occurrences of (__force __u32) below.

These occurances are only in this diff to
access the prefix len, there are other places that use the big-endian value.

Quoted 5 lines

The problem comes with the IPVS-IPv6 support:
in same attribute we provide once IPv4 netmask in big-endian order and second time a prefix length in host order. Even if we add new attribute for prefix length, we still have to support old binaries.

Thanks, I understand. That is rather unfortunate but as you say we are somewhat stuck.

I have queued-up this patch in ipvs-next.

Quoted 171 lines
Quoted 156 lines
Quoted 156 lines
include/net/ip_vs.h +2 -2
 };
 
 
 struct ip_vs_dest_user_kern {
 	/* destination server address */
 	union nf_inet_addr	addr;
-	u16			port;
+	__be16			port;
 
 	/* real server options */
 	unsigned int		conn_flags;	/* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
 	__u32                   fwmark;   /* firewall mark of the service */
 	unsigned int		flags;	  /* service status flags */
 	unsigned int		timeout;  /* persistent timeout in ticks */
-	__be32			netmask;  /* grouping granularity */
+	__be32			netmask;  /* grouping granularity, mask/plen */
 	struct net		*net;
 
 	struct list_head	destinations;  /* real server d-linked list */
include/uapi/linux/ip_vs.h +2 -2
index 8a2d438..a245377 100644
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
 #define IPVS_GENL_VERSION	0x1
 
 struct ip_vs_flags {
-	__be32 flags;
-	__be32 mask;
+	__u32 flags;
+	__u32 mask;
 };
 
 /* Generic Netlink command attributes */
net/netfilter/ipvs/ip_vs_core.c +2 -1
index f26fe33..a0d7bd3 100644
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
 	/* Mask saddr with the netmask to adjust template granularity */
 #ifdef CONFIG_IP_VS_IPV6
 	if (svc->af == AF_INET6)
-		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask);
+		ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
+				 (__force __u32) svc->netmask);
 	else
 #endif
 		snet.ip = iph->saddr.ip & svc->netmask;
net/netfilter/ipvs/ip_vs_ctl.c +22 -14
index 5a65444..68901e4 100644
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out_err;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out_err;
+		}
 	}
 #endif
 
@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
 	}
 
 #ifdef CONFIG_IP_VS_IPV6
-	if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
-		ret = -EINVAL;
-		goto out;
+	if (u->af == AF_INET6) {
+		__u32 plen = (__force __u32) u->netmask;
+
+		if (plen < 1 || plen > 128) {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 #endif
 
@@ -2890,7 +2898,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	} else {
 		if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
 		    nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
-		    nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port))
+		    nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
 			goto nla_put_failure;
 	}
 
@@ -2900,7 +2908,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
-	    nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
+	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
 		goto nla_put_failure;
 	if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
 		goto nla_put_failure;
@@ -3013,7 +3021,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 	} else {
 		usvc->protocol = nla_get_u16(nla_protocol);
 		nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
-		usvc->port = nla_get_u16(nla_port);
+		usvc->port = nla_get_be16(nla_port);
 		usvc->fwmark = 0;
 	}
 
@@ -3053,7 +3061,7 @@ static int ip_vs_genl_parse_service(struct net *net,
 		usvc->sched_name = nla_data(nla_sched);
 		usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
 		usvc->timeout = nla_get_u32(nla_timeout);
-		usvc->netmask = nla_get_u32(nla_netmask);
+		usvc->netmask = nla_get_be32(nla_netmask);
 	}
 
 	return 0;
@@ -3079,7 +3087,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
 		return -EMSGSIZE;
 
 	if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
-	    nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
+	    nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
 	    nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
 			(atomic_read(&dest->conn_flags) &
 			 IP_VS_CONN_F_FWD_MASK)) ||
@@ -3188,7 +3196,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	memset(udest, 0, sizeof(*udest));
 
 	nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
-	udest->port = nla_get_u16(nla_port);
+	udest->port = nla_get_be16(nla_port);
 
 	/* If a full entry was requested, check for the additional fields */
 	if (full_entry) {
@@ -3213,8 +3221,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
 	return 0;
 }
 
-static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid)
+static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid)
 {
 	struct nlattr *nl_daemon;
 
@@ -3235,8 +3243,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
Quoted 9 lines
Quoted 9 lines
net/netfilter/ipvs/ip_vs_ctl.c +2 -2
-static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state,
-				  const char *mcast_ifn, __be32 syncid,
+static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
+				  const char *mcast_ifn, __u32 syncid,
 				  struct netlink_callback *cb)
 {
 	void *hdr;
Signature · 1 line
1.7.3.4

Regards

--
Julian Anastasov <[email protected]>

author maintainer
#24 lore raw

PATCH 6/6 ipvs: fix the remaining sparse warnings in ip_vs_ctl.c

In reply to Julian Anastasov

- RCU annotations for ip_vs_info_seq_start and _stop
- __percpu for cpustats
- properly dereference svc->pe in ip_vs_genl_fill_service

---
 net/netfilter/ipvs/ip_vs_ctl.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +6 -4
index 68901e4..5b142fb 100644
@@ -1945,8 +1945,8 @@ static struct ip_vs_service *ip_vs_info_array(struct seq_file *seq, loff_t pos)
 }
 
 static void *ip_vs_info_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(RCU)
 {
-
 	rcu_read_lock();
 	return *pos ? ip_vs_info_array(seq, *pos - 1) : SEQ_START_TOKEN;
 }
@@ -2001,6 +2001,7 @@ static void *ip_vs_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void ip_vs_info_seq_stop(struct seq_file *seq, void *v)
+	__releases(RCU)
 {
 	rcu_read_unlock();
 }
@@ -2145,7 +2146,7 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v)
 {
 	struct net *net = seq_file_single_net(seq);
 	struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats;
-	struct ip_vs_cpu_stats *cpustats = tot_stats->cpustats;
+	struct ip_vs_cpu_stats __percpu *cpustats = tot_stats->cpustats;
 	struct ip_vs_stats_user rates;
 	int i;
 
@@ -2882,6 +2883,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 				   struct ip_vs_service *svc)
 {
 	struct ip_vs_scheduler *sched;
+	struct ip_vs_pe *pe;
 	struct nlattr *nl_service;
 	struct ip_vs_flags flags = { .flags = svc->flags,
 				     .mask = ~0 };
@@ -2903,9 +2905,9 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	}
 
 	sched = rcu_dereference_protected(svc->scheduler, 1);
+	pe = rcu_dereference_protected(svc->pe, 1);
 	if (nla_put_string(skb, IPVS_SVC_ATTR_SCHED_NAME, sched->name) ||
-	    (svc->pe &&
-	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
+	    (pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
 	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
Signature · 1 line
1.7.3.4
maintainer
#25 lore raw

Re: [PATCH net-next 6/6] ipvs: fix the remaining sparse warnings in ip_vs_ctl.c

Quoted 3 lines · Julian Anastasov

- RCU annotations for ip_vs_info_seq_start and _stop
- __percpu for cpustats
- properly dereference svc->pe in ip_vs_genl_fill_service

Thanks, I have queued this up in ipvs-next.

Quoted 59 lines
---
 net/netfilter/ipvs/ip_vs_ctl.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +6 -4
index 68901e4..5b142fb 100644
@@ -1945,8 +1945,8 @@ static struct ip_vs_service *ip_vs_info_array(struct seq_file *seq, loff_t pos)
 }
 
 static void *ip_vs_info_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(RCU)
 {
-
 	rcu_read_lock();
 	return *pos ? ip_vs_info_array(seq, *pos - 1) : SEQ_START_TOKEN;
 }
@@ -2001,6 +2001,7 @@ static void *ip_vs_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void ip_vs_info_seq_stop(struct seq_file *seq, void *v)
+	__releases(RCU)
 {
 	rcu_read_unlock();
 }
@@ -2145,7 +2146,7 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v)
 {
 	struct net *net = seq_file_single_net(seq);
 	struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats;
-	struct ip_vs_cpu_stats *cpustats = tot_stats->cpustats;
+	struct ip_vs_cpu_stats __percpu *cpustats = tot_stats->cpustats;
 	struct ip_vs_stats_user rates;
 	int i;
 
@@ -2882,6 +2883,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 				   struct ip_vs_service *svc)
 {
 	struct ip_vs_scheduler *sched;
+	struct ip_vs_pe *pe;
 	struct nlattr *nl_service;
 	struct ip_vs_flags flags = { .flags = svc->flags,
 				     .mask = ~0 };
@@ -2903,9 +2905,9 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
 	}
 
 	sched = rcu_dereference_protected(svc->scheduler, 1);
+	pe = rcu_dereference_protected(svc->pe, 1);
 	if (nla_put_string(skb, IPVS_SVC_ATTR_SCHED_NAME, sched->name) ||
-	    (svc->pe &&
-	     nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
+	    (pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) ||
 	    nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
 	    nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
 	    nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
Signature · 1 line
1.7.3.4