introduce VCPUOP_register_runstate_phys_memory_area hypercall
RFC PATCH 1/1 introduce VCPUOP_register_runstate_phys_memory_area hypercall
From: Andrii Anisov <[email protected]>
An RFC version of the runstate registration with phys address. Runstate area access is implemented with mapping on each update once for all accesses.
--- xen/arch/arm/domain.c | 63 ++++++++++++++++++++++++++--- xen/common/domain.c | 101 ++++++++++++++++++++++++++++++++++++++++++++-- xen/include/public/vcpu.h | 15 +++++++ xen/include/xen/sched.h | 28 +++++++++---- 4 files changed, 190 insertions(+), 17 deletions(-)
xen/arch/arm/domain.c +57 -6
@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,
@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); } -__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );if ( guest_handle ) {
@@ -303,6 +301,58 @@ static void update_runstate_area(struct vcpu *v) } } +extern int map_runstate_area (struct vcpu *v,struct vcpu_runstate_info **area); +extern void unmap_runstate_area (struct vcpu_runstate_info *area); + +static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate; + +if (map_runstate_area (v, &runstate) ) +return ; + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + +memcpy (runstate, &v->runstate,sizeof (v->runstate)); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + } + +unmap_runstate_area (runstate); +} + +/* Update per-VCPU guest runstate shared memory area (if registered). */ +static void update_runstate_area (struct vcpu *v) +{ +if (xchg (&v->runstate_in_use,1 ) ) +return ; + +switch ( v->runstate_guest_type ) + { +case RUNSTATE_NONE : +break ; + +case RUNSTATE_VADDR : +update_runstate_by_gvaddr (v); +break ; + +case RUNSTATE_PADDR : +update_runstate_by_gpaddr (v); +break ; + } + +xchg (&v->runstate_in_use,0 ); +} +static void schedule_tail (struct vcpu *prev) {ctxt_switch_from (prev);
@@ -998,6 +1048,7 @@ long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) a {case VCPUOP_register_vcpu_info:case VCPUOP_register_runstate_memory_area: +case VCPUOP_register_runstate_phys_memory_area:return do_vcpu_op (cmd, vcpuid, arg);default :return -EINVAL ;
xen/common/domain.c +97 -4
135 lines not on this page · raw message
xen/include/public/vcpu.h +15 -0
@@ -235,6 +235,21 @@ struct vcpu_register_time_memory_area {typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t ;DEFINE_XEN_GUEST_HANDLE (vcpu_register_time_memory_area_t); +/* +* Register a shared memory area from which the guest may obtain its own +* runstate information without needing to execute a hypercall. +* Notes: +* 1. The registered address must be guest's physical address. +* 2. The registered runstate area should not cross page boundary. +* 3. Only one shared area may be registered per VCPU. The shared area is +* updated by the hypervisor each time the VCPU is scheduled. Thus +* runstate.state will always be RUNSTATE_running and +* runstate.state_entry_time will indicate the system time at which the +* VCPU was last scheduled to run. +* @extra_arg == pointer to vcpu_register_runstate_memory_area structure. +*/ +#define VCPUOP_register_runstate_phys_memory_area 14 +#endif /* __XEN_PUBLIC_VCPU_H__ */ /*
xen/include/xen/sched.h +21 -7
@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use; + +union + {#ifndef CONFIG_COMPAT -# define runstate_guest (v) ((v)->runstate_guest) -XEN_GUEST_HANDLE (vcpu_runstate_info_t) runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt) +XEN_GUEST_HANDLE (vcpu_runstate_info_t) virt;/* guest address */ #else -# define runstate_guest (v) ((v)->runstate_guest.native) -union { -XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; -XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; - } runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt.native) +union { +XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; +XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; + } virt;/* guest address */ #endif +paddr_t phys; + } runstate_guest; +/* last time when vCPU is scheduled out */ uint64_t last_run_time;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/1 Introduce runstate area registration with phys address
From: Andrii Anisov <[email protected]>
Following discussion [1] it is introduced and implemented a runstate registration interface which uses guest's phys address instead of a virtual one. The new hypercall employes the same data structures as a predecessor, but expects the vcpu_runstate_info structure to not cross a page boundary. The interface is implemented in a way vcpu_runstate_info structure is mapped to the hypervisor on the hypercall processing and is directly accessed during its updates. This runstate area mapping follows vcpu_info structure registration.
Permanent mapping of runstate area would consume vmap area on arm32 what is limited to 1G. Though it might be OK because it would be possible to increase the ARM32 virtual address area by reworking the address space.
The series is tested for ARM64. Build tested for x86. I'd appreciate if someone could check it with x86.
The Linux kernel patch is here [2]. Though it is for 4.14. It is not still convinced the absolute correctness of that patch, yet this should be better aligned with linux community.
Changes in:
v3: This version again implements runstate mapping on init approach.
Patches are squashed and refactored in order to not allow virt and phys interfaces function simultaneously but replace one another on init. In order to measure performance impact of permanent mapping vs mapping on access there written two RFC patches which follow mapping on access approach with the little difference:
- RFC 1 - using copy_to_guest_phys_flush_dcache() for each access to runstate area.
- RFC 2 - mapping runstate area before all update manipulations and unmap after.
RFC patches were implemented for ARM only, because performance measurements were done on ARM64 machine.
There were made performance measurements of approaches (runstate mapped on access vs mapped on registration). The test setups are as following:
Thin Dom0 (Linux with intiramfs) with DomD running rich Yocto Linux. In DomD 3d benchmark numbers are compared. The benchmark is GlMark2. GLMark2 is ran with different resolutions in order to emit different irq load, where 320x240 emits high IRQ load, but 1920x1080 emits low irq load. Separately tested baking DomD benchmark run with primitive Dom0 CPU burn (dd), in order to stimulate VCPU(dX)->VCPU(dY) switches rather than VCPU(dX)->idle->VCPU(dX).
with following results:
mapped mapped mapped
on init on access on update
RFC 1 RFC 2
GLMark2 320x240 2906 2856 (-2%) 2903 (0)
+Dom0 CPUBurn 2166 2106 (-3%) 2134 (1%)
GLMark2 800x600 2396 2367 (-1%) 2393 (0%)
+Dom0 CPUBurn 1958 1911 (-2%) 1942 (-1%)
GLMark2 1920x1080 939 936 (0%) 935 (0%)
+Dom0 CPUBurn 909 901 (-1%) 907 (0%)
Also it was checked IRQ latency difference using TBM in a setup similar to [5]. Please note that the IRQ rate is one in 30 seconds, and only VCPU->idle->VCPU use-case is considered. With following results (in ns, the timer granularity 120ns):
mapped on init:
max=10080 warm_max=8760 min=6600 avg=6699
mapped on update (RFC1):
max=10440 warm_max=7560 min=7320 avg=7419
mapped on access (RFC2)
max=11520 warm_max=7920 min=7200 avg=7299
v2: It was reconsidered the new runstate interface implementation. The new
interface is made independent of the old one. Do not share runstate_area field, and consequently avoid excessive concurrency with the old runstate interface usage.
Introduced locks in order to resolve possible concurrency between runstate area registration and usage.
Addressed comments from Jan Beulich [3][4] about coding style nits. Though some of them become obsolete with refactoring and few are picked into this thread for further discussion.
There were made performance measurements of approaches (runstate mapped on access vs mapped on registration). The test setups are as following:
Thin Dom0 (Linux with intiramfs) with DomD running rich Yocto Linux. In DomD 3d benchmark numbers are compared. The benchmark is GlMark2. GLMark2 is ran with different resolutions in order to emit different irq load, where 320x240 emits high IRQ load, but 1920x1080 emits low irq load. Separately tested baking DomD benchmark run with primitive Dom0 CPU burn (dd), in order to stimulate VCPU(dX)->VCPU(dY) switches rather than VCPU(dX)->idle->VCPU(dX).
with following results:
mapped mapped
on access on init
GLMark2 320x240 2852 2877 +0.8%
+Dom0 CPUBurn 2088 2094 +0.2%
GLMark2 800x600 2368 2375 +0.3%
+Dom0 CPUBurn 1868 1921 +2.8%
GLMark2 1920x1080 931 931 0%
+Dom0 CPUBurn 892 894 +0.2%
Please note that "mapped on access" means using the old runstate registering interface. And runstate update in this case still often fails to map runstate area like [5], despite the fact that our Linux kernel does not have KPTI enabled. So runstate area update, in this case, is really shortened.
Also it was checked IRQ latency difference using TBM in a setup similar to [5]. Please note that the IRQ rate is one in 30 seconds, and only VCPU->idle->VCPU use-case is considered. With following results (in ns, the timer granularity 120ns):
mapped on access:
max=9960 warm_max=8640 min=7200 avg=7626
mapped on init:
max=9480 warm_max=8400 min=7080 avg=7341
Unfortunately there are no consitent results yet from profiling using Lauterbach PowerTrace. Still in communication with the tracer vendor in order to setup the proper configuration.
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg00416.html
[2] https://github.com/aanisov/linux/commit/ba34d2780f57ea43f81810cd695aace7b55c0f29
[3] https://lists.xenproject.org/archives/html/xen-devel/2019-03/msg00936.html
[4] https://lists.xenproject.org/archives/html/xen-devel/2019-03/msg00934.html
[5] https://lists.xenproject.org/archives/html/xen-devel/2019-01/msg02369.html
[6] https://lists.xenproject.org/archives/html/xen-devel/2018-12/msg02297.html
Andrii Anisov (1):
xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
xen/arch/arm/domain.c | 58 ++++++++++++++++++--- xen/arch/x86/domain.c | 99 ++++++++++++++++++++++++++++++++--- xen/arch/x86/x86_64/domain.c | 16 +++++- xen/common/domain.c | 121 +++++++++++++++++++++++++++++++++++++++---- xen/include/public/vcpu.h | 15 ++++++ xen/include/xen/sched.h | 28 +++++++--- 6 files changed, 306 insertions(+), 31 deletions(-)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/1 xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Andrii AnisovFrom: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
So it was agreed to register runstate with the guest's physical address so that its mapping is permanent from the hypervisor point of view. [1]
The hypercall employs the same vcpu_register_runstate_memory_area structure for the interface, but requires a registered area to not cross a page boundary.
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg00416.html
--- xen/arch/arm/domain.c | 58 ++++++++++++++++++--- xen/arch/x86/domain.c | 99 ++++++++++++++++++++++++++++++++--- xen/arch/x86/x86_64/domain.c | 16 +++++- xen/common/domain.c | 121 +++++++++++++++++++++++++++++++++++++++---- xen/include/public/vcpu.h | 15 ++++++ xen/include/xen/sched.h | 28 +++++++--- 6 files changed, 306 insertions(+), 31 deletions(-)
xen/arch/arm/domain.c +52 -6
@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,
@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); } -__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );if ( guest_handle ) {
@@ -303,6 +301,53 @@ static void update_runstate_area(struct vcpu *v) } } +static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + +memcpy (v->runstate_guest.phys, &v->runstate,sizeof (v->runstate)); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + } +} + +/* Update per-VCPU guest runstate shared memory area (if registered). */ +static void update_runstate_area (struct vcpu *v) +{ +if (xchg (&v->runstate_in_use,1 ) ) +return ; + +switch ( v->runstate_guest_type ) + { +case RUNSTATE_NONE : +break ; + +case RUNSTATE_VADDR : +update_runstate_by_gvaddr (v); +break ; + +case RUNSTATE_PADDR : +update_runstate_by_gpaddr (v); +break ; + } + +xchg (&v->runstate_in_use,0 ); +} +static void schedule_tail (struct vcpu *prev) {ASSERT (prev != current);
@@ -998,6 +1043,7 @@ long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) a {case VCPUOP_register_vcpu_info:case VCPUOP_register_runstate_memory_area: +case VCPUOP_register_runstate_phys_memory_area:return do_vcpu_op (cmd, vcpuid, arg);default :return -EINVAL ;
xen/arch/x86/domain.c +92 -7
131 lines not on this page · raw message
xen/arch/x86/x86_64/domain.c +14 -2
@@ -12,6 +12,8 @@ CHECK_vcpu_get_physid;#undef xen_vcpu_get_physid +extern void discard_runstate_area (struct vcpu *v); +int arch_compat_vcpu_op (int cmd,struct vcpu *v,XEN_GUEST_HANDLE_PARAM (void ) arg)
@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ; +while (xchg (&v->runstate_in_use,1 ) ==0 ); + +discard_runstate_area (v); + rc =0 ; -guest_from_compat_handle (v->runstate_guest.compat, area.addr.h); + +guest_from_compat_handle (v->runstate_guest.virt.compat, + area.addr.h); + + v->runstate_guest_type =RUNSTATE_VADDR ;if ( v == current ) {
@@ -49,7 +59,9 @@ arch_compat_vcpu_op(vcpu_runstate_get (v, &runstate);XLAT_vcpu_runstate_info (&info, &runstate); } -__copy_to_guest (v->runstate_guest.compat, &info,1 ); +__copy_to_guest (v->runstate_guest.virt.compat, &info,1 ); + +xchg (&v->runstate_in_use,0 );break ; }
xen/common/domain.c +112 -9
150 lines not on this page · raw message
xen/include/public/vcpu.h +15 -0
@@ -235,6 +235,21 @@ struct vcpu_register_time_memory_area {typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t ;DEFINE_XEN_GUEST_HANDLE (vcpu_register_time_memory_area_t); +/* +* Register a shared memory area from which the guest may obtain its own +* runstate information without needing to execute a hypercall. +* Notes: +* 1. The registered address must be guest's physical address. +* 2. The registered runstate area should not cross page boundary. +* 3. Only one shared area may be registered per VCPU. The shared area is +* updated by the hypervisor each time the VCPU is scheduled. Thus +* runstate.state will always be RUNSTATE_running and +* runstate.state_entry_time will indicate the system time at which the +* VCPU was last scheduled to run. +* @extra_arg == pointer to vcpu_register_runstate_memory_area structure. +*/ +#define VCPUOP_register_runstate_phys_memory_area 14 +#endif /* __XEN_PUBLIC_VCPU_H__ */ /*
xen/include/xen/sched.h +21 -7
@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use; + +union + {#ifndef CONFIG_COMPAT -# define runstate_guest (v) ((v)->runstate_guest) -XEN_GUEST_HANDLE (vcpu_runstate_info_t) runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt) +XEN_GUEST_HANDLE (vcpu_runstate_info_t) virt;/* guest address */ #else -# define runstate_guest (v) ((v)->runstate_guest.native) -union { -XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; -XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; - } runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt.native) +union { +XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; +XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; + } virt;/* guest address */ #endif +void * phys; + } runstate_guest; +/* last time when vCPU is scheduled out */ uint64_t last_run_time;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.05.19 at 20:12, <[email protected]> wrote:
From: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
Quoted 10 lines
So it was agreed to register runstate with the guest's physical address so that its mapping is permanent from the hypervisor point of view. [1]
The hypercall employs the same
vcpu_register_runstate_memory_areastructure for the interface, but requires a registered area to not cross a page boundary.[1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg00416.html
Signed-off-by Andrii Anisov <[email protected]>
I would have really hoped that you would outline the intended interaction between both interfaces, such that while reviewing one can judge whether you're actually matching the goal. I think it is actually mandatory to make explicit in the public header what level of mixing is permitted, what is not permitted, and what mix of requests is simply undefined.
In particular, while we did work out during prior discussions that some level of mixing has to be permitted, I'm unconvinced that arbitrary mixing has to be allowed. For example, switching from one model to another could be permitted only with just a single active vCPU. This might allow to do away again with the runstate_in_use field you add.
Quoted 24 lines
xen/arch/arm/domain.c +3
-5@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 293
Quoted 5 lines
xen/arch/arm/domain.c +1
-1@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); } -__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );
In a prior version you did the mechanical part of adjusting the VA-based code in a prereq patch, aiding review. Is there a particular reason you folded everything into one patch now?
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 307
Quoted 8 lines
xen/arch/arm/domain.c +4
-0@@ -303,6 +301,53 @@ static void update_runstate_area(struct vcpu *v) } } +static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys;
What's the cast for here?
Quoted 19 lines
xen/arch/arm/domain.c +15
-0@@ -1614,6 +1613,92 @@ bool update_runstate_area(struct vcpu *v)return rc; } +static bool update_runstate_by_gpaddr_native (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + +memcpy (v->runstate_guest.phys, &v->runstate,sizeof (v->runstate));
xen/arch/arm/domain.c bool update_runstate_area(struct vcpu *v) · line 1640
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+ +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + } + +return true; +}
I can't help thinking that this matches the Arm code. Can common things please be put in common code? I may be asking too much, but if the pre-existing implementations are similar enough (I didn't check) perhaps they could be folded in a first step, too?
Quoted 11 lines
xen/arch/arm/domain.c +11
-0+static bool update_runstate_by_gpaddr_compat (struct vcpu *v) +{ +struct compat_vcpu_runstate_info *runstate = + (struct compat_vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb ();
xen/arch/arm/domain.c bool update_runstate_area(struct vcpu *v) · line 1661
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+ v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + + { +struct compat_vcpu_runstate_info info; +XLAT_vcpu_runstate_info (&info, &v->runstate); +memcpy (v->runstate_guest.phys, &info,sizeof (info)); + } + else + memcpy(v->runstate_guest.phys, &v->runstate, sizeof(v->runstate));
This "else" does not seem to be paired with an if(). Does this build at all?
xen/arch/x86/x86_64/domain.c line 15
Quoted 7 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -12,6 +12,8 @@ CHECK_vcpu_get_physid;#undef xen_vcpu_get_physid +extern void discard_runstate_area (struct vcpu *v);
No, this is not allowed. The declaration must be visible to both consumer and producer, so that when either side is changed things won't build until the other side gets changed too.
xen/arch/x86/x86_64/domain.c arch_compat_vcpu_op( · line 40
Quoted 5 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ; +while (xchg (&v->runstate_in_use,1 ) ==0 );
At the very least such loops want a cpu_relax() in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?
Furthermore I don't understand how this is supposed to work in the first place. The first xchg() will store 1, no matter what. Thus on the second iteration you'll find the wanted value unless the other side stored 0. Yet the other side is a simple xchg() too. Hence its first attempt would fail, but its second attempt (which we didn't exit the critical region here yet) would succeed.
Also - style.
xen/common/domain.c int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d) · line 705
Quoted 11 lines
xen/common/domain.c +5
-0@@ -698,6 +698,74 @@ int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d)return 0 ; } +static void unmap_runstate_area (struct vcpu *v) +{ +mfn_t mfn; + +if ( ! v->runstate_guest.phys )
Stray blank after ! .
xen/common/domain.c int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d) · line 714
Quoted 9 lines
xen/common/domain.c +9
-0+return ; + + mfn =domain_page_map_to_mfn (v->runstate_guest.phys); + +unmap_domain_page_global ((void *) + ((unsigned long )v->runstate_guest.phys & +PAGE_MASK )); + + v->runstate_guest.phys =NULL ;
I think you would better store NULL before unmapping.
xen/common/domain.c int domain_kill(struct domain *d) · line 808
Quoted 8 lines
xen/common/domain.c +3
-0@@ -734,7 +802,10 @@ int domain_kill(struct domain *d)if (cpupool_move_domain (d, cpupool0) )return -ERESTART ; for_each_vcpu ( d, v ) + { +discard_runstate_area_locked (v);unmap_vcpu_info (v); + }
What is the "locked" aspect here about? The guest itself is dead (i.e. fully paused) at this point, isn't it? And it won't ever be unpaused again.
Quoted 4 lines
xen/include/xen/sched.h +0
-0@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */
xen/include/xen/sched.h struct vcpu · line 173
Quoted 10 lines
xen/include/xen/sched.h +8
-0struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use;
Why "unsigned long"? Isn't a bool all you need?
Also these would now all want to be grouped in a sub-structure named "runstate", rather than having "runstate_" prefixes.
xen/include/xen/sched.h struct vcpu · line 188
Quoted 1 line
xen/include/xen/sched.h +1
-0+void * phys;
Bad ordering between * and the blanks. There ought to be a blank ahead of the *, and I don't see why you need any after it.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi Jan,
Quoted 13 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.05.19 at 20:12, <[email protected]> wrote:
From: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
Quoted 2 lines
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
I am not sure what is your point here. At least on Arm, using virtual address is not safe at all (whether KPTI is used or not). A guest can genuinely decides to shatter the mapping where the virtual address is. On Arm, this require to use the break-before-make sequence. It means the translation VA -> PA may fail is you happen to do it while the guest is using the sequence.
Some of the intermittent issues I have seen on the Arndale in the past [1] might be related to using virtual address. I am not 100% sure because even if the debug, the error does not make sense. But this is the most plausible reason for the failure.
I want to discuss this in part of the bigger attempt to rework the hypercall ABI during Xen Summit in July.
[...]
Quoted 9 lines
xen/arch/x86/x86_64/domain.c arch_compat_vcpu_op( · line 40
Quoted 5 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ; +while (xchg (&v->runstate_in_use,1 ) ==0 );At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?
Hmmm, I suggested this but it looks like a guest may call the hypercall multiple time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding to introduce a spinlock.
[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.06.19 at 13:44, <[email protected]> wrote:
Hi Jan,
Quoted 13 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.05.19 at 20:12, <[email protected]> wrote:
From: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
Quoted 2 lines
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
I am not sure what is your point here. At least on Arm, using virtual address is not safe at all (whether KPTI is used or not). A guest can genuinely decides to shatter the mapping where the virtual address is. On Arm, this require to use the break-before-make sequence. It means the translation VA -> PA may fail is you happen to do it while the guest is using the sequence.
Quoted 4 lines
Some of the intermittent issues I have seen on the Arndale in the past [1] might be related to using virtual address. I am not 100% sure because even if the debug, the error does not make sense. But this is the most plausible reason for the failure.
All fine, but Arm-specific. The point of my comment was to ask to call out that there is one environment (x86-64 PV) where this KPTI discussion is entirely inapplicable.
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/x86_64/domain.c arch_compat_vcpu_op( · line 40
Quoted 5 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ; +while (xchg (&v->runstate_in_use,1 ) ==0 );At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?
Quoted 5 lines
Hmmm, I suggested this but it looks like a guest may call the hypercall multiple time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding to introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hello Jan,
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
I am not sure what is your point here. At least on Arm, using virtual address is not safe at all (whether KPTI is used or not). A guest can genuinely decides to shatter the mapping where the virtual address is. On Arm, this require to use the break-before-make sequence. It means the translation VA -> PA may fail is you happen to do it while the guest is using the sequence.
Quoted 8 lines
Quoted 4 lines
Some of the intermittent issues I have seen on the Arndale in the past [1] might be related to using virtual address. I am not 100% sure because even if the debug, the error does not make sense. But this is the most plausible reason for the failure.
All fine, but Arm-specific. The point of my comment was to ask to call out that there is one environment (x86-64 PV) where this KPTI discussion is entirely inapplicable.
I admit that x86 specifics are quite unclear to me so clarifications and corrections in that domain are desirable.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/x86_64/domain.c +0
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ;
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Review arch_compat_vcpu_op( · line 40
Quoted 1 line
(quoted diff) +1
-0+ while( xchg(&v->runstate_in_use, 1) == 0);At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall multiple time from different vCPU. So this could be a way to delay work on the CPU.
Julien, I'm not sure I understand how work on (p?)CPU could be delayed. We are here with interrupts enabled, so here guest would just spend his own vcpu time budget. On the runstate update there is a kind-of trylock, so we would not hang there either. So what the problem?
Quoted 8 lines
Quoted 2 lines
I wanted to make the context switch mostly lockless and therefore avoiding to introduce a spinlock.>
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Firstly I did not think r/w lock specifics are needed here. We have only one reader path - runstate update on vcpu scheduling. And this path can have only one instance at the time. But it seems to be more efficient than the spinlock for the case we are not locking.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi,
Quoted 9 lines · Andrii Anisov
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/x86_64/domain.c arch_compat_vcpu_op( · line 39
Quoted 4 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) ) break; + while( xchg(&v->runstate_in_use, 1) == 0);At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Hmmm, I suggested this but it looks like a guest may call the hypercall multiple time from different vCPU. So this could be a way to delay work on the CPU.
Julien, I'm not sure I understand how work on (p?)CPU could be delayed. We are here with interrupts enabled, so here guest would just spend his own vcpu time budget.
Xen only supports only voluntary preemption. This means that if the hypercall run for a long time, you have no way to interrupt it and schedule another vCPU. In other words, the rest of the work on that specific pCPU would be delayed.
In this context, I think Jan is seeking guarantees that the lock can be taken in timely manner. If not, then we want to use a try-lock style.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 3 lines · Julien Grall
Quoted 1 line
Julien, I'm not sure I understand how work on (p?)CPU could be delayed. We are here with interrupts enabled, so here guest would just spend his own vcpu time budget.
Xen only supports only voluntary preemption.
Oh, really? Let me look into it a bit closer.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 8 lines · Andrii Anisov
Quoted 3 lines · Julien Grall
Quoted 1 line
Julien, I'm not sure I understand how work on (p?)CPU could be delayed. We are here with interrupts enabled, so here guest would just spend his own vcpu time budget.
Xen only supports only voluntary preemption.
Oh, really? Let me look into it a bit closer.
Did you expect Xen to be fully preemptible?
The function to do the scheduling is schedule(). This is either call from a softirq or directly in a few places (e.g wait()).
The only place in this path where do_softirq() will be called is on return to the guest (see leave_hypervisor_tail).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 5 lines · Julien Grall
Did you expect Xen to be fully preemptible?
The function to do the scheduling is
schedule(). This is either call from a softirq or directly in a few places (e.gwait()).The only place in this path where
do_softirq()will be called is on return to the guest (seeleave_hypervisor_tail).
Right you are! I forgot that bit. We will not pass through it on serving timer irq interrupted us in hyp mode.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Andrii AnisovJan,
Quoted 17 lines · Andrii Anisov
Hello Jan,
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 2 lines
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
I am not sure what is your point here. At least on Arm, using virtual address is not safe at all (whether KPTI is used or not). A guest can genuinely decides to shatter the mapping where the virtual address is. On Arm, this require to use the break-before-make sequence. It means the translation VA -> PA may fail is you happen to do it while the guest is using the sequence.
Some of the intermittent issues I have seen on the Arndale in the past [1] might be related to using virtual address. I am not 100% sure because even if the debug, the error does not make sense. But this is the most plausible reason for the failure.
Quoted 5 lines
Quoted 3 lines
All fine, but Arm-specific. The point of my comment was to ask to call out that there is one environment (x86-64 PV) where this KPTI discussion is entirely inapplicable.
I admit that x86 specifics are quite unclear to me so clarifications and corrections in that domain are desirable.
Could you please elaborate more about this?
Do you mean that more words should be added to the commit message about x86? If so, please provide what is proper from your point of view.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:21, <[email protected]> wrote:
Quoted 19 lines · Andrii Anisov
Quoted 17 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
I am not sure what is your point here. At least on Arm, using virtual address is not safe at all (whether KPTI is used or not). A guest can genuinely decides to shatter the mapping where the virtual address is. On Arm, this require to use the break-before-make sequence. It means the translation VA -> PA may fail is you happen to do it while the guest is using the sequence.
Quoted 4 lines
Some of the intermittent issues I have seen on the Arndale in the past [1] might be related to using virtual address. I am not 100% sure because even if the debug, the error does not make sense. But this is the most plausible reason for the failure.
All fine, but Arm-specific. The point of my comment was to ask to call out that there is one environment (x86-64 PV) where this KPTI discussion is entirely inapplicable.
Quoted 6 lines
Quoted 1 line
I admit that x86 specifics are quite unclear to me so clarifications and
corrections in that domain are desirable.
Could you please elaborate more about this?
Do you mean that more words should be added to the commit message about x86? If so, please provide what is proper from your point of view.
I still think my initial response (still visible in context) was sufficient. All I'm after is that you slightly soften your bold statement in the description (no longer visible in context).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Jan BeulichJan, Julien,
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall multiple time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding to introduce a spinlock.
Quoted 6 lines
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
So what is the conclusion here? Should we go with trylock and hypercall_create_continuation() in order to avoid locking but still not fail to the guest?
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:32, <[email protected]> wrote:
Jan, Julien,
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall
multiple
Quoted 3 lines
Quoted 3 lines
time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding
to
Quoted 8 lines
Quoted 1 line
introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Quoted 3 lines
So what is the conclusion here? Should we go with trylock and
hypercall_create_continuation()in order to avoid locking but still not fail to the guest?
I'm not convinced a "trylock" approach is needed - that's something Julien suggested. I'm pretty sure we're acquiring other locks in hypercall context without going the trylock route. I am convinced though that the pseudo-lock you've used needs to be replaced by a real (and perhaps r/w) one, _if_ there is any need for locking in the first place.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi Jan,
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:32, <[email protected]> wrote:
Jan, Julien,
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall
multiple
Quoted 3 lines
Quoted 3 lines
time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding
to
Quoted 8 lines
Quoted 1 line
introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Quoted 6 lines
Quoted 3 lines
So what is the conclusion here? Should we go with trylock and
hypercall_create_continuation()in order to avoid locking but still not fail to the guest?I'm not convinced a "trylock" approach is needed - that's something Julien suggested.
I think the trylock in the context switch is a must. Otherwise you would delay context switch if the information get updated.
Quoted 5 lines
I'm pretty sure we're acquiring other
locks in hypercall context without going the trylock route. I am convinced though that the pseudo-lock you've used needs to be replaced by a real (and perhaps r/w) one, _if_ there is any need for locking in the first place.
You were the one asking for theoretical guarantees that a guest can't abuse this to lock up a CPU. There are no way to guarantee that as multiple vCPUs could call the hypercall and take the same lock potentially delaying significantly the work.
Regarding the need of the lock, I still can't see how you can make it safe without it as you may have concurrent call.
Feel free to suggest a way.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:48, <[email protected]> wrote:
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:32, <[email protected]> wrote:
Jan, Julien,
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall
multiple
Quoted 3 lines
Quoted 3 lines
time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding
to
Quoted 8 lines
Quoted 1 line
introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
So what is the conclusion here? Should we go with trylock and
hypercall_create_continuation()in order to avoid locking but still not fail to the guest?
Quoted 5 lines
Quoted 2 lines
I'm not convinced a "trylock" approach is needed - that's something Julien suggested.
I think the trylock in the context switch is a must. Otherwise you would delay context switch if the information get updated.
Delay in what way? I.e. how would this be an issue other than for the guest itself (which shouldn't be constantly updating the address for the region)?
Quoted 10 lines
Quoted 5 lines
I'm pretty sure we're acquiring other
locks in hypercall context without going the trylock route. I am convinced though that the pseudo-lock you've used needs to be replaced by a real (and perhaps r/w) one, _if_ there is any need for locking in the first place.You were the one asking for theoretical guarantees that a guest can't abuse this to lock up a CPU. There are no way to guarantee that as multiple vCPUs could call the hypercall and take the same lock potentially delaying significantly the work.
Well, I may have gone a little too far with my original response. It just was so odd to see this pseudo lock used.
Quoted 4 lines
Regarding the need of the lock, I still can't see how you can make it safe without it as you may have concurrent call.
Feel free to suggest a way.
Well, if none can be found, then fine. I don't have the time or interest here to try and think about a lockless approach; it just doesn't _feel_ like this ought to strictly require use of a lock. This gut feeling of mine may well be wrong.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi Jan,
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:48, <[email protected]> wrote:
Hi Jan,
Quoted 28 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:32, <[email protected]> wrote:
Jan, Julien,
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall
multiple
Quoted 3 lines
Quoted 3 lines
time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding
to
Quoted 8 lines
Quoted 1 line
introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Quoted 3 lines
So what is the conclusion here? Should we go with trylock and
hypercall_create_continuation()in order to avoid locking but still not fail to the guest?I'm not convinced a "trylock" approach is needed - that's something Julien suggested.
Quoted 6 lines
Quoted 2 lines
I think the trylock in the context switch is a must. Otherwise you would delay context switch if the information get updated.
Delay in what way? I.e. how would this be an issue other than for the guest itself (which shouldn't be constantly updating the address for the region)?
Why would it only be an issue with the guest itself? Any wait on lock in Xen implies that you can't schedule another vCPU as we are not preemptible.
As the lock is taken in the context switch, I am worry that a guest continuously trying to call the hypercall and therefore use the lock may actually delay the end of the context switch. And therefore delay the rest of the work.
I suggested the trylock here, so the context switch could avoid updating the runstate if we are in the hypercall.
Quoted 18 lines
Quoted 11 lines
Quoted 6 lines
I'm pretty sure we're acquiring other
locks in hypercall context without going the trylock route. I am convinced though that the pseudo-lock you've used needs to be replaced by a real (and perhaps r/w) one, _if_ there is any need for locking in the first place.You were the one asking for theoretical guarantees that a guest can't abuse this to lock up a CPU. There are no way to guarantee that as multiple vCPUs could call the hypercall and take the same lock potentially delaying significantly the work.
Well, I may have gone a little too far with my original response. It just was so odd to see this pseudo lock used.
Quoted 3 lines
Regarding the need of the lock, I still can't see how you can make it safe without it as you may have concurrent call.
Quoted 6 lines
Quoted 1 line
Feel free to suggest a way.
Well, if none can be found, then fine. I don't have the time or interest here to try and think about a lockless approach; it just doesn't _feel_ like this ought to strictly require use of a lock. This gut feeling of mine may well be wrong.
I am not asking you to spend a lot of time on it. But if you have a gut feeling this can be done, then a little help would be extremely useful...
Otherwise, I will consider that the lock is the best way to go.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 15:14, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:48, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:32, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?Hmmm, I suggested this but it looks like a guest may call the hypercall
multiple
Quoted 3 lines
Quoted 3 lines
time from different vCPU. So this could be a way to delay work on the CPU.
I wanted to make the context switch mostly lockless and therefore avoiding
to
Quoted 8 lines
Quoted 1 line
introduce a spinlock.
Well, constructs like the above are trying to mimic a spinlock without actually using a spinlock. There are extremely rare situation in which this may indeed be warranted, but here it falls in the common "makes things worse overall" bucket, I think. To not unduly penalize the actual update paths, I think using a r/w lock would be appropriate here.
Quoted 6 lines
Quoted 3 lines
So what is the conclusion here? Should we go with trylock and
hypercall_create_continuation()in order to avoid locking but still not fail to the guest?I'm not convinced a "trylock" approach is needed - that's something Julien suggested.
I think the trylock in the context switch is a must. Otherwise you would delay context switch if the information get updated.
Quoted 6 lines
Quoted 3 lines
Delay in what way? I.e. how would this be an issue other than for the guest itself (which shouldn't be constantly updating the address for the region)?
Why would it only be an issue with the guest itself? Any wait on lock in Xen implies that you can't schedule another vCPU as we are not preemptible.
For one I initially (wrongly) understood you want the trylock in the hypercall handler. And then, for context switch, wasting the target (i.e. being switched in) vCPU's time slice is not an issue here. Of course if there's a chance that acquiring the lock could require more than a full time slice, then yes, some try-lock-ery may be needed.
However, ...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Regarding the need of the lock, I still can't see how you can make it safe without it as you may have concurrent call.
Feel free to suggest a way.
Quoted 7 lines
Quoted 4 lines
Well, if none can be found, then fine. I don't have the time or interest here to try and think about a lockless approach; it just doesn't _feel_ like this ought to strictly require use of a lock. This gut feeling of mine may well be wrong.
I am not asking you to spend a lot of time on it. But if you have a gut feeling this can be done, then a little help would be extremely useful...
... I thought I had already outlined a model: Allow cross-vCPU updates only while the target vCPU is still offline. Once online, a vCPU can only itself update its runstate area address. I think you can get away without any locks in this case; there may be a corner case with a vCPU being onlined right at that point in time, so there may need to be a more strict condition (like "only one online vCPU" instead of "the target vCPU is offline").
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi Jan,
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 15:14, <[email protected]> wrote:
I am not asking you to spend a lot of time on it. But if you have a gut feeling this can be done, then a little help would be extremely useful...
... I thought I had already outlined a model: Allow cross-vCPU updates only while the target vCPU is still offline. Once online, a vCPU can only itself update its runstate area address. I think you can get away without any locks in this case; there may be a corner case with a vCPU being onlined right at that point in time, so there may need to be a more strict condition (like "only one online vCPU" instead of "the target vCPU is offline").
Sorry I may have missed it. We can't really restrict the usage of the current hypercall (it is pretty lax). So I think any lockless solution would require to allow the hypercall to be used together (which I want to avoid).
If we agree to allow the two hypercalls to be used together, then if we protect the update with domain_lock() then you should be able to avoid any race with the update path as onlining a vCPU requires to take the domain_lock() (see do_vcpu_op for x86 and do_common_cpu_on for Arm).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hello Julien,
Quoted 2 lines · Julien Grall
Sorry I may have missed it. We can't really restrict the usage of the current hypercall (it is pretty lax). So I think any lockless solution would require to allow the hypercall to be used together (which I want to avoid).
I'd better say here allowing using phys and virt registered runstates together (and independently). And me personally for this approach, for sure not encouraging users (guests) to do so.
Quoted 1 line
If we agree to allow the two hypercalls to be used together, then if we protect the update with
domain_lock()then you should be able to avoid any race with the update path as onlining a vCPU requires to take thedomain_lock()(seedo_vcpu_opfor x86 anddo_common_cpu_onfor Arm).
Could you please clarify are you saying about protection runstate mapping update or runstate values update? I'd not use the common lock for all vcpus runstate value update, unless it is an rw lock or doing trylock on it.
BTW, I'm a bit confused, are you OK with lock (not trylock) existing in hypercall?
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 1 line · Andrii Anisov
Hello Julien,
Hi,
Quoted 6 lines · Julien Grall
Quoted 2 lines
Sorry I may have missed it. We can't really restrict the usage of the current hypercall (it is pretty lax). So I think any lockless solution would require to allow the hypercall to be used together (which I want to avoid).
I'd better say here allowing using phys and virt registered runstates together (and independently). And me personally for this approach, for sure not encouraging users (guests) to do so.
Why? What are the benefits for a guest to use the two interface together? After all they have exactly the same data...
Quoted 4 lines
Quoted 2 lines
If we agree to allow the two hypercalls to be used together, then if we protect the update with
domain_lock()then you should be able to avoid any race with the update path as onlining a vCPU requires to take thedomain_lock()(seedo_vcpu_opfor x86 anddo_common_cpu_onfor Arm).Could you please clarify are you saying about protection runstate mapping update or runstate values update?
runstate mapping.
Quoted 1 line
BTW, I'm a bit confused, are you OK with lock (not trylock) existing in hypercall?
This is still in discussion.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 1 line · Julien Grall
Why? What are the benefits for a guest to use the two interface together?
I do not say the guest has to use both interfaces simultaneously. It is logically odd, doing so will only reflect in increasing of hypervisor overhead. But such an implementation will have a simpler code, which expected to be (a bit) faster.
So the code simplicity would be a benefit for us. Lower hypervisor overhead is a benefit for sane guests, which use only one interface.
BTW, dropping the old interface implementation will be much easier in future if it will not clash with the new one.
Quoted 1 line
After all they have exactly the same data...
Yes, but normal guests should use only one interface.
Quoted 3 lines
Quoted 1 line
BTW, I'm a bit confused, are you OK with lock (not trylock) existing in hypercall?
This is still in discussion.
I see. So I'll think about the continuation implementation in meanwhile.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hi Andrii,
Quoted 8 lines · Andrii Anisov
Quoted 1 line · Julien Grall
Why? What are the benefits for a guest to use the two interface together?
I do not say the guest has to use both interfaces simultaneously. It is logically odd, doing so will only reflect in increasing of hypervisor overhead. But such an implementation will have a simpler code, which expected to be (a bit) faster. > So the code simplicity would be a benefit for us. Lower hypervisor overhead is a benefit for sane guests, which use only one interface.
I hope you are aware that speaking about speed here is quite irrelevant. The difference would be clear lost in the noise of the rest of the context switch.
But, if you allow something, then most likely someone will use it. However, you have to differentiate implementation vs documentation.
In this case, I don't think the implementation should dictate what is going to be exposed.
If you document that it can't happen, then you have room to forbid the mix in the future (assuming this can't be done now).
In other word, the more lax is the interface, the more difficult it is tighten in the future.
I am not going to push for an implementation that forbid the mix. But I am strongly going to push for any documentation of the expected interaction. So we don't make our life miserable later on.
Quoted 2 lines
BTW, dropping the old interface implementation will be much easier in future if it will not clash with the new one.
I am afraid we will never be able to remove the old interface.
Quoted 4 lines
Quoted 2 lines
After all they have exactly the same data...
Yes, but normal guests should use only one interface.
See above.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 1 line · Julien Grall
I hope you are aware that speaking about speed here is quite irrelevant. The difference would be clear lost in the noise of the rest of the context switch.
Mmm... I have that understanding. Yet I'd rather try to not increase the noise, if not reduce.
BTW, I'll remember that to you on your next conditional branch removal ;)
Quoted 9 lines
But, if you allow something, then most likely someone will use it. However, you have to differentiate implementation vs documentation.
In this case, I don't think the implementation should dictate what is going to be exposed.
If you document that it can't happen, then you have room to forbid the mix in the future (assuming this can't be done now).
In other word, the more lax is the interface, the more difficult it is tighten in the future.
I am not going to push for an implementation that forbid the mix. But I am strongly going to push for any documentation of the expected interaction. So we don't make our life miserable later on.
I do not encourage using both interfaces simultaneously, it is pointless.
If you are saying that this matter could be solved with the appropriate documentation, it's OK with me.
Quoted 2 lines
Quoted 1 line
BTW, dropping the old interface implementation will be much easier in future if it will not clash with the new one.
I am afraid we will never be able to remove the old interface.
Maybe.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 11 lines · Andrii Anisov
Quoted 9 lines · Julien Grall
But, if you allow something, then most likely someone will use it. However, you have to differentiate implementation vs documentation.
In this case, I don't think the implementation should dictate what is going to be exposed.
If you document that it can't happen, then you have room to forbid the mix in the future (assuming this can't be done now).
In other word, the more lax is the interface, the more difficult it is tighten in the future.
I am not going to push for an implementation that forbid the mix. But I am strongly going to push for any documentation of the expected interaction. So we don't make our life miserable later on.
Quoted 7 lines
I do not encourage using both interfaces simultaneously, it is pointless.
If you are saying that this matter could be solved with the appropriate documentation, it's OK with me.Quoted 2 lines
Quoted 1 line
BTW, dropping the old interface implementation will be much easier in future if it will not clash with the new one.
I am afraid we will never be able to remove the old interface.
Maybe.
Well, that a stable ABI... Even if I would love to remove it, you can't get rid of old guests that easily...
Cheers,
Quoted 1 line
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 1 line · Julien Grall
Well, that a stable ABI... Even if I would love to remove it, you can't get rid of old guests that easily...
In 5 years, as XEN did for LK 3.18?
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.06.19 at 18:25, <[email protected]> wrote:
Quoted 1 line · Julien Grall
Well, that a stable ABI... Even if I would love to remove it, you can't get
rid of old guests that easily...
In 5 years, as XEN did for LK 3.18?
I'm afraid I don't even know how to best word a reply to this. What has the Linux kernel version got to do with the interfaces provided by Xen? Is your reply meant to say that something was removed from the Linux kernel in that version? That's fine - consumers can stop consuming interfaces they don't like to use. But Xen (the producer of interfaces like the one discussed here) can't lightly stop providing interfaces, irrespective of their use in upstream Linux.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Andrii AnisovQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.06.19 at 17:11, <[email protected]> wrote:
Quoted 1 line · Julien Grall
After all they have exactly the same data...
Yes, but normal guests should use only one interface.
I thought it had been clarified already that normal guests can very well use both interfaces, just not both at the same time: Boot loader and OS could disagree in this regard, as the prime example.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hello Jan,
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.06.19 at 17:11, <[email protected]> wrote:
Quoted 1 line · Julien Grall
After all they have exactly the same data...
Yes, but normal guests should use only one interface.
I thought it had been clarified already that normal guests can very well use both interfaces, just not both at the same time: Boot loader and OS could disagree in this regard, as the prime example.
I missed "at the same time".
We may require existing runstate area unregistering if the system is aware of it. But it is for the new interface. The old one has no documentation about the unregistering. The implicit way is known to us, but not known to users. How to solve the clash?
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 14.06.19 at 18:23, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.06.19 at 17:11, <[email protected]> wrote:
Quoted 1 line · Julien Grall
After all they have exactly the same data...
Yes, but normal guests should use only one interface.
I thought it had been clarified already that normal guests can very well use both interfaces, just not both at the same time: Boot loader and OS could disagree in this regard, as the prime example.
Quoted 7 lines
I missed "at the same time".
We may require existing runstate area unregistering if the system is aware of it. But it is for the new interface.
The old one has no documentation about the unregistering. The implicit way is known to us, but not known to users.
How to solve the clash?
And once again I'm not sure what to answer, considering that I've already outlined a possible model (without any explicit unregistration).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Hello Jan,
Quoted 8 lines · Jan Beulich
Quoted 5 lines
We may require existing runstate area unregistering if the system is aware of it. But it is for the new interface.
The old one has no documentation about the unregistering. The implicit way is known to us, but not known to users.
How to solve the clash?And once again I'm not sure what to answer, considering that I've already outlined a possible model (without any explicit unregistration).
Just to be sure, "the model" you are talking about is following:
Quoted 3 lines
I thought it had been clarified already that normal guests can very well use both interfaces, just not both at the same time: Boot loader and OS could disagree in this regard, as the prime example.
Is it correct?
But with the current interface (VA) that model is already broken without unregistration. On change between entities with different VA spaces the hypervisor definitely has a chance to spoil the new VA space at the old address. IMHO it should be fixed (at least documented) for the old interface.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.06.19 at 17:32, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines
We may require existing runstate area unregistering if the system is aware of it. But it is for the new interface.
The old one has no documentation about the unregistering. The implicit way is known to us, but not known to users.
How to solve the clash?And once again I'm not sure what to answer, considering that I've already outlined a possible model (without any explicit unregistration).
Quoted 7 lines
Just to be sure, "the model" you are talking about is following:
Quoted 3 lines
I thought it had been clarified already that normal guests can very well use both interfaces, just not both at the same time: Boot loader and OS could disagree in this regard, as the prime example.
Is it correct?
Not really - what you quote is a statement, not the outline of a model. The basic idea for enforcement of a restriction was to allow switching modes only when just one vCPU is online in a guest.
Quoted 4 lines
But with the current interface (VA) that model is already broken without unregistration. On change between entities with different VA spaces the hypervisor definitely has a chance to spoil the new VA space at the old address. IMHO it should be fixed (at least documented) for the old interface.
Document - sure, feel free. Fix - I don't see how you would do this. Every component handing control onto another one would be in charge on its own. That's not under our control.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Jan BeulichHello Jan,
Quoted 23 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.05.19 at 20:12, <[email protected]> wrote:
From: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
Quoted 7 lines
So it was agreed to register runstate with the guest's physical address so that its mapping is permanent from the hypervisor point of view. [1]
The hypercall employs the same
vcpu_register_runstate_memory_areastructure for the interface, but requires a registered area to not cross a page boundary.
Quoted 6 lines
Quoted 3 lines
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg00416.html
Signed-off-by Andrii Anisov <[email protected]>I would have really hoped that you would outline the intended interaction between both interfaces,
I'd suppose no specific interaction between interfaces. I hardly imagine realistic use-cases where this might be needed.
Quoted 8 lines
such that while reviewing one can judge whether
you're actually matching the goal. I think it is actually mandatory to make
explicit in the public header what level of mixing is permitted, what is not
permitted, and what mix of requests is simply undefined.> In particular, while we did work out during prior discussions that some level of mixing has to be permitted, I'm unconvinced that arbitrary
mixing has to be allowed. For example, switching from one model to
another could be permitted only with just a single active vCPU. This
might allow to do away again with therunstate_in_usefield you add.
Well, my point here is to left it as is, maybe add more documentation. If one likes shooting his leg, we should only care about avoiding ricochet harms hypervisor or other guests. If you disagree, please suggest your interaction model, I'll be happy to implement it.
Quoted 28 lines
Quoted 28 lines
xen/arch/arm/domain.c +3
-5@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); }
Quoted 6 lines
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 293
Quoted 2 lines
xen/arch/arm/domain.c +1
-1-__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );In a prior version you did the mechanical part of adjusting the VA-based code in a prereq patch, aiding review. Is there a particular reason you folded everything into one patch now?
I silently followed suggestion from George [1]. Any objections?
Quoted 38 lines
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 307
Quoted 9 lines
xen/arch/arm/domain.c +4
-0@@ -303,6 +301,53 @@ static void update_runstate_area(struct vcpu *v) } } +static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys;What's the cast for here?
Quoted 26 lines
xen/arch/arm/domain.c +22
-0@@ -1614,6 +1613,92 @@ bool update_runstate_area(struct vcpu *v)return rc; } +static bool update_runstate_by_gpaddr_native (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + +memcpy (v->runstate_guest.phys, &v->runstate,sizeof (v->runstate)); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + }
Quoted 8 lines
xen/arch/arm/domain.c bool update_runstate_area(struct vcpu *v) · line 1640
Quoted 3 lines
xen/arch/arm/domain.c +3
-0+ +return true; +}I can't help thinking that this matches the Arm code. Can common things please be put in common code? I may be asking too much, but if the pre-existing implementations are similar enough (I didn't check) perhaps they could be folded in a first step, too?
The problem thought to be the interface: on x86 update_runstate_area() returns bool, but on ARM it is void.
But for the common function update_runstate_by_gpaddr_~native~() it would not be a problem, because we will return proper bool from the refactored update_runstate_area(). Thank you for the point.
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/domain.c +16
-0+static bool update_runstate_by_gpaddr_compat (struct vcpu *v) +{ +struct compat_vcpu_runstate_info *runstate = + (struct compat_vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + + { +struct compat_vcpu_runstate_info info;
Quoted 8 lines
xen/arch/arm/domain.c bool update_runstate_area(struct vcpu *v) · line 1661
Quoted 5 lines
xen/arch/arm/domain.c +5
-0+XLAT_vcpu_runstate_info (&info, &v->runstate); +memcpy (v->runstate_guest.phys, &info,sizeof (info)); + } +else +memcpy (v->runstate_guest.phys, &v->runstate,sizeof (v->runstate));This "else" does not seem to be paired with an
if(). Does this build at all?
This particular - not!
And it is really strange, I remember I checked patch compilation for x86. Looking through git reflog to realize at what amend it became broken. But also I do not completely understand the meaning of "_compat" and if it should be supported here?
Quoted 23 lines
xen/arch/x86/x86_64/domain.c line 15
Quoted 8 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -12,6 +12,8 @@ CHECK_vcpu_get_physid;#undef xen_vcpu_get_physid +extern void discard_runstate_area (struct vcpu *v);No, this is not allowed. The declaration must be visible to both consumer and producer, so that when either side is changed things won't build until the other side gets changed too.
xen/arch/x86/x86_64/domain.c arch_compat_vcpu_op( · line 40
Quoted 5 lines
xen/arch/x86/x86_64/domain.c +1
-0@@ -35,8 +37,16 @@ arch_compat_vcpu_op( !compat_handle_okay(area.addr.h, 1) )break ; +while (xchg (&v->runstate_in_use,1 ) ==0 );At the very least such loops want a
cpu_relax()in their bodies. But this being on a hypercall path - are there theoretical guarantees that a guest can't abuse this to lock up a CPU?
Quoted 8 lines
Furthermore I don't understand how this is supposed to work in the first place. The first
xchg()will store 1, no matter what. Thus on the second iteration you'll find the wanted value unless the other side stored 0. Yet the other side is a simplexchg()too. Hence its first attempt would fail, but its second attempt (which we didn't exit the critical region here yet) would succeed.Also - style.
Will leave this part for locking issue discussion.
Quoted 7 lines
Quoted 7 lines
xen/common/domain.c +0
-0@@ -698,6 +698,74 @@ int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d)return 0 ; }
Quoted 7 lines
xen/common/domain.c int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d) · line 705
Quoted 5 lines
xen/common/domain.c +5
-0+static void unmap_runstate_area (struct vcpu *v) +{ +mfn_t mfn; + +if ( ! v->runstate_guest.phys )Stray blank after ! .
OK.
Quoted 12 lines
xen/common/domain.c int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d) · line 714
Quoted 10 lines
xen/common/domain.c +9
-0+return ; + + mfn =domain_page_map_to_mfn (v->runstate_guest.phys); + +unmap_domain_page_global ((void *) + ((unsigned long )v->runstate_guest.phys & +PAGE_MASK )); + + v->runstate_guest.phys =NULL ;I think you would better store NULL before unmapping.
Do you mean using local variable to pass address to unmap_domain_page_global(), and setting v->runstate_guest.phys to NULL prior to unmap?
Quoted 13 lines
xen/common/domain.c int domain_kill(struct domain *d) · line 808
Quoted 9 lines
xen/common/domain.c +3
-0@@ -734,7 +802,10 @@ int domain_kill(struct domain *d)if (cpupool_move_domain (d, cpupool0) )return -ERESTART ; for_each_vcpu ( d, v ) + { +discard_runstate_area_locked (v);unmap_vcpu_info (v); + }What is the "locked" aspect here about? The guest itself is dead (i.e. fully paused) at this point, isn't it? And it won't ever be unpaused again.
You are right. All vcpus here are stopped. We can discard runstate area without locking.
Quoted 6 lines
Quoted 6 lines
xen/include/xen/sched.h +0
-0@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */
Quoted 11 lines
xen/include/xen/sched.h struct vcpu · line 173
Quoted 9 lines
xen/include/xen/sched.h +8
-0struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use;Why "unsigned long"? Isn't a bool all you need?
Bool should be enough. But it seems we will have a lock here.
Quoted 2 lines
Also these would now all want to be grouped in a sub-structure named "runstate", rather than having "
runstate_" prefixes.
Member runstate has already a type of struct vcpu_runstate_info which is an interface type.runstate_guest is a union. I'd not like moving runstate_guest union into another substructure. Because we would have long lines like v->struct.runstate_guest.virt.p->state_entry_time.
Quoted 5 lines
xen/include/xen/sched.h struct vcpu · line 188
Quoted 2 lines
xen/include/xen/sched.h +1
-0+void * phys;Bad ordering between * and the blanks. There ought to be a blank ahead of the *, and I don't see why you need any after it.
OK.
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-05/msg00599.html
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 11.06.19 at 18:09, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.05.19 at 20:12, <[email protected]> wrote:
From: Andrii Anisov <[email protected]>
Existing interface to register runstate are with its virtual address is prone to issues which became more obvious with KPTI enablement in guests. The nature of those issues is the fact that the guest could be interrupted by the hypervisor at any time, and there is no guarantee to have the registered virtual address translated with the currently available guest's page tables. Before the KPTI such a situation was possible in case the guest is caught in the middle of PT processing (e.g. superpage shattering). With the KPTI this happens also when the guest runs userspace, so has a pretty high probability.
Except when there's no need for KPTI in the guest in the first place, as is the case for x86-64 PV guests. I think this is worthwhile clarifying.
Quoted 7 lines
So it was agreed to register runstate with the guest's physical address so that its mapping is permanent from the hypervisor point of view. [1]
The hypercall employs the same
vcpu_register_runstate_memory_areastructure for the interface, but requires a registered area to not cross a page boundary.Quoted 6 lines
Quoted 3 lines
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg00416.html
Signed-off-by Andrii Anisov <[email protected]>I would have really hoped that you would outline the intended interaction between both interfaces,
I'd suppose no specific interaction between interfaces. I hardly imagine realistic use-cases where this might be needed.
Quoted 9 lines
such that while reviewing one can judge whether
you're actually matching the goal. I think it is actually mandatory to make explicit in the public header what level of mixing is permitted, what is not permitted, and what mix of requests is simply undefined.>
In particular, while we did work out during prior discussions that some level of mixing has to be permitted, I'm unconvinced that arbitrary mixing has to be allowed. For example, switching from one model to another could be permitted only with just a single active vCPU. This might allow to do away again with therunstate_in_usefield you add.
Quoted 5 lines
Well, my point here is to left it as is, maybe add more documentation. If one likes shooting his leg, we should only care about avoiding ricochet harms hypervisor or other guests.
If you disagree, please suggest your interaction model, I'll be happy to implement it.
Well, if "mix as you like" is fine for guests to follow, then okay. But we need to be _really_ certain there's no issue with this. Relaxing the interface is always possible, while tightening an interface is almost always at least a problem, if possible at all.
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/domain.c +3
-5@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); }
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 293
Quoted 2 lines
xen/arch/arm/domain.c +1
-1-__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );In a prior version you did the mechanical part of adjusting the VA-based code in a prereq patch, aiding review. Is there a particular reason you folded everything into one patch now?
I silently followed suggestion from George [1]. Any objections?
Hmm, I can't read this into George's suggestion. Aiui he did suggest not to split the definition of the new interface from its implementation. But that doesn't necessarily mean to squash _everything_ in one patch.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/arm/domain.c +16
-0+static bool update_runstate_by_gpaddr_compat (struct vcpu *v) +{ +struct compat_vcpu_runstate_info *runstate = + (struct compat_vcpu_runstate_info *)v->runstate_guest.phys; + +ASSERT (runstate !=NULL ); + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + runstate->state_entry_time |=XEN_RUNSTATE_UPDATE ; +smp_wmb (); + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + } + + { +struct compat_vcpu_runstate_info info;Quoted 8 lines
xen/arch/arm/domain.c
Quoted 5 lines
xen/arch/arm/domain.c +5
-0+XLAT_vcpu_runstate_info (&info, &v->runstate); +memcpy (v->runstate_guest.phys, &info,sizeof (info)); + } +else +memcpy (v->runstate_guest.phys, &v->runstate,sizeof (v->runstate));This "else" does not seem to be paired with an
if(). Does this build at all?
Quoted 5 lines
This particular - not!
And it is really strange, I remember I checked patch compilation for x86. Looking through git reflog to realize at what amend it became broken. But also I do not completely understand the meaning of "_compat" and if it should be supported here?
Well, I'm afraid I don't understand what you're after. Of course compat mode guests need to continue to be supported, and the new interface would also better be available to them. And it is a fact that their runstate area layout differs from that of 64-bit guests.
Quoted 10 lines
Quoted 9 lines
xen/arch/arm/domain.c
Quoted 7 lines
xen/arch/arm/domain.c +7
-0+ mfn =domain_page_map_to_mfn (v->runstate_guest.phys); + +unmap_domain_page_global ((void *) + ((unsigned long )v->runstate_guest.phys & +PAGE_MASK )); + + v->runstate_guest.phys =NULL ;I think you would better store NULL before unmapping.
Quoted 3 lines
Do you mean using local variable to pass address to
unmap_domain_page_global(), and settingv->runstate_guest.physto NULL prior to unmap?
Yes.
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/sched.h +0
-0@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ Quoted 11 lines
xen/include/xen/sched.h struct vcpu · line 173
Quoted 9 lines
xen/include/xen/sched.h +8
-0struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use;Why "unsigned long"? Isn't a bool all you need?
Bool should be enough. But it seems we will have a lock here.
Quoted 8 lines
Quoted 2 lines
Also these would now all want to be grouped in a sub-structure named "runstate", rather than having "
runstate_" prefixes.Member
runstatehas already a type ofstruct vcpu_runstate_infowhich is an interface type.runstate_guestis a union. I'd not like movingrunstate_guestunion into another substructure. Because we would have long lines likev->struct.runstate_guest.virt.p->state_entry_time.
You didn't get my point then: What I'm after is
struct {
struct vcpu_runstate_info info;
enum {
RUNSTATE_NONE,
RUNSTATE_PADDR,
RUNSTATE_VADDR,
} guest_type;
bool in_use;
} runstate;(and of course the transformation to runstate.info broken out into a separate prerreq patch).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Jan,
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Well, my point here is to left it as is, maybe add more documentation. If one likes shooting his leg, we should only care about avoiding ricochet harms hypervisor or other guests.
If you disagree, please suggest your interaction model, I'll be happy to implement it.Well, if "mix as you like" is fine for guests to follow, then okay. But we need to be _really_ certain there's no issue with this.
I'm not aware about potential problems from the guest side. Do you have any ideas about it?
Quoted 3 lines
Relaxing
the interface is always possible, while tightening an interface is almost always at least a problem, if possible at all.
True.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
In a prior version you did the mechanical part of adjusting the VA-based code in a prereq patch, aiding review. Is there a particular reason you folded everything into one patch now?
I silently followed suggestion from George [1]. Any objections?
Hmm, I can't read this into George's suggestion. Aiui he did suggest not to split the definition of the new interface from its implementation. But that doesn't necessarily mean to squash _everything_ in one patch.
OK.
It looks that what you said firstly is closer to V1 of this stuff. Will keep this in mind for the next version.
Quoted 5 lines
Well, I'm afraid I don't understand what you're after. Of course compat mode guests need to continue to be supported, and the new interface would also better be available to them. And it is a fact that their runstate area layout differs from that of 64-bit guests.
OK.
Quoted 30 lines
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/sched.h +0
-0@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ Quoted 11 lines
xen/include/xen/sched.h struct vcpu · line 173
Quoted 9 lines
xen/include/xen/sched.h +8
-0struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use;Why "unsigned long"? Isn't a bool all you need?
Bool should be enough. But it seems we will have a lock here.
Quoted 8 lines
Quoted 2 lines
Also these would now all want to be grouped in a sub-structure named "runstate", rather than having "
runstate_" prefixes.Member
runstatehas already a type ofstruct vcpu_runstate_infowhich is an interface type.runstate_guestis a union. I'd not like movingrunstate_guestunion into another substructure. Because we would have long lines likev->struct.runstate_guest.virt.p->state_entry_time.You didn't get my point then: What I'm after is
Quoted 9 lines
struct {
struct vcpu_runstate_info info;
enum {
RUNSTATE_NONE,
RUNSTATE_PADDR,
RUNSTATE_VADDR,
} guest_type;
bool in_use;
} runstate;Did you miss runstate_guest as a member of that struct?
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.06.19 at 14:17, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Well, my point here is to left it as is, maybe add more documentation. If one likes shooting his leg, we should only care about avoiding ricochet
harms
Quoted 4 lines
Quoted 3 lines
hypervisor or other guests.
If you disagree, please suggest your interaction model, I'll be happy to implement it.
Quoted 5 lines
Quoted 2 lines
Well, if "mix as you like" is fine for guests to follow, then okay. But we need to be _really_ certain there's no issue with this.
I'm not aware about potential problems from the guest side. Do you have any ideas about it?
I didn't spend time trying to figure something out, but ...
Quoted 5 lines
Quoted 3 lines
Relaxing
the interface is always possible, while tightening an interface is almost always at least a problem, if possible at all.True.
... you agreeing here suggests someone should, and this would better not (only) be the reviewer(s).
Quoted 40 lines
Quoted 30 lines
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/sched.h +0
-0@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ Quoted 11 lines
xen/include/xen/sched.h struct vcpu · line 173
Quoted 9 lines
xen/include/xen/sched.h +8
-0struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use;Why "unsigned long"? Isn't a bool all you need?
Bool should be enough. But it seems we will have a lock here.
Quoted 8 lines
Quoted 2 lines
Also these would now all want to be grouped in a sub-structure named "runstate", rather than having "
runstate_" prefixes.Member
runstatehas already a type ofstruct vcpu_runstate_infowhich is an interface type.runstate_guestis a union. I'd not like movingrunstate_guestunion into another substructure. Because we would have long lines likev->struct.runstate_guest.virt.p->state_entry_time.You didn't get my point then: What I'm after is
Quoted 9 lines
struct { struct vcpu_runstate_info info; enum { RUNSTATE_NONE, RUNSTATE_PADDR, RUNSTATE_VADDR, } guest_type; bool in_use; } runstate;
Quoted 1 line
Did you miss
runstate_guestas a member of that struct?
Quite possible. I've outlined it only anyway, for you to get the idea.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v3] xen: introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Jan BeulichSorry,
Missed one comment
Quoted 6 lines · Jan Beulich
xen/arch/arm/domain.c static void update_runstate_area(struct vcpu *v) · line 307
Quoted 4 lines
xen/arch/arm/domain.c +4
-0+static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct vcpu_runstate_info *runstate = + (struct vcpu_runstate_info *)v->runstate_guest.phys;What's the cast for here?
Seems to be not needed.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 1/1 introduce VCPUOP_register_runstate_phys_memory_area hypercall
In reply to Andrii AnisovFrom: Andrii Anisov <[email protected]>
An RFC version of the runstate registration with phys address. Runstate area access is implemented with mapping on each access, like old interface did.
--- xen/arch/arm/domain.c | 63 ++++++++++++++++++++++++++++++++++++++++++----- xen/common/domain.c | 51 +++++++++++++++++++++++++++++++++++--- xen/include/public/vcpu.h | 15 +++++++++++ xen/include/xen/sched.h | 28 +++++++++++++++------ 4 files changed, 140 insertions(+), 17 deletions(-)
xen/arch/arm/domain.c +57 -6
@@ -274,17 +274,15 @@ static void ctxt_switch_to(struct vcpu *n)virt_timer_restore (n); } -/* Update per-VCPU guest runstate shared memory area (if registered). */ -static void update_runstate_area (struct vcpu *v) +static void update_runstate_by_gvaddr (struct vcpu *v) {void __user *guest_handle =NULL ; -if (guest_handle_is_null (runstate_guest (v)) ) -return ; +ASSERT (!guest_handle_is_null (runstate_guest_virt (v)));if (VM_ASSIST (v->domain, runstate_update_flag) ) { - guest_handle = &v->runstate_guest.p->state_entry_time +1 ; + guest_handle = &v->runstate_guest.virt.p->state_entry_time +1 ; guest_handle--; v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; __raw_copy_to_guest(guest_handle,
@@ -292,7 +290,7 @@ static void update_runstate_area(struct vcpu *v)smp_wmb (); } -__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest_virt (v), &v->runstate,1 );if ( guest_handle ) {
@@ -303,6 +301,58 @@ static void update_runstate_area(struct vcpu *v) } } +extern int map_runstate_area (struct vcpu *v,struct vcpu_runstate_info **area); +extern void unmap_runstate_area (struct vcpu_runstate_info *area); + +static void update_runstate_by_gpaddr (struct vcpu *v) +{ +struct domain *d = v->domain; +paddr_t gpaddr =0 ; + + +if (VM_ASSIST (v->domain, runstate_update_flag) ) + { + gpaddr = v->runstate_guest.phys + offsetof(struct vcpu_runstate_info , state_entry_time) +sizeof (uint64_t ) -1 ; + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; +copy_to_guest_phys_flush_dcache (d, gpaddr, + (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); +smp_wmb (); + } + +copy_to_guest_phys_flush_dcache (d, v->runstate_guest.phys, &v->runstate,sizeof (struct vcpu_runstate_info )); + +if ( gpaddr ) + { + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +smp_wmb (); +copy_to_guest_phys_flush_dcache (d, gpaddr, + (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); + } +} + +/* Update per-VCPU guest runstate shared memory area (if registered). */ +static void update_runstate_area (struct vcpu *v) +{ +if (xchg (&v->runstate_in_use,1 ) ) +return ; + +switch ( v->runstate_guest_type ) + { +case RUNSTATE_NONE : +break ; + +case RUNSTATE_VADDR : +update_runstate_by_gvaddr (v); +break ; + +case RUNSTATE_PADDR : +update_runstate_by_gpaddr (v); +break ; + } + +xchg (&v->runstate_in_use,0 ); +} +static void schedule_tail (struct vcpu *prev) {ctxt_switch_from (prev);
@@ -998,6 +1048,7 @@ long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) a {case VCPUOP_register_vcpu_info:case VCPUOP_register_runstate_memory_area: +case VCPUOP_register_runstate_phys_memory_area:return do_vcpu_op (cmd, vcpuid, arg);default :return -EINVAL ;
xen/common/domain.c +47 -4
85 lines not on this page · raw message
xen/include/public/vcpu.h +15 -0
@@ -235,6 +235,21 @@ struct vcpu_register_time_memory_area {typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t ;DEFINE_XEN_GUEST_HANDLE (vcpu_register_time_memory_area_t); +/* +* Register a shared memory area from which the guest may obtain its own +* runstate information without needing to execute a hypercall. +* Notes: +* 1. The registered address must be guest's physical address. +* 2. The registered runstate area should not cross page boundary. +* 3. Only one shared area may be registered per VCPU. The shared area is +* updated by the hypervisor each time the VCPU is scheduled. Thus +* runstate.state will always be RUNSTATE_running and +* runstate.state_entry_time will indicate the system time at which the +* VCPU was last scheduled to run. +* @extra_arg == pointer to vcpu_register_runstate_memory_area structure. +*/ +#define VCPUOP_register_runstate_phys_memory_area 14 +#endif /* __XEN_PUBLIC_VCPU_H__ */ /*
xen/include/xen/sched.h +21 -7
@@ -163,17 +163,31 @@ struct vcpuvoid *sched_priv;/* scheduler-specific data */ struct vcpu_runstate_info runstate; + +enum { +RUNSTATE_NONE =0 , +RUNSTATE_PADDR =1 , +RUNSTATE_VADDR =2 , + } runstate_guest_type; + +unsigned long runstate_in_use; + +union + {#ifndef CONFIG_COMPAT -# define runstate_guest (v) ((v)->runstate_guest) -XEN_GUEST_HANDLE (vcpu_runstate_info_t) runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt) +XEN_GUEST_HANDLE (vcpu_runstate_info_t) virt;/* guest address */ #else -# define runstate_guest (v) ((v)->runstate_guest.native) -union { -XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; -XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; - } runstate_guest;/* guest address */ +# define runstate_guest_virt (v) ((v)->runstate_guest.virt.native) +union { +XEN_GUEST_HANDLE (vcpu_runstate_info_t) native; +XEN_GUEST_HANDLE (vcpu_runstate_info_compat_t) compat; + } virt;/* guest address */ #endif +paddr_t phys; + } runstate_guest; +/* last time when vCPU is scheduled out */ uint64_t last_run_time;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Andrii,
I am not answering on the content yet, I will do that separately. The threading for this series looks quite confusing. The head of the thread is this patch (i.e RFC 2) but then you have a cover letter within the thread tagged "V3".
From what I understand, the 2 e-mails tagged "V3" is the original version where as RFC 2 and RFC 3 are variants. Am I correct?
If so, for next time, I would recommend to have the cover letter first and then all the patches send "In-Reply-To" the cover letter. This makes easier to track series.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hello Julien,
Quoted 1 line · Julien Grall
I am not answering on the content yet, I will do that separately. The threading for this series looks quite confusing. The head of the thread is this patch (i.e RFC 2) but then you have a cover letter within the thread tagged "V3".
Actually I've noticed the mangled threading. But not sure why it is so. I just passed a folder with those patches to git-send-mail.
Quoted 1 line
From what I understand, the 2 e-mails tagged "V3" is the original version where as RFC 2 and RFC 3 are variants. Am I correct?
Yes, sure.
Quoted 1 line
If so, for next time, I would recommend to have the cover letter first and then all the patches send "In-Reply-To" the cover letter. This makes easier to track series.
It might help. But before it worked well without additional tricks.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Andrii Anisov
Hello Julien,
Quoted 1 line · Julien Grall
I am not answering on the content yet, I will do that separately. The threading for this series looks quite confusing. The head of the thread is this patch (i.e RFC 2) but then you have a cover letter within the thread tagged "V3".
Actually I've noticed the mangled threading. But not sure why it is so. I just passed a folder with those patches to git-send-mail.
IIRC, git-send-email will use the first e-mail in the alphabetical order as the "top e-mail" and all the other will be send "In-Reply-To".
Quoted 8 lines
Quoted 2 lines
From what I understand, the 2 e-mails tagged "V3" is the original version where as RFC 2 and RFC 3 are variants. Am I correct?
Yes, sure.
Quoted 1 line
If so, for next time, I would recommend to have the cover letter first and then all the patches send "In-Reply-To" the cover letter. This makes easier to track series.
It might help. But before it worked well without additional tricks.
In general, all the patch sent are starting with a number followed by the title. The number ensure the correct ordering. If you don't have number then, you will fallback to alphabetical order.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 1 line · Julien Grall
In general, all the patch sent are starting with a number followed by the title. The number ensure the correct ordering. If you don't have number then, you will fallback to alphabetical order.
Ah, yes, sure. I did rename manually RFC1 patch file. But somewhy missed renaming RFC2 patch file.
Signature · 7 lines
Sincerely, Andrii Anisov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel