From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: Potential race in ip4_datagram_release_cb Date: Fri, 06 Jun 2014 10:56:04 -0700 Message-ID: <1402077364.3645.310.camel@edumazet-glaptop2.roam.corp.google.com> References: <1402059375.3645.284.camel@edumazet-glaptop2.roam.corp.google.com> <1402071367.3645.305.camel@edumazet-glaptop2.roam.corp.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Alexey Preobrazhensky , "netdev@vger.kernel.org" , Kostya Serebryany , Dmitry Vyukov , Lars Bull , Eric Dumazet , Bruce Curtis , Maciej =?UTF-8?Q?=C5=BBenczykowski?= , dormando To: Alexei Starovoitov Return-path: Received: from mail-pd0-f182.google.com ([209.85.192.182]:43435 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751108AbaFFR4H (ORCPT ); Fri, 6 Jun 2014 13:56:07 -0400 Received: by mail-pd0-f182.google.com with SMTP id r10so2719769pdi.27 for ; Fri, 06 Jun 2014 10:56:06 -0700 (PDT) In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Fri, 2014-06-06 at 10:44 -0700, Alexei Starovoitov wrote: > On Fri, Jun 6, 2014 at 9:16 AM, Eric Dumazet wrote: > > We should either : > > > > 1) use xchg() and no lock at all to change sk_dst_cache, as we did for > > sk_rx_dst ( cf udp_sk_rx_dst_set() ) > > > > 2) No longer use sk_dst_lock, and always use the socket lock > > (sk->sk_lock.slock) instead. > > Probably needs some combination of both. I do not think so. If we use xchg(), then we do not need anything else. If we use a spinlock, then xchg() seems useless. Any combination is buggy. In the past, UDP transmit was holding socket lock, but we added a lockless path, and I suppose more people use a UDP socket from different threads. Then, Steffen added the ip4_datagram_release_cb() thing, increasing the chance of mixing both 'protections'. Setting sk_dst_cache should hardly be a hot path.