Skip to contentSkip to conversation

IPVS fixes for corner cases

PATCH Superseded Julian Anastasov 3 participants 13 messages Aug 28, 2013 – Sep 11, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Julian Anastasov

author maintainer
#0 lore raw

cover IPVS fixes for corner cases

The patchset contains fixes for races during
dest and service deletion caused from the recent RCU changes.

The last change is required if CPU 0 can be missing
from the mask of possible CPUs. Otherwise, it can be considered a non-fatal change.

Julian Anastasov (4):
ipvs: do not use dest after ip_vs_dest_put in LBLC
ipvs: do not use dest after ip_vs_dest_put in LBLCR
ipvs: make the service replacement more robust
ipvs: stats should not depend on CPU 0

 include/net/ip_vs.h              |    6 +--
 net/netfilter/ipvs/ip_vs_core.c  |   12 ++++-
 net/netfilter/ipvs/ip_vs_ctl.c   |   90 +++++++++++++++-----------------------
 net/netfilter/ipvs/ip_vs_est.c   |    4 +-
 net/netfilter/ipvs/ip_vs_lblc.c  |   68 +++++++++++++---------------
 net/netfilter/ipvs/ip_vs_lblcr.c |   50 ++++++++-------------
 6 files changed, 101 insertions(+), 129 deletions(-)
Signature · 1 line
1.7.3.4
author maintainer
#1 lore raw

PATCH 1/4 ipvs: do not use dest after ip_vs_dest_put in LBLC

commit c2a4ffb70eef39 ("ipvs: convert lblc scheduler to rcu") allows RCU readers to use dest after calling ip_vs_dest_put(). In the corner case it can race with ip_vs_dest_trash_expire() which can release the dest while it is being returned to the RCU readers as scheduling result.

To fix the problem do not allow en->dest to be replaced and defer the ip_vs_dest_put() call by using RCU callback. Now en->dest does not need to be RCU pointer.

---
 net/netfilter/ipvs/ip_vs_lblc.c |   68 ++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 37 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +31 -37
index 1383b0e..b39b0e9 100644
@@ -93,7 +93,7 @@ struct ip_vs_lblc_entry {
 	struct hlist_node	list;
 	int			af;		/* address family */
 	union nf_inet_addr      addr;           /* destination IP address */
-	struct ip_vs_dest __rcu	*dest;          /* real server (cache) */
+	struct ip_vs_dest	*dest;          /* real server (cache) */
 	unsigned long           lastuse;        /* last used time */
 	struct rcu_head		rcu_head;
 };
@@ -130,20 +130,21 @@ static struct ctl_table vs_vars_table[] = {
 };
 #endif
 
-static inline void ip_vs_lblc_free(struct ip_vs_lblc_entry *en)
+static void ip_vs_lblc_rcu_free(struct rcu_head *head)
 {
-	struct ip_vs_dest *dest;
+	struct ip_vs_lblc_entry *en = container_of(head,
+						   struct ip_vs_lblc_entry,
+						   rcu_head);
 
-	hlist_del_rcu(&en->list);
-	/*
-	 * We don't kfree dest because it is referred either by its service
-	 * or the trash dest list.
-	 */
-	dest = rcu_dereference_protected(en->dest, 1);
-	ip_vs_dest_put(dest);
-	kfree_rcu(en, rcu_head);
+	ip_vs_dest_put(en->dest);
+	kfree(en);
 }
 
