From patchwork Wed Jul 2 19:36:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrill Gorcunov X-Patchwork-Id: 4467751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4CF1ABEEAA for ; Wed, 2 Jul 2014 19:40:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7003020394 for ; Wed, 2 Jul 2014 19:40:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72EF12037F for ; Wed, 2 Jul 2014 19:40:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2QLO-0006rO-EQ; Wed, 02 Jul 2014 19:37:26 +0000 Received: from mail-lb0-x236.google.com ([2a00:1450:4010:c04::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2QLM-0006nw-0B for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 19:37:24 +0000 Received: by mail-lb0-f182.google.com with SMTP id c11so8195200lbj.41 for ; Wed, 02 Jul 2014 12:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=lUFFAJWIOG6pRuLdvwNsRBxIvlwhGe7yuB9yVYTySls=; b=lEFQwfdiCAS8hyKzxsrORZeeP5lroI28HXoKOA7aOLXmwXCc0nk+XyLfqcFrE0nGB9 3tw2S1Z1GNy7B40CuspV5O4DlyRu9ai6IBga7eJcgn+wjbtSTAkmB3R3EtnAGUaoCq4w aFXyBUPNgNiYErgUJrDjt7wwvlBZfWDRcSa67+zHScFWTB14G0Ox8mCUTGDLRm2zV99p y1Pb8sNi62MgfEBLXq6168dj9R+rOKyYtA7K0FVjEy5Wo4Z9LbWj3lK/p1IMRF9oFCv7 096Kb6Zn09/CQKtfaKsLC+wCpLS1E6iZpm9ugn/h23IDfKJ9zAfNfdWsjxFfHPdPnbRs SerA== X-Received: by 10.112.24.167 with SMTP id v7mr33304517lbf.19.1404329820924; Wed, 02 Jul 2014 12:37:00 -0700 (PDT) Received: from moon.localdomain ([5.18.180.63]) by mx.google.com with ESMTPSA id h2sm12268526lam.47.2014.07.02.12.37.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jul 2014 12:37:00 -0700 (PDT) Received: by moon.localdomain (Postfix, from userid 1000) id CD6B6841704; Wed, 2 Jul 2014 23:36:59 +0400 (MSK) Date: Wed, 2 Jul 2014 23:36:59 +0400 From: Cyrill Gorcunov To: Arnd Bergmann Subject: Re: [patch 3/4] timerfd: Implement timerfd_ioctl method to restore timerfd_ctx::ticks Message-ID: <20140702193659.GI12440@moon> References: <20140623185431.396309193@openvz.org> <53B4382F.9030908@codeaurora.org> <20140702170416.GG12440@moon> <4188254.Av1Z2pQssC@wuerfel> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4188254.Av1Z2pQssC@wuerfel> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140702_123724_232429_1969C1E2 X-CRM114-Status: GOOD ( 17.04 ) X-Spam-Score: -0.1 (/) Cc: Vladimir Davydov , Andrey Vagin , Pavel Emelyanov , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Kerrisk , Thomas Gleixner , Andrew Morton , Linux ARM kernel mailing list , Christopher Covington X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Updated variant, thanks a lot for feedback! --- From: Cyrill Gorcunov Subject: timerfd: Implement timerfd_ioctl method to restore timerfd_ctx::ticks, v3 The read() of timerfd files allows to fetch the number of timer ticks while there is no way to set it back from userspace. To restore the timer's state as it was at checkpoint moment we need a path to bring @ticks back. Initially I thought about writing ticks back via write() interface but it seems such API is somehow obscure. Instead implement timerfd_ioctl() method with TFD_IOC_SET_TICKS command which allows to adjust @ticks into non-zero value waking up the waiters. I wrapped code with CONFIG_CHECKPOINT_RESTORE which can be dropped off if there users except c/r camp appear. v2 (by akpm@): - Use define timerfd_ioctl NULL for non c/r config v3: - Use copy_from_user for @ticks fetching since not all arch support get_user for 8 byte argument CC: Thomas Gleixner CC: Andrew Morton CC: Andrey Vagin CC: Arnd Bergmann CC: Christopher Covington CC: Pavel Emelyanov CC: Vladimir Davydov Signed-off-by: Cyrill Gorcunov --- fs/timerfd.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/timerfd.h | 5 +++++ 2 files changed, 42 insertions(+) Index: linux-2.6.git/fs/timerfd.c =================================================================== --- linux-2.6.git.orig/fs/timerfd.c +++ linux-2.6.git/fs/timerfd.c @@ -315,12 +315,49 @@ static int timerfd_show(struct seq_file #define timerfd_show NULL #endif +#ifdef CONFIG_CHECKPOINT_RESTORE +static long timerfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct timerfd_ctx *ctx = file->private_data; + int ret = 0; + + switch (cmd) { + case TFD_IOC_SET_TICKS: { + u64 ticks; + + if (copy_from_user(&ticks, (u64 __user *)arg, sizeof(ticks))) + return -EFAULT; + if (!ticks) + return -EINVAL; + + spin_lock_irq(&ctx->wqh.lock); + if (!timerfd_canceled(ctx)) { + ctx->ticks = ticks; + if (ticks) + wake_up_locked(&ctx->wqh); + } else + ret = -ECANCELED; + spin_unlock_irq(&ctx->wqh.lock); + break; + } + default: + ret = -ENOTTY; + break; + } + + return ret; +} +#else +#define timerfd_ioctl NULL +#endif + static const struct file_operations timerfd_fops = { .release = timerfd_release, .poll = timerfd_poll, .read = timerfd_read, .llseek = noop_llseek, .show_fdinfo = timerfd_show, + .unlocked_ioctl = timerfd_ioctl, }; static int timerfd_fget(int fd, struct fd *p) Index: linux-2.6.git/include/linux/timerfd.h =================================================================== --- linux-2.6.git.orig/include/linux/timerfd.h +++ linux-2.6.git/include/linux/timerfd.h @@ -11,6 +11,9 @@ /* For O_CLOEXEC and O_NONBLOCK */ #include +/* For _IO helpers */ +#include + /* * CAREFUL: Check include/asm-generic/fcntl.h when defining * new flags, since they might collide with O_* ones. We want @@ -29,4 +32,6 @@ /* Flags for timerfd_settime. */ #define TFD_SETTIME_FLAGS (TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET) +#define TFD_IOC_SET_TICKS _IOW('T', 0, u64) + #endif /* _LINUX_TIMERFD_H */