netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guillaume Nault <gnault@redhat.com>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
	kuba@kernel.org, mkubecek@suse.cz, netdev@vger.kernel.org,
	pabeni@redhat.com
Subject: Re: [PATCH net-next v2] tcp: Dump bound-only sockets in inet_diag.
Date: Mon, 27 Nov 2023 18:26:05 +0100	[thread overview]
Message-ID: <ZWTRLVuFF+575qrI@debian> (raw)
In-Reply-To: <20231125013942.80997-1-kuniyu@amazon.com>

On Fri, Nov 24, 2023 at 05:39:42PM -0800, Kuniyuki Iwashima wrote:
> > +			spin_lock_bh(&ibb->lock);
> > +			inet_bind_bucket_for_each(tb2, &ibb->chain) {
> > +				if (!net_eq(ib2_net(tb2), net))
> > +					continue;
> > +
> > +				sk_for_each_bound_bhash2(sk, &tb2->owners) {
> > +					struct inet_sock *inet = inet_sk(sk);
> > +
> > +					if (num < s_num)
> > +						goto next_bind;
> > +
> > +					if (sk->sk_state != TCP_CLOSE ||
> > +					    !inet->inet_num)
> > +						goto next_bind;
> > +
> > +					if (r->sdiag_family != AF_UNSPEC &&
> > +					    r->sdiag_family != sk->sk_family)
> > +						goto next_bind;
> > +
> > +					if (!inet_diag_bc_sk(bc, sk))
> > +						goto next_bind;
> > +
> > +					if (!refcount_inc_not_zero(&sk->sk_refcnt))
> > +						goto next_bind;
> 
> I guess this is copied from the ehash code below, but could
> refcount_inc_not_zero() fail for bhash2 under spin_lock_bh() ?

My understanding is that it can't fail, but I prefered to keep the test
to be on the safe side.

I can post a v3 using a plain sock_hold(), if you prefer.

> > +
> > +					num_arr[accum] = num;
> > +					sk_arr[accum] = sk;
> > +					if (++accum == SKARR_SZ)
> > +						goto pause_bind_walk;
> > +next_bind:
> > +					num++;
> > +				}
> > +			}


  reply	other threads:[~2023-11-27 17:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 23:11 [PATCH net-next v2] tcp: Dump bound-only sockets in inet_diag Guillaume Nault
2023-11-25  1:39 ` Kuniyuki Iwashima
2023-11-27 17:26   ` Guillaume Nault [this message]
2023-11-27 17:56     ` Kuniyuki Iwashima
2023-11-28  1:13       ` Guillaume Nault
2023-11-28 10:14 ` Eric Dumazet
2023-11-28 22:18   ` Guillaume Nault
2023-11-29 15:39     ` Eric Dumazet
2023-11-29 17:52       ` Guillaume Nault

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=ZWTRLVuFF+575qrI@debian \
    --to=gnault@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@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).