From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 09/11] gnttab: avoid spurious maptrack handle allocation failures Date: Wed, 21 Jun 2017 03:37:29 -0600 Message-ID: <594A5A7902000078001650BA@prv-mh.provo.novell.com> References: <594A57B10200007800165012@prv-mh.provo.novell.com> <594A57B10200007800165012@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0C341249.3__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNc4t-0000ZU-5Z for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 09:37:35 +0000 In-Reply-To: <594A57B10200007800165012@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan 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. --=__Part0C341249.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When no memory is available in the hypervisor, rather than immediately failing the request try to steal a handle from another vCPU. Reported-by: George Dunlap Signed-off-by: Jan Beulich --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -397,7 +397,7 @@ get_maptrack_handle( struct vcpu *curr =3D current; unsigned int i, head; grant_handle_t handle; - struct grant_mapping *new_mt; + struct grant_mapping *new_mt =3D NULL; =20 handle =3D __get_maptrack_handle(lgt, curr); if ( likely(handle !=3D -1) ) @@ -408,8 +408,13 @@ get_maptrack_handle( /* * If we've run out of frames, try stealing an entry from another * VCPU (in case the guest isn't mapping across its VCPUs evenly). + * Also use this path in case we're out of memory, to avoid spurious + * failures. */ - if ( nr_maptrack_frames(lgt) >=3D max_maptrack_frames ) + if ( nr_maptrack_frames(lgt) < max_maptrack_frames ) + new_mt =3D alloc_xenheap_page(); + + if ( !new_mt ) { /* * Can drop the lock since no other VCPU can be adding a new @@ -432,12 +437,6 @@ get_maptrack_handle( return steal_maptrack_handle(lgt, curr); } =20 - new_mt =3D alloc_xenheap_page(); - if ( !new_mt ) - { - spin_unlock(&lgt->maptrack_lock); - return -1; - } clear_page(new_mt); =20 /* --=__Part0C341249.3__= Content-Type: text/plain; name="gnttab-spurious-mt-handle-fail.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gnttab-spurious-mt-handle-fail.patch" gnttab: avoid spurious maptrack handle allocation failures=0A=0AWhen no = memory is available in the hypervisor, rather than immediately=0Afailing = the request try to steal a handle from another vCPU.=0A=0AReported-by: = George Dunlap =0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/common/grant_table.c=0A+++ b/xen/common/= grant_table.c=0A@@ -397,7 +397,7 @@ get_maptrack_handle(=0A struct = vcpu *curr =3D current;=0A unsigned int i, head;=0A = grant_handle_t handle;=0A- struct grant_mapping *new_mt;=0A+ = struct grant_mapping *new_mt =3D NULL;=0A =0A handle =3D __get_maptra= ck_handle(lgt, curr);=0A if ( likely(handle !=3D -1) )=0A@@ -408,8 = +408,13 @@ get_maptrack_handle(=0A /*=0A * If we've run out of = frames, try stealing an entry from another=0A * VCPU (in case the = guest isn't mapping across its VCPUs evenly).=0A+ * Also use this path = in case we're out of memory, to avoid spurious=0A+ * failures.=0A = */=0A- if ( nr_maptrack_frames(lgt) >=3D max_maptrack_frames )=0A+ = if ( nr_maptrack_frames(lgt) < max_maptrack_frames )=0A+ new_mt =3D = alloc_xenheap_page();=0A+=0A+ if ( !new_mt )=0A {=0A /*=0A = * Can drop the lock since no other VCPU can be adding a new=0A@@ = -432,12 +437,6 @@ get_maptrack_handle(=0A return steal_maptrack_han= dle(lgt, curr);=0A }=0A =0A- new_mt =3D alloc_xenheap_page();=0A- = if ( !new_mt )=0A- {=0A- spin_unlock(&lgt->maptrack_lock);=0A- = return -1;=0A- }=0A clear_page(new_mt);=0A =0A /*=0A --=__Part0C341249.3__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part0C341249.3__=--