From: Steffen Klassert <steffen.klassert@secunet.com>
To: Julian Anastasov <ja@ssi.bg>
Cc: David Miller <davem@davemloft.net>,
"Yurij M. Plotnikov" <Yurij.Plotnikov@oktetlabs.ru>,
netdev@vger.kernel.org
Subject: Re: [PATCH 1/2] ipv4: Invalidate the socket cached route on pmtu events if possible
Date: Tue, 22 Jan 2013 09:42:23 +0100 [thread overview]
Message-ID: <20130122084223.GC9147@secunet.com> (raw)
In-Reply-To: <alpine.LFD.2.00.1301212245170.1886@ja.ssi.bg>
On Mon, Jan 21, 2013 at 11:18:27PM +0200, Julian Anastasov wrote:
>
> Hello,
>
> On Mon, 21 Jan 2013, Steffen Klassert wrote:
>
> > +{
> > + const struct iphdr *iph = (const struct iphdr *) skb->data;
> > + struct flowi4 fl4;
> > + struct rtable *rt;
> > + struct dst_entry *dst;
> > +
> > + bh_lock_sock(sk);
> > + rt = (struct rtable *) __sk_dst_get(sk);
>
> I just saw another problem, sorry that
> I missed it the first time. Here __sk_dst_get
> does not get reference...
>
Somehow I thought that I can reuse the the refcount
from the socket, but __sk_dst_set() will release it
when we continue to use the same route.
> > +
> > + if (sock_owned_by_user(sk) || !rt) {
> > + __ipv4_sk_update_pmtu(skb, sk, mtu);
> > + goto out;
> > + }
> > +
> > + __build_flow_key(&fl4, sk, iph, 0, 0, 0, 0, 0);
> > +
> > + if (!__sk_dst_check(sk, 0)) {
> > + rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
> > + if (IS_ERR(rt))
> > + goto out;
>
> but here rt->dst comes with reference.
>
> > + }
>
> May be here we can use 'else dst_hold(&rt->dst);' ?
> It is needed for __sk_dst_set.
>
> > +
> > + __ip_rt_update_pmtu((struct rtable *) rt->dst.path, &fl4, mtu);
> > +
> > + dst = dst_check(&rt->dst, 0);
> > + if (!dst) {
>
> dst_release(&rt->dst);
>
> > + rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
> > + if (IS_ERR(rt))
> > + goto out;
> > +
> > + dst = &rt->dst;
>
> Remove above line...
>
> > + }
> > +
>
> and use here __sk_dst_set(sk, &rt->dst) instead:
>
> > + __sk_dst_set(sk, dst);
>
> Another variant is to remember with flag 'new_rt'
> that we should call __sk_dst_set, eg. when rt comes from
> ip_route_output_flow. By this way we can avoid some of
> the dst_hold/dst_release calls if sk_dst_cache is not
> changed. IIRC, according to sk_dst_check, dst_check can
> not return different dst from the ->check method.
>
With this variant, we also need to check the new_rt flag
before we call the dst_release() function you mentioned
above, right?
I think we should avoid refcounts whenever we can,
so I prefer this variant. I'll do a patch.
Thanks!
next prev parent reply other threads:[~2013-01-22 8:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-21 11:59 [PATCH 1/2] ipv4: Invalidate the socket cached route on pmtu events if possible Steffen Klassert
2013-01-21 12:00 ` [PATCH 2/2] ipv4: Add a socket release callback for datagram sockets Steffen Klassert
2013-01-21 19:18 ` David Miller
2013-01-21 19:18 ` [PATCH 1/2] ipv4: Invalidate the socket cached route on pmtu events if possible David Miller
2013-01-21 21:18 ` Julian Anastasov
2013-01-22 8:42 ` Steffen Klassert [this message]
2013-01-22 9:04 ` Julian Anastasov
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=20130122084223.GC9147@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=Yurij.Plotnikov@oktetlabs.ru \
--cc=davem@davemloft.net \
--cc=ja@ssi.bg \
--cc=netdev@vger.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).