All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
@ 2019-10-23  8:57 Roger Pau Monne
  2019-10-23  9:06 ` Jürgen Groß
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roger Pau Monne @ 2019-10-23  8:57 UTC (permalink / raw)
  To: xen-devel
  Cc: Jürgen Groß,
	Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monne

If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
the value of the time stamp counter the vcpu time info must also be
updated, or the time calculated by the guest using the Xen PV clock
interface will be skewed.

Update the vcpu time info when the guest writes to either MSR_IA32_TSC
or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
pv-shim on AMD hardware, since the shim will aggressively try to keep
TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
reliable.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Jürgen Groß <jgross@suse.com>
---
 xen/arch/x86/hvm/hvm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 9acd359c99..e4c0425330 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -442,6 +442,8 @@ static void hvm_set_guest_tsc_msr(struct vcpu *v, u64 guest_tsc)
 
     hvm_set_guest_tsc(v, guest_tsc);
     v->arch.hvm.msr_tsc_adjust += v->arch.hvm.cache_tsc_offset - tsc_offset;
+    if ( v == current )
+        update_vcpu_system_time(v);
 }
 
 static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
@@ -449,6 +451,8 @@ static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
     v->arch.hvm.cache_tsc_offset += tsc_adjust - v->arch.hvm.msr_tsc_adjust;
     hvm_set_tsc_offset(v, v->arch.hvm.cache_tsc_offset, 0);
     v->arch.hvm.msr_tsc_adjust = tsc_adjust;
+    if ( v == current )
+        update_vcpu_system_time(v);
 }
 
 u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc)
-- 
2.23.0


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

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

* Re: [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
  2019-10-23  8:57 [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments Roger Pau Monne
@ 2019-10-23  9:06 ` Jürgen Groß
  2019-10-23 10:55 ` Wei Liu
  2019-10-23 14:08 ` Jan Beulich
  2 siblings, 0 replies; 6+ messages in thread
From: Jürgen Groß @ 2019-10-23  9:06 UTC (permalink / raw)
  To: Roger Pau Monne, xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich

On 23.10.19 10:57, Roger Pau Monne wrote:
> If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
> the value of the time stamp counter the vcpu time info must also be
> updated, or the time calculated by the guest using the Xen PV clock
> interface will be skewed.
> 
> Update the vcpu time info when the guest writes to either MSR_IA32_TSC
> or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
> pv-shim on AMD hardware, since the shim will aggressively try to keep
> TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
> reliable.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Release-acked-by: Juergen Gross <jgross@suse.com>


Juergen

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

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

* Re: [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
  2019-10-23  8:57 [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments Roger Pau Monne
  2019-10-23  9:06 ` Jürgen Groß
@ 2019-10-23 10:55 ` Wei Liu
  2019-10-23 11:05   ` Roger Pau Monné
  2019-10-23 14:08 ` Jan Beulich
  2 siblings, 1 reply; 6+ messages in thread
From: Wei Liu @ 2019-10-23 10:55 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: Jürgen Groß, xen-devel, Wei Liu, Jan Beulich, Andrew Cooper

On Wed, Oct 23, 2019 at 10:57:39AM +0200, Roger Pau Monne wrote:
> If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
> the value of the time stamp counter the vcpu time info must also be
> updated, or the time calculated by the guest using the Xen PV clock
> interface will be skewed.
> 
> Update the vcpu time info when the guest writes to either MSR_IA32_TSC
> or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
> pv-shim on AMD hardware, since the shim will aggressively try to keep
> TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
> reliable.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> Cc: Jürgen Groß <jgross@suse.com>
> ---
>  xen/arch/x86/hvm/hvm.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 9acd359c99..e4c0425330 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -442,6 +442,8 @@ static void hvm_set_guest_tsc_msr(struct vcpu *v, u64 guest_tsc)
>  
>      hvm_set_guest_tsc(v, guest_tsc);
>      v->arch.hvm.msr_tsc_adjust += v->arch.hvm.cache_tsc_offset - tsc_offset;
> +    if ( v == current )
> +        update_vcpu_system_time(v);

Why not get rid of the test and always call update_vcpu_system_time(v)?

Wei.

>  }
>  
>  static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
> @@ -449,6 +451,8 @@ static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
>      v->arch.hvm.cache_tsc_offset += tsc_adjust - v->arch.hvm.msr_tsc_adjust;
>      hvm_set_tsc_offset(v, v->arch.hvm.cache_tsc_offset, 0);
>      v->arch.hvm.msr_tsc_adjust = tsc_adjust;
> +    if ( v == current )
> +        update_vcpu_system_time(v);
>  }
>  
>  u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc)
> -- 
> 2.23.0
> 

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

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

