Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp44981rwi; Thu, 3 Nov 2022 17:03:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7acqOuzvPblqWqBefNXK5RodPM9DMI+BixJb6Al4dd9K1JjLgC9NC0PThKCl+sBQLV3uVE X-Received: by 2002:a05:6402:1145:b0:464:ac8:c57e with SMTP id g5-20020a056402114500b004640ac8c57emr10531491edw.58.1667520212264; Thu, 03 Nov 2022 17:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667520212; cv=none; d=google.com; s=arc-20160816; b=vw4VKhlKSyMZEMGMoRXORuuH+f6tanTA5fm3L93fPybWr9O/MjCaTbfWMDe2Tk4Eol 4bWLruCrx/Ufbbd690V2/4Ft9EwaY7tvI/XigsYbNmSP3KYohN+qZw0DueVEipIpL1X6 t4TcUzRsHG+ry7YuieM/Z11wiogDm73HqyPHWEygx9qBxAUEH3B98daNwPxfKp3Y7HfS Ks/gxYWAv7R7tVO8/fPOL2nSdswqLyUXL8OMUwZIfwYn2ArZkg0RnFbM4ghEolry64Nz 36zUqzJBS4CFSrJtnv69uI9WQbCpjxPoYfXXv8GvUWFMLvb0nWRnF9lJ7TkwpcOg6Qm0 4hvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OIWN7urgPvg7gWQ/2jmCuNIcCwluarihUklEPGyHjcg=; b=oQuWIiQFIBE0eSc20ZNSbGeHWgXQrDw2Pm5HzGkYQCl4rc8dmdURIekOT1Sr+pxKxj pMLxPGYyuT28hUnSJuGcQ5XyJuitDW0OwC2tjjxupAZ/WYMPap9a+jnY6mVfLmtFw6j8 Axaa7me1qKOUy5TpX0hRUO09ei0fkosnMjWy+fFvdKxMq1w1qkDH4UNJQEFpnDtWdEUH R0+p3GAXx3ucUFxSGXqC/9PNqM7Rh/XbKxludhtMbHrrjEwPsxG24szo8QpDcD23KRc+ 0ZI3BHJjU5l+moYZvX7xrxSee/5D0YsBlOAmDN0LLIPj8A2jR39dhZTWaurEmQUDmqUj 3dlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WfZQ7T5J; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a508a86000000b004615937b174si2696848edj.480.2022.11.03.17.01.51; Thu, 03 Nov 2022 17:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WfZQ7T5J; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbiKDAAg (ORCPT + 67 others); Thu, 3 Nov 2022 20:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbiKDAAf (ORCPT ); Thu, 3 Nov 2022 20:00:35 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228102229C for ; Thu, 3 Nov 2022 17:00:33 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-3691e040abaso30261397b3.9 for ; Thu, 03 Nov 2022 17:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OIWN7urgPvg7gWQ/2jmCuNIcCwluarihUklEPGyHjcg=; b=WfZQ7T5J19AGsPaNUJuOsP0Km5Ixqe3g2OjzWlZ48O9n++G6HOElr/NHRpLA9fDnwr zjRaF+oN7J52K4Hkt1QfKpCQB5Wz5OV6RrsZAgAUs0tkU6h0aV7cYd6yEHz8xOWTUUaE nTwx3sfZXExTHFKflgZ0kHbhOyWH5xYa/4o8baHcab29Hq9pAX7cOlT1SrWXDbt87QYk qqJgjVZVqEHQO2qDmqBHDnF4n6wAmtRz5tmd/UsTP0SD10mD6uXXRAlwFdt5yYXaLs84 Q6NGteraqshFTYF08psP5WYnjWqJg/XADvug0NuClQLOveJFe7i203jnVfhv2iws1QsI 5poA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=OIWN7urgPvg7gWQ/2jmCuNIcCwluarihUklEPGyHjcg=; b=bhDCffbHt1Ne4Mr7MKvYi77WQJsIeh5W1kbT3GpEoczIFM6FnDXdIUQwUtsgB7uruN vxmB+KCP6oLDuVGGkiE4LSlOKx9X/F6bb3+glLEN7nJeiiJ66z1gtKHPSOmxvMZ12d1W G8y8dbemDC03ogFKaxIfMw2ARVR/qLIvvPcdK1nDYjUAykL84zfQGnp25uFx25Qf7bXP DAkjzIF2+xmpdBiBMCympKmsXbh8TRnfDaej/FK1S4ESjOyZXlMIeVKlOz8rWZQe2yZP rlXaXM91+4c2WfcOs/H0KPkLQzprNBxXZB+y5R22ds6lRFElmG9RJcQbQxGxt3L1qKnN dG9g== X-Gm-Message-State: ACrzQf1FYDbCGuHTR7LQG0iFUYA3eTlEjBkq494wwL4eUpMoeYZY+gjP PQwd50neHR2/1THhA+BEp5I1UWhBtZihtcaiXkZevw== X-Received: by 2002:a81:6084:0:b0:370:10fa:c4ff with SMTP id u126-20020a816084000000b0037010fac4ffmr32397029ywb.255.1667520032026; Thu, 03 Nov 2022 17:00:32 -0700 (PDT) MIME-Version: 1.0 References: <20221027150525.753064657@goodmis.org> <20221027150928.780676863@goodmis.org> <20221027155513.60b211e2@gandalf.local.home> <20221027163453.383bbf8e@gandalf.local.home> <20221027170720.31497319@gandalf.local.home> <20221027183511.66b058c4@gandalf.local.home> <20221028183149.2882a29b@gandalf.local.home> <20221028154617.3c63ba68@kernel.org> <27a6a587fee5e9172e41acd16ae1bc1f556fdbd7.camel@redhat.com> <20221103175123.744d0f37@rorschach.local.home> In-Reply-To: <20221103175123.744d0f37@rorschach.local.home> From: Eric Dumazet Date: Thu, 3 Nov 2022 17:00:20 -0700 Message-ID: Subject: Re: [RFC][PATCH v2 19/31] timers: net: Use del_timer_shutdown() before freeing timer To: Steven Rostedt Cc: Paolo Abeni , Jakub Kicinski , Linus Torvalds , linux-kernel@vger.kernel.org, Thomas Gleixner , Stephen Boyd , Guenter Roeck , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Mirko Lindner , Stephen Hemminger , Martin KaFai Lau , Alexei Starovoitov , Kuniyuki Iwashima , Pavel Begunkov , Menglong Dong , linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, bridge@lists.linux-foundation.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, lvs-devel@vger.kernel.org, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, tipc-discussion@lists.sourceforge.net Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Thu, Nov 3, 2022 at 2:51 PM Steven Rostedt wrote: > > On Sun, 30 Oct 2022 18:22:03 +0100 > Paolo Abeni wrote: > > > On the positive side, I think converting the sk_stop_timer in > > inet_csk_clear_xmit_timers() should be safe and should cover the issue > > reported by Guenter > > Would something like this be OK? > > [ Note, talking with Thomas Gleixner, we agreed that we are changing the > name to: time_shutdown_sync() and timer_shutdown() (no wait version). > I'll be posting new patches soon. ] > > -- Steve > > diff --git a/include/net/sock.h b/include/net/sock.h > index 22f8bab583dd..0ef58697d4e5 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -2439,6 +2439,8 @@ void sk_stop_timer(struct sock *sk, struct timer_list *timer); > > void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer); > > +void sk_shutdown_timer(struct sock *sk, struct timer_list *timer); > + > int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue, > struct sk_buff *skb, unsigned int flags, > void (*destructor)(struct sock *sk, > diff --git a/net/core/sock.c b/net/core/sock.c > index a3ba0358c77c..82124862b594 100644 > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -3357,6 +3357,13 @@ void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer) > } > EXPORT_SYMBOL(sk_stop_timer_sync); > > +void sk_shutdown_timer(struct sock *sk, struct timer_list* timer) > +{ > + if (timer_shutdown(timer)) > + __sock_put(sk); > +} > +EXPORT_SYMBOL(sk_shutdown_timer); > + > void sock_init_data(struct socket *sock, struct sock *sk) > { > sk_init_common(sk); > diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c > index 5e70228c5ae9..71f398f51958 100644 > --- a/net/ipv4/inet_connection_sock.c > +++ b/net/ipv4/inet_connection_sock.c > @@ -722,15 +722,15 @@ void inet_csk_clear_xmit_timers(struct sock *sk) > > icsk->icsk_pending = icsk->icsk_ack.pending = 0; > > - sk_stop_timer(sk, &icsk->icsk_retransmit_timer); > - sk_stop_timer(sk, &icsk->icsk_delack_timer); > - sk_stop_timer(sk, &sk->sk_timer); > + sk_shutdown_timer(sk, &icsk->icsk_retransmit_timer); > + sk_shutdown_timer(sk, &icsk->icsk_delack_timer); > + sk_shutdown_timer(sk, &sk->sk_timer); > } > EXPORT_SYMBOL(inet_csk_clear_xmit_timers); inet_csk_clear_xmit_timers() can be called multiple times during TCP socket lifetime. (See tcp_disconnect(), which can be followed by another connect() ... and loop) Maybe add a second parameter, or add a new inet_csk_shutdown_xmit_timers() only called from tcp_v4_destroy_sock() ? > > void inet_csk_delete_keepalive_timer(struct sock *sk) > { > - sk_stop_timer(sk, &sk->sk_timer); > + sk_shutdown_timer(sk, &sk->sk_timer); SO_KEEPALIVE can be called multiple times in a TCP socket lifetime, on/off/on/off/... I suggest leaving sk_stop_timer() here. Eventually inet_csk_clear_xmit_timers( sk, destroy=true) (or inet_csk_shutdown_xmit_timers(()) will be called before the socket is destroyed.