All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH] x86/time: update TSC stamp on restore from deep C-state
@ 2020-01-14 19:36 Igor Druzhinin
  2020-01-15  9:47 ` Roger Pau Monné
  2020-01-15 11:32 ` Jan Beulich
  0 siblings, 2 replies; 23+ messages in thread
From: Igor Druzhinin @ 2020-01-14 19:36 UTC (permalink / raw)
  To: xen-devel; +Cc: andrew.cooper3, Igor Druzhinin, wl, jbeulich, roger.pau

If ITSC is not available on CPU (e.g if running nested as PV shim)
then X86_FEATURE_NONSTOP_TSC is not advertised in certain cases, i.e.
all AMD and some old Intel processors. In which case TSC would need to
be restored on CPU from platform time by Xen upon exiting deep C-states.

As platform time might be behind the last TSC stamp recorded for the
current CPU, invariant of TSC stamp being always behind local TSC counter
is violated. This has an effect of get_s_time() going negative resulting
in eventual system hang or crash.

Fix this issue by updating local TSC stamp along with TSC counter write.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
This caused reliable hangs of shim domains with multiple vCPUs on all AMD
systems. The problem got also reproduced on bare-metal by artifically
masking ITSC feature bit. The proposed fix has been verified for both
cases.
---
 xen/arch/x86/time.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index e79cb4d..f6b26f8 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -955,10 +955,16 @@ u64 stime2tsc(s_time_t stime)
 
 void cstate_restore_tsc(void)
 {
+    struct cpu_time *t = &this_cpu(cpu_time);
+
     if ( boot_cpu_has(X86_FEATURE_NONSTOP_TSC) )
         return;
 
-    write_tsc(stime2tsc(read_platform_stime(NULL)));
+    t->stamp.master_stime = read_platform_stime(NULL);
+    t->stamp.local_tsc = stime2tsc(t->stamp.master_stime);
+    t->stamp.local_stime = t->stamp.master_stime;
+
+    write_tsc(t->stamp.local_tsc);
 }
 
 /***************************************************************************
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2020-01-16 12:27 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 19:36 [Xen-devel] [PATCH] x86/time: update TSC stamp on restore from deep C-state Igor Druzhinin
2020-01-15  9:47 ` Roger Pau Monné
2020-01-15 11:40   ` Jan Beulich
2020-01-15 11:53     ` Roger Pau Monné
2020-01-15 12:49       ` Jan Beulich
2020-01-15 13:44         ` Roger Pau Monné
2020-01-15 16:21           ` Jan Beulich
2020-01-16  9:33             ` Roger Pau Monné
2020-01-16  9:38               ` Jan Beulich
2020-01-16 12:09                 ` Igor Druzhinin
2020-01-16 12:25                   ` Roger Pau Monné
2020-01-15 12:25     ` Igor Druzhinin
2020-01-15 12:31       ` Igor Druzhinin
2020-01-15 12:41         ` Jan Beulich
2020-01-15 12:36   ` Igor Druzhinin
2020-01-15 13:23     ` Roger Pau Monné
2020-01-15 14:45       ` Igor Druzhinin
2020-01-15 11:32 ` Jan Beulich
2020-01-15 12:28   ` Igor Druzhinin
2020-01-15 12:39     ` Jan Beulich
2020-01-15 12:47       ` Igor Druzhinin
2020-01-15 12:54         ` Jan Beulich
2020-01-15 14:55           ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.