From patchwork Tue Nov 15 20:28:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2927370wru; Tue, 15 Nov 2022 12:29:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf6xwn5sjaQIH+CcVHn2NHzHIQL/O38LlMxo4rn49+oASTrfX+1waRnIbHfqlv6hwwN5hFqe X-Received: by 2002:a17:90a:bf13:b0:209:8dc1:fdbd with SMTP id c19-20020a17090abf1300b002098dc1fdbdmr139829pjs.46.1668544156926; Tue, 15 Nov 2022 12:29:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544156; cv=none; d=google.com; s=arc-20160816; b=FUDe02hJl1Pj95BYAWDznW9utJ1qn+4BKQyutbBdZThqZdxZJ8+hp7ovvnt/Di58ge FzGUzrwhhFuh/G1PfZdMAYYBqPU4ZnExz7XbDupkTezK2JyDBAJSs8Fx+6f/sY+x70V5 tT4F+JpwinwFzHiUxBUiZ3Q8pxv3y9owClYnGBKu681/KFbQWu8jGeOFTnw1gsOaBCRj Q65Mwtown+KNZerPxFMGVM8Mmk6asiroA9JIienavMXdSHMxi/Oc17qWxzZXzPXNyJSS fpCqY8ziNxtLs774QjwD82TOVj4E06NWLKsMe5BFw/P20jo+PJPiMuelYq4psIyJc4ka Qflw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=n0dkKkggW4roLGRCIUa+7bvzAL1A7Ub2KzNnTnDcHNY=; b=hx6wvaOsfCnD/pHNtDTX8CMah+XzfkUqYnYksQtq3Jllu/lEW3TyA/t3CGBy+N8eNf z0v+8BhjHbRK/zuQUwttsLzG7VJ+XqwI7Ue0yOCVC62npFwINjRX2+mBx6J1D26JBLk3 l/Kgk16PoKkB/RbIWHWC/nl2IhH+4ZTs1YDUsGiRx5KAUhcJeHmdw7HwBvAKGLjAM37U lmMXJvCluK4ZAco8kCafYjYigsu8vZnGsu4YSoLu+VTOwGpDh80IWo5whyY1S6jK0Vf5 QAbJQufJHJBQZPofyBwdA8Rk/dE/Fx/AlEq6fBQd+An9P/EIxGzGzO+VJE3x76XZf/Xz /00w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="V/6MAHyP"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j20-20020aa78014000000b00557c8a20395si11256143pfi.120.2022.11.15.12.29.03; Tue, 15 Nov 2022 12:29:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b="V/6MAHyP"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbiKOU2m (ORCPT + 99 others); Tue, 15 Nov 2022 15:28:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbiKOU2h (ORCPT ); Tue, 15 Nov 2022 15:28:37 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BB262E4; Tue, 15 Nov 2022 12:28:36 -0800 (PST) Message-ID: <20221115202117.038937247@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544114; 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: references:references; bh=n0dkKkggW4roLGRCIUa+7bvzAL1A7Ub2KzNnTnDcHNY=; b=V/6MAHyPzrFi23hNIU7yKp2sjm0Fo4s8ktSn1TgtQreuowD63BLr3FDIiD2oFu/Ghl7TRq ZBgeYTuR1Mt49G52Zv57XCeUN5X7SVySJJrA34D6ANU/oOWt3iKPkj49kNZBfSxBpewhOR LxtkhWWIeKi8LY+HKLEG4GEoK610INmYKRs9Jyah5Q/1VviFHeAhH1Hp+jYcmg9RpBTo0u jfPdM1vC6eRm+T040dBuoWX/LQDuCJ8BomfPhA3NWQGz/W21jfWgV0FkZb6/5rjCLgDH7s L0kkbZvUVf+tBbmamNPUMTanv9XYUByoykfoVn6ZAbHeV9mbWB/WBzdjWOQTew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544114; 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: references:references; bh=n0dkKkggW4roLGRCIUa+7bvzAL1A7Ub2KzNnTnDcHNY=; b=Wzwm5zhLaRyKmarqNDBEEnls0xQC7FvuSWazpAOJHIOb/gRW32CuT3bo8Z7wMAR+Fmlxp7 CoqZteH9eo1nOSAQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 01/15] ARM: spear: Do not use timer namespace for timer_shutdown() function References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:34 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595357942597967?= X-GMAIL-MSGID: =?utf-8?q?1749595357942597967?= From: "Steven Rostedt (Google)" A new "shutdown" timer state is being added to the generic timer code. One of the functions to change the timer into the state is called "timer_shutdown()". This means that there can not be other functions called "timer_shutdown()" as the timer code owns the "timer_*" name space. Rename timer_shutdown() to spear_timer_shutdown() to avoid this conflict. Signed-off-by: Steven Rostedt (Google) Signed-off-by: Thomas Gleixner Tested-by: Guenter Roeck Reviewed-by: Guenter Roeck Acked-by: Arnd Bergmann Acked-by: Viresh Kumar Link: https://lkml.kernel.org/r/20221106212701.822440504@goodmis.org Link: https://lore.kernel.org/all/20221105060155.228348078@goodmis.org/ Link: https://lore.kernel.org/r/20221110064146.810953418@goodmis.org --- arch/arm/mach-spear/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-spear/time.c b/arch/arm/mach-spear/time.c index e979e2197f8e..5371c824786d 100644 --- a/arch/arm/mach-spear/time.c +++ b/arch/arm/mach-spear/time.c @@ -90,7 +90,7 @@ static void __init spear_clocksource_init(void) 200, 16, clocksource_mmio_readw_up); } -static inline void timer_shutdown(struct clock_event_device *evt) +static inline void spear_timer_shutdown(struct clock_event_device *evt) { u16 val = readw(gpt_base + CR(CLKEVT)); @@ -101,7 +101,7 @@ static inline void timer_shutdown(struct clock_event_device *evt) static int spear_shutdown(struct clock_event_device *evt) { - timer_shutdown(evt); + spear_timer_shutdown(evt); return 0; } @@ -111,7 +111,7 @@ static int spear_set_oneshot(struct clock_event_device *evt) u16 val; /* stop the timer */ - timer_shutdown(evt); + spear_timer_shutdown(evt); val = readw(gpt_base + CR(CLKEVT)); val |= CTRL_ONE_SHOT; @@ -126,7 +126,7 @@ static int spear_set_periodic(struct clock_event_device *evt) u16 val; /* stop the timer */ - timer_shutdown(evt); + spear_timer_shutdown(evt); period = clk_get_rate(gpt_clk) / HZ; period >>= CTRL_PRESCALER16; From patchwork Tue Nov 15 20:28:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2927413wru; Tue, 15 Nov 2022 12:29:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5mHKE/mAk897T9Yy2cpwVmJHF6o95XUOY2OE14OEQ7+LlfuJa2KnYuwJJjkMO0fgisw1u6 X-Received: by 2002:a17:90a:4e4a:b0:211:55d8:4cdd with SMTP id t10-20020a17090a4e4a00b0021155d84cddmr97963pjl.133.1668544164037; Tue, 15 Nov 2022 12:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544164; cv=none; d=google.com; s=arc-20160816; b=bENPZIuQSD/NPt3QuHpIcKWN89nP+bVRBz48z6fV+coP1JVpoiXDPPGW2gOLGin3dF qnWW3YvqGYwhoYO+mDTT6RQqvxCIEDXF75fXTCFWHdZvASZyzYBoikMiVG/Bujt6Na1D irb0gZ3H8Gx/mhgUfoSDoifc+NOW5VlqRo85nntA2eXBDw3i4iLmpb/ZHKi9Izhr7XVU n2obf0LxdyY0CbWOZgkuTQh0F0AFF1BXdbFlW/znNEDx0HE2eptVVPyyvpJM0P0AmnNe 5mlEu+fWkqSsS22GZ8h2GFC4yhA+1N27owOlCbQNgG22jnzRw0txYxAgLQwqiXx36XFU QnZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=96srhAwXJ3UQoCsDoL5fPAIasWFtP8WUr4N49zZJa6E=; b=bLVTygWKyf7iHw2BKZZp9b6fkMXcUT1T5aEHCPODBktBVpwCUnWhpo4sJ43QQ+0daC z2spo9hck3DxG40rIQR8MA8si5XbhNcBU5TmEMdYmQqwEy1m+B3TkDfAKExG/MPRdp9S yglcVGLgmRajLzHcNwBDlc3gUgWQ0ZNrFitCxVwPsnACC2Dz8yxVg6FI2i0vrLdcbJc7 sKi/7abk7HRvQBXzHUWyHaIT6t+6JlK3nqsZHUDNB+7zPgxVrtWnU/TpLvnNz68QeUzC cFcC4sIYwcHiL6Nig3JCZYTGzhyVUf597tYliRjIaUYzrUPi+ajcp4H6G2fbqhIC7VN8 JRJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RdgXZ0TA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=jvgBZ08Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a056a00151300b005712c9c1134si14316282pfu.192.2022.11.15.12.29.10; Tue, 15 Nov 2022 12:29:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=RdgXZ0TA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=jvgBZ08Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231794AbiKOU2q (ORCPT + 99 others); Tue, 15 Nov 2022 15:28:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231519AbiKOU2i (ORCPT ); Tue, 15 Nov 2022 15:28:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8C936259; Tue, 15 Nov 2022 12:28:37 -0800 (PST) Message-ID: <20221115202117.098759370@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544116; 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: references:references; bh=96srhAwXJ3UQoCsDoL5fPAIasWFtP8WUr4N49zZJa6E=; b=RdgXZ0TAWxdPBxv55AEPOK9e0UfkZQLA9JjjZ7uvLWUZjHD6wBxpnhDJaWs8kClPVPzwOB O7JaVb4WrPrMxeq0aC7oAjKrVz8kXSSiRY9BcUD8GSaxxWBjumGJz3koA4RGoO1R/gbLPJ b1ov7R8K68Nrx5tnApOrGySSwYPXObjONsZmUFiKtf6CRLrjSKO7Na7u3vymGQVFrSS0F6 5tdQbyW06tHApT51YNCrM9M1Nhj3PxJj0C0pw3CzTCsDgZ6nzv42p4gxdZa9zuouuDsYls 2hQtgdQqp2z3vE2zFkpIf9e8ZTsVBdpeY6LG5OU2vHWdn5j103iG8mlKHxqxoA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544116; 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: references:references; bh=96srhAwXJ3UQoCsDoL5fPAIasWFtP8WUr4N49zZJa6E=; b=jvgBZ08ZC6v9uKLQdG4akvwUOYV8XuypmessNrW3f8c1pxr4YFGpVHbLj1gXiPRFcdIuOh jAjBznVk4m9GKmBw== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Marc Zyngier , Arnd Bergmann , Viresh Kumar , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 02/15] clocksource/drivers/arm_arch_timer: Do not use timer namespace for timer_shutdown() function References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:35 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595365296351064?= X-GMAIL-MSGID: =?utf-8?q?1749595365296351064?= From: "Steven Rostedt (Google)" A new "shutdown" timer state is being added to the generic timer code. One of the functions to change the timer into the state is called "timer_shutdown()". This means that there can not be other functions called "timer_shutdown()" as the timer code owns the "timer_*" name space. Rename timer_shutdown() to arch_timer_shutdown() to avoid this conflict. Signed-off-by: Steven Rostedt (Google) Signed-off-by: Thomas Gleixner Tested-by: Guenter Roeck Reviewed-by: Guenter Roeck Acked-by: Marc Zyngier Link: https://lkml.kernel.org/r/20221106212702.002251651@goodmis.org Link: https://lore.kernel.org/all/20221105060155.409832154@goodmis.org/ Link: https://lore.kernel.org/r/20221110064146.981725531@goodmis.org --- drivers/clocksource/arm_arch_timer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index a7ff77550e17..9c3420a0d19d 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -687,8 +687,8 @@ static irqreturn_t arch_timer_handler_virt_mem(int irq, void *dev_id) return timer_handler(ARCH_TIMER_MEM_VIRT_ACCESS, evt); } -static __always_inline int timer_shutdown(const int access, - struct clock_event_device *clk) +static __always_inline int arch_timer_shutdown(const int access, + struct clock_event_device *clk) { unsigned long ctrl; @@ -701,22 +701,22 @@ static __always_inline int timer_shutdown(const int access, static int arch_timer_shutdown_virt(struct clock_event_device *clk) { - return timer_shutdown(ARCH_TIMER_VIRT_ACCESS, clk); + return arch_timer_shutdown(ARCH_TIMER_VIRT_ACCESS, clk); } static int arch_timer_shutdown_phys(struct clock_event_device *clk) { - return timer_shutdown(ARCH_TIMER_PHYS_ACCESS, clk); + return arch_timer_shutdown(ARCH_TIMER_PHYS_ACCESS, clk); } static int arch_timer_shutdown_virt_mem(struct clock_event_device *clk) { - return timer_shutdown(ARCH_TIMER_MEM_VIRT_ACCESS, clk); + return arch_timer_shutdown(ARCH_TIMER_MEM_VIRT_ACCESS, clk); } static int arch_timer_shutdown_phys_mem(struct clock_event_device *clk) { - return timer_shutdown(ARCH_TIMER_MEM_PHYS_ACCESS, clk); + return arch_timer_shutdown(ARCH_TIMER_MEM_PHYS_ACCESS, clk); } static __always_inline void set_next_event(const int access, unsigned long evt, From patchwork Tue Nov 15 20:28:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2927477wru; Tue, 15 Nov 2022 12:29:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Wb6y/Sp57PSyjOgKKzJQWaWrBaGtGx6lBiCECQNcuZYqMDKu7e6OOskMuDgXlJsJI5XJJ X-Received: by 2002:a17:90b:3c5:b0:20a:7d06:fe48 with SMTP id go5-20020a17090b03c500b0020a7d06fe48mr70617pjb.176.1668544175885; Tue, 15 Nov 2022 12:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544175; cv=none; d=google.com; s=arc-20160816; b=0K8BpdPM1d/SCFM7G0p5ImMPGplk0Krni1SBHEtlABML2xmnNS3ilfOKukyYLthXl2 F/f/M+00DtDYAiL28U4GdXzolhDkjorC+2gddc/+PvIAO00CvRInnXF06eyTbt3CcusO NMDdkfNtOIgjxdd3YTgtVxWgCiXZjJLXkDRgob5R+hs/ZO7WdPnQaIZNo7D08Y5TtHiK DmUA43JgyWu4GDEw1ePdiAIEy0qGJZLqq3xVvugypuXSsAAW8/oPYtk0btyidIE2TZJw 4Wm7tbXfomWYR/pnM/yXNqEO3lSEc2h772CFfMYpc65dY3N/Jc1Ou3QW+GBqRIwUICJU k/Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=XkUTDmMIm9+EPawG5WF0ZN1LAtqzHJ1HnPEjTlQs+bs=; b=KqyguywweGW30MfBmuiO9GzqI4IBnLviDxPlo4Am4IWChCYaXprpsQiJF2PDZKuMcP yMKTu9Es1zH3hoAZezhimUBNF8E2QT9uuTfGaL3RFYErEgPC4xGmXhZa3LHMYi313ns7 OeBklDyQQ/K/56C9xH5yXG+WcLIV497wggXOyrjFDiHl+pnCOkzQrnDE8FwZJk9UOwl0 MGsMzORZDgIsJHYHLffhoqwoncGt0ttnpuHsxQR9WLAy98PMLqwk9y852ZAKsvT28h+Z PRN2r0PckbZmWGz1yE2X3rtBtcZB4mRX/9kMywCtHj7QSWdIhuOPREvR8n/Lh8/zzLS5 QALQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Fi36xP8x; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Ec+YRUPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a635f09000000b00476a08c5d68si4564906pgb.822.2022.11.15.12.29.20; Tue, 15 Nov 2022 12:29:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=Fi36xP8x; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Ec+YRUPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbiKOU2z (ORCPT + 99 others); Tue, 15 Nov 2022 15:28:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231546AbiKOU2k (ORCPT ); Tue, 15 Nov 2022 15:28:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 725A2BF4B; Tue, 15 Nov 2022 12:28:39 -0800 (PST) Message-ID: <20221115202117.155698423@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544118; 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: references:references; bh=XkUTDmMIm9+EPawG5WF0ZN1LAtqzHJ1HnPEjTlQs+bs=; b=Fi36xP8xEr0b8q4crFzmOBOuoxHNolpYNIKpASmvfwUs/YLtp2+wBL0v6XY/z7pgmVg40C gsMSYOkN4+7deRm+WxlYQtlGeG7G8kylRsaZxzjgfNdAlkGQdb7adBHXiBAmfqjTJH1do4 Shd9j4xVl90qHFXiJVsd/F3K/8vwi+kjojRtTxa0aiImhsLgeQd5Ub/vjg71huf6yfTW59 KgNckXe4/O8EQAPgTX1YWRqZnT5ZcetkvYwQC+xautb+oAz3gyQrFRQ32Wksqx/t48B0WJ 5Je0f1MFsxQ4X9rHcxGucrxF/MJjCQBxOETKvgiYRY5TweYvhN1yO9S5x6vbmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544118; 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: references:references; bh=XkUTDmMIm9+EPawG5WF0ZN1LAtqzHJ1HnPEjTlQs+bs=; b=Ec+YRUPAfh4gt7iLKcdpnngFg4Ood+QYpf42sb+zcDU8hzoNzMtGTCqFksk1yWymrmGZfB pQjNqYMReVVD9lDA== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 03/15] clocksource/drivers/sp804: Do not use timer namespace for timer_shutdown() function References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:37 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595377612516537?= X-GMAIL-MSGID: =?utf-8?q?1749595377612516537?= From: "Steven Rostedt (Google)" A new "shutdown" timer state is being added to the generic timer code. One of the functions to change the timer into the state is called "timer_shutdown()". This means that there can not be other functions called "timer_shutdown()" as the timer code owns the "timer_*" name space. Rename timer_shutdown() to evt_timer_shutdown() to avoid this conflict. Signed-off-by: Steven Rostedt (Google) Signed-off-by: Thomas Gleixner Tested-by: Guenter Roeck Reviewed-by: Guenter Roeck Link: https://lkml.kernel.org/r/20221106212702.182883323@goodmis.org Link: https://lore.kernel.org/all/20221105060155.592778858@goodmis.org/ Link: https://lore.kernel.org/r/20221110064147.158230501@goodmis.org --- drivers/clocksource/timer-sp804.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c index e6a87f4af2b5..cd1916c05325 100644 --- a/drivers/clocksource/timer-sp804.c +++ b/drivers/clocksource/timer-sp804.c @@ -155,14 +155,14 @@ static irqreturn_t sp804_timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static inline void timer_shutdown(struct clock_event_device *evt) +static inline void evt_timer_shutdown(struct clock_event_device *evt) { writel(0, common_clkevt->ctrl); } static int sp804_shutdown(struct clock_event_device *evt) { - timer_shutdown(evt); + evt_timer_shutdown(evt); return 0; } @@ -171,7 +171,7 @@ static int sp804_set_periodic(struct clock_event_device *evt) unsigned long ctrl = TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE; - timer_shutdown(evt); + evt_timer_shutdown(evt); writel(common_clkevt->reload, common_clkevt->load); writel(ctrl, common_clkevt->ctrl); return 0; From patchwork Tue Nov 15 20:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2927516wru; Tue, 15 Nov 2022 12:29:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5PG+FZd4ld2mLNMre6j/YmFzmmKmdTtKClWkT4UQNHE/KsEDTLwYtlBvepp7gxKvdxlRuY X-Received: by 2002:a17:902:b48d:b0:188:b8cf:85b with SMTP id y13-20020a170902b48d00b00188b8cf085bmr5500854plr.126.1668544182489; Tue, 15 Nov 2022 12:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544182; cv=none; d=google.com; s=arc-20160816; b=Dl4Ag5nFxUpSCu0s4JvNCfgk4cmetMAfmfoAU07kDKSoq5hekQTy+HyEH4rQb2IgC9 tHrjAbmOSokTEM92rYpbPbcHvEojx5WIMP55mF+lf8ho+dX2vKBFCNN8IFtMTY0yvd8n bk9fZ6mW3rZk+89qOJarRlchQOMa66vMKRupPPZN3jzEr53Db/vs8DFTHHH1SbGAhObA jfCyxlaU6WWAu0C59bKqIC0GSpa/X884LvBDRRgmodWPDVOVYxRr3KZdPObsl9Ty8rk7 NJ5zG0uiMC8h6WWUwaEHBUN28KQk19Uijzil87cZYapPFzlzsOJWDe19X6ZLo0McAqju Z3OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=3TBA6m8Bui7HopFhQ4Bz43kzwszNO0sb5x3eSnipnV0=; b=dvSJPMdB2/W7+6ezfLeSCbgIY8Rgi+uy+Hcqbe/qOXX+D8ec48xhZDd4HjssEvEl/4 fsD/MWXfG3vH0BgHVkow6aDRCwWjOViQGKcnppRackekDjDE2PPKDAbwlqsAntLTits5 BhyrvMR4sPZEOJtYx+qeOIWnal52kVEwQxOVz/8fC3mi8EDYLOco7nJNuPZLpc2ivqQq Pa84uOyEg7uCBL4shuaz16/XiZW2GbnG5LIgWmulq4w0Gijep9bElwLwwEBBYBOQkmXO hGRsR1Smlx9TE1FFNHa8x1FG/tcLvwcPoMD8WLRfK9thc7bjFNxx1J91LGjjvIpDSsPG XQmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CnGelLBE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a655c8d000000b00439dcdd3cfdsi13507866pgt.825.2022.11.15.12.29.28; Tue, 15 Nov 2022 12:29:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=CnGelLBE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbiKOU3D (ORCPT + 99 others); Tue, 15 Nov 2022 15:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbiKOU2m (ORCPT ); Tue, 15 Nov 2022 15:28:42 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1952BDE93; Tue, 15 Nov 2022 12:28:41 -0800 (PST) Message-ID: <20221115202117.212339280@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544119; 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: references:references; bh=3TBA6m8Bui7HopFhQ4Bz43kzwszNO0sb5x3eSnipnV0=; b=CnGelLBE0Fa85YjIR35gJaKjBm/eUBT0c7RRftGo7CvC9/gQL8eQiSl9bpw8uXwvYVj+5X YcgEmxPqRUsd/YsKCIV8sGkFHINcPbcrZn3Vftp4oPrdmAChvCzJRrsK446Iisg2irt67i UqyUYuZXLEKS3ms2Z5WSLe8nmYdFYXQW6qjVg90q4SXQOSRC+Y9Aqu5BwUBdnCOSykPlDy z0g9P2ZBAmmxbohG/ZSF4jpAhx3gGkubIHsCFOQEFCvSF7xIcyNXdJh7VtaAoTXHPl70Ih 7RjR05xoWFmNlKbGpDJg7876fzQuCCtnG83wUr88KKOq4I3yflOJ2mUS0C06Sg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544119; 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: references:references; bh=3TBA6m8Bui7HopFhQ4Bz43kzwszNO0sb5x3eSnipnV0=; b=RLinhQXJtS9wYfu34J619sF3m7jtZSMxOgQg18D6H7+Pz454qb6YYMDZ+510IR8kUAC3Ze Q2q1BB+iVBJasIAw== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 04/15] timers: Get rid of del_singleshot_timer_sync() References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:39 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595384895953286?= X-GMAIL-MSGID: =?utf-8?q?1749595384895953286?= del_singleshot_timer_sync() used to be an optimization for deleting timers which are not rearmed from the timer callback function. This optimization turned out to be broken and got mapped to del_timer_sync() about 17 years ago. Get rid of the undocumented indirection and use del_timer_sync() directly. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Steven Rostedt (Google) --- drivers/char/tpm/tpm-dev-common.c | 4 ++-- drivers/staging/wlan-ng/hfa384x_usb.c | 4 ++-- drivers/staging/wlan-ng/prism2usb.c | 6 +++--- include/linux/timer.h | 2 -- kernel/time/timer.c | 2 +- net/sunrpc/xprt.c | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -155,7 +155,7 @@ ssize_t tpm_common_read(struct file *fil out: if (!priv->response_length) { *off = 0; - del_singleshot_timer_sync(&priv->user_read_timer); + del_timer_sync(&priv->user_read_timer); flush_work(&priv->timeout_work); } mutex_unlock(&priv->buffer_mutex); @@ -262,7 +262,7 @@ ssize_t tpm_common_write(struct file *fi void tpm_common_release(struct file *file, struct file_priv *priv) { flush_work(&priv->async_work); - del_singleshot_timer_sync(&priv->user_read_timer); + del_timer_sync(&priv->user_read_timer); flush_work(&priv->timeout_work); file->private_data = NULL; priv->response_length = 0; --- a/drivers/staging/wlan-ng/hfa384x_usb.c +++ b/drivers/staging/wlan-ng/hfa384x_usb.c @@ -1116,8 +1116,8 @@ static int hfa384x_usbctlx_complete_sync if (ctlx == get_active_ctlx(hw)) { spin_unlock_irqrestore(&hw->ctlxq.lock, flags); - del_singleshot_timer_sync(&hw->reqtimer); - del_singleshot_timer_sync(&hw->resptimer); + del_timer_sync(&hw->reqtimer); + del_timer_sync(&hw->resptimer); hw->req_timer_done = 1; hw->resp_timer_done = 1; usb_kill_urb(&hw->ctlx_urb); --- a/drivers/staging/wlan-ng/prism2usb.c +++ b/drivers/staging/wlan-ng/prism2usb.c @@ -170,9 +170,9 @@ static void prism2sta_disconnect_usb(str */ prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable); - del_singleshot_timer_sync(&hw->throttle); - del_singleshot_timer_sync(&hw->reqtimer); - del_singleshot_timer_sync(&hw->resptimer); + del_timer_sync(&hw->throttle); + del_timer_sync(&hw->reqtimer); + del_timer_sync(&hw->resptimer); /* Unlink all the URBs. This "removes the wheels" * from the entire CTLX handling mechanism. --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -190,8 +190,6 @@ extern int try_to_del_timer_sync(struct # define del_timer_sync(t) del_timer(t) #endif -#define del_singleshot_timer_sync(t) del_timer_sync(t) - extern void init_timers(void); struct hrtimer; extern enum hrtimer_restart it_real_fn(struct hrtimer *); --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1933,7 +1933,7 @@ signed long __sched schedule_timeout(sig timer_setup_on_stack(&timer.timer, process_timeout, 0); __mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING); schedule(); - del_singleshot_timer_sync(&timer.timer); + del_timer_sync(&timer.timer); /* Remove the timer from the object tracker */ destroy_timer_on_stack(&timer.timer); --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -1164,7 +1164,7 @@ xprt_request_enqueue_receive(struct rpc_ spin_unlock(&xprt->queue_lock); /* Turn off autodisconnect */ - del_singleshot_timer_sync(&xprt->timer); + del_timer_sync(&xprt->timer); return 0; } From patchwork Tue Nov 15 20:28:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2930473wru; Tue, 15 Nov 2022 12:38:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HNlgQp5UGFUIcwy8odjB4dtjCTYxs1YUhUm+qIyNg0EOBzrRA6FLsKrW7PXgVKAg47zDX X-Received: by 2002:a17:907:110d:b0:7a9:6107:572a with SMTP id qu13-20020a170907110d00b007a96107572amr15582770ejb.729.1668544680580; Tue, 15 Nov 2022 12:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544680; cv=none; d=google.com; s=arc-20160816; b=H33jinq1TZjUM2H8dopaGPz+tA24PGqCOsR0YSwwudAP7xv/m1cD0QgbiLdQlZgtGR k0CU2N3bcgO33RUK2AiHZNUHPoLSZveYxiUiebSPs0Al5V4fMjwt35Xt86WOCxFUs1Bu mc8n0LaxOfoCjzi6M1tL/2I0B5LiRkZR9ihAD28Kp9Z1qiZvVfU1jdBfqb6p+h5l+ni2 ZI26fqNHvYE0TUYk/7y40VeFFYPjuHosERakZTgnBnqYt8+yl5U/zZd/LIrwG1hJYe6U yWCdnamsj3xpep1gxItFCVGeDgxDsm3ywBAZkk5xknMa7Rg8GqLuwbZkGou+KavTikGp MpjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=+c6hXmXMFU+cA9M4ph7NzjesG8KGkczgV8QouyLFMhg=; b=Gvb24IEkglTit2t+sxz8KG37F0fJykQfbJ9VRbTriPYILtTpqRXCE51CqM4u3phRj/ gKYEPTYF4WDm3CKRv1uGsnFa4iY+LP+Beu8DV2iFpwmp/WeDvE9GjJtCOu/oqSG46o66 gT4Pz2q4vxxTWXdNERjDTaKsqJHMnZuHZ7JwjtylwYdFvkrhtJkwWo/eQBlFAYdg5woe YtExx1qIwjRPdBuLLIUtbapRm+DdIIJ0v0hjRpQ4blaDcD6834CQCvx/LiydBCUsGSmG BV5mEasruL0dSlUMY6i62ZkCChqC6j+c4bg9z+hMae2wCSx52aLzDcp+RF9wJSSn8hXG Zdkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Rk3f/zGx"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a1709064e8e00b007973c84ba55si5383253eju.298.2022.11.15.12.37.36; Tue, 15 Nov 2022 12:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b="Rk3f/zGx"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232096AbiKOU3J (ORCPT + 99 others); Tue, 15 Nov 2022 15:29:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbiKOU2r (ORCPT ); Tue, 15 Nov 2022 15:28:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6EA1056C; Tue, 15 Nov 2022 12:28:43 -0800 (PST) Message-ID: <20221115202117.267934419@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544122; 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: references:references; bh=+c6hXmXMFU+cA9M4ph7NzjesG8KGkczgV8QouyLFMhg=; b=Rk3f/zGx/ynmX6PJI0+Y/8yGMsMSaGsqFNzAwtnfnWpoXMm7qOFmlpjwCtkNjf5gUM6F0O hvFKvBn3aZALHNCWW5BaBsHJ+vPYoxgwYXQUo1fO6w8B5pfWWL/sF3We+OFujgCprXMzdU Xuf+cRNzeaS3oR9T88JsS4oYQsQ1mljxlgP5q9yp+ON9vtuI4k4rB23sK/8oYnqG1f9bqt N469PmNJNlhLPSehiztNG2eBzCddF3LcPNlRuM6AkAoSAJPP9DWJJ7Yl8wKZqbetE3BJQS 6MDJicVS0Kg0JIC9gdLzrKqrV1GCoQQqrkon5xTvhWY8tSFhdAOk6WWlaKvluA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544122; 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: references:references; bh=+c6hXmXMFU+cA9M4ph7NzjesG8KGkczgV8QouyLFMhg=; b=vHzcFij6caEAmwrBaTi6i/5ROuLhTfBF0oiSGsA/MCF+cI6pPQ9eZaxtUgGzlevwFMT4Gt G3EpvNkyAxD+vGBQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 05/15] timers: Replace BUG_ON()s References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:41 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595906901705831?= X-GMAIL-MSGID: =?utf-8?q?1749595906901705831?= The timer code still has a few BUG_ON()s left which are crashing the kernel in situations where it still can recover or simply refuse to take an action. Remove the one in the hotplug callback which checks for the CPU being offline. If that happens then the whole hotplug machinery will explode in colourful ways. Replace the rest with WARN_ON_ONCE() and conditional returns where appropriate. Signed-off-by: Thomas Gleixner Reviewed-by: Steven Rostedt (Google) --- kernel/time/timer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1193,7 +1193,8 @@ EXPORT_SYMBOL(timer_reduce); */ void add_timer(struct timer_list *timer) { - BUG_ON(timer_pending(timer)); + if (WARN_ON_ONCE(timer_pending(timer))) + return; __mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING); } EXPORT_SYMBOL(add_timer); @@ -1210,7 +1211,8 @@ void add_timer_on(struct timer_list *tim struct timer_base *new_base, *base; unsigned long flags; - BUG_ON(timer_pending(timer) || !timer->function); + if (WARN_ON_ONCE(timer_pending(timer) || !timer->function)) + return; new_base = get_timer_cpu_base(timer->flags, cpu); @@ -2017,8 +2019,6 @@ int timers_dead_cpu(unsigned int cpu) struct timer_base *new_base; int b, i; - BUG_ON(cpu_online(cpu)); - for (b = 0; b < NR_BASES; b++) { old_base = per_cpu_ptr(&timer_bases[b], cpu); new_base = get_cpu_ptr(&timer_bases[b]); @@ -2035,7 +2035,8 @@ int timers_dead_cpu(unsigned int cpu) */ forward_timer_base(new_base); - BUG_ON(old_base->running_timer); + WARN_ON_ONCE(old_base->running_timer); + old_base->running_timer = NULL; for (i = 0; i < WHEEL_SIZE; i++) migrate_timer_list(new_base, old_base->vectors + i); From patchwork Tue Nov 15 20:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2932822wru; Tue, 15 Nov 2022 12:44:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ipf/G4uC4mLalTRC7YjxUsfpIBoXS+XAwlHfm8zqXYQj6i4IAkPtykdh0d2mf4/O0fIvo X-Received: by 2002:a17:906:ccd6:b0:78d:9002:fe3b with SMTP id ot22-20020a170906ccd600b0078d9002fe3bmr15389761ejb.769.1668545090683; Tue, 15 Nov 2022 12:44:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668545090; cv=none; d=google.com; s=arc-20160816; b=ZMl52niZqIkOVn37FR/OzRG9s2QhRAbP34r9IxM73f6wXZ0k1Q2yGaKkHiM7h3eqGA 24KEAIWN50coUnnha/lyuSko4qsgMiYNsB7UDYTyhMZHgvhWP/TRiqVHDuoHXbAVqE3O u+q8QC+4lh9HHGX8a1V6hsQ9c9adphNMUhoy211TrmroA/cN2lIa9EHvSuyrZILnJuq1 0qiV98kfkMKuO2wEp7cyDpI5r32OsvEPLLPG6MiEVCn+Lh+7PuF3cjxMV83pUlqefDW3 T/PvPhhEynEtgI3j4EdQsRSJLMRWfrMm1cSTyARk8l5HPzytB89TtQKS7qOi0PJ22KJf kU9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=6cZSGjH3qyMbROnQcZtnm1o8seSCPpQTaHxAost1YAs=; b=XBgjHHeLWu2V4xrdI8dUYl4f36qZMUbaO3S4jjWqFubYE+Yew2rxrkEQWNBstsRNQg R/2fKa1dz1WYAy+Wc8uKOG9tdNZrcrnT77JHwsXYkiTs2BTAR0GvOo3E5eY9eyMrNKbZ cHswa3MByqM7kaE1TGiJtb4rKEusSPpp3XlI98Xq/7kkLwJdxCRBjDTZEYk/jAxI8TC/ k7g3yqWjaCJ72q6Ifkz1zG33MBfdy7RvDSAmGuWa3RomY5GEDW7UwmR51KrggGT3sQnZ K6VmiEb/uWjlo9+7jW4Sf9G0MUg+VIe2cLPON/mpVcRSO4YcUl7zXF8pw4uAlsJZhFpf pzFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="hrWJV5/p"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="wEVNpE/t"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p7-20020a1709060e8700b007ae286f26b1si10014733ejf.620.2022.11.15.12.44.24; Tue, 15 Nov 2022 12:44:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b="hrWJV5/p"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="wEVNpE/t"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232661AbiKOU3T (ORCPT + 99 others); Tue, 15 Nov 2022 15:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232290AbiKOU3H (ORCPT ); Tue, 15 Nov 2022 15:29:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B7111817; Tue, 15 Nov 2022 12:28:46 -0800 (PST) Message-ID: <20221115202117.323694948@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544123; 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: references:references; bh=6cZSGjH3qyMbROnQcZtnm1o8seSCPpQTaHxAost1YAs=; b=hrWJV5/plQBGgIENR/xr7Z0DoZ3Mfkd/0tlI7YWcodMj10Mj5okVcfd1levrvtzR5LNxSi +63ScI6/Eg3SLHc1JQUS+TDd7tw6HWC6uv2m7mqUxFA5DX1JYrG9u9u3P7PNBKBiZaXJT8 Lxyka2WclfssbcH1Se0/me7mcqBxUnJNIM8cHg6ShTYa3Wly5u/gHkhKOSdboE/Pz3n3ZF V/+0Da1YUWwRpKcLEBFCA7LvuC65d34CjAqRmOYE4jVGA7Y+QUbWuaDdMQpHA6Gr5sJRkE DolJnJyF3kdbx6BEnAXpZEoI3A17NA0lzu3cjZkOlRWaEH5JibPGmn5N/21N7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544123; 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: references:references; bh=6cZSGjH3qyMbROnQcZtnm1o8seSCPpQTaHxAost1YAs=; b=wEVNpE/t66kQjXzo0ebhqqDbAYys835ST56yXVY/VwNrzdbSXCOeLE4zJGtzDKGqJAnc80 IetBmqMjOrsxenBw== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 06/15] timers: Update kernel-doc for various functions References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:43 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596337172852680?= X-GMAIL-MSGID: =?utf-8?q?1749596337172852680?= The kernel-doc of timer related functions is partially uncomprehensible word salad. Rewrite it to make it useful. Signed-off-by: Thomas Gleixner --- kernel/time/timer.c | 131 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 54 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1121,14 +1121,16 @@ static inline int } /** - * mod_timer_pending - modify a pending timer's timeout - * @timer: the pending timer to be modified - * @expires: new timeout in jiffies + * mod_timer_pending - Modify a pending timer's timeout + * @timer: The pending timer to be modified + * @expires: New timeout in jiffies * - * mod_timer_pending() is the same for pending timers as mod_timer(), - * but will not re-activate and modify already deleted timers. + * mod_timer_pending() is the same for pending timers as mod_timer(), but + * will not activate inactive timers. * - * It is useful for unserialized use of timers. + * Return: + * * %0 - The timer was inactive and not modified + * * %1 - The timer was active and requeued to expire at @expires */ int mod_timer_pending(struct timer_list *timer, unsigned long expires) { @@ -1137,9 +1139,9 @@ int mod_timer_pending(struct timer_list EXPORT_SYMBOL(mod_timer_pending); /** - * mod_timer - modify a timer's timeout - * @timer: the timer to be modified - * @expires: new timeout in jiffies + * mod_timer - Modify a timer's timeout + * @timer: The timer to be modified + * @expires: New timeout in jiffies * * mod_timer() is a more efficient way to update the expire field of an * active timer (if the timer is inactive it will be activated) @@ -1152,9 +1154,11 @@ EXPORT_SYMBOL(mod_timer_pending); * same timer, then mod_timer() is the only safe way to modify the timeout, * since add_timer() cannot modify an already running timer. * - * The function returns whether it has modified a pending timer or not. - * (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an - * active timer returns 1.) + * Return: + * * %0 - The timer was inactive and started + * * %1 - The timer was active and requeued to expire at @expires or + * the timer was active and not modified because @expires did + * not change the effective expiry time */ int mod_timer(struct timer_list *timer, unsigned long expires) { @@ -1168,8 +1172,15 @@ EXPORT_SYMBOL(mod_timer); * @expires: New timeout in jiffies * * timer_reduce() is very similar to mod_timer(), except that it will only - * modify a running timer if that would reduce the expiration time (it will - * start a timer that isn't running). + * modify an enqueued timer if that would reduce the expiration time. If + * @timer is not enqueued it starts the timer. + * + * Return: + * * %0 - The timer was inactive and started + * * %1 - The timer was active and requeued to expire at @expires or + * the timer was active and not modified because @expires + * did not change the effective expiry time such that the + * timer would expire earlier than already scheduled */ int timer_reduce(struct timer_list *timer, unsigned long expires) { @@ -1178,18 +1189,18 @@ int timer_reduce(struct timer_list *time EXPORT_SYMBOL(timer_reduce); /** - * add_timer - start a timer - * @timer: the timer to be added + * add_timer - Start a timer + * @timer: The timer to be started * - * The kernel will do a ->function(@timer) callback from the - * timer interrupt at the ->expires point in the future. The - * current time is 'jiffies'. + * Start @timer to expire at @timer->expires in the future. @timer->expires + * is the absolute expiry time measured in 'jiffies'. When the timer expires + * timer->function(timer) will be invoked from soft interrupt context. * - * The timer's ->expires, ->function fields must be set prior calling this - * function. + * The @timer->expires and @timer->function fields must be set prior + * calling this function. * - * Timers with an ->expires field in the past will be executed in the next - * timer tick. + * If @timer->expires is already in the past @timer will be queued to + * expire at the next timer tick. */ void add_timer(struct timer_list *timer) { @@ -1200,11 +1211,12 @@ void add_timer(struct timer_list *timer) EXPORT_SYMBOL(add_timer); /** - * add_timer_on - start a timer on a particular CPU - * @timer: the timer to be added - * @cpu: the CPU to start it on + * add_timer_on - Start a timer on a particular CPU + * @timer: The timer to be started + * @cpu: The CPU to start it on * - * This is not very scalable on SMP. Double adds are not possible. + * This can only operate on an inactive timer. Attempts to invoke this on + * an active timer are rejected with a warning. */ void add_timer_on(struct timer_list *timer, int cpu) { @@ -1240,15 +1252,17 @@ void add_timer_on(struct timer_list *tim EXPORT_SYMBOL_GPL(add_timer_on); /** - * del_timer - deactivate a timer. - * @timer: the timer to be deactivated - * - * del_timer() deactivates a timer - this works on both active and inactive - * timers. + * del_timer - Deactivate a timer. + * @timer: The timer to be deactivated * - * The function returns whether it has deactivated a pending timer or not. - * (ie. del_timer() of an inactive timer returns 0, del_timer() of an - * active timer returns 1.) + * Contrary to del_timer_sync() this function does not wait for an + * eventually running timer callback on a different CPU and it neither + * prevents rearming of the timer. If @timer can be rearmed concurrently + * then the return value of this function is meaningless. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated */ int del_timer(struct timer_list *timer) { @@ -1270,10 +1284,16 @@ EXPORT_SYMBOL(del_timer); /** * try_to_del_timer_sync - Try to deactivate a timer - * @timer: timer to delete + * @timer: Timer to deactivate * - * This function tries to deactivate a timer. Upon successful (ret >= 0) - * exit the timer is not queued and the handler is not running on any CPU. + * This function cannot guarantee that the timer cannot be rearmed right + * after dropping the base lock. That needs to be prevented by the calling + * code if necessary. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated + * * %-1 - The timer callback function is running on a different CPU */ int try_to_del_timer_sync(struct timer_list *timer) { @@ -1369,23 +1389,19 @@ static inline void del_timer_wait_runnin #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT) /** - * del_timer_sync - deactivate a timer and wait for the handler to finish. - * @timer: the timer to be deactivated - * - * This function only differs from del_timer() on SMP: besides deactivating - * the timer it also makes sure the handler has finished executing on other - * CPUs. + * del_timer_sync - Deactivate a timer and wait for the handler to finish. + * @timer: The timer to be deactivated * * Synchronization rules: Callers must prevent restarting of the timer, * otherwise this function is meaningless. It must not be called from * interrupt contexts unless the timer is an irqsafe one. The caller must - * not hold locks which would prevent completion of the timer's - * handler. The timer's handler must not call add_timer_on(). Upon exit the - * timer is not queued and the handler is not running on any CPU. - * - * Note: For !irqsafe timers, you must not hold locks that are held in - * interrupt context while calling this function. Even if the lock has - * nothing to do with the timer in question. Here's why:: + * not hold locks which would prevent completion of the timer's callback + * function. The timer's handler must not call add_timer_on(). Upon exit + * the timer is not queued and the handler is not running on any CPU. + * + * For !irqsafe timers, the caller must not hold locks that are held in + * interrupt context. Even if the lock has nothing to do with the timer in + * question. Here's why:: * * CPU0 CPU1 * ---- ---- @@ -1399,10 +1415,17 @@ static inline void del_timer_wait_runnin * while (base->running_timer == mytimer); * * Now del_timer_sync() will never return and never release somelock. - * The interrupt on the other CPU is waiting to grab somelock but - * it has interrupted the softirq that CPU0 is waiting to finish. + * The interrupt on the other CPU is waiting to grab somelock but it has + * interrupted the softirq that CPU0 is waiting to finish. * - * The function returns whether it has deactivated a pending timer or not. + * This function cannot guarantee that the timer is not rearmed again by + * some concurrent or preempting code, right after it dropped the base + * lock. If there is the possibility of a concurrent rearm then the return + * value of the function is meaningless. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated */ int del_timer_sync(struct timer_list *timer) { From patchwork Tue Nov 15 20:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2931675wru; Tue, 15 Nov 2022 12:41:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5liKBqzQw53SuZkjaFYm80w5odsVscQHEt7TBSYAfZLOzYMpi4UqMsW9j4yEwASgQZ0PoT X-Received: by 2002:a17:906:b2ca:b0:7ad:92c5:637a with SMTP id cf10-20020a170906b2ca00b007ad92c5637amr15576266ejb.87.1668544883070; Tue, 15 Nov 2022 12:41:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544883; cv=none; d=google.com; s=arc-20160816; b=kropOI9a7iov6G+9vgj6IwPxuc7hlbAx/PPMNmiqYP2v3owiFnuK2YhHv4miKA9hz3 235ZNMwUP9M6sofXuB89a+PnRShZPjzEhwtGzZ+Qz0Ac82KX3GdOfwwchVYD3vVLkobF J7BLL1cyUoN+i4Wn8sekBuieU1EUhvVyFPDMlh4YXSzfSyDsWnCzgM0osKtu2rH/cENw dUhLin6SuabFG46y1F42TlT6Li5VIxpf88KlX367Ie9mvHj744px45Wtj/b22Letqfc+ Tbt93YRqEGZjKBA9JZTx8kM0CuvAurlzUYJgGBsAfhUMdsdyh0/pS7a9GWIZqeKvsnX3 NL0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=jmwINQ2aLPhomCKb2of90IzUc3f8LPfpTdJJ0tjAXWA=; b=z1WWA1W6YWkMRRkUyTVBifkfWeSosiFSiqOiv2hV5PzMZAUDrBXei1R0mqkD58IhL7 uhW/cYoBPiKdtVoUoCtZix/o6F6YuG8GdMvqkjQPeF4KhD6XQBDOC23I9cMFjxOawfZf 8a8QhMBJp3cHqsguWGf6BIIGs9Td8BXAHl4a+w1i8zsxrEo0wp4aUXeI9u88qsr3liGp MrsaIZKtFC9UVyunTcr6fjwrEieRD/ydbmQ5bJUcJlCpzuhTsNvIsW9FHXzaMhMI70lz WkSxq81PGQrUHI6ZfnL+ajc8dWDilVWBolrUjUKC2d3EFUh32/74awS7vVVCtAC/ebah /wNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uYnmubxL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=fEWc8E3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho42-20020a1709070eaa00b007ae9813f960si13380539ejc.948.2022.11.15.12.40.58; Tue, 15 Nov 2022 12:41:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=uYnmubxL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=fEWc8E3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbiKOU31 (ORCPT + 99 others); Tue, 15 Nov 2022 15:29:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232302AbiKOU3H (ORCPT ); Tue, 15 Nov 2022 15:29:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EAF8EE11; Tue, 15 Nov 2022 12:28:46 -0800 (PST) Message-ID: <20221115202117.381022914@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544125; 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: references:references; bh=jmwINQ2aLPhomCKb2of90IzUc3f8LPfpTdJJ0tjAXWA=; b=uYnmubxL74vpNPe1yY7N8Ixqeqx72Wk6fNXKkOehstD1Kst8YCLM99Ny385r8ft3qBjxcO awJytt30xm/q3wd5G5r4QR5ameAHC7AUYsr8zyiHkJeoiPageSFmLY9cZqKwim9gDTfjed JRidt/RofyASggWNqLjTwP+T5bmW+NsDvYb5Q8KKMhYNXagjHee5H4Y5e6RqXLGHBsGzWB wGzMion+vWBvhXNWYdknKCU46FfIQRVFuh4G7mWmMinmflf3/r9DuMm5gGfxMLdUnQOChA N1c8IpfX0rTUoKgc47SspELF8+AHdC48zjhWzMvyDhiMQBLVY8zKBSaykcu1nw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544125; 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: references:references; bh=jmwINQ2aLPhomCKb2of90IzUc3f8LPfpTdJJ0tjAXWA=; b=fEWc8E3qz1ewulSShtWTP1Ypkngwuu+VLMWXHStwK0sydhqhHyrAtn/QK21EYbxjzHdLWb Vf6wiNaxhCC7t7AQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 07/15] timers: Use del_timer_sync() even on UP References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:44 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596119338348530?= X-GMAIL-MSGID: =?utf-8?q?1749596119338348530?= del_timer_sync() is assumed to be pointless on uniprocessor systems and can be mapped to del_timer() because in theory del_timer() can never be invoked while the timer callback function is executed. This is not entirely true because del_timer() can be invoked from interrupt context and therefore hit in the middle of a running timer callback. Contrary to that del_timer_sync() is not allowed to be invoked from interrupt context unless the affected timer is marked with TIMER_IRQSAFE. del_timer_sync() has proper checks in place to detect such a situation. Give up on the UP optimization and make del_timer_sync() unconditionally available. Co-developed-by: Steven Rostedt Signed-off-by: Steven Rostedt Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org --- include/linux/timer.h | 7 +------ kernel/time/timer.c | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -183,12 +183,7 @@ extern int timer_reduce(struct timer_lis extern void add_timer(struct timer_list *timer); extern int try_to_del_timer_sync(struct timer_list *timer); - -#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT) - extern int del_timer_sync(struct timer_list *timer); -#else -# define del_timer_sync(t) del_timer(t) -#endif +extern int del_timer_sync(struct timer_list *timer); extern void init_timers(void); struct hrtimer; --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1387,7 +1387,6 @@ static inline void timer_sync_wait_runni static inline void del_timer_wait_running(struct timer_list *timer) { } #endif -#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT) /** * del_timer_sync - Deactivate a timer and wait for the handler to finish. * @timer: The timer to be deactivated @@ -1468,7 +1467,6 @@ int del_timer_sync(struct timer_list *ti return ret; } EXPORT_SYMBOL(del_timer_sync); -#endif static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list *), From patchwork Tue Nov 15 20:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2931343wru; Tue, 15 Nov 2022 12:40:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+KMYMAGLUaApKYW5vdRgoYQ/q0CgQNvTKaSnlopadGasKN0rKWYdemkUUBSLresgBxlIA X-Received: by 2002:a17:907:9546:b0:7ac:d0ae:feba with SMTP id ex6-20020a170907954600b007acd0aefebamr15465089ejc.646.1668544825261; Tue, 15 Nov 2022 12:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544825; cv=none; d=google.com; s=arc-20160816; b=ajONfTxn5/d9Kquy6ns3EdL4NG6vZVmPdNfjV2FBadzr5MDkvLiUzvyAu0X0PI6Msk SH1zoZ11zUCQEQFXAVXS+uHfrto9L5yFVR2Gmt785zFq13YUgF6jAQoRk8hDRFpZoqe7 NlkVD0gesIC49MTx3F8z2CviriFTlo68rjESjUjx1OqipugbYrkpAQgxeUdFE9AwHTTA PTl6uI2L2adC4sBCNwjGAa2lBPsJQeQn58EeSvyw2iFHJBISa6SmDSlcXep41Hbis2Dj IcReBBlspKhcvZ6war9a8eVA/GsVsi6iMZge7IgF97ePbUejDTJV33anTcAxoXPyRUc4 K/Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=lhI4vWrTLS0UmEPOy+yLY9a4+uY4zqdwPZIU3WEgia8=; b=BR2S36pm9ylPCfeD5LUKsSGjhgIW4YsX05s/8TEgGGi2J8t9HrnU3YgSyrEMmGI1su gk5HkyjB1O71cv/AeOJ5ZaWfma4p3vY76CY4Fm1BAJATBG5fOMbHRkM53IBN4rMV/yzu dCkklQnf4jXM9goUXqsQlGyzgg+h1IzTyA9ij7MqybK5YmihmC5PRzkaFueipYPjw2m2 9aUdeizsnMjt7KBYCMPnBEuc3JGP0ImDRjgbEmgUXoBj/yqMNC0XPGNTgBXufED/OpW0 RfsQNQVwAS66a4cH1zmn7leTtg3Vrrvv3u0mFvBGkKlNTy8zWUNoXJoddXfSPb0MkXIV +EHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0L0jDWVh; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i20-20020a50fc14000000b00461f7a83e58si11581252edr.46.2022.11.15.12.40.01; Tue, 15 Nov 2022 12:40:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=0L0jDWVh; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238283AbiKOU36 (ORCPT + 99 others); Tue, 15 Nov 2022 15:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232569AbiKOU3R (ORCPT ); Tue, 15 Nov 2022 15:29:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C891659D; Tue, 15 Nov 2022 12:28:48 -0800 (PST) Message-ID: <20221115202117.438013991@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544127; 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: references:references; bh=lhI4vWrTLS0UmEPOy+yLY9a4+uY4zqdwPZIU3WEgia8=; b=0L0jDWVheTH+lUpVH8Cme4AHvqhxzhwFM5thzlZjbYNCixajpNtYarLKjs5JhMfYmXdt0I Boa11in0Rf90i9OJfB1ECG5n5eslv3vZJLD97TtXc+3yK4auw1H+l4olFGw3CRtqzTWRga AE+8PxmgCmfYpQ+xCpe0K2ii+psAf3J/LbXfKnAggA+wCOQRnz/kjnmlQ5TrwyB92YnrO1 UkouQQOg9ZjS0qTBWbPDP/bvHeGril3j/gLwombTEPBzWYWRg1R/n3wHRkol9pwuWPesUO 7SO4O3jnZisJbfNS29Divd52EwkD5WH5btGRnO2574O8jPE+Z2zjzZW9bgZNwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544127; 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: references:references; bh=lhI4vWrTLS0UmEPOy+yLY9a4+uY4zqdwPZIU3WEgia8=; b=xyGRlNWi/OwMd0LPS63ukFn7w/SoiFAGTc11LkVlCjaQiuLBDCvZc0dfsQP/9bI2lq+drz qk+HLo8SCblDu7DA== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 08/15] timers: Rename del_timer_sync() to timer_delete_sync() References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:46 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596058519608280?= X-GMAIL-MSGID: =?utf-8?q?1749596058519608280?= The timer related functions do not have a strict timer_ prefixed namespace which is really annoying. Rename del_timer_sync() to timer_delete_sync() and provide del_timer_sync() as a wrapper. Document that del_timer_sync() is not for new code. Signed-off-by: Thomas Gleixner Reviewed-by: Steven Rostedt (Google) --- include/linux/timer.h | 15 ++++++++++++++- kernel/time/timer.c | 18 +++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -183,7 +183,20 @@ extern int timer_reduce(struct timer_lis extern void add_timer(struct timer_list *timer); extern int try_to_del_timer_sync(struct timer_list *timer); -extern int del_timer_sync(struct timer_list *timer); +extern int timer_delete_sync(struct timer_list *timer); + +/** + * del_timer_sync - Delete a pending timer and wait for a running callback + * @timer: The timer to be deleted + * + * See timer_delete_sync() for detailed explanation. + * + * Do not use in new code. Use timer_delete_sync() instead. + */ +static inline int del_timer_sync(struct timer_list *timer) +{ + return timer_delete_sync(timer); +} extern void init_timers(void); struct hrtimer; --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1083,7 +1083,7 @@ static inline int /* * We are trying to schedule the timer on the new base. * However we can't change timer's base while it is running, - * otherwise del_timer_sync() can't detect that the timer's + * otherwise timer_delete_sync() can't detect that the timer's * handler yet has not finished. This also guarantees that the * timer is serialized wrt itself. */ @@ -1255,7 +1255,7 @@ EXPORT_SYMBOL_GPL(add_timer_on); * del_timer - Deactivate a timer. * @timer: The timer to be deactivated * - * Contrary to del_timer_sync() this function does not wait for an + * Contrary to timer_delete_sync() this function does not wait for an * eventually running timer callback on a different CPU and it neither * prevents rearming of the timer. If @timer can be rearmed concurrently * then the return value of this function is meaningless. @@ -1388,7 +1388,7 @@ static inline void del_timer_wait_runnin #endif /** - * del_timer_sync - Deactivate a timer and wait for the handler to finish. + * timer_delete_sync - Deactivate a timer and wait for the handler to finish. * @timer: The timer to be deactivated * * Synchronization rules: Callers must prevent restarting of the timer, @@ -1410,10 +1410,10 @@ static inline void del_timer_wait_runnin * spin_lock_irq(somelock); * * spin_lock(somelock); - * del_timer_sync(mytimer); + * timer_delete_sync(mytimer); * while (base->running_timer == mytimer); * - * Now del_timer_sync() will never return and never release somelock. + * Now timer_delete_sync() will never return and never release somelock. * The interrupt on the other CPU is waiting to grab somelock but it has * interrupted the softirq that CPU0 is waiting to finish. * @@ -1426,7 +1426,7 @@ static inline void del_timer_wait_runnin * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -int del_timer_sync(struct timer_list *timer) +int timer_delete_sync(struct timer_list *timer) { int ret; @@ -1466,7 +1466,7 @@ int del_timer_sync(struct timer_list *ti return ret; } -EXPORT_SYMBOL(del_timer_sync); +EXPORT_SYMBOL(timer_delete_sync); static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list *), @@ -1488,8 +1488,8 @@ static void call_timer_fn(struct timer_l #endif /* * Couple the lock chain with the lock chain at - * del_timer_sync() by acquiring the lock_map around the fn() - * call here and in del_timer_sync(). + * timer_delete_sync() by acquiring the lock_map around the fn() + * call here and in timer_delete_sync(). */ lock_map_acquire(&lockdep_map); From patchwork Tue Nov 15 20:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2931190wru; Tue, 15 Nov 2022 12:40:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf57wjX8qW4TraHIbFiz2xDFZL5FXRbnc8SAKDPisz52BdYxGgfbWmIAr3Wzo5zS6cHSk/Kk X-Received: by 2002:a17:907:8c15:b0:78d:9e04:d8c2 with SMTP id ta21-20020a1709078c1500b0078d9e04d8c2mr14687724ejc.614.1668544800016; Tue, 15 Nov 2022 12:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544800; cv=none; d=google.com; s=arc-20160816; b=Fl7QjBewxN5j2yNM8z+Q4fEs3Q4DV9rBgBPInyQlhJ5qnvqXDQ5v3MYTVuxrCIytOt r/FPkMeNJ56O/ARARSEuJiEfiDzAI4Z+sWlmgJednyODx9VFtbQus0QXMGs5yi56FQnY Q5rtwjcSNKhNDZW0MhSsxCSzcvQiiTA5WAVDSzh0bfx+ECdVxRxEywQQUsCaFPwge2Qs uxtoyFUPHE8FwSnujSkQ3/f2dVYnUeD1m+7XPE+AMm/XqlFd28fWxgnaDuVMRbIIBkX7 HfXFuAIE8bn2V+Cr8ikHLuRisIkWmOmmf8BezAIKHPX9sMvpvjVIr92HmrX8bJAoWvAX oxLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=hwBlr7gRdPWX+jcuURdCYYPD+CIC4n+uInKylO/pJp4=; b=vgu3rh7njPb+iJGKFPxGmXoD8FFq7TzXjDNx+iPW03NnxEt6CyXR3xQuTxJTGgYTde +HJr2LXEYqBoE2mRsKqMWGKaCnKViJ/sPlHr7QUEocn9lQDprGySa95+b7boLrucSgEg IFPg7lWxzeS2N2sGZtEzhWrW0N3Qd+XvYAUOwonOMSnOb1TUW2fUCDeP/vRQ/FG3511z AyzVQsRK1PHP892ZamDqc8Z7zyFd3Fa7tiS3PrHlT2upwzQ4evPoQn0E6KGX5JeZW4Dd 1jfnh15EwTawRG6ByhrE9QAAMCRMqzx6J5kl9VXmVJGaCa7jJXVxj4ThV7lx6YRyDuLm 7ifw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cujHDrZm; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t5-20020a056402524500b00461992160edsi12848989edd.384.2022.11.15.12.39.35; Tue, 15 Nov 2022 12:39:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=cujHDrZm; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238351AbiKOUaB (ORCPT + 99 others); Tue, 15 Nov 2022 15:30:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236796AbiKOU3u (ORCPT ); Tue, 15 Nov 2022 15:29:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FB3D27DCC; Tue, 15 Nov 2022 12:28:49 -0800 (PST) Message-ID: <20221115202117.497653635@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544128; 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: references:references; bh=hwBlr7gRdPWX+jcuURdCYYPD+CIC4n+uInKylO/pJp4=; b=cujHDrZmE0+epA410xB6Bu9FcCpqiFA3XQwhDwRg6wOuiZmgkn8s/7d7AmmzCtox+smY9R WlNCN7BHjq8+OSfvTfSNMdbJgQ4dWTywfuH5I0RUBhCn75y8Vn+ERKeQyOBu0fVpDOUomz xz7N3ZyMftM2uYc4JdyTsdWNBHUXEqC6wZfRM1818iGAjiHcLLX7XwcAeUT1ypsCE5nESa EgN/YJkELwNPFBFQuErn2z/eR0k1Wm8SR0OPHy+8F0r2f/k6JP55uOtbcm8aaMyf6VAStL gdBGrY3pp6V+lPis2q7mffcsmFEGtu9yhQDMXzlsoGmlceCJmP5tOFiZAzFIcg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544128; 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: references:references; bh=hwBlr7gRdPWX+jcuURdCYYPD+CIC4n+uInKylO/pJp4=; b=HI3JwTkBI1GYhGcCHxXUijTPCARgWfZW+5HHmAbAr4btEdlS8X8hMiOZquMMmYRYAAHCIg mHAaonGXLg89MkBQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 09/15] timers: Rename del_timer() to timer_delete() References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:48 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596032317634058?= X-GMAIL-MSGID: =?utf-8?q?1749596032317634058?= The timer related functions do not have a strict timer_ prefixed namespace which is really annoying. Rename del_timer() to timer_delete() and provide del_timer() as a wrapper. Document that del_timer() is not for new code. Signed-off-by: Thomas Gleixner Reviewed-by: Steven Rostedt (Google) --- include/linux/timer.h | 15 ++++++++++++++- kernel/time/timer.c | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -169,7 +169,6 @@ static inline int timer_pending(const st } extern void add_timer_on(struct timer_list *timer, int cpu); -extern int del_timer(struct timer_list * timer); extern int mod_timer(struct timer_list *timer, unsigned long expires); extern int mod_timer_pending(struct timer_list *timer, unsigned long expires); extern int timer_reduce(struct timer_list *timer, unsigned long expires); @@ -184,6 +183,7 @@ extern void add_timer(struct timer_list extern int try_to_del_timer_sync(struct timer_list *timer); extern int timer_delete_sync(struct timer_list *timer); +extern int timer_delete(struct timer_list *timer); /** * del_timer_sync - Delete a pending timer and wait for a running callback @@ -198,6 +198,19 @@ static inline int del_timer_sync(struct return timer_delete_sync(timer); } +/** + * del_timer - Delete a pending timer + * @timer: The timer to be deleted + * + * See timer_delete() for detailed explanation. + * + * Do not use in new code. Use timer_delete() instead. + */ +static inline int del_timer(struct timer_list *timer) +{ + return timer_delete(timer); +} + extern void init_timers(void); struct hrtimer; extern enum hrtimer_restart it_real_fn(struct hrtimer *); --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1252,7 +1252,7 @@ void add_timer_on(struct timer_list *tim EXPORT_SYMBOL_GPL(add_timer_on); /** - * del_timer - Deactivate a timer. + * timer_delete - Deactivate a timer. * @timer: The timer to be deactivated * * Contrary to timer_delete_sync() this function does not wait for an @@ -1264,7 +1264,7 @@ EXPORT_SYMBOL_GPL(add_timer_on); * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -int del_timer(struct timer_list *timer) +int timer_delete(struct timer_list *timer) { struct timer_base *base; unsigned long flags; @@ -1280,7 +1280,7 @@ int del_timer(struct timer_list *timer) return ret; } -EXPORT_SYMBOL(del_timer); +EXPORT_SYMBOL(timer_delete); /** * try_to_del_timer_sync - Try to deactivate a timer From patchwork Tue Nov 15 20:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2928988wru; Tue, 15 Nov 2022 12:33:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AOGHESs4h+0wFXPkXxNxl1ShD+6LDVNdmmZeZTb6/ee8Rra71LbB9FdX5sXrKQ/o7zbok X-Received: by 2002:a63:185c:0:b0:452:8774:d5ab with SMTP id 28-20020a63185c000000b004528774d5abmr17727260pgy.74.1668544411571; Tue, 15 Nov 2022 12:33:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544411; cv=none; d=google.com; s=arc-20160816; b=rnJXM+GXLgPF6rKb3dyb9o8b5EpzA6gJ1HuHwcwsbdxUcquZLZSn5omfyUMCm3uEJO LZXNi/C3qyiNee5bvSusxjbh58PSInGKwBPgjIb0oySKRV+1M/g9X3c4NZc7Aw5EjiWn CNq01p1MemdsqM8hagkpdGD1/FUYuL45MKnqQKZjSmpohPG4+ly82tJG+KF4v5QJ8+Gx Azoy1zbrQTQsVE1vhZIObQy9oekcVySem2d4wwN0lX6CCVWRyXWt3UqyWODdnEkkgeUb pSZCi9kepORY2OjLQgkeAQKy6XCSU6mI6niVwHjbDkSwRG7grKxRyMsBqXe8efrG1nW0 BZaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=SxmsamQKO8OkpV2q7TQuf2k1ewfFDi/3K4xIkU+U+FA=; b=bq5bFTeTwWmpSWW/ZhXk15mv/7swap9/gzQk3LFA/0/wrGvqBF1VGr3YwaJuCgcESd 9KGIZxO0Uz6gFSYXqAcSIt1BSeAOjpppt1nFMRv6r51YeY4EIehPp5FQpbrg+Wu0weCa x+M7yXu7iEyyZR2LIzrvd5rlFBzSOEKQgqf85zLFSj4l4W81PHiEZMd5o34PfXJubRob yJOcTDMFcC9ydrp2vU1XnSV1mCKUtbH0U5ybFSBgVx5KNL269i2BrKIabrjklTOczDOc OtA+0BLC4IMSb4Y+jh7w/hcmAhxmbdXMnWP4GQdI28Af+vUm1lT7G4e3PPETZ9qHohK2 wzdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZrKO38gF; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l192-20020a6391c9000000b00470004b8407si13178882pge.574.2022.11.15.12.33.17; Tue, 15 Nov 2022 12:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=ZrKO38gF; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbiKOUaX (ORCPT + 99 others); Tue, 15 Nov 2022 15:30:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbiKOU3v (ORCPT ); Tue, 15 Nov 2022 15:29:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F3C2C65C; Tue, 15 Nov 2022 12:28:51 -0800 (PST) Message-ID: <20221115202117.560506554@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544130; 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: references:references; bh=SxmsamQKO8OkpV2q7TQuf2k1ewfFDi/3K4xIkU+U+FA=; b=ZrKO38gF+2iYdI0mZW42EdhLVffO2HDAY5Qlmu6U35oVTvzQgn37kNusNfS4zFw/Xv1IpI Cfhqi84/3Pj3FWCF1Rmk76SbVjJ3RXrUGSshc9S336mQ/za9grPJhelKgpNXVRkBJSAfXC M4vEhW5clGgEpri/vWQ5KHUH5KJo7tI2OSIyqrGW3HscobQSuEiGrcsCntOWeO23Hkd/U2 sQpzzrRzLS99G4MWjLeu9ylvpUA1pslVF8K/0mO43BzkugatvNYAE1gxwt2n4MNAL75G8E anACnCNlMLl3L0TPN0rYjbBuwCyV72FniUoluZo2o9eziNmauPZn0mdLdj1Ozw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544130; 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: references:references; bh=SxmsamQKO8OkpV2q7TQuf2k1ewfFDi/3K4xIkU+U+FA=; b=d6TOZiz/wlnmLvLXJoDwcXe/phqBW/oIPCdnJ5iSWkiCzcYNsyrfqVUqvxafZVM6bZsDOA yQTgdVhsGI5jPTCg== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 10/15] timers: Silently ignore timers with a NULL function References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:49 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595624880020311?= X-GMAIL-MSGID: =?utf-8?q?1749595624880020311?= Tearing down timers which have circular dependencies to other functionality, e.g. workqueues, where the timer can schedule work and work can arm timers is not trivial. In those cases it is desired to shutdown the timer in a way which prevents rearming of the timer. The mechanism to do so it to set timer->function to NULL and use this as an indicator for the timer arming functions to ignore the (re)arm request. In preparation for that replace the warnings in the relevant code pathes with checks for timer->function == NULL and discard the rearm request silently. Add debug_assert_init() instead of the WARN_ON_ONCE(!timer->function) checks so that debug objects can warn about non-initialized timers. If developers fail to enable debug objects and then waste lots of time to figure out why their non-initialized timer is not firing, they deserve it. Co-developed-by: Steven Rostedt Signed-off-by: Steven Rostedt Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org --- kernel/time/timer.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1017,7 +1017,7 @@ static inline int unsigned int idx = UINT_MAX; int ret = 0; - BUG_ON(!timer->function); + debug_assert_init(timer); /* * This is a common optimization triggered by the networking code - if @@ -1044,6 +1044,14 @@ static inline int * dequeue/enqueue dance. */ base = lock_timer_base(timer, &flags); + /* + * Has @timer been shutdown? This needs to be evaluated + * while holding base lock to prevent a race against the + * shutdown code. + */ + if (!timer->function) + goto out_unlock; + forward_timer_base(base); if (timer_pending(timer) && (options & MOD_TIMER_REDUCE) && @@ -1070,6 +1078,14 @@ static inline int } } else { base = lock_timer_base(timer, &flags); + /* + * Has @timer been shutdown? This needs to be evaluated + * while holding base lock to prevent a race against the + * shutdown code. + */ + if (!timer->function) + goto out_unlock; + forward_timer_base(base); } @@ -1128,6 +1144,9 @@ static inline int * mod_timer_pending() is the same for pending timers as mod_timer(), but * will not activate inactive timers. * + * If @timer->function == NULL then the start operation is silently + * discarded. + * * Return: * * %0 - The timer was inactive and not modified * * %1 - The timer was active and requeued to expire at @expires @@ -1154,6 +1173,9 @@ EXPORT_SYMBOL(mod_timer_pending); * same timer, then mod_timer() is the only safe way to modify the timeout, * since add_timer() cannot modify an already running timer. * + * If @timer->function == NULL then the start operation is silently + * discarded, the return value is 0 and meaningless. + * * Return: * * %0 - The timer was inactive and started * * %1 - The timer was active and requeued to expire at @expires or @@ -1175,6 +1197,9 @@ EXPORT_SYMBOL(mod_timer); * modify an enqueued timer if that would reduce the expiration time. If * @timer is not enqueued it starts the timer. * + * If @timer->function == NULL then the start operation is silently + * discarded. + * * Return: * * %0 - The timer was inactive and started * * %1 - The timer was active and requeued to expire at @expires or @@ -1201,6 +1226,9 @@ EXPORT_SYMBOL(timer_reduce); * * If @timer->expires is already in the past @timer will be queued to * expire at the next timer tick. + * + * If @timer->function == NULL then the start operation is silently + * discarded. */ void add_timer(struct timer_list *timer) { @@ -1217,13 +1245,18 @@ EXPORT_SYMBOL(add_timer); * * This can only operate on an inactive timer. Attempts to invoke this on * an active timer are rejected with a warning. + * + * If @timer->function == NULL then the start operation is silently + * discarded. */ void add_timer_on(struct timer_list *timer, int cpu) { struct timer_base *new_base, *base; unsigned long flags; - if (WARN_ON_ONCE(timer_pending(timer) || !timer->function)) + debug_assert_init(timer); + + if (WARN_ON_ONCE(timer_pending(timer))) return; new_base = get_timer_cpu_base(timer->flags, cpu); @@ -1234,6 +1267,13 @@ void add_timer_on(struct timer_list *tim * wrong base locked. See lock_timer_base(). */ base = lock_timer_base(timer, &flags); + /* + * Has @timer been shutdown? This needs to be evaluated while + * holding base lock to prevent a race against the shutdown code. + */ + if (!timer->function) + goto out_unlock; + if (base != new_base) { timer->flags |= TIMER_MIGRATING; @@ -1247,6 +1287,7 @@ void add_timer_on(struct timer_list *tim debug_timer_activate(timer); internal_add_timer(base, timer); +out_unlock: raw_spin_unlock_irqrestore(&base->lock, flags); } EXPORT_SYMBOL_GPL(add_timer_on); @@ -1532,6 +1573,12 @@ static void expire_timers(struct timer_b fn = timer->function; + if (WARN_ON_ONCE(!fn)) { + /* Should never happen. Emphasis on should! */ + base->running_timer = NULL; + return; + } + if (timer->flags & TIMER_IRQSAFE) { raw_spin_unlock(&base->lock); call_timer_fn(timer, fn, baseclk); From patchwork Tue Nov 15 20:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2932779wru; Tue, 15 Nov 2022 12:44:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TjAPEFvhK7NYuXWD3oVxg2XE3AgBQjgjC/tjh8ELTvOyPL3ODz57/bssEwCMjJnD2RLR5 X-Received: by 2002:a05:6402:b61:b0:461:ed40:c2f2 with SMTP id cb1-20020a0564020b6100b00461ed40c2f2mr16117631edb.404.1668545082137; Tue, 15 Nov 2022 12:44:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668545082; cv=none; d=google.com; s=arc-20160816; b=OLg4CfS5cUbF4oWlI5F+du1qd98s0tYPmgidvbvMafQMIC8xFbNLTFUKzQN79JtUNb 3Iuuoj3Y0Tjss1hGiPDEl6lBcizjTOPgDiVJOfdHdMsPM20AM2jCfuBvYv7pJOyeSl2D 0ooIUT9AZCdEwJMh8rIxTQjbI9HKIyinm2oN8So1LKGpUINHgiWh9MDHpShKBgkRCcqr YJcAp6U2jKZv1Sqy6RFb3fCUNZle/+p+5XLseziK2/ccRfs3KtocsIvx8bZAppJdC/i6 VnAU54bRscPjC6WtJOK/OMywyFYXj1e1EQ/ei2nZVmX9K3z+waPViCYaXbEJPACSQHDv KWKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=0ZlvY9ool6Ve+kUwOJkRD108DUOqW8Zib/pBYB0+vgk=; b=ieiKYllocU6awRQo8C81D0W4PctC/yqbPjflOIuRdTQG6Ik2BFvdiyTHZs6kGQbi+J eiHeRkFzbuW1IlgIMEzmAGmqFJgPU8FmiaTekgP4CovxaKhpNiWqzvh7iXsjDfvZ+Dyy ZpqTttiCdRSMaVQTK4hAePXwzj5KWxFK4mqQ3RklqTyFuG4yTlJqXVDURQ5kjD+tw0Zn +S0GXpmzr17rtigEwemyBRbx5sK3KAcdF8u+iz5F1GrwpTPBB6cjHSqCzqbYJ3J2Gbij dMd8g3JeG6PNtk9ZKx5kI2Us8jE8/OISuFwK1cRIxTiESIx1cVesV6aNBFlYmnC9Eh/x 16DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xFaX+k2V; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr6-20020a1709073f8600b007ad86fb5914si16127464ejc.917.2022.11.15.12.44.18; Tue, 15 Nov 2022 12:44:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=xFaX+k2V; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238085AbiKOUaf (ORCPT + 99 others); Tue, 15 Nov 2022 15:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbiKOU3w (ORCPT ); Tue, 15 Nov 2022 15:29:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 576232E688; Tue, 15 Nov 2022 12:28:53 -0800 (PST) Message-ID: <20221115202117.618987487@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544132; 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: references:references; bh=0ZlvY9ool6Ve+kUwOJkRD108DUOqW8Zib/pBYB0+vgk=; b=xFaX+k2VM8PXVE37HnWdfEYAyM5Zri33jJRXYDZ6OQ/qJKRiDh+mRrWz26q5mXkkCQy0C9 OgyufN/x9BczOdWYGaRyr/kyNbXdANSnerf/n21I2C6DAQXabjD23YNkVijJWOXj3sV4k1 bGfh8aJaNobtgpNOkcoROzI8uIPRSAtkjKY4lUOzTsqrQP2MHukX63mV7KsMPgPYZgibwn Lag0cjdUdjsYUpcsnUit0fFu6YSH5GAKFWb8PT6R0yXSq+++FwPbRMwk2eRFrMi4+5zzg8 VN+GKeddbDuUFUxtENU1B/V4Hb4QDCCTJsb36PKC1Qb4vnERxpf7xpg1PYZsSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544132; 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: references:references; bh=0ZlvY9ool6Ve+kUwOJkRD108DUOqW8Zib/pBYB0+vgk=; b=NJgs5/ebD7dQ0piSM2TFYFDuzA+DPBpImSZ+DQaXcZW/iHBwo6EdCY5vbnTTcULFYo+z2Y njB7NocJThPzE1BQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 11/15] timers: Split [try_to_]del_timer[_sync]() to prepare for shutdown mode References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:51 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596327786138969?= X-GMAIL-MSGID: =?utf-8?q?1749596327786138969?= Tearing down timers which have circular dependencies to other functionality, e.g. workqueues, where the timer can schedule work and work can arm timers is not trivial. In those cases it is desired to shutdown the timer in a way which prevents rearming of the timer. The mechanism to do so it to set timer->function to NULL and use this as an indicator for the timer arming functions to ignore the (re)arm request. Split the inner workings of try_do_del_timer_sync(), del_timer_sync() and del_timer() into helper functions to prepare for implementing the shutdown functionality. No functional change. Co-developed-by: Steven Rostedt Signed-off-by: Steven Rostedt Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org --- kernel/time/timer.c | 136 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 47 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1293,19 +1293,14 @@ void add_timer_on(struct timer_list *tim EXPORT_SYMBOL_GPL(add_timer_on); /** - * timer_delete - Deactivate a timer. + * __timer_delete - Internal function: Deactivate a timer. * @timer: The timer to be deactivated * - * Contrary to timer_delete_sync() this function does not wait for an - * eventually running timer callback on a different CPU and it neither - * prevents rearming of the timer. If @timer can be rearmed concurrently - * then the return value of this function is meaningless. - * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -int timer_delete(struct timer_list *timer) +static int __timer_delete(struct timer_list *timer) { struct timer_base *base; unsigned long flags; @@ -1321,22 +1316,36 @@ int timer_delete(struct timer_list *time return ret; } + +/** + * timer_delete - Deactivate a timer. + * @timer: The timer to be deactivated + * + * Contrary to timer_delete_sync() this function does not wait for an + * eventually running timer callback on a different CPU and it neither + * prevents rearming of the timer. If @timer can be rearmed concurrently + * then the return value of this function is meaningless. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated + */ +int timer_delete(struct timer_list *timer) +{ + return __timer_delete(timer); +} EXPORT_SYMBOL(timer_delete); /** - * try_to_del_timer_sync - Try to deactivate a timer + * __try_to_del_timer_sync - Internal function: Try to deactivate a timer * @timer: Timer to deactivate * - * This function cannot guarantee that the timer cannot be rearmed right - * after dropping the base lock. That needs to be prevented by the calling - * code if necessary. - * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated * * %-1 - The timer callback function is running on a different CPU */ -int try_to_del_timer_sync(struct timer_list *timer) +static int __try_to_del_timer_sync(struct timer_list *timer) { struct timer_base *base; unsigned long flags; @@ -1353,6 +1362,25 @@ int try_to_del_timer_sync(struct timer_l return ret; } + +/** + * try_to_del_timer_sync - Try to deactivate a timer + * @timer: Timer to deactivate + * + * This function cannot guarantee that the timer cannot be rearmed + * right after dropping the base lock. That needs to be prevented + * by the calling code if necessary. If the timer can be rearmed + * concurrently then the return value is meaningless. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated + * * %-1 - The timer callback function is running on a different CPU + */ +int try_to_del_timer_sync(struct timer_list *timer) +{ + return __try_to_del_timer_sync(timer); +} EXPORT_SYMBOL(try_to_del_timer_sync); #ifdef CONFIG_PREEMPT_RT @@ -1429,45 +1457,15 @@ static inline void del_timer_wait_runnin #endif /** - * timer_delete_sync - Deactivate a timer and wait for the handler to finish. + * __timer_delete_sync - Internal function: Deactivate a timer and wait + * for the handler to finish. * @timer: The timer to be deactivated * - * Synchronization rules: Callers must prevent restarting of the timer, - * otherwise this function is meaningless. It must not be called from - * interrupt contexts unless the timer is an irqsafe one. The caller must - * not hold locks which would prevent completion of the timer's callback - * function. The timer's handler must not call add_timer_on(). Upon exit - * the timer is not queued and the handler is not running on any CPU. - * - * For !irqsafe timers, the caller must not hold locks that are held in - * interrupt context. Even if the lock has nothing to do with the timer in - * question. Here's why:: - * - * CPU0 CPU1 - * ---- ---- - * - * call_timer_fn(); - * base->running_timer = mytimer; - * spin_lock_irq(somelock); - * - * spin_lock(somelock); - * timer_delete_sync(mytimer); - * while (base->running_timer == mytimer); - * - * Now timer_delete_sync() will never return and never release somelock. - * The interrupt on the other CPU is waiting to grab somelock but it has - * interrupted the softirq that CPU0 is waiting to finish. - * - * This function cannot guarantee that the timer is not rearmed again by - * some concurrent or preempting code, right after it dropped the base - * lock. If there is the possibility of a concurrent rearm then the return - * value of the function is meaningless. - * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -int timer_delete_sync(struct timer_list *timer) +static int __timer_delete_sync(struct timer_list *timer) { int ret; @@ -1497,7 +1495,7 @@ int timer_delete_sync(struct timer_list lockdep_assert_preemption_enabled(); do { - ret = try_to_del_timer_sync(timer); + ret = __try_to_del_timer_sync(timer); if (unlikely(ret < 0)) { del_timer_wait_running(timer); @@ -1507,6 +1505,50 @@ int timer_delete_sync(struct timer_list return ret; } + +/** + * timer_delete_sync - Deactivate a timer and wait for the handler to finish. + * @timer: The timer to be deactivated + * + * Synchronization rules: Callers must prevent restarting of the timer, + * otherwise this function is meaningless. It must not be called from + * interrupt contexts unless the timer is an irqsafe one. The caller must + * not hold locks which would prevent completion of the timer's callback + * function. The timer's handler must not call add_timer_on(). Upon exit + * the timer is not queued and the handler is not running on any CPU. + * + * For !irqsafe timers, the caller must not hold locks that are held in + * interrupt context. Even if the lock has nothing to do with the timer in + * question. Here's why:: + * + * CPU0 CPU1 + * ---- ---- + * + * call_timer_fn(); + * base->running_timer = mytimer; + * spin_lock_irq(somelock); + * + * spin_lock(somelock); + * timer_delete_sync(mytimer); + * while (base->running_timer == mytimer); + * + * Now timer_delete_sync() will never return and never release somelock. + * The interrupt on the other CPU is waiting to grab somelock but it has + * interrupted the softirq that CPU0 is waiting to finish. + * + * This function cannot guarantee that the timer is not rearmed again by + * some concurrent or preempting code, right after it dropped the base + * lock. If there is the possibility of a concurrent rearm then the return + * value of the function is meaningless. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending and deactivated + */ +int timer_delete_sync(struct timer_list *timer) +{ + return __timer_delete_sync(timer); +} EXPORT_SYMBOL(timer_delete_sync); static void call_timer_fn(struct timer_list *timer, From patchwork Tue Nov 15 20:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2932386wru; Tue, 15 Nov 2022 12:43:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf42ScCvF0sJZVTDna2rD+R6fXmzWCZai5fb60PueKvtWJmF1QUJtV7iMtx6IrBYXEOA/5c2 X-Received: by 2002:aa7:d803:0:b0:467:67e1:ca61 with SMTP id v3-20020aa7d803000000b0046767e1ca61mr16019163edq.27.1668545011145; Tue, 15 Nov 2022 12:43:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668545011; cv=none; d=google.com; s=arc-20160816; b=uuFv2eIgU8DuYzWLTeGkqE3pWl/tCwaInRRXovoexkNYLCXRfeCScCltilfxM1gnft ubpekzwVlMyWjFgMX8DWa37EoI2OoU9AWSKGo9CDtpxK32e8BHvzTAOi6ipMcXn8/aON /NebbjX+Wgh5JgUhlgNCSu/BJmAmy4vAaK+N2IVeEDk08Wpo/xdak0LasnjUjJ3gYwmd khN/VmIc6yivQWBKo/GeVPG0I2v2wew0WgC1qBRYmpMthwP7dq3zJwL0Goqs1ciG8NZ8 Hcp3KsuVHcfL4K0XSOVnaKn6wefR4fD6l32xU/lB/Bw5juEbNCqPjj/KLOo8Veb2foff 0Rbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=CMA3/F6shbK4k7ry5l4qNuN5eRgfA3B1IvghuSgAvLA=; b=Vi9Smxid8oO1NkAmIiw0bljzIfKgq+w9zJxdL8ngB97tX+TULQtvK52RB8b26/9YHT 2WvYPepORN97KxgE29wsGWxJyydZ6INMGFzA7m3eHlcXb1+k+BUezNCarT0HjAHiWFl5 +qqoxzOnUjdkXUJRhcXlFl/JgIntEDvKbnLrw2ZR/VwnBxqaRmkjTgHIkUXGH8tjGcyk EC3lKNUkYRE12uteO9U5TKQI+Vuo6UA+7No3D9F5uqMyjwOW0ld/gP7aEbEZC7c4c5Ph pbWiwoHdNRIXtiQ26mJmTmHWp2E83CV7prk7wiCBwMqapETi7HJEdKn/ip4m/AFZSnx3 hWiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yXmSHTSo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a05640227cb00b0046151310d6dsi6312992ede.498.2022.11.15.12.43.06; Tue, 15 Nov 2022 12:43:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=yXmSHTSo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238429AbiKOUaj (ORCPT + 99 others); Tue, 15 Nov 2022 15:30:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbiKOU3y (ORCPT ); Tue, 15 Nov 2022 15:29:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A7F2F39B; Tue, 15 Nov 2022 12:28:54 -0800 (PST) Message-ID: <20221115202117.677534558@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544133; 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: references:references; bh=CMA3/F6shbK4k7ry5l4qNuN5eRgfA3B1IvghuSgAvLA=; b=yXmSHTSo1ZQBpUliMVqpYYG71tsCxggZcVcgvKFqSOyHDhC63Uqh3jC+og91pGV0qu7F/d 7dkIqQWHMbFpczm9+SdH3WrXhNO+gmXjwsDHL7tn7X/LQQKKbuk1zbNfPdP1Kgf/E6rJ7M C4vR+d6yklxYLcl/St5gAeP7zOvynm+KSdvxU8A0IhkBWun9QONlQWp0hwXvMXGJ35XZQP mV6ZDj4bn4N/wl0e9ngYMZmhabiXlqSADctDCm/6yNQqkXewNTeRbFug6bdJNrf4oY8AK0 mKuV87A5OUW6EKbP3ayxghf/pnHwj1cjuvT/sq+oburuNOJo23eatGhyBiGJ1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544133; 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: references:references; bh=CMA3/F6shbK4k7ry5l4qNuN5eRgfA3B1IvghuSgAvLA=; b=0Hc8vR2pcI5jKQgmf03VNuXybj0omi1sTaKONPNs1f9g+9R23oUxHa98ZNt+5iOhYyO9GI FNnH4uXINeUStgAg== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 12/15] timers: Add shutdown mechanism to the internal functions References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:52 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749596253185787535?= X-GMAIL-MSGID: =?utf-8?q?1749596253185787535?= Tearing down timers which have circular dependencies to other functionality, e.g. workqueues, where the timer can schedule work and work can arm timers is not trivial. In those cases it is desired to shutdown the timer in a way which prevents rearming of the timer. The mechanism to do so it to set timer->function to NULL and use this as an indicator for the timer arming functions to ignore the (re)arm request. Add a shutdown argument to the relevant internal functions which makes the actual deactivation code set timer->function to NULL which in turn prevents rearming of the timer. Co-developed-by: Steven Rostedt Signed-off-by: Steven Rostedt Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org --- kernel/time/timer.c | 64 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 9 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1293,14 +1293,21 @@ void add_timer_on(struct timer_list *tim EXPORT_SYMBOL_GPL(add_timer_on); /** - * __timer_delete - Internal function: Deactivate a timer. + * __timer_delete - Internal function: Deactivate a timer * @timer: The timer to be deactivated + * @shutdown: If true this indicates that the timer is about to be + * shutdown permanently. + * + * If @shutdown is true then @timer->function is set to NULL under the + * timer base lock which prevents further rearming of the time. In that + * case any attempt to rearm @timer after this function returns will be + * silently ignored. * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -static int __timer_delete(struct timer_list *timer) +static int __timer_delete(struct timer_list *timer, bool shutdown) { struct timer_base *base; unsigned long flags; @@ -1308,9 +1315,22 @@ static int __timer_delete(struct timer_l debug_assert_init(timer); - if (timer_pending(timer)) { + /* + * If @shutdown is set then the lock has to be taken whether the + * timer is pending or not to protect against a concurrent rearm + * which might hit between the lockless pending check and the lock + * aquisition. By taking the lock it is ensured that such a newly + * enqueued timer is dequeued and cannot end up with + * timer->function == NULL in the expiry code. + * + * If timer->function is currently executed, then this makes sure + * that the callback cannot requeue the timer. + */ + if (timer_pending(timer) || shutdown) { base = lock_timer_base(timer, &flags); ret = detach_if_pending(timer, base, true); + if (shutdown) + timer->function = NULL; raw_spin_unlock_irqrestore(&base->lock, flags); } @@ -1332,20 +1352,31 @@ static int __timer_delete(struct timer_l */ int timer_delete(struct timer_list *timer) { - return __timer_delete(timer); + return __timer_delete(timer, false); } EXPORT_SYMBOL(timer_delete); /** * __try_to_del_timer_sync - Internal function: Try to deactivate a timer * @timer: Timer to deactivate + * @shutdown: If true this indicates that the timer is about to be + * shutdown permanently. + * + * If @shutdown is true then @timer->function is set to NULL under the + * timer base lock which prevents further rearming of the timer. Any + * attempt to rearm @timer after this function returns will be silently + * ignored. + * + * This function cannot guarantee that the timer cannot be rearmed + * right after dropping the base lock if @shutdown is false. That + * needs to be prevented by the calling code if necessary. * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated * * %-1 - The timer callback function is running on a different CPU */ -static int __try_to_del_timer_sync(struct timer_list *timer) +static int __try_to_del_timer_sync(struct timer_list *timer, bool shutdown) { struct timer_base *base; unsigned long flags; @@ -1357,6 +1388,8 @@ static int __try_to_del_timer_sync(struc if (base->running_timer != timer) ret = detach_if_pending(timer, base, true); + if (shutdown) + timer->function = NULL; raw_spin_unlock_irqrestore(&base->lock, flags); @@ -1379,7 +1412,7 @@ static int __try_to_del_timer_sync(struc */ int try_to_del_timer_sync(struct timer_list *timer) { - return __try_to_del_timer_sync(timer); + return __try_to_del_timer_sync(timer, false); } EXPORT_SYMBOL(try_to_del_timer_sync); @@ -1460,12 +1493,25 @@ static inline void del_timer_wait_runnin * __timer_delete_sync - Internal function: Deactivate a timer and wait * for the handler to finish. * @timer: The timer to be deactivated + * @shutdown: If true @timer->function will be set to NULL under the + * timer base lock which prevents rearming of @timer + * + * If @shutdown is not set the timer can be rearmed later. If the timer can + * be rearmed concurrently, i.e. after dropping the base lock then the + * return value is meaningless. + * + * If @shutdown is set then @timer->function is set to NULL under timer + * base lock which prevents rearming of the timer. Any attempt to rearm + * a shutdown timer is silently ignored. + * + * If the timer should be reused after shutdown it has to be initialized + * again. * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated */ -static int __timer_delete_sync(struct timer_list *timer) +static int __timer_delete_sync(struct timer_list *timer, bool shutdown) { int ret; @@ -1495,7 +1541,7 @@ static int __timer_delete_sync(struct ti lockdep_assert_preemption_enabled(); do { - ret = __try_to_del_timer_sync(timer); + ret = __try_to_del_timer_sync(timer, shutdown); if (unlikely(ret < 0)) { del_timer_wait_running(timer); @@ -1547,7 +1593,7 @@ static int __timer_delete_sync(struct ti */ int timer_delete_sync(struct timer_list *timer) { - return __timer_delete_sync(timer); + return __timer_delete_sync(timer, false); } EXPORT_SYMBOL(timer_delete_sync); From patchwork Tue Nov 15 20:28:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2933320wru; Tue, 15 Nov 2022 12:46:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf7yEuXc14v7CvxK6UHys/S3Q45yG3Rbw+4ljW0a/ytUHgB+CBQWuqLAVFAfkHVMWTq2DC9A X-Received: by 2002:a17:906:1c0e:b0:789:d492:89f5 with SMTP id k14-20020a1709061c0e00b00789d49289f5mr15962655ejg.103.1668545184976; Tue, 15 Nov 2022 12:46:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668545184; cv=none; d=google.com; s=arc-20160816; b=mNDXrIQkOFDEm5iMbkaXnC4YvlDpQdwj4s2VLrpfQFkVVkzbeRzXUcF+b2XWHvmFxD AlduwdImcS/uP0Gh4blXZy8qwMP2UBSdYNS56ftqQdVJ9u/eipMP65FR3VtzVlHkG0D2 vjdeIZwHp+0mP6Os3Ib0N2qxC4LnLEbvLJjtmYmt+Bzs4WHVXa7B07NoEtKpeXmWyZDp WXQyx3w8rR354STPdYXXqk2tfnFjy5qtqvrevoaW7MqZgs6CEUFzHbvd++tpXlX91xue 7dRjMDS5tCq/W15pduHgzLo2m8ggsH7cU5GLVE66HGBGWJqi8KiIkEn4JoaFrIKg8nmG OnWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=OpHwjOnh4n2ouDGqJq7UHmNfkqTHGyLXhgGNomWMTL8=; b=FObNccKH0ohSjVp/wlukI/dmzYnURRvrVUUnTRImPEBETuA+c9vfr+MlnQjOFh0Sia QCfkPiUyXDyRLuxMzCVuwSTbgaKv4I0UmMOPbun9JsprEcus/1UinpQtH6oFWZOtU60C I12ffPp79v56NRkqUwhfChlXei5lKhScpov2vsfjcy7zlgtsn85jdXRdpOmEa7TOyAbI T615Xnr9FKZXJ0byciX6l1WW2gIaLWvoKwX2MGWyc/P2K+3Yr412cvCYWGSZNK/ANYJM cvED2u9g6DY+dtCeAforpjlTFcO+oBZ6b0Fyb8wPVNLb1kt3XJP5XJ1xFHv8T5tTtGTK TZ2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iaxbbzgB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9xaeUZyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js6-20020a17090797c600b0078dffe01cbesi14120583ejc.4.2022.11.15.12.46.00; Tue, 15 Nov 2022 12:46:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=iaxbbzgB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9xaeUZyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbiKOUbE (ORCPT + 99 others); Tue, 15 Nov 2022 15:31:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232839AbiKOU36 (ORCPT ); Tue, 15 Nov 2022 15:29:58 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E6330577; Tue, 15 Nov 2022 12:28:56 -0800 (PST) Message-ID: <20221115202117.734852797@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544135; 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: references:references; bh=OpHwjOnh4n2ouDGqJq7UHmNfkqTHGyLXhgGNomWMTL8=; b=iaxbbzgBzX6LpFDrEhsMRJlwE/ucdDOLH3g8tpfT6ie1wrorVhv2qekUUqjtJ1dhYc1i+r W5RdSgX+HOwo1dAzqtX9/56X2jUhMZMbMTrqkT4hGO0GszaSqY8mRDW/BXat0Oc5BcsZpQ tQDi5LuQ+BqrcAwgx1KTgL14McMIISwekmqrVw8Zy0rey2vT6yYLjEVqyuNu0DLiAMkqZ6 zqzNG4QbKby5PMUb7mbFgNgXRTxWPaFLw8KF1r8yfM3u+yh/6RQAi/Shfn/zozYEDz31MG j868C8MBHq6VJEWM26a5+GL0rbT3urbICzN74RSJSmlwkfYzWwXJEHcMuDGI0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544135; 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: references:references; bh=OpHwjOnh4n2ouDGqJq7UHmNfkqTHGyLXhgGNomWMTL8=; b=9xaeUZySIPDSxCd9axx87kzIobpZc7nGEbaHSSosrmv3Ak008tbG1XKM7hLxwKT/suRF93 c8YoYSaOFba3k4DA== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 13/15] timers: Provide timer_shutdown[_sync]() References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:54 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595349054994232?= X-GMAIL-MSGID: =?utf-8?q?1749596436073485562?= Tearing down timers which have circular dependencies to other functionality, e.g. workqueues, where the timer can schedule work and work can arm timers is not trivial. In those cases it is desired to shutdown the timer in a way which prevents rearming of the timer. The mechanism to do so it to set timer->function to NULL and use this as an indicator for the timer arming functions to ignore the (re)arm request. Expose new interfaces for this: timer_shutdown_sync() and timer_shutdown(). timer_shutdown_sync() has the same functionality as timer_delete_sync() plus the NULL-ification of the timer function. timer_shutdown() has the same functionality as timer_delete() plus the NULL-ification of the timer function. In both cases the rearming of the timer is prevented by silently discarding rearm attempts due to timer->function being NULL. Co-developed-by: Steven Rostedt Signed-off-by: Steven Rostedt Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home Link: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org --- include/linux/timer.h | 2 + kernel/time/timer.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -184,6 +184,8 @@ extern void add_timer(struct timer_list extern int try_to_del_timer_sync(struct timer_list *timer); extern int timer_delete_sync(struct timer_list *timer); extern int timer_delete(struct timer_list *timer); +extern int timer_shutdown_sync(struct timer_list *timer); +extern int timer_shutdown(struct timer_list *timer); /** * del_timer_sync - Delete a pending timer and wait for a running callback --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1357,6 +1357,27 @@ int timer_delete(struct timer_list *time EXPORT_SYMBOL(timer_delete); /** + * timer_shutdown - Deactivate a timer and prevent rearming + * @timer: The timer to be deactivated + * + * The function does not wait for an eventually running timer callback on a + * different CPU but it prevents rearming of the timer. Any attempt to arm + * @timer after this function returns will be silently ignored. + * + * This function is useful for teardown code and should only be used when + * timer_shutdown_sync() cannot be invoked due to locking or context constraints. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending + */ +int timer_shutdown(struct timer_list *timer) +{ + return __timer_delete(timer, true); +} +EXPORT_SYMBOL_GPL(timer_shutdown); + +/** * __try_to_del_timer_sync - Internal function: Try to deactivate a timer * @timer: Timer to deactivate * @shutdown: If true this indicates that the timer is about to be @@ -1587,6 +1608,9 @@ static int __timer_delete_sync(struct ti * lock. If there is the possibility of a concurrent rearm then the return * value of the function is meaningless. * + * If such a guarantee is needed, e.g. for teardown situations then use + * timer_shutdown_sync() instead. + * * Return: * * %0 - The timer was not pending * * %1 - The timer was pending and deactivated @@ -1597,6 +1621,48 @@ int timer_delete_sync(struct timer_list } EXPORT_SYMBOL(timer_delete_sync); +/** + * timer_shutdown_sync - Shutdown a timer and prevent rearming + * @timer: The timer to be shutdown + * + * When the function returns it is guaranteed that: + * - @timer is not queued + * - The callback function of @timer is not running + * - @timer cannot be enqueued again. Any attempt to rearm + * @timer is silently ignored. + * + * See timer_delete_sync() for synchronization rules. + * + * This function is useful for final teardown of an infrastructure where + * the timer is subject to a circular dependency problem. + * + * A common pattern for this is a timer and a workqueue where the timer can + * schedule work and work can arm the timer. On shutdown the workqueue must + * be destroyed and the timer must be prevented from rearming. Unless the + * code has conditionals like 'if (mything->in_shutdown)' to prevent that + * there is no way to get this correct with timer_delete_sync(). + * + * timer_shutdown_sync() is solving the problem. The correct ordering of + * calls in this case is: + * + * timer_shutdown_sync(&mything->timer); + * workqueue_destroy(&mything->workqueue); + * + * After this 'mything' can be safely freed. + * + * This obviously requires that the timer is not required to be functional + * for the rest of the shutdown operation. + * + * Return: + * * %0 - The timer was not pending + * * %1 - The timer was pending + */ +int timer_shutdown_sync(struct timer_list *timer) +{ + return __timer_delete_sync(timer, true); +} +EXPORT_SYMBOL_GPL(timer_shutdown_sync); + static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list *), unsigned long baseclk) From patchwork Tue Nov 15 20:28:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2930600wru; Tue, 15 Nov 2022 12:38:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5LMmzDB1lnAkk9Gu4F97xDRuRHL/ChYZegk/vnc72bU4j6RubG3SqLysRL6npldK6aKjvW X-Received: by 2002:a17:907:8b0a:b0:78d:99f2:a94e with SMTP id sz10-20020a1709078b0a00b0078d99f2a94emr15448552ejc.232.1668544703035; Tue, 15 Nov 2022 12:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544703; cv=none; d=google.com; s=arc-20160816; b=Yz85uYrSxPBB2trn/JoXaOZDTBxUM0HBeW2eySwYyOw37RLXAjbXx2IgqB+sEypYrE G4nN+EI+Nfs0snLj2bOsx3POjsRl01Q01xP/vpptP4/2DG31FhyynCPeYBof27l1NDFX /Hfpj3Fy68J/lq0okyEyXeqVC8yvuymkliQ0xQqdeOfqHKL1SZ0JVp7x+bg8UXto6Gyr pyhnKpqboCFGC3ET4ZsGJDG0YxDTIecUQkhMRsR9j8XFth+x4cpSQ2U+A7JOpYVsun2F pVR3mt6eVONPKVCcsp1PLrwP8P1A4/i992hORMgdu4fVMAEoFEUmf5zEBU1FfSSjIYsJ hdUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=kJsB0B8f0qFmQ81lyDCpvVT7DxA3aerH8vXT9O1XEA4=; b=A/SG5DWfXKzGKbroU3zM5hcxS4+88wWLea0jLIYPewMNWC2bDoWJ+kYJv/fdgdRJVI ZhPV4sIt/aDf5iof8vxrsTTHJX8qY8qNtLqgPDy5ZbVL+JFYY6qVIWAoU42THrlGG2sT ERU9YfgYjO0FXEZX8CmYIVyunncpVPjE6rSChzpKC3uWHn6GftHPBTDeYo6mzsrg3Qlu PDLSfzwUKeDmo6ScXVoq3xfqHJHiAe+EtwSN2XNCv+Skfyt1y42PlWcHp9usvzZQieDQ qDDa1xGtT+4Om2HMb8cW83zjs7NIoXJPflVRjq/2eK9Gq/kV+lvFhwHBeliYLC0m8bMe wg1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Pu8SGB0c; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wt13-20020a170906ee8d00b0078d1e08f1e5si13181277ejb.919.2022.11.15.12.37.58; Tue, 15 Nov 2022 12:38:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=Pu8SGB0c; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbiKOUbV (ORCPT + 99 others); Tue, 15 Nov 2022 15:31:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236982AbiKOUaH (ORCPT ); Tue, 15 Nov 2022 15:30:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 667FA30F6D; Tue, 15 Nov 2022 12:28:58 -0800 (PST) Message-ID: <20221115202117.792861106@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544136; 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: references:references; bh=kJsB0B8f0qFmQ81lyDCpvVT7DxA3aerH8vXT9O1XEA4=; b=Pu8SGB0c4W4WMOpJe5pArorCPiSQIfam8L1S5Y3Jy/MOZU7i/qTWWK04Wv2U0sTLgC41vH MHoPL+Jpgxoh8gNyIFsohKaXUFu8JEOSdN2CoBihJFNzVr/Cs4vzi1ETiRfX5m/SuaSEdO TqvCu2TViqhmsdshMLYVdLLWxEGSdQvruEXbDZnSDq301cajJDI0wiYrpvUkZwvizmSo7F ewcKB/ps/v1ulqAQxxuVDXOXyUGghbSDOLSqf2Ip/0chghKDhJp4PaOk9x+zjtrwEPxTBk PY1ZUTY824R52JGJ/hHQ+a4h6/fI3PA8FHtqV1PGOskSVMDBSQhcYgBjKvgQPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544136; 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: references:references; bh=kJsB0B8f0qFmQ81lyDCpvVT7DxA3aerH8vXT9O1XEA4=; b=F4IRW1/tgARIGOV4ZTNZkN6R2tHnpA0BWQ7F+t6okMkuF4n/c+Xhc2P3opbia4Q8r/2MGA CVzmleEVKnlNrPCA== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [patch 14/15] timers: Update the documentation to reflect on the new timer_shutdown() API References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:56 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595930516231450?= X-GMAIL-MSGID: =?utf-8?q?1749595930516231450?= From: "Steven Rostedt (Google)" In order to make sure that a timer is not re-armed after it is stopped before freeing, a new shutdown state is added to the timer code. The API timer_shutdown_sync() and timer_shutdown() must be called before the object that holds the timer can be freed. Update the documentation to reflect this new workflow. [ tglx: Updated to the new semantics and removed the bogus claim that del_timer_sync() returns the number of removal attempts ] Signed-off-by: Steven Rostedt (Google) Signed-off-by: Thomas Gleixner Tested-by: Guenter Roeck Link: https://lore.kernel.org/r/20221110064147.712934793@goodmis.org --- Documentation/RCU/Design/Requirements/Requirements.rst | 2 +- Documentation/core-api/local_ops.rst | 2 +- Documentation/kernel-hacking/locking.rst | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) --- a/Documentation/RCU/Design/Requirements/Requirements.rst +++ b/Documentation/RCU/Design/Requirements/Requirements.rst @@ -1858,7 +1858,7 @@ unloaded. After a given module has been one of its functions results in a segmentation fault. The module-unload functions must therefore cancel any delayed calls to loadable-module functions, for example, any outstanding mod_timer() must be dealt -with via del_timer_sync() or similar. +with via timer_shutdown_sync(). Unfortunately, there is no way to cancel an RCU callback; once you invoke call_rcu(), the callback function is eventually going to be --- a/Documentation/core-api/local_ops.rst +++ b/Documentation/core-api/local_ops.rst @@ -191,7 +191,7 @@ Here is a sample module which implements static void __exit test_exit(void) { - del_timer_sync(&test_timer); + timer_shutdown_sync(&test_timer); } module_init(test_init); --- a/Documentation/kernel-hacking/locking.rst +++ b/Documentation/kernel-hacking/locking.rst @@ -1003,11 +1003,14 @@ If 0, it means (in this case) that it is Another common problem is deleting timers which restart themselves (by -calling add_timer() at the end of their timer function). -Because this is a fairly common case which is prone to races, you should -use del_timer_sync() (``include/linux/timer.h``) to -handle this case. It returns the number of times the timer had to be -deleted before we finally stopped it from adding itself back in. +calling add_timer() at the end of their timer function). Because this is a +fairly common case which is prone to races, you should use del_timer_sync() +(``include/linux/timer.h``) to handle this case. + +Before freeing a timer, timer_shutdown() or timer_shutdown_sync() should be +called which will keep it from being rearmed. Any subsequent attempt to +rearm the timer will be silently ignored by the core code. + Locking Speed ============= From patchwork Tue Nov 15 20:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 20544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2929069wru; Tue, 15 Nov 2022 12:33:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Y7A4rzbPeJ90lp/7s8qxDzbsmbVg9tfm8rDTaIHlADmRCDornzGPXhmD5/KGN9H60/a8G X-Received: by 2002:a62:820d:0:b0:56b:fe1d:5735 with SMTP id w13-20020a62820d000000b0056bfe1d5735mr19555057pfd.24.1668544425006; Tue, 15 Nov 2022 12:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668544424; cv=none; d=google.com; s=arc-20160816; b=oppFfC1Slj16Q82CupFUV/5PN7jIFnt6R2JTlFeSoWHoJNqF+gSLCdi9NSUoZIZLAV sV7KIoeGEDmdwcg+wcpZ4kSAC5U3/yYMKyU8je/cKn/viFmUOokGkfv9rakhyeA86Q1t 1MpSdMWgs1ODjyr4s7zUVmAfguwXqO7Q9SgS+Zt1U6cJAWuQmx6iNP6Cmm//Qa1NHDj1 hfE5KKOd9WNtzenVcgJPNhoEcxUs+cdmwlifxV3aGsIAWD1GuQfmHgltJTQ0RpUjuKeD pqV0nDKOMOxbgEm/W5cMm/dNjZGJ+DTokyfuw2G7nfLlb7UT7EAzfuMQ5aPgIA0Ue3hG gIIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=VMt+lAYwXqKzwEHThJOieOqFot6Ei0mDFg2C3AsrckQ=; b=dBWT2/WPUhPwD13BwrD6XlNtFeOuzV2hBmEAw7OXuSBPM0AhbotJOzZmBqg7/wk3q5 zU6QwK/oW0I8hJt87wEvbqsXadbCuWZYn2/XlX1SKoIE1Hm+gO8knG6wzQ1uMSafpS3A veXi5PjfvIljRvFH3T8AvmVvQaOUZdFu8x0CewFVP/1pCDmLehTpXTyc+1fVHeffy7ix u60kP8cvIAY9TOyQ7YD4GdRK2+c8FsrvA+x/oc5Ti0qySA96/WAoYOZGc/xVGI5b+kjI ZsTj1wausv1GSdcKnGHnLw8Y1etV7DRZRd1QKTayAR9TXdBJsqas7QUWSVvO+k7GF6nE lF5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mucQ8oXb; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a17090a86c100b00202880e0827si15913553pjv.28.2022.11.15.12.33.31; Tue, 15 Nov 2022 12:33:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=mucQ8oXb; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231989AbiKOUbh (ORCPT + 99 others); Tue, 15 Nov 2022 15:31:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237900AbiKOUaU (ORCPT ); Tue, 15 Nov 2022 15:30:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFDB430F78; Tue, 15 Nov 2022 12:29:00 -0800 (PST) Message-ID: <20221115202117.849485477@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544138; 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: references:references; bh=VMt+lAYwXqKzwEHThJOieOqFot6Ei0mDFg2C3AsrckQ=; b=mucQ8oXb0C4aCUY5JIMHL0lQvqrUa82sVbkH31UQxuzVpLZFZOmZrs0aoHSqp8pIGl/3ks XzbBlbaPcq7AdSa8X4h2kftgSOMVq0C5uEW1sgpJkvQoDwU0yqOrm1FD/muU/i1qildMby 3Hi4LCjz97NdVP1G1qQmV699Fe2I2dEXIR0EfIxNv/9KwsFNlwjyBEtPCFUJpSvHMhwFrM eA2HUfkCi7ahca5KpV4TI7TeG1Sbh22gIBXFxV3I+KZoNZpmsdlal4ZIax8x/yWtlwdybP FRU/wSK1ulaN4C96T3M46wWFUuj2HoJBfMu/F1M2zALqXL11TdMvSXtouh9STg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544138; 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: references:references; bh=VMt+lAYwXqKzwEHThJOieOqFot6Ei0mDFg2C3AsrckQ=; b=OuvYR8kVkCDqlom60FXFh8tOQHo9j2OPSo2cnx3iin3PXTYDtXFF5m4yF0hgM7KN3NI2NA n/k4I9w9C1CNd/AQ== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , Anna-Maria Behnsen , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Arnd Bergmann , Viresh Kumar , Marc Zyngier Subject: [patch 15/15] Bluetooth: hci_qca: Fix the teardown problem for real References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:57 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749595639474361002?= X-GMAIL-MSGID: =?utf-8?q?1749595639474361002?= While discussing solutions for the teardown problem which results from circular dependencies between timers and workqueues, where timers schedule work from their timer callback and workqueues arm the timers from work items, it was discovered that the recent fix to the QCA code is incorrect. That commit fixes the obvious problem of using del_timer() instead of del_timer_sync() and reorders the teardown calls to destroy_workqueue(wq); del_timer_sync(t); This makes it less likely to explode, but it's still broken: destroy_workqueue(wq); /* After this point @wq cannot be touched anymore */ ---> timer expires queue_work(wq) <---- Results in a NULl pointer dereference deep in the work queue core code. del_timer_sync(t); Use the new timer_shutdown_sync() function to ensure that the timers are disarmed, no timer callbacks are running and the timers cannot be armed again. This restores the original teardown sequence: timer_shutdown_sync(t); destroy_workqueue(wq); which is now correct because the timer core silently ignores potential rearming attempts which can happen when destroy_workqueue() drains pending work before mopping up the workqueue. Fixes: 72ef98445aca ("Bluetooth: hci_qca: Use del_timer_sync() before freeing") Signed-off-by: Thomas Gleixner Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Link: https://lore.kernel.org/all/87iljhsftt.ffs@tglx Acked-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_qca.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -696,9 +696,15 @@ static int qca_close(struct hci_uart *hu skb_queue_purge(&qca->tx_wait_q); skb_queue_purge(&qca->txq); skb_queue_purge(&qca->rx_memdump_q); + /* + * Shut the timers down so they can't be rearmed when + * destroy_workqueue() drains pending work which in turn might try + * to arm a timer. After shutdown rearm attempts are silently + * ignored by the timer core code. + */ + timer_shutdown_sync(&qca->tx_idle_timer); + timer_shutdown_sync(&qca->wake_retrans_timer); destroy_workqueue(qca->workqueue); - del_timer_sync(&qca->tx_idle_timer); - del_timer_sync(&qca->wake_retrans_timer); qca->hu = NULL; kfree_skb(qca->rx_skb);