Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1209181pxb; Wed, 10 Feb 2021 02:56:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7SddBT6fpPbYf8yjU5NrqJbog47g0PQMIKLV1yzCrzh5XxSAfETnTE60BOeGqHgaS5Mq7 X-Received: by 2002:a17:906:6bda:: with SMTP id t26mr2378181ejs.50.1612954579737; Wed, 10 Feb 2021 02:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612954579; cv=none; d=google.com; s=arc-20160816; b=G99uQxKgyYHaXfb7S0PsPB2ow0iL3dPF2dL8gkH9BjdBOto0XqoYEPb7c/itJ4hLrw pPDP0YQnjrALw0TX56kQLXIEUawcMVYf/mgmIEbmE0ptMCrYhXZw1/Mly7OGFyAt4PV3 J5HnmNyrQrMC0z64X9oTRUjL86zD8Ot4DXEHl/eoqSzn7ijzLUgNzfYtA+WdQ0sNnQB3 aQqn/RH4bgGA7lWAFrDMcReNP6wq3eRMuJGAHJ5yuhXsZQK8MoKTyMWSy6xMzVDNR+Rw 47qpDyoRflgYdajX7EzAyio/jfHDI1tk9fLAzpyqmccLzTWJt4INaXmy5Ue2A5iPTRI9 Kg7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CSWTljAeWob0D34tfK7gClPE/MNhEVH6W5TDM2Drl+0=; b=aQApF6VCsXpkQ6LHb4xYs8/HthBE0RzM3OLbrS3onjBW8IQ8XzwGMFOLI8ZR6m83YK PpDkMsCm7K46xI5cVsUWN7Sp3wgzzCK55CHpIOVtOuOHPT/Ep0dUql77KuvclWvnEES9 s/uut4agu9VvPOl6Y4D2DCsIv/5lT8PCWcoKSoYVLSEL1LbsGRo5XH96VUT3oPnSM7YQ KMivue/ZujRciJIeWX2cHiNeNxXiEQTdUSaj8hE62wI5LWsqZ+d+2urwIQijGa2EhACf 6THTrSfe2VRRMvJ7MwYz/EjVFuQw/J3jRKHtyKt+VmaaLovyi0JUHeDox6lrOSqhYJf/ ObnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ns6iSXNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si1138422eds.438.2021.02.10.02.55.56; Wed, 10 Feb 2021 02:56:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ns6iSXNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231518AbhBJKzJ (ORCPT + 99 others); Wed, 10 Feb 2021 05:55:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:51866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbhBJKwa (ORCPT ); Wed, 10 Feb 2021 05:52:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6428364E2F; Wed, 10 Feb 2021 10:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612954309; bh=Y6sCoyxE53CReNPUEbiccEMYwSH7CbdJeBLkyQtM4kg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ns6iSXNhiO6JrMRZy7ZlMVQLaPRp1McXSsStX4jQFhFyY/3Rou9ZqtYBi5SaeFPYF QWPaiZkmmCIX5zqXPp6/oLk/bITbO77eAC0JY+rhf6ejTYfCkVnlll7Un18DWTc2fQ RWg/hwN+Lq7jzqYDbL1VR+Y9nHYiCzLtrfuJBH0Y= Date: Wed, 10 Feb 2021 11:51:46 +0100 From: Greg Kroah-Hartman To: Hikaru Nishida Cc: linux-kernel@vger.kernel.org, suleiman@google.com, Alexander Graf , Andra Paraschiv , Masahiro Yamada Subject: Re: [RFC PATCH 2/2] drivers/virt: introduce CLOCK_BOOTTIME adjustment sysfs interface driver Message-ID: References: <20210210103908.1720658-1-hikalium@google.com> <20210210193728.RFC.2.I03c0323c1564a18210ec98fb78b3eb728a90c2d2@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210210193728.RFC.2.I03c0323c1564a18210ec98fb78b3eb728a90c2d2@changeid> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 07:39:08PM +0900, Hikaru Nishida wrote: > From: Hikaru Nishida > > This adds a sysfs interface /sys/kernel/boottime_adj to enable advancing > CLOCK_BOOTTIME from the userspace without actual susupend/resume cycles. > > This gives a way to mitigate CLOCK_BOOTTIME divergence between guest > and host on virtualized environments after suspend/resume cycles on > the host. > > We observed an issue of a guest application that expects there is a gap > between CLOCK_BOOTTIME and CLOCK_MONOTONIC after the device is suspended > to detect whether the device went into suspend or not. > Since the guest is paused instead of being actually suspended during the > host's suspension, guest kernel doesn't advance CLOCK_BOOTTIME correctly > and there is no way to correct that. > > To solve the problem, this change introduces a way to modify a gap > between those clocks and align the timer behavior to host's one. > > Signed-off-by: Hikaru Nishida > --- > > drivers/virt/Kconfig | 9 ++++++ > drivers/virt/Makefile | 1 + > drivers/virt/boottime_adj.c | 57 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 67 insertions(+) > create mode 100644 drivers/virt/boottime_adj.c > > diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig > index 80c5f9c16ec1..149b4e763e4d 100644 > --- a/drivers/virt/Kconfig > +++ b/drivers/virt/Kconfig > @@ -13,6 +13,15 @@ menuconfig VIRT_DRIVERS > > if VIRT_DRIVERS > > +config BOOTTIME_ADJUSTMENT > + tristate "CLOCK_BOOTTIME adjustment sysfs interface" > + help > + The CLOCK_BOOTTIME adjustment sysfs interface driver > + provides a sysfs interface ( /sys/kernel/boottime_adj ) > + to enable adjusting CLOCK_BOOTTIME from the userspace. > + > + If unsure, say N. > + > config FSL_HV_MANAGER > tristate "Freescale hypervisor management driver" > depends on FSL_SOC > diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile > index f28425ce4b39..1bbb476ddba9 100644 > --- a/drivers/virt/Makefile > +++ b/drivers/virt/Makefile > @@ -3,6 +3,7 @@ > # Makefile for drivers that support virtualization > # > > +obj-$(CONFIG_BOOTTIME_ADJUSTMENT) += boottime_adj.o > obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o > obj-y += vboxguest/ > > diff --git a/drivers/virt/boottime_adj.c b/drivers/virt/boottime_adj.c > new file mode 100644 > index 000000000000..9cc717d8accc > --- /dev/null > +++ b/drivers/virt/boottime_adj.c > @@ -0,0 +1,57 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later Do you really mean "or later"? I have to ask... > +/* > + * CLOCK_BOOTTIME Adjustment Interface Driver No copyright, nice! Your company lawyers will be having a word with you... :( > + */ > + > +#include > +#include > +#include > + > +static struct kobject *kobj_boottime_adj; > + > +/* > + * Write to /sys/kernel/boottime_adj advances CLOCK_BOOTTIME by given delta. > + */ > +static ssize_t boottime_adj_write(struct kobject *kobj, > + struct kobj_attribute *attr, const char *buf, > + size_t count) > +{ > + int error; > + struct timespec64 delta; > + > + if (sscanf(buf, "%lld %ld", &delta.tv_sec, &delta.tv_nsec) != 2) > + return -EINVAL; sysfs is "one value per file", but as you did not provide documentation on what this does, I can't tell if you really are following this or not. > + > + error = timekeeping_adjust_boottime(&delta); > + if (error) > + return error; > + > + pr_info("%s: CLOCK_BOOTTIME has been advanced by %+lld seconds and %+ld nanoseconds\n", > + __func__, delta.tv_sec, delta.tv_nsec); If kernels are working normally, no messages are printed to the log. Do not allow userspace to spam things. > + return count; > +} > + > +static struct kobj_attribute boottime_adj_attr = > +__ATTR(boottime_adj, 0200, NULL, boottime_adj_write); __ATTR_RO() please. > + > +static int __init boottime_adj_init(void) > +{ > + int error; > + > + error = sysfs_create_file(kernel_kobj, &boottime_adj_attr.attr); > + if (error) { > + pr_warn("%s: failed to init\n", __func__); why warn again? > + return error; > + } > + return 0; > +} > + > +static void __exit boottime_adj_cleanup(void) > +{ > + kobject_put(kobj_boottime_adj); You just called put on a kobject you never initialized????? Are you sure this file has been tested? odd... greg k-h