From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 03/11] make steal_page() return a proper error value Date: Wed, 21 Jun 2017 03:32:27 -0600 Message-ID: <594A594B0200007800165052@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="=__Part7D45633B.4__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNc01-00082R-DA for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 09:32:33 +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 , Julien Grall 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. --=__Part7D45633B.4__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... and use it where suitable (the tmem caller doesn't propagate an error code). While it doesn't matter as much, also make donate_page() follow suit on x86 (on ARM it already returns -ENOSYS). Also move their declarations to common code and add __must_check. Signed-off-by: Jan Beulich --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1090,7 +1090,7 @@ int donate_page(struct domain *d, struct int steal_page( struct domain *d, struct page_info *page, unsigned int memflags) { - return -1; + return -EOPNOTSUPP; } =20 int page_is_ram_type(unsigned long mfn, unsigned long mem_type) --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4424,7 +4424,7 @@ int donate_page( page_to_mfn(page), d->domain_id, owner ? owner->domain_id : DOMID_INVALID, page->count_info, page->u.inuse.type_info); - return -1; + return -EINVAL; } =20 int steal_page( @@ -4435,7 +4435,7 @@ int steal_page( const struct domain *owner =3D dom_xen; =20 if ( paging_mode_external(d) ) - return -1; + return -EOPNOTSUPP; =20 spin_lock(&d->page_alloc_lock); =20 @@ -4490,7 +4490,7 @@ int steal_page( page_to_mfn(page), d->domain_id, owner ? owner->domain_id : DOMID_INVALID, page->count_info, page->u.inuse.type_info); - return -1; + return -EINVAL; } =20 static int __do_update_va_mapping( --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1843,10 +1843,10 @@ gnttab_transfer( } =20 page =3D mfn_to_page(mfn); - if ( steal_page(d, page, 0) < 0 ) + if ( (rc =3D steal_page(d, page, 0)) < 0 ) { put_gfn(d, gop.mfn); - gop.status =3D GNTST_bad_page; + gop.status =3D rc =3D=3D -EINVAL ? GNTST_bad_page : GNTST_gene= ral_error; goto copyback; } =20 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -566,10 +566,10 @@ static long memory_exchange(XEN_GUEST_HA =20 page =3D mfn_to_page(mfn); =20 - if ( unlikely(steal_page(d, page, MEMF_no_refcount)) ) + rc =3D steal_page(d, page, MEMF_no_refcount); + if ( unlikely(rc) ) { put_gfn(d, gmfn + k); - rc =3D -EINVAL; goto fail; } =20 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -322,11 +322,6 @@ static inline int relinquish_shared_page /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg); =20 -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags); -int donate_page( - struct domain *d, struct page_info *page, unsigned int memflags); - #define domain_set_alloc_bitsize(d) ((void)0) #define domain_clamp_alloc_bitsize(d, b) (b) =20 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -550,11 +550,6 @@ long subarch_memory_op(unsigned long cmd int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void))= ; int compat_subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void)); =20 -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags); -int donate_page( - struct domain *d, struct page_info *page, unsigned int memflags); - int map_ldt_shadow_page(unsigned int); =20 #define NIL(type) ((type *)-sizeof(type)) --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -567,8 +567,12 @@ int xenmem_add_to_physmap_one(struct dom union xen_add_to_physmap_batch_extra extra, unsigned long idx, gfn_t gfn); =20 -/* Returns 0 on success, or negative on error. */ +/* Return 0 on success, or negative on error. */ int __must_check guest_remove_page(struct domain *d, unsigned long gmfn); +int __must_check steal_page(struct domain *d, struct page_info *page, + unsigned int memflags); +int __must_check donate_page(struct domain *d, struct page_info *page, + unsigned int memflags); =20 #define RAM_TYPE_CONVENTIONAL 0x00000001 #define RAM_TYPE_RESERVED 0x00000002 --=__Part7D45633B.4__= Content-Type: text/plain; name="steal_page-retval.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="steal_page-retval.patch" make steal_page() return a proper error value=0A=0A... and use it where = suitable (the tmem caller doesn't propagate an=0Aerror code). While it = doesn't matter as much, also make donate_page()=0Afollow suit on x86 (on = ARM it already returns -ENOSYS).=0A=0AAlso move their declarations to = common code and add __must_check.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/arm/mm.c=0A+++ b/xen/arch/arm/mm.c= =0A@@ -1090,7 +1090,7 @@ int donate_page(struct domain *d, struct=0A int = steal_page(=0A struct domain *d, struct page_info *page, unsigned int = memflags)=0A {=0A- return -1;=0A+ return -EOPNOTSUPP;=0A }=0A =0A = int page_is_ram_type(unsigned long mfn, unsigned long mem_type)=0A--- = a/xen/arch/x86/mm.c=0A+++ b/xen/arch/x86/mm.c=0A@@ -4424,7 +4424,7 @@ int = donate_page(=0A page_to_mfn(page), d->domain_id,=0A = owner ? owner->domain_id : DOMID_INVALID,=0A page->count_in= fo, page->u.inuse.type_info);=0A- return -1;=0A+ return -EINVAL;=0A = }=0A =0A int steal_page(=0A@@ -4435,7 +4435,7 @@ int steal_page(=0A = const struct domain *owner =3D dom_xen;=0A =0A if ( paging_mode_externa= l(d) )=0A- return -1;=0A+ return -EOPNOTSUPP;=0A =0A = spin_lock(&d->page_alloc_lock);=0A =0A@@ -4490,7 +4490,7 @@ int steal_page(= =0A page_to_mfn(page), d->domain_id,=0A owner ? = owner->domain_id : DOMID_INVALID,=0A page->count_info, = page->u.inuse.type_info);=0A- return -1;=0A+ return -EINVAL;=0A }=0A = =0A static int __do_update_va_mapping(=0A--- a/xen/common/grant_table.c=0A+= ++ b/xen/common/grant_table.c=0A@@ -1843,10 +1843,10 @@ gnttab_transfer(=0A= }=0A =0A page =3D mfn_to_page(mfn);=0A- if ( = steal_page(d, page, 0) < 0 )=0A+ if ( (rc =3D steal_page(d, page, = 0)) < 0 )=0A {=0A put_gfn(d, gop.mfn);=0A- = gop.status =3D GNTST_bad_page;=0A+ gop.status =3D rc =3D=3D = -EINVAL ? GNTST_bad_page : GNTST_general_error;=0A goto = copyback;=0A }=0A =0A--- a/xen/common/memory.c=0A+++ b/xen/common/m= emory.c=0A@@ -566,10 +566,10 @@ static long memory_exchange(XEN_GUEST_HA=0A= =0A page =3D mfn_to_page(mfn);=0A =0A- if = ( unlikely(steal_page(d, page, MEMF_no_refcount)) )=0A+ rc = =3D steal_page(d, page, MEMF_no_refcount);=0A+ if ( = unlikely(rc) )=0A {=0A put_gfn(d, gmfn = + k);=0A- rc =3D -EINVAL;=0A goto = fail;=0A }=0A =0A--- a/xen/include/asm-arm/mm.h=0A+++ = b/xen/include/asm-arm/mm.h=0A@@ -322,11 +322,6 @@ static inline int = relinquish_shared_page=0A /* Arch-specific portion of memory_op hypercall. = */=0A long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);=0A = =0A-int steal_page(=0A- struct domain *d, struct page_info *page, = unsigned int memflags);=0A-int donate_page(=0A- struct domain *d, = struct page_info *page, unsigned int memflags);=0A-=0A #define domain_set_a= lloc_bitsize(d) ((void)0)=0A #define domain_clamp_alloc_bitsize(d, b) = (b)=0A =0A--- a/xen/include/asm-x86/mm.h=0A+++ b/xen/include/asm-x86/mm.h= =0A@@ -550,11 +550,6 @@ long subarch_memory_op(unsigned long cmd=0A int = compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void));=0A = int compat_subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void));=0A = =0A-int steal_page(=0A- struct domain *d, struct page_info *page, = unsigned int memflags);=0A-int donate_page(=0A- struct domain *d, = struct page_info *page, unsigned int memflags);=0A-=0A int map_ldt_shadow_p= age(unsigned int);=0A =0A #define NIL(type) ((type *)-sizeof(type))=0A--- = a/xen/include/xen/mm.h=0A+++ b/xen/include/xen/mm.h=0A@@ -567,8 +567,12 @@ = int xenmem_add_to_physmap_one(struct dom=0A = union xen_add_to_physmap_batch_extra extra,=0A = unsigned long idx, gfn_t gfn);=0A =0A-/* Returns 0 on success, or = negative on error. */=0A+/* Return 0 on success, or negative on error. = */=0A int __must_check guest_remove_page(struct domain *d, unsigned long = gmfn);=0A+int __must_check steal_page(struct domain *d, struct page_info = *page,=0A+ unsigned int memflags);=0A+int = __must_check donate_page(struct domain *d, struct page_info *page,=0A+ = unsigned int memflags);=0A =0A #define RAM_TYPE_CON= VENTIONAL 0x00000001=0A #define RAM_TYPE_RESERVED 0x00000002=0A --=__Part7D45633B.4__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part7D45633B.4__=--