From: Cong Wang <xiyou.wangcong@gmail.com>
To: Saeed Mahameed <saeed@kernel.org>
Cc: netdev@vger.kernel.org, g.nault@alphalink.fr,
Cong Wang <cong.wang@bytedance.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
Jakub Sitnicki <jakub@cloudflare.com>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [Patch net 1/2] l2tp: convert l2tp_tunnel_list to idr
Date: Sat, 7 Jan 2023 11:48:15 -0800 [thread overview]
Message-ID: <Y7nMf2TuV8GS8xII@pop-os.localdomain> (raw)
In-Reply-To: <Y7m5AKECbfk0Mq0K@x130>
On Sat, Jan 07, 2023 at 10:25:04AM -0800, Saeed Mahameed wrote:
> On 05 Jan 11:13, Cong Wang wrote:
> > From: Cong Wang <cong.wang@bytedance.com>
> >
> > l2tp uses l2tp_tunnel_list to track all registered tunnels and
> > to allocate tunnel ID's. IDR can do the same job.
> >
> > More importantly, with IDR we can hold the ID before a successful
> > registration so that we don't need to worry about late error
> > hanlding, it is not easy to rollback socket changes.
> >
> > This is a preparation for the following fix.
> >
> > Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > Cc: Guillaume Nault <g.nault@alphalink.fr>
> > Cc: Jakub Sitnicki <jakub@cloudflare.com>
> > Cc: Eric Dumazet <edumazet@google.com>
> > Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> > ---
> > net/l2tp/l2tp_core.c | 93 ++++++++++++++++++++++-------------------
> > net/l2tp/l2tp_core.h | 3 +-
> > net/l2tp/l2tp_netlink.c | 3 +-
> > net/l2tp/l2tp_ppp.c | 3 +-
> > 4 files changed, 57 insertions(+), 45 deletions(-)
> >
> > diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
> > index 9a1415fe3fa7..570249a91c6c 100644
> > --- a/net/l2tp/l2tp_core.c
> > +++ b/net/l2tp/l2tp_core.c
> > @@ -104,9 +104,9 @@ static struct workqueue_struct *l2tp_wq;
> > /* per-net private data for this module */
> > static unsigned int l2tp_net_id;
> > struct l2tp_net {
> > - struct list_head l2tp_tunnel_list;
> > - /* Lock for write access to l2tp_tunnel_list */
> > - spinlock_t l2tp_tunnel_list_lock;
> > + /* Lock for write access to l2tp_tunnel_idr */
> > + spinlock_t l2tp_tunnel_idr_lock;
> > + struct idr l2tp_tunnel_idr;
> > struct hlist_head l2tp_session_hlist[L2TP_HASH_SIZE_2];
> > /* Lock for write access to l2tp_session_hlist */
> > spinlock_t l2tp_session_hlist_lock;
> > @@ -208,13 +208,10 @@ struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id)
> > struct l2tp_tunnel *tunnel;
> >
> > rcu_read_lock_bh();
> > - list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) {
> > - if (tunnel->tunnel_id == tunnel_id &&
> > - refcount_inc_not_zero(&tunnel->ref_count)) {
> > - rcu_read_unlock_bh();
> > -
> > - return tunnel;
> > - }
> > + tunnel = idr_find(&pn->l2tp_tunnel_idr, tunnel_id);
> > + if (tunnel && refcount_inc_not_zero(&tunnel->ref_count)) {
> > + rcu_read_unlock_bh();
> > + return tunnel;
> > }
> > rcu_read_unlock_bh();
> >
> > @@ -224,13 +221,14 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_get);
> >
> > struct l2tp_tunnel *l2tp_tunnel_get_nth(const struct net *net, int nth)
> > {
> > - const struct l2tp_net *pn = l2tp_pernet(net);
> > + struct l2tp_net *pn = l2tp_pernet(net);
>
> Any reason to remove the const keyword ?
Yes, GCC complained about discarding const in idr_for_each_entry_ul().
Thanks.
next prev parent reply other threads:[~2023-01-07 19:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 19:13 [Patch net 0/2] l2tp: fix race conditions in l2tp_tunnel_register() Cong Wang
2023-01-05 19:13 ` [Patch net 1/2] l2tp: convert l2tp_tunnel_list to idr Cong Wang
2023-01-07 18:25 ` Saeed Mahameed
2023-01-07 19:48 ` Cong Wang [this message]
2023-01-07 19:48 ` Guillaume Nault
2023-01-09 9:55 ` Tom Parkin
2023-01-10 6:49 ` Cong Wang
2023-01-05 19:13 ` [Patch net 2/2] l2tp: close all race conditions in l2tp_tunnel_register() Cong Wang
2023-01-07 18:41 ` Saeed Mahameed
2023-01-07 19:52 ` Cong Wang
2023-01-10 1:36 ` Jakub Kicinski
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=Y7nMf2TuV8GS8xII@pop-os.localdomain \
--to=xiyou.wangcong@gmail.com \
--cc=cong.wang@bytedance.com \
--cc=edumazet@google.com \
--cc=g.nault@alphalink.fr \
--cc=jakub@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=saeed@kernel.org \
/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).