* [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
@ 2023-10-27 20:42 Peter Martincic
2023-11-06 1:30 ` Wei Liu
0 siblings, 1 reply; 4+ messages in thread
From: Peter Martincic @ 2023-10-27 20:42 UTC (permalink / raw)
To: linux-hyperv@vger.kernel.org; +Cc: Michael Kelley (LINUX), Boqun Feng, Wei Liu
From 529fcea5d296c22b1dc6c23d55bd6417794b3cda Mon Sep 17 00:00:00 2001
From: Peter Martincic <pmartincic@microsoft.com>
Date: Mon, 16 Oct 2023 16:41:10 -0700
Subject: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
Windows hosts can omit the _SYNC flag to due a bug on resume from modern
suspend. If the guest is sufficiently behind, treat a _SAMPLE the same
as if _SYNC was received.
This is hidden behind param hv_utils.timesync_implicit.
Signed-off-by: Peter Martincic <pmartincic@microsoft.com>
---
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..158f5ff4b809 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 Windows hosts, the sync flag may not always be sent on resume.
+ * Force a sync if it's 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
2023-10-27 20:42 [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC Peter Martincic
@ 2023-11-06 1:30 ` Wei Liu
2023-11-06 18:18 ` [EXTERNAL] " Peter Martincic
0 siblings, 1 reply; 4+ messages in thread
From: Wei Liu @ 2023-11-06 1:30 UTC (permalink / raw)
To: Peter Martincic
Cc: linux-hyperv@vger.kernel.org, Michael Kelley (LINUX), Boqun Feng,
Wei Liu, Wei Liu
On Fri, Oct 27, 2023 at 08:42:33PM +0000, Peter Martincic wrote:
> From 529fcea5d296c22b1dc6c23d55bd6417794b3cda Mon Sep 17 00:00:00 2001
> From: Peter Martincic <pmartincic@microsoft.com>
> Date: Mon, 16 Oct 2023 16:41:10 -0700
> Subject: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
>
> Windows hosts can omit the _SYNC flag to due a bug on resume from modern
> suspend. If the guest is sufficiently behind, treat a _SAMPLE the same
> as if _SYNC was received.
>
> This is hidden behind param hv_utils.timesync_implicit.
>
> Signed-off-by: Peter Martincic <pmartincic@microsoft.com>
Boqun, what do you think about this patch?
> ---
> 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..158f5ff4b809 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 Windows hosts, the sync flag may not always be sent on resume.
> + * Force a sync if it's 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [EXTERNAL] Re: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
2023-11-06 1:30 ` Wei Liu
@ 2023-11-06 18:18 ` Peter Martincic
2023-11-06 19:01 ` Boqun Feng
0 siblings, 1 reply; 4+ messages in thread
From: Peter Martincic @ 2023-11-06 18:18 UTC (permalink / raw)
To: Wei Liu
Cc: linux-hyperv@vger.kernel.org, Michael Kelley (LINUX), Boqun Feng,
Wei Liu
Sorry for the formatting/recipient/procedure mistakes. I've an updated commit message based on feedback from Michael. I'll wait to hear back from you and Boqun before I post V2/updates.
Thanks again,
Peter
-----Original Message-----
From: Wei Liu <wei.liu@kernel.org>
Sent: Sunday, November 5, 2023 5:31 PM
To: Peter Martincic <pmartincic@microsoft.com>
Cc: linux-hyperv@vger.kernel.org; Michael Kelley (LINUX) <mikelley@microsoft.com>; Boqun Feng <Boqun.Feng@microsoft.com>; Wei Liu <liuwe@microsoft.com>; Wei Liu <wei.liu@kernel.org>
Subject: [EXTERNAL] Re: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
On Fri, Oct 27, 2023 at 08:42:33PM +0000, Peter Martincic wrote:
> From 529fcea5d296c22b1dc6c23d55bd6417794b3cda Mon Sep 17 00:00:00 2001
> From: Peter Martincic <pmartincic@microsoft.com>
> Date: Mon, 16 Oct 2023 16:41:10 -0700
> Subject: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
>
> Windows hosts can omit the _SYNC flag to due a bug on resume from
> modern suspend. If the guest is sufficiently behind, treat a _SAMPLE
> the same as if _SYNC was received.
>
> This is hidden behind param hv_utils.timesync_implicit.
>
> Signed-off-by: Peter Martincic <pmartincic@microsoft.com>
Boqun, what do you think about this patch?
> ---
> 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..158f5ff4b809 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 Windows hosts, the sync flag may not always be sent on resume.
> + * Force a sync if it's 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [EXTERNAL] Re: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
2023-11-06 18:18 ` [EXTERNAL] " Peter Martincic
@ 2023-11-06 19:01 ` Boqun Feng
0 siblings, 0 replies; 4+ messages in thread
From: Boqun Feng @ 2023-11-06 19:01 UTC (permalink / raw)
To: Peter Martincic
Cc: Wei Liu, linux-hyperv@vger.kernel.org, Michael Kelley (LINUX),
Boqun Feng, Wei Liu
On Mon, Nov 06, 2023 at 06:18:48PM +0000, Peter Martincic wrote:
> Sorry for the formatting/recipient/procedure mistakes. I've an updated commit message based on feedback from Michael. I'll wait to hear back from you and Boqun before I post V2/updates.
>
> Thanks again,
> Peter
>
> -----Original Message-----
> From: Wei Liu <wei.liu@kernel.org>
> Sent: Sunday, November 5, 2023 5:31 PM
> To: Peter Martincic <pmartincic@microsoft.com>
> Cc: linux-hyperv@vger.kernel.org; Michael Kelley (LINUX) <mikelley@microsoft.com>; Boqun Feng <Boqun.Feng@microsoft.com>; Wei Liu <liuwe@microsoft.com>; Wei Liu <wei.liu@kernel.org>
> Subject: [EXTERNAL] Re: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
>
> On Fri, Oct 27, 2023 at 08:42:33PM +0000, Peter Martincic wrote:
> > From 529fcea5d296c22b1dc6c23d55bd6417794b3cda Mon Sep 17 00:00:00 2001
> > From: Peter Martincic <pmartincic@microsoft.com>
> > Date: Mon, 16 Oct 2023 16:41:10 -0700
> > Subject: [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC
> >
> > Windows hosts can omit the _SYNC flag to due a bug on resume from
> > modern suspend. If the guest is sufficiently behind, treat a _SAMPLE
> > the same as if _SYNC was received.
> >
> > This is hidden behind param hv_utils.timesync_implicit.
> >
> > Signed-off-by: Peter Martincic <pmartincic@microsoft.com>
>
> Boqun, what do you think about this patch?
>
The patch looks good to me. Peter, feel free to send the V2 and I will
give my Acked-by.
Regards,
Boqun
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-06 19:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27 20:42 [PATCH] hv_utils: Allow implicit ICTIMESYNCFLAG_SYNC Peter Martincic
2023-11-06 1:30 ` Wei Liu
2023-11-06 18:18 ` [EXTERNAL] " Peter Martincic
2023-11-06 19:01 ` Boqun Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).