+static inline void ip_vs_lblc_del(struct ip_vs_lblc_entry *en)
+{
+	hlist_del_rcu(&en->list);
+	call_rcu(&en->rcu_head, ip_vs_lblc_rcu_free);
+}
 
 /*
  *	Returns hash value for IPVS LBLC entry
@@ -203,30 +204,23 @@ ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr,
 	struct ip_vs_lblc_entry *en;
 
 	en = ip_vs_lblc_get(dest->af, tbl, daddr);
-	if (!en) {
-		en = kmalloc(sizeof(*en), GFP_ATOMIC);
-		if (!en)
-			return NULL;
-
-		en->af = dest->af;
-		ip_vs_addr_copy(dest->af, &en->addr, daddr);
-		en->lastuse = jiffies;
+	if (en) {
+		if (en->dest == dest)
+			return en;
+		ip_vs_lblc_del(en);
+	}
+	en = kmalloc(sizeof(*en), GFP_ATOMIC);
+	if (!en)
+		return NULL;
 
-		ip_vs_dest_hold(dest);
-		RCU_INIT_POINTER(en->dest, dest);
+	en->af = dest->af;
+	ip_vs_addr_copy(dest->af, &en->addr, daddr);
+	en->lastuse = jiffies;
 
-		ip_vs_lblc_hash(tbl, en);
-	} else {
-		struct ip_vs_dest *old_dest;
+	ip_vs_dest_hold(dest);
+	en->dest = dest;
 
-		old_dest = rcu_dereference_protected(en->dest, 1);
-		if (old_dest != dest) {
-			ip_vs_dest_put(old_dest);
-			ip_vs_dest_hold(dest);
-			/* No ordering constraints for refcnt */
-			RCU_INIT_POINTER(en->dest, dest);
-		}
-	}
+	ip_vs_lblc_hash(tbl, en);
 
 	return en;
 }
@@ -246,7 +240,7 @@ static void ip_vs_lblc_flush(struct ip_vs_service *svc)
 	tbl->dead = 1;
 	for (i=0; i<IP_VS_LBLC_TAB_SIZE; i++) {
 		hlist_for_each_entry_safe(en, next, &tbl->bucket[i], list) {
-			ip_vs_lblc_free(en);
+			ip_vs_lblc_del(en);
 			atomic_dec(&tbl->entries);
 		}
 	}
@@ -281,7 +275,7 @@ static inline void ip_vs_lblc_full_check(struct ip_vs_service *svc)
 					sysctl_lblc_expiration(svc)))
 				continue;
 
-			ip_vs_lblc_free(en);
+			ip_vs_lblc_del(en);
 			atomic_dec(&tbl->entries);
 		}
 		spin_unlock(&svc->sched_lock);
@@ -335,7 +329,7 @@ static void ip_vs_lblc_check_expire(unsigned long data)
 			if (time_before(now, en->lastuse + ENTRY_TIMEOUT))
 				continue;
 
-			ip_vs_lblc_free(en);
+			ip_vs_lblc_del(en);
 			atomic_dec(&tbl->entries);
 			goal--;
 		}
@@ -511,7 +505,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
 		 * free up entries from the trash at any time.
 		 */
 
-		dest = rcu_dereference(en->dest);
+		dest = en->dest;
 		if ((dest->flags & IP_VS_DEST_F_AVAILABLE) &&
 		    atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc))
 			goto out;
@@ -631,7 +625,7 @@ static void __exit ip_vs_lblc_cleanup(void)
 {
 	unregister_ip_vs_scheduler(&ip_vs_lblc_scheduler);
 	unregister_pernet_subsys(&ip_vs_lblc_ops);
-	synchronize_rcu();
+	rcu_barrier();
 }
 
 
Signature · 1 line
1.7.3.4
author maintainer
#2 lore raw

PATCH 2/4 ipvs: do not use dest after ip_vs_dest_put in LBLCR

In reply to Julian Anastasov

commit c5549571f975ab ("ipvs: convert lblcr scheduler to rcu") allows RCU readers to use dest after calling ip_vs_dest_put(). In the corner case it can race with ip_vs_dest_trash_expire() which can release the dest while it is being returned to the RCU readers as scheduling result.

To fix the problem do not allow e->dest to be replaced and defer the ip_vs_dest_put() call by using RCU callback. Now e->dest does not need to be RCU pointer.

---
 net/netfilter/ipvs/ip_vs_lblcr.c |   50 +++++++++++++++----------------------
 1 files changed, 20 insertions(+), 30 deletions(-)
net/netfilter/ipvs/ip_vs_lblcr.c +20 -30
index 3cd85b2..64de585 100644
@@ -89,7 +89,7 @@
  */
 struct ip_vs_dest_set_elem {
 	struct list_head	list;          /* list link */
-	struct ip_vs_dest __rcu *dest;         /* destination server */
+	struct ip_vs_dest	*dest;		/* destination server */
 	struct rcu_head		rcu_head;
 };
 
