netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mleitner@redhat.com
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Xin Long <lucien.xin@gmail.com>,
	netdev@vger.kernel.org, linux-sctp@vger.kernel.org,
	vyasevic@redhat.com, daniel@iogearbox.net, davem@davemloft.net
Subject: Re: [PATCH net-next 1/5] sctp: add the rhashtable apis for sctp global transport hashtable
Date: Mon, 11 Jan 2016 14:00:40 -0200	[thread overview]
Message-ID: <20160111160039.GA6061@mrl.redhat.com> (raw)
In-Reply-To: <20160111093012.GA23525@gondor.apana.org.au>

On Mon, Jan 11, 2016 at 05:30:12PM +0800, Herbert Xu wrote:
> Xin Long <lucien.xin@gmail.com> wrote:
> >
> > +static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
> > +                               const void *ptr)
> > +{
> > +       const struct sctp_hash_cmp_arg *x = arg->key;
> > +       const struct sctp_transport *t = ptr;
> > +       struct sctp_association *asoc = t->asoc;
> > +       const struct net *net = x->net;
> > +
> > +       if (x->laddr->v4.sin_port != htons(asoc->base.bind_addr.port))
> > +               return 1;
> > +       if (!sctp_cmp_addr_exact(&t->ipaddr, x->paddr))
> > +               return 1;
> > +       if (!net_eq(sock_net(asoc->base.sk), net))
> > +               return 1;
> > +       if (!sctp_bind_addr_match(&asoc->base.bind_addr,
> > +                                 x->laddr, sctp_sk(asoc->base.sk)))
> > +               return 1;
> > +
> > +       return 0;
> > +}
> > +
> > +static inline u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
> > +{
> > +       const struct sctp_transport *t = data;
> > +       const union sctp_addr *paddr = &t->ipaddr;
> > +       const struct net *net = sock_net(t->asoc->base.sk);
> > +       u16 lport = htons(t->asoc->base.bind_addr.port);
> > +       u32 addr;
> > +
> > +       if (paddr->sa.sa_family == AF_INET6)
> > +               addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > +       else
> > +               addr = paddr->v4.sin_addr.s_addr;
> > +
> > +       return  jhash_3words(addr, ((__u32)paddr->v4.sin_port) << 16 |
> > +                            (__force __u32)lport, net_hash_mix(net), seed);
> > +}
> > +
> > +static inline u32 sctp_hash_key(const void *data, u32 len, u32 seed)
> > +{
> > +       const struct sctp_hash_cmp_arg *x = data;
> > +       const union sctp_addr *paddr = x->paddr;
> > +       const struct net *net = x->net;
> > +       u16 lport = x->laddr->v4.sin_port;
> > +       u32 addr;
> > +
> > +       if (paddr->sa.sa_family == AF_INET6)
> > +               addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > +       else
> > +               addr = paddr->v4.sin_addr.s_addr;
> > +
> > +       return  jhash_3words(addr, ((__u32)paddr->v4.sin_port) << 16 |
> > +                            (__force __u32)lport, net_hash_mix(net), seed);
> > +}
> 
> There's your problem.  You are allowing multiple objects to hash
> to the same value.  This is unacceptable with rhashtable because
> we use the hash chain length to determine if we're under attack
> and need to rehash.  This is the reason why you would see EBUSY
> during insertion.

Cool. Then I guess we don't really have an issue here. The case that
fails is an artificial load test which is virtually impossible to be hit
in real world, or at least I really hope so. The test, as in Xin's
attachment, will load more than 1600 IP addresses in one host (2 vCPU
during the test) and attempt to start an assoc from each of those using
the very same (lport, daddr, dport)-tuple.

Doing so is just unreasonable. Note that net is also hashed, so
even if we consider it could be 1600 containers, it is fine.

> So instead of inserting your objects as is, you should instead hash
> a list object that then links to all the objects that has the same
> hash key.

Now that it is clarified, I'm thinking we should just get ride of that
loop on EBUSY. No real reason to have extra code only to support an
artificial test. Agree?

Thanks,
Marcelo

  reply	other threads:[~2016-01-11 16:00 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-30 15:50 [PATCH net-next 0/5] sctp: use transport hashtable to replace association's with rhashtable Xin Long
2015-12-30 15:50 ` [PATCH net-next 1/5] sctp: add the rhashtable apis for sctp global transport hashtable Xin Long
2015-12-30 15:50   ` [PATCH net-next 2/5] sctp: apply rhashtable api to send/recv path Xin Long
2015-12-30 15:50     ` [PATCH net-next 3/5] sctp: apply rhashtable api to sctp procfs Xin Long
2015-12-30 15:50       ` [PATCH net-next 4/5] sctp: drop the old assoc hashtable of sctp Xin Long
2015-12-30 15:50         ` [PATCH net-next 5/5] sctp: remove the local_bh_disable/enable in sctp_endpoint_lookup_assoc Xin Long
2016-01-05 19:07     ` [PATCH net-next 2/5] sctp: apply rhashtable api to send/recv path Vlad Yasevich
2016-01-06 16:18       ` Xin Long
2016-01-06 17:42       ` mleitner
2016-01-11 15:00         ` Vlad Yasevich
2015-12-30 16:57   ` [PATCH net-next 1/5] sctp: add the rhashtable apis for sctp global transport hashtable Eric Dumazet
2015-12-30 17:50     ` David Miller
2016-01-11  9:32       ` Herbert Xu
2016-01-11 16:33         ` Marcelo Ricardo Leitner
2016-01-11 18:08           ` Vlad Yasevich
2016-01-11 18:19             ` Marcelo Ricardo Leitner
2015-12-30 17:41   ` Marcelo Ricardo Leitner
2016-01-05 10:10     ` Xin Long
2016-01-11  9:22       ` Herbert Xu
2016-01-05 18:38   ` Vlad Yasevich
2016-01-06 17:01     ` Xin Long
2016-01-06 18:19       ` Marcelo Ricardo Leitner
2016-01-07 17:23         ` Marcelo Ricardo Leitner
2016-01-07 20:28       ` Vlad Yasevich
2016-01-11  9:30   ` Herbert Xu
2016-01-11 16:00     ` mleitner [this message]
2016-01-11 17:20       ` Vlad Yasevich
2016-01-11 18:09         ` mleitner
2016-01-11 21:35           ` David Miller
2016-01-11 21:31         ` David Miller
2015-12-30 17:19 ` [PATCH net-next 0/5] sctp: use transport hashtable to replace association's with rhashtable Eric Dumazet
2015-12-30 17:32   ` Marcelo Ricardo Leitner
2015-12-30 19:11     ` Eric Dumazet
2015-12-30 20:44       ` David Miller
2015-12-30 21:57         ` Eric Dumazet
2015-12-30 22:29           ` Marcelo Ricardo Leitner
2015-12-30 17:52   ` David Miller
2015-12-30 19:03     ` Eric Dumazet
2015-12-30 20:40       ` David Miller
2016-01-04 22:30 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160111160039.GA6061@mrl.redhat.com \
    --to=mleitner@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vyasevic@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).