From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934589AbcI0PqA (ORCPT ); Tue, 27 Sep 2016 11:46:00 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33072 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934052AbcI0Ppo (ORCPT ); Tue, 27 Sep 2016 11:45:44 -0400 Date: Tue, 27 Sep 2016 18:45:40 +0300 From: Cyrill Gorcunov To: Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, David Miller , kuznet@ms2.inr.ac.ru, jmorris@namei.org, yoshfuji@linux-ipv6.org, kaber@trash.net, avagin@openvz.org, stephen@networkplumber.org Subject: Re: [PATCH v4] net: ip, diag -- Add diag interface for raw sockets Message-ID: <20160927154540.GO1876@uranus.lan> References: <20160927150831.GN1876@uranus.lan> <1474990799.28155.54.camel@edumazet-glaptop3.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1474990799.28155.54.camel@edumazet-glaptop3.roam.corp.google.com> User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 27, 2016 at 08:39:59AM -0700, Eric Dumazet wrote: ... > > + } > > + if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) > > + sk = NULL; > > Minor detail, but note that raw sockets do not use rcu (yet) > > Since you have read_lock(&hashinfo->lock), no writer can suddenly change > sk->sk_refcnt to a zero value. > > Therefore, a mere "sock_hold(sk)" should be enough to get a reference on > the socket. > > Using atomic_inc_not_zero() also works, but might distract/confuse the > next guy trying to understand this code ;) Oh, I see. Thanks Eric! I'll update the patch (hopefully tonight) and send it out (need to finish urgent task atm).