Common hypercall handing improvements
PATCH 1/1 Common hypercall handing improvements
This original purpose of this work was towards the RFC patch at the end of the series, but there turned out to be a lot of cleanup opportunity in common and ARM code as well.
Andrew Cooper (7):
x86/hypercall: Make the HVM hcall_preempted boolean common arm/hypercall: Use the common hcall_preempted boolean xen/multicall: Use the common hcall_preempted boolean x86/hypercall: Make the HVM hcall_64bit boolean common x86/hypercall: Split out PV hypercall infrastructure x86/hypercall: Move hypercall continuation logic [RFC] x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
xen/arch/arm/domain.c | 19 +--
xen/arch/arm/traps.c | 16 +-
xen/arch/x86/Kconfig | 68 ++++++--
xen/arch/x86/Makefile | 3 +-
xen/arch/x86/domain.c | 198 ----------------------
xen/arch/x86/hvm/hvm.c | 9 +-
xen/arch/x86/hvm/hypercall.c | 19 +--
xen/arch/x86/hypercall.c | 326 +++++++++++++++++--------------------
xen/arch/x86/pv/Makefile | 1 +
xen/arch/x86/{ => pv}/hypercall.c | 78 ++-------
xen/common/multicall.c | 4 +-
xen/include/asm-x86/hvm/vcpu.h | 3 -
xen/include/xen/multicall.h | 2 -
xen/include/xen/sched.h | 6 +
xen/tools/kconfig/allrandom.config | 4 +
15 files changed, 252 insertions(+), 504 deletions(-)
create mode 100644 xen/arch/x86/pv/Makefile
copy xen/arch/x86/{ => pv}/hypercall.c (82%)Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/1 x86/hypercall: Make the HVM hcall_preempted boolean common
HVM guests currently make use of arch.hvm_vcpu.hcall_preempted to track hypercall preemption in struct vcpu. Move this boolean to being common at the top level of struct vcpu, which will allow it to be reused elsewhere.
Alter the PV preemption logic to use this boolean. This simplifies the code by removing guest-type-specific knowledge, and removes the risk of accidently skipping backwards or forwards multiple times and corrupting %rip.
In pv_hypercall() the old_rip bodge can be removed, and parameter clobbering can happen based on a more obvious condition.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/domain.c | 16 ++-------------- xen/arch/x86/hvm/hypercall.c | 8 ++++---- xen/arch/x86/hypercall.c | 17 ++++++++++++----- xen/include/asm-x86/hvm/vcpu.h | 1 - xen/include/xen/sched.h | 2 ++ 5 files changed, 20 insertions(+), 24 deletions(-)
xen/arch/x86/domain.c +2 -14
@@ -2198,20 +2198,12 @@ void sync_vcpu_execstate(struct vcpu *v)void hypercall_cancel_continuation (void ) { -struct cpu_user_regs *regs =guest_cpu_user_regs ();struct mc_state *mcs = ¤t->mc_state;if ( mcs->flags & MCSF_in_multicall ) - {__clear_bit (_MCSF_call_preempted, &mcs->flags); - }else - { -if (is_pv_vcpu (current) ) - regs->rip +=2 ;/* skip re-execute 'syscall' / 'int $xx' */ -else - current->arch.hvm_vcpu.hcall_preempted =0 ; - } + current->hcall_preempted = false; } unsigned long hypercall_create_continuation(
@@ -2239,11 +2231,7 @@ unsigned long hypercall_create_continuation( regs->rax = op; -/* Ensure the hypercall trap instruction is re-executed. */ -if (is_pv_vcpu (curr) ) - regs->rip -=2 ;/* re-execute 'syscall' / 'int $xx' */ -else - curr->arch.hvm_vcpu.hcall_preempted =1 ; + curr->hcall_preempted = true; if ( is_pv_vcpu(curr) ? !is_pv_32bit_vcpu(curr) :
xen/arch/x86/hvm/hypercall.c +4 -4
@@ -176,7 +176,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)return HVM_HCALL_completed; } - curr->arch.hvm_vcpu.hcall_preempted =0 ; + curr->hcall_preempted = false;if ( mode ==8 ) {
@@ -210,7 +210,7 @@ int hvm_hypercall(struct cpu_user_regs *regs) curr->arch.hvm_vcpu.hcall_64bit =0 ;#ifndef NDEBUG -if ( !curr->arch.hvm_vcpu.hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( hypercall_args_table[eax].native )
@@ -254,7 +254,7 @@ int hvm_hypercall(struct cpu_user_regs *regs) ebp);#ifndef NDEBUG -if ( !curr->arch.hvm_vcpu.hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( hypercall_args_table[eax].compat )
@@ -272,7 +272,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)HVM_DBG_LOG (DBG_LEVEL_HCALL ,"hcall%lu -> %lx" , eax, regs->rax); -if ( curr->arch.hvm_vcpu.hcall_preempted ) +if ( curr->hcall_preempted )return HVM_HCALL_preempted; if ( unlikely(currd->arch.hvm_domain.qemu_mapcache_invalidate) &&
xen/arch/x86/hypercall.c +12 -5
@@ -141,9 +141,6 @@ static const hypercall_table_t pv_hypercall_table[] = {void pv_hypercall (struct cpu_user_regs *regs) {struct vcpu *curr = current; -#ifndef NDEBUG -unsigned long old_rip = regs->rip; -#endif unsigned long eax;ASSERT (guest_kernel_mode (curr, regs));
@@ -160,6 +157,8 @@ void pv_hypercall(struct cpu_user_regs *regs)return ; } + curr->hcall_preempted = false; +if ( !is_pv_32bit_vcpu (curr) ) {unsigned long rdi = regs->rdi;
@@ -191,7 +190,7 @@ void pv_hypercall(struct cpu_user_regs *regs) regs->rax = pv_hypercall_table[eax].native (rdi, rsi, rdx, r10, r8, r9);#ifndef NDEBUG -if ( regs->rip == old_rip ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( hypercall_args_table[eax].native )
@@ -238,7 +237,7 @@ void pv_hypercall(struct cpu_user_regs *regs) regs->_eax = pv_hypercall_table[eax].compat (ebx, ecx, edx, esi, edi, ebp);#ifndef NDEBUG -if ( regs->rip == old_rip ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( hypercall_args_table[eax].compat )
@@ -254,6 +253,14 @@ void pv_hypercall(struct cpu_user_regs *regs)#endif } +/* +* PV guests use SYSCALL or INT $0x82 to make a hypercall, both of which +* have trap semantics. If the hypercall has been preempted, rewind the +* instruction pointer to reexecute the instruction. +*/ +if ( curr->hcall_preempted ) + regs->rip -=2 ; +perfc_incr (hypercalls); }
xen/include/asm-x86/hvm/vcpu.h +0 -1
@@ -166,7 +166,6 @@ struct hvm_vcpu {bool debug_state_latch;bool single_step; -bool hcall_preempted;bool hcall_64bit;struct hvm_vcpu_asid n1asid;
xen/include/xen/sched.h +2 -0
@@ -202,6 +202,8 @@ struct vcpubool paused_for_shutdown;/* VCPU need affinity restored */ bool affinity_broken; +/* A hypercall has been preempted. */ +bool hcall_preempted;/*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 1/7] x86/hypercall: Make the HVM hcall_preempted boolean common
xen/include/xen/sched.h struct vcpu · line 209
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
xen/include/xen/sched.h +2
-0@@ -202,6 +202,8 @@ struct vcpubool paused_for_shutdown;/* VCPU need affinity restored */ bool affinity_broken; +/* A hypercall has been preempted. */ +bool hcall_preempted;/*
Would you mind moving this addition between the two existing blank lines, so that together with the later movement here of hcall_64bit the two appear as a proper pair? With that
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 1/1 arm/hypercall: Use the common hcall_preempted boolean
In reply to Andrew CooperWith hcall_preempted having just been made common, ARM can use use it to simplify its hypercall handling.
This simplifies the continuation logic and removes the risk of accidentally skipping multiple instructions.
---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
NB: Only compile tested, not functionally tested. However, it is basically an identical transformation as done to x86 PV guests in the previous patch, which I have tested thoroughly.
--- xen/arch/arm/domain.c | 10 ++-------- xen/arch/arm/traps.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-)
xen/arch/arm/domain.c +2 -8
@@ -349,17 +349,12 @@ void sync_vcpu_execstate(struct vcpu *v)void hypercall_cancel_continuation (void ) { -struct cpu_user_regs *regs =guest_cpu_user_regs ();struct mc_state *mcs = ¤t->mc_state;if ( mcs->flags & MCSF_in_multicall ) - {__clear_bit (_MCSF_call_preempted, &mcs->flags); - }else - { - regs->pc +=4 ;/* undo re-execute 'hvc #XEN_HYPERCALL_TAG' */ - } + current->hcall_preempted = false; } unsigned long hypercall_create_continuation(
@@ -391,8 +386,7 @@ unsigned long hypercall_create_continuation( { regs =guest_cpu_user_regs (); -/* Ensure the hypercall trap instruction is re-executed. */ - regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + current->hcall_preempted = true;#ifdef CONFIG_ARM_64 if ( !is_32bit_domain (current->domain) )
xen/arch/arm/traps.c +8 -8
@@ -1454,9 +1454,6 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, unsigned long iss) {arm_hypercall_fn_t call =NULL ; -#ifndef NDEBUG -register_t orig_pc = regs->pc; -#endif BUILD_BUG_ON (NR_hypercalls <ARRAY_SIZE (arm_hypercall_table) );
@@ -1470,6 +1467,8 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,return ; } + current->hcall_preempted = false; +perfc_incra (hypercalls, *nr); call = arm_hypercall_table[*nr].fn;if ( call ==NULL )
@@ -1481,12 +1480,9 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,HYPERCALL_RESULT_REG (regs) =call (HYPERCALL_ARGS (regs));#ifndef NDEBUG -/* -* Clobber argument registers only if pc is unchanged, otherwise -* this is a hypercall continuation. -*/ -if ( orig_pc == regs->pc ) +if ( !current->hcall_preempted ) { +/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( arm_hypercall_table[*nr].nr_args ) {case 5 :HYPERCALL_ARG5 (regs) =0xDEADBEEF ;case 4 :HYPERCALL_ARG4 (regs) =0xDEADBEEF ;
@@ -1499,6 +1495,10 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, *nr = 0xDEADBEEF; }#endif + +/* Ensure the hypercall trap instruction is re-executed. */ +if ( current->hcall_preempted ) + regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ }static bool check_multicall_32bit_clean (struct multicall_entry *multi)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] arm/hypercall: Use the common hcall_preempted boolean
Hi Andrew,
Quoted 7 lines · Andrew Cooper
With
hcall_preemptedhaving just been made common, ARM can use use it to simplify its hypercall handling.This simplifies the continuation logic and removes the risk of accidentally skipping multiple instructions.
Signed-off-by Andrew Cooper <[email protected]>
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/1 xen/multicall: Use the common hcall_preempted boolean
In reply to Andrew CooperThe now-common hcall_preempted boolean is perfectly usable for multicalls. Remove the multicall-specific preemption mechanism.
---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/arm/domain.c | 13 +++---------- xen/arch/x86/domain.c | 19 ++++++------------- xen/common/multicall.c | 4 +++- xen/include/xen/multicall.h | 2 -- 4 files changed, 12 insertions(+), 26 deletions(-)
xen/arch/arm/domain.c +3 -10
@@ -349,12 +349,7 @@ void sync_vcpu_execstate(struct vcpu *v)void hypercall_cancel_continuation (void ) { -struct mc_state *mcs = ¤t->mc_state; - -if ( mcs->flags & MCSF_in_multicall ) -__clear_bit (_MCSF_call_preempted, &mcs->flags); -else - current->hcall_preempted = false; + current->hcall_preempted = false; } unsigned long hypercall_create_continuation(
@@ -370,12 +365,12 @@ unsigned long hypercall_create_continuation(/* All hypercalls take at least one argument */ BUG_ON ( !p || *p =='\0' ); + current->hcall_preempted = true; +va_start (args, format);if ( mcs->flags & MCSF_in_multicall ) { -__set_bit (_MCSF_call_preempted, &mcs->flags); -for ( i =0 ; *p !='\0' ; i++ ) mcs->call.args[i] =next_arg (p, args);
@@ -386,8 +381,6 @@ unsigned long hypercall_create_continuation( { regs =guest_cpu_user_regs (); - current->hcall_preempted = true; -#ifdef CONFIG_ARM_64 if ( !is_32bit_domain (current->domain) ) {
xen/arch/x86/domain.c +6 -13
@@ -2198,41 +2198,34 @@ void sync_vcpu_execstate(struct vcpu *v)void hypercall_cancel_continuation (void ) { -struct mc_state *mcs = ¤t->mc_state; - -if ( mcs->flags & MCSF_in_multicall ) -__clear_bit (_MCSF_call_preempted, &mcs->flags); -else - current->hcall_preempted = false; + current->hcall_preempted = false; }unsigned long hypercall_create_continuation (unsigned int op,const char *format, ...) { -struct mc_state *mcs = ¤t->mc_state; +struct vcpu *curr = current; +struct mc_state *mcs = &curr->mc_state;const char *p = format;unsigned long arg;unsigned int i;va_list args; + curr->hcall_preempted = true; +va_start (args, format);if ( mcs->flags & MCSF_in_multicall ) { -__set_bit (_MCSF_call_preempted, &mcs->flags); -for ( i =0 ; *p !='\0' ; i++ ) mcs->call.args[i] =next_arg (p, args); }else {struct cpu_user_regs *regs =guest_cpu_user_regs (); -struct vcpu *curr = current; regs->rax = op; - curr->hcall_preempted = true; -if (is_pv_vcpu (curr) ? !is_pv_32bit_vcpu (curr) : curr->arch.hvm_vcpu.hcall_64bit )
@@ -2293,7 +2286,7 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,if ( mcs->flags & MCSF_in_multicall ) { -if ( !(mcs->flags & MCSF_call_preempted) ) +if ( !current->hcall_preempted ) {va_end (args);return 0 ;
xen/common/multicall.c +3 -1
@@ -79,7 +79,7 @@ do_multicall(if (unlikely (__copy_field_to_guest (call_list, &mcs->call, result)) ) rc = -EFAULT ; -else if ( mcs->flags & MCSF_call_preempted ) +else if ( current->hcall_preempted ) {/* Translate sub-call continuation to guest layout */ xlat_multicall_entry (mcs);
@@ -87,6 +87,8 @@ do_multicall(/* Copy the sub-call continuation. */ if (likely (!__copy_to_guest (call_list, &mcs->call,1 )) ) goto preempted; +else +hypercall_cancel_continuation (); rc = -EFAULT ; }else
xen/include/xen/multicall.h +0 -2
@@ -11,9 +11,7 @@#endif #define _MCSF_in_multicall 0 -#define _MCSF_call_preempted 1#define MCSF_in_multicall (1<<_MCSF_in_multicall) -#define MCSF_call_preempted (1<<_MCSF_call_preempted) struct mc_state { unsigned long flags; union {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] xen/multicall: Use the common hcall_preempted boolean
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
The now-common
hcall_preemptedboolean is perfectly usable for multicalls.
Something must have gone in the wrong order here: This is not part of a series, and I can't see hcall_preempted being common in staging.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] xen/multicall: Use the common hcall_preempted boolean
Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
The now-common
hcall_preemptedboolean is perfectly usable for multicalls.Something must have gone in the wrong order here: This is not part of a series, and I can't see
hcall_preemptedbeing common in staging.
Sorry. I fumbled git format-patch and omitted the patch numbers.
The correct order of the series is:
Andrew Cooper (7):
x86/hypercall: Make the HVM hcall_preempted boolean common arm/hypercall: Use the common hcall_preempted boolean xen/multicall: Use the common hcall_preempted boolean x86/hypercall: Make the HVM hcall_64bit boolean common x86/hypercall: Split out PV hypercall infrastructure x86/hypercall: Move hypercall continuation logic [RFC] x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/7] xen/multicall: Use the common hcall_preempted boolean
In reply to Andrew CooperQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
The now-common
hcall_preemptedboolean is perfectly usable for multicalls. Remove the multicall-specific preemption mechanism.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] xen/multicall: Use the common hcall_preempted boolean
In reply to Andrew CooperHi Andrew,
Quoted 4 lines · Andrew Cooper
The now-common
hcall_preemptedboolean is perfectly usable for multicalls. Remove the multicall-specific preemption mechanism.Signed-off-by Andrew Cooper <[email protected]>
For the ARM bits:
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/1 x86/hypercall: Make the HVM hcall_64bit boolean common
In reply to Andrew CooperHVM guests currently make use of arch.hvm_vcpu.hcall_64bit to track the ABI of the hypercall in use.
The rest of Xen deals in terms of the comat ABI or not, so rename the boolean and make it common, guared by CONFIG_COMPAT to avoid bloat if a compat ABI is not wanted/needed.
Set hcall_compat uniformly for PV guests as well as HVM guests. This removes the remaining piece of guest-type-specific knowledge from hypercall_create_continuation(), allowing it to operate only in terms of the hypercall ABI in use.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/domain.c | 4 +--- xen/arch/x86/hvm/hvm.c | 9 +++------ xen/arch/x86/hvm/hypercall.c | 11 +++++------ xen/arch/x86/hypercall.c | 2 ++ xen/include/asm-x86/hvm/vcpu.h | 2 -- xen/include/xen/sched.h | 4 ++++ 6 files changed, 15 insertions(+), 17 deletions(-)
xen/arch/x86/domain.c +1 -3
@@ -2226,9 +2226,7 @@ unsigned long hypercall_create_continuation( regs->rax = op; -if (is_pv_vcpu (curr) ? - !is_pv_32bit_vcpu (curr) : - curr->arch.hvm_vcpu.hcall_64bit ) +if ( !curr->hcall_compat ) {for ( i =0 ; *p !='\0' ; i++ ) {
xen/arch/x86/hvm/hvm.c +3 -6
@@ -3254,8 +3254,7 @@ unsigned long copy_to_user_hvm(void *to, const void *from, unsigned int len) {int rc; -if ( !current->arch.hvm_vcpu.hcall_64bit && -is_compat_arg_xlat_range (to, len) ) +if ( current->hcall_compat &&is_compat_arg_xlat_range (to, len) ) {memcpy (to, from, len);return 0 ;
@@ -3269,8 +3268,7 @@ unsigned long clear_user_hvm(void *to, unsigned int len) {int rc; -if ( !current->arch.hvm_vcpu.hcall_64bit && -is_compat_arg_xlat_range (to, len) ) +if ( current->hcall_compat &&is_compat_arg_xlat_range (to, len) ) {memset (to,0x00 , len);return 0 ;
@@ -3284,8 +3282,7 @@ unsigned long copy_from_user_hvm(void *to, const void *from, unsigned len) {int rc; -if ( !current->arch.hvm_vcpu.hcall_64bit && -is_compat_arg_xlat_range (from, len) ) +if ( current->hcall_compat &&is_compat_arg_xlat_range (from, len) ) {memcpy (to, from, len);return 0 ;
xen/arch/x86/hvm/hypercall.c +5 -6
@@ -35,7 +35,7 @@ static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } -if ( curr->arch.hvm_vcpu.hcall_64bit ) +if ( !curr->hcall_compat ) rc =do_memory_op (cmd, arg);else rc =compat_memory_op (cmd, arg);
@@ -65,7 +65,7 @@ static long hvm_grant_table_op(return -ENOSYS ; } -if ( current->arch.hvm_vcpu.hcall_64bit ) +if ( !current->hcall_compat )return do_grant_table_op (cmd, uop, count);else return compat_grant_table_op (cmd, uop, count);
@@ -89,7 +89,7 @@ static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } -if ( curr->arch.hvm_vcpu.hcall_64bit ) +if ( !curr->hcall_compat )return do_physdev_op (cmd, arg);else return compat_physdev_op (cmd, arg);
@@ -203,12 +203,9 @@ int hvm_hypercall(struct cpu_user_regs *regs) }#endif - curr->arch.hvm_vcpu.hcall_64bit =1 ; regs->rax = hvm_hypercall_table[eax].native (rdi, rsi, rdx, r10, r8, r9); - curr->arch.hvm_vcpu.hcall_64bit =0 ; -#ifndef NDEBUG if ( !curr->hcall_preempted ) {
@@ -250,8 +247,10 @@ int hvm_hypercall(struct cpu_user_regs *regs) }#endif + curr->hcall_compat = true; regs->rax = hvm_hypercall_table[eax].compat (ebx, ecx, edx, esi, edi, ebp); + curr->hcall_compat = false;#ifndef NDEBUG if ( !curr->hcall_preempted )
xen/arch/x86/hypercall.c +2 -0
@@ -234,7 +234,9 @@ void pv_hypercall(struct cpu_user_regs *regs)__trace_hypercall (TRC_PV_HYPERCALL_V2 , eax, args); } + curr->hcall_compat = true; regs->_eax = pv_hypercall_table[eax].compat (ebx, ecx, edx, esi, edi, ebp); + curr->hcall_compat = false;#ifndef NDEBUG if ( !curr->hcall_preempted )
xen/include/asm-x86/hvm/vcpu.h +0 -2
@@ -166,8 +166,6 @@ struct hvm_vcpu {bool debug_state_latch;bool single_step; -bool hcall_64bit; -struct hvm_vcpu_asid n1asid;u32 msr_tsc_aux;
xen/include/xen/sched.h +4 -0
@@ -204,6 +204,10 @@ struct vcpubool affinity_broken;/* A hypercall has been preempted. */ bool hcall_preempted; +#ifdef CONFIG_COMPAT +/* A hypercall is using the compat ABI? */ +bool hcall_compat; +#endif /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 4/7] x86/hypercall: Make the HVM hcall_64bit boolean common
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
HVM guests currently make use of arch.hvm_vcpu.hcall_64bit to track the ABI of the hypercall in use.
The rest of Xen deals in terms of the comat ABI or not, so rename the boolean and make it common, guared by
CONFIG_COMPATto avoid bloat if a compat ABI is not wanted/needed.
Quoted 6 lines
Set
hcall_compatuniformly for PV guests as well as HVM guests. This removes the remaining piece of guest-type-specific knowledge fromhypercall_create_continuation(), allowing it to operate only in terms of the hypercall ABI in use.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 1/1 x86/hypercall: Split out PV hypercall infrastructure
In reply to Andrew CooperRepurpose arch/x86/hypercall.c to be common x86 hypercall infrastructure, and move the PV specific routines to arch/x86/pv/hypercall.c
This is purely code motion.
---
CC: Jan Beulich <[email protected]>
---
xen/arch/x86/Makefile | 1 +
xen/arch/x86/hypercall.c | 226 +-------------------------------------
xen/arch/x86/pv/Makefile | 1 +
xen/arch/x86/{ => pv}/hypercall.c | 59 +---------
4 files changed, 8 insertions(+), 279 deletions(-)
create mode 100644 xen/arch/x86/pv/Makefile
copy xen/arch/x86/{ => pv}/hypercall.c (84%)xen/arch/x86/Makefile +1 -0
@@ -4,6 +4,7 @@ subdir-y += genapic subdir-y += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile +subdir-y += pv subdir-y += x86_64 alternative-y := alternative.init.o
xen/arch/x86/hypercall.c +2 -224
245 lines not on this page · raw message
xen/arch/x86/pv/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += hypercall.o
xen/arch/x86/pv/hypercall.c renamed from xen/arch/x86/hypercall.c +4 -55
75 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] x86/hypercall: Split out PV hypercall infrastructure
xen/arch/x86/pv/hypercall.c line 2
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
xen/arch/x86/pv/hypercall.c renamed from xen/arch/x86/hypercall.c +1
-1@@ -1,5 +1,7 @@/****************************************************************************** -* arch/x86/hypercall.c +* arch/pv/hypercall.c
arch/x86/pv/hypercall.c (if we really need files to name themselves)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 1/1 x86/hypercall: Move hypercall continuation logic
In reply to Andrew CooperThe newly-repurposed arch/x86/hypercall.c is a more appropriate place for the hypercall continuation logic to live.
This is purely code motion.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/domain.c | 177 ----------------------------------------------- xen/arch/x86/hypercall.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 177 deletions(-)
xen/arch/x86/domain.c +0 -177
@@ -2184,183 +2184,6 @@ void sync_vcpu_execstate(struct vcpu *v)flush_tlb_mask (v->vcpu_dirty_cpumask); } -#define next_arg (fmt, args) ({ \ - unsigned long __arg; \ - switch ( *(fmt)++ ) \ - { \ - case 'i': __arg = (unsigned long)va_arg(args, unsigned int); break; \ - case 'l': __arg = (unsigned long)va_arg(args, unsigned long); break; \ - case 'h': __arg = (unsigned long)va_arg(args, void *); break; \ - default: __arg = 0; BUG(); \ - } \ - __arg; \ -}) - -void hypercall_cancel_continuation (void ) -{ - current->hcall_preempted = false; -} - -unsigned long hypercall_create_continuation ( -unsigned int op,const char *format, ...) -{ -struct vcpu *curr = current; -struct mc_state *mcs = &curr->mc_state; -const char *p = format; -unsigned long arg; -unsigned int i; -va_list args; - - curr->hcall_preempted = true; - -va_start (args, format); - -if ( mcs->flags & MCSF_in_multicall ) - { -for ( i =0 ; *p !='\0' ; i++ ) - mcs->call.args[i] =next_arg (p, args); - } -else - { -struct cpu_user_regs *regs =guest_cpu_user_regs (); - - regs->rax = op; - -if ( !curr->hcall_compat ) - { -for ( i =0 ; *p !='\0' ; i++ ) - { - arg =next_arg (p, args); -switch ( i ) - { -case 0 : regs->rdi = arg;break ; -case 1 : regs->rsi = arg;break ; -case 2 : regs->rdx = arg;break ; -case 3 : regs->r10 = arg;break ; -case 4 : regs->r8 = arg;break ; -case 5 : regs->r9 = arg;break ; - } - } - } -else - { -for ( i =0 ; *p !='\0' ; i++ ) - { - arg =next_arg (p, args); -switch ( i ) - { -case 0 : regs->rbx = arg;break ; -case 1 : regs->rcx = arg;break ; -case 2 : regs->rdx = arg;break ; -case 3 : regs->rsi = arg;break ; -case 4 : regs->rdi = arg;break ; -case 5 : regs->rbp = arg;break ; - } - } - } - } - -va_end (args); - -return op; -} - -int hypercall_xlat_continuation (unsigned int *id,unsigned int nr, -unsigned int mask, ...) -{ -int rc =0 ; -struct mc_state *mcs = ¤t->mc_state; -struct cpu_user_regs *regs; -unsigned int i, cval =0 ; -unsigned long nval =0 ; -va_list args; - -ASSERT (nr <=ARRAY_SIZE (mcs->call.args)); -ASSERT (!(mask >> nr)); -ASSERT (!id || *id < nr); -ASSERT (!id || !(mask & (1U << *id))); - -va_start (args, mask); - -if ( mcs->flags & MCSF_in_multicall ) - { -if ( !current->hcall_preempted ) - { -va_end (args); -return 0 ; - } - -for ( i =0 ; i < nr; ++i, mask >>=1 ) - { -if ( mask &1 ) - { - nval = va_arg(args, unsigned long); - cval = va_arg(args, unsigned int); -if ( cval == nval ) - mask &= ~1U ; -else -BUG_ON (nval == (unsigned int )nval); - } -else if ( id && *id == i ) - { - *id = mcs->call.args[i]; - id =NULL ; - } -if ( (mask &1 ) && mcs->call.args[i] == nval ) - { - mcs->call.args[i] = cval; - ++rc; - } -else -BUG_ON (mcs->call.args[i] != (unsigned int )mcs->call.args[i]); - } - } -else - { - regs =guest_cpu_user_regs (); -for ( i =0 ; i < nr; ++i, mask >>=1 ) - { -unsigned long *reg; - -switch ( i ) - { -case 0 : reg = ®s->rbx;break ; -case 1 : reg = ®s->rcx;break ; -case 2 : reg = ®s->rdx;break ; -case 3 : reg = ®s->rsi;break ; -case 4 : reg = ®s->rdi;break ; -case 5 : reg = ®s->rbp;break ; -default :BUG (); reg =NULL ;break ; - } -if ( (mask &1 ) ) - { - nval = va_arg(args, unsigned long); - cval = va_arg(args, unsigned int); -if ( cval == nval ) - mask &= ~1U ; -else -BUG_ON (nval == (unsigned int )nval); - } -else if ( id && *id == i ) - { - *id = *reg; - id =NULL ; - } -if ( (mask &1 ) && *reg == nval ) - { - *reg = cval; - ++rc; - } -else -BUG_ON (*reg != (unsigned int )*reg); - } - } - -va_end (args); - -return rc; -} -static int relinquish_memory (struct domain *d,struct page_list_head *list,unsigned long type) {
xen/arch/x86/hypercall.c +177 -0
183 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] x86/hypercall: Move hypercall continuation logic
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
The newly-repurposed
arch/x86/hypercall.cis a more appropriate place for the hypercall continuation logic to live.This is purely code motion.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
RFC PATCH 1/1 x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
In reply to Andrew CooperMaking PV and HVM guests individually compilable is useful as a reduction in hypervisor size, and as an aid to enforcing clean API boundaries.
Introduce CONFIG_PV and CONFIG_HVM, although there is a lot of work to do until either can actually be disabled.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/Kconfig | 68 ++++++++++++++++++++++++++++---------- xen/arch/x86/Makefile | 4 +-- xen/tools/kconfig/allrandom.config | 4 +++ 3 files changed, 56 insertions(+), 20 deletions(-)
xen/arch/x86/Kconfig +50 -18
@@ -32,6 +32,56 @@ menu "Architecture Features" source "arch/Kconfig" +config PV + def_bool y + prompt "PV guest support" if EXPERT = "y" + depends on X86 + ---help--- + Support for Xen Paravirtual guests. + + Xen PV guests use Ring Deprivileging as a method of virtualisation. + This requires no specific hardware support, but does require an OS + capable of running PV under Xen. + + If unsure, say Y. + + TODO: This is a work in process, and Xen doesn't currently compile + if this option is disabled. + +config HVM + def_bool y + prompt "HVM guest support" if EXPERT = "y" + depends on X86 + ---help--- + Support for Xen Hardware Virtual Machine guests. + + Xen HVM guests use hardware virtualisation extentions (Intel VT-x, + AMD SVM) to run OSes. This requires a CPU with appropriate + extentions, but can in principle run any OS, even if unmodified. + + If unsure, say Y. + + TODO: This is a work in process, and Xen doesn't currently compile + if this option is disabled. + +config HVM_FEP + bool "HVM Forced Emulation Prefix support" if EXPERT = "y" + default DEBUG + depends on HVM + ---help--- + Compiles in a feature that allows HVM guest to arbitrarily + exercise the instruction emulator. + + This feature can only be enabled during boot time with + appropriate hypervisor command line option. Please read + hypervisor command line documentation before trying to use + this feature. + + This is strictly for testing purposes, and not appropriate + for use in production. + + If unsure, say N. + config SHADOW_PAGING bool "Shadow Paging" default y
@@ -61,24 +111,6 @@ config BIGMEM If unsure, say N. -config HVM_FEP - bool "HVM Forced Emulation Prefix support" if EXPERT = "y" - default DEBUG - ---help--- - - Compiles in a feature that allows HVM guest to arbitrarily - exercise the instruction emulator. - - This feature can only be enabled during boot time with - appropriate hypervisor command line option. Please read - hypervisor command line documentation before trying to use - this feature. - - This is strictly for testing purposes, and not appropriate - for use in production. - - If unsure, say N. - config TBOOT def_bool y prompt "Xen tboot support" if EXPERT = "y"
xen/arch/x86/Makefile +2 -2
@@ -1,10 +1,10 @@ subdir-y += acpi subdir-y += cpu subdir-y += genapic -subdir-y += hvm +subdir-$(CONFIG_HVM) += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile -subdir-y += pv +subdir-$(CONFIG_PV) += pv subdir-y += x86_64 alternative-y := alternative.init.o
xen/tools/kconfig/allrandom.config +4 -0
@@ -1,3 +1,7 @@ # Explicit option choices not subject to regular RANDCONFIG CONFIG_GCOV_FORMAT_AUTODETECT=y + +# Being able to compile-out guest subsystems is a work-in-progress. +CONFIG_PV=y +CONFIG_HVM=y
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] [RFC] x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
Making PV and HVM guests individually compilable is useful as a reduction in hypervisor size, and as an aid to enforcing clean API boundaries.
Introduce
CONFIG_PVandCONFIG_HVM, although there is a lot of work to do until either can actually be disabled.
While this is a nice goal, is it really useful to add these config options now, rather than when that lot of work is at least near completion? Or otherwise, how about making them prompt-less for now even for EXPERT?
Quoted 16 lines
xen/arch/x86/Kconfig +10
-0@@ -32,6 +32,56 @@ menu "Architecture Features" source "arch/Kconfig" +config PV + def_bool y + prompt "PV guest support" if EXPERT = "y" + depends on X86 + ---help--- + Support for Xen Paravirtual guests. + + Xen PV guests use Ring Deprivileging as a method of virtualisation. + This requires no specific hardware support, but does require an OS + capable of running PV under Xen.
xen/arch/x86/Kconfig menu "Architecture Features" · line 54
Quoted 10 lines
xen/arch/x86/Kconfig +10
-0+ + If unsure, say Y. + + TODO: This is a work in process, and Xen doesn't currently compile + if this option is disabled. + +config HVM + def_bool y + prompt "HVM guest support" if EXPERT = "y" + depends on X86
Both of them getting selected to "no" makes extremely little sense, I think, so I would wish to have a guard against that. Maybe the user visible part wants to be a choice (both, PV only, HVM only), selecting prompt-less PV and HVM as necessary?
Furthermore, considering what file they're in, I don't think the "depends on X86" are necessary here (oddly enough TBOOT has this too, but SHADOW_PAGING and BIGMEM don't).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] [RFC] x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
Making PV and HVM guests individually compilable is useful as a reduction in hypervisor size, and as an aid to enforcing clean API boundaries.
Introduce
CONFIG_PVandCONFIG_HVM, although there is a lot of work to do until either can actually be disabled.While this is a nice goal, is it really useful to add these config options now, rather than when that lot of work is at least near completion?
Hence the RFC on this patch.
Quoted 2 lines
Or otherwise, how about making them prompt-less for now even for EXPERT?
Doesn't that prohibit them from being altered, even for development purposes?
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/Kconfig +16
-0@@ -32,6 +32,56 @@ menu "Architecture Features" source "arch/Kconfig" +config PV + def_bool y + prompt "PV guest support" if EXPERT = "y" + depends on X86 + ---help--- + Support for Xen Paravirtual guests. + + Xen PV guests use Ring Deprivileging as a method of virtualisation. + This requires no specific hardware support, but does require an OS + capable of running PV under Xen. + + If unsure, say Y. + + TODO: This is a work in process, and Xen doesn't currently compile + if this option is disabled. +
Quoted 8 lines
xen/arch/x86/Kconfig menu "Architecture Features" · line 54
Quoted 4 lines
xen/arch/x86/Kconfig +4
-0+config HVM + def_bool y + prompt "HVM guest support" if EXPERT = "y" + depends on X86Both of them getting selected to "no" makes extremely little sense, I think, so I would wish to have a guard against that. Maybe the user visible part wants to be a choice (both, PV only, HVM only), selecting prompt-less PV and HVM as necessary?
There are a few edgecases whether neither would be useful, e.g. seeing if we have subsystems in the resulting compile which should be covered under PV or HVM. I also had occason to need no guests whatsoever when doing the HPET work (and I still have the debugging patch to allow Xen to run without a dom0).
As this is already under EXPERT (and I expect that not to change), I don't it is too much of a problem allowing both to be disabled.
Quoted 3 lines
Furthermore, considering what file they're in, I don't think the "depends on X86" are necessary here (oddly enough TBOOT has this too, but
SHADOW_PAGINGand BIGMEM don't).
I did find this weird.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] [RFC] x86/kconfig: Introduce CONFIG_PV and CONFIG_HVM
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 15:58, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 20:41, <[email protected]> wrote:
Making PV and HVM guests individually compilable is useful as a reduction in hypervisor size, and as an aid to enforcing clean API boundaries.
Introduce
CONFIG_PVandCONFIG_HVM, although there is a lot of work to do until either can actually be disabled.While this is a nice goal, is it really useful to add these config options now, rather than when that lot of work is at least near completion?
Quoted 7 lines
Hence the RFC on this patch.
Quoted 2 lines
Or otherwise, how about making them prompt-less for now even for EXPERT?
Doesn't that prohibit them from being altered, even for development purposes?
Well, one would have to add a prompt line for the value to be changeable. But that would be a 1-line change, much smaller compared to the patch here, and hence acceptable imo.
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
xen/arch/x86/Kconfig +16
-0@@ -32,6 +32,56 @@ menu "Architecture Features" source "arch/Kconfig" +config PV + def_bool y + prompt "PV guest support" if EXPERT = "y" + depends on X86 + ---help--- + Support for Xen Paravirtual guests. + + Xen PV guests use Ring Deprivileging as a method of virtualisation. + This requires no specific hardware support, but does require an OS + capable of running PV under Xen. + + If unsure, say Y. + + TODO: This is a work in process, and Xen doesn't currently compile + if this option is disabled. +Quoted 8 lines
xen/arch/x86/Kconfig menu "Architecture Features" · line 54
Quoted 4 lines
xen/arch/x86/Kconfig +4
-0+config HVM + def_bool y + prompt "HVM guest support" if EXPERT = "y" + depends on X86Both of them getting selected to "no" makes extremely little sense, I think, so I would wish to have a guard against that. Maybe the user visible part wants to be a choice (both, PV only, HVM only), selecting prompt-less PV and HVM as necessary?
Quoted 5 lines
There are a few edgecases whether neither would be useful, e.g. seeing if we have subsystems in the resulting compile which should be covered under PV or HVM. I also had occason to need no guests whatsoever when doing the HPET work (and I still have the debugging patch to allow Xen to run without a dom0).
Oh, okay.
Quoted 5 lines
Quoted 3 lines
Furthermore, considering what file they're in, I don't think the "depends on X86" are necessary here (oddly enough TBOOT has this too, but
SHADOW_PAGINGand BIGMEM don't).I did find this weird.
Which part - the pointlessly present one, or the absent ones?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel