Support consistent reads of mapped vcpu_runstate_info
Subsystems (8)
Juergen Gross
maintainercover Support consistent reads of mapped vcpu_runstate_info
A guest mapping vcpu_runstate_info into its memory can't read this information from another cpu but the one the data is referring to. Reason is there is no reliable way for the guest to detect a concurrent data update by the hypervisor.
This patch series adds an update flag to the mapped data which can be used by the guest to detect an update is occurring. As this flag is modifying the current interface it has to be activated by using a vm_assist hypercall, which in turn has to be made available for ARM.
Runtime tested on x86 with a modified Linux kernel using the new feature.
Compile tested only for ARM.
Juergen Gross (2):
xen/arm: add support for vm_assist hypercall
xen: add update indicator to vcpu_runstate_info
xen/arch/arm/domain.c | 22 ++++++++++++++++++++++ xen/arch/arm/traps.c | 1 + xen/arch/x86/domain.c | 31 +++++++++++++++++++++++++++++++ xen/common/domain.c | 2 -- xen/common/kernel.c | 2 -- xen/include/asm-arm/config.h | 2 ++ xen/include/asm-x86/config.h | 1 + xen/include/public/vcpu.h | 6 ++++++ xen/include/public/xen.h | 7 +++++++ 9 files changed, 70 insertions(+), 4 deletions(-)
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH 1/2 xen/arm: add support for vm_assist hypercall
Up to now the vm_assist hypercall hasn't been supported on ARM, as there are only x86 specific features to switch. Add support of vm_assist on ARM for future use.
--- xen/arch/arm/traps.c | 1 + xen/common/domain.c | 2 -- xen/common/kernel.c | 2 -- xen/include/asm-arm/config.h | 2 ++ 4 files changed, 3 insertions(+), 4 deletions(-)
xen/arch/arm/traps.c +1 -0
@@ -1284,6 +1284,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(vm_assist, 2), };#ifndef NDEBUG
xen/common/domain.c +0 -2
@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {
@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd, unsigned int type,return -ENOSYS ; } -#endif struct pirq *pirq_get_info (struct domain *d,int pirq) {
xen/common/kernel.c +0 -2
@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif DO (ni_hypercall)(void ) {
xen/include/asm-arm/config.h +2 -0
@@ -199,6 +199,8 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) +#define VM_ASSIST_VALID (0) +#endif /* __ARM_CONFIG_H__ */ /* * Local variables:
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Hi Juergen,
Quoted 5 lines · Juergen Gross
Up to now the
vm_assisthypercall hasn't been supported on ARM, as there are only x86 specific features to switch. Add support ofvm_assiston ARM for future use.Signed-off-by Juergen Gross <[email protected]>
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
In reply to Juergen GrossQuoted 23 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-2@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 9 lines
xen/common/kernel.c +0
-2@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif
Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-2@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c +0
-0@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; }
Quoted 10 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 6 lines
xen/common/kernel.c +0
-2-#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Removing is not necessary, right.
OTOH there is no arch left needing those #ifdef-s to be in place. Or do you think we should guard each single functionality in xen/common by such means? I don't think so. In this case keeping the #ifdef-s would be for historical reasons only.
If you really want I can keep them or do the removal in a separate patch if you want to split functional addition and related cleanup.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 16:42, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/common/domain.c long do_vcpu_op(int cmd, unsigned int vcpuid,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-0@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 14 lines
Quoted 14 lines
xen/common/domain.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif Quoted 5 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd,
Quoted 5 lines
xen/common/domain.c +0
-0struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c +0
-0@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 13 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 9 lines
xen/common/kernel.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Quoted 6 lines
Removing is not necessary, right.
OTOH there is no arch left needing those #ifdef-s to be in place. Or do you think we should guard each single functionality in xen/common by such means? I don't think so. In this case keeping the #ifdef-s would be for historical reasons only.
No, I don't want to go overboard with this. But we added these not so long ago, so I see no reason why they should now be removed again, just to maybe have them added in a couple of years again.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 48 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 16:42, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/common/domain.c long do_vcpu_op(int cmd, unsigned int vcpuid,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-0@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 14 lines
Quoted 14 lines
xen/common/domain.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif Quoted 5 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd,
Quoted 5 lines
xen/common/domain.c +0
-0struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c +0
-0@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 13 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 9 lines
xen/common/kernel.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Quoted 6 lines
Removing is not necessary, right.
OTOH there is no arch left needing those #ifdef-s to be in place. Or do you think we should guard each single functionality in xen/common by such means? I don't think so. In this case keeping the #ifdef-s would be for historical reasons only.
Quoted 4 lines
No, I don't want to go overboard with this. But we added these not so long ago, so I see no reason why they should now be removed again, just to maybe have them added in a couple of years again.
Hmm, those #ifdef-s where needed for ARM, as on ARM there just was no flag to be set via vm_assist hypercall. The new flag added in the next patch is suitable for all architectures, so there would be no reason for not supporting vm_assist in a new to be supported architecture.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:08, <[email protected]> wrote:
Quoted 48 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 16:42, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/common/domain.c long do_vcpu_op(int cmd, unsigned int vcpuid,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-0@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 14 lines
Quoted 14 lines
xen/common/domain.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif Quoted 5 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd,
Quoted 5 lines
xen/common/domain.c +0
-0struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c +0
-0@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 13 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 9 lines
xen/common/kernel.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Quoted 6 lines
Removing is not necessary, right.
OTOH there is no arch left needing those #ifdef-s to be in place. Or do you think we should guard each single functionality in xen/common by such means? I don't think so. In this case keeping the #ifdef-s would be for historical reasons only.
Quoted 4 lines
No, I don't want to go overboard with this. But we added these not so long ago, so I see no reason why they should now be removed again, just to maybe have them added in a couple of years again.
Quoted 4 lines
Hmm, those #ifdef-s where needed for ARM, as on ARM there just was no flag to be set via
vm_assisthypercall. The new flag added in the next patch is suitable for all architectures, so there would be no reason for not supportingvm_assistin a new to be supported architecture.
Hmm, you have a point here. Otoh new architectures should probably assume that behavior even without having explicitly asked for it.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 55 lines · Jan Beulich
Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:08, <[email protected]> wrote:
Quoted 52 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 16:42, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/common/domain.c long do_vcpu_op(int cmd, unsigned int vcpuid,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/common/domain.c +0
-0@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 14 lines
Quoted 14 lines
xen/common/domain.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd,unsigned int type, return -ENOSYS; } -#endif Quoted 5 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd,
Quoted 5 lines
xen/common/domain.c +0
-0struct pirq *pirq_get_info (struct domain *d,int pirq){
xen/common/kernel.c +0
-0@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 13 lines
xen/common/kernel.c DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 449
Quoted 9 lines
xen/common/kernel.c +0
-2return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif Removing these #ifdef-s is neither necessary for this patch (at least afaict) nor desirable (after all they had got added so that an arch doesn't get this code compiled for no reason).
Quoted 6 lines
Removing is not necessary, right.
OTOH there is no arch left needing those #ifdef-s to be in place. Or do you think we should guard each single functionality in xen/common by such means? I don't think so. In this case keeping the #ifdef-s would be for historical reasons only.
No, I don't want to go overboard with this. But we added these not so long ago, so I see no reason why they should now be removed again, just to maybe have them added in a couple of years again.
Quoted 8 lines
Quoted 4 lines
Hmm, those #ifdef-s where needed for ARM, as on ARM there just was no flag to be set via
vm_assisthypercall. The new flag added in the next patch is suitable for all architectures, so there would be no reason for not supportingvm_assistin a new to be supported architecture.Hmm, you have a point here. Otoh new architectures should probably assume that behavior even without having explicitly asked for it.
I don't think so, but you are the maintainer. In case there are no objections by other maintainers I'll leave the #ifdef-s in place.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Stefano Stabellini
maintainerRe: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
In reply to Juergen GrossQuoted 66 lines · Juergen Gross
Up to now the
vm_assisthypercall hasn't been supported on ARM, as there are only x86 specific features to switch. Add support ofvm_assiston ARM for future use.Signed-off-by Juergen Gross <[email protected]>--- xen/arch/arm/traps.c | 1 + xen/common/domain.c | 2 -- xen/common/kernel.c | 2 -- xen/include/asm-arm/config.h | 2 ++ 4 files changed, 3 insertions(+), 4 deletions(-)xen/arch/arm/traps.c +1
-0@@ -1284,6 +1284,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(vm_assist, 2), };#ifndef NDEBUG xen/common/domain.c +0
-2@@ -1408,7 +1408,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID long vm_assist (struct domain *p,unsigned int cmd,unsigned int type,unsigned long valid) {@@ -1427,7 +1426,6 @@ long vm_assist(struct domain *p, unsigned int cmd, unsigned int type,return -ENOSYS ; } -#endif struct pirq *pirq_get_info (struct domain *d,int pirq) {xen/common/kernel.c +0
-2@@ -441,12 +441,10 @@ DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {return vm_assist (current->domain, cmd, type,VM_ASSIST_VALID ); } -#endif DO (ni_hypercall)(void ) {xen/include/asm-arm/config.h +0
-0
xen/include/asm-arm/config.h extern unsigned long frametable_virt_end; · line 202
Quoted 4 lines
xen/include/asm-arm/config.h +1
-0@@ -199,6 +199,8 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) +#define VM_ASSIST_VALID (0)
This is a nit, but as VM_ASSIST_VALID is only used with #ifdef, I would just:
#define VM_ASSIST_VALID
the two previous #define are to 0, because they are replacing functions.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Hi Stefano,
Quoted 8 lines · Stefano Stabellini
Quoted 8 lines
xen/include/asm-arm/config.h +0
-0@@ -199,6 +199,8 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0)
Quoted 8 lines
xen/include/asm-arm/config.h extern unsigned long frametable_virt_end; · line 202
Quoted 1 line
xen/include/asm-arm/config.h +1
-0+#define VM_ASSIST_VALID (0)This is a nit, but as
VM_ASSIST_VALIDis only used with #ifdef, I would just:#define
VM_ASSIST_VALIDthe two previous #define are to 0, because they are replacing functions.
VM_ASSIST_VALID is used as an argument for vm_assist (see kernel.c) to know which option is valid. We have to define VM_ASSIST_VALID to 0 because there no valid option for the moment on ARM.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Stefano Stabellini
maintainerRe: [PATCH 1/2] xen/arm: add support for vm_assist hypercall
Quoted 16 lines · Julien Grall
Hi Stefano,
Quoted 13 lines · Stefano Stabellini
xen/include/asm-arm/config.h extern unsigned long frametable_virt_end; · line 202
Quoted 9 lines
xen/include/asm-arm/config.h +1
-0@@ -199,6 +199,8 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) +#define VM_ASSIST_VALID (0)This is a nit, but as
VM_ASSIST_VALIDis only used with #ifdef, I would just:
Quoted 7 lines
Quoted 3 lines
#define
VM_ASSIST_VALIDthe two previous #define are to 0, because they are replacing functions.
VM_ASSIST_VALIDis used as an argument forvm_assist(seekernel.c) to know which option is valid. We have to defineVM_ASSIST_VALIDto 0 because there no valid option for the moment on ARM.
Ah, I missed that one. And I see that in the following patch is updated with the new bit.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH 2/2 xen: add update indicator to vcpu_runstate_info
In reply to Juergen GrossIn order to support reading another vcpu's mapped vcpu_runstate_info an indicator for an occurring update of the runstate information is needed.
Add the possibility to activate setting this indicator in the highest bit of state_entry_time via a vm_assist hypercall. When activated the update indicator will be set before the runstate information is modified in guest memory and it will be reset after modification is done. As state_entry_time is guaranteed to be different after each update the guest can detect any update (either in progress or while reading the runstate data) by comparing state_entry_time before and after reading runstate data: in case the values differ or the update indicator was set the data might be inconsistent and should be reread.
--- xen/arch/arm/domain.c | 22 ++++++++++++++++++++++ xen/arch/x86/domain.c | 31 +++++++++++++++++++++++++++++++ xen/include/asm-arm/config.h | 2 +- xen/include/asm-x86/config.h | 1 + xen/include/public/vcpu.h | 6 ++++++ xen/include/public/xen.h | 7 +++++++ 6 files changed, 68 insertions(+), 1 deletion(-)
xen/arch/arm/domain.c +22 -0
@@ -239,10 +239,32 @@ static void ctxt_switch_to(struct vcpu *n)/* Update per-VCPU guest runstate shared memory area (if registered). */ static void update_runstate_area (struct vcpu *v) { +bool_t update_flag; +void __user *guest_handle =NULL ; +unsigned off =0 ; +if (guest_handle_is_null (runstate_guest (v)) )return ; + update_flag =VM_ASSIST (v->domain, runstate_update_flag); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ; + guest_handle = v->runstate_guest.p; + guest_handle += off; + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); +wmb (); + } +__copy_to_guest (runstate_guest (v), &v->runstate,1 ); + +if ( update_flag ) + { + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +wmb (); +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); + } }static void schedule_tail (struct vcpu *prev)
xen/arch/x86/domain.c +31 -0
@@ -1925,13 +1925,37 @@ static void paravirt_ctxt_switch_to(struct vcpu *v)bool_t update_runstate_area (struct vcpu *v) {bool_t rc; +bool_t update_flag;smap_check_policy_t smap_policy; +void __user *guest_handle =NULL ; +unsigned off =0 ;if (guest_handle_is_null (runstate_guest (v)) )return 1 ; + update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED ); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ; +if (has_32bit_shinfo (v->domain) ) + { + guest_handle = v->runstate_guest.compat.p; + guest_handle += offsetof(struct compat_vcpu_runstate_info , + state_entry_time) +7 ; + } +else + { + guest_handle = v->runstate_guest.native.p; + guest_handle += off; + } + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); +wmb (); + } +if (has_32bit_shinfo (v->domain) ) {struct compat_vcpu_runstate_info info;
@@ -1944,6 +1968,13 @@ bool_t update_runstate_area(struct vcpu *v) rc =__copy_to_guest (runstate_guest (v), &v->runstate,1 ) !=sizeof (v->runstate); +if ( update_flag ) + { + v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; +wmb (); +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); + } +smap_policy_change (v, smap_policy);return rc;
xen/include/asm-arm/config.h +1 -1
@@ -199,7 +199,7 @@ extern unsigned long frametable_virt_end;#define watchdog_disable () ((void)0)#define watchdog_enable () ((void)0) -#define VM_ASSIST_VALID (0) +#define VM_ASSIST_VALID (1UL << VMASST_TYPE_runstate_update_flag)#endif /* __ARM_CONFIG_H__ */ /*
xen/include/asm-x86/config.h +1 -0
@@ -332,6 +332,7 @@ extern unsigned long xen_phys_start; (1UL << VMASST_TYPE_writable_pagetables) | \ (1UL << VMASST_TYPE_pae_extended_cr3) | \ (1UL << VMASST_TYPE_architectural_iopl) | \ + (1UL << VMASST_TYPE_runstate_update_flag)| \ (1UL << VMASST_TYPE_m2p_strict))#define VM_ASSIST_VALID NATIVE_VM_ASSIST_VALID#define COMPAT_VM_ASSIST_VALID (NATIVE_VM_ASSIST_VALID & \
xen/include/public/vcpu.h +6 -0
@@ -84,6 +84,12 @@ struct vcpu_runstate_info {/* When was current state entered (system time, ns)? */ uint64_t state_entry_time;/* +* Update indicator set in state_entry_time: +* When activated via VMASST_TYPE_runstate_update_flag, set during +* updates in guest memory mapped copy of vcpu_runstate_info. +*/ +#define XEN_RUNSTATE_UPDATE (1ULL << 63) +/* * Time spent in each RUNSTATE_* (ns). The sum of these times is * guaranteed not to drift from system time. */
xen/include/public/xen.h +7 -0
@@ -510,6 +510,13 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);#define VMASST_TYPE_architectural_iopl 4/* +* All guests: activate update indicator in vcpu_runstate_info +* Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped +* vcpu_runstate_info during updates of the runstate information. +*/ +#define VMASST_TYPE_runstate_update_flag 5 + +/* * x86/64 guests: strictly hide M2P from user mode. * This allows the guest to control respective hypervisor behavior: * - when not set, L4 tables get created with the respective slot blank,
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 14 lines · Juergen Gross
xen/arch/arm/domain.c +4
-0@@ -239,10 +239,32 @@ static void ctxt_switch_to(struct vcpu *n)/* Update per-VCPU guest runstate shared memory area (if registered). */ static void update_runstate_area (struct vcpu *v) { +bool_t update_flag; +void __user *guest_handle =NULL ; +unsigned off =0 ; +if (guest_handle_is_null (runstate_guest (v)) )return ;
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 257
Quoted 10 lines
xen/arch/arm/domain.c +9
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ; + guest_handle = v->runstate_guest.p; + guest_handle += off; + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); +wmb ();
smp_wmb(), throughout.
A whole lot of code gets this wrong in Xen, and plan to clean it all up in 4.8
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Juergen Gross
xen/arch/arm/domain.c +4
-0@@ -239,10 +239,32 @@ static void ctxt_switch_to(struct vcpu *n)/* Update per-VCPU guest runstate shared memory area (if registered). */ static void update_runstate_area (struct vcpu *v) { +bool_t update_flag; +void __user *guest_handle =NULL ; +unsigned off =0 ; +if (guest_handle_is_null (runstate_guest (v)) )return ;
Quoted 11 lines
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 257
Quoted 9 lines
xen/arch/arm/domain.c +9
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ; + guest_handle = v->runstate_guest.p; + guest_handle += off; + v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; +__raw_copy_to_guest (guest_handle, (void *)&v->runstate + off,1 ); +wmb ();
smp_wmb(), throughout.
Okay.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
In reply to Juergen Grossxen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1928
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-0@@ -1925,13 +1925,37 @@ static void paravirt_ctxt_switch_to(struct vcpu *v)bool_t update_runstate_area (struct vcpu *v) {bool_t rc; +bool_t update_flag;
I think this variable is superfluous (and causes more register pressure in the compiler), since ...
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1930
Quoted 2 lines
xen/arch/x86/domain.c +1
-0smap_check_policy_t smap_policy; +void __user *guest_handle =NULL ;
... you can key off of this being non-NULL or ...
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1931
Quoted 1 line
xen/arch/x86/domain.c +1
-0+unsigned off =0 ;
... this being non-zero in the second if().
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1942
Quoted 10 lines
xen/arch/x86/domain.c +5
-0if (guest_handle_is_null (runstate_guest (v)) )return 1 ; + update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED ); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;
How come this is outside the following if()? Also sizeof(...) - 1 please instead of the literal 7.
xen/include/public/vcpu.h struct vcpu_runstate_info { · line 91
Quoted 11 lines
xen/include/public/vcpu.h +5
-0@@ -84,6 +84,12 @@ struct vcpu_runstate_info {/* When was current state entered (system time, ns)? */ uint64_t state_entry_time;/* +* Update indicator set in state_entry_time: +* When activated via VMASST_TYPE_runstate_update_flag, set during +* updates in guest memory mapped copy of vcpu_runstate_info. +*/ +#define XEN_RUNSTATE_UPDATE (1ULL << 63)
I think this should be UINT64_C(1), as ULL is not a C89 compatible suffix, but by requiring uint64_t I think we can imply that along with that C99 type the platform also surfaces respective macros.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 12 lines · Jan Beulich
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1928
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-0@@ -1925,13 +1925,37 @@ static void paravirt_ctxt_switch_to(struct vcpu *v)bool_t update_runstate_area (struct vcpu *v) {bool_t rc; +bool_t update_flag;I think this variable is superfluous (and causes more register pressure in the compiler), since ...
Quoted 8 lines
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1930
Quoted 2 lines
xen/arch/x86/domain.c +1
-0smap_check_policy_t smap_policy; +void __user *guest_handle =NULL ;... you can key off of this being non-NULL or ...
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1931
Quoted 1 line
xen/arch/x86/domain.c +1
-0+unsigned off =0 ;... this being non-zero in the second
if().
Okay. Will change.
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/domain.c +2
-0if (guest_handle_is_null (runstate_guest (v)) )return 1 ; + update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED );
Quoted 6 lines
xen/arch/x86/domain.c static void paravirt_ctxt_switch_to(struct vcpu *v) · line 1941
Quoted 3 lines
xen/arch/x86/domain.c +3
-0+if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.
I'm using off for the source address in __raw_copy_to_guest(), too. Regarding sizeof(): okay.
Quoted 16 lines
xen/include/public/vcpu.h struct vcpu_runstate_info { · line 91
Quoted 12 lines
xen/include/public/vcpu.h +5
-0@@ -84,6 +84,12 @@ struct vcpu_runstate_info {/* When was current state entered (system time, ns)? */ uint64_t state_entry_time;/* +* Update indicator set in state_entry_time: +* When activated via VMASST_TYPE_runstate_update_flag, set during +* updates in guest memory mapped copy of vcpu_runstate_info. +*/ +#define XEN_RUNSTATE_UPDATE (1ULL << 63)I think this should be
UINT64_C(1), as ULL is not a C89 compatible suffix, but by requiringuint64_tI think we can imply that along with that C99 type the platform also surfaces respective macros.
Okay.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:04, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
if ( guest_handle_is_null(runstate_guest(v)) )
return 1;xen/arch/x86/domain.c +2
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED );
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 252
Quoted 3 lines
xen/arch/arm/domain.c +3
-0+if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.I'm using off for the source address in
__raw_copy_to_guest(), too.
But the offset should, afaict, be different for 32-bit (x86) and 64-bit (or ARM).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:04, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
if ( guest_handle_is_null(runstate_guest(v)) )
return 1;xen/arch/x86/domain.c +5
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED ); +if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.I'm using off for the source address in
__raw_copy_to_guest(), too.But the offset should, afaict, be different for 32-bit (x86) and 64-bit (or ARM).
Why? The offset is applied to v->runstate which clearly is the same for 32 and 64 bit domains, as it is the hypervisor private structure. Different offsets have to be applied at the destination side only, and this is done properly (at least I think so).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:54, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:04, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
if ( guest_handle_is_null(runstate_guest(v)) )
return 1;xen/arch/x86/domain.c +2
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED );Quoted 6 lines
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 252
Quoted 3 lines
xen/arch/arm/domain.c +3
-0+if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.I'm using off for the source address in
__raw_copy_to_guest(), too.
Quoted 7 lines
Quoted 2 lines
But the offset should, afaict, be different for 32-bit (x86) and 64-bit (or ARM).
Why? The offset is applied to
v->runstatewhich clearly is the same for 32 and 64 bit domains, as it is the hypervisor private structure. Different offsets have to be applied at the destination side only, and this is done properly (at least I think so).
But as you say you use the offset for two purposes: The use on the guest handle is which is problematic; the use on the hypervisor internal structure is of course fine.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Stefano Stabellini
maintainerRe: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:54, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:04, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
if ( guest_handle_is_null(runstate_guest(v)) )
return 1;xen/arch/x86/domain.c +2
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED );Quoted 8 lines
Quoted 6 lines
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 252
Quoted 3 lines
xen/arch/arm/domain.c +3
-0+if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.I'm using off for the source address in
__raw_copy_to_guest(), too.But the offset should, afaict, be different for 32-bit (x86) and 64-bit (or ARM).
Quoted 8 lines
Quoted 4 lines
Why? The offset is applied to
v->runstatewhich clearly is the same for 32 and 64 bit domains, as it is the hypervisor private structure. Different offsets have to be applied at the destination side only, and this is done properly (at least I think so).But as you say you use the offset for two purposes: The use on the guest handle is which is problematic; the use on the hypervisor internal structure is of course fine.
The code is a bit ugly, but it looks like it would work on ARM
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Juergen Gross
maintainerRe: [PATCH 2/2] xen: add update indicator to vcpu_runstate_info
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:54, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 17:04, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.05.16 at 15:22, <[email protected]> wrote:
if ( guest_handle_is_null(runstate_guest(v)) )
return 1;xen/arch/x86/domain.c +2
-0+ update_flag =VM_ASSIST (v->domain, runstate_update_flag); + smap_policy =smap_policy_change (v,SMAP_CHECK_ENABLED );Quoted 8 lines
Quoted 6 lines
xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 252
Quoted 3 lines
xen/arch/arm/domain.c +3
-0+if ( update_flag ) + { + off = offsetof(struct vcpu_runstate_info , state_entry_time) +7 ;How come this is outside the following
if()? Also sizeof(...) - 1 please instead of the literal 7.I'm using off for the source address in
__raw_copy_to_guest(), too.But the offset should, afaict, be different for 32-bit (x86) and 64-bit (or ARM).
Quoted 8 lines
Quoted 4 lines
Why? The offset is applied to
v->runstatewhich clearly is the same for 32 and 64 bit domains, as it is the hypervisor private structure. Different offsets have to be applied at the destination side only, and this is done properly (at least I think so).But as you say you use the offset for two purposes: The use on the guest handle is which is problematic; the use on the hypervisor internal structure is of course fine.
In the compat case I don't use it for the guest_handle:
+ if ( has_32bit_shinfo(v->domain) )
+ {
+ guest_handle = v->runstate_guest.compat.p;
+ guest_handle += offsetof(struct compat_vcpu_runstate_info,
+ state_entry_time) + 7;
+ }
+ else
+ {+ guest_handle = v->runstate_guest.native.p;
+ guest_handle += off;
+ }
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Hi Juergen,
Quoted 5 lines · Juergen Gross
A guest mapping
vcpu_runstate_infointo its memory can't read this information from another cpu but the one the data is referring to. Reason is there is no reliable way for the guest to detect a concurrent data update by the hypervisor.
Quoted 8 lines
This patch series adds an update flag to the mapped data which can be used by the guest to detect an update is occurring. As this flag is modifying the current interface it has to be activated by using a
vm_assisthypercall, which in turn has to be made available for ARM.Runtime tested on x86 with a modified Linux kernel using the new feature.
Compile tested only for ARM.
I would like to give a go on ARM. Who it be possible to provide the patch for Linux and how to test it?
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 13 lines · Julien Grall
Hi Juergen,
Quoted 10 lines · Juergen Gross
A guest mapping
vcpu_runstate_infointo its memory can't read this information from another cpu but the one the data is referring to. Reason is there is no reliable way for the guest to detect a concurrent data update by the hypervisor.This patch series adds an update flag to the mapped data which can be used by the guest to detect an update is occurring. As this flag is modifying the current interface it has to be activated by using a
vm_assisthypercall, which in turn has to be made available for ARM.
Quoted 6 lines
Quoted 3 lines
Runtime tested on x86 with a modified Linux kernel using the new feature.
Compile tested only for ARM.I would like to give a go on ARM. Who it be possible to provide the patch for Linux and how to test it?
Sure. You'll need the four attached patches (to be applied on top of kernel 4.6). With CONFIG_PARAVIRT_TIME_ACCOUNTING set in the kernel config, full functionality will be used (without being set the runstate info of other cpus won't be read).
You can verify the vm_assist hypercall has worked via "xl debug-keys q" and "xl dmesg | grep vm_assist" (value should be 00000020 on ARM).
Juergen
Quoted 1 line
From
689b4ba8c13be73ed51e485a7f7baea593d0ce6eMon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Tue, 17 May 2016 14:03:02 +0200
Subject: [PATCH v4] xen: add steal_clock support on x86
The pv_time_ops structure contains a function pointer for the "steal_clock" functionality used only by KVM and Xen on ARM. Xen on x86 uses its own mechanism to account for the "stolen" time a thread wasn't able to run due to hypervisor scheduling.
Add support in Xen arch independent time handling for this feature by moving it out of the arm arch into drivers/xen and remove the x86 Xen hack.
---
V4: minor adjustments as requested by Stefano Stabellini (remove
no longer needed #include, remove __init from header)
V3: add #include <asm/paravirt.h> to avoid build error on arm
V2: remove the x86 do_stolen_accounting() hack
--- arch/arm/xen/enlighten.c | 18 ++---------------- arch/x86/xen/time.c | 44 ++------------------------------------------ drivers/xen/time.c | 20 ++++++++++++++++++++ include/linux/kernel_stat.h | 1 - include/xen/xen-ops.h | 1 + kernel/sched/cputime.c | 10 ---------- 6 files changed, 25 insertions(+), 69 deletions(-)
arch/arm/xen/enlighten.c +2 -16
@@ -12,7 +12,6 @@#include <xen/page.h> #include <xen/interface/sched.h> #include <xen/xen-ops.h> -#include <asm/paravirt.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <asm/system_misc.h>
@@ -84,19 +83,6 @@ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, }EXPORT_SYMBOL_GPL (xen_unmap_domain_gfn_range); -static unsigned long long xen_stolen_accounting (int cpu) -{ -struct vcpu_runstate_info state; - -BUG_ON (cpu !=smp_processor_id ()); - -xen_get_runstate_snapshot (&state); - -WARN_ON (state.state != RUNSTATE_running); - -return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline]; -} -static void xen_read_wallclock (struct timespec64 *ts) {u32 version;
@@ -355,8 +341,8 @@ static int __init xen_guest_init(void)register_cpu_notifier (&xen_cpu_notifier); - pv_time_ops.steal_clock = xen_stolen_accounting; -static_key_slow_inc (¶virt_steal_enabled); +xen_time_setup_guest (); +if (xen_initial_domain ())pvclock_gtod_register_notifier (&xen_pvclock_gtod_notifier);
arch/x86/xen/time.c +2 -42
68 lines not on this page · raw message
drivers/xen/time.c +20 -0
@@ -6,6 +6,7 @@#include <linux/math64.h> #include <linux/gfp.h> +#include <asm/paravirt.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -75,6 +76,15 @@ bool xen_vcpu_stolen(int vcpu)return per_cpu (xen_runstate, vcpu).state == RUNSTATE_runnable; } +static u64 xen_steal_clock (int cpu) +{ +struct vcpu_runstate_info state; + +BUG_ON (cpu !=smp_processor_id ()); +xen_get_runstate_snapshot (&state); +return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline]; +} +void xen_setup_runstate_info (int cpu) {struct vcpu_register_runstate_memory_area area;
@@ -86,3 +96,13 @@ void xen_setup_runstate_info(int cpu)BUG (); } +void __init xen_time_setup_guest (void ) +{ + pv_time_ops.steal_clock = xen_steal_clock; + +static_key_slow_inc (¶virt_steal_enabled); +/* +* We can't set paravirt_steal_rq_enabled as this would require the +* capability to read another cpu's runstate info. +*/ +}
include/linux/kernel_stat.h +0 -1
@@ -92,7 +92,6 @@ static inline void account_process_tick(struct task_struct *tsk, int user)extern void account_process_tick (struct task_struct *,int user);#endif -extern void account_steal_ticks (unsigned long ticks);extern void account_idle_ticks (unsigned long ticks);#endif /* _LINUX_KERNEL_STAT_H */
include/xen/xen-ops.h +1 -0
@@ -21,6 +21,7 @@ void xen_resume_notifier_unregister(struct notifier_block *nb);bool xen_vcpu_stolen (int vcpu);void xen_setup_runstate_info (int cpu); +void xen_time_setup_guest (void );void xen_get_runstate_snapshot (struct vcpu_runstate_info *res);int xen_setup_shutdown_event (void );
kernel/sched/cputime.c +0 -10
@@ -490,16 +490,6 @@ void account_process_tick(struct task_struct *p, int user_tick) }/* -* Account multiple ticks of steal time. -* @p: the process from which the cpu time has been stolen -* @ticks: number of stolen ticks -*/ -void account_steal_ticks (unsigned long ticks) -{ -account_steal_time (jiffies_to_cputime (ticks)); -} - -/* * Account multiple ticks of idle time. * @ticks: number of stolen ticks */
Signature · 1 line
2.6.6
Quoted 1 line
From
4073bb301aed18981ec69c3cf5f0df4fae567d7cMon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Fri, 20 May 2016 09:32:30 +0200
Subject: [PATCH 1/3] xen: update xen headers
Update some Xen headers to be able to use new functionality.
--- include/xen/interface/vcpu.h | 24 +++++++++++++++--------- include/xen/interface/xen.h | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-)
include/xen/interface/vcpu.h +15 -9
@@ -75,15 +75,21 @@*/ #define VCPUOP_get_runstate_info 4struct vcpu_runstate_info { -/* VCPU's current state (RUNSTATE_*). */ -int state; -/* When was current state entered (system time, ns)? */ -uint64_t state_entry_time; -/* -* Time spent in each RUNSTATE_* (ns). The sum of these times is -* guaranteed not to drift from system time. -*/ -uint64_t time[4 ]; +/* VCPU's current state (RUNSTATE_*). */ +int state; +/* When was current state entered (system time, ns)? */ +uint64_t state_entry_time; +/* +* Update indicator set in state_entry_time: +* When activated via VMASST_TYPE_runstate_update_flag, set during +* updates in guest memory mapped copy of vcpu_runstate_info. +*/ +#define XEN_RUNSTATE_UPDATE (1ULL << 63) +/* +* Time spent in each RUNSTATE_* (ns). The sum of these times is +* guaranteed not to drift from system time. +*/ +uint64_t time[4 ]; };DEFINE_GUEST_HANDLE_STRUCT (vcpu_runstate_info);
include/xen/interface/xen.h +16 -1
@@ -413,7 +413,22 @@ DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);/* x86/PAE guests: support PDPTs above 4GB. */ #define VMASST_TYPE_pae_extended_cr3 3 -#define MAX_VMASST_TYPE 3 +/* +* x86 guests: Sane behaviour for virtual iopl +* - virtual iopl updated from do_iret() hypercalls. +* - virtual iopl reported in bounce frames. +* - guest kernels assumed to be level 0 for the purpose of iopl checks. +*/ +#define VMASST_TYPE_architectural_iopl 4 + +/* +* All guests: activate update indicator in vcpu_runstate_info +* Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped +* vcpu_runstate_info during updates of the runstate information. +*/ +#define VMASST_TYPE_runstate_update_flag 5 + +#define MAX_VMASST_TYPE 5#ifndef __ASSEMBLY__
Signature · 1 line
2.6.6
Quoted 1 line
From
ab457b88c03a66c6051ac022b51bc5c218f48842Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Fri, 20 May 2016 12:08:21 +0200
Subject: [PATCH 2/3] arm/xen: add support for vm_assist hypercall
Add support for the Xen HYPERVISOR_vm_assist hypercall.
--- arch/arm/include/asm/xen/hypercall.h | 1 + arch/arm/xen/enlighten.c | 1 + arch/arm/xen/hypercall.S | 1 + arch/arm64/xen/hypercall.S | 1 + 4 files changed, 4 insertions(+)
arch/arm/include/asm/xen/hypercall.h +1 -0
@@ -52,6 +52,7 @@ int HYPERVISOR_memory_op(unsigned int cmd, void *arg);int HYPERVISOR_physdev_op (int cmd,void *arg);int HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args);int HYPERVISOR_tmem_op (void *arg); +int HYPERVISOR_vm_assist (unsigned int cmd,unsigned int type);int HYPERVISOR_platform_op_raw (void *arg);static inline int HYPERVISOR_platform_op (struct xen_platform_op *op) {
arch/arm/xen/enlighten.c +1 -0
@@ -389,4 +389,5 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op);EXPORT_SYMBOL_GPL (HYPERVISOR_tmem_op);EXPORT_SYMBOL_GPL (HYPERVISOR_platform_op);EXPORT_SYMBOL_GPL (HYPERVISOR_multicall); +EXPORT_SYMBOL_GPL (HYPERVISOR_vm_assist);EXPORT_SYMBOL_GPL (privcmd_call);
arch/arm/xen/hypercall.S +1 -0
@@ -91,6 +91,7 @@ HYPERCALL3(vcpu_op); HYPERCALL1(tmem_op); HYPERCALL1(platform_op_raw); HYPERCALL2(multicall); +HYPERCALL2(vm_assist); ENTRY(privcmd_call) stmdb sp!, {r4}
arch/arm64/xen/hypercall.S +1 -0
@@ -82,6 +82,7 @@ HYPERCALL3(vcpu_op); HYPERCALL1(tmem_op); HYPERCALL1(platform_op_raw); HYPERCALL2(multicall); +HYPERCALL2(vm_assist); ENTRY(privcmd_call) mov x16, x0
Signature · 1 line
2.6.6
Quoted 1 line
From
f27da1aba6c9c92add4f88b4dcec517e5e321caaMon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Fri, 20 May 2016 12:25:58 +0200
Subject: [PATCH 3/3] xen: support runqueue steal time on xen
Up to now reading the stolen time of a remote cpu was not possible in a performant way under Xen. This made support of runqueue steal time via paravirt_steal_rq_enabled impossible.
With the addition of an appropriate hypervisor interface this is now possible, so add the support.
--- drivers/xen/time.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
drivers/xen/time.c +25 -17
77 lines not on this page · raw message
Signature · 1 line
2.6.6
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel