lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 30 Jul 2019 20:09:33 +0000
From:   Saeed Mahameed <saeedm@...lanox.com>
To:     "willemdebruijn.kernel@...il.com" <willemdebruijn.kernel@...il.com>
CC:     Roi Dayan <roid@...lanox.com>,
        "davem@...emloft.net" <davem@...emloft.net>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        Vlad Buslov <vladbu@...lanox.com>,
        Jianbo Liu <jianbol@...lanox.com>
Subject: Re: [net-next 08/13] net/mlx5e: Protect tc flows hashtable with rcu

On Tue, 2019-07-30 at 12:37 -0400, Willem de Bruijn wrote:
> On Tue, Jul 30, 2019 at 12:16 PM Willem de Bruijn
> <willemdebruijn.kernel@...il.com> wrote:
> > On Mon, Jul 29, 2019 at 7:50 PM Saeed Mahameed <saeedm@...lanox.com
> > > wrote:
> > > From: Vlad Buslov <vladbu@...lanox.com>
> > > 
> > > In order to remove dependency on rtnl lock, access to tc flows
> > > hashtable
> > > must be explicitly protected from concurrent flows removal.
> > > 
> > > Extend tc flow structure with rcu to allow concurrent parallel
> > > access. Use
> > > rcu read lock to safely lookup flow in tc flows hash table, and
> > > take
> > > reference to it. Use rcu free for flow deletion to accommodate
> > > concurrent
> > > stats requests.
> > > 
> > > Add new DELETED flow flag. Imlement new flow_flag_test_and_set()
> > > helper
> > > that is used to set a flag and return its previous value. Use it
> > > to
> > > atomically set the flag in mlx5e_delete_flower() to guarantee
> > > that flow can
> > > only be deleted once, even when same flow is deleted concurrently
> > > by
> > > multiple tasks.
> > > 
> > > Signed-off-by: Vlad Buslov <vladbu@...lanox.com>
> > > Reviewed-by: Jianbo Liu <jianbol@...lanox.com>
> > > Reviewed-by: Roi Dayan <roid@...lanox.com>
> > > Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
> > > ---
> > > @@ -3492,16 +3507,32 @@ int mlx5e_delete_flower(struct net_device
> > > *dev, struct mlx5e_priv *priv,
> > >  {
> > >         struct rhashtable *tc_ht = get_tc_ht(priv, flags);
> > >         struct mlx5e_tc_flow *flow;
> > > +       int err;
> > > 
> > > +       rcu_read_lock();
> > >         flow = rhashtable_lookup_fast(tc_ht, &f->cookie,
> > > tc_ht_params);
> > > -       if (!flow || !same_flow_direction(flow, flags))
> > > -               return -EINVAL;
> > > +       if (!flow || !same_flow_direction(flow, flags)) {
> > > +               err = -EINVAL;
> > > +               goto errout;
> > > +       }
> > > 
> > > +       /* Only delete the flow if it doesn't have
> > > MLX5E_TC_FLOW_DELETED flag
> > > +        * set.
> > > +        */
> > > +       if (flow_flag_test_and_set(flow, DELETED)) {
> > > +               err = -EINVAL;
> > > +               goto errout;
> > > +       }
> > >         rhashtable_remove_fast(tc_ht, &flow->node, tc_ht_params);
> > > +       rcu_read_unlock();
> > > 
> > >         mlx5e_flow_put(priv, flow);
> > 
> > Dereferencing flow outside rcu readside critical section? Does a
> > build
> > with lockdep not complain?
> 
> Eh no, it won't. The surprising part to me was to use a readside
> critical section when performing a write action on an RCU ptr. The
> DELETED flag ensures that multiple writers will not compete to call
> rhashtable_remove_fast. rcu_read_lock is a common pattern to do
> rhashtable lookup + delete.
> 

correct.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