@@ -107,11 +107,7 @@ static void ip_vs_dest_set_insert(struct ip_vs_dest_set *set,
 
 	if (check) {
 		list_for_each_entry(e, &set->list, list) {
-			struct ip_vs_dest *d;
-
-			d = rcu_dereference_protected(e->dest, 1);
-			if (d == dest)
-				/* already existed */
+			if (e->dest == dest)
 				return;
 		}
 	}
@@ -121,7 +117,7 @@ static void ip_vs_dest_set_insert(struct ip_vs_dest_set *set,
 		return;
 
 	ip_vs_dest_hold(dest);
-	RCU_INIT_POINTER(e->dest, dest);
+	e->dest = dest;
 
 	list_add_rcu(&e->list, &set->list);
 	atomic_inc(&set->size);
@@ -129,22 +125,27 @@ static void ip_vs_dest_set_insert(struct ip_vs_dest_set *set,
 	set->lastmod = jiffies;
 }
 
+static void ip_vs_lblcr_elem_rcu_free(struct rcu_head *head)
+{
+	struct ip_vs_dest_set_elem *e;
+
+	e = container_of(head, struct ip_vs_dest_set_elem, rcu_head);
+	ip_vs_dest_put(e->dest);
+	kfree(e);
+}
+
 static void
 ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
 {
 	struct ip_vs_dest_set_elem *e;
 
 	list_for_each_entry(e, &set->list, list) {
-		struct ip_vs_dest *d;
-
-		d = rcu_dereference_protected(e->dest, 1);
-		if (d == dest) {
+		if (e->dest == dest) {
 			/* HIT */
 			atomic_dec(&set->size);
 			set->lastmod = jiffies;
-			ip_vs_dest_put(dest);
 			list_del_rcu(&e->list);
-			kfree_rcu(e, rcu_head);
+			call_rcu(&e->rcu_head, ip_vs_lblcr_elem_rcu_free);
 			break;
 		}
 	}
@@ -155,16 +156,8 @@ static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
 	struct ip_vs_dest_set_elem *e, *ep;
 
 	list_for_each_entry_safe(e, ep, &set->list, list) {
-		struct ip_vs_dest *d;
-
-		d = rcu_dereference_protected(e->dest, 1);
-		/*
-		 * We don't kfree dest because it is referred either
-		 * by its service or by the trash dest list.
-		 */
-		ip_vs_dest_put(d);
 		list_del_rcu(&e->list);
-		kfree_rcu(e, rcu_head);
+		call_rcu(&e->rcu_head, ip_vs_lblcr_elem_rcu_free);
 	}
 }
 
@@ -175,12 +168,9 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
 	struct ip_vs_dest *dest, *least;
 	int loh, doh;
 
-	if (set == NULL)
-		return NULL;
-
 	/* select the first destination server, whose weight > 0 */
 	list_for_each_entry_rcu(e, &set->list, list) {
-		least = rcu_dereference(e->dest);
+		least = e->dest;
 		if (least->flags & IP_VS_DEST_F_OVERLOAD)
 			continue;
 
@@ -195,7 +185,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
 	/* find the destination with the weighted least load */
   nextstage:
 	list_for_each_entry_continue_rcu(e, &set->list, list) {
-		dest = rcu_dereference(e->dest);
+		dest = e->dest;
 		if (dest->flags & IP_VS_DEST_F_OVERLOAD)
 			continue;
 
@@ -232,7 +222,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
 
 	/* select the first destination server, whose weight > 0 */
 	list_for_each_entry(e, &set->list, list) {
-		most = rcu_dereference_protected(e->dest, 1);
+		most = e->dest;
 		if (atomic_read(&most->weight) > 0) {
 			moh = ip_vs_dest_conn_overhead(most);
 			goto nextstage;
@@ -243,7 +233,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
 	/* find the destination with the weighted most load */
   nextstage:
 	list_for_each_entry_continue(e, &set->list, list) {
-		dest = rcu_dereference_protected(e->dest, 1);
+		dest = e->dest;
 		doh = ip_vs_dest_conn_overhead(dest);
 		/* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */
 		if ((moh * atomic_read(&dest->weight) <
@@ -819,7 +809,7 @@ static void __exit ip_vs_lblcr_cleanup(void)
 {
 	unregister_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
 	unregister_pernet_subsys(&ip_vs_lblcr_ops);
-	synchronize_rcu();
+	rcu_barrier();
 }
 
 
Signature · 1 line
1.7.3.4
author maintainer
#3 lore raw

PATCH 3/4 ipvs: make the service replacement more robust

In reply to Julian Anastasov

commit 578bc3ef1e473a ("ipvs: reorganize dest trash") added IP_VS_DEST_STATE_REMOVING flag and RCU callback named ip_vs_dest_wait_readers() to keep dests and services after removal for at least a RCU grace period. But we have the following corner cases:

- we can not reuse the same dest if its service is removed while IP_VS_DEST_STATE_REMOVING is still set because another dest removal in the first grace period can not extend this period. It can happen when ipvsadm -C && ipvsadm -R is used.

- dest->svc can be replaced but ip_vs_in_stats() and ip_vs_out_stats() have no explicit read memory barriers when accessing dest->svc. It can happen that dest->svc was just freed (replaced) while we use it to update the stats.

We solve the problems as follows:

- IP_VS_DEST_STATE_REMOVING is removed and we ensure a fixed idle period for the dest (IP_VS_DEST_TRASH_PERIOD). idle_start will remember when for first time after deletion we noticed dest->refcnt=0. Later, the connections can grab a reference while in RCU grace period but if refcnt becomes 0 we can safely free the dest and its svc.

- dest->svc becomes RCU pointer. As result, we add explicit RCU locking in ip_vs_in_stats() and ip_vs_out_stats().

- __ip_vs_unbind_svc is renamed to __ip_vs_svc_put(), it now can free the service immediately or after a RCU grace period. dest->svc is not set to NULL anymore.

As result, unlinked dests and their services are
freed always after IP_VS_DEST_TRASH_PERIOD period, unused services are freed after a RCU grace period.

---
 include/net/ip_vs.h             |    6 +--
 net/netfilter/ipvs/ip_vs_core.c |   12 ++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |   90 +++++++++++++++------------------------
 3 files changed, 47 insertions(+), 61 deletions(-)
include/net/ip_vs.h +2 -4
index f0d70f0..ce3e942 100644
@@ -723,8 +723,6 @@ struct ip_vs_dest_dst {
 	struct rcu_head		rcu_head;
 };
 
-/* In grace period after removing */
-#define IP_VS_DEST_STATE_REMOVING	0x01
 /*
  *	The real server destination forwarding entry
  *	with ip address, port number, and so on.
@@ -742,7 +740,7 @@ struct ip_vs_dest {
 
 	atomic_t		refcnt;		/* reference counter */
 	struct ip_vs_stats      stats;          /* statistics */
-	unsigned long		state;		/* state flags */
+	unsigned long		idle_start;	/* start time, jiffies */
 
 	/* connection counters and thresholds */
 	atomic_t		activeconns;	/* active connections */
@@ -756,7 +754,7 @@ struct ip_vs_dest {
 	struct ip_vs_dest_dst __rcu *dest_dst;	/* cached dst info */
 
 	/* for virtual service */
-	struct ip_vs_service	*svc;		/* service it belongs to */
+	struct ip_vs_service __rcu *svc;	/* service it belongs to */
 	__u16			protocol;	/* which protocol (TCP/UDP) */
 	__be16			vport;		/* virtual port number */
 	union nf_inet_addr	vaddr;		/* virtual IP address */
net/netfilter/ipvs/ip_vs_core.c +10 -2
index 4f69e83..74fd00c 100644
@@ -116,6 +116,7 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 
 	if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
 		struct ip_vs_cpu_stats *s;
+		struct ip_vs_service *svc;
 
 		s = this_cpu_ptr(dest->stats.cpustats);
 		s->ustats.inpkts++;
@@ -123,11 +124,14 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 		s->ustats.inbytes += skb->len;
 		u64_stats_update_end(&s->syncp);
 
-		s = this_cpu_ptr(dest->svc->stats.cpustats);
+		rcu_read_lock();
+		svc = rcu_dereference(dest->svc);
+		s = this_cpu_ptr(svc->stats.cpustats);
 		s->ustats.inpkts++;
 		u64_stats_update_begin(&s->syncp);
 		s->ustats.inbytes += skb->len;
 		u64_stats_update_end(&s->syncp);
+		rcu_read_unlock();
 
 		s = this_cpu_ptr(ipvs->tot_stats.cpustats);
 		s->ustats.inpkts++;
@@ -146,6 +150,7 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 
 	if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
 		struct ip_vs_cpu_stats *s;
+		struct ip_vs_service *svc;
 
 		s = this_cpu_ptr(dest->stats.cpustats);
 		s->ustats.outpkts++;
@@ -153,11 +158,14 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 		s->ustats.outbytes += skb->len;
 		u64_stats_update_end(&s->syncp);
 
-		s = this_cpu_ptr(dest->svc->stats.cpustats);
+		rcu_read_lock();
+		svc = rcu_dereference(dest->svc);
+		s = this_cpu_ptr(svc->stats.cpustats);
 		s->ustats.outpkts++;
 		u64_stats_update_begin(&s->syncp);
 		s->ustats.outbytes += skb->len;
 		u64_stats_update_end(&s->syncp);
+		rcu_read_unlock();
 
 		s = this_cpu_ptr(ipvs->tot_stats.cpustats);
 		s->ustats.outpkts++;
net/netfilter/ipvs/ip_vs_ctl.c +35 -55

195 lines not on this page · raw message

Signature · 1 line
1.7.3.4
author maintainer
#4 lore raw

Re: [PATCH net 3/4] ipvs: make the service replacement more robust

Hello,

net/netfilter/ipvs/ip_vs_ctl.c void __net_exit ip_vs_control_net_cleanup(struct net *net) · line 3825

Quoted 7 lines · Julian Anastasov
net/netfilter/ipvs/ip_vs_ctl.c +0 -4
-	/* Some dest can be in grace period even before cleanup, we have to
-	 * defer ip_vs_trash_cleanup until ip_vs_dest_wait_readers is called.
-	 */
-	rcu_barrier();
 	ip_vs_trash_cleanup(net);
 	ip_vs_stop_estimator(net, &ipvs->tot_stats);
 	ip_vs_control_net_cleanup_sysctl(net);

Simon, I have to update this patch. rcu_barrier
can not simply disappear because LBLC[R] use RCU callbacks and we have to wait them to put the final reference to dest before calling ip_vs_trash_cleanup(). It needs different solution, if possible without rcu_barrier. I'll send updated patchset in next days.

Regards

--
Julian Anastasov <[email protected]>

maintainer
#5 lore raw

Re: [PATCH net 3/4] ipvs: make the service replacement more robust

Quoted 5 lines · Julian Anastasov

Hello,

On Wed, 28 Aug 2013, Julian Anastasov wrote:

Quoted 14 lines

net/netfilter/ipvs/ip_vs_ctl.c void __net_exit ip_vs_control_net_cleanup(struct net *net) · line 3825

Quoted 7 lines
net/netfilter/ipvs/ip_vs_ctl.c +0 -4
-	/* Some dest can be in grace period even before cleanup, we have to
-	 * defer ip_vs_trash_cleanup until ip_vs_dest_wait_readers is called.
-	 */
-	rcu_barrier();
 	ip_vs_trash_cleanup(net);
 	ip_vs_stop_estimator(net, &ipvs->tot_stats);
 	ip_vs_control_net_cleanup_sysctl(net);

Simon, I have to update this patch. rcu_barrier
can not simply disappear because LBLC[R] use RCU callbacks and we have to wait them to put the final reference to dest before calling ip_vs_trash_cleanup(). It needs different solution, if possible without rcu_barrier. I'll send updated patchset in next days.

Thanks, noted.

author maintainer
#6 lore raw

PATCH 4/4 ipvs: stats should not depend on CPU 0

In reply to Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

---
 net/netfilter/ipvs/ip_vs_est.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_est.c +3 -1
index 6bee6d0..1425e9a 100644
@@ -59,12 +59,13 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 				 struct ip_vs_cpu_stats __percpu *stats)
 {
 	int i;
+	bool add = false;
 
 	for_each_possible_cpu(i) {
 		struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
 		unsigned int start;
 		__u64 inbytes, outbytes;
-		if (i) {
+		if (add) {
 			sum->conns += s->ustats.conns;
 			sum->inpkts += s->ustats.inpkts;
 			sum->outpkts += s->ustats.outpkts;
@@ -76,6 +77,7 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 			sum->inbytes += inbytes;
 			sum->outbytes += outbytes;
 		} else {
+			add = true;
 			sum->conns = s->ustats.conns;
 			sum->inpkts = s->ustats.inpkts;
 			sum->outpkts = s->ustats.outpkts;
Signature · 1 line
1.7.3.4
maintainer
#7 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

[ Cc: Hans Schillstrom ]

Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

It seems reasonable to me that this condition could occur, though I am not aware of a specific case where that is so.

Can I confirm that this problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs")?

Quoted 36 lines
---
 net/netfilter/ipvs/ip_vs_est.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_est.c +3 -1
index 6bee6d0..1425e9a 100644
@@ -59,12 +59,13 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 				 struct ip_vs_cpu_stats __percpu *stats)
 {
 	int i;
+	bool add = false;
 
 	for_each_possible_cpu(i) {
 		struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
 		unsigned int start;
 		__u64 inbytes, outbytes;
-		if (i) {
+		if (add) {
 			sum->conns += s->ustats.conns;
 			sum->inpkts += s->ustats.inpkts;
 			sum->outpkts += s->ustats.outpkts;
@@ -76,6 +77,7 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 			sum->inbytes += inbytes;
 			sum->outbytes += outbytes;
 		} else {
+			add = true;
 			sum->conns = s->ustats.conns;
 			sum->inpkts = s->ustats.inpkts;
 			sum->outpkts = s->ustats.outpkts;
Signature · 1 line
1.7.3.4
author maintainer
#8 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

Hello,

Quoted 11 lines · Simon Horman

[ Cc: Hans Schillstrom ]

Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

It seems reasonable to me that this condition could occur, though I am not aware of a specific case where that is so.

Can I confirm that this problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs")?

That is correct, I forgot to track the initial
commit, you can freely add such information before applying.

Regards

--
Julian Anastasov <[email protected]>

Acked-by on v1 4/4
#9 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

In reply to Julian Anastasov
Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

Not a very common case, but still possible.

Quoted 1 line
Quoted 31 lines
---
 net/netfilter/ipvs/ip_vs_est.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_est.c +3 -1
index 6bee6d0..1425e9a 100644
@@ -59,12 +59,13 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 				 struct ip_vs_cpu_stats __percpu *stats)
 {
 	int i;
+	bool add = false;
 
 	for_each_possible_cpu(i) {
 		struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
 		unsigned int start;
 		__u64 inbytes, outbytes;
-		if (i) {
+		if (add) {
 			sum->conns += s->ustats.conns;
 			sum->inpkts += s->ustats.inpkts;
 			sum->outpkts += s->ustats.outpkts;
@@ -76,6 +77,7 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 			sum->inbytes += inbytes;
 			sum->outbytes += outbytes;
 		} else {
+			add = true;
 			sum->conns = s->ustats.conns;
 			sum->inpkts = s->ustats.inpkts;
 			sum->outpkts = s->ustats.outpkts;
maintainer Acked-by Hans Schillstrom
#10 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

Quoted 26 lines · Julian Anastasov

Hello,

Quoted 11 lines · Simon Horman

[ Cc: Hans Schillstrom ]

Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

It seems reasonable to me that this condition could occur, though I am not aware of a specific case where that is so.

Can I confirm that this problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs")?

That is correct, I forgot to track the initial
commit, you can freely add such information before applying.

Regards

--
Julian Anastasov <[email protected]>

Quoted 10 lines · Hans Schillstrom
Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

Not a very common case, but still possible.

Quoted 1 line

Thanks guys, I have queued up the following in the ipvs tree along with the rest of this series.

From 056a057b581b7a98669e65745c9866d233f82a18 Mon Sep 17 00:00:00 2001
From: Julian Anastasov <[email protected]>
Date: Wed, 28 Aug 2013 19:29:36 +0300
Subject: [PATCH] ipvs: stats should not depend on CPU 0

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

This problem was introduced by 17fc9963f837ef1
("IPVS: netns, ip_vs_stats and its procfs").

---
 net/netfilter/ipvs/ip_vs_est.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_est.c +3 -1
index 6bee6d0..1425e9a 100644
@@ -59,12 +59,13 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 				 struct ip_vs_cpu_stats __percpu *stats)
 {
 	int i;
+	bool add = false;
 
 	for_each_possible_cpu(i) {
 		struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
 		unsigned int start;
 		__u64 inbytes, outbytes;
-		if (i) {
+		if (add) {
 			sum->conns += s->ustats.conns;
 			sum->inpkts += s->ustats.inpkts;
 			sum->outpkts += s->ustats.outpkts;
@@ -76,6 +77,7 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 			sum->inbytes += inbytes;
 			sum->outbytes += outbytes;
 		} else {
+			add = true;
 			sum->conns = s->ustats.conns;
 			sum->inpkts = s->ustats.inpkts;
 			sum->outpkts = s->ustats.outpkts;
Signature · 1 line
1.8.3.2
maintainer Acked-by Hans Schillstrom
#11 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

Quoted 36 lines · Simon Horman
Quoted 26 lines · Julian Anastasov

Hello,

Quoted 11 lines · Simon Horman

[ Cc: Hans Schillstrom ]

Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

It seems reasonable to me that this condition could occur, though I am not aware of a specific case where that is so.

Can I confirm that this problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs")?

That is correct, I forgot to track the initial
commit, you can freely add such information before applying.

Regards

--
Julian Anastasov <[email protected]>

Quoted 7 lines · Hans Schillstrom
Quoted 2 lines · Julian Anastasov

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

Not a very common case, but still possible.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks guys, I have queued up the following in the ipvs tree along with the rest of this series.

Bother, I messed up the commit-id in the changelog. The corrected version, which I will queue up, is.

From 77f12c00cd6603e93dcb729aa6dc206cb8bb3a46 Mon Sep 17 00:00:00 2001
From: Julian Anastasov <[email protected]>
Date: Wed, 28 Aug 2013 19:29:36 +0300
Subject: [PATCH] ipvs: stats should not depend on CPU 0

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

This problem was introduced by b17fc9963f837ef1
("IPVS: netns, ip_vs_stats and its procfs").

---
 net/netfilter/ipvs/ip_vs_est.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_est.c +3 -1
index 6bee6d0..1425e9a 100644
@@ -59,12 +59,13 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 				 struct ip_vs_cpu_stats __percpu *stats)
 {
 	int i;
+	bool add = false;
 
 	for_each_possible_cpu(i) {
 		struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
 		unsigned int start;
 		__u64 inbytes, outbytes;
-		if (i) {
+		if (add) {
 			sum->conns += s->ustats.conns;
 			sum->inpkts += s->ustats.inpkts;
 			sum->outpkts += s->ustats.outpkts;
@@ -76,6 +77,7 @@ static void ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
 			sum->inbytes += inbytes;
 			sum->outbytes += outbytes;
 		} else {
+			add = true;
 			sum->conns = s->ustats.conns;
 			sum->inpkts = s->ustats.inpkts;
 			sum->outpkts = s->ustats.outpkts;
Signature · 1 line
1.8.3.2
author maintainer
#12 lore raw

Re: [PATCH net 4/4] ipvs: stats should not depend on CPU 0

Hello,

Quoted 9 lines · Simon Horman
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Can I confirm that this problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs")?

That is correct, I forgot to track the initial
commit, you can freely add such information before applying.

Bother, I messed up the commit-id in the changelog. The corrected version, which I will queue up, is.

OK, I noticed it too. Later you post pull request
with wrong commit, I hope Pablo will pull a fixed patch because ipvs-fixes-for-v3.11 still has old commit.

Quoted 10 lines
Quoted 1 line

From 77f12c00cd6603e93dcb729aa6dc206cb8bb3a46 Mon Sep 17 00:00:00 2001

From: Julian Anastasov <[email protected]>
Date: Wed, 28 Aug 2013 19:29:36 +0300
Subject: [PATCH] ipvs: stats should not depend on CPU 0

When reading percpu stats we need to properly reset the sum when CPU 0 is not present in the possible mask.

This problem was introduced by b17fc9963f837ef1 ("IPVS: netns, ip_vs_stats and its procfs").

Regards

--
Julian Anastasov <[email protected]>