Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2407815rdb; Mon, 20 Nov 2023 09:56:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ1nht+qsrL3vnGdsjwm6y6HLq0ZQ4HmanKLa31gibMSSxLTjj5empd7WxlRZkinzEYKIx X-Received: by 2002:a05:6808:150d:b0:3b6:da98:4381 with SMTP id u13-20020a056808150d00b003b6da984381mr12757982oiw.33.1700502987353; Mon, 20 Nov 2023 09:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700502987; cv=none; d=google.com; s=arc-20160816; b=G6FBfqSFyDEZwIFTPZMOhfMWS42i0VmdOcVNEr/cwfU/wTh9YoUCUD306IMYB421FJ OEQDlDxI6MQ8/F9t7czt6aLcLEJc30z95x0PMNbgjG3qjVxG7Nl85ejFWt+TpXLs5hTJ U/55+yn+QAE6PcJlLGL4fLkkXSmNyRxePjlcQsKPs1C4e16wRtjkfjCMLlUGZgpcrMbS GLtJLhd7o+ImeFIBtbWumnO06sB2oGkbL08PigUWOHWq8hDqPydB8bawDNTnX6Jto3Fc YxLXLdfSmlehoLkF3DKv4rPNY8C3YY/esutoLNXXJzSs5LOHjZPPisTfRcBz68or8hvx uhDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xLJOaSiMX4j029aOHc7oApRw+KVD1nkO9hjnIeQA3ws=; fh=cECbmmbdlJ6lgVAvx+6QT1kGrdUwsUzK+M7vTYQhd/k=; b=gtdcXaLJti+VsLTf99ueSRx5WRfK4aZBBCFNM+AWprM+8oUbA68xv/n/JE9aDJ3Vqg yhFRy/H91jXf6+1Ana/9FDyeB8cbngNfVCcz8lQ7Fv1f1/lODfCVcXUcJnq/ju2erPdx COuCnnShGJQTpNZFidp1wMmJAlY/X7tVbBdKak3stFzmtJKBgpDseOz/nnKuD9Be1+gw fPdxIfP6u3uSBYdngfaiJ843Wg01RrsIBqLVRc+oEmBvQKAZkYy0nwK/CJhb5nvV3SlD +iTJyjvMXeqz9XTFYbrZqjhwkrwpeJyhNZU3OKFW37xR0sgmu00QTGg7NLRxmGNqFfCm PJ9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e9jj7Qax; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 36-20020a631464000000b005859c255ce8si8706013pgu.819.2023.11.20.09.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:56:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e9jj7Qax; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 332C98080D76; Mon, 20 Nov 2023 09:56:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233838AbjKTR4M (ORCPT + 99 others); Mon, 20 Nov 2023 12:56:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231557AbjKTR4L (ORCPT ); Mon, 20 Nov 2023 12:56:11 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DC3C3 for ; Mon, 20 Nov 2023 09:56:05 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-548ae9a5eeaso265a12.1 for ; Mon, 20 Nov 2023 09:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700502964; x=1701107764; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xLJOaSiMX4j029aOHc7oApRw+KVD1nkO9hjnIeQA3ws=; b=e9jj7QaxGuoKYKJ/edph7ZXHgkEd1MqMMRfIhh+50RWMP30+7dG23wkhLc0gI3gL2j bRlLvI7ubsRmP3mOJqGkZ9eQyrtjaQWU8UwawZbBxvI2gn1iymZOGxrrWTlWHuU0ycv5 Wkm+UYSGSlB5KqYbbsUupnF5M+wySXNuYLTM3/tZj0B21dqGBdrsllA90Bv/6dKmSPvG Me6nNg2X+D65Yjm7J0ksXPWJCOqobHtBI2JaC/u8MGXHV9sC8OWU8+zrvs5dej47ibxr RkXyMFOFAt8EHPCJeoJb7hBoi6P1I5PhOqrPJC771//Y6dlAMI/Ng33rtW/z1Xn0EdEu KNXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700502964; x=1701107764; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xLJOaSiMX4j029aOHc7oApRw+KVD1nkO9hjnIeQA3ws=; b=phix2cPcC1g4sw268ANqnMmFFeWArWwMtrVLPOi7JhrtLW/j4jprhpEh853cx1DN1L FSs+/WFOaEzfmEPPOcijy5OFYLQ/xXchBBdfK4i60wdUJlCp5kztty8jcc30+vPWZGrW psw1UVsfq2kcBM1isi9zdou2MpW2UdrZVjZmAUpg8tVQIfLnm8kRXs058jFlqv1fKkC9 jsVWTlIAXNDhe7f/DlHTYWvaCk5lzi2UmYEuaSx+YtflAeqH3MTl9j2ncWgY5ngywpnt +x7PgVClLUQhDUqVukLl9KWz2YR8JNXTl0vFAY8bRgS9BW3BTVpWp0sgYyQ61yB7F+wp doOw== X-Gm-Message-State: AOJu0YyfdLY5eZerd3Ych3OEBlbl9fdd87ufxL7yUct8BcfcUibtukmk Kp+OGKA12P7BADzvAFMPQXW8h7GWMOmj+I/kORk8Ea7pFbTMBBjnNe4q0g== X-Received: by 2002:a05:6402:3784:b0:544:24a8:ebd with SMTP id et4-20020a056402378400b0054424a80ebdmr272603edb.4.1700502963990; Mon, 20 Nov 2023 09:56:03 -0800 (PST) MIME-Version: 1.0 References: <20231115210509.481514-1-vschneid@redhat.com> <20231115210509.481514-2-vschneid@redhat.com> In-Reply-To: <20231115210509.481514-2-vschneid@redhat.com> From: Eric Dumazet Date: Mon, 20 Nov 2023 18:55:50 +0100 Message-ID: Subject: Re: [PATCH v2 1/2] tcp/dcpp: Un-pin tw_timer To: Valentin Schneider 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:56:24 -0800 (PST) On Wed, Nov 15, 2023 at 10:05=E2=80=AFPM Valentin Schneider wrote: > > The TCP timewait timer is proving to be problematic for setups where sche= duler > CPU isolation is achieved at runtime via cpusets (as opposed to staticall= y via > isolcpus=3Ddomains). > > What happens there is a CPU goes through tcp_time_wait(), arming the time= _wait > timer, then gets isolated. TCP_TIMEWAIT_LEN later, the timer fires, causi= ng > interference for the now-isolated CPU. This is conceptually similar to th= e issue > described in > e02b93124855 ("workqueue: Unbind kworkers before sending them to exit()= ") > > Keep softirqs disabled, but make the timer un-pinned and arm it *after* t= he > hashdance. > > This introduces the following (non-fatal) race: > > CPU0 CPU1 > allocates a tw > insert it in hash table > finds the TW and removes it > (timer cancel does nothing) > arms a TW timer, lasting > > This partially reverts > ed2e92394589 ("tcp/dccp: fix timewait races in timer handling") > and > ec94c2696f0b ("tcp/dccp: avoid one atomic operation for timewait hashda= nce") > > This also reinstores a comment from > ec94c2696f0b ("tcp/dccp: avoid one atomic operation for timewait hashda= nce") > as inet_twsk_hashdance() had a "Step 1" and "Step 3" comment, but the "St= ep > 2" had gone missing. > > Link: https://lore.kernel.org/all/ZPhpfMjSiHVjQkTk@localhost.localdomain/ > Signed-off-by: Valentin Schneider > --- > net/dccp/minisocks.c | 16 +++++++--------- > net/ipv4/inet_timewait_sock.c | 20 +++++++++++++++----- > net/ipv4/tcp_minisocks.c | 16 +++++++--------- > 3 files changed, 29 insertions(+), 23 deletions(-) > > diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c > index 64d805b27adde..2f0fad4255e36 100644 > --- a/net/dccp/minisocks.c > +++ b/net/dccp/minisocks.c > @@ -53,16 +53,14 @@ void dccp_time_wait(struct sock *sk, int state, int t= imeo) > if (state =3D=3D DCCP_TIME_WAIT) > timeo =3D DCCP_TIMEWAIT_LEN; > > - /* tw_timer is pinned, so we need to make sure BH are dis= abled > - * in following section, otherwise timer handler could ru= n before > - * we complete the initialization. > - */ > - local_bh_disable(); > - inet_twsk_schedule(tw, timeo); > - /* Linkage updates. > - * Note that access to tw after this point is illegal. > - */ > + local_bh_disable(); > + > + // Linkage updates > inet_twsk_hashdance(tw, sk, &dccp_hashinfo); > + inet_twsk_schedule(tw, timeo); We could arm a timer there, while another thread/cpu found the TW in the ehash table. > + // Access to tw after this point is illegal. > + inet_twsk_put(tw); This would eventually call inet_twsk_free() while the timer is armed. I think more work is needed. Perhaps make sure that a live timer owns a reference on tw->tw_refcnt (This is not the case atm)