Re: [PATCH 11/14] netfilter: ipset: Introduce RCU locking in the hash types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2 Dec 2014, Pablo Neira Ayuso wrote:

> > diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> > index 974ff38..8f51ba4 100644
> > --- a/net/netfilter/ipset/ip_set_hash_gen.h
> > +++ b/net/netfilter/ipset/ip_set_hash_gen.h
> > @@ -10,19 +10,19 @@
> >  
> >  #include <linux/rcupdate.h>
> >  #include <linux/jhash.h>
> > +#include <linux/types.h>
> >  #include <linux/netfilter/ipset/ip_set_timeout.h>
> > -#ifndef rcu_dereference_bh
> > -#define rcu_dereference_bh(p)	rcu_dereference(p)
> > -#endif
> > +
> > +#define __ipset_dereference_protected(p, c)	rcu_dereference_protected(p, c)
> > +#define ipset_dereference_protected(p, set) \
> > +	__ipset_dereference_protected(p, spin_is_locked(&(set)->lock))
> >  
> >  #define rcu_dereference_bh_nfnl(p)	rcu_dereference_bh_check(p, 1)
> >  
> [...]
> >  /* Flush a hash type of set: destroy all elements */
> > @@ -376,16 +359,16 @@ mtype_flush(struct ip_set *set)
> >  	struct hbucket *n;
> >  	u32 i;
> >  
> > -	t = rcu_dereference_bh_nfnl(h->table);
> > +	t = ipset_dereference_protected(h->table, set);
> >  	for (i = 0; i < jhash_size(t->htable_bits); i++) {
> > -		n = hbucket(t, i);
> > -		if (n->size) {
> > -			if (set->extensions & IPSET_EXT_DESTROY)
> > -				mtype_ext_cleanup(set, n);
> > -			n->size = n->pos = 0;
> > -			/* FIXME: use slab cache */
> > -			kfree(n->value);
> > -		}
> > +		n = __ipset_dereference_protected(hbucket(t, i), 1);
> 
> What is your intention with these macros?

The macros serve to solve sparse checking warnings. Without the macros one 
can get:

/usr/src/git/ipset/ipset/kernel/net/netfilter/ipset/ip_set_hash_gen.h:369:19: 
warning: incorrect type in assignment (different address spaces)
/usr/src/git/ipset/ipset/kernel/net/netfilter/ipset/ip_set_hash_gen.h:369:19:    
expected struct hbucket *n
/usr/src/git/ipset/ipset/kernel/net/netfilter/ipset/ip_set_hash_gen.h:369:19:    
got struct hbucket [noderef] <asn:4>*<noident>

The real condition (spin is locked) is always checked before the loop, in 
ipset_dereference_protected. Inside the loop it's not checked again and 
again.

Best regards,
Jozsef
-
E-mail  : kadlec@xxxxxxxxxxxxxxxxx, kadlecsik.jozsef@xxxxxxxxxxxxx
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
          H-1525 Budapest 114, POB. 49, Hungary
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux