From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbdJENS4 (ORCPT ); Thu, 5 Oct 2017 09:18:56 -0400 Received: from terminus.zytor.com ([65.50.211.136]:36829 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310AbdJENSy (ORCPT ); Thu, 5 Oct 2017 09:18:54 -0400 Date: Thu, 5 Oct 2017 06:03:49 -0700 From: tip-bot for Kees Cook Message-ID: Cc: linux@roeck-us.net, pmladek@suse.com, cmetcalf@mellanox.com, manish.chopra@cavium.com, oleg@redhat.com, hpa@zytor.com, harish.patil@cavium.com, paulus@samba.org, gregkh@linuxfoundation.org, benh@kernel.crashing.org, tj@kernel.org, kvalo@qca.qualcomm.com, ubraun@linux.vnet.ibm.com, schwidefsky@de.ibm.com, stefanr@s5r6.in-berlin.de, john.stultz@linaro.org, akpm@linux-foundation.org, rjw@rjwysocki.net, tglx@linutronix.de, mingo@kernel.org, ralf@linux-mips.org, jwi@linux.vnet.ibm.com, sre@kernel.org, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, jiangshanlai@gmail.com, martin.petersen@oracle.com, pavel@ucw.cz, sudipm.mukherjee@gmail.com, sboyd@codeaurora.org, arnd@arndb.de, mark.gross@intel.com, jejb@linux.vnet.ibm.com, keescook@chromium.org, geert@linux-m68k.org, heiko.carstens@de.ibm.com, wim@iguana.be, len.brown@intel.com, mdr@sgi.com, mpe@ellerman.id.au Reply-To: len.brown@intel.com, mdr@sgi.com, mpe@ellerman.id.au, keescook@chromium.org, geert@linux-m68k.org, heiko.carstens@de.ibm.com, wim@iguana.be, mark.gross@intel.com, jejb@linux.vnet.ibm.com, arnd@arndb.de, sboyd@codeaurora.org, pavel@ucw.cz, sudipm.mukherjee@gmail.com, linux-kernel@vger.kernel.org, jiangshanlai@gmail.com, martin.petersen@oracle.com, tglx@linutronix.de, mingo@kernel.org, jwi@linux.vnet.ibm.com, ralf@linux-mips.org, sre@kernel.org, viresh.kumar@linaro.org, akpm@linux-foundation.org, rjw@rjwysocki.net, schwidefsky@de.ibm.com, stefanr@s5r6.in-berlin.de, john.stultz@linaro.org, benh@kernel.crashing.org, kvalo@qca.qualcomm.com, ubraun@linux.vnet.ibm.com, tj@kernel.org, hpa@zytor.com, paulus@samba.org, harish.patil@cavium.com, gregkh@linuxfoundation.org, manish.chopra@cavium.com, oleg@redhat.com, cmetcalf@mellanox.com, linux@roeck-us.net, pmladek@suse.com In-Reply-To: <1507159627-127660-2-git-send-email-keescook@chromium.org> References: <1507159627-127660-2-git-send-email-keescook@chromium.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] timer: Convert schedule_timeout() to use from_timer() Git-Commit-ID: 58e1177b4cd10b0d358faf7d7ebb3779f98bc3ea X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 58e1177b4cd10b0d358faf7d7ebb3779f98bc3ea Gitweb: https://git.kernel.org/tip/58e1177b4cd10b0d358faf7d7ebb3779f98bc3ea Author: Kees Cook AuthorDate: Wed, 4 Oct 2017 16:26:55 -0700 Committer: Thomas Gleixner CommitDate: Thu, 5 Oct 2017 15:01:16 +0200 timer: Convert schedule_timeout() to use from_timer() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new from_timer() helper and passing the timer pointer explicitly. Since this special timer is on the stack, it needs to have a wrapper structure to carry state once .data is eliminated. Signed-off-by: Kees Cook Signed-off-by: Thomas Gleixner Cc: linux-mips@linux-mips.org Cc: Petr Mladek Cc: Benjamin Herrenschmidt Cc: Lai Jiangshan Cc: Sebastian Reichel Cc: Kalle Valo Cc: Paul Mackerras Cc: Pavel Machek Cc: linux1394-devel@lists.sourceforge.net Cc: Chris Metcalf Cc: linux-s390@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: "James E.J. Bottomley" Cc: Wim Van Sebroeck Cc: Michael Ellerman Cc: Ursula Braun Cc: Geert Uytterhoeven Cc: Viresh Kumar Cc: Harish Patil Cc: Guenter Roeck Cc: Manish Chopra Cc: Len Brown Cc: Arnd Bergmann Cc: linux-pm@vger.kernel.org Cc: Heiko Carstens Cc: Tejun Heo Cc: Julian Wiedmann Cc: John Stultz Cc: Mark Gross Cc: "Rafael J. Wysocki" Cc: linux-watchdog@vger.kernel.org Cc: linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" Cc: Greg Kroah-Hartman Cc: Stephen Boyd Cc: Oleg Nesterov Cc: Ralf Baechle Cc: Stefan Richter Cc: Michael Reed Cc: netdev@vger.kernel.org Cc: Martin Schwidefsky Cc: Andrew Morton Cc: linuxppc-dev@lists.ozlabs.org Cc: Sudip Mukherjee Link: https://lkml.kernel.org/r/1507159627-127660-2-git-send-email-keescook@chromium.org --- include/linux/timer.h | 8 ++++++++ kernel/time/timer.c | 26 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/linux/timer.h b/include/linux/timer.h index 6383c52..5ef5c9e 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -179,6 +179,14 @@ static inline void timer_setup(struct timer_list *timer, (TIMER_DATA_TYPE)timer, flags); } +static inline void timer_setup_on_stack(struct timer_list *timer, + void (*callback)(struct timer_list *), + unsigned int flags) +{ + __setup_timer_on_stack(timer, (TIMER_FUNC_TYPE)callback, + (TIMER_DATA_TYPE)timer, flags); +} + #define from_timer(var, callback_timer, timer_fieldname) \ container_of(callback_timer, typeof(*var), timer_fieldname) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index f2674a0..38613ce 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1668,9 +1668,20 @@ void run_local_timers(void) raise_softirq(TIMER_SOFTIRQ); } -static void process_timeout(unsigned long __data) +/* + * Since schedule_timeout()'s timer is defined on the stack, it must store + * the target task on the stack as well. + */ +struct process_timer { + struct timer_list timer; + struct task_struct *task; +}; + +static void process_timeout(struct timer_list *t) { - wake_up_process((struct task_struct *)__data); + struct process_timer *timeout = from_timer(timeout, t, timer); + + wake_up_process(timeout->task); } /** @@ -1704,7 +1715,7 @@ static void process_timeout(unsigned long __data) */ signed long __sched schedule_timeout(signed long timeout) { - struct timer_list timer; + struct process_timer timer; unsigned long expire; switch (timeout) @@ -1738,13 +1749,14 @@ signed long __sched schedule_timeout(signed long timeout) expire = timeout + jiffies; - setup_timer_on_stack(&timer, process_timeout, (unsigned long)current); - __mod_timer(&timer, expire, false); + timer.task = current; + timer_setup_on_stack(&timer.timer, process_timeout, 0); + __mod_timer(&timer.timer, expire, false); schedule(); - del_singleshot_timer_sync(&timer); + del_singleshot_timer_sync(&timer.timer); /* Remove the timer from the object tracker */ - destroy_timer_on_stack(&timer); + destroy_timer_on_stack(&timer.timer); timeout = expire - jiffies;