* Re: [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
  2019-10-23 10:55 ` Wei Liu
@ 2019-10-23 11:05   ` Roger Pau Monné
  2019-10-23 11:18     ` Wei Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Roger Pau Monné @ 2019-10-23 11:05 UTC (permalink / raw)
  To: Wei Liu; +Cc: Jürgen Groß, xen-devel, Jan Beulich, Andrew Cooper

On Wed, Oct 23, 2019 at 11:55:13AM +0100, Wei Liu wrote:
> On Wed, Oct 23, 2019 at 10:57:39AM +0200, Roger Pau Monne wrote:
> > If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
> > the value of the time stamp counter the vcpu time info must also be
> > updated, or the time calculated by the guest using the Xen PV clock
> > interface will be skewed.
> > 
> > Update the vcpu time info when the guest writes to either MSR_IA32_TSC
> > or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
> > pv-shim on AMD hardware, since the shim will aggressively try to keep
> > TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
> > reliable.
> > 
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > ---
> > Cc: Jürgen Groß <jgross@suse.com>
> > ---
> >  xen/arch/x86/hvm/hvm.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> > index 9acd359c99..e4c0425330 100644
> > --- a/xen/arch/x86/hvm/hvm.c
> > +++ b/xen/arch/x86/hvm/hvm.c
> > @@ -442,6 +442,8 @@ static void hvm_set_guest_tsc_msr(struct vcpu *v, u64 guest_tsc)
> >  
> >      hvm_set_guest_tsc(v, guest_tsc);
> >      v->arch.hvm.msr_tsc_adjust += v->arch.hvm.cache_tsc_offset - tsc_offset;
> > +    if ( v == current )
> > +        update_vcpu_system_time(v);
> 
> Why not get rid of the test and always call update_vcpu_system_time(v)?

If the vcpu is not running the update will be done by the scheduling
code in schedule_tail. Calling update_vcpu_system_time unconditionally
would work, I was just trying to avoid the overhead if it's not really
needed.

Thanks, Roger.

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

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

* Re: [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
  2019-10-23 11:05   ` Roger Pau Monné
@ 2019-10-23 11:18     ` Wei Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Wei Liu @ 2019-10-23 11:18 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jürgen Groß, xen-devel, Jan Beulich, Wei Liu, Andrew Cooper

On Wed, Oct 23, 2019 at 01:05:14PM +0200, Roger Pau Monné wrote:
> On Wed, Oct 23, 2019 at 11:55:13AM +0100, Wei Liu wrote:
> > On Wed, Oct 23, 2019 at 10:57:39AM +0200, Roger Pau Monne wrote:
> > > If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
> > > the value of the time stamp counter the vcpu time info must also be
> > > updated, or the time calculated by the guest using the Xen PV clock
> > > interface will be skewed.
> > > 
> > > Update the vcpu time info when the guest writes to either MSR_IA32_TSC
> > > or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
> > > pv-shim on AMD hardware, since the shim will aggressively try to keep
> > > TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
> > > reliable.
> > > 
> > > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > > ---
> > > Cc: Jürgen Groß <jgross@suse.com>
> > > ---
> > >  xen/arch/x86/hvm/hvm.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> > > index 9acd359c99..e4c0425330 100644
> > > --- a/xen/arch/x86/hvm/hvm.c
> > > +++ b/xen/arch/x86/hvm/hvm.c
> > > @@ -442,6 +442,8 @@ static void hvm_set_guest_tsc_msr(struct vcpu *v, u64 guest_tsc)
> > >  
> > >      hvm_set_guest_tsc(v, guest_tsc);
> > >      v->arch.hvm.msr_tsc_adjust += v->arch.hvm.cache_tsc_offset - tsc_offset;
> > > +    if ( v == current )
> > > +        update_vcpu_system_time(v);
> > 
> > Why not get rid of the test and always call update_vcpu_system_time(v)?
> 
> If the vcpu is not running the update will be done by the scheduling
> code in schedule_tail. Calling update_vcpu_system_time unconditionally
> would work, I was just trying to avoid the overhead if it's not really
> needed.
> 

Fair enough.

Reviewed-by: Wei Liu <wl@xen.org>

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

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

* Re: [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments
  2019-10-23  8:57 [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments Roger Pau Monne
  2019-10-23  9:06 ` Jürgen Groß
  2019-10-23 10:55 ` Wei Liu
@ 2019-10-23 14:08 ` Jan Beulich
  2 siblings, 0 replies; 6+ messages in thread
From: Jan Beulich @ 2019-10-23 14:08 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: Jürgen Groß, xen-devel, Wei Liu, Andrew Cooper

On 23.10.2019 10:57, Roger Pau Monne wrote:
> If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
> the value of the time stamp counter the vcpu time info must also be
> updated, or the time calculated by the guest using the Xen PV clock
> interface will be skewed.
> 
> Update the vcpu time info when the guest writes to either MSR_IA32_TSC
> or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
> pv-shim on AMD hardware, since the shim will aggressively try to keep
> TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
> reliable.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

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

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

end of thread, other threads:[~2019-10-23 14:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23  8:57 [Xen-devel] [PATCH for-4.13] x86/tsc: update vcpu time info on guest TSC adjustments Roger Pau Monne
2019-10-23  9:06 ` Jürgen Groß
2019-10-23 10:55 ` Wei Liu
2019-10-23 11:05   ` Roger Pau Monné
2019-10-23 11:18     ` Wei Liu
2019-10-23 14:08 ` Jan Beulich

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.