net: free ip_vs_dest structs when refcnt=0
Subsystems (5)
PATCH v2 1/1 net: free ip_vs_dest structs when refcnt=0
Currently, the ip_vs_dest cache frees ip_vs_dest objects when their reference count becomes < 0. Aside from not being semantically sound, this is problematic for the new type refcount_t, which will be introduced shortly in a separate patch. refcount_t is the new kernel type for holding reference counts, and provides overflow protection and a constrained interface relative to atomic_t (the type currently being used for kernel reference counts).
Per Julian Anastasov: "The problem is that dest_trash currently holds deleted dests (unlinked from RCU lists) with refcnt=0." Changing dest_trash to hold dest with refcnt=1 will allow us to free ip_vs_dest structs when their refcnt=0, in ip_vs_dest_put_and_free().
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_ctl.c | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-)
include/net/ip_vs.h +1 -1
@@ -1421,7 +1421,7 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)static inline void ip_vs_dest_put_and_free (struct ip_vs_dest *dest) { -if (atomic_dec_return (&dest->refcnt) <0 ) +if (atomic_dec_and_test (&dest->refcnt))kfree (dest); }
net/netfilter/ipvs/ip_vs_ctl.c +3 -5
@@ -711,7 +711,6 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af, dest->vport == svc->port))) {/* HIT */ list_del (&dest->t_list); -ip_vs_dest_hold (dest); goto out; } }
@@ -741,7 +740,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest)* When the ip_vs_control_clearup is activated by ipvs module exit, * the service tables must have been flushed and all the connections * are expired, and the refcnt of each destination in the trash must -* be 0, so we simply release them here. +* be 1, so we simply release them here. */ static void ip_vs_trash_cleanup (struct netns_ipvs *ipvs) {
@@ -1080,11 +1079,10 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,if (list_empty (&ipvs->dest_trash) && !cleanup)mod_timer (&ipvs->dest_trash_timer, jiffies + (IP_VS_DEST_TRASH_PERIOD >>1 )); -/* dest lives in trash without reference */ +/* dest lives in trash with reference */ list_add (&dest->t_list, &ipvs->dest_trash); dest->idle_start =0 ;spin_unlock_bh (&ipvs->dest_trash_lock); -ip_vs_dest_put (dest); }
@@ -1160,7 +1158,7 @@ static void ip_vs_dest_trash_expire(unsigned long data)spin_lock (&ipvs->dest_trash_lock);list_for_each_entry_safe (dest, next, &ipvs->dest_trash, t_list) { -if (atomic_read (&dest->refcnt) >0 ) +if (atomic_read (&dest->refcnt) >1 )continue ;if (dest->idle_start) { if (time_before(now, dest->idle_start +
Signature · 1 line
2.7.4
Julian Anastasov
maintainerHello,
Quoted 8 lines · David Windsor
Currently, the
ip_vs_destcache freesip_vs_destobjects when their reference count becomes < 0. Aside from not being semantically sound, this is problematic for the new typerefcount_t, which will be introduced shortly in a separate patch.refcount_tis the new kernel type for holding reference counts, and provides overflow protection and a constrained interface relative toatomic_t(the type currently being used for kernel reference counts).
Quoted 6 lines
Per Julian Anastasov: "The problem is that
dest_trashcurrently holds deleted dests (unlinked from RCU lists) with refcnt=0." Changingdest_trashto hold dest with refcnt=1 will allow us to freeip_vs_deststructs when their refcnt=0, inip_vs_dest_put_and_free().Signed-off-by David Windsor <[email protected]>
Thanks! I tested the first version and this one
just adds the needed changes in comments, so
Simon and Pablo, this is more appropriate for
ipvs-next/nf-next. Please apply!
Quoted 63 lines
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_ctl.c | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-)include/net/ip_vs.h +1
-1@@ -1421,7 +1421,7 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)static inline void ip_vs_dest_put_and_free (struct ip_vs_dest *dest) { -if (atomic_dec_return (&dest->refcnt) <0 ) +if (atomic_dec_and_test (&dest->refcnt))kfree (dest); }net/netfilter/ipvs/ip_vs_ctl.c +3
-5@@ -711,7 +711,6 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af, dest->vport == svc->port))) {/* HIT */ list_del (&dest->t_list); -ip_vs_dest_hold (dest); goto out; } }@@ -741,7 +740,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest)* When the ip_vs_control_clearup is activated by ipvs module exit, * the service tables must have been flushed and all the connections * are expired, and the refcnt of each destination in the trash must -* be 0, so we simply release them here. +* be 1, so we simply release them here. */ static void ip_vs_trash_cleanup (struct netns_ipvs *ipvs) {@@ -1080,11 +1079,10 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,if (list_empty (&ipvs->dest_trash) && !cleanup)mod_timer (&ipvs->dest_trash_timer, jiffies + (IP_VS_DEST_TRASH_PERIOD >>1 )); -/* dest lives in trash without reference */ +/* dest lives in trash with reference */ list_add (&dest->t_list, &ipvs->dest_trash); dest->idle_start =0 ;spin_unlock_bh (&ipvs->dest_trash_lock); -ip_vs_dest_put (dest); }@@ -1160,7 +1158,7 @@ static void ip_vs_dest_trash_expire(unsigned long data)spin_lock (&ipvs->dest_trash_lock);list_for_each_entry_safe (dest, next, &ipvs->dest_trash, t_list) { -if (atomic_read (&dest->refcnt) >0 ) +if (atomic_read (&dest->refcnt) >1 )continue ;if (dest->idle_start) { if (time_before(now, dest->idle_start +Signature · 1 line
2.7.4
Regards
--
Julian Anastasov <[email protected]>
Simon Horman
maintainerQuoted 20 lines · Julian Anastasov
Hello,
Quoted 8 lines · David Windsor
Currently, the
ip_vs_destcache freesip_vs_destobjects when their reference count becomes < 0. Aside from not being semantically sound, this is problematic for the new typerefcount_t, which will be introduced shortly in a separate patch.refcount_tis the new kernel type for holding reference counts, and provides overflow protection and a constrained interface relative toatomic_t(the type currently being used for kernel reference counts).Quoted 6 lines
Per Julian Anastasov: "The problem is that
dest_trashcurrently holds deleted dests (unlinked from RCU lists) with refcnt=0." Changingdest_trashto hold dest with refcnt=1 will allow us to freeip_vs_deststructs when their refcnt=0, inip_vs_dest_put_and_free().Signed-off-by David Windsor <[email protected]>
Quoted 7 lines
Thanks! I tested the first version and this one
just adds the needed changes in comments, soSigned-off-by Julian Anastasov <[email protected]>Simon and Pablo, this is more appropriate for
ipvs-next/nf-next. Please apply!
Pablo, would you mind taking this one directly into nf-next?
Quoted 70 lines
Quoted 64 lines
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_ctl.c | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-)include/net/ip_vs.h +1
-1@@ -1421,7 +1421,7 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)static inline void ip_vs_dest_put_and_free (struct ip_vs_dest *dest) { -if (atomic_dec_return (&dest->refcnt) <0 ) +if (atomic_dec_and_test (&dest->refcnt))kfree (dest); }net/netfilter/ipvs/ip_vs_ctl.c +3
-5@@ -711,7 +711,6 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af, dest->vport == svc->port))) {/* HIT */ list_del (&dest->t_list); -ip_vs_dest_hold (dest); goto out; } }@@ -741,7 +740,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest)* When the ip_vs_control_clearup is activated by ipvs module exit, * the service tables must have been flushed and all the connections * are expired, and the refcnt of each destination in the trash must -* be 0, so we simply release them here. +* be 1, so we simply release them here. */ static void ip_vs_trash_cleanup (struct netns_ipvs *ipvs) {@@ -1080,11 +1079,10 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,if (list_empty (&ipvs->dest_trash) && !cleanup)mod_timer (&ipvs->dest_trash_timer, jiffies + (IP_VS_DEST_TRASH_PERIOD >>1 )); -/* dest lives in trash without reference */ +/* dest lives in trash with reference */ list_add (&dest->t_list, &ipvs->dest_trash); dest->idle_start =0 ;spin_unlock_bh (&ipvs->dest_trash_lock); -ip_vs_dest_put (dest); }@@ -1160,7 +1158,7 @@ static void ip_vs_dest_trash_expire(unsigned long data)spin_lock (&ipvs->dest_trash_lock);list_for_each_entry_safe (dest, next, &ipvs->dest_trash, t_list) { -if (atomic_read (&dest->refcnt) >0 ) +if (atomic_read (&dest->refcnt) >1 )continue ;if (dest->idle_start) { if (time_before(now, dest->idle_start +Signature · 1 line
2.7.4Regards
--
Julian Anastasov <[email protected]>
Pablo Neira Ayuso
maintainerQuoted 24 lines · Simon Horman
Quoted 23 lines · Julian Anastasov
Hello,
Quoted 8 lines · David Windsor
Currently, the
ip_vs_destcache freesip_vs_destobjects when their reference count becomes < 0. Aside from not being semantically sound, this is problematic for the new typerefcount_t, which will be introduced shortly in a separate patch.refcount_tis the new kernel type for holding reference counts, and provides overflow protection and a constrained interface relative toatomic_t(the type currently being used for kernel reference counts).Quoted 6 lines
Per Julian Anastasov: "The problem is that
dest_trashcurrently holds deleted dests (unlinked from RCU lists) with refcnt=0." Changingdest_trashto hold dest with refcnt=1 will allow us to freeip_vs_deststructs when their refcnt=0, inip_vs_dest_put_and_free().Signed-off-by David Windsor <[email protected]>Thanks! I tested the first version and this one
just adds the needed changes in comments, so
Quoted 8 lines
Quoted 4 lines
Signed-off-by Julian Anastasov <[email protected]>Simon and Pablo, this is more appropriate for
ipvs-next/nf-next. Please apply!Pablo, would you mind taking this one directly into nf-next?
Signed-off-by Simon Horman <[email protected]>
Sure, no problem. I'll take it. Thanks!
Simon Horman
maintainerQuoted 27 lines · Pablo Neira Ayuso
Quoted 26 lines · Simon Horman
Quoted 25 lines · Julian Anastasov
Hello,
Quoted 8 lines · David Windsor
Currently, the
ip_vs_destcache freesip_vs_destobjects when their reference count becomes < 0. Aside from not being semantically sound, this is problematic for the new typerefcount_t, which will be introduced shortly in a separate patch.refcount_tis the new kernel type for holding reference counts, and provides overflow protection and a constrained interface relative toatomic_t(the type currently being used for kernel reference counts).Quoted 6 lines
Per Julian Anastasov: "The problem is that
dest_trashcurrently holds deleted dests (unlinked from RCU lists) with refcnt=0." Changingdest_trashto hold dest with refcnt=1 will allow us to freeip_vs_deststructs when their refcnt=0, inip_vs_dest_put_and_free().Signed-off-by David Windsor <[email protected]>Thanks! I tested the first version and this one
just adds the needed changes in comments, soSigned-off-by Julian Anastasov <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Simon and Pablo, this is more appropriate for
ipvs-next/nf-next. Please apply!Pablo, would you mind taking this one directly into nf-next?
Signed-off-by Simon Horman <[email protected]>Sure, no problem. I'll take it. Thanks!
Thanks!