Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp543038rdb; Thu, 30 Nov 2023 11:17:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCSAvEsIYKoW4E1QSJULyHbKkp4i8uoDs8LwBQhRt9bTcWa4rp1q8uWkuY/ggmvs2gzdj1 X-Received: by 2002:a17:90b:3b4d:b0:285:b876:5033 with SMTP id ot13-20020a17090b3b4d00b00285b8765033mr14442331pjb.49.1701371868664; Thu, 30 Nov 2023 11:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701371868; cv=none; d=google.com; s=arc-20160816; b=TeweMu7QqhyjhF7r8hOpz2whhOVAHPZSytNWuVsLeQFmZr+IgQYqMe2BaAdiBU88kl nnPsbCthcg4TPZ65X9dHeT9/QuvNapIG9U/Pm9p0vKKfajkQeILCZnr1yf0zFTz7wrkQ /iKM3WiSz9qJ4vsg7vnIlnKegJThQFe7XDi3QS8U8IuKVt1zaOLF3ifrYS6JVezOt+vc azFjg84nUgWhqurLWz+2dKJB5XN5JS7bxFMdW2a1wPp803V0aa+lrbZm2k4rpBFpYqzo w1L/C/mP5DKtLNqfjUbaSPZKNiL9N5ZeY4Sdvld19rcI+pCHY1YHWYE0gqUPV7XF++9O p2Ig== 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:feedback-id :dkim-signature; bh=etUM6pU7GXADCSsGQkpd5054784+nonMf6sWSZzwGYM=; fh=KDVVmV+4SAssduolZmRT0Sz2N79Hj5n1cH4zhuk9dUI=; b=nwctTeWGHrN/0/EJjv3C0Pu8rSe6a5TSRsjnEac+BEQ30HsDAA7CEd+5jtLdA06fMN RBV1HoS+xiK85f3K0b5nJ0GzWq7vqtXabrz9D1e/0v7AezcSxbFsgrU0yXTQuCmvclEv igGoNgwnAT7FwckXc9nQO8effwRRwQFReQ8+symbKQ+6wDIbZNy1Yc7u0jNpBfCMRvla bNPCBQbSHiZe/i2oyqkqvJFpnLxv4M2uUunSQuenhZbNwmngMWiHDts0EX8Qj60DTck2 Zk52rBjMe4m2NkqoloQir5valjXAzk+OkhQOTWy2mLAZE48bCcLM67CHMhDP4iSsKEww cVpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WqL993bS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x1-20020a17090a6c0100b00285256a3127si4121613pjj.132.2023.11.30.11.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:17:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WqL993bS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 579E9826E3AC; Thu, 30 Nov 2023 11:17:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235234AbjK3TR3 (ORCPT + 99 others); Thu, 30 Nov 2023 14:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235220AbjK3TR1 (ORCPT ); Thu, 30 Nov 2023 14:17:27 -0500 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE553D40; Thu, 30 Nov 2023 11:17:33 -0800 (PST) Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-67a16594723so7858916d6.3; Thu, 30 Nov 2023 11:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701371853; x=1701976653; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=etUM6pU7GXADCSsGQkpd5054784+nonMf6sWSZzwGYM=; b=WqL993bSPJ3P0krJh3GMyD+48RvzR0P39KMN4cHA9SnuwLhC+5ptSwOyRkw4Pu3Jb1 nr/RicHqZaGsUJvKz4rwoWvTQA1B5EY/QZqJc0ke4KWbfSy6+sDNa0L64vsjvcDgn8l+ LFCPvaLYOtFuRUZ47O203OrkVn1f8ZGnLMfQfMQHpOSUA6Ul46JR7tGUfH5bgrFCLfaU AwLGOwf7xLDT3Di8P2cM+XCtyryVfHRaSUolZ9lBfWgvvwkiCcncvmcEhN91Jx3LGH7Z +OQWChjcEVQg8LX3wyDBOGKbbt1Hp1W6fY2nWauE09e5OrheT28FK1Eprp7KkyxS8NLS h+vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701371853; x=1701976653; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=etUM6pU7GXADCSsGQkpd5054784+nonMf6sWSZzwGYM=; b=mu5R4sTFWiSu8kbLoItycy261eP56B9ArBunS+GeynV6WgjnTnBBgDl8k2GgJcpKJC jBr7KT84gxpkksdy8wjGCHNtsUjXMN63bDjmKBX79r55WXuHHF8Za/PTG3KcgewN2fca kDpJ6YbGfD2h1/ON6jMZgIMr5p6gd4TaPjBMfOmjsUzyijin3GSdnzuCeXXILpFsb0si PPQSwKtsjI6bXDRt+QY/y55/T4pW874AjARD2Oo4B1NBXSaKh36ALIHaGnbU+D39G1P/ 2dqlXdoCTFE8KSLfsloKwzbRbNUYTfroywQTPdk/dhk/lQe3d2F1AShZHC7ZvytQBuZL JXyw== X-Gm-Message-State: AOJu0YyEmufByx4vKOfN354cOl6roU5Ti9RWu90yUkzx90AgYBu9rqD3 0LWCFjx8zYjAj3UTrae8zFU= X-Received: by 2002:a05:6214:1d02:b0:67a:150e:45fd with SMTP id e2-20020a0562141d0200b0067a150e45fdmr32703340qvd.49.1701371852962; Thu, 30 Nov 2023 11:17:32 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id k12-20020a05621414ec00b0067a8fe21448sm282885qvw.2.2023.11.30.11.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:17:32 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 1C26927C005B; Thu, 30 Nov 2023 14:17:32 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 30 Nov 2023 14:17:32 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeijedguddvvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveei udffiedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Nov 2023 14:17:31 -0500 (EST) Date: Thu, 30 Nov 2023 11:16:43 -0800 From: Boqun Feng To: pmartincic@linux.microsoft.com Cc: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC Message-ID: References: <20231127213524.52783-1-pmartincic@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231127213524.52783-1-pmartincic@linux.microsoft.com> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,TVD_PH_BODY_ACCOUNTS_PRE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 11:17:46 -0800 (PST) On Mon, Nov 27, 2023 at 01:35:24PM -0800, pmartincic@linux.microsoft.com wrote: > From: Peter Martincic > > Hyper-V hosts can omit the _SYNC flag to due a bug on resume from modern > suspend. In such a case, the guest may fail to update its time-of-day to > account for the period when it was suspended, and could proceed with a > significantly wrong time-of-day. In such a case when the guest is > significantly behind, fix it by treating a _SAMPLE the same as if _SYNC > was received so that the guest time-of-day is updated. > > This is hidden behind param hv_utils.timesync_implicit. > > Signed-off-by: Peter Martincic Looks good to me. Acked-by: Boqun Feng Regards, Boqun > --- > drivers/hv/hv_util.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > > diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c > index 42aec2c5606a..9c97c4065fe7 100644 > --- a/drivers/hv/hv_util.c > +++ b/drivers/hv/hv_util.c > @@ -296,6 +296,11 @@ static struct { > spinlock_t lock; > } host_ts; > > +static bool timesync_implicit; > + > +module_param(timesync_implicit, bool, 0644); > +MODULE_PARM_DESC(timesync_implicit, "If set treat SAMPLE as SYNC when clock is behind"); > + > static inline u64 reftime_to_ns(u64 reftime) > { > return (reftime - WLTIMEDELTA) * 100; > @@ -344,6 +349,29 @@ static void hv_set_host_time(struct work_struct *work) > do_settimeofday64(&ts); > } > > +/* > + * Due to a bug on Hyper-V hosts, the sync flag may not always be sent on resume. > + * Force a sync if the guest is behind. > + */ > +static inline bool hv_implicit_sync(u64 host_time) > +{ > + struct timespec64 new_ts; > + struct timespec64 threshold_ts; > + > + new_ts = ns_to_timespec64(reftime_to_ns(host_time)); > + ktime_get_real_ts64(&threshold_ts); > + > + threshold_ts.tv_sec += 5; > + > + /* > + * If guest behind the host by 5 or more seconds. > + */ > + if (timespec64_compare(&new_ts, &threshold_ts) >= 0) > + return true; > + > + return false; > +} > + > /* > * Synchronize time with host after reboot, restore, etc. > * > @@ -384,7 +412,8 @@ static inline void adj_guesttime(u64 hosttime, u64 reftime, u8 adj_flags) > spin_unlock_irqrestore(&host_ts.lock, flags); > > /* Schedule work to do do_settimeofday64() */ > - if (adj_flags & ICTIMESYNCFLAG_SYNC) > + if ((adj_flags & ICTIMESYNCFLAG_SYNC) || > + (timesync_implicit && hv_implicit_sync(host_ts.host_time))) > schedule_work(&adj_time_work); > } > > -- > 2.34.1 >