All of lore.kernel.org
 help / color / mirror / Atom feed
* sock_hold and sock_put
@ 2015-06-24  9:17 ratheesh kannoth
  2015-06-24 12:46 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: ratheesh kannoth @ 2015-06-24  9:17 UTC (permalink / raw)
  To: netdev, linux-newbie

Hi list,

There is a comment on sock_hold() function -

561 /* Grab socket reference count. This operation is valid only
562    when sk is ALREADY grabbed f.e. it is found in hash table
563    or a list and the lookup is made under lock preventing hash table
564    modifications.
565  */


But i could see instances of sock hold() in kernel  without any locks.


How  the race between sock_hold() and sock_put() is prevented in  smp ?

note: I would like to use sock_hold() and sock_put() in
netdev_notifier chain call back functions.

-Ratheesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sock_hold and sock_put
  2015-06-24  9:17 sock_hold and sock_put ratheesh kannoth
@ 2015-06-24 12:46 ` Eric Dumazet
  2015-06-24 14:14   ` ratheesh kannoth
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2015-06-24 12:46 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: netdev, linux-newbie

On Wed, 2015-06-24 at 14:47 +0530, ratheesh kannoth wrote:
> Hi list,
> 
> There is a comment on sock_hold() function -
> 
> 561 /* Grab socket reference count. This operation is valid only
> 562    when sk is ALREADY grabbed f.e. it is found in hash table
> 563    or a list and the lookup is made under lock preventing hash table
> 564    modifications.
> 565  */
> 
> 
> But i could see instances of sock hold() in kernel  without any locks.
> 
> 
> How  the race between sock_hold() and sock_put() is prevented in  smp ?
> 
> note: I would like to use sock_hold() and sock_put() in
> netdev_notifier chain call back functions.

You misunderstood the comment.

Comment only stated that sock_hold() must be used in contexts where
caller owns a reference (and will eventually release it later with
sock_put().

There is nothing about having a lock here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sock_hold and sock_put
  2015-06-24 12:46 ` Eric Dumazet
@ 2015-06-24 14:14   ` ratheesh kannoth
  2015-06-24 15:26     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: ratheesh kannoth @ 2015-06-24 14:14 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev, linux-newbie

On Wed, Jun 24, 2015 at 6:16 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> You misunderstood the comment.
>
> Comment only stated that sock_hold() must be used in contexts where
> caller owns a reference (and will eventually release it later with
> sock_put().
>
> There is nothing about having a lock here.

Thanks. I think, i did not put the question right.

I understood the comment perfectly. Suppose i need to use the
sock_hold in some callbacks ( say netdev_notifier chain callback)
function. How can i gurantee race won't happen at the point where i
call sock_hold().
 If i put the question  in another way - say kernel is doing a
sock_put() on a socket, and at the same time  the   netdev_callback
function( that i implemented ) is called on another core ( in smp
machine ). and the  callback is  holding (sock_hold()) on the same
sock.

Thanks,
Ratheesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sock_hold and sock_put
  2015-06-24 14:14   ` ratheesh kannoth
@ 2015-06-24 15:26     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2015-06-24 15:26 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: netdev, linux-newbie

On Wed, 2015-06-24 at 19:44 +0530, ratheesh kannoth wrote:
> On Wed, Jun 24, 2015 at 6:16 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > You misunderstood the comment.
> >
> > Comment only stated that sock_hold() must be used in contexts where
> > caller owns a reference (and will eventually release it later with
> > sock_put().
> >
> > There is nothing about having a lock here.
> 
> Thanks. I think, i did not put the question right.
> 
> I understood the comment perfectly. Suppose i need to use the
> sock_hold in some callbacks ( say netdev_notifier chain callback)
> function. How can i gurantee race won't happen at the point where i
> call sock_hold().
>  If i put the question  in another way - say kernel is doing a
> sock_put() on a socket, and at the same time  the   netdev_callback
> function( that i implemented ) is called on another core ( in smp
> machine ). and the  callback is  holding (sock_hold()) on the same
> sock.

You can not possibly use sock_hold() from the callback, unless you
already took a reference on the socket _before_ callback was called, to
make sure socket would not disappear.

Its hard to understand what you try to do here.

If you worry because socket would disappear when "kernel is doing a
sock_put()", then it means you did not take the needed extra reference
to make sure callback would access a valid socket.


--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-24 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24  9:17 sock_hold and sock_put ratheesh kannoth
2015-06-24 12:46 ` Eric Dumazet
2015-06-24 14:14   ` ratheesh kannoth
2015-06-24 15:26     ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.