From patchwork Wed Oct 4 23:26:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9985867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7799B602B8 for ; Wed, 4 Oct 2017 23:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EFB128BF1 for ; Wed, 4 Oct 2017 23:28:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5184B28C10; Wed, 4 Oct 2017 23:28:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C37EE28BF1 for ; Wed, 4 Oct 2017 23:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751255AbdJDX14 (ORCPT ); Wed, 4 Oct 2017 19:27:56 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:54196 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750951AbdJDX1y (ORCPT ); Wed, 4 Oct 2017 19:27:54 -0400 Received: by mail-pf0-f174.google.com with SMTP id n73so362806pfg.10 for ; Wed, 04 Oct 2017 16:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=67lNcmTJD8eDcRFIcEYRPiQyX9e9vZL80l8VumkvgEE=; b=L1eOrapKBcJORksGEyUWyYFBS+3F8VUxXZm7yG+1yWIUKm5fcUwsYFP6uPqNPez4Ej Lj5Nt+phsunYNpRR4aMhIrIbs7TBo4B8W9Q2ZI8yLx/lM/N0gFzjrzTt5D61sDaLN6Et AQnbwOxULVfSggKNmwpnJHNzb4cdJSDxh12Q8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=67lNcmTJD8eDcRFIcEYRPiQyX9e9vZL80l8VumkvgEE=; b=WjxT9j7ihuuYKF+3RLTuAu2/SFjQ1hS23xafnUzgsNdy44pEAfuT3QcTMwKKzQdFP6 hOq6GE7KcdmTBld9xVW9eptlN3t+8T6+O6144sGudBlNquypVq3AsV3xw6PAUx99JJ6B boNwrNnfsgKlITd3Ts+T53dMr9n1+EULTWRQanlgpoieg6MR1QsZIYGR02lfvySpH36N rtV2w6rLp9XUcx4Q6w4SiTLfcqPPZhwWWeyChO+S38/7juC0TW/GrnrHSmoqB0Cz6ZQx CpX4jRjJJbl4H2LnzG1ZI1x5s8cEu06b7RdQ4Dasx+sGDWbxzw15uZzq6AcydRaS+rRU IUcA== X-Gm-Message-State: AHPjjUhvgeeeEFL77cW/ryHKn/vRUBtqQT9z3jJDuuS/ky1pBtJQSr6o HcBQH2/NgIHSuS94Z/oYLZGSdg== X-Google-Smtp-Source: AOwi7QC9F+kEL/da8sr1x4sfLUOlhO7naWz+N7GbL2+b834jPamhjYfFp2VcRdQT+qeh+v7G+2yzmw== X-Received: by 10.99.108.66 with SMTP id h63mr20000225pgc.211.1507159673590; Wed, 04 Oct 2017 16:27:53 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id s9sm28691081pfk.20.2017.10.04.16.27.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 16:27:51 -0700 (PDT) From: Kees Cook To: Thomas Gleixner Cc: Kees Cook , John Stultz , Stephen Boyd , Andrew Morton , Arnd Bergmann , Benjamin Herrenschmidt , Chris Metcalf , Geert Uytterhoeven , Greg Kroah-Hartman , Guenter Roeck , Harish Patil , Heiko Carstens , "James E.J. Bottomley" , Julian Wiedmann , Kalle Valo , Lai Jiangshan , Len Brown , Manish Chopra , Mark Gross , "Martin K. Petersen" , Martin Schwidefsky , Michael Ellerman , Michael Reed , netdev@vger.kernel.org, Oleg Nesterov , Paul Mackerras , Pavel Machek , Petr Mladek , "Rafael J. Wysocki" , Ralf Baechle , Sebastian Reichel , Stefan Richter , Sudip Mukherjee , Tejun Heo , Ursula Braun , Viresh Kumar , Wim Van Sebroeck , linux1394-devel@lists.sourceforge.net, linux-mips@linux-mips.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/13] timer: Convert schedule_timeout() to use from_timer() Date: Wed, 4 Oct 2017 16:26:55 -0700 Message-Id: <1507159627-127660-2-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507159627-127660-1-git-send-email-keescook@chromium.org> References: <1507159627-127660-1-git-send-email-keescook@chromium.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Signed-off-by: Kees Cook --- 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 6383c528b148..5ef5c9e41a09 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 f2674a056c26..38613ced2324 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;