From: "Jan Beulich" Subject: [PATCH] x86/memshr: fix preemption in relinquish_shared_pages() Date: Tue, 17 Dec 2013 09:07:07 +0000 Message-ID: <52B0224B020000780010E067@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB5865A2B.1__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VsqcR-0006bM-0d for xen-devel@lists.xenproject.org; Tue, 17 Dec 2013 09:07:11 +0000 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 , Andres Lagar-Cavilla 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. --=__PartB5865A2B.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline For one, should hypercall_preempt_check() return false the first time it gets called, it would never have got called again (because count, being checked for equality, didn't get reset to zero). And then, if there were a huge range of unshared pages, with count not getting incremented at all in that case there would also not be any preemption. Fix this by using a biased increment (ratio 1:16 for unshared vs shared pages), and check for certain bits in count to be clear rather than for a specific value (the alternative would be to do a greater-or-equal comparison and flush the value to zero in case of a "false" return from hypercall_preempt_check()). Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1290,11 +1290,13 @@ int relinquish_shared_pages(struct domai set_rc =3D p2m->set_entry(p2m, gfn, _mfn(0), PAGE_ORDER_4K, p2m_invalid, p2m_access_rwx); ASSERT(set_rc !=3D 0); - count++; + count +=3D 0x10; } + else + ++count; =20 - /* Preempt every 2MiB. Arbitrary */ - if ( (count =3D=3D 512) && hypercall_preempt_check() ) + /* Preempt every 2MiB (shared) or 32MiB (unshared) - arbitrary. = */ + if ( !(count & 0x1ff0) && hypercall_preempt_check() ) { p2m->next_shared_gfn_to_relinquish =3D gfn + 1; rc =3D -EAGAIN; --=__PartB5865A2B.1__= Content-Type: text/plain; name="x86-memshr-cleanup-preemption.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-memshr-cleanup-preemption.patch" x86/memshr: fix preemption in relinquish_shared_pages()=0A=0AFor one, = should hypercall_preempt_check() return false the first time=0Ait gets = called, it would never have got called again (because count,=0Abeing = checked for equality, didn't get reset to zero).=0A=0AAnd then, if there = were a huge range of unshared pages, with count not=0Agetting incremented = at all in that case there would also not be any=0Apreemption.=0A=0AFix = this by using a biased increment (ratio 1:16 for unshared vs shared=0Apages= ), and check for certain bits in count to be clear rather than for=0Aa = specific value (the alternative would be to do a greater-or-equal=0Acompari= son and flush the value to zero in case of a "false" return from=0Ahypercal= l_preempt_check()).=0A=0ASigned-off-by: Jan Beulich =0A= =0A--- a/xen/arch/x86/mm/mem_sharing.c=0A+++ b/xen/arch/x86/mm/mem_sharing.= c=0A@@ -1290,11 +1290,13 @@ int relinquish_shared_pages(struct domai=0A = set_rc =3D p2m->set_entry(p2m, gfn, _mfn(0), PAGE_ORDER_4K,=0A = p2m_invalid, p2m_access_rwx);=0A = ASSERT(set_rc !=3D 0);=0A- count++;=0A+ count = +=3D 0x10;=0A }=0A+ else=0A+ ++count;=0A =0A- = /* Preempt every 2MiB. Arbitrary */=0A- if ( (count =3D=3D 512) = && hypercall_preempt_check() )=0A+ /* Preempt every 2MiB (shared) = or 32MiB (unshared) - arbitrary. */=0A+ if ( !(count & 0x1ff0) && = hypercall_preempt_check() )=0A {=0A p2m->next_shared_gf= n_to_relinquish =3D gfn + 1;=0A rc =3D -EAGAIN;=0A --=__PartB5865A2B.1__= 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 --=__PartB5865A2B.1__=--