From: "Jan Beulich" Subject: [PATCH 2/2] x86: make hypercall preemption checks consistent Date: Tue, 04 Mar 2014 11:26:06 +0000 Message-ID: <5315C65E0200007800120CF7@nat28.tlf.novell.com> References: <5315C5370200007800120CE4@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC8FA835E.0__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WKnUD-0008I0-03 for xen-devel@lists.xenproject.org; Tue, 04 Mar 2014 11:26:13 +0000 In-Reply-To: <5315C5370200007800120CE4@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Tim Deegan , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartC8FA835E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - never preempt on the first iteration (ensure forward progress) - never preempt on the last iteration (pointless/wasteful) Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2934,7 +2934,7 @@ long do_mmuext_op( =20 for ( i =3D 0; i < count; i++ ) { - if ( curr->arch.old_guest_table || hypercall_preempt_check() ) + if ( curr->arch.old_guest_table || (i && hypercall_preempt_check()= ) ) { rc =3D -EAGAIN; break; @@ -3481,7 +3481,7 @@ long do_mmu_update( =20 for ( i =3D 0; i < count; i++ ) { - if ( curr->arch.old_guest_table || hypercall_preempt_check() ) + if ( curr->arch.old_guest_table || (i && hypercall_preempt_check()= ) ) { rc =3D -EAGAIN; break; --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -326,7 +326,7 @@ hap_set_allocation(struct domain *d, uns else pages -=3D d->arch.paging.hap.p2m_pages; =20 - while ( d->arch.paging.hap.total_pages !=3D pages ) + for ( ; ; ) { if ( d->arch.paging.hap.total_pages < pages ) { @@ -355,6 +355,8 @@ hap_set_allocation(struct domain *d, uns d->arch.paging.hap.total_pages--; free_domheap_page(pg); } + else + break; =20 /* Check to see if we need to yield and try again */ if ( preempted && hypercall_preempt_check() ) --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -242,7 +242,8 @@ p2m_pod_set_cache_target(struct p2m_doma =20 p2m_pod_cache_add(p2m, page, order); =20 - if ( hypercall_preempt_check() && preemptible ) + if ( preemptible && pod_target !=3D p2m->pod.count && + hypercall_preempt_check() ) { ret =3D -EAGAIN; goto out; @@ -286,7 +287,8 @@ p2m_pod_set_cache_target(struct p2m_doma =20 put_page(page+i); =20 - if ( hypercall_preempt_check() && preemptible ) + if ( preemptible && pod_target !=3D p2m->pod.count && + hypercall_preempt_check() ) { ret =3D -EAGAIN; goto out; --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1672,7 +1672,7 @@ static unsigned int sh_set_allocation(st SHADOW_PRINTK("current %i target %i\n",=20 d->arch.paging.shadow.total_pages, pages); =20 - while ( d->arch.paging.shadow.total_pages !=3D pages )=20 + for ( ; ; ) { if ( d->arch.paging.shadow.total_pages < pages )=20 { @@ -1707,6 +1707,8 @@ static unsigned int sh_set_allocation(st d->arch.paging.shadow.total_pages--; free_domheap_page(sp); } + else + break; =20 /* Check to see if we need to yield and try again */ if ( preempted && hypercall_preempt_check() ) --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -3596,13 +3596,6 @@ long do_set_trap_table(XEN_GUEST_HANDLE_ =20 for ( ; ; ) { - if ( hypercall_preempt_check() ) - { - rc =3D hypercall_create_continuation( - __HYPERVISOR_set_trap_table, "h", traps); - break; - } - if ( copy_from_guest(&cur, traps, 1) ) { rc =3D -EFAULT; @@ -3623,6 +3616,13 @@ long do_set_trap_table(XEN_GUEST_HANDLE_ init_int80_direct_trap(curr); =20 guest_handle_add_offset(traps, 1); + + if ( hypercall_preempt_check() ) + { + rc =3D hypercall_create_continuation( + __HYPERVISOR_set_trap_table, "h", traps); + break; + } } =20 return rc; --- a/xen/arch/x86/x86_64/compat/traps.c +++ b/xen/arch/x86/x86_64/compat/traps.c @@ -329,13 +329,6 @@ int compat_set_trap_table(XEN_GUEST_HAND =20 for ( ; ; ) { - if ( hypercall_preempt_check() ) - { - rc =3D hypercall_create_continuation( - __HYPERVISOR_set_trap_table, "h", traps); - break; - } - if ( copy_from_guest(&cur, traps, 1) ) { rc =3D -EFAULT; @@ -353,6 +346,13 @@ int compat_set_trap_table(XEN_GUEST_HAND init_int80_direct_trap(current); =20 guest_handle_add_offset(traps, 1); + + if ( hypercall_preempt_check() ) + { + rc =3D hypercall_create_continuation( + __HYPERVISOR_set_trap_table, "h", traps); + break; + } } =20 return rc; --=__PartC8FA835E.0__= Content-Type: text/plain; name="preempt-progress-x86.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="preempt-progress-x86.patch" x86: make hypercall preemption checks consistent=0A=0A- never preempt on = the first iteration (ensure forward progress)=0A- never preempt on the = last iteration (pointless/wasteful)=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/mm.c=0A+++ b/xen/arch/x86/mm.c= =0A@@ -2934,7 +2934,7 @@ long do_mmuext_op(=0A =0A for ( i =3D 0; i < = count; i++ )=0A {=0A- if ( curr->arch.old_guest_table || = hypercall_preempt_check() )=0A+ if ( curr->arch.old_guest_table || = (i && hypercall_preempt_check()) )=0A {=0A rc =3D = -EAGAIN;=0A break;=0A@@ -3481,7 +3481,7 @@ long do_mmu_update(= =0A =0A for ( i =3D 0; i < count; i++ )=0A {=0A- if ( = curr->arch.old_guest_table || hypercall_preempt_check() )=0A+ if ( = curr->arch.old_guest_table || (i && hypercall_preempt_check()) )=0A = {=0A rc =3D -EAGAIN;=0A break;=0A--- a/xen/arch/x8= 6/mm/hap/hap.c=0A+++ b/xen/arch/x86/mm/hap/hap.c=0A@@ -326,7 +326,7 @@ = hap_set_allocation(struct domain *d, uns=0A else=0A pages -=3D = d->arch.paging.hap.p2m_pages;=0A =0A- while ( d->arch.paging.hap.total_p= ages !=3D pages )=0A+ for ( ; ; )=0A {=0A if ( d->arch.pagin= g.hap.total_pages < pages )=0A {=0A@@ -355,6 +355,8 @@ hap_set_allo= cation(struct domain *d, uns=0A d->arch.paging.hap.total_pages-= -;=0A free_domheap_page(pg);=0A }=0A+ else=0A+ = break;=0A =0A /* Check to see if we need to yield and = try again */=0A if ( preempted && hypercall_preempt_check() = )=0A--- a/xen/arch/x86/mm/p2m-pod.c=0A+++ b/xen/arch/x86/mm/p2m-pod.c=0A@@ = -242,7 +242,8 @@ p2m_pod_set_cache_target(struct p2m_doma=0A =0A = p2m_pod_cache_add(p2m, page, order);=0A =0A- if ( hypercall_preempt_= check() && preemptible )=0A+ if ( preemptible && pod_target !=3D = p2m->pod.count &&=0A+ hypercall_preempt_check() )=0A = {=0A ret =3D -EAGAIN;=0A goto out;=0A@@ -286,7 = +287,8 @@ p2m_pod_set_cache_target(struct p2m_doma=0A =0A = put_page(page+i);=0A =0A- if ( hypercall_preempt_check() && = preemptible )=0A+ if ( preemptible && pod_target !=3D p2m->pod.c= ount &&=0A+ hypercall_preempt_check() )=0A = {=0A ret =3D -EAGAIN;=0A goto out;=0A--- = a/xen/arch/x86/mm/shadow/common.c=0A+++ b/xen/arch/x86/mm/shadow/common.c= =0A@@ -1672,7 +1672,7 @@ static unsigned int sh_set_allocation(st=0A = SHADOW_PRINTK("current %i target %i\n", =0A d->arch.pagi= ng.shadow.total_pages, pages);=0A =0A- while ( d->arch.paging.shadow.tot= al_pages !=3D pages ) =0A+ for ( ; ; )=0A {=0A if ( = d->arch.paging.shadow.total_pages < pages ) =0A {=0A@@ -1707,6 = +1707,8 @@ static unsigned int sh_set_allocation(st=0A = d->arch.paging.shadow.total_pages--;=0A free_domheap_page(sp);= =0A }=0A+ else=0A+ break;=0A =0A /* = Check to see if we need to yield and try again */=0A if ( = preempted && hypercall_preempt_check() )=0A--- a/xen/arch/x86/traps.c=0A+++= b/xen/arch/x86/traps.c=0A@@ -3596,13 +3596,6 @@ long do_set_trap_table(XEN= _GUEST_HANDLE_=0A =0A for ( ; ; )=0A {=0A- if ( hypercall_pr= eempt_check() )=0A- {=0A- rc =3D hypercall_create_continu= ation(=0A- __HYPERVISOR_set_trap_table, "h", traps);=0A- = break;=0A- }=0A-=0A if ( copy_from_guest(&cur, = traps, 1) )=0A {=0A rc =3D -EFAULT;=0A@@ -3623,6 = +3616,13 @@ long do_set_trap_table(XEN_GUEST_HANDLE_=0A = init_int80_direct_trap(curr);=0A =0A guest_handle_add_offset(traps,= 1);=0A+=0A+ if ( hypercall_preempt_check() )=0A+ {=0A+ = rc =3D hypercall_create_continuation(=0A+ __HYPERVISOR= _set_trap_table, "h", traps);=0A+ break;=0A+ }=0A = }=0A =0A return rc;=0A--- a/xen/arch/x86/x86_64/compat/traps.c=0A+++ = b/xen/arch/x86/x86_64/compat/traps.c=0A@@ -329,13 +329,6 @@ int compat_set_= trap_table(XEN_GUEST_HAND=0A =0A for ( ; ; )=0A {=0A- if ( = hypercall_preempt_check() )=0A- {=0A- rc =3D hypercall_cr= eate_continuation(=0A- __HYPERVISOR_set_trap_table, "h", = traps);=0A- break;=0A- }=0A-=0A if ( copy_from_gu= est(&cur, traps, 1) )=0A {=0A rc =3D -EFAULT;=0A@@ = -353,6 +346,13 @@ int compat_set_trap_table(XEN_GUEST_HAND=0A = init_int80_direct_trap(current);=0A =0A guest_handle_add_offset(tra= ps, 1);=0A+=0A+ if ( hypercall_preempt_check() )=0A+ {=0A+ = rc =3D hypercall_create_continuation(=0A+ = __HYPERVISOR_set_trap_table, "h", traps);=0A+ break;=0A+ = }=0A }=0A =0A return rc;=0A --=__PartC8FA835E.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartC8FA835E.0__=--