Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2385674rdb; Fri, 8 Dec 2023 06:47:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF3lMOpFqEWgdALznfiz0+iUSxcma0qdXAttWOuBg/LweLHMpKd+GbrJPf1XFIAk6i8Scu X-Received: by 2002:a17:902:e54e:b0:1d0:70f7:ba02 with SMTP id n14-20020a170902e54e00b001d070f7ba02mr111536plf.92.1702046873123; Fri, 08 Dec 2023 06:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702046873; cv=none; d=google.com; s=arc-20160816; b=QX+GNKIGo8kzu9CPC+HgssvVDqToPDHZQZbbLXGQxMEgxO+MIFPqwd8PxKXfPzBu6V kh4ezAfhSrXKJO5vc3SvlCWLExWmtAU3epvB6e8vmj5+t4crQv5XaI3FBaPICD4x5hTi dAPXDIoNbEXLnr2hmcYAv+hxT72oWvvHsOKS+F4HJpcXnnn7aWJC+aU0jrceVRHVWQHX 3dnwxkBR3M9IAf1aTQCLiGKytXam3ccgxvYjzwmGj4nIxBsMQVnT16+AwsgUlJcGEoNc 4LIshsyddMGSPneNUngzNYrZaQXnbYBkrDkU4RQXsX/1hP6HO9H4Ds6BLm735femyUnA idgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=7OyK/hwOtOLcmVz6X7PhUXWLJeC6+muyilj4AjJlSQo=; fh=nUIIZ96eGUJlC/ERdRqSUO1EdlkzLZ4tDkCqjMGbnss=; b=rr+YGqxFEMaJTlMiLLR3EIE83RU07N6EcoTQKd2KktJxAdY8zOL9Mq3EOBpysOZawt TNOOPUE6i8SdquZkgygoBNmrfqWeMdUgajyx1MM/LAb2Q5HMO70HtPXkVFRhorRji0v9 lp8tywTrIQqfNQieGuaueyeuQ71UfDmPmNQYDvUuwQ2LcXr5GYywhRK1Vp7S1vBo4i4H eCD1Iey+brK/n9Qbh3Bhq4kogqibYG+Xzkh23Uq1yYx1aVlPcjcXOd2Y+/HZNuzFaCq9 51qsABAHFo3z+Evkw2XPxmXtUMN9MsfW2EaltTFpZvoUQ8/sBeKZpNzYM0HtlH+hLPlp QBHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hJIJdovF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id iz22-20020a170902ef9600b001d0050e2452si1673630plb.45.2023.12.08.06.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 06:47:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hJIJdovF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E7411837B889; Fri, 8 Dec 2023 06:47:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573995AbjLHOrh (ORCPT + 99 others); Fri, 8 Dec 2023 09:47:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573984AbjLHOrg (ORCPT ); Fri, 8 Dec 2023 09:47:36 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97820173B for ; Fri, 8 Dec 2023 06:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702046861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7OyK/hwOtOLcmVz6X7PhUXWLJeC6+muyilj4AjJlSQo=; b=hJIJdovFLgLc/zQXkFoX6CRYHKWhdn2Um3JAHdYus0E+3SPqNRxGpLbuq9XZLZaJeMDum6 8ACeriA6rw4R/eziYr25N8F7ZPDTFwzX4hevHfEdyV0unG5FPaqZ4lIX4RbDmqyZaE93G9 RsZRgCbzzm3FC3knY1Xp1xAdDP5WqZY= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-jv1jmP0ZMqqAkEGbg_OjXQ-1; Fri, 08 Dec 2023 09:47:40 -0500 X-MC-Unique: jv1jmP0ZMqqAkEGbg_OjXQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-77f41dc15b7so182584485a.2 for ; Fri, 08 Dec 2023 06:47:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702046859; x=1702651659; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7OyK/hwOtOLcmVz6X7PhUXWLJeC6+muyilj4AjJlSQo=; b=N31/TGkod7eT8wxtbU0AhhHk5Dq4lL9tScjfI06oDn+0jTGwrrAC5MsONtT+VWxKTn /BygZNSfpUFXnwrZ6uyXSfYkXC0OjOQkxXKI0LJYswgUo5fA6gWp0s+58hZHvu34yx+t zknkia6CZEkqa4FHlFNWVbCpA67T7ZAumr2AEFaU0nwVk08pYAs8/mcrKHWMnvkaqGym qpRazuVmX5JYzVi2E57evdm4pM5TLf00xs3Vop8QlOtW8oqeqaWjygk69d3ErFqiAXXA 6Qv5nbs3F5cK6XgJpcoNq9EHw7U988RHElS8xiJhbRgVkiSKfPQb8HBXYl2ZOhAS+XyD 9P8w== X-Gm-Message-State: AOJu0Yy1TwD6UXxXAk6pJWNI/iV0MsF+Fz6IJJVQnCBp50dYYKro4Bf1 GGh+SfyrMf7+nLtCogOzIVj5tYAf558cueM5hUageM8XbrWyIrS0SHUr+F1hK1KQPpQpTQVdGUS 4AN9KIbzUagdtxFagdBBy0EXolLYpXEps X-Received: by 2002:a05:620a:12fc:b0:77f:9a0:4c0b with SMTP id f28-20020a05620a12fc00b0077f09a04c0bmr189732qkl.106.1702046859814; Fri, 08 Dec 2023 06:47:39 -0800 (PST) X-Received: by 2002:a05:620a:12fc:b0:77f:9a0:4c0b with SMTP id f28-20020a05620a12fc00b0077f09a04c0bmr189720qkl.106.1702046859556; Fri, 08 Dec 2023 06:47:39 -0800 (PST) Received: from vschneid-thinkpadt14sgen2i.remote.csb (213-44-141-166.abo.bbox.fr. [213.44.141.166]) by smtp.gmail.com with ESMTPSA id h6-20020a05620a13e600b0077f287b2393sm733803qkl.63.2023.12.08.06.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 06:47:38 -0800 (PST) From: Valentin Schneider To: Eric Dumazet Cc: dccp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Juri Lelli , Tomas Glozar , Sebastian Andrzej Siewior , Thomas Gleixner Subject: Re: [PATCH v2 1/2] tcp/dcpp: Un-pin tw_timer In-Reply-To: References: <20231115210509.481514-1-vschneid@redhat.com> <20231115210509.481514-2-vschneid@redhat.com> Date: Fri, 08 Dec 2023 15:47:35 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=0.6 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 08 Dec 2023 06:47:51 -0800 (PST) On 23/11/23 17:32, Eric Dumazet wrote: > Again, I think you missed some details. > > I am OOO for a few days, I do not have time to elaborate. > > You will need to properly track active timer by elevating > tw->tw_refcnt, or I guarantee something wrong will happen. I apologize if I'm being thick skulled, I've been staring at the code and tracing on live systems and I still can't see the issue with refcounts. The patch has the hashdance set the refcount to 4: * - one reference for bhash chain. * - one reference for ehash chain. * - one reference for timer. * - one reference for ourself (our caller will release it). AFAICT, finding & using the socket via the ehash table comes with a refcount_inc (e.g. __inet_lookup_established()). Worst case, the lookup happens after programming the timer, and we get a inet_twsk_deschedule_put(). This reduces the refcount by: 3 via inet_twsk_kill(): 1 (sk_nulls_del_node_init_rcu()) 1 (inet_twsk_bind_unhash()) 1 (inet_twsk_put()) 1 via inet_twsk_put() IOW 4 total. So we can have: tcp_time_wait() inet_twsk_hashdance(); // refcount = 4 inet_twsk_schedule(); // timer armed tcp_v4_rcv() sk = __inet_lookup_skb(); // refcount = 5 (+1) inet_twsk_deschedule_put(inet_twsk(sk)); inet_twsk_kill(tw) // refcount = 2 (-3) inet_twsk_put(tw) // refcount = 1 (-1) inet_twsk_put(tw) // refcount = 0 (-1) __inet_hash_connect() can invoke inet_twsk_bind_unhash() by itself before calling inet_twsk_deschedule_put(), but that just means it won't be done by the latter, so the total refcount delta remains the same. Thinking about it differently, this would mean that currently (without the patch) another CPU can bring the refcount to 0 without disarming the timer, because the patch is making the initial value one higher. What am I missing?