xen: update system time immediately when VCPUOP_register_vcpu_info
PATCH v2 1/1 xen: update system time immediately when VCPUOP_register_vcpu_info
The guest may access the pv vcpu_time_info immediately after VCPUOP_register_vcpu_info. This is to borrow the idea of VCPUOP_register_vcpu_time_memory_area, where the force_update_vcpu_system_time() is called immediately when the new memory area is registered.
Otherwise, we may observe clock drift at the VM side if the VM accesses the clocksource immediately after VCPUOP_register_vcpu_info().
Reference:
https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00571.html
---
Changed since v1:
- Implement force_update_vcpu_system_time() for ARM (suggested by Jan Beulich)
While I have tested ARM compilation with aarch64-linux-gnu-gcc, I did not test on ARM platform.
xen/arch/arm/time.c | 5 +++++ xen/common/domain.c | 2 ++ xen/include/asm-arm/time.h | 2 ++ 3 files changed, 9 insertions(+)
xen/arch/arm/time.c +5 -0
@@ -351,6 +351,11 @@ void update_vcpu_system_time(struct vcpu *v)/* XXX update shared_info->wc_* */ } +void force_update_vcpu_system_time (struct vcpu *v) +{ +update_vcpu_system_time (v); +} +void domain_set_time_offset (struct domain *d,int64_t time_offset_seconds) { d->time_offset.seconds = time_offset_seconds;
xen/common/domain.c +2 -0
@@ -1704,6 +1704,8 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg) rc =map_vcpu_info (v, info.mfn, info.offset);domain_unlock (d); +force_update_vcpu_system_time (v); +break ; }
xen/include/asm-arm/time.h +2 -0
@@ -105,6 +105,8 @@ extern uint64_t ns_to_ticks(s_time_t ns);void preinit_xen_time (void ); +void force_update_vcpu_system_time (struct vcpu *v); +#endif /* __ARM_TIME_H__ */ /* * Local variables:
Signature · 1 line
2.17.1
Quoted 11 lines · Dongli Zhang
The guest may access the pv
vcpu_time_infoimmediately afterVCPUOP_register_vcpu_info. This is to borrow the idea ofVCPUOP_register_vcpu_time_memory_area, where theforce_update_vcpu_system_time()is called immediately when the new memory area is registered.Otherwise, we may observe clock drift at the VM side if the VM accesses the clocksource immediately after
VCPUOP_register_vcpu_info().Reference:
https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00571.html
Quoted 8 lines
Cc Joe Jin <[email protected]>Signed-off-by Dongli Zhang <[email protected]>---
Changed since v1:
- Implementforce_update_vcpu_system_time()for ARM (suggested by Jan Beulich)
While I have tested ARM compilation with aarch64-linux-gnu-gcc, I did not test on ARM platform.
This is fine. Of course it is not going to do anything on ARM given that update_vcpu_system_time in unimplemented but it is certainly harmless.
For the ARM part:
Quoted 50 lines
xen/arch/arm/time.c | 5 +++++ xen/common/domain.c | 2 ++ xen/include/asm-arm/time.h | 2 ++ 3 files changed, 9 insertions(+)xen/arch/arm/time.c +5
-0@@ -351,6 +351,11 @@ void update_vcpu_system_time(struct vcpu *v)/* XXX update shared_info->wc_* */ } +void force_update_vcpu_system_time (struct vcpu *v) +{ +update_vcpu_system_time (v); +} +void domain_set_time_offset (struct domain *d,int64_t time_offset_seconds) { d->time_offset.seconds = time_offset_seconds;xen/common/domain.c +2
-0@@ -1704,6 +1704,8 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg) rc =map_vcpu_info (v, info.mfn, info.offset);domain_unlock (d); +force_update_vcpu_system_time (v); +break ; }xen/include/asm-arm/time.h +2
-0@@ -105,6 +105,8 @@ extern uint64_t ns_to_ticks(s_time_t ns);void preinit_xen_time (void ); +void force_update_vcpu_system_time (struct vcpu *v); +#endif /* __ARM_TIME_H__ */ /* * Local variables: Signature · 1 line
2.17.1
Quoted 6 lines · Dongli Zhang
The guest may access the pv
vcpu_time_infoimmediately afterVCPUOP_register_vcpu_info. This is to borrow the idea ofVCPUOP_register_vcpu_time_memory_area, where theforce_update_vcpu_system_time()is called immediately when the new memory area is registered.
Quoted 7 lines
Otherwise, we may observe clock drift at the VM side if the VM accesses the clocksource immediately after
VCPUOP_register_vcpu_info().Reference:
https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00571.htmlCc Joe Jin <[email protected]>Signed-off-by Dongli Zhang <[email protected]>
Ian - any thoughts towards 4.16 here either way?
Jan
Jan Beulich writes ("Re: [PATCH v2 1/1] xen: update system time immediately when VCPUOP_register_vcpu_info"):
Quoted 10 lines · Dongli Zhang
Quoted 9 lines
The guest may access the pv
vcpu_time_infoimmediately afterVCPUOP_register_vcpu_info. This is to borrow the idea ofVCPUOP_register_vcpu_time_memory_area, where theforce_update_vcpu_system_time()is called immediately when the new memory area is registered.Otherwise, we may observe clock drift at the VM side if the VM accesses the clocksource immediately after
VCPUOP_register_vcpu_info().
Quoted 8 lines
Quoted 4 lines
Reference:
https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00571.htmlCc Joe Jin <[email protected]>Signed-off-by Dongli Zhang <[email protected]>Reviewed-by Jan Beulich <[email protected]>Ian - any thoughts towards 4.16 here either way?
This looks like a bugfix to me, and the diff is certainly small. I am positively inclined. I would like to know what the risks are. Stefano says this does nothing on ARM so the risk would be to x86. Can you advise ?
Thanks,
Ian.
Quoted 16 lines · Ian Jackson
Jan Beulich writes ("Re: [PATCH v2 1/1] xen: update system time immediately when
VCPUOP_register_vcpu_info"):Quoted 15 lines · Dongli Zhang
Quoted 13 lines
The guest may access the pv
vcpu_time_infoimmediately afterVCPUOP_register_vcpu_info. This is to borrow the idea ofVCPUOP_register_vcpu_time_memory_area, where theforce_update_vcpu_system_time()is called immediately when the new memory area is registered.Otherwise, we may observe clock drift at the VM side if the VM accesses the clocksource immediately after
VCPUOP_register_vcpu_info().Reference:
https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00571.htmlCc Joe Jin <[email protected]>Signed-off-by Dongli Zhang <[email protected]>
Quoted 8 lines
Quoted 3 lines
Reviewed-by Jan Beulich <[email protected]>Ian - any thoughts towards 4.16 here either way?
This looks like a bugfix to me, and the diff is certainly small. I am positively inclined. I would like to know what the risks are. Stefano says this does nothing on ARM so the risk would be to x86. Can you advise ?
I don't see any noteworthy risks - a call to a function gets added in a 2nd place; the function itself has been working fine for years, and it is fine to be used in this new context.
Jan
Jan Beulich writes ("Re: [PATCH v2 1/1] xen: update system time immediately when VCPUOP_register_vcpu_info"):
Quoted 3 lines
I don't see any noteworthy risks - a call to a function gets added in a 2nd place; the function itself has been working fine for years, and it is fine to be used in this new context.
Thanks.
I think this part:
| it is fine to be used in this new context.
was where I wanted a 2nd opinion for confirmation.